From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#25111: (Inaccurate documentation of inhibit-modification-hooks) Date: Sat, 25 May 2019 10:36:55 -0400 Message-ID: <87sgt28ut4.fsf@gmail.com> References: <8360myl7ay.fsf@gnu.org> <87wpfbpual.fsf@russet.org.uk> <83eg1iiffm.fsf@gnu.org> <87pol1kon4.fsf@russet.org.uk> <83bmwlggix.fsf@gnu.org> <878trmxgjh.fsf@russet.org.uk> <83lgvlcet1.fsf@gnu.org> <20190519203119.GA5309@ACM> <87y32u908k.fsf@gmail.com> <20190525134407.GA10864@ACM> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="254434"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) Cc: 25111@debbugs.gnu.org, Phillip Lord To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat May 25 16:38:34 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hUXof-001448-Vv for geb-bug-gnu-emacs@m.gmane.org; Sat, 25 May 2019 16:38:34 +0200 Original-Received: from localhost ([127.0.0.1]:42823 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUXoe-0005Bq-V5 for geb-bug-gnu-emacs@m.gmane.org; Sat, 25 May 2019 10:38:32 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:56761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUXoD-0004yr-FF for bug-gnu-emacs@gnu.org; Sat, 25 May 2019 10:38:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hUXoB-0003P1-NW for bug-gnu-emacs@gnu.org; Sat, 25 May 2019 10:38:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35795) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hUXoB-0003Oq-Ii for bug-gnu-emacs@gnu.org; Sat, 25 May 2019 10:38:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hUXoB-0006SH-Do for bug-gnu-emacs@gnu.org; Sat, 25 May 2019 10:38:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 25 May 2019 14:38:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25111 X-GNU-PR-Package: emacs Original-Received: via spool by 25111-submit@debbugs.gnu.org id=B25111.155879502524713 (code B ref 25111); Sat, 25 May 2019 14:38:03 +0000 Original-Received: (at 25111) by debbugs.gnu.org; 25 May 2019 14:37:05 +0000 Original-Received: from localhost ([127.0.0.1]:49332 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hUXnF-0006QW-0I for submit@debbugs.gnu.org; Sat, 25 May 2019 10:37:05 -0400 Original-Received: from mail-it1-f182.google.com ([209.85.166.182]:38841) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hUXnD-0006Q3-5n for 25111@debbugs.gnu.org; Sat, 25 May 2019 10:37:03 -0400 Original-Received: by mail-it1-f182.google.com with SMTP id i63so17999394ita.3 for <25111@debbugs.gnu.org>; Sat, 25 May 2019 07:37:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=lAw61V5YPlrs+Bw1SsPS3trKyTQYr0zw72ZOEZa7R9U=; b=jfZl6TR5Gg4fE+kARvonoO4h1t2q5Z4oPhxqPGrO4Z7NHqZZ6f6bLoxCz8hWG/OE5m fHJ7qBe3rXV27vB1C1yQc3FOA1ZjcPIdvAB83DtGmzETrGbtg+tmwP6TS6E+uviu6azi DIQTo5t8IsiTQ18HjJhT1/eV+0r3mTuLBqo5Ar3XzrlkF9ETrDseuKCEP/r3u6cm9D9i 9g807d8yDQSPTmzPeX+0TKuS4n+Lehb4kYYqVKvgxJjO6Q+yGln+AXLFBIdRu6Vcafr2 nUmSNYkPQsQyaY2lSwZwc1MSRbJsd44P2A7QV0p72JnUvSUuREkeQa4ywN61X2V+qHWd lDCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=lAw61V5YPlrs+Bw1SsPS3trKyTQYr0zw72ZOEZa7R9U=; b=UTeFc0Lftj3YQGqZzFFVP0/g+VIOony1Agwg2bZJ72pLAAOKHl7HMZZyUZ88nqaVME YuxeqaOiDVcGwYyWL3b8cCmB6DQUF1RBXvcYX4cqW5pvVR8VYCXidVBF7zvjcm4ycSmV UcMl2KTB+CpANUaB2J4Cu+o3t550hDIt68co3vkn0xdYPDlt5DeX6jlw4OOP4bf/Tn6G 3MKdpj0qRs+PdzL9Uei4IUSzJKxsYtujS+dwGJyk/k3Jk0aR7hyKHz2T13NtfsCTTxRA 8fP5i96o8APUBvz85q+fmTPASVsqph7Bb2LDvYQChX71rB5Cl36OxPBsvAWlbJ7GVg8V avSQ== X-Gm-Message-State: APjAAAXHPgl1S5SYFIejN6UbYAFoQmgzBP+jN57KbDpQcUa6KdSH7Tka moFk6pQWD8XBUAcwN9TyA3w= X-Google-Smtp-Source: APXvYqxappfRR9ohRNLy02Z2oKF+oq3pIRcIZ8/wuVK940OZ3ErqxUQfyS3yXx7dlW29KE8NOMUD5A== X-Received: by 2002:a24:4415:: with SMTP id o21mr21697476ita.143.1558795017568; Sat, 25 May 2019 07:36:57 -0700 (PDT) Original-Received: from minid (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.gmail.com with ESMTPSA id q10sm1957155ioi.52.2019.05.25.07.36.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 25 May 2019 07:36:56 -0700 (PDT) In-Reply-To: <20190525134407.GA10864@ACM> (Alan Mackenzie's message of "Sat, 25 May 2019 13:44:07 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:159760 Archived-At: --=-=-= Content-Type: text/plain Alan Mackenzie 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: --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=bug-25111-binding-of-inhibit-mod-hooks.el Content-Description: testing inhibit-modification-hooks binding (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")) --=-=-= Content-Type: text/plain Which produces this: mod-hook-text-prop (1 4), inhibit? nil mod-hook-change-fun (1 4), inhibit? t mod-hook-ov-prop (# nil 1 4), inhibit? t mod-hook-change-fun (1 1 3), inhibit? t mod-hook-ov-prop (# 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Clarify-elisp-ref-for-inhibit-modification-hooks-Bug.patch Content-Description: patch >From 7f6453596b7753af7704eaac7f27ebba8d03cfc4 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie 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 --- 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 --=-=-=--