From b6272981710f319320d9a749b2414d3b3b0d21bc Mon Sep 17 00:00:00 2001 From: Wetlize Date: Wed, 18 Aug 2021 00:39:42 +0300 Subject: [PATCH] (fix){preview,grep}-visit: always navigate to the source of the preview Previously when the preview and buffer would be opened, it would just display the buffer at the last visited position without performing any repositiong. To enforce the correct behavior, the point should be always moved after the buffer is visited, and not before. --- org-roam-mode.el | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/org-roam-mode.el b/org-roam-mode.el index 0534f6d..c1a3910 100644 --- a/org-roam-mode.el +++ b/org-roam-mode.el @@ -379,7 +379,8 @@ the same time: The preview content comes from FILE, and the link as at POINT.") (defun org-roam-preview-visit (file point &optional other-window) - "Visit FILE at POINT. With OTHER-WINDOW non-nil do so in another window. + "Visit FILE at POINT and return the visited buffer. +With OTHER-WINDOW non-nil do so in another window. In interactive calls OTHER-WINDOW is set with `universal-argument'." (interactive (list (org-roam-buffer-file-at-point 'assert) @@ -389,11 +390,12 @@ In interactive calls OTHER-WINDOW is set with (display-buffer-fn (if other-window #'switch-to-buffer-other-window #'pop-to-buffer-same-window))) + (funcall display-buffer-fn buf) (with-current-buffer buf (widen) (goto-char point)) - (funcall display-buffer-fn buf) - (when (org-invisible-p) (org-show-context)))) + (when (org-invisible-p) (org-show-context)) + buf)) (defun org-roam-preview-get-contents (file point) "Get preview content for FILE at POINT." @@ -593,7 +595,7 @@ Sorts by title." "A `magit-section' used by `org-roam-mode' to contain grep output.") (defun org-roam-grep-visit (file &optional other-window row col) - "Visits FILE. If ROW, move to the row, and if COL move to the COL. + "Visit FILE at row ROW (if any) and column COL (if any). Return the buffer. With OTHER-WINDOW non-nil (in interactive calls set with `universal-argument') display the buffer in another window instead." @@ -605,6 +607,7 @@ instead." (display-buffer-fn (if other-window #'switch-to-buffer-other-window #'pop-to-buffer-same-window))) + (funcall display-buffer-fn buf) (with-current-buffer buf (widen) (goto-char (point-min)) @@ -612,8 +615,8 @@ instead." (forward-line (1- row))) (when col (forward-char (1- col)))) - (funcall display-buffer-fn buf) - (when (org-invisible-p) (org-show-context)))) + (when (org-invisible-p) (org-show-context)) + buf)) ;;;; Unlinked references (defvar org-roam-unlinked-references-result-re