浏览代码

Links: Fix opening links to current file from a string.

Patch by Andreas Burtzlaff.
Carsten Dominik 16 年之前
父节点
当前提交
9936b09ec3
共有 2 个文件被更改,包括 20 次插入7 次删除
  1. 6 0
      lisp/ChangeLog
  2. 14 7
      lisp/org.el

+ 6 - 0
lisp/ChangeLog

@@ -1,3 +1,9 @@
+2009-04-04  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org.el (org-open-link-from-string): Pass reference buffer to
+	`org-open-at-point'.
+	(org-open-at-point): New optional argument `reference-buffer'.
+
 2009-04-03  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org.el (org-scan-tags): Make tag scan find headline in first

+ 14 - 7
lisp/org.el

@@ -7446,14 +7446,15 @@ Org-mode syntax."
 (defun org-open-link-from-string (s &optional arg)
   "Open a link in the string S, as if it was in Org-mode."
   (interactive "sLink: \nP")
-  (with-temp-buffer
-    (let ((org-inhibit-startup t))
-      (org-mode)
-      (insert s)
-      (goto-char (point-min))
-      (org-open-at-point arg))))
+  (let ((reference-buffer (current-buffer)))
+    (with-temp-buffer
+      (let ((org-inhibit-startup t))
+	(org-mode)
+	(insert s)
+	(goto-char (point-min))
+	(org-open-at-point arg reference-buffer)))))
 
-(defun org-open-at-point (&optional in-emacs)
+(defun org-open-at-point (&optional in-emacs reference-buffer)
   "Open link at or after point.
 If there is no link at point, this function will search forward up to
 the end of the current subtree.
@@ -7517,6 +7518,12 @@ application the system uses for this file type."
 	  (throw 'match t)))
       (unless path
 	(error "No link found"))
+
+      ;; switch back to reference buffer
+      ;; needed when if called in a temporary buffer through
+      ;; org-open-link-from-string
+      (and reference-buffer (switch-to-buffer reference-buffer))
+
       ;; Remove any trailing spaces in path
       (if (string-match " +\\'" path)
 	  (setq path (replace-match "" t t path)))