From: João Távora Date: Mon, 23 Dec 2019 23:19:01 +0000 (+0000) Subject: Slightly simplify lisp/icomplete.el with new icomplete--category helper X-Git-Tag: emacs-27.0.90~241 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=fe0ed17175;p=emacs.git 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. (cherry picked from commit 24a1f520f91c278cb8cc57325ea80285a3b252cf) --- diff --git a/lisp/icomplete.el b/lisp/icomplete.el index cd20064be02..4d6dfcd18a1 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el @@ -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))