From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gregory Heytings Newsgroups: gmane.emacs.bugs Subject: bug#56682: feature/improved-locked-narrowing 9dee6df39c: Reworked locked narrowing. Date: Fri, 05 May 2023 21:29:16 +0000 Message-ID: References: <166939872890.18950.12581667269687468681@vcs2.savannah.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> <834joqiyuq.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34010"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 56682@debbugs.gnu.org, monnier@iro.umontreal.ca To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri May 05 23:30:34 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 1pv30c-0008bq-Ar for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 05 May 2023 23:30:34 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pv30E-00089n-Ub; Fri, 05 May 2023 17:30:11 -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 1pv307-00084W-CB for bug-gnu-emacs@gnu.org; Fri, 05 May 2023 17:30: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 1pv307-0005nm-1V for bug-gnu-emacs@gnu.org; Fri, 05 May 2023 17:30:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pv306-0000Ao-Nj for bug-gnu-emacs@gnu.org; Fri, 05 May 2023 17:30:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Gregory Heytings Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 05 May 2023 21:30:02 +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.1683322165573 (code B ref 56682); Fri, 05 May 2023 21:30:02 +0000 Original-Received: (at 56682) by debbugs.gnu.org; 5 May 2023 21:29:25 +0000 Original-Received: from localhost ([127.0.0.1]:57661 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pv2zT-000098-2I for submit@debbugs.gnu.org; Fri, 05 May 2023 17:29:25 -0400 Original-Received: from heytings.org ([95.142.160.155]:50284) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pv2zN-00008m-Fr for 56682@debbugs.gnu.org; Fri, 05 May 2023 17:29:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=heytings.org; s=20220101; t=1683322156; bh=6QA+KTwdFs3Idmi7aPFK7wWpGLTKGGbNFQhaGNibDpw=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References:From; b=L/+ob1SZs/MkWob0ZFxMAWgR/Ziv3Xy27ZVbzr0ETzSNM+CEbn9Wns8GYm8iOFQ6w ttadwAky7h2lXErk7GVA7v9xgmDhyCh8P89ITUaKPBChMj8UeSh8pKgLGkrz3drx88 AfvYWR1QqWgqPMRrng57gW+t6Hbrmqi2WNAOXIEky9j5hSM2cDA2npRaaC56dfu5Xp boQQyRezDX2PdWmD5YcqmbvTlZTk0GSd9TitnSEw/lbEuHHaPyCLz26xhqd86ZwZcz 5ZWLWWJQg7bAFQcEURqu/WpcuRgmnG+njAIZAAW/0k6lTgpNAv4c5fYtnYx77PklBb hGHi06qXZJYBg== In-Reply-To: <834joqiyuq.fsf@gnu.org> 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:261147 Archived-At: Thanks for your detailed review. >> + struct Lisp_Marker *begv >> + = labeled_restrictions_get_bound (buf, true, true); >> + struct Lisp_Marker *zv >> + = labeled_restrictions_get_bound (buf, false, true); > > 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.) > Good question. You mean that it would have been better to return a Lisp_Object, right? I don't recall exactly, I think it was because in the calls to SET_BUF_BEGV_BOTH/SET_BUF_ZV_BOTH (which are the only places where the return value of labeled_restrictions_get_bound are used) one can use the pointer to a struct Lisp_Marker immediately, whereas a call to XMARKER would have been necessary if a Lisp_Object had been used. >> 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? > We are removing them temporarily, just before the Fwiden, and they are restored by save_restriction_restore. >> record_unwind_protect (save_restriction_restore, >> save_restriction_save ()); >> + labeled_restrictions_remove_in_current_buffer (); >> Fwiden (); > > And why here? > For the same reason: calls to Fwiden which are preceded by a "record_unwind_protect (save_restriction_restore, save_restriction_save ());" are meant to temporarily widen the buffer, and restore the restrictions upon returning from the function. So we temporarily remove labeled restrictions as well (and they are restored by save_restriction_restore, too). >> record_unwind_protect (save_restriction_restore, save_restriction_save ()); >> + labeled_restrictions_remove_in_current_buffer (); > > And here? > For the same reason again ;-) >> 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); > > Why do we remove the restrictions here? > ... and again ;-) >> + 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. > Good catch, thanks! >> +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. > Okay, I'll add that. > > Is it okay for this function to return a position > POS, its input? > Unless I misunderstood something, it cannot, because find_newline1 is called with end = pos and end_byte = pos_bytepos.