From ebd3b0223ed340855a489d81da070536e369735f Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 24 Jul 2018 20:01:42 +0200 Subject: [PATCH] Fix followed org links not recentering correctly Links like `file:test.cpp::45` would open file.cpp, but end up somewhere else than line 45. Same with links like `file:test.cpp::int main()`. --- modules/lang/org/autoload/org.el | 6 ++---- modules/lang/org/config.el | 6 ++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/lang/org/autoload/org.el b/modules/lang/org/autoload/org.el index 4859fb687..c4a22eec9 100644 --- a/modules/lang/org/autoload/org.el +++ b/modules/lang/org/autoload/org.el @@ -60,8 +60,7 @@ If on a: - link: follow it - otherwise, refresh all inline images in current tree." (interactive) - (let* ((scroll-pt (window-start)) - (context (org-element-context)) + (let* ((context (org-element-context)) (type (org-element-type context))) ;; skip over unimportant contexts (while (and context (memq type '(verbatim code bold italic underline strike-through subscript superscript))) @@ -127,8 +126,7 @@ If on a: (+org/refresh-inline-images) (org-open-at-point)))) - (_ (+org/refresh-inline-images))) - (set-window-start nil scroll-pt))) + (_ (+org/refresh-inline-images))))) ;;;###autoload (defun +org/insert-item (direction) diff --git a/modules/lang/org/config.el b/modules/lang/org/config.el index bee1bd342..d9b884fe1 100644 --- a/modules/lang/org/config.el +++ b/modules/lang/org/config.el @@ -347,6 +347,12 @@ between the two." ;; Don't open separate windows (setf (alist-get 'file org-link-frame-setup) #'find-file) + (defun +org|delayed-recenter () + "`recenter', but after a tiny delay. Necessary to prevent certain race +conditions where a window's buffer hasn't changed at the time this hook is run." + (run-at-time 0.1 nil #'recenter)) + (add-hook 'org-follow-link-hook #'+org|delayed-recenter) + ;; Fix variable height org-level-N faces in the eldoc string (defun +org*fix-font-size-variation-in-eldoc (orig-fn) (cl-letf (((symbol-function 'org-format-outline-path)