unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Eli Zaretskii <eliz@gnu.org>, Stefan Monnier <monnier@iro.umontreal.ca>
Cc: rahguzar@zohomail.eu, 61098@debbugs.gnu.org
Subject: bug#61098: 29.0.60; Confusing behavior of show-paren-mode
Date: Sun, 5 Feb 2023 19:21:29 +0200	[thread overview]
Message-ID: <4731344a-7406-5cf0-43eb-c77520c2a2c1@yandex.ru> (raw)
In-Reply-To: <83tu00qgmu.fsf@gnu.org>

On 05/02/2023 17:24, Eli Zaretskii wrote:
>> From: Stefan Monnier<monnier@iro.umontreal.ca>
>> Cc:rahguzar@zohomail.eu,61098@debbugs.gnu.org,dgutov@yandex.ru
>> Date: Sun, 05 Feb 2023 10:19:24 -0500
>>
>>> I guess I don't understand what show-paren-local-mode does, then.  Let
>>> me explain my line of reasoning:
>>>
>>>    (define-minor-mode show-paren-local-mode
>>>      "Toggle `show-paren-mode' only in this buffer."
>>>      :variable ( show-paren-mode .
>>> 		(lambda (val) (setq-local show-paren-mode val)))
>>>      (cond
>>>       ((eq show-paren-mode (default-value 'show-paren-mode))
>>>        (unless show-paren-mode
>>> 	(show-paren--delete-overlays))
>>>        (kill-local-variable 'show-paren-mode))
>>>       ((not (default-value 'show-paren-mode))
>>>        ;; Locally enabled, but globally disabled.
>>>        (show-paren-mode 1)                ; Setup the timer.
>>>        (setq-default show-paren-mode nil) ; But keep it globally disabled.
>>>        )
>>>       (t ;; Locally disabled only.
>>>        (show-paren--delete-overlays))))
>>>
>>> When I looked at the above function and stepped through it in the OP's
>>> scenario, what I saw was that the 2nd condition of 'cond' doesn't
>>> fire, because the default-value of show-paren-mode is t nowadays.  So
>>> I concluded that this code relies on the mode being globally off by
>>> default, and attempted to fix the condition that turns the mode on
>>> locally even though it is on globally.
>> But if the mode is already globally enabled, the (setq-default show-paren-mode nil)
>> will definitely not be right: you'd end up disabling it globally (while
>> maybe keeping it enabled locally).
>>
>>> The predicate used by the timer requires either a match of the buffer
>>> (which doesn't happen in this case) or that the local value of
>>> show-paren-mode is non-nil.  Setting the local value non-nil is the
>>> job of the mode function, isn't it?
>> Yes, but the first branch of the `cond` incorrectly does
>> `kill-local-variable` under the assumption that the local value doesn't
>> matter if it's the same as the global one, but that's not true here
>> because (as a wise man said):
>>
>>     The predicate used by the timer requires either a match of the buffer
>>     (which doesn't happen in this case) or that the local value of
>>     show-paren-mode is non-nil.
> This answers only half of my questions, but if you and Dmitry think
> Dmitry's patch will solve this problem, then Dmitry, please install it
> and close this bug.

Installed.

Some testing revealed a certain issue, which until now was not really a 
problem:

The first time I 'M-x show-paren-local-mode' with show-paren-mode 
enabled globally, it _turns off_ the mode locally. Which kind of makes 
sense for a lot of cases, but not when the user's intention is to 
forcibly enable it.

Evaluating (show-paren-local-mode 1) still does the intended thing, though.

Just as well as (add-hook 'some-special-mode #'show-paren-local-mode).

Toggling 'M-x show-paren-local-mdoe' twice also does that.

If we do consider this a problem, a further fix could look like this:

diff --git a/lisp/paren.el b/lisp/paren.el
index 7ee4e9ae682..f2756db6cd9 100644
--- a/lisp/paren.el
+++ b/lisp/paren.el
@@ -161,7 +161,9 @@ show-paren--delete-overlays
  ;;;###autoload
  (define-minor-mode show-paren-local-mode
    "Toggle `show-paren-mode' only in this buffer."
-  :variable ( show-paren-mode .
+  :variable ( (and show-paren-mode
+                   (buffer-match-p show-paren-predicate (current-buffer)))
+              .
                (lambda (val) (setq-local show-paren-mode val)))
    (cond
     ((eq show-paren-mode (default-value 'show-paren-mode))






  reply	other threads:[~2023-02-05 17:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-27 16:03 bug#61098: 29.0.60; Confusing behavior of show-paren-mode Rah Guzar via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-28 12:20 ` Eli Zaretskii
2023-01-30 19:21   ` Rah Guzar via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-31 12:03     ` Eli Zaretskii
2023-01-31 13:03       ` Rah Guzar via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-31 14:13         ` Eli Zaretskii
2023-01-31 14:41           ` Dmitry Gutov
2023-01-31 22:42       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-01 17:48         ` Eli Zaretskii
2023-02-05 15:19           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-05 15:24             ` Eli Zaretskii
2023-02-05 17:21               ` Dmitry Gutov [this message]
2023-02-05 18:29                 ` Eli Zaretskii
2023-02-05 19:06                   ` Dmitry Gutov
2023-02-05 18:57                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-05 19:09                   ` Dmitry Gutov
2023-01-31  2:37   ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4731344a-7406-5cf0-43eb-c77520c2a2c1@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=61098@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=rahguzar@zohomail.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).