Fix: (org-ql-find--snippet-*) Use save-excursion

This commit is contained in:
Adam Porter 2022-08-15 16:16:55 -05:00
parent 06f1e1be6f
commit 6257ae8304

View file

@ -232,29 +232,31 @@ single predicate)."
(defun org-ql-find--snippet-simple (&optional _regexp) (defun org-ql-find--snippet-simple (&optional _regexp)
"Return a snippet of the current entry. "Return a snippet of the current entry.
Returns up to `org-ql-find-snippet-length' characters." Returns up to `org-ql-find-snippet-length' characters."
(org-end-of-meta-data t) (save-excursion
(unless (org-at-heading-p) (org-end-of-meta-data t)
(let ((end (min (+ (point) org-ql-find-snippet-length) (unless (org-at-heading-p)
(org-entry-end-position)))) (let ((end (min (+ (point) org-ql-find-snippet-length)
(concat org-ql-find-snippet-prefix (org-entry-end-position))))
(truncate-string-to-width (concat org-ql-find-snippet-prefix
(replace-regexp-in-string "\n" " " (buffer-substring (point) end) (truncate-string-to-width
t t) (replace-regexp-in-string "\n" " " (buffer-substring (point) end)
50 nil nil t))))) t t)
50 nil nil t))))))
(defun org-ql-find--snippet-regexp (regexp) (defun org-ql-find--snippet-regexp (regexp)
"Return a snippet of the current entry's matches for REGEXP." "Return a snippet of the current entry's matches for REGEXP."
;; REGEXP may be nil if there are no qualifying tokens in the query. ;; REGEXP may be nil if there are no qualifying tokens in the query.
(when regexp (when regexp
(org-end-of-meta-data t) (save-excursion
(unless (org-at-heading-p) (org-end-of-meta-data t)
(let* ((end (org-entry-end-position)) (unless (org-at-heading-p)
(snippets (cl-loop while (re-search-forward regexp end t) (let* ((end (org-entry-end-position))
concat (match-string 0) concat "" (snippets (cl-loop while (re-search-forward regexp end t)
do (goto-char (match-end 0))))) concat (match-string 0) concat ""
(unless (string-empty-p snippets) do (goto-char (match-end 0)))))
(concat org-ql-find-snippet-prefix (unless (string-empty-p snippets)
(replace-regexp-in-string (rx (1+ "\n")) " " snippets t t))))))) (concat org-ql-find-snippet-prefix
(replace-regexp-in-string (rx (1+ "\n")) " " snippets t t))))))))
(provide 'org-ql-find) (provide 'org-ql-find)