* Why does signaling an error not call set-message-function? @ 2022-04-05 8:01 Mario Lang 2022-04-05 11:38 ` Eli Zaretskii 0 siblings, 1 reply; 12+ messages in thread From: Mario Lang @ 2022-04-05 8:01 UTC (permalink / raw) To: emacs-devel Hi. I just realized that only a certain type of message goes through `set-message-function'. In particular, things like (signal 'end-of-buffer nil) write to the echo area but do not trigger set-message-function. This is a bit unexpected. Is there an equivalent hook for error messages going to the echo area? -- CYa, ⡍⠁⠗⠊⠕ ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Why does signaling an error not call set-message-function? 2022-04-05 8:01 Why does signaling an error not call set-message-function? Mario Lang @ 2022-04-05 11:38 ` Eli Zaretskii 2022-04-05 12:05 ` Mario Lang 0 siblings, 1 reply; 12+ messages in thread From: Eli Zaretskii @ 2022-04-05 11:38 UTC (permalink / raw) To: Mario Lang; +Cc: emacs-devel > From: Mario Lang <mlang@blind.guru> > Date: Tue, 05 Apr 2022 10:01:58 +0200 > > Hi. > > I just realized that only a certain type of message goes through > `set-message-function'. In particular, things like > > (signal 'end-of-buffer nil) > > write to the echo area but do not trigger set-message-function. > > This is a bit unexpected. Is there an equivalent hook for > error messages going to the echo area? (set-message-function _does_ affect echo-area messages, just not any kind of them.) Are you sure it is a good idea to allow running arbitrary Lisp when Emacs wants to signal an error? ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Why does signaling an error not call set-message-function? 2022-04-05 11:38 ` Eli Zaretskii @ 2022-04-05 12:05 ` Mario Lang 2022-04-05 12:21 ` Eli Zaretskii 0 siblings, 1 reply; 12+ messages in thread From: Mario Lang @ 2022-04-05 12:05 UTC (permalink / raw) To: emacs-devel Eli Zaretskii <eliz@gnu.org> writes: >> From: Mario Lang <mlang@blind.guru> >> Date: Tue, 05 Apr 2022 10:01:58 +0200 >> >> Hi. >> >> I just realized that only a certain type of message goes through >> `set-message-function'. In particular, things like >> >> (signal 'end-of-buffer nil) >> >> write to the echo area but do not trigger set-message-function. >> >> This is a bit unexpected. Is there an equivalent hook for >> error messages going to the echo area? > > (set-message-function _does_ affect echo-area messages, just not any > kind of them.) OK, point taken. > Are you sure it is a good idea to allow running arbitrary Lisp when > Emacs wants to signal an error? My motivation is that I am trying to redirect echo area messages to an external display. Why? Think of it like Emacspeak for braille users. When I press M-< "Mark set" is displayed, but if I press cursor up, "Beginning of buffer" is not. This seems arbitrary. I realize that signals which pop up the debugger / backtrace might be problematic to interfere with, but... The messages from `user-error' and those error symbols which only display an echo area message should be easier to programmatically see IMO. -- CYa, ⡍⠁⠗⠊⠕ ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Why does signaling an error not call set-message-function? 2022-04-05 12:05 ` Mario Lang @ 2022-04-05 12:21 ` Eli Zaretskii 2022-04-05 12:55 ` Mario Lang 2022-04-05 13:14 ` Stefan Monnier 0 siblings, 2 replies; 12+ messages in thread From: Eli Zaretskii @ 2022-04-05 12:21 UTC (permalink / raw) To: Mario Lang; +Cc: emacs-devel > From: Mario Lang <mlang@blind.guru> > Date: Tue, 05 Apr 2022 14:05:00 +0200 > > > Are you sure it is a good idea to allow running arbitrary Lisp when > > Emacs wants to signal an error? > > My motivation is that I am trying to redirect echo area messages to an > external display. Why? Think of it like Emacspeak for braille users. > When I press M-< "Mark set" is displayed, > but if I press cursor up, "Beginning of buffer" is not. > This seems arbitrary. I realize that signals which pop up the > debugger / backtrace might be problematic to interfere with, but... > The messages from `user-error' and those error symbols which only > display an echo area message should be easier to programmatically see IMO. AFAIR, the set-message-function feature is explicitly for controlling the output that goes via calls to 'message'. Maybe we should emphasize this in the doc string. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Why does signaling an error not call set-message-function? 2022-04-05 12:21 ` Eli Zaretskii @ 2022-04-05 12:55 ` Mario Lang 2022-04-05 13:58 ` T.V Raman 2022-04-05 13:14 ` Stefan Monnier 1 sibling, 1 reply; 12+ messages in thread From: Mario Lang @ 2022-04-05 12:55 UTC (permalink / raw) To: emacs-devel; +Cc: raman Eli Zaretskii <eliz@gnu.org> writes: >> From: Mario Lang <mlang@blind.guru> >> Date: Tue, 05 Apr 2022 14:05:00 +0200 >> >> > Are you sure it is a good idea to allow running arbitrary Lisp when >> > Emacs wants to signal an error? >> >> My motivation is that I am trying to redirect echo area messages to an >> external display. Why? Think of it like Emacspeak for braille users. >> When I press M-< "Mark set" is displayed, >> but if I press cursor up, "Beginning of buffer" is not. >> This seems arbitrary. I realize that signals which pop up the >> debugger / backtrace might be problematic to interfere with, but... >> The messages from `user-error' and those error symbols which only >> display an echo area message should be easier to programmatically see IMO. > > AFAIR, the set-message-function feature is explicitly for controlling > the output that goes via calls to 'message'. Maybe we should > emphasize this in the doc string. OK, I get it, `set-message-function' is for `message' only. @Raman: How do you solve this in Emacspeak? IOW, if (user-error "foo") or (signal 'beginning-of-buffer nil) are called, how does Emacspeak collect the resulting echo area output? The only hack I can think of is to advice `user-error' and `signal', and DTRT if `signal' is called with a symbol that has an error-message slot. -- CYa, ⡍⠁⠗⠊⠕ ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Why does signaling an error not call set-message-function? 2022-04-05 12:55 ` Mario Lang @ 2022-04-05 13:58 ` T.V Raman 0 siblings, 0 replies; 12+ messages in thread From: T.V Raman @ 2022-04-05 13:58 UTC (permalink / raw) To: mlang; +Cc: emacs-devel, raman Se the relevant code in module emacspeak-advice.el Mario Lang writes: > Eli Zaretskii <eliz@gnu.org> writes: > > >> From: Mario Lang <mlang@blind.guru> > >> Date: Tue, 05 Apr 2022 14:05:00 +0200 > >> > >> > Are you sure it is a good idea to allow running arbitrary Lisp when > >> > Emacs wants to signal an error? > >> > >> My motivation is that I am trying to redirect echo area messages to an > >> external display. Why? Think of it like Emacspeak for braille users. > >> When I press M-< "Mark set" is displayed, > >> but if I press cursor up, "Beginning of buffer" is not. > >> This seems arbitrary. I realize that signals which pop up the > >> debugger / backtrace might be problematic to interfere with, but... > >> The messages from `user-error' and those error symbols which only > >> display an echo area message should be easier to programmatically see IMO. > > > > AFAIR, the set-message-function feature is explicitly for controlling > > the output that goes via calls to 'message'. Maybe we should > > emphasize this in the doc string. > > OK, I get it, `set-message-function' is for `message' only. > > @Raman: How do you solve this in Emacspeak? > IOW, if (user-error "foo") or (signal 'beginning-of-buffer nil) are > called, how does Emacspeak collect the resulting echo area output? > > The only hack I can think of is to advice `user-error' > and `signal', and DTRT if `signal' is called with a symbol that has an > error-message slot. > > -- > CYa, > ⡍⠁⠗⠊⠕ -- Thanks, --Raman(I Search, I Find, I Misplace, I Research) ♉ Id: kg:/m/0285kf1 🦮 -- Thanks, --Raman(I Search, I Find, I Misplace, I Research) ♉ Id: kg:/m/0285kf1 🦮 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Why does signaling an error not call set-message-function? 2022-04-05 12:21 ` Eli Zaretskii 2022-04-05 12:55 ` Mario Lang @ 2022-04-05 13:14 ` Stefan Monnier 2022-04-05 13:20 ` Eli Zaretskii 1 sibling, 1 reply; 12+ messages in thread From: Stefan Monnier @ 2022-04-05 13:14 UTC (permalink / raw) To: Eli Zaretskii; +Cc: Mario Lang, emacs-devel > AFAIR, the set-message-function feature is explicitly for controlling > the output that goes via calls to 'message'. Maybe we should > emphasize this in the doc string. OTOH which echo-area message goes through `message` and which goes through some lower-level C function is largely an implementation detail (e.g. in order to know that uncaught errors get displayed without going through `message` the user has to read the C code, AFAICT), so I think it makes sense to try and make sure we go through `set-message-function` whenever possible. Stefan ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Why does signaling an error not call set-message-function? 2022-04-05 13:14 ` Stefan Monnier @ 2022-04-05 13:20 ` Eli Zaretskii 2022-04-05 13:34 ` Stefan Monnier 0 siblings, 1 reply; 12+ messages in thread From: Eli Zaretskii @ 2022-04-05 13:20 UTC (permalink / raw) To: Stefan Monnier; +Cc: mlang, emacs-devel > From: Stefan Monnier <monnier@iro.umontreal.ca> > Cc: Mario Lang <mlang@blind.guru>, emacs-devel@gnu.org > Date: Tue, 05 Apr 2022 09:14:58 -0400 > > > AFAIR, the set-message-function feature is explicitly for controlling > > the output that goes via calls to 'message'. Maybe we should > > emphasize this in the doc string. > > OTOH which echo-area message goes through `message` and which goes > through some lower-level C function is largely an implementation detail > (e.g. in order to know that uncaught errors get displayed without going > through `message` the user has to read the C code, AFAICT), so I think > it makes sense to try and make sure we go through `set-message-function` > whenever possible. But not when we signal an error, surely? ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Why does signaling an error not call set-message-function? 2022-04-05 13:20 ` Eli Zaretskii @ 2022-04-05 13:34 ` Stefan Monnier 2022-04-05 13:39 ` Eli Zaretskii 0 siblings, 1 reply; 12+ messages in thread From: Stefan Monnier @ 2022-04-05 13:34 UTC (permalink / raw) To: Eli Zaretskii; +Cc: mlang, emacs-devel > But not when we signal an error, surely? Why not? I don't see a problem running arbitrary ELisp code at that time. After all, we already exited the error-signaling context, and we'll run arbitrary ELisp code right after, e.g. for `post-command-hook`, for the next command, etc... Stefan ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Why does signaling an error not call set-message-function? 2022-04-05 13:34 ` Stefan Monnier @ 2022-04-05 13:39 ` Eli Zaretskii 2022-04-05 14:19 ` Stefan Monnier 0 siblings, 1 reply; 12+ messages in thread From: Eli Zaretskii @ 2022-04-05 13:39 UTC (permalink / raw) To: Stefan Monnier; +Cc: mlang, emacs-devel > From: Stefan Monnier <monnier@iro.umontreal.ca> > Cc: mlang@blind.guru, emacs-devel@gnu.org > Date: Tue, 05 Apr 2022 09:34:03 -0400 > > > But not when we signal an error, surely? > > Why not? > > I don't see a problem running arbitrary ELisp code at that time. > > After all, we already exited the error-signaling context We did? ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Why does signaling an error not call set-message-function? 2022-04-05 13:39 ` Eli Zaretskii @ 2022-04-05 14:19 ` Stefan Monnier 2022-04-05 16:07 ` T.V Raman 0 siblings, 1 reply; 12+ messages in thread From: Stefan Monnier @ 2022-04-05 14:19 UTC (permalink / raw) To: Eli Zaretskii; +Cc: mlang, emacs-devel >> I don't see a problem running arbitrary ELisp code at that time. >> After all, we already exited the error-signaling context > We did? You made me doubt, but indeed I see: Lisp_Object command_loop_2 (Lisp_Object handlers) { register Lisp_Object val; do val = internal_condition_case (command_loop_1, handlers, cmd_error); while (!NILP (val)); return Qnil; } So `cmd_error` is run after we exit the error-signaling context. Also while looking at it, I saw tht `cmd_error` then calls `cmd_error_internal` which calls `command-error-function`: command-error-function is a variable defined in ‘C source code’. Its value is ‘help-command-error-confusable-suggestions’ Function to output error messages. Called with three arguments: - the error data, a list of the form (SIGNALED-CONDITION . SIGNAL-DATA) such as what ‘condition-case’ would bind its variable to, - the context (a string which normally goes at the start of the message), - the Lisp function within which the error was signaled. Also see ‘set-message-function’ (which controls how non-error messages are displayed). So we do already allow running arbitrary ELisp code in there ;-) Stefan ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Why does signaling an error not call set-message-function? 2022-04-05 14:19 ` Stefan Monnier @ 2022-04-05 16:07 ` T.V Raman 0 siblings, 0 replies; 12+ messages in thread From: T.V Raman @ 2022-04-05 16:07 UTC (permalink / raw) To: Stefan Monnier; +Cc: Eli Zaretskii, mlang, emacs-devel [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain; charset=gb18030, Size: 1965 bytes --] Stefan Monnier <monnier@iro.umontreal.ca> writes: Emacspeak in module emacspeak-advice.el https://github.com/tvraman/emacspeak/blob/master/lisp/emacspeak-advice.el#L819 uses the following lines to handle this: (defun emacspeak-error-handler (data context _calling-function) "Emacspeak custom error handler." (emacspeak-auditory-icon 'warn-user) (message "%s %s" (or context " ") (error-message-string data))) >>> I don't see a problem running arbitrary ELisp code at that time. >>> After all, we already exited the error-signaling context >> We did? > > You made me doubt, but indeed I see: > > Lisp_Object > command_loop_2 (Lisp_Object handlers) > { > register Lisp_Object val; > > do > val = internal_condition_case (command_loop_1, handlers, cmd_error); > while (!NILP (val)); > > return Qnil; > } > > So `cmd_error` is run after we exit the error-signaling context. > Also while looking at it, I saw tht `cmd_error` then calls > `cmd_error_internal` which calls `command-error-function`: > > command-error-function is a variable defined in ¡®C source code¡¯. > > Its value is ¡®help-command-error-confusable-suggestions¡¯ > > Function to output error messages. > Called with three arguments: > - the error data, a list of the form (SIGNALED-CONDITION . SIGNAL-DATA) > such as what ¡®condition-case¡¯ would bind its variable to, > - the context (a string which normally goes at the start of the message), > - the Lisp function within which the error was signaled. > > Also see ¡®set-message-function¡¯ (which controls how non-error messages > are displayed). > > So we do already allow running arbitrary ELisp code in there ;-) > > > Stefan > > -- Thanks, --Raman(I Search, I Find, I Misplace, I Research) 7©4 Id: kg:/m/0285kf1 0Ü8 ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2022-04-05 16:07 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-04-05 8:01 Why does signaling an error not call set-message-function? Mario Lang 2022-04-05 11:38 ` Eli Zaretskii 2022-04-05 12:05 ` Mario Lang 2022-04-05 12:21 ` Eli Zaretskii 2022-04-05 12:55 ` Mario Lang 2022-04-05 13:58 ` T.V Raman 2022-04-05 13:14 ` Stefan Monnier 2022-04-05 13:20 ` Eli Zaretskii 2022-04-05 13:34 ` Stefan Monnier 2022-04-05 13:39 ` Eli Zaretskii 2022-04-05 14:19 ` Stefan Monnier 2022-04-05 16:07 ` T.V Raman
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).