summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-10-31 09:28:14 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-10-31 09:47:57 -0700
commit07ef01648a38d3a7074e6597c44ce32ab67efb5c (patch)
tree63e0e7abf7ed4ab42aa29d1f9a5231dee2eab1ce
parent9291e4bf702dd086172f8e010dac00ab3f370c82 (diff)
downloaddotfiles-07ef01648a38d3a7074e6597c44ce32ab67efb5c.tar.gz
spw/dired-copy-filename-as-kill: several improvements
- Quote even when just one file. - Don't behave like M-& when invoked from subdirectory header line. - Tweak comments.
-rw-r--r--.emacs.d/init.el60
1 files changed, 36 insertions, 24 deletions
diff --git a/.emacs.d/init.el b/.emacs.d/init.el
index 8f6f25e0..0d4ddeae 100644
--- a/.emacs.d/init.el
+++ b/.emacs.d/init.el
@@ -2798,30 +2798,42 @@ mutt's review view, after exiting EDITOR."
(defun spw/dired-copy-filename-as-kill (&optional arg)
(interactive "P")
- ;; Invoking with '!', and no prefix argument, is a shortcut for copying
- ;; absolute paths, and behaving like 'M-!' rather than like 'M-&'.
- ;;
- ;; As we pass the prefix argument on to `dired-copy-filename-as-kill', there
- ;; isn't a way to pass a prefix argument to 'M-&' (it wouldn't make sense to
- ;; pass a prefix argument to 'M-!'). One can use, e.g., C-u M-& C-x o &.
- (if (and (not arg) (char-equal last-command-event ?!))
- (dired-copy-filename-as-kill 0)
- (call-interactively #'dired-copy-filename-as-kill))
- ;; Here we try to do something sensible based on what the prefix argument
- ;; means to `dired-copy-filename-as-kill'.
- (cond ((if arg
- (zerop (prefix-numeric-value arg))
- (char-equal last-command-event ?!))
- (spw/eshell-jump))
- ((consp arg)
- (spw/eshell-jump nil 'strict))
- (t
- (spw/eshell-jump nil t)))
- (if (= (point) eshell-last-output-end)
- (save-excursion (insert ?\s) (yank) (insert ?\s))
- (just-one-space)
- (yank)
- (just-one-space)))
+ (let* ((subdir (dired-get-subdir))
+ (files
+ ;; We treat as primary the meanings of the prefix argument to
+ ;; `dired-copy-filename-as-kill', then try to call `spw/eshell-jump'
+ ;; in a way that corresponds. Thus, there isn't a way to express a
+ ;; prefix argument to 'M-&', but one can use, e.g., C-u M-& C-x o &.
+ ;; (It wouldn't make sense to pass a prefix argument to 'M-!').
+ ;;
+ ;; Invoking with '!', and no prefix argument, is a shortcut for
+ ;; copying absolute paths, and behaving more like 'M-!' than 'M-&'.
+ (cond (subdir
+ (prog1 (ensure-list subdir) (spw/eshell-jump)))
+ ((if arg
+ (zerop (prefix-numeric-value arg))
+ (char-equal last-command-event ?!))
+ (prog1 (dired-get-marked-files) (spw/eshell-jump)))
+ ((consp arg)
+ (prog1 (dired-get-marked-files t)
+ (spw/eshell-jump nil 'strict)))
+ (t
+ (prog1 (dired-get-marked-files
+ 'no-dir (and arg (prefix-numeric-value arg)))
+ (spw/eshell-jump nil t)))))
+ (string
+ (mapconcat (lambda (file)
+ (if (string-match-p "[ \"']" file)
+ (format "%S" file)
+ file))
+ files
+ " ")))
+ (unless (string-empty-p string)
+ (if (= (point) eshell-last-output-end)
+ (save-excursion (insert ?\s string ?\s))
+ (just-one-space)
+ (insert string)
+ (just-one-space)))))
(spw/feature-define-keys dired
"!" #'spw/dired-copy-filename-as-kill
"&" #'spw/dired-copy-filename-as-kill)