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: Emanuel Berg
Subject: Re: if and only if an Error message
Date: Sat, 19 Jul 2014 13:48:53 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Michael Heerdegen <michael_heerdegen@web.de> writes:

> It's not harmful.  But it's not a user option, so if
> you set its value, you should know what you are doing
> and how the flag is used internally.

If I had to know what I'm doing nothing would ever be
done. Even more so, if I know it, then why do it...

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

> I would start trying something like this ...

Thank you!

Yes, check this out - 

(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)

-- 
underground experts united


reply via email to

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