summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-10-08 09:00:27 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-10-14 10:38:02 -0700
commitf9935a910c26e6f30f058b55a7ca02b29ac4f970 (patch)
tree78556521c39643c8bc392037ef3d8cf54cb8ba6a
parent9a35c0d52634851d34ca08d83a97b1aba20f7596 (diff)
downloaddotfiles-f9935a910c26e6f30f058b55a7ca02b29ac4f970.tar.gz
try out a different unix-word-rubout when completing filenames
-rw-r--r--.emacs.d/init.el29
1 files changed, 25 insertions, 4 deletions
diff --git a/.emacs.d/init.el b/.emacs.d/init.el
index a463a66c..479858d0 100644
--- a/.emacs.d/init.el
+++ b/.emacs.d/init.el
@@ -833,14 +833,17 @@ to open them using `spw/try-external-open'")
;; and moreover, kill back to whitespace is often what's wanted, for
;; correcting typos and just for deletion, e.g. of whole e-mail addresses,
;; whole long form command line arguments in Eshell, etc.
-(defun spw/unix-word-rubout (arg)
+(defun spw/unix-word-rubout (arg &optional pos neg)
(interactive "p")
+ ;; Do skip over \n because `backward-kill-word' does.
+ (unless pos (setq pos "[:space:]\n"))
+ (unless neg (setq neg "^[:space:]\n"))
(undo-boundary)
(let ((start (point)))
- ;; Do skip over \n because `backward-kill-word' does. Go only backwards.
+ ;; Go only backwards.
(dotimes (_ (abs arg))
- (skip-chars-backward "[:space:]\n")
- (skip-chars-backward "^[:space:]\n"))
+ (skip-chars-backward pos)
+ (skip-chars-backward neg))
;; Skip forward over any read-only text (e.g. an Eshell or comint prompt).
(when-let ((beg (and (get-char-property (point) 'read-only)
(next-single-char-property-change
@@ -1118,6 +1121,24 @@ to open them using `spw/try-external-open'")
(call-interactively #'icomplete-fido-ret))))
(define-key icomplete-fido-mode-map [?\r] #'icomplete-fido-exit)
+(defun spw/icomplete-choose-rubout ()
+ ;; See `icomplete--category'.
+ (when (eq (completion-metadata-get
+ (completion-metadata
+ (buffer-substring-no-properties (minibuffer-prompt-end) (point))
+ minibuffer-completion-table
+ minibuffer-completion-predicate)
+ 'category)
+ 'file)
+ (let ((map (make-sparse-keymap)))
+ (define-key
+ map "\C-w"
+ (lambda (arg)
+ (interactive "p")
+ (spw/unix-word-rubout arg "/:[:space:]\n" "^/:[:space:]\n")))
+ (use-local-map (make-composed-keymap map (current-local-map))))))
+(add-hook 'icomplete-minibuffer-setup-hook #'spw/icomplete-choose-rubout)
+
;; Default binding for this function, M-TAB, may not be available to Emacs
;; as it is commonly used by window managers etc., and this is very useful
;; when renaming files. Also, when typing a path to a remote file on a host