diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2012-08-25 10:38:25 +0200 |
---|---|---|
committer | Nicolas Goaziou <n.goaziou@gmail.com> | 2012-08-25 10:38:25 +0200 |
commit | d86f09a8541adef364163a29dda66f9cac2b4ff7 (patch) | |
tree | b42628528bea10c4b7774c91b7fdab8ed2560fbe | |
parent | d09a6b3db57a23bd72a83ac57aadf665aed18e26 (diff) | |
download | org-mode-d86f09a8541adef364163a29dda66f9cac2b4ff7.tar.gz |
org-element: Extract search option and application in "file"-type links
* lisp/org-element.el (org-element-link-type-is-file): New variable.
(org-element-link-parser): Extract search option and application in
"file"-type links.
* contrib/lisp/org-e-html.el (org-e-html-link): Remove components
extraction since this in now done in `org-element-link-parser'.
* contrib/lisp/org-e-odt.el: Remove components extraction since this
in now done in `org-element-link-parser'.
* contrib/lisp/org-e-texinfo.el (org-e-texinfo-link): Remove
components extraction since this in now done in
`org-element-link-parser'.
* contrib/lisp/org-e-latex.el (org-e-latex-link): Remove components
extraction since this in now done in `org-element-link-parser'.
* contrib/lisp/org-e-man.el (org-e-man-link): Remove components
extraction since this in now done in `org-element-link-parser'.
* contrib/lisp/org-e-groff.el (org-e-groff-link): Remove components
extraction since this in now done in `org-element-link-parser'.
* contrib/lisp/org-md.el (org-md-link): Remove components extraction
since this in now done in `org-element-link-parser'.
* testing/lisp/test-org-element.el: Add tests.
-rw-r--r-- | contrib/lisp/org-e-groff.el | 2 | ||||
-rw-r--r-- | contrib/lisp/org-e-html.el | 4 | ||||
-rw-r--r-- | contrib/lisp/org-e-latex.el | 2 | ||||
-rw-r--r-- | contrib/lisp/org-e-man.el | 2 | ||||
-rw-r--r-- | contrib/lisp/org-e-odt.el | 2 | ||||
-rw-r--r-- | contrib/lisp/org-e-texinfo.el | 2 | ||||
-rw-r--r-- | contrib/lisp/org-md.el | 4 | ||||
-rw-r--r-- | lisp/org-element.el | 29 | ||||
-rw-r--r-- | testing/lisp/test-org-element.el | 20 |
9 files changed, 46 insertions, 21 deletions
diff --git a/contrib/lisp/org-e-groff.el b/contrib/lisp/org-e-groff.el index 756a818..c1860e8 100644 --- a/contrib/lisp/org-e-groff.el +++ b/contrib/lisp/org-e-groff.el @@ -1336,8 +1336,6 @@ INFO is a plist holding contextual information. See ((member type '("http" "https" "ftp" "mailto")) (concat type ":" raw-path)) ((string= type "file") - (when (string-match "\\(.+\\)::.+" raw-path) - (setq raw-path (match-string 1 raw-path))) (if (file-name-absolute-p raw-path) (concat "file://" (expand-file-name raw-path)) (concat "file://" raw-path))) diff --git a/contrib/lisp/org-e-html.el b/contrib/lisp/org-e-html.el index 94f42ea..0d991ea 100644 --- a/contrib/lisp/org-e-html.el +++ b/contrib/lisp/org-e-html.el @@ -2277,10 +2277,6 @@ INFO is a plist holding contextual information. See ((member type '("http" "https" "ftp" "mailto")) (concat type ":" raw-path)) ((string= type "file") - ;; Extract just the file path and strip all other - ;; components. - (when (string-match "\\(.+\\)::.+" raw-path) - (setq raw-path (match-string 1 raw-path))) ;; Treat links to ".org" files as ".html", if needed. (setq raw-path (funcall --link-org-files-as-html-maybe raw-path info)) diff --git a/contrib/lisp/org-e-latex.el b/contrib/lisp/org-e-latex.el index 8dd2d92..f2b8e92 100644 --- a/contrib/lisp/org-e-latex.el +++ b/contrib/lisp/org-e-latex.el @@ -1748,8 +1748,6 @@ INFO is a plist holding contextual information. See ((member type '("http" "https" "ftp" "mailto")) (concat type ":" raw-path)) ((string= type "file") - (when (string-match "\\(.+\\)::.+" raw-path) - (setq raw-path (match-string 1 raw-path))) (if (file-name-absolute-p raw-path) (concat "file://" (expand-file-name raw-path)) (concat "file://" raw-path))) diff --git a/contrib/lisp/org-e-man.el b/contrib/lisp/org-e-man.el index 981f831..264fdef 100644 --- a/contrib/lisp/org-e-man.el +++ b/contrib/lisp/org-e-man.el @@ -731,8 +731,6 @@ INFO is a plist holding contextual information. See ((member type '("http" "https" "ftp" "mailto")) (concat type ":" raw-path)) ((string= type "file") - (when (string-match "\\(.+\\)::.+" raw-path) - (setq raw-path (match-string 1 raw-path))) (if (file-name-absolute-p raw-path) (concat "file://" (expand-file-name raw-path)) (concat "file://" raw-path))) diff --git a/contrib/lisp/org-e-odt.el b/contrib/lisp/org-e-odt.el index 0f9e2d4..d83c72f 100644 --- a/contrib/lisp/org-e-odt.el +++ b/contrib/lisp/org-e-odt.el @@ -2485,8 +2485,6 @@ INFO is a plist holding contextual information. See ((member type '("http" "https" "ftp" "mailto")) (concat type ":" raw-path)) ((string= type "file") - (when (string-match "\\(.+\\)::.+" raw-path) - (setq raw-path (match-string 1 raw-path))) (if (file-name-absolute-p raw-path) (concat "file://" (expand-file-name raw-path)) (concat "file://" raw-path))) diff --git a/contrib/lisp/org-e-texinfo.el b/contrib/lisp/org-e-texinfo.el index a19139f..d744a3a 100644 --- a/contrib/lisp/org-e-texinfo.el +++ b/contrib/lisp/org-e-texinfo.el @@ -1223,8 +1223,6 @@ INFO is a plist holding contextual information. See ((member type '("http" "https" "ftp")) (concat type ":" raw-path)) ((string= type "file") - (when (string-match "\\(.+\\)::.+" raw-path) - (setq raw-path (match-string 1 raw-path))) (if (file-name-absolute-p raw-path) (concat "file://" (expand-file-name raw-path)) (concat "file://" raw-path))) diff --git a/contrib/lisp/org-md.el b/contrib/lisp/org-md.el index 4579ca3..8e8189c 100644 --- a/contrib/lisp/org-md.el +++ b/contrib/lisp/org-md.el @@ -307,10 +307,6 @@ a communication channel." ((member type '("http" "https" "ftp")) (concat type ":" raw-path)) ((equal type "file") - ;; Extract just the file path and strip - ;; all other components. - (when (string-match "\\(.+\\)::.+" raw-path) - (setq raw-path (match-string 1 raw-path))) ;; Treat links to ".org" files as ".html", ;; if needed. (setq raw-path diff --git a/lisp/org-element.el b/lisp/org-element.el index f0e1a0f..265ca53 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -214,6 +214,12 @@ regexp matching one object can also match the other object.") Names must be uppercase. Any block whose name has no association is parsed with `org-element-special-block-parser'.") +(defconst org-element-link-type-is-file + '("file" "file+emacs" "file+sys" "docview") + "List of link types equivalent to \"file\". +Only these types can accept search options and an explicit +application to open them.") + (defconst org-element-affiliated-keywords '("CAPTION" "DATA" "HEADER" "HEADERS" "LABEL" "NAME" "PLOT" "RESNAME" "RESULT" "RESULTS" "SOURCE" "SRCNAME" "TBLNAME") @@ -2717,14 +2723,15 @@ beginning position." "Parse link at point. Return a list whose CAR is `link' and CDR a plist with `:type', -`:path', `:raw-link', `:begin', `:end', `:contents-begin', -`:contents-end' and `:post-blank' as keywords. +`:path', `:raw-link', `:application', `:search-option', `:begin', +`:end', `:contents-begin', `:contents-end' and `:post-blank' as +keywords. Assume point is at the beginning of the link." (save-excursion (let ((begin (point)) end contents-begin contents-end link-end post-blank path type - raw-link link) + raw-link link search-option application) (cond ;; Type 1: Text targeted from a radio target. ((and org-target-link-regexp (looking-at org-target-link-regexp)) @@ -2779,10 +2786,26 @@ Assume point is at the beginning of the link." ;; LINK-END variable. (setq post-blank (progn (goto-char link-end) (skip-chars-forward " \t")) end (point)) + ;; Extract search option and opening application out of + ;; "file"-type links. + (when (member type org-element-link-type-is-file) + ;; Application. + (cond ((string-match "^file\\+\\(.*\\)$" type) + (setq application (match-string 1 type))) + ((not (string-match "^file" type)) + (setq application type))) + ;; Extract search option from PATH. + (when (string-match "::\\(.*\\)$" path) + (setq search-option (match-string 1 path) + path (replace-match "" nil nil path))) + ;; Make sure TYPE always report "file". + (setq type "file")) (list 'link (list :type type :path path :raw-link (or raw-link path) + :application application + :search-option search-option :begin begin :end end :contents-begin contents-begin diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 63faca1..1b119ca 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -1101,6 +1101,26 @@ e^{i\\pi}+1=0 (org-element-property :type (org-element-map (org-element-parse-buffer) 'link 'identity nil t))))) + ;; 2.9 File-type link with search option. + (should + (equal + '(("file" "projects.org" "*task title")) + (org-test-with-temp-text "[[file:projects.org::*task title]]" + (org-element-map + (org-element-parse-buffer) 'link + (lambda (l) (list (org-element-property :type l) + (org-element-property :path l) + (org-element-property :search-option l))))))) + ;; 2.10 File-type link with application. + (should + (equal + '(("file" "projects.org" "docview")) + (org-test-with-temp-text "[[docview:projects.org]]" + (org-element-map + (org-element-parse-buffer) 'link + (lambda (l) (list (org-element-property :type l) + (org-element-property :path l) + (org-element-property :application l))))))) ;; 3. Plain link. (should (org-test-with-temp-text "A link: http://orgmode.org" |