unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb.
@ 2024-01-03 18:37 Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
       [not found] ` <handler.68234.B.170430710530123.ack@debbugs.gnu.org>
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-01-03 18:37 UTC (permalink / raw)
  To: 68234

[-- Attachment #1: Type: text/plain, Size: 203 bytes --]

Avoids erroneous mismatched paren highlighting when highlighting large
expressions of around 10,000 lines.

This value was last increased in 2009, from 25->100kb. This patch
increases it from 100->400.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Increase-blink-matching-paren-distance-by-300kb.patch --]
[-- Type: text/x-patch, Size: 1085 bytes --]

From d55e8ce5d98389bc8bbe4dac97bc76bb957e791e Mon Sep 17 00:00:00 2001
From: Antero Mejr <antero@mailbox.org>
Date: Wed, 3 Jan 2024 18:29:43 +0000
Subject: [PATCH] Increase blink-matching-paren-distance by 300kb.

* lisp/simple.el (blink-matching-paren-distance): Increase from 100kb
to 400kb.
---
 lisp/simple.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 4f6d2ee12c3..177ea640506 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9260,10 +9260,10 @@ It is also ignored if `show-paren-mode' is enabled."
   :type 'boolean
   :group 'paren-blinking)
 
-(defcustom blink-matching-paren-distance (* 100 1024)
+(defcustom blink-matching-paren-distance (* 400 1024)
   "If non-nil, maximum distance to search backwards for matching open-paren.
 If nil, search stops at the beginning of the accessible portion of the buffer."
-  :version "23.2"                       ; 25->100k
+  :version "23.2"                       ; 25->100k, 30->400k
   :type '(choice (const nil) integer)
   :group 'paren-blinking)
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb.
       [not found] ` <handler.68234.B.170430710530123.ack@debbugs.gnu.org>
@ 2024-01-03 18:48   ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-01-04 11:31     ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-01-03 18:48 UTC (permalink / raw)
  To: 68234

[-- Attachment #1: Type: text/plain, Size: 114 bytes --]

Messed up the code comment on the last patch, please use this patch
instead (also added Bug# to commit message).


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Increase-blink-matching-paren-distance-by-300kb.patch --]
[-- Type: text/x-patch, Size: 1094 bytes --]

From 8875e658456074e92272bcbb6d31c8db47d4658a Mon Sep 17 00:00:00 2001
From: Antero Mejr <antero@mailbox.org>
Date: Wed, 3 Jan 2024 18:29:43 +0000
Subject: [PATCH] Increase blink-matching-paren-distance by 300kb.

* lisp/simple.el (blink-matching-paren-distance): Increase from 100kb
to 400kb.  (Bug#68234)
---
 lisp/simple.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 4f6d2ee12c3..d4a339f37dc 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9260,10 +9260,10 @@ It is also ignored if `show-paren-mode' is enabled."
   :type 'boolean
   :group 'paren-blinking)
 
-(defcustom blink-matching-paren-distance (* 100 1024)
+(defcustom blink-matching-paren-distance (* 400 1024)
   "If non-nil, maximum distance to search backwards for matching open-paren.
 If nil, search stops at the beginning of the accessible portion of the buffer."
-  :version "23.2"                       ; 25->100k
+  :version "23.2"                       ; 25->100k->400k
   :type '(choice (const nil) integer)
   :group 'paren-blinking)
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb.
  2024-01-03 18:37 bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
       [not found] ` <handler.68234.B.170430710530123.ack@debbugs.gnu.org>
@ 2024-01-04  4:50 ` Stefan Kangas
  2024-01-04 19:22   ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-01-04 21:03 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2 siblings, 1 reply; 14+ messages in thread
From: Stefan Kangas @ 2024-01-04  4:50 UTC (permalink / raw)
  To: Antero Mejr, 68234

Antero Mejr via "Bug reports for GNU Emacs, the Swiss army knife of text
editors" <bug-gnu-emacs@gnu.org> writes:

> Avoids erroneous mismatched paren highlighting when highlighting large
> expressions of around 10,000 lines.
>
> This value was last increased in 2009, from 25->100kb. This patch
> increases it from 100->400.

Makes sense to me.

> From d55e8ce5d98389bc8bbe4dac97bc76bb957e791e Mon Sep 17 00:00:00 2001
> From: Antero Mejr <antero@mailbox.org>
> Date: Wed, 3 Jan 2024 18:29:43 +0000
> Subject: [PATCH] Increase blink-matching-paren-distance by 300kb.
>
> * lisp/simple.el (blink-matching-paren-distance): Increase from 100kb
> to 400kb.
> ---
>  lisp/simple.el | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lisp/simple.el b/lisp/simple.el
> index 4f6d2ee12c3..177ea640506 100644
> --- a/lisp/simple.el
> +++ b/lisp/simple.el
> @@ -9260,10 +9260,10 @@ It is also ignored if `show-paren-mode' is enabled."
>    :type 'boolean
>    :group 'paren-blinking)
>
> -(defcustom blink-matching-paren-distance (* 100 1024)
> +(defcustom blink-matching-paren-distance (* 400 1024)
>    "If non-nil, maximum distance to search backwards for matching open-paren.
>  If nil, search stops at the beginning of the accessible portion of the buffer."
> -  :version "23.2"                       ; 25->100k
> +  :version "23.2"                       ; 25->100k, 30->400k

This should read:

 +  :version "30.1"                       ; 100->400k

Or even just:

 +  :version "30.1"

>    :type '(choice (const nil) integer)
>    :group 'paren-blinking)
>
> --
> 2.43.0





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb.
  2024-01-03 18:48   ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-01-04 11:31     ` Eli Zaretskii
  2024-01-04 23:08       ` Stefan Kangas
  0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2024-01-04 11:31 UTC (permalink / raw)
  To: Antero Mejr, Stefan Kangas; +Cc: 68234

> Date: Wed, 03 Jan 2024 18:48:41 +0000
> From:  Antero Mejr via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> 
> >From 8875e658456074e92272bcbb6d31c8db47d4658a Mon Sep 17 00:00:00 2001
> From: Antero Mejr <antero@mailbox.org>
> Date: Wed, 3 Jan 2024 18:29:43 +0000
> Subject: [PATCH] Increase blink-matching-paren-distance by 300kb.
> 
> * lisp/simple.el (blink-matching-paren-distance): Increase from 100kb
> to 400kb.  (Bug#68234)
> ---
>  lisp/simple.el | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lisp/simple.el b/lisp/simple.el
> index 4f6d2ee12c3..d4a339f37dc 100644
> --- a/lisp/simple.el
> +++ b/lisp/simple.el
> @@ -9260,10 +9260,10 @@ It is also ignored if `show-paren-mode' is enabled."
>    :type 'boolean
>    :group 'paren-blinking)
>  
> -(defcustom blink-matching-paren-distance (* 100 1024)
> +(defcustom blink-matching-paren-distance (* 400 1024)
>    "If non-nil, maximum distance to search backwards for matching open-paren.
>  If nil, search stops at the beginning of the accessible portion of the buffer."
> -  :version "23.2"                       ; 25->100k
> +  :version "23.2"                       ; 25->100k->400k
>    :type '(choice (const nil) integer)
>    :group 'paren-blinking)

Do people feel okay with increasing this value by a factor of 4?  This
blinking is supposed to be very fast, so if this will slow down
display, it's not TRT.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb.
  2024-01-04  4:50 ` Stefan Kangas
@ 2024-01-04 19:22   ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 14+ messages in thread
From: Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-01-04 19:22 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 68234

[-- Attachment #1: Type: text/plain, Size: 213 bytes --]

Stefan Kangas <stefankangas@gmail.com> writes:

> This should read:
>
>  +  :version "30.1"                       ; 100->400k
>
> Or even just:
>
>  +  :version "30.1"
>

New patch attached, removed the comment.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Increase-blink-matching-paren-distance-by-300kb.patch --]
[-- Type: text/x-patch, Size: 1055 bytes --]

From 8a3fe1a6c7bbe8b88fc21d4c48d4bac223214a1d Mon Sep 17 00:00:00 2001
From: Antero Mejr <antero@mailbox.org>
Date: Wed, 3 Jan 2024 18:29:43 +0000
Subject: [PATCH] Increase blink-matching-paren-distance by 300kb.

* lisp/simple.el (blink-matching-paren-distance): Increase from 100kb
to 400kb.  (Bug#68234)
---
 lisp/simple.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 4f6d2ee12c3..a464123f8b5 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9260,10 +9260,10 @@ It is also ignored if `show-paren-mode' is enabled."
   :type 'boolean
   :group 'paren-blinking)
 
-(defcustom blink-matching-paren-distance (* 100 1024)
+(defcustom blink-matching-paren-distance (* 400 1024)
   "If non-nil, maximum distance to search backwards for matching open-paren.
 If nil, search stops at the beginning of the accessible portion of the buffer."
-  :version "23.2"                       ; 25->100k
+  :version "30.1"
   :type '(choice (const nil) integer)
   :group 'paren-blinking)
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb.
  2024-01-03 18:37 bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
       [not found] ` <handler.68234.B.170430710530123.ack@debbugs.gnu.org>
  2024-01-04  4:50 ` Stefan Kangas
@ 2024-01-04 21:03 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-01-04 21:36   ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2 siblings, 1 reply; 14+ messages in thread
From: Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-01-04 21:03 UTC (permalink / raw)
  To: 68234; +Cc: antero

Antero Mejr via "Bug reports for GNU Emacs, the Swiss army knife of text
editors" <bug-gnu-emacs@gnu.org> writes:

> Avoids erroneous mismatched paren highlighting when highlighting large
> expressions of around 10,000 lines.
>

Do you have a practical example of those expressions that are 10,000
lines long?  I think they are rare enough that people affected by
possible paren mismatching with them could simply tweak
blink-matching-paren-distance in their customization file.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb.
  2024-01-04 21:03 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-01-04 21:36   ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 14+ messages in thread
From: Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-01-04 21:36 UTC (permalink / raw)
  To: Daniel Martín; +Cc: 68234

Daniel Martín <mardani29@yahoo.es> writes:

> Do you have a practical example of those expressions that are 10,000
> lines long?  I think they are rare enough that people affected by
> possible paren mismatching with them could simply tweak
> blink-matching-paren-distance in their customization file.

First time seeing it was an SXML expression for a website (about 6k
lines), second time was an allowlist filter (about 10k lines).

I don't think there is a noticable performance penalty in searching a
wider region, which is why I proposed increasing the default.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb.
  2024-01-04 11:31     ` Eli Zaretskii
@ 2024-01-04 23:08       ` Stefan Kangas
  2024-01-05  7:49         ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Stefan Kangas @ 2024-01-04 23:08 UTC (permalink / raw)
  To: Eli Zaretskii, Antero Mejr; +Cc: 68234

Eli Zaretskii <eliz@gnu.org> writes:

>> -(defcustom blink-matching-paren-distance (* 100 1024)
>> +(defcustom blink-matching-paren-distance (* 400 1024)
>>    "If non-nil, maximum distance to search backwards for matching open-paren.
>>  If nil, search stops at the beginning of the accessible portion of the buffer."
>> -  :version "23.2"                       ; 25->100k
>> +  :version "23.2"                       ; 25->100k->400k
>>    :type '(choice (const nil) integer)
>>    :group 'paren-blinking)
>
> Do people feel okay with increasing this value by a factor of 4?  This
> blinking is supposed to be very fast, so if this will slow down
> display, it's not TRT.

I benchmarked this on my old ~2013 GNU/Linux machine using:

  (progn
  (goto-char (point-max))
  (insert "}")
  (let ((minibuffer-message-timeout 0)
        (blink-matching-delay 0)
        (repeat 20) fst)
    (dolist (distance (number-sequence 100 1000 100))
      (let* ((blink-matching-paren-distance (* distance 1024))
             (time (car (benchmark-run repeat (blink-matching-open)))))
        (message "distance %-4dKB takes %-.3fs (x%.1f)"
                 distance
                 (/ time repeat)
                 (/ time (setq fst (or fst time))))))))

In src/lisp.h (176 KB/5607 lines), I get:

  distance 100 KB takes 0.011s (x1.0)
  distance 200 KB takes 0.015s (x1.3)
  distance 300 KB takes 0.015s (x1.3)
  distance 400 KB takes 0.015s (x1.3) *
  [etc.]

In src/xterm.c (945 KB/32842 lines), I get:

  distance 100 KB takes 0.010s (x1.0)
  distance 200 KB takes 0.017s (x1.6)
  distance 300 KB takes 0.025s (x2.4)
  distance 400 KB takes 0.034s (x3.3) *
  distance 500 KB takes 0.042s (x4.1)
  distance 600 KB takes 0.051s (x5.0)
  distance 700 KB takes 0.060s (x5.8)
  distance 800 KB takes 0.068s (x6.7)
  distance 900 KB takes 0.078s (x7.6)
  distance 1000KB takes 0.079s (x7.7)

I also tried this in a ridiculous 23 MB header file that I found in the
Linux kernel tree, which my Emacs opens in fundamental-mode:

  distance 100 KB takes 0.005s (x1.0)
  distance 200 KB takes 0.005s (x1.0)
  distance 300 KB takes 0.008s (x1.5)
  distance 400 KB takes 0.010s (x2.0) *
  distance 500 KB takes 0.013s (x2.5)
  distance 600 KB takes 0.015s (x3.1)
  distance 700 KB takes 0.018s (x3.6)
  distance 800 KB takes 0.020s (x4.1)
  distance 900 KB takes 0.023s (x4.6)
  distance 1000KB takes 0.025s (x5.1)

Humans can't perceive delays smaller than 100 ms, so my conclusion here
is that setting this to 400 KB shouldn't normally lead to any noticeable
slowdown.  On the other hand, we get improved correctness, which sounds
like a win.

We also have to take into account the compound effect with other
features (such as third-party packages) that also may be slowing things
down.  However, this should only affect typing closing parens, so maybe
correctness could still be considered more important.

Of course, we could also double (instead of quadruple) this number, and
get most of the benefits still.

Eli, do you have any preference?

Note finally that the above examined files are unusually large (as is
often the case in our tree).

PS. Out of interest, in a recent copy of the Linux kernel the median
    *.[ch] file size is ~5 KB.  In emacs/src, we have instead a median
    *.[ch] file size of ~21KB.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb.
  2024-01-04 23:08       ` Stefan Kangas
@ 2024-01-05  7:49         ` Eli Zaretskii
  2024-01-05 20:50           ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-01-09  5:56           ` Stefan Kangas
  0 siblings, 2 replies; 14+ messages in thread
From: Eli Zaretskii @ 2024-01-05  7:49 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: antero, 68234

> From: Stefan Kangas <stefankangas@gmail.com>
> Date: Thu, 4 Jan 2024 15:08:35 -0800
> Cc: 68234@debbugs.gnu.org
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > Do people feel okay with increasing this value by a factor of 4?  This
> > blinking is supposed to be very fast, so if this will slow down
> > display, it's not TRT.
> 
> I benchmarked this on my old ~2013 GNU/Linux machine using:
> 
>   (progn
>   (goto-char (point-max))
>   (insert "}")
>   (let ((minibuffer-message-timeout 0)
>         (blink-matching-delay 0)
>         (repeat 20) fst)
>     (dolist (distance (number-sequence 100 1000 100))
>       (let* ((blink-matching-paren-distance (* distance 1024))
>              (time (car (benchmark-run repeat (blink-matching-open)))))
>         (message "distance %-4dKB takes %-.3fs (x%.1f)"
>                  distance
>                  (/ time repeat)
>                  (/ time (setq fst (or fst time))))))))
> 
> In src/lisp.h (176 KB/5607 lines), I get:
> 
>   distance 100 KB takes 0.011s (x1.0)
>   distance 200 KB takes 0.015s (x1.3)
>   distance 300 KB takes 0.015s (x1.3)
>   distance 400 KB takes 0.015s (x1.3) *
>   [etc.]
> 
> In src/xterm.c (945 KB/32842 lines), I get:
> 
>   distance 100 KB takes 0.010s (x1.0)
>   distance 200 KB takes 0.017s (x1.6)
>   distance 300 KB takes 0.025s (x2.4)
>   distance 400 KB takes 0.034s (x3.3) *
>   distance 500 KB takes 0.042s (x4.1)
>   distance 600 KB takes 0.051s (x5.0)
>   distance 700 KB takes 0.060s (x5.8)
>   distance 800 KB takes 0.068s (x6.7)
>   distance 900 KB takes 0.078s (x7.6)
>   distance 1000KB takes 0.079s (x7.7)

Based on these times, I don't recommend raising the threshold above
200K.

> I also tried this in a ridiculous 23 MB header file that I found in the
> Linux kernel tree, which my Emacs opens in fundamental-mode:

I don't think Fundamental mode is relevant: everything is
lightning-fast there.  I would be interested in modes like Python,
though, if this is relevant for them.

> Humans can't perceive delays smaller than 100 ms

That's not true: 50 ms is already perceptible.  Moreover, this
particular time is an add-on to the redisplay time after cursor
movement, so adding even a few tens of msec could easily pass the
perception threshold.  And finally, some people, including on this
list, use machines older and much slower than those from 10 years ago.

> Of course, we could also double (instead of quadruple) this number, and
> get most of the benefits still.
> 
> Eli, do you have any preference?

I think we can at most double it at this time.  This is a defcustom,
so people can always increase it in their local configurations if they
have much faster machines and need routinely to cope with such large
parenthetical expressions.

> Note finally that the above examined files are unusually large (as is
> often the case in our tree).

What matters is not the size of the file, but the size of a
parenthetical expression.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb.
  2024-01-05  7:49         ` Eli Zaretskii
@ 2024-01-05 20:50           ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-01-05 21:10             ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-01-06  7:01             ` Eli Zaretskii
  2024-01-09  5:56           ` Stefan Kangas
  1 sibling, 2 replies; 14+ messages in thread
From: Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-01-05 20:50 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Stefan Kangas, 68234

[-- Attachment #1: Type: text/plain, Size: 451 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

> I think we can at most double it at this time.  This is a defcustom,
> so people can always increase it in their local configurations if they
> have much faster machines and need routinely to cope with such large
> parenthetical expressions.

If we're not increasing it that much, can we change the behavior to not
wrongly indicate mismatched parens for expressions where you can't be
sure? Patch is attached.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Don-t-show-mismatched-parens-if-search-region-is-nar.patch --]
[-- Type: text/x-patch, Size: 3283 bytes --]

From a6dcc9007601122e4bef95f4316cd5452e8d6b38 Mon Sep 17 00:00:00 2001
From: Antero Mejr <antero@mailbox.org>
Date: Fri, 5 Jan 2024 20:37:52 +0000
Subject: [PATCH] Don't show mismatched parens if search region is narrowed

* lisp/paren.el (show-paren--default): Don't highlight paren as
mismatched if region is narrowed.
* lisp/simple.el (blink-matching-open): Don't display mismatched paren
message if region is narrowed.  (Bug#68234)
---
 lisp/paren.el  | 18 ++++++++++++------
 lisp/simple.el |  5 ++++-
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/lisp/paren.el b/lisp/paren.el
index cb29b8311a5..dbfd0ab4ffd 100644
--- a/lisp/paren.el
+++ b/lisp/paren.el
@@ -246,7 +246,7 @@ It is the default value of `show-paren-data-function'."
           (if (ppss-comment-depth (syntax-ppss))
               nil
             parse-sexp-ignore-comments))
-	 pos mismatch here-beg here-end)
+	 pos mismatch here-beg here-end narrowed)
     ;;
     ;; Find the other end of the sexp.
     (when dir
@@ -254,10 +254,15 @@ It is the default value of `show-paren-data-function'."
 	    here-end (if (eq dir 1) (1+ outside) outside))
       (save-restriction
 	;; Determine the range within which to look for a match.
-	(when blink-matching-paren-distance
-	  (narrow-to-region
-	   (max (point-min) (- (point) blink-matching-paren-distance))
-	   (min (point-max) (+ (point) blink-matching-paren-distance))))
+        (let ((start (- (point) blink-matching-paren-distance))
+              (end (+ (point) blink-matching-paren-distance)))
+	  (when blink-matching-paren-distance
+            ;; If narrowed, the match may be outside the region.
+            (setq narrowed (or (and (< (point-min) start) (eq dir -1))
+                               (and (> (point-max) end) (eq dir 1))))
+	    (narrow-to-region
+	     (max (point-min) start)
+	     (min (point-max) end))))
 	;; Scan across one sexp within that range.
 	;; Errors or nil mean there is a mismatch.
 	(condition-case ()
@@ -275,7 +280,8 @@ It is the default value of `show-paren-data-function'."
 	;; If found a "matching" paren, see if it is the right
 	;; kind of paren to match the one we started at.
 	(if (not (integerp pos))
-	    (if mismatch (list here-beg here-end nil nil t))
+	    (if (and mismatch (not narrowed))
+                (list here-beg here-end nil nil t))
 	  (let ((beg (min pos outside)) (end (max pos outside)))
 	    (unless (eq (syntax-class (syntax-after beg)) 8)
 	      (setq mismatch
diff --git a/lisp/simple.el b/lisp/simple.el
index a464123f8b5..b3c4f456372 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9360,9 +9360,12 @@ The function should return non-nil if the two tokens do not match.")
                           (forward-char 1))
                         (point))
                     (error nil))))))
+           ;; If narrowed, the match may be outside the region.
+           (narrowed (< (minibuffer-prompt-end)
+                        (- (point) blink-matching-paren-distance)))
            (mismatch (funcall blink-matching-check-function blinkpos oldpos)))
       (cond
-       (mismatch
+       ((and mismatch (not narrowed))
         (if blinkpos
             (if (minibufferp)
                 (minibuffer-message "Mismatched parentheses")
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb.
  2024-01-05 20:50           ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-01-05 21:10             ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-01-06  7:01             ` Eli Zaretskii
  1 sibling, 0 replies; 14+ messages in thread
From: Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-01-05 21:10 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Stefan Kangas, 68234

[-- Attachment #1: Type: text/plain, Size: 599 bytes --]

Antero Mejr <antero@mailbox.org> writes:

> Eli Zaretskii <eliz@gnu.org> writes:
>
>> I think we can at most double it at this time.  This is a defcustom,
>> so people can always increase it in their local configurations if they
>> have much faster machines and need routinely to cope with such large
>> parenthetical expressions.
>
> If we're not increasing it that much, can we change the behavior to not
> wrongly indicate mismatched parens for expressions where you can't be
> sure? Patch is attached.

Updated version of the last patch, accounts for when
blink-matching-paren-distance is nil.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Don-t-show-mismatched-parens-if-search-region-is-nar.patch --]
[-- Type: text/x-patch, Size: 4237 bytes --]

From bb48036f39affb549fd71ee417d4cf9b111eaabf Mon Sep 17 00:00:00 2001
From: Antero Mejr <antero@mailbox.org>
Date: Fri, 5 Jan 2024 20:37:52 +0000
Subject: [PATCH] Don't show mismatched parens if search region is narrowed

* lisp/paren.el (show-paren--default): Don't highlight paren as
mismatched if region is narrowed.
* lisp/simple.el (blink-matching-open): Don't display mismatched paren
message if region is narrowed.  (Bug#68234)
---
 lisp/paren.el  | 16 +++++++++++-----
 lisp/simple.el | 17 +++++++++++------
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/lisp/paren.el b/lisp/paren.el
index cb29b8311a5..267289f9273 100644
--- a/lisp/paren.el
+++ b/lisp/paren.el
@@ -246,7 +246,7 @@ It is the default value of `show-paren-data-function'."
           (if (ppss-comment-depth (syntax-ppss))
               nil
             parse-sexp-ignore-comments))
-	 pos mismatch here-beg here-end)
+	 pos mismatch here-beg here-end narrowed)
     ;;
     ;; Find the other end of the sexp.
     (when dir
@@ -255,9 +255,14 @@ It is the default value of `show-paren-data-function'."
       (save-restriction
 	;; Determine the range within which to look for a match.
 	(when blink-matching-paren-distance
-	  (narrow-to-region
-	   (max (point-min) (- (point) blink-matching-paren-distance))
-	   (min (point-max) (+ (point) blink-matching-paren-distance))))
+          (let ((start (- (point) blink-matching-paren-distance))
+                (end (+ (point) blink-matching-paren-distance)))
+            ;; If narrowed, the match may be outside the region.
+            (setq narrowed (or (and (< (point-min) start) (eq dir -1))
+                               (and (> (point-max) end) (eq dir 1))))
+	    (narrow-to-region
+	     (max (point-min) start)
+	     (min (point-max) end))))
 	;; Scan across one sexp within that range.
 	;; Errors or nil mean there is a mismatch.
 	(condition-case ()
@@ -275,7 +280,8 @@ It is the default value of `show-paren-data-function'."
 	;; If found a "matching" paren, see if it is the right
 	;; kind of paren to match the one we started at.
 	(if (not (integerp pos))
-	    (if mismatch (list here-beg here-end nil nil t))
+	    (if (and mismatch (not narrowed))
+                (list here-beg here-end nil nil t))
 	  (let ((beg (min pos outside)) (end (max pos outside)))
 	    (unless (eq (syntax-class (syntax-after beg)) 8)
 	      (setq mismatch
diff --git a/lisp/simple.el b/lisp/simple.el
index a464123f8b5..473532dc9bd 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9335,15 +9335,20 @@ The function should return non-nil if the two tokens do not match.")
 	     blink-matching-paren)
     (let* ((oldpos (point))
 	   (message-log-max nil) ; Don't log messages about paren matching.
+           (narrowed nil)
 	   (blinkpos
             (save-excursion
               (save-restriction
 		(syntax-propertize (point))
-                (if blink-matching-paren-distance
-                    (narrow-to-region
-                     (max (minibuffer-prompt-end) ;(point-min) unless minibuf.
-                          (- (point) blink-matching-paren-distance))
-                     oldpos))
+                (when blink-matching-paren-distance
+                  (let ((start (- (point)
+                                  blink-matching-paren-distance)))
+                  ;; If narrowed, the match may be outside the region.
+                  (setq narrowed (< (minibuffer-prompt-end) start))
+                  (narrow-to-region
+                   (max (minibuffer-prompt-end) ;(point-min) unless minibuf.
+                        start)
+                   oldpos)))
                 (let ((parse-sexp-ignore-comments
                        (and parse-sexp-ignore-comments
                             (not blink-matching-paren-dont-ignore-comments))))
@@ -9362,7 +9367,7 @@ The function should return non-nil if the two tokens do not match.")
                     (error nil))))))
            (mismatch (funcall blink-matching-check-function blinkpos oldpos)))
       (cond
-       (mismatch
+       ((and mismatch (not narrowed))
         (if blinkpos
             (if (minibufferp)
                 (minibuffer-message "Mismatched parentheses")
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb.
  2024-01-05 20:50           ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-01-05 21:10             ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-01-06  7:01             ` Eli Zaretskii
  2024-01-06 12:09               ` Stefan Kangas
  1 sibling, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2024-01-06  7:01 UTC (permalink / raw)
  To: Antero Mejr; +Cc: stefankangas, 68234

> From: Antero Mejr <antero@mailbox.org>
> Cc: Stefan Kangas <stefankangas@gmail.com>,  68234@debbugs.gnu.org
> Date: Fri, 05 Jan 2024 20:50:45 +0000
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > I think we can at most double it at this time.  This is a defcustom,
> > so people can always increase it in their local configurations if they
> > have much faster machines and need routinely to cope with such large
> > parenthetical expressions.
> 
> If we're not increasing it that much, can we change the behavior to not
> wrongly indicate mismatched parens for expressions where you can't be
> sure? Patch is attached.

AFAIU, this will show nothing when the matching parenthesis is not
found?  If so, why is that a good idea?

In general, I don't understand why this rare situation should draw so
much attention.  Does this happen to you frequently?  If so, does it
happen with many files?  You could solve this either by changing the
value as a file-local variable or globally by customizing the limit in
your init files.  What I don't understand is why should we make
significant changes that will affect everyone, when the problem is
rare and affects only you or a small number of users?  User options
exist because no single value can ever be good for everyone or every
situation, so the right solution for such cases is to customize the
option.

Or what am I missing?





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb.
  2024-01-06  7:01             ` Eli Zaretskii
@ 2024-01-06 12:09               ` Stefan Kangas
  0 siblings, 0 replies; 14+ messages in thread
From: Stefan Kangas @ 2024-01-06 12:09 UTC (permalink / raw)
  To: Eli Zaretskii, Antero Mejr; +Cc: 68234

Eli Zaretskii <eliz@gnu.org> writes:

> AFAIU, this will show nothing when the matching parenthesis is not
> found?  If so, why is that a good idea?

I guess the point is to avoid false positives: Emacs confidently says
"no matching paren", but actually there is one.  We just didn't try hard
enough to find it.

On the other hand, perhaps we could just adjust the message to make it
more clear: "no matching parenthesis within 100000 characters" or
something like that (but only if the buffer is indeed longer).  (But
then I wouldn't bother with the (* 100 1024) part, and just do 100000 or
200000 outright to improve the display.  This is a nit though.)





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb.
  2024-01-05  7:49         ` Eli Zaretskii
  2024-01-05 20:50           ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-01-09  5:56           ` Stefan Kangas
  1 sibling, 0 replies; 14+ messages in thread
From: Stefan Kangas @ 2024-01-09  5:56 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: antero, 68234

Eli Zaretskii <eliz@gnu.org> writes:

> I think we can at most double it at this time.  This is a defcustom,
> so people can always increase it in their local configurations if they
> have much faster machines and need routinely to cope with such large
> parenthetical expressions.

Sounds good to me.

Note that performance only comes into play for ending parens, and if
there is no matching open paren.

>> Note finally that the above examined files are unusually large (as is
>> often the case in our tree).
>
> What matters is not the size of the file, but the size of a
> parenthetical expression.

That would be the best case.

The file size is the upper bound if there's no matching opening paren
(the worst case).





^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-01-09  5:56 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-03 18:37 bug#68234: [PATCH] Increase blink-matching-paren-distance by 300kb Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
     [not found] ` <handler.68234.B.170430710530123.ack@debbugs.gnu.org>
2024-01-03 18:48   ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-04 11:31     ` Eli Zaretskii
2024-01-04 23:08       ` Stefan Kangas
2024-01-05  7:49         ` Eli Zaretskii
2024-01-05 20:50           ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-05 21:10             ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-06  7:01             ` Eli Zaretskii
2024-01-06 12:09               ` Stefan Kangas
2024-01-09  5:56           ` Stefan Kangas
2024-01-04  4:50 ` Stefan Kangas
2024-01-04 19:22   ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-04 21:03 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-04 21:36   ` Antero Mejr via Bug reports for GNU Emacs, the Swiss army knife of text editors

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).