mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
(fix)buffer: change preview-content logic (#1955)
Some commit in Org 9.5 changed the AST structure, so we our previous preview content logic was borked and started showing the full contents of the file. To be forward compatible we change the content preview logic, and extract everything within the section. Fixes #1934.
This commit is contained in:
@ -397,23 +397,17 @@ In interactive calls OTHER-WINDOW is set with
|
||||
(when (org-invisible-p) (org-show-context))
|
||||
buf))
|
||||
|
||||
(defun org-roam-preview-get-contents (file point)
|
||||
"Get preview content for FILE at POINT."
|
||||
(defun org-roam-preview-get-contents (file pt)
|
||||
"Get preview content for FILE at PT."
|
||||
(save-excursion
|
||||
(org-roam-with-temp-buffer file
|
||||
(goto-char point)
|
||||
(let ((elem (org-element-at-point)))
|
||||
;; We want the parent element always
|
||||
(while (org-element-property :parent elem)
|
||||
(setq elem (org-element-property :parent elem)))
|
||||
(pcase (car elem)
|
||||
('headline ; show subtree
|
||||
(org-roam-preview-get-entry-text (point-marker) most-positive-fixnum))
|
||||
(_
|
||||
(let ((begin (org-element-property :begin elem))
|
||||
(end (org-element-property :end elem)))
|
||||
(or (string-trim (buffer-substring-no-properties begin end))
|
||||
(org-element-property :raw-value elem)))))))))
|
||||
(org-with-wide-buffer
|
||||
(goto-char pt)
|
||||
(let ((beg (progn (org-roam-end-of-meta-data t)
|
||||
(point)))
|
||||
(end (progn (org-next-visible-heading 1)
|
||||
(point))))
|
||||
(string-trim (buffer-substring-no-properties beg end)))))))
|
||||
|
||||
(defun org-roam-preview-get-entry-text (marker n-lines &optional indent)
|
||||
"Extract entry text from MARKER, at most N-LINES lines.
|
||||
|
@ -243,12 +243,13 @@ If BOUND, scan up to BOUND bytes of the buffer."
|
||||
(defun org-roam-end-of-meta-data (&optional full)
|
||||
"Like `org-end-of-meta-data', but supports file-level metadata.
|
||||
|
||||
When optional argument FULL is t, also skip planning information,
|
||||
clocking lines and any kind of drawer.
|
||||
|
||||
When FULL is non-nil but not t, skip planning information,
|
||||
properties, clocking lines and logbook drawers."
|
||||
properties, clocking lines and logbook drawers.
|
||||
|
||||
When optional argument FULL is t, skip everything above, and also
|
||||
skip keywords."
|
||||
(org-back-to-heading-or-point-min t)
|
||||
(when (org-at-heading-p) (forward-line))
|
||||
;; Skip planning information.
|
||||
(when (looking-at-p org-planning-line-re) (forward-line))
|
||||
;; Skip property drawer.
|
||||
@ -268,11 +269,14 @@ properties, clocking lines and logbook drawers."
|
||||
(if (re-search-forward "^[ \t]*:END:[ \t]*$" end t)
|
||||
(forward-line)
|
||||
(throw 'exit t)))
|
||||
;; When FULL is t, skip regular drawer too.
|
||||
((and (eq full t) (looking-at-p org-drawer-regexp))
|
||||
((looking-at-p org-drawer-regexp)
|
||||
(if (re-search-forward "^[ \t]*:END:[ \t]*$" end t)
|
||||
(forward-line)
|
||||
(throw 'exit t)))
|
||||
;; When FULL is t, skip keywords too.
|
||||
((and (eq full t)
|
||||
(looking-at-p org-keyword-regexp))
|
||||
(forward-line))
|
||||
(t (throw 'exit t))))))))
|
||||
|
||||
(defun org-roam-set-keyword (key value)
|
||||
@ -284,7 +288,7 @@ If the property is already set, it's value is replaced."
|
||||
(if (string-blank-p value)
|
||||
(kill-whole-line)
|
||||
(replace-match (concat " " value) 'fixedcase nil nil 1))
|
||||
(org-roam-end-of-meta-data)
|
||||
(org-roam-end-of-meta-data 'drawers)
|
||||
(if (save-excursion (end-of-line) (eobp))
|
||||
(progn
|
||||
(end-of-line)
|
||||
|
Reference in New Issue
Block a user