um--extract-tags : save-excursion and find-file-noselect to fix moving point and window

This commit is contained in:
bth 2026-06-04 16:25:51 -07:00
commit 508e55468e

37
um.el
View file

@ -277,16 +277,17 @@ Ultimately this relies on `xref-matches-in-files', which calls
(defun um--extract-tags (files) (defun um--extract-tags (files)
(let ((tags)) (let ((tags))
(dolist (f files) (dolist (f files)
(with-temp-buffer (with-current-buffer
(find-file f) (find-file-noselect f t)
(goto-char (point-min)) (save-excursion
(let* ((bound (save-excursion (search-forward "\n\n"))) (goto-char (point-min))
(found t)) (let* ((bound (save-excursion (search-forward "\n\n")))
(while found (found t))
(setq found (search-forward-regexp um-tag-regexp bound t)) (while found
(when found (add-to-list 'tags (buffer-substring-no-properties (setq found (search-forward-regexp um-tag-regexp bound t))
(match-beginning 1) (match-end 1)))) (when found (add-to-list 'tags (buffer-substring-no-properties
)))) (match-beginning 1) (match-end 1))))
)))))
(reverse tags))) (reverse tags)))
(defun um-tag-insert (tag) (defun um-tag-insert (tag)
@ -344,17 +345,15 @@ Negative prefix arg is handled by `um-tag-do', which see.
(completions-sort (if insert completions-sort nil)) (completions-sort (if insert completions-sort nil))
(vertico-sort-function (if insert vertico-sort-function nil)) (vertico-sort-function (if insert vertico-sort-function nil))
(tag (completing-read prompt collection nil nil nil (tag (completing-read prompt collection nil nil nil
'um-tags-history)) 'um-tags-history)))
;; TODO: save-excursion is not working around the dolist. why?
(buf (current-buffer)))
(dolist (f files) (dolist (f files)
(save-excursion (with-current-buffer
;; TODO: this should use the fallback logic: ;; TODO: this should use the fallback logic:
(find-file (expand-file-name f (um-root-path))) (find-file-noselect (expand-file-name f (um-root-path)) t)
(um-tag-do tag ARG) (save-excursion
(save-buffer))) (um-tag-do tag ARG)
(switch-to-buffer buf) (save-buffer))))
)) ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;