From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#30823: 25.3; modification-hooks of overlays are not run in some cases Date: Sat, 31 Mar 2018 09:51:53 -0400 Message-ID: <87in9cpd3a.fsf@gmail.com> References: <83lgetri7r.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1522504269 6442 195.159.176.226 (31 Mar 2018 13:51:09 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 31 Mar 2018 13:51:09 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) Cc: 30823@debbugs.gnu.org To: Ren Victor Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Mar 31 15:51:05 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f2GuP-0001Ze-28 for geb-bug-gnu-emacs@m.gmane.org; Sat, 31 Mar 2018 15:51:05 +0200 Original-Received: from localhost ([::1]:52053 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f2GwS-0006RZ-OV for geb-bug-gnu-emacs@m.gmane.org; Sat, 31 Mar 2018 09:53:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f2GwL-0006Q8-Hz for bug-gnu-emacs@gnu.org; Sat, 31 Mar 2018 09:53:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f2GwI-000284-Ef for bug-gnu-emacs@gnu.org; Sat, 31 Mar 2018 09:53:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:52801) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f2GwI-00027k-9N for bug-gnu-emacs@gnu.org; Sat, 31 Mar 2018 09:53:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1f2GwI-00008F-1c for bug-gnu-emacs@gnu.org; Sat, 31 Mar 2018 09:53:02 -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, 31 Mar 2018 13:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30823 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 30823-submit@debbugs.gnu.org id=B30823.1522504323444 (code B ref 30823); Sat, 31 Mar 2018 13:53:01 +0000 Original-Received: (at 30823) by debbugs.gnu.org; 31 Mar 2018 13:52:03 +0000 Original-Received: from localhost ([127.0.0.1]:60698 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f2GvL-00006s-5E for submit@debbugs.gnu.org; Sat, 31 Mar 2018 09:52:03 -0400 Original-Received: from mail-it0-f42.google.com ([209.85.214.42]:39490) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f2GvJ-000064-A0; Sat, 31 Mar 2018 09:52:01 -0400 Original-Received: by mail-it0-f42.google.com with SMTP id e98-v6so13988477itd.4; Sat, 31 Mar 2018 06:52:01 -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=efiXiqMbAtBGCD20hpywbnyLUcWAJcSspP0ReVSJDqE=; b=JXjOXVw9oV/caXi7pQg0lkQoR2AWKUCY/8u1ntyfpNBi491n9uJai8KIhyHt3Vzalu XtG4Ka6xA3QcRMaUm0OeeTkWcYpFzRHLDV4sX+1imxeNPByLd4q7mkiLiR1iyiUhSbye ouhDXgY9m9J0HNlZyCVAq9STq5wUKVXyPevQXNno4fJZ9SZdAzr/MDMzFay1JDvKUKaE M3esM2MUjEm+o2ioO4aG1BTjQzCurvgVAC+Oy6tn1ng6ZLCE3v/Vn/fNYNbcr6VWfd0V LraFwZOkSx2fvUNFz/VUxaTGLD/FLesxtnZiUxAPGOpIG4YFaNa4TeeuIbDgAs3p49fG PGRg== 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=efiXiqMbAtBGCD20hpywbnyLUcWAJcSspP0ReVSJDqE=; b=rM8KzrY/Kamnc7plejF5QiF1sOienVcPP9j/PAMkQJaPM7iMblxECj4ugaCq1NcAMu DwfzinjP8ksKRy+G9f3s3ZWyy/llsK3g66ht79YrJ0C14AiGKgVCJMBuAdAGSZkXhnSo RnBPJbyexOqGlEXNP6bzgyS/Fmqp9ORPaspm3tW8BBiezPctDnREpkZfY5KcW3lKdMLV RbqNXcITjFqVmVclYr0whCgQg5UHblXCMpW52sMZt/yRXbFkaK4o/2tGTEQoCIRMYA5v lbw15yaIbG3DyiF74EddqwVf1ROkAEnTqmDF2JfD5XGRoyIPie+vrdnbPJ9G+Oh74yxn IM/A== X-Gm-Message-State: ALQs6tD3PnqADiKWwki81FSrbJwNfEYgSsrkp2/wu+AcxPvN4/f9yux4 UAHgoygdaHet/czyhRRb8HjYrA== X-Google-Smtp-Source: AIpwx49IylrI7bVGgOdDtzMAUqG46HbY0s2MXL2IWpqMSwQ9uYjN1u4E7EEYS+yJuovV+cJ9tmdOdQ== X-Received: by 2002:a24:d3d0:: with SMTP id n199-v6mr6626010itg.141.1522504315501; Sat, 31 Mar 2018 06:51:55 -0700 (PDT) Original-Received: from zebian (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.googlemail.com with ESMTPSA id d1sm6142205ioj.76.2018.03.31.06.51.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 31 Mar 2018 06:51:54 -0700 (PDT) In-Reply-To: (Ren Victor's message of "Thu, 15 Mar 2018 15:29:52 +0800") 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: 208.118.235.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:144758 Archived-At: --=-=-= Content-Type: text/plain tags 30823 + patch quit Ren Victor writes: > I wrote a ert case which is encolsed. > > emacs -Q -batch -l ert -l bug30823.el -f ert-run-tests-batch-and-exit Thanks, this patch seems to fix it. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v1-0001-Don-t-skip-modification-hooks-if-1st-overlay-is-d.patch Content-Description: patch >From 41cb2b33bc62a23a0561b94f3d25e1282935a08c Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sat, 31 Mar 2018 09:33:41 -0400 Subject: [PATCH v1] Don't skip modification hooks if 1st overlay is deleted (Bug#30823) The fix for Bug#21824 "Don't invoke overlay modification hooks in wrong buffer" from 2015-11-06 prevented running of overlay hooks if the first overlay registered when running the hooks with after=nil was deleted (since a deleted overlay has no buffer, it was considered as not from the current buffer). Therefore, revert that change and instead just inhibit modification hooks when performing message coalescing (because in that case, we aren't doing the necessary preparation for running modification hooks, or even running them with after=nil at all). * src/buffer.c (report_overlay_modification): Remove checking of buffer overlay. * src/xdisp.c (message_dolog): Let-bind inhibit-modification-hooks to t around del_range_both calls * test/src/buffer-tests.el (test-modification-hooks): New test. --- src/buffer.c | 17 ----------------- src/xdisp.c | 9 +++++++++ test/src/buffer-tests.el | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index 14837372d3..a5d65da2e8 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -4543,23 +4543,6 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, bool after, Lisp_Object *copy; ptrdiff_t i; - if (size) - { - Lisp_Object ovl - = XVECTOR (last_overlay_modification_hooks)->contents[1]; - - /* If the buffer of the first overlay in the array doesn't - match the current buffer, then these modification hooks - should not be run in this buffer. This could happen when - some code calls some insdel functions, such as del_range_1, - with the PREPARE argument false -- in that case this - function is never called to record the overlay modification - hook functions in the last_overlay_modification_hooks - array, so anything we find there is not ours. */ - if (XMARKER (OVERLAY_START (ovl))->buffer != current_buffer) - return; - } - USE_SAFE_ALLOCA; SAFE_ALLOCA_LISP (copy, size); memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, diff --git a/src/xdisp.c b/src/xdisp.c index df5335e4ac..082b40b742 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -10403,6 +10403,13 @@ message_dolog (const char *m, ptrdiff_t nbytes, bool nlflag, bool multibyte) ptrdiff_t this_bol, this_bol_byte, prev_bol, prev_bol_byte; printmax_t dups; + /* Since we call del_range_both passing false for PREPARE, + we aren't prepared to run modification hooks (we could + end up calling modification hooks from another buffer and + only with AFTER=t, Bug#21824). */ + ptrdiff_t count = SPECPDL_INDEX (); + specbind (Qinhibit_modification_hooks, Qt); + insert_1_both ("\n", 1, 1, true, false, false); scan_newline (Z, Z_BYTE, BEG, BEG_BYTE, -2, false); @@ -10448,6 +10455,8 @@ message_dolog (const char *m, ptrdiff_t nbytes, bool nlflag, bool multibyte) -XFASTINT (Vmessage_log_max) - 1, false); del_range_both (BEG, BEG_BYTE, PT, PT_BYTE, false); } + + unbind_to (count, Qnil); } BEGV = marker_position (oldbegv); BEGV_BYTE = marker_byte_position (oldbegv); diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el index f9c477fbfd..5d091875b5 100644 --- a/test/src/buffer-tests.el +++ b/test/src/buffer-tests.el @@ -45,6 +45,25 @@ (should (eq buf (current-buffer)))) (when msg-ov (delete-overlay msg-ov)))))) +(ert-deftest test-modification-hooks () + "Test for bug#30823." + (let ((check-point nil) + (ov-delete nil) + (ov-set nil)) + (with-temp-buffer + (insert "abc") + (setq ov-set (make-overlay 1 3)) + (overlay-put ov-set 'modification-hooks + (list (lambda (_o after &rest _args) + (and after (setq check-point t))))) + (setq ov-delete (make-overlay 1 3)) + (overlay-put ov-delete 'modification-hooks + (list (lambda (o after &rest _args) + (and (not after) (delete-overlay o))))) + (goto-char 2) + (insert "1") + (should (eq check-point t))))) + (ert-deftest test-generate-new-buffer-name-bug27966 () (should-not (string-equal "nil" (progn (get-buffer-create "nil") -- 2.11.0 --=-=-=--