diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2022-10-14 19:21:15 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2022-10-18 12:40:47 -0700 |
commit | cd4563a9e62842e7a8f657fbf2577a731f8d49df (patch) | |
tree | 385484d859d97365b83856762c296c56c45af287 | |
parent | 2fc7c5d2b9a78ff9dc03cc9131a362bc77028f05 (diff) | |
download | dotfiles-cd4563a9e62842e7a8f657fbf2577a731f8d49df.tar.gz |
add spw/dired-copy-filename-as-kill
-rw-r--r-- | .emacs.d/init.el | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 89c982ca..fb31801b 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -1690,7 +1690,8 @@ The ideas behind these behaviours are as follows. C-x p e." (interactive "P") (require 'eshell) - (let* ((default-directory (or (and (eq major-mode 'dired-mode) + (let* ((default-directory (or (and (not (eq chdir 'strict)) + (eq major-mode 'dired-mode) (dired-current-directory)) default-directory)) (current-project (and (not (file-remote-p default-directory)) @@ -2734,6 +2735,36 @@ mutt's review view, after exiting EDITOR." ;; go ahead and advise `read-only-mode' (require 'git-annex)) +(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))) +(spw/feature-define-keys dired + "!" #'spw/dired-copy-filename-as-kill + "&" #'spw/dired-copy-filename-as-kill) + ;;;; EWW |