summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-01-17 10:42:13 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-01-17 10:42:13 +0100
commit9e4578366160cfdc484d3f4a11ba10d4739ffaa3 (patch)
tree54f145596ae02a4455512b4f0ea16725bde1f76f
parent1619aee37663a0f8980322652807440da04b2a75 (diff)
downloadorg-mode-9e4578366160cfdc484d3f4a11ba10d4739ffaa3.tar.gz
Save position before searching for a search option in case of error
* lisp/org.el (org-open-file): Save position with `org-mark-ring-push' before calling `org-link-search'.
-rw-r--r--etc/ORG-NEWS7
-rw-r--r--lisp/org.el35
2 files changed, 28 insertions, 14 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index e93986b..99952a9 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -195,6 +195,13 @@ Call ~org-agenda-set-restriction-lock~ from the agenda.
*** Computed dates in tables appear as inactive time stamps
+*** Save point before opening a file with an unknown search option
+
+When following a file link with a search option (e.g., =::#custom-id=)
+that doesn't exist in the target file, save positon before raising an
+error. As a consequence, it is possible to jump back to the original
+document with ~org-mark-ring-goto~ (default binding =C-c &=).
+
* Version 9.0
** Incompatible changes
diff --git a/lisp/org.el b/lisp/org.el
index 1807ce7..102f2d1 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -11362,12 +11362,19 @@ If the file does not exist, an error is thrown."
(search (concat file "::" search))
(t file)))
(dlink (downcase link))
- (old-buffer (current-buffer))
- (old-pos (point))
- (old-mode major-mode)
(ext
(and (string-match "\\`.*?\\.\\([a-zA-Z0-9]+\\(\\.gz\\)?\\)\\'" dfile)
(match-string 1 dfile)))
+ (save-position-maybe
+ (let ((old-buffer (current-buffer))
+ (old-pos (point))
+ (old-mode major-mode))
+ (lambda ()
+ (and (derived-mode-p 'org-mode)
+ (eq old-mode 'org-mode)
+ (or (not (eq old-buffer (current-buffer)))
+ (not (eq old-pos (point))))
+ (org-mark-ring-push old-pos old-buffer)))))
cmd link-match-data)
(cond
((member in-emacs '((16) system))
@@ -11441,7 +11448,12 @@ If the file does not exist, an error is thrown."
(widen)
(cond (line (org-goto-line line)
(when (derived-mode-p 'org-mode) (org-reveal)))
- (search (org-link-search search))))
+ (search (condition-case err
+ (org-link-search search)
+ ;; Save position before error-ing out so user
+ ;; can easily move back to the original buffer.
+ (error (funcall save-position-maybe)
+ (error (nth 1 err)))))))
((functionp cmd)
(save-match-data
(set-match-data link-match-data)
@@ -11450,23 +11462,18 @@ If the file does not exist, an error is thrown."
;; FIXME: Remove this check when most default installations
;; of Emacs have at least Org 9.0.
((debug wrong-number-of-arguments wrong-type-argument
- invalid-function)
+ invalid-function)
(user-error "Please see Org News for version 9.0 about \
`org-file-apps'--Lisp error: %S" cmd)))))
((consp cmd)
;; FIXME: Remove this check when most default installations of
- ;; Emacs have at least Org 9.0.
- ;; Heads-up instead of silently fall back to
- ;; `org-link-frame-setup' for an old usage of `org-file-apps'
- ;; with sexp instead of a function for `cmd'.
+ ;; Emacs have at least Org 9.0. Heads-up instead of silently
+ ;; fall back to `org-link-frame-setup' for an old usage of
+ ;; `org-file-apps' with sexp instead of a function for `cmd'.
(user-error "Please see Org News for version 9.0 about \
`org-file-apps'--Error: Deprecated usage of %S" cmd))
(t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
- (and (derived-mode-p 'org-mode)
- (eq old-mode 'org-mode)
- (or (not (eq old-buffer (current-buffer)))
- (not (eq old-pos (point))))
- (org-mark-ring-push old-pos old-buffer))))
+ (funcall save-position-maybe)))
(defun org-file-apps-entry-match-against-dlink-p (entry)
"This function returns non-nil if `entry' uses a regular