What are some features of Emacs Lisp that you use to solve real problems?
- One feature per answer
- Give an example and short description of the feature, not just a link to documentation
- Label the feature using bold title as the first line
See also:
What are some features of Emacs Lisp that you use to solve real problems?
See also:
emacs --script; # Emacs scripting
Since this is a Community question, I'll start off with my new favorite thing. Writing scripts with Emacs Lisp instead of bash.
#!/usr/bin/emacs --script (defun surf-news () (interactive) (progn (browse-url "http://news.ycombinator.com") (browse-url "http://stackoverflow.com") )) (surf-news)
M-x sunrise-sunset
Takes a latitude and longitude, and tells you what time sunrise and sunset are. I use it when I need to be able to, with just a few keystrokes, know at a glance what time sunrise is. I like to imagine it'll come in handy.
Advice. It lets you customize behavior without modifying the original source.
Examples are:
cc-mode
derived modeWhat's nice about advice is that you don't have to touch the original code, so when you get a new version of Emacs or whatever package you're modifying, you don't have to re-merge your changes with the new code.
The best way to learn advice is to go over the tutorial found in the advice package itself.
M-x find-library advice RET
and search for Foo games: An advice tutorial
The documentation found in that file is also very good (at least as good as the info pages).
(run-at-time time repeat function &rest args)
Perform an action at time time. Repeat the action every repeat seconds
todochiku for example uses this to 'growl' a set number of minutes in the future. I use that feature to set a reminder say 20 minutes into the future. See function todochiku-in, and my blog post about using growl from emacs.
The time can be specified in a flexible number of ways for example:
(run-at-time "2:30pm" nil 'todochiku-message "Todochiku Timer" "Make coffee"
(todochiku-icon 'bell)))
(run-at-time "30 seconds" nil 'todochiku-message "Todochiku Timer" "Do some work"
(todochiku-icon 'bell))
Change the nil to a number of seconds to have it repeat. Then when you want to disable:
(cancel-function-timers 'todochiku-message)
Fuzzy matching on M-x (and some other places)
M-x em-li-moTAB ... or M-x em*li*moTAB
expands to:
M-x emacs-lisp-mode