From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#61098: 29.0.60; Confusing behavior of show-paren-mode Date: Sun, 5 Feb 2023 19:21:29 +0200 Message-ID: <4731344a-7406-5cf0-43eb-c77520c2a2c1@yandex.ru> References: <877cx8ose0.fsf@zohomail.eu> <83o7qiam16.fsf@gnu.org> <87y1pjstse.fsf@zohomail.eu> <83r0va3o8f.fsf@gnu.org> <83k011z38k.fsf@gnu.org> <83tu00qgmu.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7004"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Cc: rahguzar@zohomail.eu, 61098@debbugs.gnu.org To: Eli Zaretskii , Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 05 18:22:15 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 1pOiiT-0001ZQ-H9 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 05 Feb 2023 18:22:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pOiiK-0007Hw-FB; Sun, 05 Feb 2023 12:22:04 -0500 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 1pOiiI-0007Hm-KD for bug-gnu-emacs@gnu.org; Sun, 05 Feb 2023 12:22:02 -0500 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 1pOiiI-0005Uh-Be for bug-gnu-emacs@gnu.org; Sun, 05 Feb 2023 12:22:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pOiiI-00064n-7g for bug-gnu-emacs@gnu.org; Sun, 05 Feb 2023 12:22:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 05 Feb 2023 17:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61098 X-GNU-PR-Package: emacs Original-Received: via spool by 61098-submit@debbugs.gnu.org id=B61098.167561770023326 (code B ref 61098); Sun, 05 Feb 2023 17:22:02 +0000 Original-Received: (at 61098) by debbugs.gnu.org; 5 Feb 2023 17:21:40 +0000 Original-Received: from localhost ([127.0.0.1]:46379 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pOihv-000649-Nh for submit@debbugs.gnu.org; Sun, 05 Feb 2023 12:21:40 -0500 Original-Received: from mail-ej1-f49.google.com ([209.85.218.49]:46942) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pOihu-00063o-00 for 61098@debbugs.gnu.org; Sun, 05 Feb 2023 12:21:38 -0500 Original-Received: by mail-ej1-f49.google.com with SMTP id p26so28080464ejx.13 for <61098@debbugs.gnu.org>; Sun, 05 Feb 2023 09:21:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=8bJhpfQ4EhtfqNMy3N8f3D1LZaiVPmwuw4mgo0lhx/I=; b=ij6WrZJrnJK07PajT928jlsNJCAa/b5Ht6z2yOZXocImV78a6Ppi82IlI1JmbRoPw4 Y2V03SdNnuO3obkjrROPzcxgbBIQDSSU9Tphnyz+IiOFPbJdwxn8YNUFwKA9Ham6uRg5 dN57zhsq1hqFeCLezuKvaJUYAJNvSLHXtYiGz8jf712fQRtMgMGdOksxU4kHIQMU2Ztf EUQQFXDGIEpM/QDKtDJXNh3jfmY9ZwPVdiFxQbNJxZum1jnQ56ezUjNCE6EjaurysoDs L3RVD2BVY7nCSU0X35Mt2EUBtoXDD0wiUXrj627Ffx1i4rULgV68WdUJyy0KjF8Lj07M kyCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8bJhpfQ4EhtfqNMy3N8f3D1LZaiVPmwuw4mgo0lhx/I=; b=543oGd7nNUEhKUNyyGX8FS18vvrTh1gJIAX+5bV9Q77rJEjbmq0LRado1hfMFWghNM CNY21q6ctC5eGCJOy1tJ1dUzZW9CSiYPJDeFARNc3rMSf43zZeuug1M9MnkBoNUB5A8z Ysy6kE81rXO6MSdFt3g71I45c1BHXN+RiAcU5idFr6MhC7w06lk59uI59d9bQ//GwMzn b1MuURcyiA/OpVTgctxBJqDTyWgoobLHpsWBNbZbs9Lw+BwMhaW8ah3Dwo00nlKAnLKO osq44ddyXQtkVrYiscfmgOGPw3x6KNv3puRqPSIMDv35nnA1AmUe0lAWraSpBaXykOBO L50w== X-Gm-Message-State: AO0yUKVfvM1jX8QWGyV1eFrvRQbR5G+Hf7u5SqmTOHWpB3vaELn4/FcS MMC8+eaZKGvrbAL+dGm1z1Y= X-Google-Smtp-Source: AK7set/DjyaQrKOCUlsHCCg1Q4YI8ZExiPZ2pwndNCZzMbv36MqZNrSqvRhGvgckc3gmjT1pCzQq1g== X-Received: by 2002:a17:906:4f10:b0:87b:d4da:602f with SMTP id t16-20020a1709064f1000b0087bd4da602fmr16830263eju.51.1675617692036; Sun, 05 Feb 2023 09:21:32 -0800 (PST) Original-Received: from [192.168.0.2] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id v26-20020a17090690da00b0086ffe8a00fdsm4292122ejw.84.2023.02.05.09.21.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 05 Feb 2023 09:21:31 -0800 (PST) Content-Language: en-US In-Reply-To: <83tu00qgmu.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:254876 Archived-At: On 05/02/2023 17:24, Eli Zaretskii wrote: >> From: Stefan Monnier >> 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))