From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#56682: feature/improved-locked-narrowing 9dee6df39c: Reworked locked narrowing. Date: Fri, 05 May 2023 18:26:05 +0300 Message-ID: <834joqiyuq.fsf@gnu.org> References: <166939872890.18950.12581667269687468681@vcs2.savannah.gnu.org> <83ttzsk6v4.fsf@gnu.org> <83wn4le8s3.fsf@gnu.org> <0f053182b02103503c26@heytings.org> <83pmaccnz7.fsf@gnu.org> <0f053182b04357300cb1@heytings.org> <83lel0chku.fsf@gnu.org> <0f053182b00a59a41caa@heytings.org> <835yc3cdhk.fsf@gnu.org> <9e9ed8043fc8bfe49bfe@heytings.org> <83h6vnaukn.fsf@gnu.org> <9e9ed8043f4ff9316461@heytings.org> <83k00exj56.fsf@gnu.org> <10ececa33f0a4af46fd2@heytings.org> <83edp3zwjk.fsf@gnu.org> <83r0t3y6yy.fsf@gnu.org> <83lejby3nk.fsf@gnu.org> <83h6tzy19k.fsf@gnu.org> <83bkk6yicv.fsf@gnu.org> <83jzxoll20.fsf@gnu.org> <221c67168567a20a89c1@heytings.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23603"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 56682@debbugs.gnu.org, monnier@iro.umontreal.ca To: Gregory Heytings Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri May 05 17:26:54 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1puxKg-0005va-E4 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 05 May 2023 17:26:54 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puxJv-0005Kj-Ud; Fri, 05 May 2023 11:26:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puxJq-0005Ft-I7 for bug-gnu-emacs@gnu.org; Fri, 05 May 2023 11:26:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1puxJq-0006iL-8h for bug-gnu-emacs@gnu.org; Fri, 05 May 2023 11:26:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1puxJq-0003nb-15 for bug-gnu-emacs@gnu.org; Fri, 05 May 2023 11:26:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 05 May 2023 15:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56682 X-GNU-PR-Package: emacs Original-Received: via spool by 56682-submit@debbugs.gnu.org id=B56682.168330032314525 (code B ref 56682); Fri, 05 May 2023 15:26:01 +0000 Original-Received: (at 56682) by debbugs.gnu.org; 5 May 2023 15:25:23 +0000 Original-Received: from localhost ([127.0.0.1]:57290 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1puxJC-0003mC-Oh for submit@debbugs.gnu.org; Fri, 05 May 2023 11:25:23 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:43564) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1puxJ9-0003lw-FL for 56682@debbugs.gnu.org; Fri, 05 May 2023 11:25:20 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puxJ3-0006Jk-22; Fri, 05 May 2023 11:25:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=7EIlLpGseCw+lBduLr6KffT/lRFgSci9K7F+8TNvW3E=; b=EP62Q79V537+ 3/6wcEqWc+RjUgdeWSf1wpnBWOg5fZvrrGdKdFkSEfw3p9FERcwjIrNlS/tO6KadTp2X6ZQzZp3Mw Of9kphx1Z6BPKHlmTy+y9Lh4wyoud8+DetvHgq0/pY9NdzEaEv3FoCwyMOgQZvfHT+vj6gciLLdy7 WVQ0V+SSW+gpX5K6+N2gAhQIwMm9hB0mogEgz5z97Rv3hzTh7Pmo9Wph0lrY64RaaQiG2v5s+E76A DJgVb7gbE8ACBL1+Whk/iZSbOxGNUO9NR/cuKdlkPegxXDQMxE6qcvHC56GtKGGpZZRmJfkm1P0wb jpCxPd6zk7eOxLsutny4FQ==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puxJ2-0003s8-Ao; Fri, 05 May 2023 11:25:12 -0400 In-Reply-To: <221c67168567a20a89c1@heytings.org> (message from Gregory Heytings on Thu, 04 May 2023 15:45:29 +0000) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:261115 Archived-At: > Date: Thu, 04 May 2023 15:45:29 +0000 > From: Gregory Heytings > cc: 56682@debbugs.gnu.org, monnier@iro.umontreal.ca > > > Please show the full diffs of the proposed merge, I will have to think > > about this again, and think hard. > > > > You can get them by checking out the scratch/long-lines-cleanup and doing > "git diff emacs-29..." Just in case, I attach the full diff. Most of it > are renamings and documentation improvements. The main code change is the > function 'get_nearby_bol_pos' used by 'get_small_narrowing_begv'. That's not all it changes, see below. > - for (val = narrowing_locks; CONSP (val); val = XCDR (val)) > + for (val = labeled_restrictions; CONSP (val); val = XCDR (val)) > { > buf = XCAR (XCAR (val)); > eassert (BUFFERP (buf)); > - struct Lisp_Marker *begv = narrowing_lock_get_bound (buf, true, true); > - struct Lisp_Marker *zv = narrowing_lock_get_bound (buf, false, true); > + struct Lisp_Marker *begv > + = labeled_restrictions_get_bound (buf, true, true); > + struct Lisp_Marker *zv > + = labeled_restrictions_get_bound (buf, false, true); > if (begv != NULL && zv != NULL) > { Why the strange design of having a function return a pointer to a 'struct Lisp_Marker'? why not return the marker itself instead? (I realize that this was so in the code we already have, but I still don't understand why you did it that way, and prefer that function to return a marker instead.) > diff --git a/src/fileio.c b/src/fileio.c > index f00c389a520..b50b3c6b935 100644 > --- a/src/fileio.c > +++ b/src/fileio.c > @@ -5269,6 +5269,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, > } > > record_unwind_protect (save_restriction_restore, save_restriction_save ()); > + labeled_restrictions_remove_in_current_buffer (); Why are we removing the restrictions as part of write-region? > diff --git a/src/indent.c b/src/indent.c > index 08d2bf5ea28..aef394dab88 100644 > --- a/src/indent.c > +++ b/src/indent.c > @@ -2065,6 +2065,7 @@ line_number_display_width (struct window *w, int *width, int *pixel_width) > { > record_unwind_protect (save_restriction_restore, > save_restriction_save ()); > + labeled_restrictions_remove_in_current_buffer (); > Fwiden (); > saved_restriction = true; > } And why here? > --- a/src/lread.c > +++ b/src/lread.c > @@ -2255,6 +2255,7 @@ readevalloop (Lisp_Object readcharfun, > record_unwind_protect_excursion (); > /* Save ZV in it. */ > record_unwind_protect (save_restriction_restore, save_restriction_save ()); > + labeled_restrictions_remove_in_current_buffer (); > /* Those get unbound after we read one expression. */ And here? > + The corresponding function 'get_medium_narrowing_zv' (and > + 'medium_narrowing_zv' field in 'struct it') is not used to set the > + end limit of a the restriction, which is again unnecessary, but to ^^^^^ Typo. > +static ptrdiff_t > +get_nearby_bol_pos (ptrdiff_t pos) > +{ > + ptrdiff_t start, pos_bytepos, cur, next, found, bol = BEGV - 1; > + int dist; > + for (dist = 500; dist <= 500000; dist *= 10) > + { > + pos_bytepos = pos == BEGV ? BEGV_BYTE : CHAR_TO_BYTE (pos); > + start = pos - dist < BEGV ? BEGV : pos - dist; > + for (cur = start; cur < pos; cur = next) > + { > + next = find_newline1 (cur, CHAR_TO_BYTE (cur), > + pos, pos_bytepos, > + 1, &found, NULL, false); > + if (found) > + bol = next; > + else > + break; > + } > + if (bol >= BEGV || start == BEGV) > + return bol; > + else > + pos = pos - dist < BEGV ? BEGV : pos - dist; > + } > + return bol; > +} This function should have a commentary describing what it does. Is it okay for this function to return a position > POS, its input? > @@ -24112,6 +24232,7 @@ display_count_lines_logically (ptrdiff_t start_byte, ptrdiff_t limit_byte, > ptrdiff_t val; > specpdl_ref pdl_count = SPECPDL_INDEX (); > record_unwind_protect (save_restriction_restore, save_restriction_save ()); > + labeled_restrictions_remove_in_current_buffer (); > Fwiden (); > val = display_count_lines (start_byte, limit_byte, count, byte_pos_ptr); > unbind_to (pdl_count, Qnil); Why do we remove the restrictions here?