summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2014-03-04 15:03:23 +0100
committerNicolas Goaziou <n.goaziou@gmail.com>2014-03-05 11:39:48 +0100
commit2891ef7f871f5c5800e9fe390a27abaed2b97eb6 (patch)
tree1a405db16948e0fb01e79ff0f0d4251f79cd66ce
parentfb8a042887629b6ac34c7b196197741915af3260 (diff)
downloadorg-mode-2891ef7f871f5c5800e9fe390a27abaed2b97eb6.tar.gz
Fix `org-open-at-point' on "docview"-type links
* lisp/org.el (org-open-at-point): Open "docview"-type links correctly, i.e., without adding "file+" first. (org-open-file-with-system, org-open-file-with-emacs): Change signature. Deprecate functions. * lisp/org-docview.el (org-docview-open): Open file even when no file number is specified. This change removes "file+emacs" and "file+sys" types from `org-link-protocols', since they are not hard-coded in `org-open-at-point'.
-rw-r--r--lisp/org-docview.el15
-rw-r--r--lisp/org.el61
2 files changed, 44 insertions, 32 deletions
diff --git a/lisp/org-docview.el b/lisp/org-docview.el
index d2db685..b907262 100644
--- a/lisp/org-docview.el
+++ b/lisp/org-docview.el
@@ -66,13 +66,14 @@
(t path)))))
(defun org-docview-open (link)
- (when (string-match "\\(.*\\)::\\([0-9]+\\)$" link)
- (let* ((path (match-string 1 link))
- (page (string-to-number (match-string 2 link))))
- (org-open-file path 1) ;; let org-mode open the file (in-emacs = 1)
- ;; to ensure org-link-frame-setup is respected
- (doc-view-goto-page page)
- )))
+ (string-match "\\(.*?\\)\\(?:::\\([0-9]+\\)\\)?$" link)
+ (let ((path (match-string 1 link))
+ (page (and (match-beginning 2)
+ (string-to-number (match-string 2 link)))))
+ ;; Let Org mode open the file (in-emacs = 1) to ensure
+ ;; org-link-frame-setup is respected.
+ (org-open-file path 1)
+ (when page (doc-view-goto-page page))))
(defun org-docview-store-link ()
"Store a link to a docview buffer."
diff --git a/lisp/org.el b/lisp/org.el
index 64ee668..7ded8c5 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -10526,17 +10526,34 @@ is used internally by `org-open-link-from-string'."
((equal type "file")
(if (string-match "[*?{]" (file-name-nondirectory path))
(dired path)
- (apply
- (or (let ((app (org-element-property :application context)))
- (nth 1 (assoc (concat "file" (and app (concat "+" app)))
- org-link-protocols)))
- #'org-open-file)
- path arg
- (let ((option (org-element-property :search-option context)))
- (cond ((not option) nil)
- ((org-string-match-p "\\`[0-9]+\\'" option)
- (list (string-to-number option)))
- (t (list nil option)))))))
+ ;; Look into `org-link-protocols' in order to find
+ ;; a DEDICATED-FUNCTION to open file. The function
+ ;; will be applied on raw link instead of parsed
+ ;; link due to the limitation in `org-add-link-type'
+ ;; ("open" function called with a single argument).
+ ;; If no such function is found, fallback to
+ ;; `org-open-file'.
+ ;;
+ ;; Note : "file+emacs" and "file+sys" types are
+ ;; hard-coded in order to escape the previous
+ ;; limitation.
+ (let* ((option (org-element-property :search-option context))
+ (app (org-element-property :application context))
+ (dedicated-function
+ (nth 1 (assoc app org-link-protocols))))
+ (if dedicated-function
+ (funcall dedicated-function
+ (concat path
+ (and option (concat "::" option))))
+ (apply #'org-open-file
+ path
+ (cond (arg)
+ ((equal app "emacs") 'emacs)
+ ((equal app "sys") 'system))
+ (cond ((not option) nil)
+ ((org-string-match-p "\\`[0-9]+\\'" option)
+ (list (string-to-number option)))
+ (t (list nil option))))))))
((assoc type org-link-protocols)
(funcall (nth 1 (assoc type org-link-protocols)) path))
((equal type "help")
@@ -10700,20 +10717,14 @@ there is one, return it."
(setq link (nth (1- nth) links)))))
(cons link end))))))
-;; Add special file links that specify the way of opening
-
-(org-add-link-type "file+sys" 'org-open-file-with-system)
-(org-add-link-type "file+emacs" 'org-open-file-with-emacs)
-(defun org-open-file-with-system (path &optional arg line search)
- "Open file at PATH using the system way of opening it.
-Optional argument ARG is ignored. See `org-open-file' for LINE
-and SEARCH arguments."
- (org-open-file path 'system line search))
-(defun org-open-file-with-emacs (path &optional arg line search)
- "Open file at PATH in Emacs.
-Optional argument ARG is ignored. See `org-open-file' for LINE
-and SEARCH arguments."
- (org-open-file path 'emacs line search))
+;; TODO: These functions are deprecated since `org-open-at-point'
+;; hard-codes behaviour for "file+emacs" and "file+sys" types.
+(defun org-open-file-with-system (path)
+ "Open file at PATH using the system way of opening it."
+ (org-open-file path 'system))
+(defun org-open-file-with-emacs (path)
+ "Open file at PATH in Emacs."
+ (org-open-file path 'emacs))
;;; File search