diff --git a/lisp/icomplete.el b/lisp/icomplete.el index 2ea5e36fa88..8013f68dcf4 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el @@ -317,6 +317,20 @@ icomplete-vertical-goto-last ;;;_* Helpers for `fido-mode' (or `ido-mode' emulation) +(cl-defgeneric icomplete-fkill-candidate (category _candidate) + (error "Sorry, don't know how to kill things for `%s'" category)) + +(cl-defmethod icomplete-kill-candidate ((_ (eq 'buffer)) thing) + (when (yes-or-no-p (concat "Kill buffer " thing "? ")) + (kill-buffer thing))) + +(cl-defmethod icomplete-kill-candidate ((_ (eq 'file)) thing) + (let* ((dir (file-name-directory (icomplete--field-string))) + (file (expand-file-name thing dir))) + (when (yes-or-no-p (concat "Delete file " file "? ")) + (delete-file file) t)))) + + (defun icomplete-fido-kill () "Kill line or current completion, like `ido-mode'. If killing to the end of line make sense, call `kill-line', @@ -331,26 +345,12 @@ icomplete-fido-kill (call-interactively 'kill-line) (let* ((all (completion-all-sorted-completions)) (thing (car all)) - (cat (icomplete--category)) - (action - (cl-case cat - (buffer - (lambda () - (when (yes-or-no-p (concat "Kill buffer " thing "? ")) - (kill-buffer thing)))) - ((project-file file) - (lambda () - (let* ((dir (file-name-directory (icomplete--field-string))) - (path (expand-file-name thing dir))) - (when (yes-or-no-p (concat "Delete file " path "? ")) - (delete-file path) t)))) - (t - (error "Sorry, don't know how to kill things for `%s'" cat))))) + (cat (icomplete--category))) (when (let (;; Allow `yes-or-no-p' to work and don't let it ;; `icomplete-exhibit' anything. (enable-recursive-minibuffers t) (icomplete-mode nil)) - (funcall action)) + (icomplete-kill-candidate cat thing)) (completion--cache-all-sorted-completions (icomplete--field-beg) (icomplete--field-end)