(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.
This commit is contained in:
Wetlize
2021-08-18 00:39:42 +03:00
parent b8a66deae9
commit b627298171

View File

@@ -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