When C-g doesn't work, you can sometimes get control back with:
pkill -SIGUSR2 emacs
As @Archenoth points out, sending the SIGUSR2 signal to Emacs turns on debug-on-quit. This can be useful, but you'll want to turn it off again at some point (possibly immediately). To do this, call M-x toggle-debug-on-quit.
More information on using SIGUSR1 and SIGUSR2 ...
Emacs provides a good amount of debugging facilities including M-x toggle-debug-on-error, M-x toggle-debug-on-quit, debug on signal (which can be used by sending USR2 to Emacs from outside), debug-on-entry (of a function), debug-on-message (when seeing a specific regexp match of a message) and finally, debug itself as alternative to instrumenting a function ...
BTW, an alternative option can be something like:
(let ((error t))
(setq error nil))
(when error (cleanup))))
The advantage is that you avoid catching&rethrowing the error, which means for example that the debugger will show you the right backtrace (the one that corresponds to the actual source ...
Two options, neither of which are perfect, come to mind. First, you could wrap most of your early initialization code (ie, before it gets to your customizations) in (ignore-errors ...). If there are errors, however, there won't be a lot of feedback -- ignore-errors will simply return nil.
A more intricate option would be to wrap the potentially buggy code ...
@Dan described well how you can turn errors into messages. You can
also do whatever you want with errors by using
Yet another option is to use
I’ll stick to condition-case here, for no reason whatsoever.
Catching the Error
This should always guarantee your key definitions get evaluated,
regardless of what happened inside ...
It looks like visible-bell mode is enabled. This means that whenever an Emacs command rings a bell (i.e. fails in some way), it will try to flash the screen.
You should be able to turn it off with (setq visible-bell nil).
Flickering is annoying, but the bell gives you useful information so I wouldn't want to suppress it completely. You can customize ...
(error (message "error=%S, data=%S" (car err) (cdr err))))
This will not only catch the error but will additionally emit a message telling you which specific error was signaled. Also, in recent Emacsen, you can use completion to see the possible error symbols.
Sadly, when you try the ...
The error in question is thrown with user-error, not simply echoed with message.
In your particular case testing the return value of evil-get-marker should work also:
(if (evil-get-marker ?8)
I don't think that input validation of top-level widgets happens automatically. Neither the info manual nor the source code suggest otherwise.
Composite widgets (e.g. editable-list) automatically validate their childs upon validation, but you need to explicitly validate top-level widgets yourself before using their values.
For instance, if your form has ...
debug-on-error, and more generally the debugger, are not available for errors raised from post-command-hook (for example, to prevent runaway recursion).
What you can do is what programmers have done from Day One: print information. But before you do that, bisect the list of functions that you have on post-command-hook, narrowing the problem down to ...
Not exactly sure what the context is or what you mean.
If by "open a window with an error" and "opening error buffer" you mean opening the debugger in buffer *Backtrace*, then set variable debug-on-error to nil to prevent that. The error message will then simply be shown in the echo area.
Variable visible-bell controls whether a bell (ding) sound is heard ...
Maybe because it's 2018 now, but in my case,
I only had to turn on debugging like wasamasa suggested:
After this, M-x eval-buffer on my faulty Elisp file
gave context by providing the position of the error,
Debugger entered--Lisp error: (invalid-read-syntax ")")
eval-buffer() ; Reading at buffer position 523
That looks fine, except that I'd use (fboundp 'define-error) instead of testing the version number.
Until Emacs-24.3 what was used instead were manual calls to put as in:
(put 'foo-error 'error-conditions '(foo-error error))
(put 'foo-error 'error-message "Foo on you!")
You can use whatever you think is most appropriate for your context. There is no "right" way for all contexts.
message does not prevent continued processing of the current command. If you want to be sure the user sees the message, you can use sit-for or sleep-for (which see).
You can pop up a window, frame, or tooltip with a message. Like message, this ...
If the function your are calling really echoes a message, you can use (current-message).
Return the string currently displayed in the echo area, or nil if
Of course, it would be better to issue an error, see other answer for more details on this.
You must define the symbol as an error first:
(define-error 'my-error "Custom error")
(signal 'my-error 'my-data)
(my-error (message "data: %S" err)))
Evaluating this form yields "data: (tmp:error . my-data)" as expected.
This appears to be coming from the function org-flag-drawer.
Use C-h f to find where this function is defined, and modify it to also give the buffer name:
(defun org-flag-drawer (flag)
"When FLAG is non-nil, hide the drawer we are within.
Otherwise make it visible."
(when (looking-at "^[ \t]*:[a-zA-Z][a-...
The docstring for condition-case (C-h f condition-case) says:
condition-case is a special form in `C source code'.
(condition-case VAR BODYFORM &rest HANDLERS)
Regain control when an error is signaled.
Executes BODYFORM and returns its value if no error happens.
Each element of HANDLERS looks like (CONDITION-NAME BODY...)
where the ...
You didn't raise an error with your error message. You just used message.
So your message actually appeared (check buffer *Messages*), but then execution continued and the second message was displayed.
If you want to stop execution when the error occurs then you need to raise another error. E.g.:
(defun my-divide-by-0 ()
(/ 1 ...
You can wrap that in ignore-errors, to ignore any error evaluating it might raise:
(ignore-errors (require-package 'clips-mode))
If you want to ignore only particular errors then you can instead wrap it with condition-case:
condition-case is a special form in C source code.
(condition-case VAR BODYFORM &rest HANDLERS)
Regain control when ...
Your error symbol test-signal is not defined. C-h f signal says:
An error symbol is a symbol with an error-conditions property
that is a list of condition names.
Let's check this for some standard error symbols and the test-signal
(get 'error 'error-conditions)
;; => (error)
(get 'args-out-of-range 'error-conditions)
;; => (args-out-of-range ...
The error message tells you where the error is: position 23740. You can go there with goto-char. Doing M-x goto-char 23740 will take you to the error. org-mode's folding may make it hard to see what's going on, so switching to fundamental-mode (with M-x fundamental-mode) first may help you see what's going on.
The other answers have pretty well covered the low-level error-handling facilities that will be useful in a case like this. Another approach that can help is modularity. For instance, I divide my initialization file into several different files (using provide as appropriate), and I load them using this function instead of require:
(defun my/require-softly ...
Write an infinite loop, and catch the error outside the loop.
Org mode 7.8.11 throws a plain error for this message. If you have a more recent version that calls user-error instead of error, replace error by user-error.
This hides all errors. It would be safer to catch only the ...