um-tag-insert-dwim understands dired
This commit is contained in:
parent
f4699477c8
commit
4ecc2eee5e
1 changed files with 24 additions and 14 deletions
24
elisp/um.el
24
elisp/um.el
|
|
@ -186,25 +186,35 @@ NOTE: this searches in the current project root only.
|
||||||
)
|
)
|
||||||
|
|
||||||
(defun um-tag-insert-dwim (tag)
|
(defun um-tag-insert-dwim (tag)
|
||||||
"Run `um-tag-insert' on the filename at point, or a list of filenames if
|
"Run `um-tag-insert' on a list of filenames if region active outside
|
||||||
region active or if marks exist in dired-mode.
|
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-journal-path'.
|
Assumes the files of interest are returned by `um-journal-path'.
|
||||||
"
|
"
|
||||||
;; TODO: should this be completing-read? Would like a history ring.
|
;; TODO: should this be completing-read? Would like a history ring.
|
||||||
(interactive "Mtag: ")
|
(interactive "Mtag: ")
|
||||||
(let ((files (if (region-active-p)
|
(let* (
|
||||||
(string-split (buffer-substring (region-beginning) (region-end)))
|
(marks (dired-get-marked-files))
|
||||||
(list (thing-at-point 'filename))))
|
;; NOTE: existing-filename to avoid returning bogus strings:
|
||||||
|
(fap (thing-at-point 'existing-filename))
|
||||||
|
(files (cond
|
||||||
|
((and (region-active-p) (not (eq major-mode 'dired-mode)))
|
||||||
|
(string-split (buffer-substring (region-beginning) (region-end))))
|
||||||
|
((and (eq major-mode 'dired-mode) marks) marks)
|
||||||
|
(fap (list fap))
|
||||||
|
))
|
||||||
;; save-excursion is not working below, why?
|
;; save-excursion is not working below, why?
|
||||||
(buf (current-buffer)))
|
(buf (current-buffer)))
|
||||||
(dolist (f files)
|
|
||||||
|
(if files (progn (dolist (f files)
|
||||||
(find-file (expand-file-name f (um-journal-path)))
|
(find-file (expand-file-name f (um-journal-path)))
|
||||||
(um-tag-insert tag)
|
(um-tag-insert tag)
|
||||||
)
|
)
|
||||||
(switch-to-buffer buf)
|
(switch-to-buffer buf)
|
||||||
(save-some-buffers t)
|
(save-some-buffers t)
|
||||||
))
|
)
|
||||||
|
(um-tag-insert tag))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; shell integration
|
;; shell integration
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue