Advice (programming): Difference between revisions

Content deleted Content added
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0
m Update syntaxhighlight tags - remove use of deprecated <source> tags - BOT in trial - BRFA
Line 22:
Another Emacs example; suppose after one corrected a misspelled word through [[ispell]], one wanted to re-spellcheck the entire buffer. <code>ispell-word</code> offers no such functionality, even if the spellchecked word is used a thousand times. One ''could'' track down the definition of <code>ispell-word</code>, copy it into one's .emacs, and write the additional functionality, but this is tedious, prone to broken-ness (the .emacs version will get out of sync with the actual Ispell Elisp module, if it even works out of its home). What one wants is fairly simple: just to run another command after <code>ispell-word</code> runs. Using advice functions, it can be done as simply as this:
 
<sourcesyntaxhighlight lang="elisp">
(defadvice ispell (after advice)
(flyspell-buffer))
(ad-activate 'ispell t)
</syntaxhighlight>
</source>
 
==Implementations==