I need to advise emacs to do something when any error dings to the user. I can't find any documentation on which function I actually need to advise.

Which function do I need to advise to do something when a user-error is unhandled?

  • Just checking: you want to do that as part of your user configuration so that it happens under every circumstances, right? Because if you're writing some package and want to react to errors while your code is running, that's completely different: you'd catch whatever signal you're interested in. – Gilles 'SO- stop being evil' Sep 22 '16 at 20:21
  • I'm looking call a special command that advises ace-jump mode to do something after it completes jumping. That advice is removed automatically once it runs, but if any error interrupts the process it won't get far enough to remove it. The end behaviour I would like is to remove the "on ace-jump-mode completion" advice if an error is signalled to prevent it executing next time ace-jump-mode is run. – jcaw Sep 22 '16 at 20:39
  • 1
    Whoa, then you're completely on the wrong track. My answer here answers the question you asked, but it doesn't give you what you need. You should not set a global configuration for this! Do everything you need to do in your advice on ace-jump-mode. Ask a question on how to do this if you need help, with an explanation of what you actually want to do and the code you have so far. – Gilles 'SO- stop being evil' Sep 22 '16 at 20:46
  • I wasn't looking for a global configuration - just to add temporary advice (albeit via the global advice system). However, you're right. I tried looking for a solution that just modified ace-jump-mode before. Looks like I missed the function I want to advise. It is ace-jump-done, which runs even if an error is signalled or ace-jump-mode is cancelled. Thanks for the help! – jcaw Sep 22 '16 at 21:09

The dinging is called ringing the bell. If the variable ring-bell-function is defined, it's called instead of the terminal-dependent method (which may either emit a sound or flash the screen). So you'd set this variable, rather than advising a function.

If you want to get information about the error, you can piggyback on the debugger trigger mechanism. Set debug-on-error to t (and possibly tune other variables mentioned in the same section of the manual to make sure that the debugger is entered in the circumstances you want) and set the variable debugger to your function. The default function is debug if you want to call it from yours.

| improve this answer | |
  • I don't want to perform this every time the bell is rung - only when a user-error is the cause. It seems like I need to advise the function that calls the ring-bell-function. Do you know which function that is? – jcaw Sep 22 '16 at 20:19
  • @JackCC It's called from C. If you want to catch user errors, then use the debugger mechanism. You get information about the cause and you can filter errors and call the real debugger afterwards. – Gilles 'SO- stop being evil' Sep 22 '16 at 20:20
  • Is there a way to do this whether or not the debugger is running? I'd like to add it as general behaviour in my init file. – jcaw Sep 22 '16 at 20:36
  • It didn't exactly solve my problem, but it was an answer to the question asked. I learned something about the error system at least! Thanks. – jcaw Sep 22 '16 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.