um-tag-dwim : um--extract-tags for delete case gives a nice list in order
This commit is contained in:
parent
278f673924
commit
1129b8d419
1 changed files with 34 additions and 10 deletions
38
um.el
38
um.el
|
|
@ -274,6 +274,21 @@ 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)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(let* ((bound (save-excursion (search-forward "\n\n")))
|
||||||
|
(found t))
|
||||||
|
(while found
|
||||||
|
(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)
|
(defun um-tag-insert (tag)
|
||||||
"Insert TAG as + tag\n in current buffer appending to the journal header."
|
"Insert TAG as + tag\n in current buffer appending to the journal header."
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
|
|
@ -310,8 +325,8 @@ Negative prefix arg is handled by `um-tag-do', which see.
|
||||||
"
|
"
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(let* (
|
(let* (
|
||||||
(prompt (format "um tag %s: " (if (> ARG 0) "insert" "delete")))
|
(insert (> ARG 0))
|
||||||
(tag (completing-read prompt um-tags-history nil nil nil 'um-tags-history))
|
(prompt (format "um tag %s: " (if insert "insert" "delete")))
|
||||||
(marks (if (eq major-mode 'dired-mode) (dired-get-marked-files) nil))
|
(marks (if (eq major-mode 'dired-mode) (dired-get-marked-files) nil))
|
||||||
;; NOTE: should avoid bogus strings when in a markdown buffer:
|
;; NOTE: should avoid bogus strings when in a markdown buffer:
|
||||||
(fap (um-find-file-at-point))
|
(fap (um-find-file-at-point))
|
||||||
|
|
@ -320,17 +335,26 @@ Negative prefix arg is handled by `um-tag-do', which see.
|
||||||
(string-split (buffer-substring (region-beginning) (region-end))))
|
(string-split (buffer-substring (region-beginning) (region-end))))
|
||||||
(marks marks)
|
(marks marks)
|
||||||
(fap (list fap))
|
(fap (list fap))
|
||||||
|
(t (list (buffer-file-name)))
|
||||||
))
|
))
|
||||||
;; save-excursion is not working below, why?
|
(collection (if insert um-tags-history (um--extract-tags files)))
|
||||||
|
;; no need for dupes:
|
||||||
|
(history-delete-duplicates t)
|
||||||
|
;; override sorting when deleting, because we sort the tags:
|
||||||
|
(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)))
|
(buf (current-buffer)))
|
||||||
|
|
||||||
(if files (progn (dolist (f files)
|
(dolist (f files)
|
||||||
|
(save-excursion
|
||||||
;; 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 (expand-file-name f (um-root-path)))
|
||||||
(um-tag-do tag ARG)
|
(um-tag-do tag ARG)
|
||||||
(save-buffer))
|
(save-buffer)))
|
||||||
(switch-to-buffer buf))
|
(switch-to-buffer buf)
|
||||||
(save-excursion (um-tag-do tag ARG) (save-buffer)))
|
|
||||||
))
|
))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue