From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#12426: 24.2.50; Emacs is closed unexpectedly after query-replace Date: Thu, 13 Sep 2012 19:47:31 +0300 Message-ID: <83zk4tvpi4.fsf@gnu.org> References: <837grzw0ek.fsf@gnu.org> <83627jvzd8.fsf@gnu.org> <50514C9C.8010004@yandex.ru> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1347554909 4914 80.91.229.3 (13 Sep 2012 16:48:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 13 Sep 2012 16:48:29 +0000 (UTC) Cc: 12426@debbugs.gnu.org To: Dmitry Antipov , Richard Stallman Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Sep 13 18:48:31 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TCCaa-0007me-5u for geb-bug-gnu-emacs@m.gmane.org; Thu, 13 Sep 2012 18:48:28 +0200 Original-Received: from localhost ([::1]:46605 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCCaW-00034G-I4 for geb-bug-gnu-emacs@m.gmane.org; Thu, 13 Sep 2012 12:48:24 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:42613) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCCaO-000318-2b for bug-gnu-emacs@gnu.org; Thu, 13 Sep 2012 12:48:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TCCaI-0003of-3l for bug-gnu-emacs@gnu.org; Thu, 13 Sep 2012 12:48:15 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:50788) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCCaI-0003oZ-0R for bug-gnu-emacs@gnu.org; Thu, 13 Sep 2012 12:48:10 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TCCb7-0004Ld-Un for bug-gnu-emacs@gnu.org; Thu, 13 Sep 2012 12:49:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 13 Sep 2012 16:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12426 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 12426-submit@debbugs.gnu.org id=B12426.134755490616672 (code B ref 12426); Thu, 13 Sep 2012 16:49:01 +0000 Original-Received: (at 12426) by debbugs.gnu.org; 13 Sep 2012 16:48:26 +0000 Original-Received: from localhost ([127.0.0.1]:60334 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TCCaX-0004Kp-BE for submit@debbugs.gnu.org; Thu, 13 Sep 2012 12:48:26 -0400 Original-Received: from mtaout22.012.net.il ([80.179.55.172]:41440) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TCCaT-0004Kf-AT for 12426@debbugs.gnu.org; Thu, 13 Sep 2012 12:48:23 -0400 Original-Received: from conversion-daemon.a-mtaout22.012.net.il by a-mtaout22.012.net.il (HyperSendmail v2007.08) id <0MAA00000RW5Z200@a-mtaout22.012.net.il> for 12426@debbugs.gnu.org; Thu, 13 Sep 2012 19:47:18 +0300 (IDT) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout22.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0MAA000B5RYTUA20@a-mtaout22.012.net.il>; Thu, 13 Sep 2012 19:47:18 +0300 (IDT) In-reply-to: <50514C9C.8010004@yandex.ru> X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:64241 Archived-At: > Date: Thu, 13 Sep 2012 07:01:48 +0400 > From: Dmitry Antipov > CC: dmoncayo@gmail.com, 12426@debbugs.gnu.org > > IIUC marker can have out-of-buffer-range position, but only somewhere in the > middle of an insertion/deletion/replace operation; out-of-range position should > be detected and immediately fixed by adjust_markers_for_{delete,insert,replace}. But marker_position and marker_byte_position are simple getters of these two attributes of a marker. If these attributes can be out of range for some window of time, then the getters shouldn't enforce this limitation. Otherwise, they are getters that cannot be used in some situations, which is IMO bad SE. At the very least that should be documented. adjust_markers_for_* functions access the marker positions directly, bypassing these two getters. If we want to enforce the assertions you added, we should change OVERLAY_POSITION not to use the getter, but access the struct directly, too. > BTW, look at this code from replace_range: > > /* Adjust the overlay center as needed. This must be done after > adjusting the markers that bound the overlays. */ > adjust_overlays_for_delete (from, nchars_del); > adjust_overlays_for_insert (from, inschars); > > /* Adjust markers for the deletion and the insertion. */ > if (markers) > adjust_markers_for_replace (from, from_byte, nchars_del, nbytes_del, > inschars, outgoing_insbytes); > > The comment explicitly says that overlays should be adjusted _after_ markers, > but the code adjusts overlays and then markers :-(. Since an overlays are > bounded by markers, the comment looks correct but the code isn't. I suppose > that the code snippets above should be swapped. This was introduced in revision 40908 by Richard, and looks quite deliberate. So switching the order might not be TRT, especially since adjust_overlays_for_insert recenters the overlays around the buffer position in question, which makes access to overlays faster. I tried to look in the various related mailing lists for the reason of the change in revision 40908, but couldn't find anything appropriate. Richard, do you happen to remember the reason? The change and its log entry are below; it looks like this was accompanied by some changes in Lisp as well. 2001-11-11 Richard M. Stallman * insdel.c (replace_range): Use adjust_markers_for_replace instead of adjust_markers_for_delete and adjust_markers_for_insert. * intervals.h: Declare set_text_properties and set_text_properties_1. * textprop.c (set_text_properties_1): New subroutine broken out of set_text_properties. (set_text_properties): Use set_text_properties_1. * intervals.c (graft_intervals_into_buffer): Use set_text_properties_1 to clear out properties. * search.c (Freplace_match): Use replace_range to insert and delete. Don't request property inheritance from surrounding text. === modified file 'src/insdel.c' --- src/insdel.c 2001-10-26 12:02:21 +0000 +++ src/insdel.c 2001-11-11 20:04:45 +0000 @@ -1423,13 +1423,6 @@ replace_range (from, to, new, prepare, i if (! EQ (current_buffer->undo_list, Qt)) deletion = make_buffer_string_both (from, from_byte, to, to_byte, 1); - if (markers) - /* Relocate all markers pointing into the new, larger gap - to point at the end of the text before the gap. - Do this before recording the deletion, - so that undo handles this after reinserting the text. */ - adjust_markers_for_delete (from, from_byte, to, to_byte); - GAP_SIZE += nbytes_del; ZV -= nchars_del; Z -= nchars_del; @@ -1489,10 +1482,11 @@ replace_range (from, to, new, prepare, i adjusting the markers that bound the overlays. */ adjust_overlays_for_delete (from, nchars_del); adjust_overlays_for_insert (from, inschars); + + /* Adjust markers for the deletion and the insertion. */ if (markers) - adjust_markers_for_insert (from, from_byte, - from + inschars, from_byte + outgoing_insbytes, - 0); + adjust_markers_for_replace (from, from_byte, nchars_del, nbytes_del, + inschars, outgoing_insbytes); offset_intervals (current_buffer, from, inschars - nchars_del);