views:

625

answers:

5

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:

  1. Hidden features of Python
  2. Hidden features of Ruby
  3. Hidden features of Perl
  4. Hidden features of Java
+6  A: 

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)
+6  A: 

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.

Dominic Rodger
p.s. Know this doesn't really fit the bill, but I found this function the other day whilst looking into some timezone issues I was having with org-mode, and I just needed to share this amazingly pointless feature with someone.
Dominic Rodger
+3  A: 

Advice. It lets you customize behavior without modifying the original source.

Examples are:

What'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).

Trey Jackson
+4  A: 
(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)
justinhj
I installed Snarl and todochiku and it fell over and cried. It looks like a nice suite. :-/
Paul Nathan
Hi Paul, Growl should work... what platform?
justinhj
@justinhj: Tried Growl but it eats M-x combos, which as an emacs-user, I rely on. Windows XP.
Paul Nathan
I had that problem... took me a while to figure out it was growl. here's my solution from the growl mailing list.. > To fix it I went into the config file and changed the keyboard> > shortcut to Alt-Z which I don't need. But shouldn't it be possible for> > Growl to accept the Alt-X without preventing other apps from seeing> > the event?> >> > YOUR DRIVE:/Documents and Settings/YOU/Local Settings/Application> > Data/ Growl/2.0.0.0/user.config
justinhj
Alt-Z is for zap-to-char. I used LWin+Z and LWin+Shift+Z for the two keyboard shortcuts. LWin is the left Windows key. For the right Windows key, use RWin.
Chry Cheng
A: 

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
slomojo