Slightly simplify lisp/icomplete.el with new icomplete--category helper
* lisp/icomplete.el (icomplete-fido-kill) (icomplete-fido-delete-char, icomplete-fido-ret) (icomplete-fido-backward-updir, icomplete-exhibit): Use icomplete--category. (icomplete--category): New helper.
This commit is contained in:
parent
9c91204992
commit
24a1f520f9
1 changed files with 15 additions and 24 deletions
|
@ -234,15 +234,13 @@ completed. If completing files, it means delete the file. If
|
|||
completing buffers it means kill the buffer. Both actions
|
||||
require user confirmation."
|
||||
(interactive)
|
||||
(let ((beg (icomplete--field-beg)) (end (icomplete--field-end)))
|
||||
(let ((end (icomplete--field-end)))
|
||||
(if (< (point) end)
|
||||
(call-interactively 'kill-line)
|
||||
(let* ((md (completion--field-metadata beg))
|
||||
(category (alist-get 'category (cdr md)))
|
||||
(all (completion-all-sorted-completions))
|
||||
(let* ((all (completion-all-sorted-completions))
|
||||
(thing (car all))
|
||||
(action
|
||||
(pcase category
|
||||
(pcase (icomplete--category)
|
||||
(`buffer
|
||||
(lambda ()
|
||||
(when (yes-or-no-p (concat "Kill buffer " thing "? "))
|
||||
|
@ -267,11 +265,8 @@ require user confirmation."
|
|||
(defun icomplete-fido-delete-char ()
|
||||
"Delete char or maybe call `dired', like `ido-mode'."
|
||||
(interactive)
|
||||
(let* ((beg (icomplete--field-beg))
|
||||
(end (icomplete--field-end))
|
||||
(md (completion--field-metadata beg))
|
||||
(category (alist-get 'category (cdr md))))
|
||||
(if (or (< (point) end) (not (eq category 'file)))
|
||||
(let ((end (icomplete--field-end)))
|
||||
(if (or (< (point) end) (not (eq (icomplete--category) 'file)))
|
||||
(call-interactively 'delete-char)
|
||||
(dired (file-name-directory (icomplete--field-string)))
|
||||
(exit-minibuffer))))
|
||||
|
@ -279,10 +274,7 @@ require user confirmation."
|
|||
(defun icomplete-fido-ret ()
|
||||
"Exit minibuffer or enter directory, like `ido-mode'."
|
||||
(interactive)
|
||||
(let* ((beg (icomplete--field-beg))
|
||||
(md (completion--field-metadata beg))
|
||||
(category (alist-get 'category (cdr md)))
|
||||
(dir (and (eq category 'file)
|
||||
(let* ((dir (and (eq (icomplete--category) 'file)
|
||||
(file-name-directory (icomplete--field-string))))
|
||||
(current (car (completion-all-sorted-completions)))
|
||||
(probe (and dir current
|
||||
|
@ -297,12 +289,10 @@ require user confirmation."
|
|||
(defun icomplete-fido-backward-updir ()
|
||||
"Delete char before or go up directory, like `ido-mode'."
|
||||
(interactive)
|
||||
(let* ((beg (icomplete--field-beg))
|
||||
(md (completion--field-metadata beg))
|
||||
(category (alist-get 'category (cdr md))))
|
||||
(if (and (eq (char-before) ?/) (eq category 'file))
|
||||
(backward-kill-sexp 1)
|
||||
(call-interactively 'backward-delete-char))))
|
||||
(if (and (eq (char-before) ?/)
|
||||
(eq (icomplete--category) 'file))
|
||||
(backward-kill-sexp 1)
|
||||
(call-interactively 'backward-delete-char)))
|
||||
|
||||
(defvar icomplete-fido-mode-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
|
@ -392,6 +382,10 @@ completions:
|
|||
(defun icomplete--field-end ()
|
||||
(if (window-minibuffer-p) (point-max)
|
||||
(nth 1 completion-in-region--data)))
|
||||
(defun icomplete--category ()
|
||||
(let* ((beg (icomplete--field-beg))
|
||||
(md (completion--field-metadata beg)))
|
||||
(alist-get 'category (cdr md))))
|
||||
|
||||
;;;_ > icomplete-simple-completing-p ()
|
||||
(defun icomplete-simple-completing-p ()
|
||||
|
@ -488,10 +482,7 @@ See `icomplete-mode' and `minibuffer-setup-hook'."
|
|||
(sit-for icomplete-compute-delay)))
|
||||
(when (and
|
||||
icomplete-tidy-shadowed-file-names
|
||||
(eq (alist-get 'category
|
||||
(cdr (completion--field-metadata
|
||||
(icomplete--field-beg))))
|
||||
'file)
|
||||
(eq (icomplete--category) 'file)
|
||||
rfn-eshadow-overlay (overlay-buffer rfn-eshadow-overlay)
|
||||
(eq this-command 'self-insert-command)
|
||||
(= saved-point (icomplete--field-end))
|
||||
|
|
Loading…
Add table
Reference in a new issue