Browse Source

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

Patch by Andreas Burtzlaff.
Carsten Dominik 16 years ago
parent
commit
9936b09ec3
2 changed files with 20 additions and 7 deletions
  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>
 2009-04-03  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
 	* org.el (org-scan-tags): Make tag scan find headline in first
 	* 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)
 (defun org-open-link-from-string (s &optional arg)
   "Open a link in the string S, as if it was in Org-mode."
   "Open a link in the string S, as if it was in Org-mode."
   (interactive "sLink: \nP")
   (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.
   "Open link at or after point.
 If there is no link at point, this function will search forward up to
 If there is no link at point, this function will search forward up to
 the end of the current subtree.
 the end of the current subtree.
@@ -7517,6 +7518,12 @@ application the system uses for this file type."
 	  (throw 'match t)))
 	  (throw 'match t)))
       (unless path
       (unless path
 	(error "No link found"))
 	(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
       ;; Remove any trailing spaces in path
       (if (string-match " +\\'" path)
       (if (string-match " +\\'" path)
 	  (setq path (replace-match "" t t path)))
 	  (setq path (replace-match "" t t path)))