From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#56682: locked narrowing (was: bug#56682: Fix the long lines font locking related slowdowns) Date: Tue, 16 Aug 2022 15:18:23 -0400 Message-ID: References: <12348081660379417@sas2-a098efd00d24.qloud-c.yandex.net> <66bbbb95983414e79637@heytings.org> <83wnb9hadb.fsf@gnu.org> <395454dd-7238-c5d0-e924-2f65a186baa7@yandex.ru> <83r11hh4pm.fsf@gnu.org> <3a1232a17b09ce88af40@heytings.org> <83edxghqg2.fsf@gnu.org> <325f95fd2bcc0b666b0b@heytings.org> <83edxgfi75.fsf@gnu.org> <5e3c3081-f098-8140-c767-b895c32bf30b@yandex.ru> <835yisffil.fsf@gnu.org> <831qtgff78.fsf@gnu.org> <83zgg4dw4y.fsf@gnu.org> <83r11gdrr4.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31833"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 56682@debbugs.gnu.org, gregory@heytings.org, dgutov@yandex.ru To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 16 21:19:24 2022 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 1oO25y-000804-A4 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 16 Aug 2022 21:19:22 +0200 Original-Received: from localhost ([::1]:59044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oO25x-0002wV-Dh for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 16 Aug 2022 15:19:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54862) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oO25e-0002wK-Oh for bug-gnu-emacs@gnu.org; Tue, 16 Aug 2022 15:19:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58625) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oO25e-0001QV-DO for bug-gnu-emacs@gnu.org; Tue, 16 Aug 2022 15:19:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oO25e-00076w-8y for bug-gnu-emacs@gnu.org; Tue, 16 Aug 2022 15:19:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 16 Aug 2022 19:19: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.166067752427307 (code B ref 56682); Tue, 16 Aug 2022 19:19:02 +0000 Original-Received: (at 56682) by debbugs.gnu.org; 16 Aug 2022 19:18:44 +0000 Original-Received: from localhost ([127.0.0.1]:48374 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oO25K-00076M-OX for submit@debbugs.gnu.org; Tue, 16 Aug 2022 15:18:43 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:3618) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oO25A-00075z-8P for 56682@debbugs.gnu.org; Tue, 16 Aug 2022 15:18:41 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id CD4128076B; Tue, 16 Aug 2022 15:18:26 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 86333801B5; Tue, 16 Aug 2022 15:18:24 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1660677504; bh=vaewjrrcuMDUB5LZOvF66HSn+5wOzPFxfYDSfQKH9sE=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=Xax7UhiwMCQccRDlY0yeMHT0D96PrgNVZS7A7PUoqL9flmTgCcK8r1hR8nWHf/vkG N9NPsOIFdNRc8YxFYscit3jTqrUH977GA0npnrL3a9SjTCsoDbdDNlepzSLelRqBRd +/xiTAnBQwM+gug1vEmPw3OLpAaZOBlk3Fv9hAAJC1sp4suSmhf0cpJThtHWxWgSpK M52ybWER+6mUMueBWKsaUSZnfKc8aYa+PG5UKI4eDC+Jfy3GrMtiBzAngh5Qmx1Nyf Td9lO3UkeseRb5mUDnsgibakV2/8cYYZD6hO4S8xzY0nMva4GgU+ukS0JGvQaBLVSQ mUZUvW28U3H8A== Original-Received: from alfajor (unknown [45.44.229.252]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 51B791202E7; Tue, 16 Aug 2022 15:18:24 -0400 (EDT) In-Reply-To: <83r11gdrr4.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 16 Aug 2022 20:26:23 +0300") 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" Xref: news.gmane.io gmane.emacs.bugs:239996 Archived-At: Eli Zaretskii [2022-08-16 20:26:23] wrote: >> From: Stefan Monnier >> Cc: dgutov@yandex.ru, 56682@debbugs.gnu.org, gregory@heytings.org >> Date: Tue, 16 Aug 2022 13:15:04 -0400 >> Eli Zaretskii [2022-08-16 18:51:41] wrote: >> >> I missed it then: you're saying that I can make nlinum-mode override the >> >> locked narrowing to find the real current line number without having to >> >> recompile Emacs? >> > No, I'm saying that you can test improvements in nlinum-mode that >> > would make it work better with long lines without recompiling. >> How? > I'm sure you can figure it out if you just think for a few seconds. I have no idea where to start because I can't see any way to circumvent the locked narrowing. > But if you want me to do it for you, then please tell which changes do > you want to try and in what situations, because the technique depends > on that. I'd start with the patch below. > (Not that I understand where are you going with this. Especially > since a feature to unlock the narrowing is just one simple commit > away.) I really appreciate Gregory's (and your) work to improve the handling of long lines. This was way overdue. *BUT* the code for the locked narrowing just .... sucks rocks. [ Sorry, Gregory. But see below for more concrete/constructive criticism. ] So, given that you (Eli) accepted it into `master` and have not voiced concerns over it even after Dmitry's and my complaints, I feel that you do support it enough that I'm not in a position to just install "one simple commit". The most glaring problems I see with it (beside the impossibility to override the locking, obviously): - `widen` will silently fail. Maybe this is the right thing to do, maybe not, but it's definitely not clear (e.g. it leads to inf-loops in CC-mode, which doesn't seem much better than the excruciating slowdowns that locked narrowing is intended to fix). It *should* be (or have been) discussed. - Not only you can't `widen` but you can't narrow either (`narrow-to-region` just does nothing when the restriction is locked, regardless if the call tries to grow or shrink the restriction). AFAIK this is a plain bug, but given the fundamental disagreement about what is "right" in this discussion, I can't be sure. - The locking is global: any `widen` or `narrow-to-region` will fail when a locked narrowing is in effect, even when it's applied to an unrelated buffer. Again, it looks like a plain bug, but... - ...the plural in the name "restrictions-locked" suggests that the global effect is on purpose, tho I can't see any justification for it. - The doc for `restrictions-locked` says: This happens when `narrow-to-region', which see, is called from Lisp with an optional argument LOCK non-nil. but the `narrow-to-region` function doesn't have any such LOCK argument. - The `narrow_to_region_internal` function, when called with `lock=true` oddly includes the functionality of save-restriction to restore the restriction and point but not to restore the `restrictions-locked` state. - In that same function the two branches of the `if (lock)` have a lot of obvious redundancy. So, yes, I could go and write a patch which I think fixes those problems, but I don't understand how this code made it to `master` in the first place, so I feel like I'm missing something and can't be sure what is considered a bug and what is considered a feature. Stefan diff --git a/nlinum.el b/nlinum.el index 4f0e02fef1..3feaaca5c3 100644 --- a/nlinum.el +++ b/nlinum.el @@ -312,7 +312,7 @@ Only works right if point is at BOL." (if nlinum-widen (save-excursion (save-restriction - (widen) + (REALLY-widen) (forward-line 0) ;In case (point-min) was not at BOL. (let ((nlinum-widen nil)) (nlinum--line-number-at-pos))))