From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Parenthesis matching should consider the kind of parenthesis during pair-search Date: Mon, 12 Feb 2024 12:58:18 +0000 Message-ID: References: <87r0hh6g1d.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29500"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: =?iso-8859-1?Q?Herman=2C_G=E9za?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Feb 12 13:59:00 2024 Return-path: Envelope-to: ged-emacs-devel@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 1rZVtj-0007XZ-Mg for ged-emacs-devel@m.gmane-mx.org; Mon, 12 Feb 2024 13:58:59 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rZVtC-0006Ua-0u; Mon, 12 Feb 2024 07:58:26 -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 1rZVt9-0006UR-Q3 for emacs-devel@gnu.org; Mon, 12 Feb 2024 07:58:23 -0500 Original-Received: from mail.muc.de ([193.149.48.3]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rZVt8-0002F4-23 for emacs-devel@gnu.org; Mon, 12 Feb 2024 07:58:23 -0500 Original-Received: (qmail 79036 invoked by uid 3782); 12 Feb 2024 13:58:19 +0100 Original-Received: from acm.muc.de (pd953abfc.dip0.t-ipconnect.de [217.83.171.252]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Mon, 12 Feb 2024 13:58:19 +0100 Original-Received: (qmail 23464 invoked by uid 1000); 12 Feb 2024 12:58:18 -0000 Content-Disposition: inline In-Reply-To: <87r0hh6g1d.fsf@gmail.com> X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.3; envelope-from=acm@muc.de; helo=mail.muc.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:316131 Archived-At: Hello, Géza. On Mon, Feb 12, 2024 at 12:49:03 +0100, Herman, Géza wrote: > Hi all, > Emacs parenthesis matching works differently than I'd have > expected (what show-paren-mode shows). As I understand it, it > searches for the matching pair by not considering the kind of the > parenthesis (no matter whether it's a curly/square/etc bracket). The low level routines like scan-lists work by scanning over text counting the nesting level of open and close parentheses, "ignoring" comments and strings as it goes. (That "ignoring" is somewhat complicated.) When the depth of nesting gets back to zero, that's where the matching close paren is. > And after it found it, then it considers the kind, and if there is > a mismatch then it is shown in red. Usually this is not a > problem, because parentheses come in pairs which are usually > nested. But if this is not true, then Emacs works unexpectedly in > my opinion. See this Makefile example: "$(info })" (this prints a > } to stdout). In this case, emacs shows } as the "matching" pair > of the (. And as the kind doesn't match, it's a mismatch. But > I'd have expected that the pair of ( is the ), and } doesn't have > a matching pair (because this is what actually happens in this > example). > What do you think, shouldn't Emacs consider the kind of > parenthesis when during searching for a pair? (in other words, it > should ignore all other kinds of parentheses when it searches for > a pair) No, I don't think that. ;-) A lot of the time (?most of the time), we want Emacs to point out paren mismatch errors, and that alternative way of scanning parens would prevent this. If you have a specific need to consider only ( and ) as the balancing parens, ignoring [, ], {, }, etc., you can achieve this by removing the open/close syntax-table entries from these characters first. See the chapter "Syntax Tables" in the Elisp manual for details. Be aware that swapping syntax tables repeatedly can slow your program down, since it clears useful caches in doing so. > Thanks, > Geza -- Alan Mackenzie (Nuremberg, Germany).