2010-11-07

Built-in functions in emacs

For the last couple days I've being trying to add advice (http://bit.ly/9khTDk) to execute-extended-command (Aka M-x). What I wanted to do was have a function executed directly after execute-extended-command, which keeps track of what commands I use, which I then can study to see what I could add a key-binding to.

The thing is, it didnt run. Damn irritating.

First, I thought it was a variable scope issue. Perhaps the hash I wrote to from the advice wasnt the one I declared? To see if it was actually run, I made the function output a message to the *Message* buffer, which it never did when I ran M-x foo.

So then I thought 'hmm, perhaps the advice never triggered?', so I looked in the variable ad-advised-functions, where my advice showed up. Ok, so its in the list of advices to be run.

So I went and asked uncle google, and after a little fiddling with search terms, I found this: http://aaronhawley.livejournal.com/26901.html

You dont have to follow that link, I'll summarize: You can advise almost all functions in emacs. To be more specific, you can advise functions written in emacs-lisp, but not the ones written in C.

execute-extended-command is written in C. And so Aaron S. Hawley re-wrote it, in elisp. Rather pretty code, but also complex, implying that there could be a bug lurking there.

Now the question I'm asking myself is- shall I replace my built-in execute-extended-command with his elisp variant, or write a wrapper function which I can then bind to M-x?

0 comments:

Post a Comment