The function that sets up the minibuffer is read_minibuf
in minibuf.c
. As of Emacs 24, it is called from the primitives read-from-minibuffer
and read-no-blanks-input
, and Fread_from_minibuffer
is in turned called from read-string
. The hook minibuffer-setup-hook
is the first piece of Lisp code that read_minibuf
executes. If that's too late for you, you're going to need to run your code before any of read-from-minibuffer
, read-no-blanks-input
and read-string
is executed. In earlier Emacs versions, there were more functions that called read_minibuf
via C, especially completing-read
, but these now go via Lisp.
Here's some code for Emacs ≥24.4 that sets up a one-time advice executed before the first time one of these functions executed.
(defun before-first-read-from-minibuffer (&rest ignored)
(message "Before first read-from-minibuffer")
(advice-remove 'read-from-minibuffer 'before-first-read-from-minibuffer)
(advice-remove 'read-no-blanks-input 'before-first-read-from-minibuffer)
(advice-remove 'read-string 'before-first-read-from-minibuffer))
(advice-add 'read-from-minibuffer :before 'before-first-read-from-minibuffer)
(advice-add 'read-no-blanks-input :before 'before-first-read-from-minibuffer)
(advice-add 'read-string :before 'before-first-read-from-minibuffer)
The corresponding code with the older advice facility that works in previous Emacs versions would be something like:
(defadvice read-from-minibuffer
(before before-first-read-from-minibuffer activate)
(message "Before first read-from-minibuffer")
(ad-remove-advice 'read-from-minibuffer 'before 'before-first-read-from-minibuffer)
(ad-activate 'read-from-minibuffer))
defadvice
using:before
would help? I must admit I'm just guesing though, given the aforementioned lack of information.minibuffer-setup-hook
is run before the minibuffer is entered, so obviously, you mean something different.(add-hook 'minibuffer-setup-hook 'ido-ubiquitous-mode)
doesn't enableido-ubiquitous-mode
early enough. You can only tell the mode is enabled on the second time the minibuffer is entered.