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

19
um.el
View file

@ -277,8 +277,9 @@ Ultimately this relies on `xref-matches-in-files', which calls
(defun um--extract-tags (files)
(let ((tags))
(dolist (f files)
(with-temp-buffer
(find-file f)
(with-current-buffer
(find-file-noselect f t)
(save-excursion
(goto-char (point-min))
(let* ((bound (save-excursion (search-forward "\n\n")))
(found t))
@ -286,7 +287,7 @@ Ultimately this relies on `xref-matches-in-files', which calls
(setq found (search-forward-regexp um-tag-regexp bound t))
(when found (add-to-list 'tags (buffer-substring-no-properties
(match-beginning 1) (match-end 1))))
))))
)))))
(reverse tags)))
(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))
(vertico-sort-function (if insert vertico-sort-function nil))
(tag (completing-read prompt collection nil nil nil
'um-tags-history))
;; TODO: save-excursion is not working around the dolist. why?
(buf (current-buffer)))
'um-tags-history)))
(dolist (f files)
(save-excursion
(with-current-buffer
;; 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)
(save-excursion
(um-tag-do tag ARG)
(save-buffer)))
(switch-to-buffer buf)
(save-buffer))))
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;