From e1d24f3c4cdc052d9ba87801fde09fae0d86d0b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Sun, 3 Nov 2019 13:10:40 +0000 Subject: New fido-mode, emulates ido-mode with icomplete-mode * lisp/icomplete.el (icomplete-fido-mode-map): New variable. (icomplete--fido-mode-setup): New function. (fido-mode): New global minor mode. --- lisp/icomplete.el | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) (limited to 'lisp/icomplete.el') diff --git a/lisp/icomplete.el b/lisp/icomplete.el index e1d6236943c..777fdce13a0 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el @@ -223,21 +223,7 @@ Last entry becomes the first and can be selected with (push (car last) comps) (completion--cache-all-sorted-completions beg end comps)))) -;;; `ido-mode' emulation -;;; -;;; The following "magic-ido" commands can be bound in -;;; `icomplete-mode-map' to make `icomplete-mode' behave more like -;;; `ido-mode'. Evaluate this to try it out. -;;; -;;; (let ((imap icomplete-minibuffer-map)) -;;; (define-key imap (kbd "C-k") 'icomplete-magic-ido-kill) -;;; (define-key imap (kbd "C-d") 'icomplete-magic-ido-delete-char) -;;; (define-key imap (kbd "RET") 'icomplete-magic-ido-ret) -;;; (define-key imap (kbd "DEL") 'icomplete-magic-ido-backward-updir)) -;;; -;;; For more ido behaviour, you'll probably like this too: -;;; -;;; (setq icomplete-tidy-shadowed-file-names t) +;;; Helpers for `fido-mode' (or `ido-mode' emulation) ;;; (defun icomplete-magic-ido-kill () "Kill line or current completion, like `ido-mode'. @@ -312,6 +298,42 @@ require user confirmation." (backward-kill-sexp 1) (call-interactively 'backward-delete-char)))) +(defvar icomplete-fido-mode-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "C-k") 'icomplete-magic-ido-kill) + (define-key map (kbd "C-d") 'icomplete-magic-ido-delete-char) + (define-key map (kbd "RET") 'icomplete-magic-ido-ret) + (define-key map (kbd "DEL") 'icomplete-magic-ido-backward-updir) + (define-key map (kbd "M-j") 'exit-minibuffer) + (define-key map (kbd "C-s") 'icomplete-forward-completions) + (define-key map (kbd "C-r") 'icomplete-backward-completions) + map) + "Keymap used by `fido-mode' in the minibuffer.") + +(defun icomplete--fido-mode-setup () + "Setup `fido-mode''s minibuffer." + (use-local-map (make-composed-keymap icomplete-fido-mode-map + (current-local-map))) + (setq-local icomplete-tidy-shadowed-file-names t + icomplete-show-matches-on-no-input t + icomplete-hide-common-prefix nil + completion-styles '(flex) + completion-category-defaults nil)) + +;;;###autoload +(define-minor-mode fido-mode + "An enhanced `icomplete-mode' that emulates `ido-mode'. + +This global minor mode makes minibuffer completion behave +more like `ido-mode' than regular `icomplete-mode'." + :global t :group 'icomplete + (remove-hook 'minibuffer-setup-hook #'icomplete-minibuffer-setup) + (remove-hook 'minibuffer-setup-hook #'icomplete--fido-mode-setup) + (when fido-mode + (setq icomplete-mode t) + (add-hook 'minibuffer-setup-hook #'icomplete-minibuffer-setup) + (add-hook 'minibuffer-setup-hook #'icomplete--fido-mode-setup))) + ;;;_ > icomplete-mode (&optional prefix) ;;;###autoload (define-minor-mode icomplete-mode -- cgit v1.2.1