all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Undo defalias
@ 2023-02-28  1:23 Óscar Fuentes
  2023-02-28  9:17 ` Gregory Heytings
  2023-03-03 15:29 ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 16+ messages in thread
From: Óscar Fuentes @ 2023-02-28  1:23 UTC (permalink / raw)
  To: help-gnu-emacs

Somehow `message' ended aliased to `ignore':

C-h f message

message is an alias for ‘ignore’.
...

To repair this damage (without restarting Emacs) usually I would go to
the definition of `message' and evaluate it, but this function is
defined in C.

How could I bind back `message' to its original function definition?




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Undo defalias
  2023-02-28  1:23 Undo defalias Óscar Fuentes
@ 2023-02-28  9:17 ` Gregory Heytings
  2023-02-28 15:56   ` Óscar Fuentes
  2023-03-03 15:29 ` Stefan Monnier via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 16+ messages in thread
From: Gregory Heytings @ 2023-02-28  9:17 UTC (permalink / raw)
  To: Óscar Fuentes; +Cc: help-gnu-emacs


>
> Somehow `message' ended aliased to `ignore':
>
> C-h f message
>
> message is an alias for ‘ignore’.
> ...
>
> To repair this damage (without restarting Emacs) usually I would go to 
> the definition of `message' and evaluate it, but this function is 
> defined in C.
>
> How could I bind back `message' to its original function definition?
>

