From 5819cd5babe56ea9a2ab05d8925f4ca6f9dc45c9 Mon Sep 17 00:00:00 2001 From: bth Date: Thu, 25 Dec 2025 17:53:05 -0800 Subject: [PATCH] um-tag-insert-dwim : negative prefix arg means delete --- elisp/um.el | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/elisp/um.el b/elisp/um.el index ae994d8..08c313a 100644 --- a/elisp/um.el +++ b/elisp/um.el @@ -189,15 +189,33 @@ Ultimately this relies on `xref-matches-in-files', which calls `xref-search-prog (insert (concat "+ " tag "\n")) ) +(defun um-tag-delete (tag) + "Delete TAG from the journal header in current buffer." + (goto-char (point-min)) + (search-forward (concat "+ " tag "\n")) + (previous-line) + (kill-line) + ) + +(defun um-tag-do (tag insert) + "Insert or delete TAG from the journal header in current buffer. + +insert when INSERT > 0, delete otherwise." + (if (> insert 0) + (um-tag-insert tag) + (um-tag-delete tag))) + ;;;###autoload -(defun um-tag-insert-dwim () - "Run `um-tag-insert' on a list of filenames if region active outside +(defun um-tag-insert-dwim (ARG) + "Run `um-tag-do' on a list of filenames if region active outside dired-mode, or if marks exist in dired-mode, or the filename at point, and finally in the current buffer if none of those conditions match. Assumes the files of interest are returned by `um-root-path'. + +Negative prefix arg is handled by `um-tag-do', which see. " - (interactive) + (interactive "p") (let* ( (tag (completing-read "insert um tag: " um-tags-history nil nil nil 'um-tags-history)) (marks (if (eq major-mode 'dired-mode) (dired-get-marked-files) nil)) @@ -216,12 +234,12 @@ Assumes the files of interest are returned by `um-root-path'. (if files (progn (dolist (f files) ;; TODO: this should use the fallback logic: (find-file (expand-file-name f (um-root-path))) - (um-tag-insert tag) + (um-tag-do tag ARG) ) (switch-to-buffer buf) (save-some-buffers t) ) - (um-tag-insert tag)) + (um-tag-do tag ARG)) (let ((history-delete-duplicates t)) (add-to-history 'um-tags-history tag))))