From: Noam Postavsky <npostavs@gmail.com>
To: Alan Mackenzie <acm@muc.de>
Cc: 25111@debbugs.gnu.org, Phillip Lord <phillip.lord@russet.org.uk>
Subject: bug#25111: (Inaccurate documentation of inhibit-modification-hooks)
Date: Sat, 25 May 2019 10:36:55 -0400 [thread overview]
Message-ID: <87sgt28ut4.fsf@gmail.com> (raw)
In-Reply-To: <20190525134407.GA10864@ACM> (Alan Mackenzie's message of "Sat, 25 May 2019 13:44:07 +0000")
[-- Attachment #1: Type: text/plain, Size: 508 bytes --]
Alan Mackenzie <acm@muc.de> writes:
>>> @@ -3621,9 +3621,14 @@ Special Properties
>
>>> +When Emacs calls these functions, @code{inhibit-modification-hooks} is
>>> +set to @code{nil}.
>
>> As Phillip mentioned in the OP, Emacs in fact binds it to t.
>
> Are you sure? We're talking here about the text property (in which I
> think inhibit-modification-hooks IS at nil) as opposed to the overlay
> property (where inhibit-modification-hooks is bound to t).
Oh, you're quite right. Here's some test code:
[-- Attachment #2: testing inhibit-modification-hooks binding --]
[-- Type: text/plain, Size: 788 bytes --]
(defun mod-hook-text-prop (&rest args)
(message "mod-hook-text-prop %S, inhibit? %S" args inhibit-modification-hooks))
(defun mod-hook-ov-prop (&rest args)
(message "mod-hook-ov-prop %S, inhibit? %S" args inhibit-modification-hooks))
(defun mod-hook-change-fun (&rest args)
(message "mod-hook-change-fun %S, inhibit? %S" args inhibit-modification-hooks))
(with-current-buffer (get-buffer-create "*test*")
(insert (propertize "foo\n" 'modification-hooks '(mod-hook-text-prop)))
(let ((ov (make-overlay (point-min) (point-max) )))
(overlay-put ov 'modification-hooks '(mod-hook-ov-prop)))
(setq-local before-change-functions '(mod-hook-change-fun))
(setq-local after-change-functions '(mod-hook-change-fun))
(goto-char (point-min))
(delete-char 3)
(insert "bar"))
[-- Attachment #3: Type: text/plain, Size: 605 bytes --]
Which produces this:
mod-hook-text-prop (1 4), inhibit? nil
mod-hook-change-fun (1 4), inhibit? t
mod-hook-ov-prop (#<overlay from 1 to 5 in *test*> nil 1 4), inhibit? t
mod-hook-change-fun (1 1 3), inhibit? t
mod-hook-ov-prop (#<overlay from 1 to 2 in *test*> t 1 1 3), inhibit? t
mod-hook-change-fun (1 1), inhibit? t
mod-hook-change-fun (1 4 0), inhibit? t
I think we need to emphasize the difference in this case, it's rather
confusing.
> I'll answer the rest of your post later, I've got a lot on in Real Life
> at the moment.
No rush. I've updated the patch based on your and Eli's feedback.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: patch --]
[-- Type: text/x-diff, Size: 3019 bytes --]
From 7f6453596b7753af7704eaac7f27ebba8d03cfc4 Mon Sep 17 00:00:00 2001
From: Alan Mackenzie <acm@muc.de>
Date: Sun, 19 May 2019 20:31:19 +0000
Subject: [PATCH] Clarify elisp ref for inhibit-modification-hooks (Bug#25111)
* doc/lispref/display.texi (Overlay Properties):
* doc/lispref/text.texi (Change Hooks): Explain that
inhibit-modification-hooks is bound to t while executing change hooks,
and suggest binding to nil with suitable precautions when modifying
buffer from a change hook.
(Special Properties): Emphasize that inhibit-modification-hooks is
left set to nil when executing text property change hooks.
Co-authored-by: Noam Postavsky <npostavs@gmail.com>
---
doc/lispref/display.texi | 6 +++---
doc/lispref/text.texi | 12 ++++++++----
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index b07999432c..59d02d540a 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -1708,9 +1708,9 @@ Overlay Properties
length is the number of characters deleted, and the post-change
beginning and end are equal.)
-If these functions modify the buffer, they should bind
-@code{inhibit-modification-hooks} to @code{t} around doing so, to
-avoid confusing the internal mechanism that calls these hooks.
+Similar to change hooks, when these functions are called,
+@code{inhibit-modification-hooks} is bound to @code{t}. @xref{Change
+Hooks}.
Text properties also support the @code{modification-hooks} property,
but the details are somewhat different (@pxref{Special Properties}).
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index f3d222b708..c935cfe49b 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -3514,9 +3514,10 @@ Special Properties
hook will only be run when removing some characters, replacing them
with others, or changing their text-properties.
-If these functions modify the buffer, they should bind
-@code{inhibit-modification-hooks} to @code{t} around doing so, to
-avoid confusing the internal mechanism that calls these hooks.
+When Emacs calls these functions, @code{inhibit-modification-hooks} is
+set to @code{nil}, unlike for change hooks. When writing a function
+which modifies the buffer, consider binding it @code{t}, to avoid
+recursive calls. @xref{Change Hooks}.
Overlays also support the @code{modification-hooks} property, but the
details are somewhat different (@pxref{Overlay Properties}).
@@ -5093,5 +5094,8 @@ Change Hooks
a modification hook does not cause other modification hooks to be run.
If you do want modification hooks to be run in a particular piece of
code that is itself run from a modification hook, then rebind locally
-@code{inhibit-modification-hooks} to @code{nil}.
+@code{inhibit-modification-hooks} to @code{nil}. However, doing this
+may cause recursive calls to the modification hooks, so be sure to
+prepare for that (for example, by binding some variable which tells
+your hook to do nothing).
@end defvar
--
2.11.0
next prev parent reply other threads:[~2019-05-25 14:36 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-04 20:53 bug#25111: Phillip Lord
2016-12-05 15:33 ` bug#25111: Eli Zaretskii
[not found] ` <87wpfbpual.fsf@russet.org.uk>
2016-12-07 16:40 ` bug#25111: Phillip Lord
[not found] ` <WM!2f8d5bad87de09a0621b1f025704a97dd719ed1ae7d08e03f6b419e215cd51bc54917b522795d7421de3533c07950608!@mailhub-mx1>
2016-12-08 15:55 ` bug#25111: Eli Zaretskii
2016-12-09 17:17 ` bug#25111: Phillip Lord
2016-12-09 17:26 ` bug#25111: Eli Zaretskii
2016-12-11 22:11 ` bug#25111: Phillip Lord
2016-12-12 16:06 ` bug#25111: Eli Zaretskii
2019-05-19 20:31 ` bug#25111: (Inaccurate documentation of inhibit-modification-hooks) Alan Mackenzie
2019-05-25 12:39 ` Noam Postavsky
2019-05-25 13:44 ` Alan Mackenzie
2019-05-25 14:36 ` Noam Postavsky [this message]
2019-05-27 14:31 ` Alan Mackenzie
2019-06-03 19:15 ` Alan Mackenzie
2019-06-03 19:26 ` npostavs
2019-06-04 9:32 ` Alan Mackenzie
2019-06-04 14:36 ` Eli Zaretskii
2019-06-09 12:00 ` Eli Zaretskii
2019-06-09 20:45 ` Alan Mackenzie
2019-06-24 12:52 ` Alan Mackenzie
2019-06-24 22:48 ` Noam Postavsky
2019-06-25 9:17 ` Alan Mackenzie
2019-05-25 13:49 ` Eli Zaretskii
2016-12-05 17:39 ` bug#25111: How modification-hooks let-bind inhibit-modification-hooks? Noam Postavsky
2016-12-05 18:37 ` Eli Zaretskii
2017-03-09 19:34 ` Noam Postavsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sgt28ut4.fsf@gmail.com \
--to=npostavs@gmail.com \
--cc=25111@debbugs.gnu.org \
--cc=acm@muc.de \
--cc=phillip.lord@russet.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.