summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2023-05-07 11:49:20 -0700
committerSean Whitton <spwhitton@spwhitton.name>2023-05-07 11:49:27 -0700
commita3e49609743895d3f9fe443ba183aabbe9afa8d9 (patch)
tree12be36f052203bdbabc50c4f3299e38b9da83757
parent6509f55c3f84e81e04455e3f65aafcbd5132e2ec (diff)
downloaddotfiles-a3e49609743895d3f9fe443ba183aabbe9afa8d9.tar.gz
refactor spw/icomplete-tab
No functional change.
-rw-r--r--.emacs.d/init.el40
1 files changed, 20 insertions, 20 deletions
diff --git a/.emacs.d/init.el b/.emacs.d/init.el
index 296b0e30..0ad77a61 100644
--- a/.emacs.d/init.el
+++ b/.emacs.d/init.el
@@ -1231,31 +1231,31 @@ To be used only when it seems to be necessary."
(defun spw/icomplete-tab ()
(interactive)
(when-let* ((current (car completion-all-sorted-completions)))
- ;; For in-buffer completion it should always be fine to just call
- ;; `icomplete-force-complete', and not exit, because of how in-buffer
- ;; completion uses a transient map (an alternative would be to guess
- ;; whether completing a file name, e.g. (string-suffix-p "/" current)) ...
- (if (or (not (window-minibuffer-p))
- (and (spw/minibuffer-completing-file-name-p)
- (let ((dir (file-name-directory (minibuffer-contents))))
- (file-directory-p
- (if dir (expand-file-name (directory-file-name current)
+ (if (and (window-minibuffer-p)
+ (not (and (spw/minibuffer-completing-file-name-p)
+ (file-directory-p
+ (if-let ((dir (file-name-directory
+ (minibuffer-contents))))
+ (expand-file-name (directory-file-name current)
(substitute-env-vars dir))
- current)))))
- (progn
- (icomplete-force-complete)
- (unless (window-minibuffer-p)
- ;; ... but if there is now only one candidate remaining, then it's
- ;; the one we just selected, so do exit completion.
- (letrec ((buf (current-buffer))
- (fun
- (lambda ()
+ current)))))
+ (icomplete-force-complete-and-exit)
+ ;; For in-buffer completion it should always be fine to just call
+ ;; `icomplete-force-complete', and not exit, because of how in-buffer
+ ;; completion uses a transient map (an alternative would be to guess
+ ;; whether completing a file name, e.g. (string-suffix-p "/" current)).
+ ;; However, if after calling `icomplete-force-complete' there is now
+ ;; only one candidate remaining then it's the one we just selected, so
+ ;; do exit completion.
+ (icomplete-force-complete)
+ (unless (window-minibuffer-p)
+ (letrec ((buf (current-buffer))
+ (fun (lambda ()
(advice-remove 'icomplete-post-command-hook fun)
(with-current-buffer buf
(when (atom (cdr completion-all-sorted-completions))
(completion-in-region-mode -1))))))
- (advice-add 'icomplete-post-command-hook :after fun))))
- (icomplete-force-complete-and-exit))))
+ (advice-add 'icomplete-post-command-hook :after fun))))))
(define-key icomplete-minibuffer-map [?\t] #'spw/icomplete-tab)
(define-key icomplete-minibuffer-map [remap minibuffer-complete-and-exit] nil)