Posts Tagged ‘emacs elisp’

Accessing Documentation from Emacs

Thursday, July 2nd, 2009

Today’s re-additions to my .emacs file:

(defun my-help ()
  "If function given tries to `describe-function' if variable
uses 'describe-variable', otherwise uses `manual-entry' to display
manpage of a `current-word'."
  (interactive)
  (let ((var (variable-at-point)))
    (if (symbolp var)
        (describe-variable var)
      (let ((fn (function-called-at-point)))
        (if fn
            (describe-function fn)
          (man (current-word)))))))
 
(global-set-key [f1] 'my-help)

This function was one I found somewhere online, and is incredibly useful. It will attempt to give help on the word at point, no matter what it is. If it is a variable, it will call the describe-variable function. If it is a function, it will call describe-function to give documentation. If it isn’t a elisp variable of function, it will return the results of the ‘man’ command on the word, which is still useful in programming if you have packages such as manpages-dev. While these commands are all possible individually, having one key that does whatever it should to give documentation, instead of having to choose documentation functions, makes my life so much easier when reading elisp.