Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable auto-complete in Emacs minibuffer

Tags:

emacs

elisp

I'm trying to turn auto-complete in the minibuffer:

(add-hook 'minibuffer-setup-hook 'auto-complete-mode)

What I get is auto-complete working in the first instance of minibuffer, but no longer. That is the full minibuffer-setup-hook after loading:

(auto-complete-mode turn-on-visual-line-mode ido-minibuffer-setup rfn-eshadow-setup-minibuffer minibuffer-history-isearch-setup minibuffer-history-initialize)

How to turn auto-complete on persistently?

like image 546
Anton Tarasenko Avatar asked Dec 22 '22 08:12

Anton Tarasenko


2 Answers

You rarely ever want to add a function symbol to a hook variable if that function acts as a toggle (which will be the case for most minor modes).

minibuffer-setup-hook runs "just after entry to minibuffer", which means that you would be enabling auto complete mode the first time you enter the minibuffer; disabling it the second time; enabling it the third time; etc...

Typically you would either look to see if there's a pre-defined turn-on-autocomplete-mode type of function, or define your own:

(defun my-turn-on-auto-complete-mode ()
  (auto-complete-mode 1)) ;; an argument of 1 will enable most modes
(add-hook 'minibuffer-setup-hook 'my-turn-on-auto-complete-mode)

I can't test that, because you haven't linked to the autocomplete-mode you are using.

like image 114
phils Avatar answered Dec 27 '22 11:12

phils


The creator of "auto-complete-mode" explicitly excludes the minibuffer for use with auto completion. The definition for the minor mode is:

(define-global-minor-mode global-auto-complete-mode
  auto-complete-mode auto-complete-mode-maybe
  :group 'auto-complete)

so the "turn mode on" function is "auto-complete-mode-maybe" - the definition of that function is:

(defun auto-complete-mode-maybe ()
  "What buffer `auto-complete-mode' prefers."
  (if (and (not (minibufferp (current-buffer)))
           (memq major-mode ac-modes))
      (auto-complete-mode 1)))

This function explicitly tests in the if statement if the current-buffer is the minibuffer and doesn't turn on the auto-complete-mode if it is.

If you want to use auto-complete-mode in the minibuffer, you should probably contact the maintainer of the mode and ask him why he excluded the minibuffer and what programming changes he feels are necessary to enable the mode in the minibuffer.

like image 45
zev Avatar answered Dec 27 '22 09:12

zev