(defmacro undefalias (symbol)
   `(progn
      (fset ,symbol (cadr (get ,symbol 'function-history)))
      (put ,symbol 'function-history (cddr (get ,symbol 'function-history)))))


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Undo defalias
  2023-02-28  9:17 ` Gregory Heytings
@ 2023-02-28 15:56   ` Óscar Fuentes
  2023-03-01 20:36     ` Emanuel Berg
  0 siblings, 1 reply; 16+ messages in thread
From: Óscar Fuentes @ 2023-02-28 15:56 UTC (permalink / raw)
  To: help-gnu-emacs

Gregory Heytings <gregory@heytings.org> writes:

>>
>> Somehow `message' ended aliased to `ignore':
>>
>> C-h f message
>>
>> message is an alias for ‘ignore’.
>> ...
>>
>> To repair this damage (without restarting Emacs) usually I would go
>> to the definition of `message' and evaluate it, but this function is
>> defined in C.
>>
>> How could I bind back `message' to its original function definition?
>>
>
> (defmacro undefalias (symbol)
>   `(progn
>      (fset ,symbol (cadr (get ,symbol 'function-history)))
>      (put ,symbol 'function-history (cddr (get ,symbol 'function-history)))))

Thank you. It didn't work on the affected Emacs session ( (message "foo)
throwed "Symbol’s function definition is void: message"), most likely
because of my previous attempts of fixing it, but it works on emacs -Q.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Undo defalias
  2023-02-28 15:56   ` Óscar Fuentes
@ 2023-03-01 20:36     ` Emanuel Berg
  0 siblings, 0 replies; 16+ messages in thread
From: Emanuel Berg @ 2023-03-01 20:36 UTC (permalink / raw)
  To: help-gnu-emacs

Óscar Fuentes wrote:

>> (defmacro undefalias (symbol)
>>   `(progn
>>      (fset ,symbol (cadr (get ,symbol 'function-history)))
>>      (put ,symbol 'function-history (cddr (get ,symbol 'function-history)))))
>
> Thank you. It didn't work on the affected Emacs session (
> (message "foo) throwed "Symbol’s function definition is
> void: message"), most likely because of my previous attempts
> of fixing it, but it works on emacs -Q.

Something like that is maybe something to add to vanilla
Emacs, even.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Undo defalias
  2023-02-28  1:23 Undo defalias Óscar Fuentes
  2023-02-28  9:17 ` Gregory Heytings
@ 2023-03-03 15:29 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2023-03-03 15:37   ` Gregory Heytings
  2023-03-03 16:00   ` Óscar Fuentes
  1 sibling, 2 replies; 16+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2023-03-03 15:29 UTC (permalink / raw)
  To: help-gnu-emacs

> Somehow `message' ended aliased to `ignore':

That'd be a bug.
Probably a piece of code intended to do that temporarily but the
restoration code failed or failed to be run.

It'd be good to track it down and get the code fixed.

> How could I bind back `message' to its original function definition?

Depends on how it got set to `ignore` (you can try exiting from
a recursive edit or a minibuffer), but in many cases it's impossible:
the #<subr message> object may simply not be reachable from anywhere any
more :-(


        Stefan




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Undo defalias
  2023-03-03 15:29 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2023-03-03 15:37   ` Gregory Heytings
  2023-03-03 15:49     ` Stefan Monnier via Users list for the GNU Emacs text editor
  2023-03-03 16:00   ` Óscar Fuentes
  1 sibling, 1 reply; 16+ messages in thread
From: Gregory Heytings @ 2023-03-03 15:37 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs


>
> Depends on how it got set to `ignore` (you can try exiting from a 
> recursive edit or a minibuffer), but in many cases it's impossible: the 
> #<subr message> object may simply not be reachable from anywhere any 
> more :-(
>

It is: see the short POC code I posted.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Undo defalias
  2023-03-03 15:37   ` Gregory Heytings
@ 2023-03-03 15:49     ` Stefan Monnier via Users list for the GNU Emacs text editor
  2023-03-03 15:52       ` Eli Zaretskii
  2023-03-03 16:01       ` Gregory Heytings
  0 siblings, 2 replies; 16+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2023-03-03 15:49 UTC (permalink / raw)
  To: help-gnu-emacs

>> Depends on how it got set to `ignore` (you can try exiting from
>> a recursive edit or a minibuffer), but in many cases it's impossible: the
>> #<subr message> object may simply not be reachable from anywhere any
>> more :-(
> It is: see the short POC code I posted.

The POC you posted works only if `message` was redefined in some
particular way, such as when a loading a file that has

    (defalias 'message #'ignore)

but then it wouldn't be the result of a bug but of deliberate harm :-)
AFAIK most cases where `message` can end up aliased to `ignore` is when
you have code doing

    (cl-letf (((symbol-function 'message) #'ignore))
      ...)

In that case, the previous value won't be found in `function-history`.
As for why is the `ignore` rebinding is still active...


        Stefan




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Undo defalias
  2023-03-03 15:49     ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2023-03-03 15:52       ` Eli Zaretskii
  2023-03-03 16:01       ` Gregory Heytings
  1 sibling, 0 replies; 16+ messages in thread
From: Eli Zaretskii @ 2023-03-03 15:52 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Fri, 03 Mar 2023 10:49:57 -0500
> From:  Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
> 
> AFAIK most cases where `message` can end up aliased to `ignore` is when
> you have code doing
> 
>     (cl-letf (((symbol-function 'message) #'ignore))
>       ...)
> 
> In that case, the previous value won't be found in `function-history`.

Maybe we should modify cl-letf (and other methods, if any) to record
the changes in function-history?



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Undo defalias
  2023-03-03 15:29 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2023-03-03 15:37   ` Gregory Heytings
@ 2023-03-03 16:00   ` Óscar Fuentes
  2023-03-03 16:17     ` Gregory Heytings
  2023-03-03 16:33     ` Stefan Monnier via Users list for the GNU Emacs text editor
  1 sibling, 2 replies; 16+ messages in thread
From: Óscar Fuentes @ 2023-03-03 16:00 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

>> Somehow `message' ended aliased to `ignore':
>
> That'd be a bug.
> Probably a piece of code intended to do that temporarily but the
> restoration code failed or failed to be run.
>
> It'd be good to track it down and get the code fixed.

The problem was caused by aggressive-indent-mode.el. It uses

(cl-letf (((symbol-function 'message) #'ignore))
 ...

There is a PR for changing it to

(let ((inhibit-message t))
 ...

which hopefully will be more robust.

>> How could I bind back `message' to its original function definition?
>
> Depends on how it got set to `ignore` (you can try exiting from
> a recursive edit or a minibuffer), but in many cases it's impossible:
> the #<subr message> object may simply not be reachable from anywhere any
> more :-(

That was what I expected, although Gregory's solution works for the case
you apply it right after

(defalias 'message 'ignore)

Tested on emacs -Q version 30.0.50.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Undo defalias
  2023-03-03 15:49     ` Stefan Monnier via Users list for the GNU Emacs text editor
  2023-03-03 15:52       ` Eli Zaretskii
@ 2023-03-03 16:01       ` Gregory Heytings
  1 sibling, 0 replies; 16+ messages in thread
From: Gregory Heytings @ 2023-03-03 16:01 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs


>
> The POC you posted works only if `message` was redefined in some 
> particular way, such as when a loading a file that has
>
> (defalias 'message #'ignore)
>
> but then it wouldn't be the result of a bug but of deliberate harm :-)
>

My understanding is that this is what the OP did, and he wanted to "undo" 
what he did.  With a Lisp function you can always open the source file 
again and C-M-x, but with a C function that's not possible.

>
> AFAIK most cases where `message` can end up aliased to `ignore` is when 
> you have code doing
>
> (cl-letf (((symbol-function 'message) #'ignore))
>   ...)
>
> In that case, the previous value won't be found in `function-history`. 
> As for why is the `ignore` rebinding is still active...
>

But in that case the meaning of message is restored when the cl-letf is 
left, no?  Am I missing something?




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Undo defalias
  2023-03-03 16:00   ` Óscar Fuentes
@ 2023-03-03 16:17     ` Gregory Heytings
  2023-03-03 16:33     ` Stefan Monnier via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 16+ messages in thread
From: Gregory Heytings @ 2023-03-03 16:17 UTC (permalink / raw)
  To: Óscar Fuentes; +Cc: help-gnu-emacs


>
> The problem was caused by aggressive-indent-mode.el. It uses
>
> (cl-letf (((symbol-function 'message) #'ignore))
>

How comes that the meaning of message is not restored after cl-letf?  Its 
docstring says: "On exit, either normally or because of a `throw' or 
error, the PLACEs are set back to their original values."




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Undo defalias
  2023-03-03 16:00   ` Óscar Fuentes
  2023-03-03 16:17     ` Gregory Heytings
@ 2023-03-03 16:33     ` Stefan Monnier via Users list for the GNU Emacs text editor
  2023-03-03 21:11       ` Óscar Fuentes
  2023-03-03 22:58       ` Gregory Heytings
  1 sibling, 2 replies; 16+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2023-03-03 16:33 UTC (permalink / raw)
  To: help-gnu-emacs

> The problem was caused by aggressive-indent-mode.el. It uses
>
> (cl-letf (((symbol-function 'message) #'ignore))
>  ...

So either:
- you're still within the `cl-letf`.  In that case
  `abort-recursive-edit` or some such should fix the problem.
- you're not within the `cl-letf` any more, in which case the question
  becomes: how come `cl-letf` didn't restore the previous value?
  `cl-letf` uses `unwind-protect` so it should restore the previous
  binding reliably even in case of errors.

[ There's admittedly the possibility/risk that you hit `C-g` (or some
  similar error occurred) right at the specific moment when `cl-letf`
  was executing the second part of the `unwind-protect` (i.e. the one
  that reset `message` to its previous definition).
  That's a known hole in our system.  ]


        Stefan




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Undo defalias
  2023-03-03 16:33     ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2023-03-03 21:11       ` Óscar Fuentes
  2023-03-05  9:32         ` Madhu
  2023-03-03 22:58       ` Gregory Heytings
  1 sibling, 1 reply; 16+ messages in thread
From: Óscar Fuentes @ 2023-03-03 21:11 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

>> The problem was caused by aggressive-indent-mode.el. It uses
>>
>> (cl-letf (((symbol-function 'message) #'ignore))
>>  ...
>
> So either:
> - you're still within the `cl-letf`.  In that case
>   `abort-recursive-edit` or some such should fix the problem.

I don't have the problematic session around anymore, but I recall seeing
a *Backtrace* buffer among the list of existing buffers. However, IIRC
Emacs says that a recursive edit is active and that indication was not
there.

> - you're not within the `cl-letf` any more, in which case the question
>   becomes: how come `cl-letf` didn't restore the previous value?
>   `cl-letf` uses `unwind-protect` so it should restore the previous
>   binding reliably even in case of errors.
>
> [ There's admittedly the possibility/risk that you hit `C-g` (or some
>   similar error occurred) right at the specific moment when `cl-letf`
>   was executing the second part of the `unwind-protect` (i.e. the one
>   that reset `message` to its previous definition).
>   That's a known hole in our system.  ]

That's also quite plausible, indeed. I tend to use C-g quite frequently.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Undo defalias
  2023-03-03 16:33     ` Stefan Monnier via Users list for the GNU Emacs text editor
  2023-03-03 21:11       ` Óscar Fuentes
@ 2023-03-03 22:58       ` Gregory Heytings
  2023-03-04  0:05         ` Stefan Monnier
  1 sibling, 1 reply; 16+ messages in thread
From: Gregory Heytings @ 2023-03-03 22:58 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs


>
> There's admittedly the possibility/risk that you hit `C-g` (or some 
> similar error occurred) right at the specific moment when `cl-letf` was 
> executing the second part of the `unwind-protect` (i.e. the one that 
> reset `message` to its previous definition).
>
> That's a known hole in our system.
>

Should we not inhibit-quit around the unwind-form of cl-letf to avoid 
this?  Otherwise the promise of cl-letf ("On exit, either normally or 
because of a `throw' or error, the PLACEs are set back to their original 
values.") is not fulfilled.  (And yes, I know that, even with 
inhibit-quit, it is still possible that a C-g would be processed just 
before we bind inhibit-quit.)




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Undo defalias
  2023-03-03 22:58       ` Gregory Heytings
@ 2023-03-04  0:05         ` Stefan Monnier
  0 siblings, 0 replies; 16+ messages in thread
From: Stefan Monnier @ 2023-03-04  0:05 UTC (permalink / raw)
  To: Gregory Heytings; +Cc: help-gnu-emacs

> Should we not inhibit-quit around the unwind-form of cl-letf to avoid this?
> Otherwise the promise of cl-letf ("On exit, either normally or because of
> a `throw' or error, the PLACEs are set back to their original values.") is
> not fulfilled.  (And yes, I know that, even with inhibit-quit, it is still
> possible that a C-g would be processed just before we bind inhibit-quit.)

As you point out, we can't solve it in ELisp.  Note that this also
affects plain old `let` (for dynamically-scoped vars), tho the
time-window is shorter.

I think we could solve it by using `inhibit-quit` during `unbind_to`,
but that's a pretty significant change.  It might be The Right Thing to
do, tho.


        Stefan





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Undo defalias
  2023-03-03 21:11       ` Óscar Fuentes
@ 2023-03-05  9:32         ` Madhu
  0 siblings, 0 replies; 16+ messages in thread
From: Madhu @ 2023-03-05  9:32 UTC (permalink / raw)
  To: help-gnu-emacs

* Óscar Fuentes <87r0u5czgg.fsf @telefonica.net> :
Wrote on Fri, 03 Mar 2023 22:11:27 +0100:

> I don't have the problematic session around anymore, but I recall seeing
> a *Backtrace* buffer among the list of existing buffers. However, IIRC
> Emacs says that a recursive edit is active and that indication was not
> there.
>> [ There's admittedly the possibility/risk that you hit `C-g` (or some
>>   similar error occurred) right at the specific moment when `cl-letf`
>>   was executing the second part of the `unwind-protect` (i.e. the one
>>   that reset `message` to its previous definition).
>>   That's a known hole in our system.  ]
>
> That's also quite plausible, indeed. I tend to use C-g quite frequently.

Many a time in emacs-29.50.x I've got into the situation where I haven't
been able to return from a recursive-edit. i.e. (minibuffer-depth) is
never 0, and with minibuffer-depth-indicate-mode I'd always see a [2] in
the minibuffer.  Admittedly this has happened less often recently.
Perhaps I was hitting this code path?




^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-03-05  9:32 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-28  1:23 Undo defalias Óscar Fuentes
2023-02-28  9:17 ` Gregory Heytings
2023-02-28 15:56   ` Óscar Fuentes
2023-03-01 20:36     ` Emanuel Berg
2023-03-03 15:29 ` Stefan Monnier via Users list for the GNU Emacs text editor
2023-03-03 15:37   ` Gregory Heytings
2023-03-03 15:49     ` Stefan Monnier via Users list for the GNU Emacs text editor
2023-03-03 15:52       ` Eli Zaretskii
2023-03-03 16:01       ` Gregory Heytings
2023-03-03 16:00   ` Óscar Fuentes
2023-03-03 16:17     ` Gregory Heytings
2023-03-03 16:33     ` Stefan Monnier via Users list for the GNU Emacs text editor
2023-03-03 21:11       ` Óscar Fuentes
2023-03-05  9:32         ` Madhu
2023-03-03 22:58       ` Gregory Heytings
2023-03-04  0:05         ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.