0

I have been experimenting with various completion frameworks in Emacs. I am currently using consult together with icomplete. I like the way things are working for me but I would like to disable icomplete for find-file. I prefer the traditional Emacs find-file.

I have tried this, which did not work:

(define-key icomplete-minibuffer-map [remap find-file] nil)
(define-key icomplete-minibuffer-map [remap write-file] nil)

I based this on the following which did work when I was experimenting using ivy.

(define-key ivy-minibuffer-map [remap counsel-find-file] nil)
(define-key ivy-minibuffer-map [remap counsel-describe-variable] nil)
(define-key ivy-minibuffer-map [remap counsel-describe-function] nil)

Below are my configurations for icomplete:

(require 'icomplete)
(icomplete-mode 1)
(setq icomplete-hide-common-prefix nil)
(setq icomplete-in-buffer t)
(icomplete-vertical-mode)
(bind-key "<tab>" 'icomplete-force-complete minibuffer-local-map)
(bind-key "<return>" 'icomplete-force-complete-and-exit minibuffer-local-map) ; exit with completion
(bind-key "C-j" 'exit-minibuffer minibuffer-local-map) ; force input unconditionally
(bind-key "C-n" 'icomplete-forward-completions minibuffer-local-map)
(bind-key "<down>" 'icomplete-forward-completions minibuffer-local-map)
(bind-key "C-p" 'icomplete-backward-completions minibuffer-local-map)
(bind-key "<up>" 'icomplete-backward-completions minibuffer-local-map)
(bind-key "<C-backspace>" 'icomplete-fido-backward-updir minibuffer-local-map)

I would appreciate some help to configure this.

Edman
  • 1,167
  • 7
  • 13
  • 1
    Advise those commands, so they turn off `icomplete-mode` only for their duration. See the Elisp manual, node [Advising Functions](https://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Functions.html) and its subnodes. Or just define your own commands, which use those commands but which turn-off `icomplete-mode` for the duration, and bind those commands to the keys used for the original commands. – Drew Feb 12 '21 at 19:13
  • I have cobbled something together, but now there is no history in the minibuffer when I click the and arrows. `;use regular find file key (defun my-find-file() (interactive) (icomplete-mode -1) (call-interactively 'find-file) (icomplete-mode 1)) (global-set-key (kbd "C-x C-f") 'my-find-file)` – Edman Feb 13 '21 at 13:12

1 Answers1

1

I had to do a little digging for this one.

find-file and others like it use the function find-file-noselect, which, in turn, uses the function given by the variable read-file-name-function in order to read a file name from the minibuffer.

Therefore, you should advise around read-file-name-function to disable icomplete (or fido) for all find-file type functions.

Beneath the surface, icomplete-mode and fido-mode simply add functions to the minibuffer-setup-hook. Looking at these functions, they all check for the variable icomplete-mode to be non-nil before running. So to disable icomplete or fido temporarily, you should let-bind the variable icomplete-mode to nil.

(defun my/disable-icomplete (fun &rest args)
  (let ((icomplete-mode nil))
    (apply fun args)))

(advice-add read-file-name-function :around #'my/disable-icomplete)