Skip to content

Commit

Permalink
(fix){preview,grep}-visit: always navigate to the source of the preview
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Wetlize committed Aug 17, 2021
1 parent b8a66de commit b627298
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions org-roam-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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."
Expand Down Expand Up @@ -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."
Expand All @@ -605,15 +607,16 @@ 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))
(when row
(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
Expand Down

0 comments on commit b627298

Please sign in to comment.