* Why is `after-change-functions' reset?
@ 2014-02-17 18:35 Michael Heerdegen
2014-02-17 22:11 ` Kalle Olavi Niemitalo
2014-02-17 23:49 ` Stefan Monnier
0 siblings, 2 replies; 5+ messages in thread
From: Michael Heerdegen @ 2014-02-17 18:35 UTC (permalink / raw
To: emacs-devel
Hello,
I'm working on a library that adds a function to
`after-change-functions'.
After some time, the thing stops working. I look at the value of
`after-change-functions' and my added function is missing.
So I thought there would have been some error that caused
`after-change-functions' to be reset. But I can preclude that - there
is no error, no error message, etc.
I had a hard time to find some recipe for emacs -Q. Here it comes:
--8<---------------cut here---------------start------------->8---
(progn
(defun foo (&rest _) ())
(add-hook 'after-change-functions 'foo)
(defun complain ()
(when (not (memq 'foo (default-value 'after-change-functions)))
(message "Why does this happen?")
(cancel-timer complain-timer)))
(defvar complain-timer
(run-with-idle-timer .03 .03 #'complain))
(require 'cl-lib)
(completing-read "Hit tab and C-g: "
(cl-loop for i from 1 to 100000
collect (format "%d" i))))
--8<---------------cut here---------------end--------------->8---
Evaluate it and hit tab (for completion) and C-g C-g in succession.
When you repeat this a few times, you get "Why does this happen?".
Is this expected behavior? In my original situation, quitting was not
involved, the above recipe was just the first reproducible program I had
discovered.
Thanks,
Michael.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Why is `after-change-functions' reset?
2014-02-17 18:35 Why is `after-change-functions' reset? Michael Heerdegen
@ 2014-02-17 22:11 ` Kalle Olavi Niemitalo
2014-02-18 17:50 ` Michael Heerdegen
2014-02-17 23:49 ` Stefan Monnier
1 sibling, 1 reply; 5+ messages in thread
From: Kalle Olavi Niemitalo @ 2014-02-17 22:11 UTC (permalink / raw
To: Emacs developers
Michael Heerdegen <michael_heerdegen@web.de> writes:
> Evaluate it and hit tab (for completion) and C-g C-g in succession.
> When you repeat this a few times, you get "Why does this happen?".
I debugged this a bit, with my custom Emacs 23.0.51. I don't
know how much this machinery has changed in later versions.
Emacs set Vquit_flag at:
handle_interrupt
tty_read_avail_input
read_avail_input
handle_async_input
input_available_signal
<signal handler called>
mark_object
Fgarbage_collect
Ffuncall
run_hook_list_with_args
signal_after_change
Fadd_text_properties
Fput_text_property
Fdisplay_completion_list
internal_with_output_to_temp_buffer
Fminibuffer_completion_help
do_completion
Fminibuffer_complete
Ffuncall
Fcall_interactively
After Fgarbage_collect returned, Ffuncall called funcall_lambda,
in which the QUIT macro detected the non-nil value of Vquit_flag
and called Fsignal (Qquit, Qnil). Because the quit was signaled
within signal_after_change, after-change-functions were not
restored.
I don't see any reasonable way to prevent after-change-functions
from being reset like this.
> In my original situation, quitting was not involved, the above
> recipe was just the first reproducible program I had discovered.
Perhaps you could change your Emacs to break when the reset
happens, and always run it in a debugger. Make
signal_before_change and signal_after_change maintain some kind
of flag or nesting counter, and set conditional breakpoints in
Fthrow and Fsignal. That will get a false positive if the error
is caught within the hook; but I don't think it happens often.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Why is `after-change-functions' reset?
2014-02-17 18:35 Why is `after-change-functions' reset? Michael Heerdegen
2014-02-17 22:11 ` Kalle Olavi Niemitalo
@ 2014-02-17 23:49 ` Stefan Monnier
2014-02-17 23:57 ` Michael Heerdegen
1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2014-02-17 23:49 UTC (permalink / raw
To: Michael Heerdegen; +Cc: emacs-devel
[ Please make it a bug report. ]
> Evaluate it and hit tab (for completion) and C-g C-g in succession.
> When you repeat this a few times, you get "Why does this happen?".
I couldn't reproduce it. After the "Why does this happen?", if you do
M-: (default-value 'after-change-functions) RET what do you get?
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Why is `after-change-functions' reset?
2014-02-17 23:49 ` Stefan Monnier
@ 2014-02-17 23:57 ` Michael Heerdegen
0 siblings, 0 replies; 5+ messages in thread
From: Michael Heerdegen @ 2014-02-17 23:57 UTC (permalink / raw
To: Stefan Monnier; +Cc: emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> [ Please make it a bug report. ]
Ok, will do.
> > Evaluate it and hit tab (for completion) and C-g C-g in succession.
> > When you repeat this a few times, you get "Why does this happen?".
>
> I couldn't reproduce it.
It doesn't always happen, but after a few iterations, it'll happen
sooner or later for me.
> After the "Why does this happen?", if you do M-: (default-value
> 'after-change-functions) RET what do you get?
nil.
Michael.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-02-18 17:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-17 18:35 Why is `after-change-functions' reset? Michael Heerdegen
2014-02-17 22:11 ` Kalle Olavi Niemitalo
2014-02-18 17:50 ` Michael Heerdegen
2014-02-17 23:49 ` Stefan Monnier
2014-02-17 23:57 ` Michael Heerdegen
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.