org-open-at-point: Preserve point unless opening link moves the point
* lisp/org.el (org-open-at-point): Preserve point when opening links. When a link opened moves point in current buffer, do move the point as needed by the link. When multiple links that are opened move point in current buffer, move point to the last such link. Fix searching for the links when opening _multiple_ the links is requested. Reported-by: Gustavo Barros <gusbrs.2016@gmail.com> Link: https://orgmode.org/list/87r0mp2srd.fsf@localhost
This commit is contained in:
parent
20ab29117c
commit
098f081591
15
lisp/org.el
15
lisp/org.el
|
@ -8495,13 +8495,20 @@ a link."
|
||||||
(org-attach-reveal-in-emacs)
|
(org-attach-reveal-in-emacs)
|
||||||
(org-attach-reveal))))
|
(org-attach-reveal))))
|
||||||
(`(,links . ,links-end)
|
(`(,links . ,links-end)
|
||||||
|
(let ((link-marker (make-marker))
|
||||||
|
(last-moved-marker (point-marker)))
|
||||||
(dolist (link (if (stringp links) (list links) links))
|
(dolist (link (if (stringp links) (list links) links))
|
||||||
(search-forward link nil links-end)
|
(search-forward link nil links-end)
|
||||||
(goto-char (match-beginning 0))
|
(goto-char (match-beginning 0))
|
||||||
;; When opening file link, current buffer may be
|
(move-marker link-marker (point))
|
||||||
;; altered.
|
(save-excursion
|
||||||
(save-current-buffer
|
(org-open-at-point arg)
|
||||||
(org-open-at-point arg))))))))
|
(unless (equal (point-marker) link-marker)
|
||||||
|
(move-marker last-moved-marker (point-marker)))))
|
||||||
|
;; If any of the links moved point in current buffer,
|
||||||
|
;; move to the point corresponding to such latest link.
|
||||||
|
;; Otherwise, restore the original point position.
|
||||||
|
(goto-char last-moved-marker)))))))
|
||||||
;; On a footnote reference or at definition's label.
|
;; On a footnote reference or at definition's label.
|
||||||
((or (eq type 'footnote-reference)
|
((or (eq type 'footnote-reference)
|
||||||
(and (eq type 'footnote-definition)
|
(and (eq type 'footnote-definition)
|
||||||
|
|
Loading…
Reference in New Issue