John Fremlin's blog: Emacs lisp: run recommended command

Posted 2009-03-02 23:00:00 GMT

There's little point in using emacs if you're not going to customise it. It is a rather buggy agglomeration of software that can only handle small files with short lines. However, in quantity there is a huge amount of code written for emacs. It is a vast system.

The Emacs Lisp snippet of mine that I'm most pleased with is a tiny function to automatically carry out the command recommended to the user. For example, if you open a file in a directory that doesn't exist, emacs will tell you how to make the directory (it says Use M-x make-directory). The following fragment allows you to run this command by pressing F6.

(defun vii-last-mx-suggestion (suggestion)
  (interactive (list 
		(read-from-minibuffer "Command to execute: "
				      (with-current-buffer "*Messages*"
					(goto-char (point-max))
					(search-backward "M-x")
					(search-forward " ")
					(thing-at-point 'symbol)))))
  (call-interactively (intern suggestion)))
(define-key global-map `[(f6)] 'vii-last-mx-suggestion)

Actually rather handy, thanks!

Posted 2013-01-03 20:44:52 GMT by leth

Post a comment