help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: if and only if an Error message


From: Michael Heerdegen
Subject: Re: if and only if an Error message
Date: Sun, 20 Jul 2014 03:42:20 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.92 (gnu/linux)

Emanuel Berg <embe8573@student.uu.se> writes:


> But put it this way: how do I find out a variable isn't
> a user option?

Yes, C-h v.  User options are these variables that can be "customized".


> (setq error-buffer-name "*Errors*")
>
> ;; inhibit the debugger -
> ;;   try this if nothing else: a wonderful thing to not
> ;;   have it hop out over half the screen for something
> ;;   that can be communicated in a few words
> (setq debug-on-error nil)
> (setq eval-expression-debug-on-error nil)
>
> ;; this does three things, see the comments
> (defun say-and-log-error (data _ fun)
>   (let*((error-str (format "%S in %S" data fun))
>         (error-buffer (get-buffer-create error-buffer-name))
>         (error-win (get-buffer-window error-buffer)) )
>     (message error-str)                  ; echo the error message
>     (with-current-buffer error-buffer
>       (goto-char (point-max))
>       (insert error-str "\n") )          ; log it
>     (if error-win
>         (with-selected-window error-win  ; move focus of error window
>           (goto-char (point-max))        ; if available
>           (recenter -1)) )))             ; (is there a better way?)
>
> ;; use it instead of the default one          
> (setq command-error-function
>       (lambda (&rest args)
>         (apply #'say-and-log-error args)) )
>
> ;; show the error buffer        
> (defun show-errors ()
>   (interactive)
>   (switch-to-buffer (get-buffer-create error-buffer-name))
>   (goto-char (point-max)) ; the same situation: the last line of data
>   (recenter -1) )         ; should be on the last window line
>                           ; whenever possible
>
> ; test here:
> ; (message 'error-as-not-string)

Looks good.

Maybe also call `discard-input' as `command-error-default-function'
does.

And (message "%s" error-str).
             ^^^^

Have fun,

Michael.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]