Mastering Emacs – Search inside minibufer

This is by far best feature in Emacs that you can use interactive search inside Minibuffer. If you want to find a function that you don’t know exact name, I do this a lot – who will remember function names in Emacs, you can use:

C-h f C-s

And search for functions. How cool is that? Almost all functions that have completion inside minibuffer work with search like

  • C-x b C-s – search for buffer to switch
  • C-h <KEY> C-s – search for help

When I switch to Emacs 24, I found that M-x C-s don’t work. So you can’t search for interactive function to execute. But you can get it back. As describe by this Emacs Bug Ticket by putting this to you .emacs file.

(defun read-extended-command ()
  "Read command name to invoke in `execute-extended-command'."
  (minibuffer-with-setup-hook
      (lambda ()
        (set (make-local-variable 'minibuffer-default-add-function)
             (lambda ()
               ;; Get a command name at point in the original buffer
               ;; to propose it after M-n.
               (let ((def (with-current-buffer
                              (window-buffer (minibuffer-selected-window))
                            (and (commandp (function-called-at-point))
                                 (format "%S" (function-called-at-point)))))
                     (all (sort (minibuffer-default-add-completions)
                                (lambda (a b) (string< a b)))))
                 (if def
                     (cons def (delete def all))
                   all)))))
    ;; Read a string, completing from and restricting to the set of
    ;; all defined commands.  Don't provide any initial input.
    ;; Save the command read on the extended-command history list.
    (completing-read
     (concat (cond
	      ((eq current-prefix-arg '-) "- ")
	      ((and (consp current-prefix-arg)
		    (eq (car current-prefix-arg) 4)) "C-u ")
	      ((and (consp current-prefix-arg)
		    (integerp (car current-prefix-arg)))
	       (format "%d " (car current-prefix-arg)))
	      ((integerp current-prefix-arg)
	       (format "%d " current-prefix-arg)))
	     ;; This isn't strictly correct if `execute-extended-command'
	     ;; is bound to anything else (e.g. [menu]).
	     ;; It could use (key-description (this-single-command-keys)),
	     ;; but actually a prompt other than "M-x" would be confusing,
	     ;; because "M-x" is a well-known prompt to read a command
	     ;; and it serves as a shorthand for "Extended command: ".
	     "M-x ")
     obarray 'commandp t nil 'extended-command-history)))

And tell me, why you will ever need Ido-mode

One note about that, when you use one interactive function inside another one you will need to call C-g twice to exit minibuffer

About these ads

  1. #1 by Nannette on June 26, 2014 - 19:37

    Great information. Lucky me I came across your blog by accident (stumbleupon).
    I’ve saved it for later!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: