This is an advanced tip, but it has simple applications.
Don't you wish you could change some of the built-in routines? You
like the way they work, but would tweak it just a little bit.
For example, 'ispell' does a great service: it provides suggestions
for the correct spelling of a misspelled word. Wonderful, I use it
all the time. However, it often has the order of choices exactly
opposite of what I'd expect.
e.g. `waht' - the correct option 'what' is #7!
`sopporting' - the correction option 'supporting' is #2!
It's much easier if the choice I usually pick is the first one.
So, it'd be great if I could just tell 'ispell' to reverse the order
of the choices provided.
Advice is a mechanism that lets you get code to run before, after, or
"around" existing elisp routines. You can modify the arguments going
in, you can modify the result, you can call the existing routing
multiple times. And this advice can be nested too.
Why use advice as opposed to re-writing the routine?
Because (especially in this example) - you don't want to muck with
having your own copy of the code. It's messy, and you might miss
upgrades to that routine with new versions of Emacs.
So, with this case in hand, I spent a minute tracking down the routine
that could be advised. I spent a minute writing the advice:
(defadvice ispell-command-loop (before ispell-reverse-miss-list activate)
"reverse the first argument to ispell-command-loop"
(ad-set-arg 0 (reverse (ad-get-arg 0))))
And now my spelling choices are in the right order! yay.
For more information on advice:
C-h i m advice RET