From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 04 04:49:00 2025 Received: (at submit) by debbugs.gnu.org; 4 Jun 2025 08:49:00 +0000 Received: from localhost ([127.0.0.1]:46941 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uMjnu-0007uX-DJ for submit@debbugs.gnu.org; Wed, 04 Jun 2025 04:48:59 -0400 Received: from lists.gnu.org ([2001:470:142::17]:60446) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uMjnq-0007st-Lx for submit@debbugs.gnu.org; Wed, 04 Jun 2025 04:48:56 -0400 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 1uMjnk-0006Qx-6y for bug-auctex@gnu.org; Wed, 04 Jun 2025 04:48:48 -0400 Received: from mout-p-101.mailbox.org ([80.241.56.151]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1uMjni-0001kl-4B for bug-auctex@gnu.org; Wed, 04 Jun 2025 04:48:47 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4bC1Sx09MGz9sd7; Wed, 4 Jun 2025 10:48:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1749026913; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=G/mvT4XMsfv0Ays0qYYtXaZV/1aDZIGZVOF/OVgkNns=; b=OWmgEryPIRAgUo92AtqfvwVTOo4xvquPuQNmzC7McW8BUxJBfhqbveDbnhMsaEgk9TCT5m ZcW3AxJBQB8A7NSwjRtuHulDirDBRDA1yzMMOFbIorvGarErymQ9+9CzY76uERpo6suK21 +53g2LiiO1XpNZdSJyupBgx8Jl3fXJE8oySTGnwmFnaOc5udarAS+p0EJpo0LyyEmqGNFD 7kI5kvW4cN8iUMdVa9LHWgkUadmZxBOeboTnKe6GRLBO9XoyDtmQlZxpDq+Q1372VewQcS grg5V+UPtW7buqIgrB38jXVN6ZN+/KKb9XwnQ2CK+UwpfEqVh9Z234m64A9vyg== From: Rahguzar To: bug-auctex@gnu.org Subject: 14.0.9; Folding of math macros with a function spec is broken Date: Wed, 04 Jun 2025 13:48:28 +0500 Message-ID: <87bjr3nb8j.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-MBO-RS-META: ddiz8bzzszs3xzhf3cm84xmtautzfpxz X-MBO-RS-ID: ce2494cff2d64b24087 Received-SPF: pass client-ip=80.241.56.151; envelope-from=rahguzar@mailbox.org; helo=mout-p-101.mailbox.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit Cc: ultrono@gmail.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain Dear AucTeX maintainers, The commits d0a57d8d Fix math macro folding to not consume subsequent brackets 33f9eb07 Fix TeX macro end detection in some edge cases break the folding of math macros with a function spec. E.g. evaluate (setq TeX-fold-math-spec-list `((,(lambda (text) (propertize text 'face '(underline))) ("underline")))) and open the attached file. Do `M-x TeX-fold-mode RET` followed by `M-x TeX-fold-buffer RET`. This results in [Error: no content or function found] getting displayed instead of \underline. My config has many folding specs which are functions and all of them exhibit the same behavior. Reverting the commits above fixes the issue. Thanks, Rahguzar Emacs : GNU Emacs 30.1 (build 1, aarch64-redhat-linux-gnu, GTK+ Version 3.24.49, cairo version 1.18.2) of 2025-04-08 Package: 14.0.9 current state: ============== (setq window-system 'pgtk LaTeX-version "2e" TeX-style-path '("/home/azeem/.local/state/emacs/auctex/" "/home/azeem/.local/state/emacs/elpaca/builds/auctex/style" "/home/azeem/.local/state/emacs/auctex/auto" "/home/azeem/.local/state/emacs/auctex/style" "auto" "style") TeX-auto-save nil TeX-parse-self nil TeX-master t TeX-command-list '(("TeX" "%(PDF)%(tex) %(file-line-error) %`%(extraopts) %S%(PDFout)%(mode)%' %(output-dir) %t" TeX-run-TeX nil (plain-TeX-mode AmSTeX-mode Texinfo-mode) :help "Run plain TeX") ("LaTeX" "%`%l%(mode)%' %T" TeX-run-TeX nil (LaTeX-mode docTeX-mode) :help "Run LaTeX") ("Makeinfo" "makeinfo %(extraopts) %(o-dir) %t" TeX-run-compile nil (Texinfo-mode) :help "Run Makeinfo with Info output") ("Makeinfo HTML" "makeinfo %(extraopts) %(o-dir) --html %t" TeX-run-compile nil (Texinfo-mode) :help "Run Makeinfo with HTML output") ("AmSTeX" "amstex %(PDFout) %`%(extraopts) %S%(mode)%' %(output-dir) %t" TeX-run-TeX nil (AmSTeX-mode) :help "Run AMSTeX") ("ConTeXt" "%(cntxcom) --once %(extraopts) %(execopts)%t" TeX-run-TeX nil (ConTeXt-mode) :help "Run ConTeXt once") ("ConTeXt Full" "%(cntxcom) %(extraopts) %(execopts)%t" TeX-run-TeX nil (ConTeXt-mode) :help "Run ConTeXt until completion") ("BibTeX" "bibtex %(O?aux)" TeX-run-BibTeX nil (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode ConTeXt-mode) :help "Run BibTeX") ("Biber" "biber %(output-dir) %s" TeX-run-Biber nil (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help "Run Biber") ("Texindex" "texindex %s.??" TeX-run-command nil (Texinfo-mode) :help "Run Texindex") ("Texi2dvi" "%(PDF)texi2dvi %t" TeX-run-command nil (Texinfo-mode) :help "Run Texi2dvi or Texi2pdf") ("View" "%V" TeX-run-discard-or-function t t :help "Run Viewer") ("Print" "%p" TeX-run-command t t :help "Print the file") ("Queue" "%q" TeX-run-background nil t :help "View the printer queue" :visible TeX-queue-command) ("File" "%(o?)dvips %d -o %f " TeX-run-dvips t (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help "Generate PostScript file") ("Dvips" "%(o?)dvips %d -o %f " TeX-run-dvips nil (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help "Convert DVI file to PostScript") ("Dvipdfmx" "dvipdfmx -o %(O?pdf) %d" TeX-run-dvipdfmx nil (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help "Convert DVI file to PDF with dvipdfmx") ("Ps2pdf" "ps2pdf %f %(O?pdf)" TeX-run-ps2pdf nil (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help "Convert PostScript file to PDF") ("LaTeXMk" "latexmk %(latexmk-out) %(file-line-error) %(output-dir) %`%(extraopts) %S%(mode)%' %t" TeX-run-TeX nil (LaTeX-mode docTeX-mode) :help "Run LaTeXMk") ("Glossaries" "makeglossaries %(d-dir) %s" TeX-run-command nil (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help "Run makeglossaries to create glossary file") ("Index" "makeindex %(O?idx)" TeX-run-index nil (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help "Run makeindex to create index file") ("upMendex" "upmendex %(O?idx)" TeX-run-index t (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help "Run upmendex to create index file") ("Xindy" "texindy %s" TeX-run-command nil (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode) :help "Run xindy to create index file") ("Check" "lacheck %s" TeX-run-compile nil (LaTeX-mode) :help "Check LaTeX file for correctness") ("ChkTeX" "chktex -v6 %s" TeX-run-compile nil (LaTeX-mode) :help "Check LaTeX file for common mistakes") ("Spell" "(TeX-ispell-document \"\")" TeX-run-function nil t :help "Spell-check the document") ("Clean" "TeX-clean" TeX-run-function nil t :help "Delete generated intermediate files") ("Clean All" "(TeX-clean t)" TeX-run-function nil t :help "Delete generated intermediate and output files") ("Other" "" TeX-run-command t t :help "Run an arbitrary command")) ) --=-=-= Content-Type: application/x-tex Content-Disposition: attachment; filename=test.tex Content-Transfer-Encoding: base64 XGRvY3VtZW50Y2xhc3N7YXJ0aWNsZX0KClxiZWdpbntkb2N1bWVudH0KJFx1bmRlcmxpbmV7YWJj fSQKXGVuZHtkb2N1bWVudH0K --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 04 06:32:23 2025 Received: (at submit) by debbugs.gnu.org; 4 Jun 2025 10:32:23 +0000 Received: from localhost ([127.0.0.1]:47651 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uMlPy-0005hW-Sc for submit@debbugs.gnu.org; Wed, 04 Jun 2025 06:32:23 -0400 Received: from lists.gnu.org ([2001:470:142::17]:54224) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uMlPv-0005h3-VS for submit@debbugs.gnu.org; Wed, 04 Jun 2025 06:32:20 -0400 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 1uMlPp-0004w2-J8 for bug-auctex@gnu.org; Wed, 04 Jun 2025 06:32:13 -0400 Received: from mail-lj1-x230.google.com ([2a00:1450:4864:20::230]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uMlPn-0006g8-Ku for bug-auctex@gnu.org; Wed, 04 Jun 2025 06:32:13 -0400 Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-3105ef2a08dso55208461fa.0 for ; Wed, 04 Jun 2025 03:32:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749033130; x=1749637930; darn=gnu.org; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=9AS3n6R4jfnvaDM5RJ0RzshwYQim/zCVvO9Bgk59Bjw=; b=ZUxJd0QhbzcWfI7C7EE4gfGPTHr7KDwshg9XaqmCIE12HFmCpc4J5gd/a5hJBWWS/s 94bhVkckt4COfWk4CnA1ON/QhTfoNMbTAzoiaYVSVfzhElvY39sUUYvtrWdYshx6fFyw 2a20cxRZZlU7pVfOBgxKxT+xfOXUotXfiscYCkH5IU6cYn7Z/sQ4mk+v5vPJ7imtp5yw rfNQKn02Lr8bu+ms25vcDY1B2Fygmdz/lNhkLHjo/KCzqyMWxVZMOmyhtwYV0uya2ey7 5SOMUJRk1fwj+J0KTcdoJcM5Liy2xQAodYIuw92P+Vqa+t3xur49WcnAmpRgJAZZMyT6 3DBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749033130; x=1749637930; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9AS3n6R4jfnvaDM5RJ0RzshwYQim/zCVvO9Bgk59Bjw=; b=iqKQR+bpH4F+rOSWmQeKqAXGYI7ftNGw6IAohwlNYHjRbqr73tK8pqzxPRmp+33o2w sT6G2cspFYwDH3qg7ow5ErfNaiKmQTIM6x9nmXlNbWZTfnQtMvwdbHxve7bipmFPpoxY gon2Bp83rbhs/8NMawVRl7UiJiGIXm4ej1gm47gu8w0oVx7gNKelGW1sTDhRxaJuBc9r 3UzySF+PjSxDdSBTn8odlyGmuM6e4Hz6YiRbEJV0/B5j4DYtyX6b9hE5XDxoQ9DNnl9g ad5sxNN3RVDfariZWJKbl8GKIZYAM6nVWVFfViRo5RTF5uNljZB9BkPC1bnkQ/Mw4Fzk 5n6Q== X-Gm-Message-State: AOJu0YySQXQsNtU2BBzF/KCTegSzT/x+OrdnIFyxQIDMxWvaF4ZQBnBd MkxQA+/MYvj5lgtmvQ/QG8YxNNhWa1ZSq0Ep1Le1j6c/kL53ORlfHceo X-Gm-Gg: ASbGncszIrY5FVEWIGj5z9HtQrCkYxOqgwMY7VESMmfbTEUrRzp67ryCZ4bgY3muiJU 8qWLsbyOTyqMjadUnYi+E2TPF3W/T94fiN31BccVMFG/5wy1/eA/RiWm36s79sLGRvcsO6I9l4C G0Bw/RPIxBSWBIEv0tiacw7LGcTbX0yxZvWghIcLKafn4uxw6wJKHvQuTtfGWMYHAb59DoBSB9s lPS75axI+GoMMhRpfO/7ooKZ4E+Ch+kG1iMk5SS0DnhwSMmmqcpLq64ZWgtg2GFis87kiMyOkHx DyN6KaRcFLNi8a3ghuw+pvq7mH7wDz1mF+S1mqKOfzLnC+ET+os8IKb3giOLnY/U+0pax9f1vFc n1W1UldKJ9P30hCuMBtjBH299jgfhbQ== X-Google-Smtp-Source: AGHT+IErFpJSigw5Fg06S8X5DbolxoNHU33PuIEKmwuL4q0RazKPrr2PZIr1Lxr6maDFHIRVinaa6Q== X-Received: by 2002:a2e:b8c6:0:b0:32a:7f39:1a2a with SMTP id 38308e7fff4ca-32ac71d986fmr6142971fa.16.1749033129581; Wed, 04 Jun 2025 03:32:09 -0700 (PDT) Received: from localhost (wlan-eduroam-130-237-240-154.su.se. [130.237.240.154]) by smtp.gmail.com with UTF8SMTPSA id 38308e7fff4ca-32a85bd26e5sm20847551fa.96.2025.06.04.03.32.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jun 2025 03:32:09 -0700 (PDT) From: "Paul D. Nelson" To: Rahguzar Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: <87bjr3nb8j.fsf@mailbox.org> (message from Rahguzar on Wed, 04 Jun 2025 13:48:28 +0500) Date: Wed, 04 Jun 2025 12:32:08 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2a00:1450:4864:20::230; envelope-from=ultrono@gmail.com; helo=mail-lj1-x230.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit Cc: bug-auctex@gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Thanks Raghuzar. The issue is the result of this change: --8<---------------cut here---------------start------------->8--- diff --git a/tex-fold.el b/tex-fold.el index 766270ef..78e5b822 100644 --- a/tex-fold.el +++ b/tex-fold.el @@ -901,6 +901,12 @@ TYPE can be either `env' for environments, `macro' for macros or (goto-char (1+ start)) (LaTeX-find-matching-end) (point)) + ((eq type 'math) + (goto-char (1+ start)) + (if (zerop (skip-chars-forward "A-Za-z@")) + (forward-char) + (skip-chars-forward "*")) + (point)) (t (goto-char start) (TeX-find-macro-end))))) --8<---------------cut here---------------end--------------->8--- The intent here was that "math macros" built-in to tex-fold don't take arguments, but this is not the case for the custom one you provide. > (setq TeX-fold-math-spec-list `((,(lambda (text) (propertize text 'face '(underline))) ("underline")))) Is there a reason to prefer this vs. the same with TeX-fold-macro-spec-list in place of TeX-fold-math-spec-list? Paul From debbugs-submit-bounces@debbugs.gnu.org Fri Jun 06 05:39:16 2025 Received: (at 78693) by debbugs.gnu.org; 6 Jun 2025 09:39:16 +0000 Received: from localhost ([127.0.0.1]:41933 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uNTXf-0007FV-Qw for submit@debbugs.gnu.org; Fri, 06 Jun 2025 05:39:16 -0400 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]:48529) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uNTXc-0007FG-DV for 78693@debbugs.gnu.org; Fri, 06 Jun 2025 05:39:13 -0400 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-5532f9ac219so2247922e87.1 for <78693@debbugs.gnu.org>; Fri, 06 Jun 2025 02:39:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749202746; x=1749807546; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=k3rsnAXSjdviPk90cgvn7rkGoHh7+ndrwqx8KmIPztA=; b=FwRkbJLaJGtDyNayKnEPsCsBbjjhque9hCddEeF8q9Ey6SJNvoh2lmxPPLH0QY4dca uEcxJX5EbWch/eZHXy8wc4a/W477Dv56O2PAPI4C3DL4FsfoHXnVJ9zIU59s9fS3oEmb P5sD/sJJkK/YHQ7CDmUQ/PVW61gvUVh48CNrfOdmc72i72gbjVnLQeg1DnrAiFC7YLAs kISkAzJ8x9ykxeo1Foo+iKTlrwzv2mFg4iotJZVbIktfPAwk9cz1IQQ3uT94vCsKwAFD cf0kgQJaPM0wwLxHy3HHwX+Yx/O3iYocXIN40hdXgBsWS2kXKamN9saFTtYwQ2qN8v0D KZMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749202746; x=1749807546; h=content-transfer-encoding:mime-version:message-id:date:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=k3rsnAXSjdviPk90cgvn7rkGoHh7+ndrwqx8KmIPztA=; b=UU2GOqoSKEDQZPMoZtuZC1JdJVXWHx2TN3kn6E7zR1dY5Ycyr8jFg9cMSWkwnpFDiy b3wbNVEwbdUdvQP6wDrDIy3fxsWIDesdTl/IhidUv1FnesGrsCb2NLl1ImsegLuzBUZX YTvAW5/ZZHZgjvCYBxiLNDXJ0f6fP8Yp1dVdNu2PNztGHxaukQb0Vz9audM73HvyKIJA H/EMokKiFpb+OS9vwdtO/ZC53c9PXNPRZM2klY10yvpX0WdPhw92smJ4AAOIOM6ABZri RLy4dSkb2B9gYSXibYn5J3qKyp9nnBiI0OOJY29oqZSfm5i1dhQ5bxPyBBcA8LAq01X3 ErLQ== X-Gm-Message-State: AOJu0YztCmh2CW0LBmO/Z1b52TO7wk+C8/tbBOBcBhiTH3kTAzM1mB5u MqKXIO+V5nVwqdDz3O57PW1dtU4Rxq0gT2nRHF+Bntrmf1XM/2map1xD X-Gm-Gg: ASbGncui8RK032SbXNPMFuVY2rj8WXt4mKYRPZ4JURihwF5USFfRWiApzj+hDlASmZl 7WddzrK5tyx7WZe1r7rj3sRiPOlU1zaLMT9b7Ke25mtVbf4quCrBwEoJtE3XZsI9mGbFyI8lYIk 5fOeFWZl9ZF3pTBaZHCDG0pcy9Jptp0Hefm8xhLwsI2gT//7gC4dgp3c9PoNqQctNZWk/U1COqQ h2APtRyCfCi3AOjnvn3Fu+N28o+0bOf+Jzh8immsNB3Q8RrLmSve9DjY1EsI0WSsp7NClgFRcJV GCcZL85i0hA5karMfRoCKEbdD4gxnKescgUITSZN3shaDdWAc+q+AXruRQ== X-Google-Smtp-Source: AGHT+IG0TURswVQ5hsBurXkL+2WO2x9UDxaSbZgYSvImmfro2DlyhpwyglYxwKzdMLhkV5yl7iDiqQ== X-Received: by 2002:a05:6512:3d03:b0:553:2418:8c0c with SMTP id 2adb3069b0e04-55366c39e0cmr587546e87.57.1749202745335; Fri, 06 Jun 2025 02:39:05 -0700 (PDT) Received: from localhost ([131.164.245.154]) by smtp.gmail.com with UTF8SMTPSA id 2adb3069b0e04-553676d7638sm136031e87.83.2025.06.06.02.39.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jun 2025 02:39:04 -0700 (PDT) From: "Paul D. Nelson" To: Rahguzar Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: <877c1qlu6l.fsf@mailbox.org> (message from Rahguzar on Thu, 05 Jun 2025 08:54:26 +0500) Date: Fri, 06 Jun 2025 11:39:03 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 3.6 (+++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Hi Raghuzar, thanks for your suggestions. Regarding (1) and (2), I searched my shared tex projects and found examples that those approaches would not fold correctly: > 1) Assume that there is no white-space between the macro name and the > brackets enclosing the arguments. This is probably not how TeX syntax > works but I think (not too sure about this) it is the [...] Content analysis details: (3.6 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 3.6 RCVD_IN_SBL_CSS RBL: Received via a relay in Spamhaus SBL-CSS [131.164.245.154 listed in zen.spamhaus.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (ultrono[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:129 listed in] [list.dnswl.org] X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 2.6 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Hi Raghuzar, thanks for your suggestions. Regarding (1) and (2), I searched my shared tex projects and found examples that those approaches would not fold correctly: > 1) Assume that there is no white-space between the macro name and the > brackets enclosing the arguments. This is probably not how TeX syntax > works but I think (not too sure about this) it is the [...] Content analysis details: (2.6 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:129 listed in] [list.dnswl.org] 3.6 RCVD_IN_SBL_CSS RBL: Received via a relay in Spamhaus SBL-CSS [131.164.245.154 listed in zen.spamhaus.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (ultrono[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager Hi Raghuzar, thanks for your suggestions. Regarding (1) and (2), I searched my shared tex projects and found examples that those approaches would not fold correctly: > 1) Assume that there is no white-space between the macro name and the > brackets enclosing the arguments. This is probably not how TeX syntax > works but I think (not too sure about this) it is the usual style. This > behavior can be controlled by a custom variable. "\in[0,1]" I also worry that style like \includegraphics [width=3D0.8\textwidth] {result.pdf} is not too uncommon. > 2) Since the problem is with optional arguments we can allow { after the > macro name but not [. "\in{\rm SL}_2" > 3) Another option can be to introduce a new spec alist for macros > without optional args. Maybe call it TeX-fold-unargumented-spec-list. Then, we would have: TeX-fold-macro-spec-list TeX-fold-math-spec-list TeX-fold-env-spec-list TeX-fold-unargumented-spec-list The defaults for *math* would move to *unargumented* and *macro*/*math* would behave identically. This seems a bit complicated. Moreover, none of the above solutions address related (but rarer) issues with argumented macros. For instance, if one includes \mathbf in *macro*/*math*, then the following folds incorrectly: $\mathbf{text} [0,1]$ (I feel like I've seen similar examples occur organically over the years, but can't quickly think of one.) ---------------------------------------------------------------------- Here's a proposed solution that seems more robust to me. Recall that *macro*/*math* are lists consisting of items (SPEC (M1 M2 ...)), where SPEC is a display specification (an integer, a string or a function) and M1, M2, ... are macro names as strings. We could enhance the display specification to allow ((SPEC . SIG) (M1 M2 ...)), where SIG is a "signature" that restricts the number of args: - nil means no restriction, - an integer n means at most n total args (so 0 means unargumented), and - a cons cell (p . q) means at most p optional and q required args. With that enhancement, we could revert d0a57d8d and tag the defaults for LaTeX-fold-math-spec-list with "0", e.g., ("=E2=88=88" ("in")) -> (("=E2=88=88" . 0) ("in")) That would fix the original "\in [0,1]" issue as well as the issue raised by Raghuzar. It would also make it easy to fix related issues, like the one with \mathbf noted above. Thoughts? ---------------------------------------------------------------------- I also thought I'd link the original proposal [1] for TeX-fold math-spec-list. My reading is that the purpose of the *macro*/*math* split was just to better organize the defaults. [1] https://lists.gnu.org/archive/html/auctex-devel/2007-01/msg00078.html ---------------------------------------------------------------------- Finally, I noticed that we've been CC'ing bug-auctex rather than the specific bug number, which is generating duplicated bugs at https://lists.gnu.org/archive/html/bug-auctex/2025-06/threads.html. I've tried to fix that here. From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 07 13:33:07 2025 Received: (at 78693) by debbugs.gnu.org; 7 Jun 2025 17:33:07 +0000 Received: from localhost ([127.0.0.1]:49487 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uNxPn-0005PP-0f for submit@debbugs.gnu.org; Sat, 07 Jun 2025 13:33:07 -0400 Received: from mout-p-201.mailbox.org ([80.241.56.171]:46124) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uNxPj-0005Oj-DY for 78693@debbugs.gnu.org; Sat, 07 Jun 2025 13:33:05 -0400 Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4bF4yX3bqfz9sv0; Sat, 7 Jun 2025 19:32:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1749317572; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NDQ1KzOARol7YNDCdaZib2p8qVBy88eRSld3WMP1LM4=; b=XqbwbkcmaQyQT8/311KsUYFQzVL2Xy/RKAvoGq/cx/rDu9TiIKCYruVyc1p+eeLeIlZabh wTo63DN3HvYfTQfZnrNIqUM1bDUUG/IupaE52k+YXC4yRq79p8ElEnPPZvn/0ZTk3TYuBs quzuehQIxBx0PyMPq9LzewPUw6knCmXgmjQOi2x++8ru6io4ZbkSqJyAXormrqDvakG8JI SY0F6Jl4FDJr8IUTDDfE2C7O4VFy4S/7Ao66/RNe+kbmASak+yWmJcSiQq8m2kpmuyeSPU 6g+2jgp46wIh1WV8wFaMsXAApLxh7e3xHm7BK4II6cp+suFMDAWPvDuVQra60w== From: Rahguzar To: "Paul D. Nelson" Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: (Paul D. Nelson's message of "Fri, 06 Jun 2025 11:39:03 +0200") References: Date: Sat, 07 Jun 2025 22:32:46 +0500 Message-ID: <87bjqzihj5.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-MBO-RS-META: 7dsrkznw9w3reic36zezy3fcneoik1q1 X-MBO-RS-ID: 0c8c111011a08c621fa X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Hi Paul, "Paul D. Nelson" writes: > Here's a proposed solution that seems more robust to me. Recall that > *macro*/*math* are lists consisting of items > > (SPEC (M1 M2 ...)), > > where SPEC is a display specification (an integer, a string or a > function) and M1, M2, ... are macro names as strings. We could enhance > the display specification to allow > > ((SPEC . SIG) (M1 M2 ...)), > > where SIG is a "signature" that restricts the number of args: > > - nil means no restriction, > > - an integer n means at most n total args (so 0 means unargumented), and > > - a cons cell (p . q) means at most p optional and q required args. > > With that enhancement, we could revert d0a57d8d and tag the defaults for > LaTeX-fold-math-spec-list with "0", e.g., > > ("=E2=88=88" ("in")) -> (("=E2=88=88" . 0) ("in")) > > That would fix the original "\in [0,1]" issue as well as the issue > raised by Raghuzar. It would also make it easy to fix related issues, > like the one with \mathbf noted above. Thoughts? I like this proposal. It is backward compatible I think it should also allow us to deal with optional arguments in a function spec. Currently if the spec is a function it only receives the mandatory arguments. If the number of arguments is part of the spec we can allow it to receive up to p+q args without breaking existing code. > Finally, I noticed that we've been CC'ing bug-auctex rather than the > specific bug number, which is generating duplicated bugs at > https://lists.gnu.org/archive/html/bug-auctex/2025-06/threads.html. > I've tried to fix that here. Thanks for catching this. I was surprised by emails about those new bugs. Rahguzar From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 07 14:33:05 2025 Received: (at 78693) by debbugs.gnu.org; 7 Jun 2025 18:33:05 +0000 Received: from localhost ([127.0.0.1]:49578 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uNyLp-0002fm-4r for submit@debbugs.gnu.org; Sat, 07 Jun 2025 14:33:05 -0400 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]:56491) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uNyLn-0002el-D2 for 78693@debbugs.gnu.org; Sat, 07 Jun 2025 14:33:04 -0400 Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-32ac42bb4e4so27223491fa.0 for <78693@debbugs.gnu.org>; Sat, 07 Jun 2025 11:33:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749321177; x=1749925977; darn=debbugs.gnu.org; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=5AjDPgiiFCZ/JlNSUtSXOf8dD/gjPnCHl6HOml11Wiw=; b=FJvfJwD2yipAF15X98IVQjzRwBsu8KnP4d1If+NYBNT2W2XEHNaxCAwGzCyXlv8P9u 8NGN/7v+UOXxRJ1fGw3OvB9iI1+WbBzT3I/EhfUhNzfXVnjeLOlt10MuNqnkOjdY/I9P 9UlAJyIfG0IIAl+r/Pn+qeM4EIgLksa+4NGOtcY+vuRpPcf9OwHq9bli+yqVjF52mUrv fBeVVlAEJtJsjZGBj/c0buaXNySuXHx6fGbaUrfsCVPt8Nqtqzk47kxu8xovbFk8a/t2 pCRQi5wgwEeUnIQxjZBcNZNsTAdEAWEPWHOwDQ+5J5kk5Yb64O033H8UAsFfm4amf+pj ASSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749321177; x=1749925977; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5AjDPgiiFCZ/JlNSUtSXOf8dD/gjPnCHl6HOml11Wiw=; b=UMYVSaS0Ly37r/GeqDlsIL1BisioTgep9Jhdae5TH2LzPgccwXM0/0loVzE28OyPIz n0jVW7uc5DfQBYKlz8KytbMlat1DnhL5VMH5vtu6fzOHrcW/VRaun/dqKyp088tzC+KD s4rXY1iFWLVOp8UBpO3CTQq5ZqEnRaQMj4V/7bPt2it4OYKUFAfVGIMl/DRVkbGyLTSg 9WWMwwWMNDLKoHNVNH1RAvtEnmfdXzQGpj6y2wVVA11CFv0AbUQcH8oh3QBeQNS2O+1N OmQV3tARxq9tsPNMiXg0Tt2WjJHEntY5RssIGsbXhpseGSvff/BY8gkm43Ov6xOLoEgO 0AOQ== X-Gm-Message-State: AOJu0YzBFePX8LTZyvx12bG5+ywDHyPVT/zAAeAhEwwNFjiwJVrZstaj o3T4lRGDUgkfA3tkTUu4ulkhGc6I3uSBiRN8BfLrDNOAlGUHCuyHzV6tXIUKGpKB X-Gm-Gg: ASbGncv+1rEwODIb361eGk9iB7yj71HdXcwuS/Cdg3KiMmlgcPRK0JZuf6PLZCdPg7A X33fRRcyG/PlRCXsznzPMLWyGXQwssJUvnJdaJFyNYnbRV0ArY0CZDcFEd+ofJm+MBScyayPAif bevXKcHelI0qINozjddnoo6z9Ks478APGxAABG2UzrnBmThvJEnWf7YfBSzogPdcQ/KtxIfx5xN OPxvn6bq/dQaFwD4JAU8rhzy9cHbFASdfUhoKPFyaccrAlJIfBMvkZWjzvkMJf6T0Ux2nXzm+Eb MGstave9i3sAE2ErUY6A70g2qmGon2dy6+/bfluMC2Fprx4maQsOCKXg X-Google-Smtp-Source: AGHT+IGA8HDE8OSYwWD7o3KNj2FZ2b1qpakF++/Jwejh4GgWshMNCsHxpRECUETPtkO78q5g6Sh/zg== X-Received: by 2002:a2e:b88c:0:b0:32a:943d:e43 with SMTP id 38308e7fff4ca-32adfb68040mr19041231fa.22.1749321176599; Sat, 07 Jun 2025 11:32:56 -0700 (PDT) Received: from localhost ([185.229.155.48]) by smtp.gmail.com with UTF8SMTPSA id 38308e7fff4ca-32ae1d0367asm5433471fa.114.2025.06.07.11.32.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jun 2025 11:32:55 -0700 (PDT) From: "Paul D. Nelson" To: Rahguzar Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: <87bjqzihj5.fsf@mailbox.org> (message from Rahguzar on Sat, 07 Jun 2025 22:32:46 +0500) Date: Sat, 07 Jun 2025 20:32:53 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi Raghuzar, > I like this proposal. It is backward compatible I think it should also > allow us to deal with optional arguments in a function spec. OK, great. I'll try fleshing it out when I get the chance. > Currently if the spec is a function it only receives the mandatory > arguments. If the number of arguments is part of the spec we can allow > it to receive up to p+q args without breaking existing code. Regarding optional arguments, I am in the habit of extracting those using TeX-fold-macro-nth-arg. This is possible because (with recent enough AUCTeX) the function display spec is always called with point at the beginning of the macro to be folded. See for instance the implementation of TeX-fold-cite-display. For this reason, I'm inclined to first implement the proposal without changing how optional args are used - we could change that later, if desired. Thanks, best, Paul From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 09 14:03:42 2025 Received: (at 78693) by debbugs.gnu.org; 9 Jun 2025 18:03:42 +0000 Received: from localhost ([127.0.0.1]:57052 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uOgqU-0007Wm-0m for submit@debbugs.gnu.org; Mon, 09 Jun 2025 14:03:42 -0400 Received: from mout-p-202.mailbox.org ([80.241.56.172]:56564) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uOgqQ-0007Vr-2A for 78693@debbugs.gnu.org; Mon, 09 Jun 2025 14:03:39 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4bGKXv1xHLz9stK; Mon, 9 Jun 2025 20:03:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1749492207; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GDRWjCWoJKsRmwmUBwxGYKJsb6CRSjmfDBA9Z7HKsEs=; b=vnVRsD+3T3L3d6nsiNBLdoB4NDmk1g4ufGldFEH5E+ySoSPFsau5Hr2DmhEuCgPTvYJGRY Kz3Ndd9CdBYVQRqXMhCZ2I922vPxVHFvy5bHipGCJE9UjNLD/h4A2imnPhm7I9xkJn8f4K dJBZ45XLQqnSfxFFgTl6/rsk042pRBSkfKkzmO+fSBzMq/prHeBrNIAW0/TZCHOORp8mFQ LnbD4TqT5SWCdzDHVd2d/JgjDKsrYvXciHuZYiiwCGhXUD3top5m6NiX+a2hARvfntmSZq jWTFHctvLlGSXlJPknZHEsdL8xjTzVIMPCYuCAHBeA1WMbF+RYBOfGxFPaYoNQ== From: Rahguzar To: "Paul D. Nelson" Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: (Paul D. Nelson's message of "Sat, 07 Jun 2025 20:32:53 +0200") References: Date: Mon, 09 Jun 2025 23:03:18 +0500 Message-ID: <87o6uw3i8p.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: text/plain X-MBO-RS-ID: de8411df30011669d63 X-MBO-RS-META: 57ohc37tjzp7nydnt8hqen4b4hh7obca X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Hi Paul, "Paul D. Nelson" writes: > Hi Raghuzar, > >> Currently if the spec is a function it only receives the mandatory >> arguments. If the number of arguments is part of the spec we can allow >> it to receive up to p+q args without breaking existing code. > > Regarding optional arguments, I am in the habit of extracting those > using TeX-fold-macro-nth-arg. This is possible because (with recent > enough AUCTeX) the function display spec is always called with point at > the beginning of the macro to be folded. See for instance the > implementation of TeX-fold-cite-display. > > For this reason, I'm inclined to first implement the proposal without > changing how optional args are used - we could change that later, if > desired. I think the difference between passing optional arg now vs later would be backward compatibility. Since the the signature part of spec is new there are no backward compatibility concerns. However if people start using the feature assuming no optional arguments are passed to the function and we start passing them later there can be breakage. I think passing the arguments directly to the function is more user friendly. However, I think documenting TeX-fold-macro-nth-arg as the way to access optional arguments is also good enough. > > Thanks, best, > Paul Best, Rahguzar From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 11 03:33:16 2025 Received: (at submit) by debbugs.gnu.org; 11 Jun 2025 07:33:16 +0000 Received: from localhost ([127.0.0.1]:46096 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uPFxU-0005sp-0b for submit@debbugs.gnu.org; Wed, 11 Jun 2025 03:33:16 -0400 Received: from lists.gnu.org ([2001:470:142::17]:43636) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uPFxD-0005r7-12 for submit@debbugs.gnu.org; Wed, 11 Jun 2025 03:32:59 -0400 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 1uPFx7-0007SE-BJ for bug-auctex@gnu.org; Wed, 11 Jun 2025 03:32:53 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPFx5-0003Ly-GT; Wed, 11 Jun 2025 03:32:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=NysgRVepcoa4om6ZRH31MxnH0ZdI8rt6BaILKhV3idM=; b=eQ0B1IC3y/Rw+zl8WN+G 32R8aJbyodcIp/fG4eWBWaMy2o4wucASCsEJHYpf+FT9HnX5A/d250nTgzOxB+RsrrEjlJ2+InV7+ MSJnsqhIj35/S3PAZvqxT6rk7pzgyuJxZUTtmX1+JDdjb6R45Tpc9KL9KWh9bQyGY7fUfbrmTmqVu taNNBRYiNkzBHrbPzn5VLS9Bw7R8LHmOMi4wXa7D1R0GGkaNZckWTQdbZlXH675ODGwtr8r5CAH1s 7AJnuWfOZ+Hv6jpZCfmv87csYGC34IOUeKmHvemhtLjZEt+4bnPC3WtlK98SQD7YE9XLiBzKlOetw XkPqZzmQwrRDSg==; From: Arash Esbati To: Rahguzar via bug-auctex via Bug reporting list for AUCTeX Subject: Re: bug#78693: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: <87bjr3nb8j.fsf@mailbox.org> References: <87bjr3nb8j.fsf@mailbox.org> Date: Wed, 11 Jun 2025 09:32:47 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: submit Cc: 78693@debbugs.gnu.org, Rahguzar , ultrono@gmail.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) forcemerge 78693 78696 78698 thanks Rahguzar via bug-auctex via Bug reporting list for AUCTeX writes: > Dear AucTeX maintainers, > > The commits > > d0a57d8d Fix math macro folding to not consume subsequent brackets > 33f9eb07 Fix TeX macro end detection in some edge cases > > break the folding of math macros with a function spec. Gents, somehow 3 bug reports where opened for this report which I'm merging now. Please try to avoid this in future. TIA. Best, Arash From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 11 03:36:53 2025 Received: (at 78693) by debbugs.gnu.org; 11 Jun 2025 07:36:54 +0000 Received: from localhost ([127.0.0.1]:46112 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uPG0u-000690-CG for submit@debbugs.gnu.org; Wed, 11 Jun 2025 03:36:53 -0400 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]:45178) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uPG0s-00068f-As for 78693@debbugs.gnu.org; Wed, 11 Jun 2025 03:36:46 -0400 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-5533302b49bso6589150e87.2 for <78693@debbugs.gnu.org>; Wed, 11 Jun 2025 00:36:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749627400; x=1750232200; darn=debbugs.gnu.org; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=ibREudmxaDk2nRzoMq7KfiHEQbxBFg+N05yDmwY5+Fg=; b=W62ma/z4tm+Als0YnYysg+Jczudl4tLZhPL4Dbyc45AZk7X3vv9tCPdSmvaxu2adKc q5GSf1gOraC0z5RyV0Jt3TqZ0gg2c2/z2rnbYIGlgjo6MgO6iGwab7Z8g/64RAK/91Kp P8+u9aKd352sRO/5HyhwxJTmnEcsTdgb8Fxf9DlTb0m8Ij/rQCjOavnL5X+bz0T4R5NH kuCUB5WamxoDHMhJI2hWSGA7hBSa1of6dIHtzSGyqv5zBn6XmG2FIEuMnoNfBU/8sjle QqS3an99xg/7TpmCOAZ8iGVJ8uu/XNCaB1xJOOMyX8LCypHTQ0hJqTPg9CadljojBTLe XGfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749627400; x=1750232200; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ibREudmxaDk2nRzoMq7KfiHEQbxBFg+N05yDmwY5+Fg=; b=pbgqmGlFthVink5mqA/533d4Bj+aieaEokn8dbrVb/vI046v6QkJEqWTN2Fsy6HloH flYTVhlFwhV3kRxXQZ6Xvc7zYSsIHplks29GZV92IB+xlYzXBG3DHa7Do6R8mw3kOsBm h6SJNzZH3N/DdKLr6ioVPQGaieJAy5oHuXWs3gDH1vL5wpaFGKNcvOcAD+GdDg+4b3/o X+u936YKb/KZm95SygVTUo3ApBDAK/nRZ9UmM6UTZznpE8b9yUjoIXNDITfuQSN2j5mg 6xPfSs8Wv4rmG1DI8CKEFqZT4cYuVUilWPR8MGyEJdtneZI1dBDkiaIBuP7DCMOd4YSX Bhlg== X-Forwarded-Encrypted: i=1; AJvYcCWxOMcksgLaL4fn0NvXIWy5HqA+b0ea1xdiNbDQdB70y3sGU3KmDhAswDFk/x1EyPS+OeqVvA==@debbugs.gnu.org X-Gm-Message-State: AOJu0YzREXd28RUA+gzvXMq+SEMekjGkLJgBuhkyH9ZcebenQqkqj9KS xkGiDCmRoxUodHmHmLheRDxEZ/nyHpAJYkFI6/BQt1rB0qRbtq/efoEN X-Gm-Gg: ASbGncu5Dus/DHLiW3GqmwbJSk9f+vXsAmHwoXIzWZJ/itAiQOzkNJG5Hau0g0SSTzP ToDCAMX07Jxp95xgmv/8Vv3F3VwxVvk7StEAjQug5+gZ7yM66WHlXI13Plj1MFnfaoSmJvgtaix rG67+pVIWwOJABGLH1cJwrZhtvfouOS60SH9ODkfezk2GhkKiJqie9WDAs+i5MxM2xb1IJ/oaca +8Q58HTXcluGRqOmZCyIpfGjo94q6VdLUKkchy+MqqsMCrwqFlnQYLo8xv+KmMGFeT8FodcoQM4 eXwiR1ALGVgQ/QF7nqrYe04xqu3ncwk+fY3wElCWm2VjUuQyqb546Mk9lfMu9IflXVQ= X-Google-Smtp-Source: AGHT+IG8KJbaKE1JLj8sll+4Wz4TDjjrsDkMXHuZYrIhrvHkwHq+fY0Zx4L7ukS1eFQB4IhHulfGHg== X-Received: by 2002:a05:6512:4006:b0:553:28b8:eecb with SMTP id 2adb3069b0e04-5539c23931bmr780191e87.38.1749627399524; Wed, 11 Jun 2025 00:36:39 -0700 (PDT) Received: from localhost ([185.229.155.48]) by smtp.gmail.com with UTF8SMTPSA id 2adb3069b0e04-553676d0ee3sm1844636e87.8.2025.06.11.00.36.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 00:36:39 -0700 (PDT) From: "Paul D. Nelson" To: Arash Esbati Subject: Re: bug#78693: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: (message from Arash Esbati on Wed, 11 Jun 2025 09:32:47 +0200) Date: Wed, 11 Jun 2025 09:36:38 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78693 Cc: bug-auctex@gnu.org, 78693@debbugs.gnu.org, rahguzar@mailbox.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Arash Esbati writes: > somehow 3 bug reports where opened for this report which I'm merging > now. Please try to avoid this in future. TIA. Thanks. For future reference, the issue is that I was CC'd on the original bug (and responded to that message, causing a cascade of new bugs), but the correct approach (as I've now learned) is to use the X-Debbugs-CC pseudo-header (https://www.debian.org/Bugs/Reporting). From debbugs-submit-bounces@debbugs.gnu.org Sun Jun 15 06:29:37 2025 Received: (at 78693) by debbugs.gnu.org; 15 Jun 2025 10:29:37 +0000 Received: from localhost ([127.0.0.1]:55236 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uQkcK-0008EY-10 for submit@debbugs.gnu.org; Sun, 15 Jun 2025 06:29:37 -0400 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]:49617) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uQkcG-0008Di-Ug for 78693@debbugs.gnu.org; Sun, 15 Jun 2025 06:29:34 -0400 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-606b6dbe316so7450967a12.3 for <78693@debbugs.gnu.org>; Sun, 15 Jun 2025 03:29:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749983366; x=1750588166; darn=debbugs.gnu.org; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=O7ZrhGrnB8CSOUueVf4FMH5dkKdtd9IwPDD668iT50Q=; b=ReaDZX5vZ6AKadadtCPeVb8eXcMRt+7vAB3fVXfHuEn2/huirT+Q5F7XAU1tIkcIo8 g1N06ZUyKTuF23PP22MSvfVE1TvUJOS9xCdxKz2O8j4VmurZylIvU0OXV2e3pNU11WZT NBAV/LExnVkp5zECvQJRmkf/h9YNp6Y2Rap0L09Ymyl9f372t3y/TtfkegG6o0n5zdVo MkBg4pfEUHkB9Zs2Q/uvgZZsfnnWg5umbru5QzmQjTtd62T4ZMn1SC48mGhkhl/jyUwW 2U63rS2OQliRKB5GbMFaJvXZ7bvKsN8XO/u6lv50SprxwAKZ6VuVHoWtz4xNiipV4hAz 6ojw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749983366; x=1750588166; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=O7ZrhGrnB8CSOUueVf4FMH5dkKdtd9IwPDD668iT50Q=; b=uqFmMZxxzwqybMX5JGAP43zXGw8VY0l+ARGaTVkN6YehWs5MVyac18huBJ6ersrEnw aSYEVP7zQmH42IuGxuWVncX9HtJCO0YMIbLwwSGvrUJZZAgjIbd8L+sW0AaZynVPt4qe 0FVgUvLvOsiO8TW3K6YhvAek7qL63ixyBDDXZjlpEis0nRQ08g/bbPPoCBF6OvPdoq7W aQHMnqLXxEWAWRecUWelrDXEx0yvnb9LDagxkgY6gPS+AdknfizemP2zsmU4aG8Yeki+ IFcl49vAXjL9dmpkZqI2+oLafyCyjrRb9VU+7G0SD9riqvjfBPe/u4u0Ylg/WbZuNM08 wPIw== X-Gm-Message-State: AOJu0YzbZMELWchgFyr/3BUvaJrrVj+Et3ZgUo97pBcQOOsnn3Alin+K MUNdjqeyxDnywvDUyRzjo53x6ePlLX8ebnCJrdvx0x6bfuozeQK+SNTD X-Gm-Gg: ASbGncuQNVbwnHKKaDOs4yHnV0dls82fVTYFMcq/fx1HsOjqTsXnxVMQmleJdXnEnE2 MUo5ouYTP6vUjWEHct0Ng8jxsyn4dSvLVJuflr0t7vuciuTjPop2SKvTvM9Ya1bVKlwsxGCyu/D TllqbXjWtpY6yN4dU6b5VkMU9mtTDvBQrLyB63JuzYxaaG5ytL6CirDqSLfn9dlxDip7I7qpPsB 9D3m6VfrjOZ2hdFW7ZtOf2pDAEfkDo+THbCIvTP1sOQ6zevA8eiScLJYEtK34UKyaTs0Vz+RAM8 q8aPM33e+1NcWFmrcWhxn7eVxniFyecUbYuuL2aUnE0rvHQOfL/fdj7a23JdDjwxqRs= X-Google-Smtp-Source: AGHT+IEMeUY8ynE3rx3PbbYrx/bACDoYLTSwdcLdy/O7+SljH+VTQk+jz/1B45H8kycY9pERAHqFyA== X-Received: by 2002:a17:906:4fca:b0:ad8:9909:20ac with SMTP id a640c23a62f3a-adfad596675mr456623066b.50.1749983366313; Sun, 15 Jun 2025 03:29:26 -0700 (PDT) Received: from localhost ([193.33.149.190]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-adec8158d4dsm455240966b.28.2025.06.15.03.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Jun 2025 03:29:25 -0700 (PDT) From: "Paul D. Nelson" To: Rahguzar Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: <87o6uw3i8p.fsf@mailbox.org> (message from Rahguzar on Mon, 09 Jun 2025 23:03:18 +0500) Date: Sun, 15 Jun 2025 12:29:24 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain Hi Raghuzar and all, Please see the attached patch which implements signature support for macro folds, following the plan outlined in my earlier email. This should address both the issue in your report and that in my earlier bug. We also need to update the manual, but I'll do that later once the general shape of the proposal is agreed upon. If you get the chance, please let me know what you think. Thanks, best, Paul --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-signature-support-for-macro-folding.patch >From 2e07366d1d5856f615c8bf7bc36fbbcdf5350055 Mon Sep 17 00:00:00 2001 From: Paul Nelson Date: Sun, 15 Jun 2025 12:24:11 +0200 Subject: [PATCH] Add signature support for macro folding Support signature restrictions to limit the number of arguments considered when folding LaTeX macros (bug#78693). * tex.el (TeX-find-macro-boundaries, TeX-find-macro-end) (TeX-find-macro-end-helper): Add optional SIGNATURE argument to restrict allowed arguments. * tex-fold.el (TeX-fold-macro-spec-list): Update docstring and type specification to document new signature format. (TeX-fold-region-macro-or-env, TeX-fold-item): Extract signature from spec and pass to 'TeX-fold-item-end'. (TeX-fold-item-end): Add optional SIGNATURE parameter. Remove special handling for math type, reverting d0a57d8d and delegating instead to 'TeX-find-macro-end'. * latex.el (LaTeX-fold-math-spec-list): Add "signature 0" to each entry, reflecting that it is a macro with no arguments. --- latex.el | 2 +- tex-fold.el | 108 +++++++++++++++++++++++++++++++--------------------- tex.el | 108 +++++++++++++++++++++++++++++++--------------------- 3 files changed, 130 insertions(+), 88 deletions(-) diff --git a/latex.el b/latex.el index 5bff638b..94666fe8 100644 --- a/latex.el +++ b/latex.el @@ -6729,7 +6729,7 @@ char." "Accents"))) submenu))) (when (and (stringp tex-token) (integerp uchar) noargp) - `(,(char-to-string uchar) (,tex-token))))) + `((,(char-to-string uchar) . 0) (,tex-token))))) `((nil "to" "" 8594) (nil "gets" "" 8592) ,@LaTeX-math-default))) diff --git a/tex-fold.el b/tex-fold.el index 78e5b822..d980ac1b 100644 --- a/tex-fold.el +++ b/tex-fold.el @@ -95,38 +95,55 @@ macros, `math' for math macros and `comment' for comments." "textbf" "textsc" "textup"))) "List of replacement specifiers and macros to fold. -The first element of each item can be a string, an integer or a -function symbol. The second element is a list of macros to fold -without the leading backslash. - -If the first element is a string, it will be used as a display -replacement for the whole macro. Numbers in braces, brackets, -parens or angle brackets will be replaced by the respective macro -argument. For example \"{1}\" will be replaced by the first -mandatory argument of the macro. One can also define -alternatives within the specifier which are used if an argument -is not found. Alternatives are separated by \"||\". They are -most useful with optional arguments. As an example, the default -specifier for \\item is \"[1]:||*\" which means that if there is -an optional argument, its value is shown followed by a colon. If -there is no optional argument, only an asterisk is used as the -display string. - -If the first element is an integer, the macro will be replaced by -the respective macro argument. - -If the first element is a function symbol, the function will be -called with all mandatory arguments of the macro and the result -of the function call will be used as a replacement for the macro. -Such functions typically return a string, but may also return the -symbol `abort' to indicate that the macro should not be folded. +The first element is of the form SPEC or (SPEC . SIG), where SPEC can be +a string, an integer or a function symbol and SIG is described below. +The second element is a list of macros to fold without the leading +backslash. + +If SPEC is a string, it will be used as a display replacement for the +whole macro. Numbers in braces, brackets, parens or angle brackets will +be replaced by the respective macro argument. For example \"{1}\" will +be replaced by the first mandatory argument of the macro. One can also +define alternatives within the specifier which are used if an argument +is not found. Alternatives are separated by \"||\". They are most +useful with optional arguments. As an example, the default specifier +for \\item is \"[1]:||*\" which means that if there is an optional +argument, its value is shown followed by a colon. If there is no +optional argument, only an asterisk is used as the display string. + +If SPEC is an integer, the macro will be replaced by the respective +macro argument. + +If SPEC is a function symbol, the function will be called with all +mandatory arguments of the macro and the result of the function call +will be used as a replacement for the macro. Such functions typically +return a string, but may also return the symbol `abort' to indicate that +the macro should not be folded. + +SIG optionally restricts the number of arguments that follow the macro. +It can be either nil, an integer, or a cons cell consisting of integers. +If it is nil, then there is no restriction. If it is an integer n, then +at most n total arguments are allowed. If it is a cons cell (p . q), +then at most p optional and q required arguments are allowed. Setting this variable does not take effect immediately. Use Customize or reset the mode." - :type '(repeat (group (choice (string :tag "Display String") - (integer :tag "Number of argument" :value 1) - (function :tag "Function to execute")) - (repeat :tag "Macros" (string)))) + :type '(repeat + (group + (choice + (string :tag "Display String") + (integer :tag "Number of argument" :value 1) + (function :tag "Function to execute") + (cons :tag "Spec with signature" + (choice (string :tag "Display String") + (integer :tag "Number of argument" :value 1) + (function :tag "Function to execute")) + (choice (const :tag "No restriction" nil) + (integer :tag "Max total arguments") + (cons :tag "Max optional and required" + (integer :tag "Max optional arguments") + (integer :tag "Max required arguments"))))) + (repeat :tag "Macros" (string)))) :package-version '(auctex . "14.0.8")) (defvar-local TeX-fold-macro-spec-list-internal nil @@ -437,9 +454,13 @@ for macros and `math' for math macros." (string (char-after (match-end 0))))))) (let* ((item-start (match-beginning 0)) - (display-string-spec (cadr (assoc item-name - fold-list))) - (item-end (TeX-fold-item-end item-start type)) + (spec-maybe-sig (cadr (assoc item-name fold-list))) + (display-string-spec (if (consp spec-maybe-sig) + (car spec-maybe-sig) + spec-maybe-sig)) + (sig (when (consp spec-maybe-sig) + (cdr spec-maybe-sig))) + (item-end (TeX-fold-item-end item-start type sig)) (ov (TeX-fold-make-overlay item-start item-end type display-string-spec))) (TeX-fold-hide-item ov)))))))))) @@ -536,7 +557,7 @@ Return non-nil if an item was found and folded, nil otherwise." TeX-fold-math-spec-list-internal) (t TeX-fold-macro-spec-list-internal))) fold-item - (display-string-spec + (spec-maybe-sig (or (catch 'found (while fold-list (setq fold-item (car fold-list)) @@ -549,7 +570,12 @@ Return non-nil if an item was found and folded, nil otherwise." (if (eq type 'env) TeX-fold-unspec-env-display-string TeX-fold-unspec-macro-display-string)))) - (item-end (TeX-fold-item-end item-start type)) + (display-string-spec (if (consp spec-maybe-sig) + (car spec-maybe-sig) + spec-maybe-sig)) + (sig (when (consp spec-maybe-sig) + (cdr spec-maybe-sig))) + (item-end (TeX-fold-item-end item-start type sig)) (ov (TeX-fold-make-overlay item-start item-end type display-string-spec))) (TeX-fold-hide-item ov)))))) @@ -882,10 +908,12 @@ display property." (overlay-put ov 'display display-string)) ov)) -(defun TeX-fold-item-end (start type) +(defun TeX-fold-item-end (start type &optional signature) "Return the end of an item of type TYPE starting at START. TYPE can be either `env' for environments, `macro' for macros or -`math' for math macros." +`math' for math macros. +Optional SIGNATURE, as in `TeX-find-macro-end', restricts the number of +allowed arguments of LaTeX macros." (save-excursion (cond ((and (eq type 'env) (eq major-mode 'ConTeXt-mode)) @@ -901,15 +929,9 @@ TYPE can be either `env' for environments, `macro' for macros or (goto-char (1+ start)) (LaTeX-find-matching-end) (point)) - ((eq type 'math) - (goto-char (1+ start)) - (if (zerop (skip-chars-forward "A-Za-z@")) - (forward-char) - (skip-chars-forward "*")) - (point)) (t (goto-char start) - (TeX-find-macro-end))))) + (TeX-find-macro-end signature))))) (defun TeX-fold-overfull-p (ov-start ov-end display-string) "Return t if an overfull line will result after adding an overlay. diff --git a/tex.el b/tex.el index 6f8267ac..74572d4e 100644 --- a/tex.el +++ b/tex.el @@ -5790,11 +5790,16 @@ If LIMIT is non-nil, do not search further up than this position in the buffer." (TeX-find-balanced-brace -1 depth limit)) -(defun TeX-find-macro-boundaries (&optional lower-bound) +(defun TeX-find-macro-boundaries (&optional lower-bound signature) "Return a cons containing the start and end of a macro. If LOWER-BOUND is given, do not search backward further than this point in buffer. Arguments enclosed in brackets or braces are -considered part of the macro." +considered part of the macro. + +If SIGNATURE is given, restrict the total number of arguments. If +SIGNATURE is an integer N, allow at most N total arguments. If +SIGNATURE is a cons cell (P . Q), allow at most P optional and Q +required arguments." ;; FIXME: Pay attention to `texmathp-allow-detached-args' and ;; `reftex-allow-detached-macro-args'. ;; Should we handle cases like \"{o} and \\[3mm] (that is, a macro @@ -5839,16 +5844,17 @@ considered part of the macro." ;; Search forward for the end of the macro. (when start-point (save-excursion - (goto-char (TeX-find-macro-end-helper start-point)) + (goto-char (TeX-find-macro-end-helper start-point signature)) (if (< orig-point (point)) (cons start-point (point)) nil)))))) -(defun TeX-find-macro-end-helper (start) +(defun TeX-find-macro-end-helper (start &optional signature) "Find the end of a macro given its START. START is the position just before the starting token of the macro. If the macro is followed by square brackets or curly braces, -those will be considered part of it." +those will be considered part of it. SIGNATURE, as in +`TeX-find-macro-boundaries', restricts how many arguments are allowed." (save-excursion (save-match-data (catch 'found @@ -5856,43 +5862,56 @@ those will be considered part of it." (if (zerop (skip-chars-forward "A-Za-z@")) (forward-char) (skip-chars-forward "*")) - (while (not (eobp)) - (cond - ;; Skip over pairs of square brackets - ((or (looking-at "[ \t]*\n?[ \t]*\\(\\[\\)") ; Be conservative: Consider + (let* ((max-tot (and (integerp signature) signature)) + (max-opt (and (consp signature) (car signature))) + (max-req (and (consp signature) (cdr signature))) + (num-opt 0) + (num-req 0)) + (while (not (eobp)) + (cond + ;; Skip over pairs of square brackets + ((or (looking-at "[ \t]*\n?[ \t]*\\(\\[\\)") ; Be conservative: Consider ; only consecutive lines. - (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp)) - (save-excursion - (forward-line 1) - (looking-at "[ \t]*\\(\\[\\)")))) - (goto-char (match-beginning 1)) - ;; Imitate `font-latex-find-matching-close', motivated by - ;; examples like \begin{enumerate}[a{]}]. - (let ((syntax (TeX-search-syntax-table ?\[ ?\])) - (parse-sexp-ignore-comments - (not (derived-mode-p 'docTeX-mode)))) - (modify-syntax-entry ?\{ "|" syntax) - (modify-syntax-entry ?\} "|" syntax) - (modify-syntax-entry ?\\ "/" syntax) - (condition-case nil - (with-syntax-table syntax - (forward-sexp)) - (scan-error (throw 'found (point)))))) - ;; Skip over pairs of curly braces - ((or (looking-at "[ \t]*\n?[ \t]*{") ; Be conservative: Consider + (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp)) + (save-excursion + (forward-line 1) + (looking-at "[ \t]*\\(\\[\\)")))) + (if (or (and max-tot (>= (+ num-opt num-req) max-tot)) + (and max-opt (>= num-opt max-opt))) + (throw 'found (point))) + (cl-incf num-opt) + (goto-char (match-beginning 1)) + ;; Imitate `font-latex-find-matching-close', motivated by + ;; examples like \begin{enumerate}[a{]}]. + (let ((syntax (TeX-search-syntax-table ?\[ ?\])) + (parse-sexp-ignore-comments + (not (derived-mode-p 'docTeX-mode)))) + (modify-syntax-entry ?\{ "|" syntax) + (modify-syntax-entry ?\} "|" syntax) + (modify-syntax-entry ?\\ "/" syntax) + (condition-case nil + (with-syntax-table syntax + (forward-sexp)) + (scan-error (throw 'found (point)))))) + ;; Skip over pairs of curly braces + ((or (looking-at "[ \t]*\n?[ \t]*{") ; Be conservative: Consider ; only consecutive lines. - (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp)) - (save-excursion - (forward-line 1) - (looking-at "[ \t]*{")))) - (goto-char (match-end 0)) - (goto-char (or (TeX-find-closing-brace) - ;; If we cannot find a regular end, use the - ;; next whitespace. - (save-excursion (skip-chars-forward "^ \t\n") - (point))))) - (t - (throw 'found (point))))) + (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp)) + (save-excursion + (forward-line 1) + (looking-at "[ \t]*{")))) + (if (or (and max-tot (>= (+ num-opt num-req) max-tot)) + (and max-req (>= num-req max-req))) + (throw 'found (match-beginning 0))) + (cl-incf num-req) + (goto-char (match-end 0)) + (goto-char (or (TeX-find-closing-brace) + ;; If we cannot find a regular end, use the + ;; next whitespace. + (save-excursion (skip-chars-forward "^ \t\n") + (point))))) + (t + (throw 'found (point)))))) ;; Make sure that this function does not return nil, even ;; when the above `while' loop is totally skipped. (bug#35638) (throw 'found (point)))))) @@ -5904,11 +5923,12 @@ in buffer. Arguments enclosed in brackets or braces are considered part of the macro." (car (TeX-find-macro-boundaries limit))) -(defun TeX-find-macro-end () +(defun TeX-find-macro-end (&optional signature) "Return the end of a macro. -Arguments enclosed in brackets or braces are considered part of -the macro." - (cdr (TeX-find-macro-boundaries))) +Arguments enclosed in brackets or braces are considered part of the +macro. SIGNATURE, as in `TeX-find-macro-boundaries', restricts how many +arguments are allowed." + (cdr (TeX-find-macro-boundaries nil signature))) (defun TeX-search-forward-unescaped (string &optional bound noerror) "Search forward from point for unescaped STRING. -- 2.39.3 (Apple Git-145) --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 21 05:55:15 2025 Received: (at 78693) by debbugs.gnu.org; 21 Jun 2025 09:55:15 +0000 Received: from localhost ([127.0.0.1]:33879 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uSuwL-0002tu-CU for submit@debbugs.gnu.org; Sat, 21 Jun 2025 05:55:14 -0400 Received: from mout-p-101.mailbox.org ([2001:67c:2050:0:465::101]:46838) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uSuwI-0002sB-6z for 78693@debbugs.gnu.org; Sat, 21 Jun 2025 05:55:11 -0400 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4bPV7m2V5Vz9ssx; Sat, 21 Jun 2025 11:55:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1750499700; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=aZNPrPKCYH+EwKuskiO/sSZNzsJ0MCQp3o2GAioJSBw=; b=tcpabgjr6WOkYB1CszPqONvOzzCONAJUNFU67tR5YOsGxI/Rpf/zqBp55NbZwixbB5MSf/ btg5CINTCxm11qYcuODEDY36bkC9VDIkMc6vw0RmubjICz6ELfk2kqL9+wu32eEbIcda2+ s8QetX6UQoqqnDyQCM6IUepJw6jZD6ydrE/0QiiZAiXG+i+QDRNC38MyvmDbtrST6odh+H 1rA9cy8jZd69ZdnU5GOrDhii9JwCIxxaAh8HKZntAhvJ4EFlZhvZpVL5iZx2yYjvGJqTHr XQMxuyQMQyIdObwLP9EXiKXADSjRxoXXoVf4r0BYDHnuIOW9WXyNkRcfOu1V4w== From: Rahguzar To: "Paul D. Nelson" Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: (Paul D. Nelson's message of "Sun, 15 Jun 2025 12:29:24 +0200") References: Date: Sat, 21 Jun 2025 14:54:55 +0500 Message-ID: <87frftbes0.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: text/plain X-MBO-RS-META: zhn4g3mnk9kuf83x69m7f39t5ch1hyh6 X-MBO-RS-ID: 17055c7ac952376535a X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Hi Paul, "Paul D. Nelson" writes: > Hi Raghuzar and all, > > Please see the attached patch which implements signature support for > macro folds, following the plan outlined in my earlier email. This > should address both the issue in your report and that in my earlier bug. > We also need to update the manual, but I'll do that later once the > general shape of the proposal is agreed upon. If you get the chance, > please let me know what you think. I have tested the patch and resolve the original issue. I haven't tested the new functionality using the SPEC. One question about it: One problem I have had is that, if I have something like \begin{align} [\hat{X},\hat{P}] = i\hbar \end{align} the commutator gets folded as an optional argument to the \begin. It is possible to not have this effect with new machinery without specifying \begin as not taking any optional arguments? I have only seen optional arguments before mandatory ones but I don't know if that can be relied upon in general. > Thanks, best, > > Paul Best, Rahguzar > [2. text/x-patch; 0001-Add-signature-support-for-macro-folding.patch]... From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 21 06:07:11 2025 Received: (at 78693) by debbugs.gnu.org; 21 Jun 2025 10:07:12 +0000 Received: from localhost ([127.0.0.1]:33911 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uSv7s-0004nU-Lp for submit@debbugs.gnu.org; Sat, 21 Jun 2025 06:07:11 -0400 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]:56614) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uSv7m-0004lL-PI for 78693@debbugs.gnu.org; Sat, 21 Jun 2025 06:07:05 -0400 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-54b09cb06b0so2893513e87.1 for <78693@debbugs.gnu.org>; Sat, 21 Jun 2025 03:07:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750500416; x=1751105216; darn=debbugs.gnu.org; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=LTt3Vq3ypq+cMQJJArm4WB83tKCZBxmkQyuoNH8yzSw=; b=bMl5+Rk/ZCVcVpEWEQnhx5zC+/G3eEfzuW6uIUP/3NugejYVHj2uSMXN2etEGGUx2O ap3nKAa3JmdwL5LnjvXplzX4uFIgxGzWDVUZk3hpaKkamW2dzuWTr5yMO9H59WYHVMeZ M2szfIzfRZrwxk50Ur6BASDp763y3Ms/UD3tAScTVxmY1uWtkiJ39W1u3OuYg80c3uF8 weM2cHJ/VeaCFabRKuDwewq++1AXFKYe/jmYL7A0ith8S621zrv0oLD0p4LLuEeyv2MO F8bNl0IL/6+b0zxDPH66sfW8SOVeCkumK0wb18/MapAO21jPZOT5fFFUXikcSifVg75N 7Dnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750500416; x=1751105216; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LTt3Vq3ypq+cMQJJArm4WB83tKCZBxmkQyuoNH8yzSw=; b=HGe1ifM4m82XuRrcM5q+F6vqZ/JxKp9KhKGyWwo1+xu7e2KZztW4spZEOdGDsNZd6V Nsa30N7YQn27XvKkIK4q1orlUmCEDIteIr9LxPwHF/U2hSe3GVJKm3OklhKACQdmMX7X bip3KnnSlFUmAVktoo6AF09tqHzgXDXJ6pxmCyYtun+g0ETFG4XyoaYvFyjqi0QDCDl1 5pnwIOWucPTwpvmkgB2UapTkuK1vk3JdRecF2o5X0Bu8OMgG4O2LZxNpo46WQighRu/P SeHyeBJOpMUKPeMF4F8U1owPDuDvutNFJjPWZTPAsi1IHpOb+f0YNUhE576VqMazpzQx OnHQ== X-Gm-Message-State: AOJu0YyCnMoru+wg6ZLnwKlap7waRY1qDCPgUySfU38jMW5AkNGkvFOr STj8GRCnGlYus3lXDkO4h+mZbwXfPX2sMoDap1OyI1Eka3597ox7/tFR X-Gm-Gg: ASbGncuY6p4ATCK9dz+TJYGKGR/z47Uf2zqt3rG+Isd3o9FinDa/qk35ELuYhbCMXNF loPRJvtzhklo8KFltuUTpBiodCi2jVr/Adm3Uy3ercmzE9GYkDQ+FtaArLI/UVtiANJqpKWnmCQ 1Aw2pvpIguTAbLwtBtOqXQv/pgL1E3tR3wqQcBbIP5sfi2llp7yflbjwEFPBXNfpsChoLLi1faJ E9j4wLtNNo85yujU0bEiILsoK08zTKZAUVX+71+NIZzuEUpxUy0Kawmt90w6DkbbdsTBOP2025v Eu2zp8uEEAMiPSB/zmkg9HA+hr3BEg3UuUrQoRlBzUZbYZBYVPOnurzEmMqn10EgoiAh X-Google-Smtp-Source: AGHT+IG20mNiYiG6LgwBKdirHN2gwhaiduFEgxY5kjOar0x9V9I4Y2TuvTxpG7/UwlLnG3KFGBCdog== X-Received: by 2002:a05:6512:b97:b0:553:3422:c39d with SMTP id 2adb3069b0e04-553e3bf3ab0mr2115683e87.37.1750500415728; Sat, 21 Jun 2025 03:06:55 -0700 (PDT) Received: from localhost ([185.229.154.192]) by smtp.gmail.com with UTF8SMTPSA id 2adb3069b0e04-553e41bbc9bsm612145e87.117.2025.06.21.03.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Jun 2025 03:06:55 -0700 (PDT) From: "Paul D. Nelson" To: Rahguzar Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: <87frftbes0.fsf@mailbox.org> (message from Rahguzar on Sat, 21 Jun 2025 14:54:55 +0500) Date: Sat, 21 Jun 2025 12:06:54 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi Raghuzar, > I have tested the patch and resolve the original issue. I haven't tested > the new functionality using the SPEC. Thanks. > One question about it: One problem I have had is that, if I have > something like > > \begin{align} > [\hat{X},\hat{P}] = i\hbar > \end{align} > > the commutator gets folded as an optional argument to the \begin. > It is possible to not have this effect with new machinery without > specifying \begin as not taking any optional arguments? Could you please share your tex folding config, or better, the part relevant for folding \begin{align}? > I have only seen optional arguments before mandatory ones but I don't > know if that can be relied upon in general. What about "\begin{theorem}[My Favorite Theorem]"? Paul From debbugs-submit-bounces@debbugs.gnu.org Sun Jun 22 03:15:03 2025 Received: (at 78693) by debbugs.gnu.org; 22 Jun 2025 07:15:03 +0000 Received: from localhost ([127.0.0.1]:46333 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uTEus-0006h8-N5 for submit@debbugs.gnu.org; Sun, 22 Jun 2025 03:15:03 -0400 Received: from mout-p-201.mailbox.org ([2001:67c:2050:0:465::201]:58798) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uTEuo-0006gC-Rh for 78693@debbugs.gnu.org; Sun, 22 Jun 2025 03:15:00 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4bQ2XQ5tv3z9tHX; Sun, 22 Jun 2025 09:14:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1750576486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=g4QBZZPVn7PLsdRBePkbV3/GsrR8Bfv1O0qQOEmBXg0=; b=m3mgQ0oYQccHooyS7jIxejLpFEoER5h95QVsju0CeDN8Q6vxn6VFxk8JgjpgZYF9xKq6lV QOjZFiL6zI4SpvaBB++q3fZkTfww6psJbNcQxkVr4meAlmjq/yNxGQpklDgfrhiRtj7im7 0AQlMIaE4X/pp7aSRy7LRwJnibXx2u1HumDACBFj19aUmHbGlb6uDwwftrmpnkpLgbaFHb mC9KL6DF/SoTZ+P3zsSfoYio0LqPB61lBIxNJ93rcCCgcHqehWorJPnxY3Bl6uv72i/vmx zU9/TlfkcCjtw4SCHd2CBcpAuqzXfUyZEtD5Htw8JIdfrG1lRS8KTdmHVFlEAA== From: Rahguzar To: "Paul D. Nelson" Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: (Paul D. Nelson's message of "Sat, 21 Jun 2025 12:06:54 +0200") References: Date: Sun, 22 Jun 2025 12:14:43 +0500 Message-ID: <87y0tk9rj0.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-MBO-RS-META: ab7d88jmrab6c491do3myt3ii4n3eu47 X-MBO-RS-ID: 27f9e84c2f98c0931de X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Paul, "Paul D. Nelson" writes: > Hi Raghuzar, > >> I have tested the patch and resolve the original issue. I haven't tested >> the new functionality using the SPEC. > > Thanks. > >> One question about it: One problem I have had is that, if I have >> something like >> >> \begin{align} >> [\hat{X},\hat{P}] =3D i\hbar >> \end{align} >> >> the commutator gets folded as an optional argument to the \begin. >> It is possible to not have this effect with new machinery without >> specifying \begin as not taking any optional arguments? > > Could you please share your tex folding config, or better, the part > relevant for folding \begin{align}? It is this: (setq TeX-fold-macro-spec-list `(("=E2=AC=96 {1}" ("begin")) ("=E2=AC=97 {1}" ("end")))) and I have included a test.tex file which you can use to see the effect. >> I have only seen optional arguments before mandatory ones but I don't >> know if that can be relied upon in general. > > What about "\begin{theorem}[My Favorite Theorem]"? > > Paul In my corner (theoretical physics) we don't do much theorem proving :) I have used environments for theorems but very rarely. I expected optional arguments after mandatory ones to be possible. For the example you give my folding would be very annoying. Rahguzar --=-=-= Content-Type: application/x-tex Content-Disposition: attachment; filename=test.tex Content-Transfer-Encoding: base64 XGRvY3VtZW50Y2xhc3N7YXJ0aWNsZX0KClxiZWdpbntkb2N1bWVudH0KICBcYmVnaW57YWxpZ259 CiAgICBbXGhhdHtYfSxcaGF0e1B9XSA9IGlcaGJhcgogIFxlbmR7YWxpZ259ClxlbmR7ZG9jdW1l bnR9Cg== --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sun Jun 22 03:40:09 2025 Received: (at 78693) by debbugs.gnu.org; 22 Jun 2025 07:40:10 +0000 Received: from localhost ([127.0.0.1]:46423 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uTFJB-00080B-DR for submit@debbugs.gnu.org; Sun, 22 Jun 2025 03:40:09 -0400 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]:50523) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uTFJ7-0007vm-7o for 78693@debbugs.gnu.org; Sun, 22 Jun 2025 03:40:06 -0400 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-553b16a0e38so3355648e87.1 for <78693@debbugs.gnu.org>; Sun, 22 Jun 2025 00:40:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750577998; x=1751182798; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=kdLJ5A+j0xdNeORxDPK6jNGxS5wJWSFON8b5UJ6Lyoo=; b=lFKdfI/frR9R3nwS3xEYk3xMznqgB6jVTeZ7Bgor/xqwaVzGQh4VFXaYdGbJw47Dbx b7Tnr2SzSipfKw+IoeCB/mSSj1QZeXQ8nIa/DJQsQOutRsyy8ktjGINOrBNwnWx7RIAR kuXea+J2dqhjQjOtlwtGxVrEr/VLBGyMigEm2BOyyKKTTuraHNh9MKUPYZw7XllKm1d7 CCQeumfQl7Wqwaf+wjcjzZ/z7t38cZmiFoJT/kbAGSe0KWeL+14FB3kLC/XU7SuYHgUm +tDqo0u8z4Os7uuhCuWLnEzYSgOHu9EXjaVFysFhlFb7WthqcEu1naW100ZPyaH8Zymu ACtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750577998; x=1751182798; h=content-transfer-encoding:mime-version:message-id:date:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=kdLJ5A+j0xdNeORxDPK6jNGxS5wJWSFON8b5UJ6Lyoo=; b=lPblWBczj5rwyNLtCiiW8zR+i+QuxPbZ7dE57oB9oHWAtJVDqYeOiAkaoE927484m8 ZZ2htJajUepRSjhTk71jBkruQ+g73xqAQO/kxI4iDMIg4O7Xx3ehRG3fc2mUJ58qqedj LL46c8i3YYpQzWBJ8kmLNCYxQfwZIb/vVX58zOVXBlGlGVme7l6aOXpni+o+X0kdgdFV rrzHwZ81ERWl4kgquAdUPwYzFmWzzqTKXblS64y1DHaM2m2vofSqjIt5qbKQ+70/rL3y +HJXUNdga6prM65x7HPp0uQOF/7/4anvTn9tdpJVSZ6sCuXubC3xPIV8iaQ4CQ13Esc/ eb6g== X-Gm-Message-State: AOJu0Yz8+aOxI0PaFQEBFjUDvm1Bi4L4aqIrgJP4qR6e0mzif9Lo866F dBuDULR47rhdp9jksHScP1LwbPEaNTJop04e8AZza1jF2BGsYJJqtsvW X-Gm-Gg: ASbGnctVXZz2so6UkX1197Rgkl8d3tlQ68ReFpEhhW8UE8KmjStf7A2WhCOLRVsLVux 39co/vfIR0xU7Pld5t33VD3V0Ouhjy6KRomBmq4m9TIYqXCf2qcstI4+4VUrDlm+jqgzQ8P5mEl FtKAjrQOfVJl68+2TM05XPpRSUrtGcfu8ofhg4Ml/QTSwv2jwSUyJm10bdCSqc0qzx+lOzCOEKA yaO6lEMEj7EZXYzlzfXE/MZH0CzXZlTwRJHXrJ+A1UL8wsXk8Whfgq/F9G6xOaXc/UvXeLs+eO6 2Jo1QcwLAn1IjhMRok9uCNqpL6oi6z9HCBhnNblPyYKXDxjDegsJw7yKBy1dU8A0TItC X-Google-Smtp-Source: AGHT+IEvZS6aApx5mmrbscStlRdiGTVx/C2DQgzeRnD9/E/LWJvI4oonAqvqLqrLAiQipJ/6kTXJKg== X-Received: by 2002:a05:6512:3b9d:b0:553:390a:e1e3 with SMTP id 2adb3069b0e04-553e3d0c648mr2481045e87.44.1750577997225; Sun, 22 Jun 2025 00:39:57 -0700 (PDT) Received: from localhost ([185.229.154.192]) by smtp.gmail.com with UTF8SMTPSA id 2adb3069b0e04-553e414cac8sm915818e87.71.2025.06.22.00.39.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 00:39:56 -0700 (PDT) From: "Paul D. Nelson" To: Rahguzar Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: <87y0tk9rj0.fsf@mailbox.org> (message from Rahguzar on Sun, 22 Jun 2025 12:14:43 +0500) Date: Sun, 22 Jun 2025 09:39:54 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi Raghuzar, Rahguzar writes: >>> One question about it: One problem I have had is that, if I have >>> something like >>> >>> \begin{align} >>> [\hat{X},\hat{P}] =3D i\hbar >>> \end{align} >>> >>> the commutator gets folded as an optional argument to the \begin. >>> It is possible to not have this effect with new machinery without >>> specifying \begin as not taking any optional arguments? >> >> Could you please share your tex folding config, or better, the part >> relevant for folding \begin{align}? > > It is this: > > (setq TeX-fold-macro-spec-list > `(("=E2=AC=96 {1}" ("begin")) > ("=E2=AC=97 {1}" ("end")))) With the new folding signature support, you can achieve the desired effect using either ;; At most 1 args. (setq TeX-fold-macro-spec-list `((("=E2=AC=96 {1}" . 1) ("begin")) (("=E2=AC=97 {1}" . 1) ("end")))) or ;; At most 0 optional, 1 required args. (setq TeX-fold-macro-spec-list `((("=E2=AC=96 {1}" . (0 . 1)) ("begin"))=20 (("=E2=AC=97 {1}" . (0 . 1)) ("end")))) --- Another approach here would be prettification, assuming you're OK with specifying each environment. I use something like: (with-eval-after-load 'tex-mode (mapc (lambda (sym) (add-to-list 'tex--prettify-symbols-alist sym)) '(("\\begin{equation}" . ?=E2=86=B4) ("\\end{equation}" . ?=E2=86=B2) ("\\begin{align}" . ?=E2=8C=88) ("\\end{align}" . ?=E2=8C=8B) ("\\begin{multline}" . ?=E2=8E=A7) ("\\end{multline}" . ?=E2=8E=AD)))) Paul From debbugs-submit-bounces@debbugs.gnu.org Sun Jun 22 06:37:23 2025 Received: (at 78693) by debbugs.gnu.org; 22 Jun 2025 10:37:23 +0000 Received: from localhost ([127.0.0.1]:46673 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uTI4g-0007Vq-L8 for submit@debbugs.gnu.org; Sun, 22 Jun 2025 06:37:23 -0400 Received: from mout-p-103.mailbox.org ([80.241.56.161]:48832) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uTI4d-0007VZ-JX for 78693@debbugs.gnu.org; Sun, 22 Jun 2025 06:37:20 -0400 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4bQ71x5L7Sz9sZK; Sun, 22 Jun 2025 12:37:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1750588629; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gjUGtea4K+7UeF76mOF4fXH7upQhuKfX957jcAjDUnU=; b=eQmybHXkKa50qlM5YduKoPp4fl/gKXX8KjYziik72KNaFG2+QP4wVNP2PIYEVravtFGLaS KwIIfjalFtCjFH27tGcDrP2hRNAfl4tPNGgOMyzsnn6efWly32k1s8HcL8eMe3RVyiYNL2 qILevyiPU0Z93nzeyAVnhXn78xVvRm29kBtbpKs5yjtVUpjU8Kn/3n/uEUNZM0lyGCW0ou yJVZ1bHLmnEUfKczwllI1RQ6aHgdQozyLhb/Yl6xWKJCni3U9fzJna60afDVx9EdyUeqQi Mh/qBslwPjamCN3FrjvHhZDYJQgYsg775xilOwDDh+Cddrff6F9jk0Ghol/s1w== From: Rahguzar To: "Paul D. Nelson" Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: (Paul D. Nelson's message of "Sun, 22 Jun 2025 09:39:54 +0200") References: Date: Sun, 22 Jun 2025 15:37:06 +0500 Message-ID: <87msa09i5p.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-MBO-RS-META: gi3qxsy8zpsnjy49gdghdgez8fm4ubja X-MBO-RS-ID: da5993ed5b0808f0847 X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Hi Paul, "Paul D. Nelson" writes: > Hi Raghuzar, > > Rahguzar writes: > >>>> One question about it: One problem I have had is that, if I have >>>> something like >>>> >>>> \begin{align} >>>> [\hat{X},\hat{P}] =3D i\hbar >>>> \end{align} >>>> >>>> the commutator gets folded as an optional argument to the \begin. >>>> It is possible to not have this effect with new machinery without >>>> specifying \begin as not taking any optional arguments? >>> >>> Could you please share your tex folding config, or better, the part >>> relevant for folding \begin{align}? >> >> It is this: >> >> (setq TeX-fold-macro-spec-list >> `(("=E2=AC=96 {1}" ("begin")) >> ("=E2=AC=97 {1}" ("end")))) > > With the new folding signature support, you can achieve the desired > effect using either > > ;; At most 1 args. > (setq TeX-fold-macro-spec-list > `((("=E2=AC=96 {1}" . 1) ("begin")) > (("=E2=AC=97 {1}" . 1) ("end")))) > > or > > ;; At most 0 optional, 1 required args. > (setq TeX-fold-macro-spec-list > `((("=E2=AC=96 {1}" . (0 . 1)) ("begin"))=20 > (("=E2=AC=97 {1}" . (0 . 1)) ("end")))) > > --- Thanks, this works for my needs. I was worried about optional arguments before the mandatory ones messing up the folding but those arguments actually get swallowed by the folding. With your suggestion of using TeX-fold-macro-nth-arg it is possible to handle optional args that come before mandatory ones which passing a 1 or (0 . 1) as spec. A bit confusing but it improves on the current situation and I don't think it is possible handle folding perfectly given how "flexible" syntax in (La)TeX is. > Another approach here would be prettification, assuming you're OK with > specifying each environment. I use something like: > > (with-eval-after-load 'tex-mode > (mapc > (lambda (sym) (add-to-list 'tex--prettify-symbols-alist sym)) > '(("\\begin{equation}" . ?=E2=86=B4) > ("\\end{equation}" . ?=E2=86=B2) > ("\\begin{align}" . ?=E2=8C=88) > ("\\end{align}" . ?=E2=8C=8B) > ("\\begin{multline}" . ?=E2=8E=A7) > ("\\end{multline}" . ?=E2=8E=AD)))) > > Paul Rahguzar From debbugs-submit-bounces@debbugs.gnu.org Sun Jun 22 16:42:14 2025 Received: (at 78693) by debbugs.gnu.org; 22 Jun 2025 20:42:14 +0000 Received: from localhost ([127.0.0.1]:49890 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uTRW1-0007eU-IT for submit@debbugs.gnu.org; Sun, 22 Jun 2025 16:42:14 -0400 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]:48535) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uTRVz-0007d0-At for 78693@debbugs.gnu.org; Sun, 22 Jun 2025 16:42:12 -0400 Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-32b910593edso26624191fa.1 for <78693@debbugs.gnu.org>; Sun, 22 Jun 2025 13:42:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750624925; x=1751229725; darn=debbugs.gnu.org; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=cXiOd+zdj5/xKTrTQi8ctsejNyXuWKzycH9F6ifWvX8=; b=Nd1X7Eh4OusrJyUVg8jgJW8tUpwTGH3WCCvAcK+1NTsJ/RCj9NrAuyMMOmkSzZIs46 /7l4fh01Lvw6G17/vuBbvXnXerEQEhppR80uGYNzKms8RerszKRdqXTZr++uIHiSM1I3 PmaLUH50OLl9AsGRKXCt0gIz/exlNlXWAfTPKRLyc4GkNvRxiSbKgHvEw64imYwEPFEo 80fpZp7bGUGyJI2xmmkItTJjAWY0dvZv3R11GCEOnxb9rJSOc2hQFghDAlOT3CjPN6h7 0bYmOte+o4IXj89w4I8Rky0Jama5bhyOpqThU5fj5OAzUMeCZF4012rs/YrfBG/yBWW2 VLBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750624925; x=1751229725; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cXiOd+zdj5/xKTrTQi8ctsejNyXuWKzycH9F6ifWvX8=; b=mvCQWDRNbBwsiJYK6X7EdEcPxtwsfUiF2uPHswhOxYD82M4vwR3n/9RnmR8fkZXZl6 5AgGgT1aM/klB7VThZ0PpPNTugH9VERmnB9OgI6eS6kxFSyVD9c9HEScSfas96Wv4T/9 dixObXQ944RUKuKDoq/EuaAU+4Ya5jvjYmoNouqmQWZZdEuHnraGU+U4ayRFGi8gyLnU /b/sO/WGPzpEfA2pPZ2OI4qm2rbBGkDaqzWRyl3EOp5QjBKJGg6J2ChDDAIWTIoewO6v SrXWs9wdHdgqPO8aR+6QkUenM+gJ9GYMlI+Ix3fag6GPQEmq72Bza1V1l/o3XXxk4+ep hthg== X-Gm-Message-State: AOJu0Yxz8Ds2VA70t4OOA2kgIlx+HNGmxx5rzjgk0YoupoPewBkjXSYU HxQcwdlpTGKwP9Gzy5Ut1/FM0ze9G8M2A6bS9jrVoghSoErFWWnWEhJJ X-Gm-Gg: ASbGncu0Gs8pm6KY/zMhhhIZ06cQ8JsqYl5MTspfWG/GZxfMEbT7zgtYL6NzuOt23mY D/T/BMrMo57bdQ0i4lGtW3W04YHYGrRzkQyZ0hZWpRpPgRfqW9UQDgDbbVQramryRILs15bIVrH NcD8P71dcuXxddYAV3/TV1HabGPM7uEaiGKRQcSrzMtBLFrmFiXGEGSnr9Mfa6KhL81a8nZjy6v u5stO1TkxXjNCqqPGXApF9gZOGrP2hwaANf/WDW7cQ0fIKZKkmrmhTQRFIdxKeUJJM7YzNLDXe5 yJcY9Z+QBI6s+OQnbOVo21mHPFPROWp7DEYEAMFrK6FWbOvpCQppjwZy717shw9zZWL0pWuAEAi /E+0= X-Google-Smtp-Source: AGHT+IH+kJgKRDvGesTYS1RWTmVYu59eKWvlPE+iVQ2Pp05UymRQkoart1gKWjP/o3Yy7UU9DCLXrA== X-Received: by 2002:a05:6512:b12:b0:553:abd6:cd3 with SMTP id 2adb3069b0e04-553e3b9a75emr2952271e87.6.1750624924432; Sun, 22 Jun 2025 13:42:04 -0700 (PDT) Received: from localhost ([185.229.154.192]) by smtp.gmail.com with UTF8SMTPSA id 2adb3069b0e04-553e41c4235sm1131000e87.185.2025.06.22.13.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 13:42:03 -0700 (PDT) From: "Paul D. Nelson" To: Rahguzar Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: <87msa09i5p.fsf@mailbox.org> (message from Rahguzar on Sun, 22 Jun 2025 15:37:06 +0500) Date: Sun, 22 Jun 2025 22:42:01 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi Rahguzar > Thanks, this works for my needs. I was worried about optional arguments > before the mandatory ones messing up the folding but those arguments > actually get swallowed by the folding. With your suggestion of using > TeX-fold-macro-nth-arg it is possible to handle optional args that come > before mandatory ones which passing a 1 or (0 . 1) as spec. A bit > confusing but it improves on the current situation and I don't think it > is possible handle folding perfectly given how "flexible" syntax in > (La)TeX is. I'm glad it seems to be working for your needs, although I'm a bit confused about what else you might be asking for here, i.e., what would "perfect" folding like? Paul From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 23 03:16:07 2025 Received: (at 78693) by debbugs.gnu.org; 23 Jun 2025 07:16:07 +0000 Received: from localhost ([127.0.0.1]:53128 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uTbPS-00014K-Sf for submit@debbugs.gnu.org; Mon, 23 Jun 2025 03:16:07 -0400 Received: from mout-p-202.mailbox.org ([2001:67c:2050:0:465::202]:58684) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uTbPO-00013J-1d for 78693@debbugs.gnu.org; Mon, 23 Jun 2025 03:16:04 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4bQfWB02Bgz9tFm; Mon, 23 Jun 2025 09:15:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1750662950; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=cmUn3ieH7Wr/UO3jUQa/EsFc+D5RkyVbcu54kTErMHg=; b=qxXGlnCdzTXgdAiTDGX/qadzudSdK149Chr9eTmtjz7tnlyuZhiawZtU0+NSeXqvbRqSCy DZ7/rOau18voCUfKRaTY1byQ1absFRK5J+JqW8ijpa7jtfyTipHGJ5rVJnQBlrEh72JLjt GC6LkyV4ESzwnSb3JV24p7Uoo0WYUeCQERjL+T1mpX4NnsmvJIGgdZFJ+tYefZI+nPUMw1 yQPF5KJVQeQ75bH6hv4Drc7fuAxdJm/9+vd+7ZLryC6xNTXncG1Babv9osy4hLPtlmBDkF gcbOuDXQu543VjRDF4STTvMgcDW6R2d3Y+c1MhIrPcUDdQPLs21UTMM2CVQicQ== From: Rahguzar To: "Paul D. Nelson" Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: (Paul D. Nelson's message of "Sun, 22 Jun 2025 22:42:01 +0200") References: Date: Mon, 23 Jun 2025 12:15:45 +0500 Message-ID: <87h6079bdq.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: text/plain X-MBO-RS-META: pjjdrf7nk15moaxnrry9o71wrkaz7oyn X-MBO-RS-ID: 666102b07d174c05099 X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Hi Paul, "Paul D. Nelson" writes: > Hi Rahguzar > >> Thanks, this works for my needs. I was worried about optional arguments >> before the mandatory ones messing up the folding but those arguments >> actually get swallowed by the folding. With your suggestion of using >> TeX-fold-macro-nth-arg it is possible to handle optional args that come >> before mandatory ones which passing a 1 or (0 . 1) as spec. A bit >> confusing but it improves on the current situation and I don't think it >> is possible handle folding perfectly given how "flexible" syntax in >> (La)TeX is. > > I'm glad it seems to be working for your needs, although I'm a bit > confused about what else you might be asking for here, i.e., what would > "perfect" folding like? Something that is able to distinguish between \begin{theorem}[My favorite theorem] and \begin{equation} [X,P] but I really don't think that is possible except by re-implementing a LaTeX compiler. The current situation is lot better (at least for me) due to your effort. Thanks! Rahguzar > Paul From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 23 15:36:57 2025 Received: (at 78693) by debbugs.gnu.org; 23 Jun 2025 19:36:57 +0000 Received: from localhost ([127.0.0.1]:57995 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uTmyP-0001DB-3T for submit@debbugs.gnu.org; Mon, 23 Jun 2025 15:36:57 -0400 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]:54614) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uTmyM-0001CR-1g for 78693@debbugs.gnu.org; Mon, 23 Jun 2025 15:36:55 -0400 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-553dceb345eso5053354e87.1 for <78693@debbugs.gnu.org>; Mon, 23 Jun 2025 12:36:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750707407; x=1751312207; darn=debbugs.gnu.org; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=cShCw+DNiMK/4ZCaYRERmf+7x3KeojJQ3M0egUPBCoI=; b=GIiFvJ+iyWPjiOjcFb0KW5qIbU2/3l0A3pQv46YJhKoYgSPt3vLxMogtY7oLVODYhz StGM8bSWQwbNUmC+OmshtE5m+OU4/9qQElsvP2j3liwBL4lPr/KZAqtLNXKUPWhZqfOG nPzKtcIUkL3GD6FBzMV3mxfKRYUuFq7jV4/cwxc/W4cY6cPED1aGjcRIwbUcyoWHyfxD Lr5yG6dx6Cxx1xW6w715FGXpaAXq1WAPO/y+nLUdQq6rS+ZWyxIV24Z34dPxH29ml3oJ wU8g7BzgaeBTF6EoYS2oXZ76N1g6BXZY8i2ZrIGdXDGxrAIQ6Zv+PB046rksCBnG/3oi 9vLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750707407; x=1751312207; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cShCw+DNiMK/4ZCaYRERmf+7x3KeojJQ3M0egUPBCoI=; b=ifBl2KskCdADoaakucvdKrZl3xWvKjydZNaBT9haT7tqfroEDjOshwZLYX23VbyJyH rtYtbzLRZkh29DYqzp5+0HlChw9+pqpGREHx4y/VLR2kfRfDtMe8Kc4QYTUKhVgAitgs sUh6GmHdMHNcSK2KgGmYPyE7FJXp7eqtdnFy/fjPC62JGRJwC2O2hQqh1J1AJLu/z3j8 Rj2H2pNjppDBpoibdjHwAqP9ch4kvmx460TD1h/yFCW0Uwz8upUtceKQabMO8ge1NhBj 7+03Ekh7QD5whH27WdN5tGrQuoRhz/TQ0UXk6Qjunu87b2tfJRYhLDdlKpYFdaqfJHLE 11IA== X-Gm-Message-State: AOJu0YxW8nesoJDxUiG1eJgN5z3YSAM5xnXSlN+TxpFXNDfHofKm3DQw D0eVSE5eDGWWuDtHmxICc/zex11gUnIoLoBhh3Rp/4lhh2K+YeoeB2Jm X-Gm-Gg: ASbGncse+qJEkmufJZekTuc7gAJ6kRMV25umkpf69PbclSLJxNccp5sNiTEPNRRP6rp PF9vdiJxyyHH9gmDlM7U4lNgQzTQeoKY5cLVHRgS5fJks5EX7lY6V0Ob+gbuxDytMFxdq/U/451 aqgaIebC6zZUzMQwB5xfa7txr/0PBivHJ9zlZEXqV6dnDcR1g453Tyy/4OtbB4PmDowBCrtPZRF Q766hFjv09zFhn23sgoNLi7PTge+ZruJSXnUPKaS9IDFW2NjG++Nvzr5C12brPZd8I8LktWdz8X e+Q2cOmsvEELxYGR5QvlWPX5yl6ce3lwyF475Du9s9GXidCG+oGI3/1enpTLNAq9pkfm X-Google-Smtp-Source: AGHT+IHtMqR0IjTkc0H0mv49s0Ty8IBJFTeoe6rZG5er4Xy0fge7rKA2i6R7Xw64Dx/yFVrSsdnzoA== X-Received: by 2002:a05:6512:3f18:b0:553:32f3:7ebe with SMTP id 2adb3069b0e04-553e3b99332mr4009666e87.2.1750707407064; Mon, 23 Jun 2025 12:36:47 -0700 (PDT) Received: from localhost ([185.229.154.192]) by smtp.gmail.com with UTF8SMTPSA id 2adb3069b0e04-553e41c3d98sm1497347e87.160.2025.06.23.12.36.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jun 2025 12:36:46 -0700 (PDT) From: "Paul D. Nelson" To: Rahguzar Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: <87h6079bdq.fsf@mailbox.org> (message from Rahguzar on Mon, 23 Jun 2025 12:15:45 +0500) Date: Mon, 23 Jun 2025 21:36:44 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi Raghuzar, Rahguzar writes: > Something that is able to distinguish between > > \begin{theorem}[My favorite theorem] > > and > > \begin{equation} > [X,P] By default, tex-fold.el folds theorem environments (taking into account their optional captions) but not equation environments. This happens via the TeX-fold-macro-spec-list entries (TeX-fold-begin-display ("begin")) (TeX-fold-end-display ("end")) and the TeX-fold-begin-end-spec-list entry for "theorem". This approach would not correctly handle "equation" environments that begin with commutator brackets, as you've noted, because the contains of those brackets would be mistakenly consumed as if they were an optional argument. To treat such cases correctly, we could allow the signature (which with the current version of the proposed patch can be an integer or pair of integers, bounding the total or optional/required arguments) to be a function. In TeX-find-macro-end-helper, we could call that function to determine whether any additional arguments should be consumed, passing along any arguments found thus far. We could assign the begin/end macros a signature function that says "for \begin macros with equation-like environments, don't accept any optional arguments". This would allow meaningful folding of both examples, without the artifact you have noted. On the other hand, it would require choosing good defaults for which environments should not admit optional args, and I don't have a clear sense there; do you? In my own setup, I do not fold equation environments, but instead use prettification, as described in my earlier email. This serves as a practical workaround. Before I adopted it, I remember encountering the same issue you described and using workarounds such as adding a blank commented line before the commutator bracket. Paul From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 24 06:50:40 2025 Received: (at 78693) by debbugs.gnu.org; 24 Jun 2025 10:50:41 +0000 Received: from localhost ([127.0.0.1]:40987 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uU1Ed-0006Qh-RE for submit@debbugs.gnu.org; Tue, 24 Jun 2025 06:50:40 -0400 Received: from mout-p-102.mailbox.org ([2001:67c:2050:0:465::102]:41258) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uU1EY-0006Of-56 for 78693@debbugs.gnu.org; Tue, 24 Jun 2025 06:50:36 -0400 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4bRMDG2NCDz9tkn; Tue, 24 Jun 2025 12:50:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1750762222; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DJOdABQcj9ML79oazlIgeuEZtzQNgAN1xtZgm0983vE=; b=YZSZu+x47FjwHZaKZvCKVR5JifKYVBIqaBUJyAr+OVT3V4MUtRSgSMOHtjflCb+wZKo8A2 eclCHHxIpSnqPw3qj8L7N95f4L3ehiEpYvFFBmOcvSVo6rc2Pd2ijT8D3Oa64Z8KT1Q/NS hkAhvHeeHti608d/eQzUtw0TeozFvlXAT+66xO+uCpjK0Gvltdg3+BnlR7lJqDWWnSteVH CCTHDiamVes5osoktH3rVF4OraVx0J7K2xogS/E6sutiK+ryQcV8UYgN0tyfe+G6lgfj2N JfQEdxaPCF+Npl0YmUjioHfEhbpQLxDuKpb9+hG79JYs3SGIhk9nB7aaNF9qIQ== From: Rahguzar To: "Paul D. Nelson" Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: (Paul D. Nelson's message of "Mon, 23 Jun 2025 21:36:44 +0200") References: Date: Tue, 24 Jun 2025 15:50:17 +0500 Message-ID: <875xgl9zx2.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: text/plain X-MBO-RS-META: ykdjx5swo4kdgmd9k9zs4jnqssqrbduh X-MBO-RS-ID: 124463347dea5e10ab0 X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Hi Paul, "Paul D. Nelson" writes: > To treat such cases correctly, we could allow the signature (which with > the current version of the proposed patch can be an integer or pair of > integers, bounding the total or optional/required arguments) to be a > function. In TeX-find-macro-end-helper, we could call that function to > determine whether any additional arguments should be consumed, passing > along any arguments found thus far. We could assign the begin/end > macros a signature function that says "for \begin macros with > equation-like environments, don't accept any optional arguments". This > would allow meaningful folding of both examples, without the artifact > you have noted. On the other hand, it would require choosing good > defaults for which environments should not admit optional args, and I > don't have a clear sense there; do you? I think a function can be a good idea but I don't know what would be a good design in that case? Should we pass it some arguments? I guess not but a function without arguments would not be easiest to use. I guess it will have to rely on TeX-fold-macro-nth-arg. One alternative I can think of is to allow a function SPEC to return not only a string but also (STR . BOUND) where BOUND determines the extent of the folding. In the present case this would allow BOUND to determined by matching on the environment name and this pattern matching wouldn't have to be duplicated in the SPEC and SIG. > In my own setup, I do not fold equation environments, but instead use > prettification, as described in my earlier email. This serves as a > practical workaround. Before I adopted it, I remember encountering the > same issue you described and using workarounds such as adding a blank > commented line before the commutator bracket. I will try some more prettification the next time I mess with my config. Thanks for that idea. Rahguzar From debbugs-submit-bounces@debbugs.gnu.org Sun Jul 06 08:32:59 2025 Received: (at 78693) by debbugs.gnu.org; 6 Jul 2025 12:32:59 +0000 Received: from localhost ([127.0.0.1]:53937 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uYOYD-0005bI-Tr for submit@debbugs.gnu.org; Sun, 06 Jul 2025 08:32:59 -0400 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]:45535) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uYOYA-0005a4-2S for 78693@debbugs.gnu.org; Sun, 06 Jul 2025 08:32:56 -0400 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-32f1df5703aso6594541fa.3 for <78693@debbugs.gnu.org>; Sun, 06 Jul 2025 05:32:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751805167; x=1752409967; darn=debbugs.gnu.org; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=YdojPGAEnm1lW6x1CqYw+vTj8DxrP7aQh2aI2gvHuto=; b=MNLOtqGvTQqHPbjcr4PvQOKggok2hMb2JclAIqUL/MT3oMCxEM3p5S8cemBScampca d7EdOxmdsAcecbbxmAri4VHslXo5vVLiOlHpnH7BMeDdwDjr5Z+RqodXV2dgr7RGz8bm be1vu8EIWWqV5IZy/Cq9y4ZHR5GO9dBngFQWs8T7p5qI6p4rGhmToiMXJPzvZqLPqsTq JqjQPrAUm+7d8an2xKq7jCnonvinYuKtc2CukjDEgnKI2KfskvhXD0Nq1ceJyUtOadSm F6OWnmxnyR5FFxFk6QwuMlCjKhssFz91CRhiccLi33bBd7cSl2EbBXHl7fIqy0sXYhAM s8HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751805167; x=1752409967; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YdojPGAEnm1lW6x1CqYw+vTj8DxrP7aQh2aI2gvHuto=; b=Ukdp4j6XNh1/nIcXMWZF7fnCN1YLQLaS+HvUmsvFpqa/b9jV/uuYkl1r9Z5xDYTSM+ 8LV+huS19rdkGXR336bBLEMLS5gQ+44rUljOgae8KfD1U0S18Y4qnS9gz4lJw25hF5oz XUamW1BIaRfVH+LoxvIM9yte+AU2/PSQPvUgKQzQkyBPlmGiZHT4ODCs4Bj4vAjCWtSl sXrmR1yPItIPvzfOzdEbQBZpWML7Z+GkAt0rrO5CV2P64+qIgWoStnnOp5S+bbDsuwY6 JZs8gLD3D2i4LnMg583PFaUrYh2l4Y113EP9XhOjnCB08BVMiQ/n0gbvACpfFWHPHhiC sbOw== X-Gm-Message-State: AOJu0YwNcDc/lucn481jgIiSx3vWJa28UKoMwPM4uLB9CAuYN2Yp18EC ZGH1jR8DCYS6OlGNKzR80+vamud0sNCwLW8uW/i4VWxrC/UNYlp1Dj3k X-Gm-Gg: ASbGnctNax9eCpmYPb03u8qZ/UVzLH9BYBuRLAb9j4ILu4CYQ5zEJsj5r0osBlvKgMZ bKErxRdfvmxy/yl9WW0dfbIHwrCu40yIqB/EqwLcBP95rv6WHWpOkizYUoEG0RpXuhgSHlzEjDO +vamThdnotG3qslkNmWCZu+o9y4yGWn99U4/Ww4ECMJO6ZrOAYoVZHAL0E4xyhP6SMMXYHKg/En dC6LLZDX9db/aZaslr5t0pWF19Mi5hG9+c18C9rzRwR4CHfUrqL4bltbYHLzcLdiaVC+vD08Y8t S+2EPaMSW/YB0uCPc2Y9uOrad0Ly5cuwhbvKqIOuMm7FSdhiQIN+QxnNJKZCsMOsPTNKaEVOf+I kzw4uKG6jHwXyjKVSKvmNZdDckqf8OA== X-Google-Smtp-Source: AGHT+IHbjdlCJdspAyjrnKJu0TIAFTXv8yJLcUQ9KK0P0syYdZ9BXmRolovpnDrga5ak0wLYG883IA== X-Received: by 2002:a2e:ae1c:0:b0:32b:784f:bca5 with SMTP id 38308e7fff4ca-32f19b84187mr15265711fa.28.1751805167059; Sun, 06 Jul 2025 05:32:47 -0700 (PDT) Received: from localhost (0x5da5fbba.static.cust.fastspeed.dk. [93.165.251.186]) by smtp.gmail.com with UTF8SMTPSA id 38308e7fff4ca-32e1b147821sm8060261fa.95.2025.07.06.05.32.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Jul 2025 05:32:46 -0700 (PDT) From: "Paul D. Nelson" To: Rahguzar Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: <875xgl9zx2.fsf@mailbox.org> (message from Rahguzar on Tue, 24 Jun 2025 15:50:17 +0500) Date: Sun, 06 Jul 2025 14:32:45 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Rahguzar, I thought about the further edge cases you raised. The attached patch is what I came up with. You mentioned the following problem: when folding \begin macros, you want to consume optional arguments following (e.g.) \begin{theorem} but not (e.g.) \begin{equation}, so as to avoid errors in, e.g., \begin{equation} [X, Y] =3D Z \end{equation} With the attached patch, you can do so as follows: --8<---------------cut here---------------start------------->8--- (defun my-equation-env-p (args) "Return non-nil when ARGS describes an equation environment. Return non-nil if the list ARGS is of the form '(\"{env}\") where ENV is an equation environment, such as equation, align, gather, multline or their starred variants." (and (=3D 1 (length args)) (let* ((envs (LaTeX--math-environment-list)) (re (concat "{" (regexp-opt envs) "}"))) (string-match-p re (car args))))) (setq-local TeX-fold-macro-spec-list `((("=E2=AC=96 {1}" . my-equation-env-p) ("begin"))=20 (("=E2=AC=97 {1}" . 1) ("end")))) --8<---------------cut here---------------end--------------->8--- This says that when determining the folding extent of a \begin macro for a display math environment, we stop after the first argument (which is just the environment name). As before, the "1" signature in the \end macro has the effect that in \end{equation} [blah] we do not fold the trailing "[blah]". Edge cases such as \begin{equation} \label{eq:blah} [X, Y] =3D Z \end{equation} are a bit subtler: with some packages, \label can accept optional arguments, so we can't avoid such cases simply by restricting the number of optional and required arguments. Instead, we use the macro spec list entry (("[l]" . TeX-fold-stop-after-first-required) ("label")) with the following predicate: (defun TeX-fold-stop-after-first-required (args) "Return nil when final element of ARGS starts with \"{\"." (and args (string-prefix-p "{" (car (last args))))) With this, when we fold \label macros, we stop consuming after the first required argument that we encounter. Thus, \label[...][...]{...} folds correctly, while \label[...]{...}[...] stops after the {...}. I can't think of any other edge cases. I think this patch is now ready to ship, although I'd welcome any feedback. Thanks, best, Paul --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-signature-support-for-macro-folding.patch >From 34ea7e6dfcd53ce863f79b6222699627873c5f83 Mon Sep 17 00:00:00 2001 From: Paul Nelson Date: Sun, 15 Jun 2025 12:24:11 +0200 Subject: [PATCH] Add signature support for macro folding Support signature restrictions to limit the arguments consumed when folding LaTeX macros (bug#78693). * tex.el (TeX-find-macro-boundaries, TeX-find-macro-end) (TeX-find-macro-end-helper): Add optional SIGNATURE argument to restrict allowed arguments. * tex-fold.el (TeX-fold--spec-type): New internal constant. (TeX-fold-macro-spec-list, TeX-fold-math-spec-list): Add signatures to default folding specifications. Update docstring and type specification to document new signature format. (TeX-fold-region-macro-or-env, TeX-fold-item): Extract signature from spec and pass to 'TeX-fold-item-end'. (TeX-fold-item-end): Add optional SIGNATURE parameter. Remove special handling for math type, reverting d0a57d8d and delegating instead to 'TeX-find-macro-end'. (TeX-fold-stop-after-first-required): New folding signature predicate. * latex.el (LaTeX-fold-math-spec-list): Add "signature 0" to each entry, reflecting that it is a macro with no arguments. * doc/auctex.texi (Folding): Document the new feature. * tex-fold.el : (TeX-fold-macro-spec-list): --- doc/auctex.texi | 17 ++++++ latex.el | 2 +- tex-fold.el | 159 ++++++++++++++++++++++++++++-------------------- tex.el | 126 ++++++++++++++++++++++++-------------- 4 files changed, 194 insertions(+), 110 deletions(-) diff --git a/doc/auctex.texi b/doc/auctex.texi index 90a8cf21..58d063f0 100644 --- a/doc/auctex.texi +++ b/doc/auctex.texi @@ -2958,6 +2958,23 @@ as a replacement for the macro. Such functions typically return a string, but may also return the symbol @code{abort} to indicate that the macro should not be folded. +Each specifier may instead be a cons cell @code{(@var{spec} . @var{sig})}, +where @var{spec} is as above and @var{sig} controls how many arguments are +considered part of the macro to fold: +@itemize @bullet +@item +@code{nil}: no limit (default). +@item +Integer @var{n}: stop after @var{n} total arguments. +@item +Cons @code{(@var{p} . @var{q})}: stop after @var{p} optional and +@var{q} required arguments. +@item +Predicate function: called repeatedly with the list of argument blocks +encountered thus far. Returns non-@code{nil} to terminate scanning early. +See the doc string of @code{TeX-find-macro-boundaries} for details. +@end itemize + The placeholder is made by copying the text from the buffer together with its properties, i.e.@: its face as well. If fontification has not happened when this is done (e.g.@: because of lazy font locking) the diff --git a/latex.el b/latex.el index 5bff638b..94666fe8 100644 --- a/latex.el +++ b/latex.el @@ -6729,7 +6729,7 @@ char." "Accents"))) submenu))) (when (and (stringp tex-token) (integerp uchar) noargp) - `(,(char-to-string uchar) (,tex-token))))) + `((,(char-to-string uchar) . 0) (,tex-token))))) `((nil "to" "" 8594) (nil "gets" "" 8592) ,@LaTeX-math-default))) diff --git a/tex-fold.el b/tex-fold.el index 78e5b822..1f3f7b04 100644 --- a/tex-fold.el +++ b/tex-fold.el @@ -72,62 +72,83 @@ macros, `math' for math macros and `comment' for comments." (const :tag "Math Macros" math) (const :tag "Comments" comment))) +(defconst TeX-fold--spec-type + '(choice + (string :tag "Display String") + (integer :tag "Number of argument" :value 1) + (function :tag "Function to execute") + (cons :tag "Spec with signature" + (choice (string :tag "Display String") + (integer :tag "Number of argument" :value 1) + (function :tag "Function to execute")) + (choice (const :tag "No restriction" nil) + (integer :tag "Max total arguments") + (cons :tag "Max optional and required" + (integer :tag "Max optional arguments") + (integer :tag "Max required arguments")) + (function :tag "Predicate function")))) + "Type spec used by TeX-fold defcustoms.") + (defcustom TeX-fold-macro-spec-list - '(("[f]" ("footnote" "marginpar")) - (TeX-fold-cite-display ("cite")) - ("[l]" ("label")) - ("[r]" ("ref" "pageref" "eqref" "footref")) - ("[i]" ("index" "glossary")) - ("[1]:||*" ("item")) - ("..." ("dots")) - ("(C)" ("copyright")) - ("(R)" ("textregistered")) - ("TM" ("texttrademark")) - (TeX-fold-alert-display ("alert")) - (TeX-fold-textcolor-display ("textcolor")) + '((("[f]" . (1 . 1)) ("footnote" "marginpar")) + ((TeX-fold-cite-display . (2 . 1)) ("cite")) + (("[l]" . TeX-fold-stop-after-first-required) ("label")) + (("[r]" . 1) ("ref" "pageref" "eqref" "footref")) + (("[i]" . (1 . 1)) ("index" "glossary")) + (("[1]:||*" . (1 . 0)) ("item")) + (("..." . 0) ("dots")) + (("(C)" . 0) ("copyright")) + (("(R)" . 0) ("textregistered")) + (("TM" . 0) ("texttrademark")) + ((TeX-fold-alert-display . 1) ("alert")) + ((TeX-fold-textcolor-display . (1 . 2)) ("textcolor")) (TeX-fold-begin-display ("begin")) - (TeX-fold-end-display ("end")) + ((TeX-fold-end-display . 1) ("end")) (1 ("part" "chapter" "section" "subsection" "subsubsection" "paragraph" "subparagraph" "part*" "chapter*" "section*" "subsection*" "subsubsection*" - "paragraph*" "subparagraph*" - "emph" "textit" "textsl" "textmd" "textrm" "textsf" "texttt" - "textbf" "textsc" "textup"))) + "paragraph*" "subparagraph*")) + ((1 . (0 . 1)) ("emph" "textit" "textsl" "textmd" "textrm" "textsf" "texttt" + "textbf" "textsc" "textup"))) "List of replacement specifiers and macros to fold. -The first element of each item can be a string, an integer or a -function symbol. The second element is a list of macros to fold -without the leading backslash. - -If the first element is a string, it will be used as a display -replacement for the whole macro. Numbers in braces, brackets, -parens or angle brackets will be replaced by the respective macro -argument. For example \"{1}\" will be replaced by the first -mandatory argument of the macro. One can also define -alternatives within the specifier which are used if an argument -is not found. Alternatives are separated by \"||\". They are -most useful with optional arguments. As an example, the default -specifier for \\item is \"[1]:||*\" which means that if there is -an optional argument, its value is shown followed by a colon. If -there is no optional argument, only an asterisk is used as the -display string. - -If the first element is an integer, the macro will be replaced by -the respective macro argument. - -If the first element is a function symbol, the function will be -called with all mandatory arguments of the macro and the result -of the function call will be used as a replacement for the macro. -Such functions typically return a string, but may also return the -symbol `abort' to indicate that the macro should not be folded. - -Setting this variable does not take effect immediately. Use -Customize or reset the mode." - :type '(repeat (group (choice (string :tag "Display String") - (integer :tag "Number of argument" :value 1) - (function :tag "Function to execute")) +The first element is of the form SPEC or (SPEC . SIG), where SPEC can be +a string, an integer or a function symbol and SIG is described below. +The second element is a list of macros to fold without the leading +backslash. + +If SPEC is a string, it will be used as a display replacement for the +whole macro. Numbers in braces, brackets, parens or angle brackets will +be replaced by the respective macro argument. For example \"{1}\" will +be replaced by the first mandatory argument of the macro. One can also +define alternatives within the specifier which are used if an argument +is not found. Alternatives are separated by \"||\". They are most +useful with optional arguments. As an example, the default specifier +for \\item is \"[1]:||*\" which means that if there is an optional +argument, its value is shown followed by a colon. If there is no +optional argument, only an asterisk is used as the display string. + +If SPEC is an integer, the macro will be replaced by the respective +macro argument. + +If SPEC is a function symbol, the function will be called with all +mandatory arguments of the macro and the result of the function call +will be used as a replacement for the macro. Such functions typically +return a string, but may also return the symbol `abort' to indicate that +the macro should not be folded. + +SIG optionally restricts how many macro arguments are consumed. It +should be of the form required by the SIGNATURE argument of +`TeX-find-macro-boundaries'. For example, if SIGNATURE is an integer n, +then at most n total arguments are consumed, while if it is a cons +cell (p . q), then at most p optional and q required arguments are +allowed. + +Setting this variable does not take effect immediately. Use Customize +or reset the mode." + :type `(repeat (group ,TeX-fold--spec-type (repeat :tag "Macros" (string)))) - :package-version '(auctex . "14.0.8")) + :package-version '(auctex . "14.0.9")) (defvar-local TeX-fold-macro-spec-list-internal nil "Internal list of display strings and macros to fold. @@ -153,9 +174,7 @@ and -fold-env-spec-list.") (defcustom TeX-fold-math-spec-list nil "List of display strings and math macros to fold." - :type '(repeat (group (choice (string :tag "Display String") - (integer :tag "Number of argument" :value 1) - (function :tag "Function to execute")) + :type `(repeat (group ,TeX-fold--spec-type (repeat :tag "Math Macros" (string))))) (defvar-local TeX-fold-math-spec-list-internal nil @@ -437,9 +456,14 @@ for macros and `math' for math macros." (string (char-after (match-end 0))))))) (let* ((item-start (match-beginning 0)) - (display-string-spec (cadr (assoc item-name - fold-list))) - (item-end (TeX-fold-item-end item-start type)) + (spec-sig? (cadr (assoc item-name fold-list))) + ;; spec-sig? is of the form SPEC or (SPEC . SIG). + (display-string-spec (if (consp spec-sig?) + (car spec-sig?) + spec-sig?)) + (sig (when (consp spec-sig?) + (cdr spec-sig?))) + (item-end (TeX-fold-item-end item-start type sig)) (ov (TeX-fold-make-overlay item-start item-end type display-string-spec))) (TeX-fold-hide-item ov)))))))))) @@ -536,7 +560,7 @@ Return non-nil if an item was found and folded, nil otherwise." TeX-fold-math-spec-list-internal) (t TeX-fold-macro-spec-list-internal))) fold-item - (display-string-spec + (spec-sig? (or (catch 'found (while fold-list (setq fold-item (car fold-list)) @@ -549,7 +573,13 @@ Return non-nil if an item was found and folded, nil otherwise." (if (eq type 'env) TeX-fold-unspec-env-display-string TeX-fold-unspec-macro-display-string)))) - (item-end (TeX-fold-item-end item-start type)) + ;; spec-sig? is of the form SPEC or (SPEC . SIG). + (display-string-spec (if (consp spec-sig?) + (car spec-sig?) + spec-sig?)) + (sig (when (consp spec-sig?) + (cdr spec-sig?))) + (item-end (TeX-fold-item-end item-start type sig)) (ov (TeX-fold-make-overlay item-start item-end type display-string-spec))) (TeX-fold-hide-item ov)))))) @@ -882,10 +912,12 @@ display property." (overlay-put ov 'display display-string)) ov)) -(defun TeX-fold-item-end (start type) +(defun TeX-fold-item-end (start type &optional signature) "Return the end of an item of type TYPE starting at START. TYPE can be either `env' for environments, `macro' for macros or -`math' for math macros." +`math' for math macros. +Optional SIGNATURE, as in `TeX-find-macro-boundaries', restricts the +allowed arguments of LaTeX macros." (save-excursion (cond ((and (eq type 'env) (eq major-mode 'ConTeXt-mode)) @@ -901,15 +933,9 @@ TYPE can be either `env' for environments, `macro' for macros or (goto-char (1+ start)) (LaTeX-find-matching-end) (point)) - ((eq type 'math) - (goto-char (1+ start)) - (if (zerop (skip-chars-forward "A-Za-z@")) - (forward-char) - (skip-chars-forward "*")) - (point)) (t (goto-char start) - (TeX-find-macro-end))))) + (TeX-find-macro-end signature))))) (defun TeX-fold-overfull-p (ov-start ov-end display-string) "Return t if an overfull line will result after adding an overlay. @@ -1070,6 +1096,9 @@ breaks will be replaced by spaces." (dolist (ov overlays) (TeX-fold-hide-item ov))))) +(defun TeX-fold-stop-after-first-required (args) + "Return nil when final element of ARGS starts with \"{\"." + (and args (string-prefix-p "{" (car (last args))))) ;;; Removal diff --git a/tex.el b/tex.el index 6f8267ac..de2b4505 100644 --- a/tex.el +++ b/tex.el @@ -5790,11 +5790,23 @@ If LIMIT is non-nil, do not search further up than this position in the buffer." (TeX-find-balanced-brace -1 depth limit)) -(defun TeX-find-macro-boundaries (&optional lower-bound) +(defun TeX-find-macro-boundaries (&optional lower-bound signature) "Return a cons containing the start and end of a macro. If LOWER-BOUND is given, do not search backward further than this point in buffer. Arguments enclosed in brackets or braces are -considered part of the macro." +considered part of the macro. + +If SIGNATURE is given, restrict the total number of arguments. If +SIGNATURE is an integer N, allow at most N total arguments. If +SIGNATURE is a cons cell (P . Q), allow at most P optional and Q +required arguments. + +Finally, SIGNATURE may be a function, called before each new argument is +consumed with a single list argument consisting of the argument blocks +encountered thus far. For example, with point before +\"\\begin{equation}\", it would be called first with the empty list () +and then with the single element list (\"{equation}\"). If SIGNATURE +returns non-nil, then no further macro arguments are consumed." ;; FIXME: Pay attention to `texmathp-allow-detached-args' and ;; `reftex-allow-detached-macro-args'. ;; Should we handle cases like \"{o} and \\[3mm] (that is, a macro @@ -5839,16 +5851,17 @@ considered part of the macro." ;; Search forward for the end of the macro. (when start-point (save-excursion - (goto-char (TeX-find-macro-end-helper start-point)) + (goto-char (TeX-find-macro-end-helper start-point signature)) (if (< orig-point (point)) (cons start-point (point)) nil)))))) -(defun TeX-find-macro-end-helper (start) +(defun TeX-find-macro-end-helper (start &optional signature) "Find the end of a macro given its START. START is the position just before the starting token of the macro. If the macro is followed by square brackets or curly braces, -those will be considered part of it." +those will be considered part of it. SIGNATURE, as in +`TeX-find-macro-boundaries', restricts how many arguments are allowed." (save-excursion (save-match-data (catch 'found @@ -5856,43 +5869,67 @@ those will be considered part of it." (if (zerop (skip-chars-forward "A-Za-z@")) (forward-char) (skip-chars-forward "*")) - (while (not (eobp)) - (cond - ;; Skip over pairs of square brackets - ((or (looking-at "[ \t]*\n?[ \t]*\\(\\[\\)") ; Be conservative: Consider + (let* ((max-tot (and (integerp signature) signature)) + (max-opt (and (consp signature) (car signature))) + (max-req (and (consp signature) (cdr signature))) + (num-opt 0) + (num-req 0) + (sig-pred (when (functionp signature) signature)) + last-arg-start last-args) + (while (not (eobp)) + (when (or (and max-tot (>= (+ num-opt num-req) max-tot)) + (and sig-pred + (progn + (when last-arg-start + (let ((arg (buffer-substring-no-properties + last-arg-start (point)))) + (setq last-args (nconc last-args (list arg))))) + (funcall sig-pred last-args)))) + (throw 'found (point))) + (cond + ;; Skip over pairs of square brackets + ((or (looking-at "[ \t]*\n?[ \t]*\\(\\[\\)") ; Be conservative: Consider ; only consecutive lines. - (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp)) - (save-excursion - (forward-line 1) - (looking-at "[ \t]*\\(\\[\\)")))) - (goto-char (match-beginning 1)) - ;; Imitate `font-latex-find-matching-close', motivated by - ;; examples like \begin{enumerate}[a{]}]. - (let ((syntax (TeX-search-syntax-table ?\[ ?\])) - (parse-sexp-ignore-comments - (not (derived-mode-p 'docTeX-mode)))) - (modify-syntax-entry ?\{ "|" syntax) - (modify-syntax-entry ?\} "|" syntax) - (modify-syntax-entry ?\\ "/" syntax) - (condition-case nil - (with-syntax-table syntax - (forward-sexp)) - (scan-error (throw 'found (point)))))) - ;; Skip over pairs of curly braces - ((or (looking-at "[ \t]*\n?[ \t]*{") ; Be conservative: Consider + (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp)) + (save-excursion + (forward-line 1) + (looking-at "[ \t]*\\(\\[\\)")))) + (when (and max-opt (>= num-opt max-opt)) + (throw 'found (point))) + (cl-incf num-opt) + (goto-char (match-beginning 1)) + (setq last-arg-start (point)) + ;; Imitate `font-latex-find-matching-close', motivated by + ;; examples like \begin{enumerate}[a{]}]. + (let ((syntax (TeX-search-syntax-table ?\[ ?\])) + (parse-sexp-ignore-comments + (not (derived-mode-p 'docTeX-mode)))) + (modify-syntax-entry ?\{ "|" syntax) + (modify-syntax-entry ?\} "|" syntax) + (modify-syntax-entry ?\\ "/" syntax) + (condition-case nil + (with-syntax-table syntax + (forward-sexp)) + (scan-error (throw 'found (point)))))) + ;; Skip over pairs of curly braces + ((or (looking-at "[ \t]*\n?[ \t]*{") ; Be conservative: Consider ; only consecutive lines. - (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp)) - (save-excursion - (forward-line 1) - (looking-at "[ \t]*{")))) - (goto-char (match-end 0)) - (goto-char (or (TeX-find-closing-brace) - ;; If we cannot find a regular end, use the - ;; next whitespace. - (save-excursion (skip-chars-forward "^ \t\n") - (point))))) - (t - (throw 'found (point))))) + (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp)) + (save-excursion + (forward-line 1) + (looking-at "[ \t]*{")))) + (when (and max-req (>= num-req max-req)) + (throw 'found (point))) + (cl-incf num-req) + (goto-char (match-end 0)) + (setq last-arg-start (1- (point))) + (goto-char (or (TeX-find-closing-brace) + ;; If we cannot find a regular end, use the + ;; next whitespace. + (save-excursion (skip-chars-forward "^ \t\n") + (point))))) + (t + (throw 'found (point)))))) ;; Make sure that this function does not return nil, even ;; when the above `while' loop is totally skipped. (bug#35638) (throw 'found (point)))))) @@ -5904,11 +5941,12 @@ in buffer. Arguments enclosed in brackets or braces are considered part of the macro." (car (TeX-find-macro-boundaries limit))) -(defun TeX-find-macro-end () +(defun TeX-find-macro-end (&optional signature) "Return the end of a macro. -Arguments enclosed in brackets or braces are considered part of -the macro." - (cdr (TeX-find-macro-boundaries))) +Arguments enclosed in brackets or braces are considered part of the +macro. SIGNATURE, as in `TeX-find-macro-boundaries', restricts how many +arguments are allowed." + (cdr (TeX-find-macro-boundaries nil signature))) (defun TeX-search-forward-unescaped (string &optional bound noerror) "Search forward from point for unescaped STRING. -- 2.39.3 (Apple Git-145) --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sun Jul 20 02:06:26 2025 Received: (at 78693) by debbugs.gnu.org; 20 Jul 2025 06:06:26 +0000 Received: from localhost ([127.0.0.1]:47831 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1udNBq-0000qI-Eo for submit@debbugs.gnu.org; Sun, 20 Jul 2025 02:06:26 -0400 Received: from mout-p-103.mailbox.org ([2001:67c:2050:0:465::103]:60070) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1udNBn-0000pk-UE for 78693@debbugs.gnu.org; Sun, 20 Jul 2025 02:06:24 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4blChN4VyLz9ssQ; Sun, 20 Jul 2025 08:06:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1752991572; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Sw2qkQjQJMQG5hgSmV4XqtvXeNj0jR/Qnuf6JekhFAc=; b=sKNstfY84X9pxI4cFmh6yMRSmjB8csRakEJvbRgjrtPX0w/G+uPglKqC2jxTi2Pq74bU35 vAtf+uD2qbSai9XmTBroz9Q4zdGaKv5DHmOpiUkIBaryNnQaIJ04cQZWLL7JC47QzCR77e d8xuDXOr1Kr08dx7zQ4fUUK6ugu8wyb9YPAmQX5jF3CS7Ysrwyqyay/zapnwK9RpRlEpNA 5V/wAlAf4t3DYEKQWL+uQzwMOWD4rKPCyqkoSDqZa4uqEGIJmNFIzsqnA8DxyOyfpHRZUw WgOrQKrlL+Y7zN6kxDZwSECG5mNZ8ODp1rg/bjIn+t/hu7hFhu2LML7KrPZj+g== From: Rahguzar To: "Paul D. Nelson" Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: (Paul D. Nelson's message of "Sun, 06 Jul 2025 14:32:45 +0200") References: Date: Sun, 20 Jul 2025 11:06:07 +0500 Message-ID: <87v7nn5rcg.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: text/plain X-MBO-RS-META: ph7nu6pe7fth6nkkd8h5fgbghtbdk4n6 X-MBO-RS-ID: 29dad87e8909e53ad47 X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Hi Paul, "Paul D. Nelson" writes: > Hi Rahguzar, > > I thought about the further edge cases you raised. The attached patch > is what I came up with. Thanks! This solution of allowing the full power of TeX-find-macro-boundaries in signature seems like the best one and in my brief testing it works well and is very flexible. > I can't think of any other edge cases. I think this patch is now ready > to ship, although I'd welcome any feedback. I also think that it is ready to ship. Thanks for all your work on this. > Thanks, best, > > Paul > > [2. text/x-patch; 0001-Add-signature-support-for-macro-folding.patch]... Best, Rahguzar From debbugs-submit-bounces@debbugs.gnu.org Sun Aug 03 09:32:31 2025 Received: (at 78693) by debbugs.gnu.org; 3 Aug 2025 13:32:32 +0000 Received: from localhost ([127.0.0.1]:43263 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uiYpA-0005B8-VP for submit@debbugs.gnu.org; Sun, 03 Aug 2025 09:32:30 -0400 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]:44237) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uiYp4-0005Ai-Dg for 78693@debbugs.gnu.org; Sun, 03 Aug 2025 09:32:24 -0400 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-55b88369530so4426335e87.0 for <78693@debbugs.gnu.org>; Sun, 03 Aug 2025 06:32:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754227936; x=1754832736; darn=debbugs.gnu.org; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=+ZGAkP9VnnCp7QXsx+je2FkxObZuv0gX70nO+hqhG6g=; b=BjtaXu/ddm5ICufTpZHcUaqq9X0rEJ1vqdfz1GQyna7TbAVfqt1wCaQ1P0klRMIkeY BU74z/cUown3Dn6zp+zTrvDoqwnyq1E0xTZ3p8B0aC1mkLjyWahq9a428AdD3yuVd5bn yNYr3nLIWUWG/d4AhJVSiZfpvWLSZESL/YzCkobvBPbMesU4F+zQAt5Hgj/hIs2IdwR3 GryoiRx5/tX0KnIjY7abQBxlq3TFMglu0WXocGJa0b2JnFVDfhXseTwSVWGLuxu4qdID hBxnjVzV7k0rrM2eIodl6Vi4CIW8ZwOsyPRbJiUj7R4DJWU6Tiz5y/epyGT/Rs0X01G+ d5GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754227936; x=1754832736; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+ZGAkP9VnnCp7QXsx+je2FkxObZuv0gX70nO+hqhG6g=; b=ByCT29DVIK1dafprqhGijazAXnhBfT7Qfwei4idfjfaC6BLMMv7vf8lr22DTr9ifnq 4uQTVjP9o3djvNlsv+trq2DJqk4AAdroMNr0CAFTxL1YkVIzUJ8WHCCGZ6qytKmzrHzD pBeeO8Gh8IISv6qPZxA8iewZ/9Sgp8mDsYPh74UItao87S1sYf/8JI5RFi2GMa+mb5SL 8k0B4DaxzsOx7GEKuBUXCjQ5+VhkyhQSr0wWActe8O6UQicu5KjP8zzO13RUUzhEKaSU MAOOA8mSs1qLsSZ7M+nyLCURC24/LfE+xdj+goIsmTZuhYgiFtrvkqlQnsAYOd6F+c3C hnug== X-Gm-Message-State: AOJu0Yyb/W3RVR9CLUMlqPD0fKVKE1rVOvLcUaBAIX/mQ57gKML1mczL 0k4XsyoJO/ywTJeG8MyprEuFSK+8LTHqtILi7j/2EM5Z9GeoaCPhfJlL X-Gm-Gg: ASbGncv05ZB/wJXo4HYNUExjcaSGv7W18vgDUY5Gv7Wx4rHn6arIPzZhPm+vtiz8+Al y3Ts2QJ7t5kzGmuChf/9BHTLwp5WUVaIknBzxEekZlTkotHG3m6eZYfoHDU2v4LekuDPRx9vUCq wyfDsaQoQqtxuf65mFniXCWepBaySmeW1sw2Pd96pv4yfxXssXNZXeJKUZURHHy5CVhZR+tkcI0 AgvXW7zcyDGcyz6wJe+z3K4YvTuxKGCJkB8a9GS3ccQj1idgeWK5RDkXbgTYHN3t41xvy5IzTBw deXx9FtJvQ3cnEgVVDYDgVYx1kz7MukWSQym+NjARfjXcTFbpasr5cabaW8DAg70kFKwpvxULjL Rq7z69pehwUr1D7DCl+uX2uTf5jt+0AjAmbEHt5+/568E8y+/2LjoXoLmHudU9W+0mBUKYKIDRP ay X-Google-Smtp-Source: AGHT+IGecA0kcnB+Yr6cgBMScKZe+Uh2B/uOhWHYf1gwlQI6igmf92o0h7h163LkkmsHkkxMJkJRaA== X-Received: by 2002:a05:6512:1252:b0:55b:941d:bde3 with SMTP id 2adb3069b0e04-55b97a67c13mr1948079e87.10.1754227935459; Sun, 03 Aug 2025 06:32:15 -0700 (PDT) Received: from localhost (0x5da5fbba.static.cust.fastspeed.dk. [93.165.251.186]) by smtp.gmail.com with UTF8SMTPSA id 38308e7fff4ca-33238911615sm13056871fa.72.2025.08.03.06.32.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Aug 2025 06:32:14 -0700 (PDT) From: "Paul D. Nelson" To: Rahguzar Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: <87v7nn5rcg.fsf@mailbox.org> (message from Rahguzar on Sun, 20 Jul 2025 11:06:07 +0500) Date: Sun, 03 Aug 2025 15:32:13 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain Rahguzar writes: > Hi Paul, > > "Paul D. Nelson" writes: > >> I can't think of any other edge cases. I think this patch is now ready >> to ship, although I'd welcome any feedback. > > I also think that it is ready to ship. Thanks for all your work on this. Thanks Raghuzar. Attaching an updated patch rebased to master. Since it's a non-local change, I figure I'll wait for Arash or Ikumi to take a quick sniff, then we can push and close. Paul --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-signature-support-for-macro-folding.patch >From 5eabc82a9a336dbf747efc138ea27f7cafa20dd0 Mon Sep 17 00:00:00 2001 From: Paul Nelson Date: Sun, 15 Jun 2025 12:24:11 +0200 Subject: [PATCH] Add signature support for macro folding Support signature restrictions to limit the arguments consumed when folding LaTeX macros (bug#78693). * tex.el (TeX-find-macro-boundaries, TeX-find-macro-end) (TeX-find-macro-end-helper): Add optional SIGNATURE argument to restrict allowed arguments. * tex-fold.el (TeX-fold--spec-type): New internal constant. (TeX-fold-macro-spec-list, TeX-fold-math-spec-list): Add signatures to default folding specifications. Update docstring and type specification to document new signature format. (TeX-fold-region-macro-or-env, TeX-fold-item): Extract signature from spec and pass to 'TeX-fold-item-end'. (TeX-fold-item-end): Add optional SIGNATURE parameter. Remove special handling for math type, reverting d0a57d8d and delegating instead to 'TeX-find-macro-end'. (TeX-fold-stop-after-first-required): New folding signature predicate. * latex.el (LaTeX-fold-math-spec-list): Add "signature 0" to each entry, reflecting that it is a macro with no arguments. * doc/auctex.texi (Folding): Document the new feature. * tex-fold.el : (TeX-fold-macro-spec-list): --- doc/auctex.texi | 17 +++++ latex.el | 3 +- tex-fold.el | 165 ++++++++++++++++++++++++++++-------------------- tex.el | 126 +++++++++++++++++++++++------------- 4 files changed, 198 insertions(+), 113 deletions(-) diff --git a/doc/auctex.texi b/doc/auctex.texi index d0d2e41c..eb692f70 100644 --- a/doc/auctex.texi +++ b/doc/auctex.texi @@ -2931,6 +2931,23 @@ as a replacement for the macro. Such functions typically return a string, but may also return the symbol @code{abort} to indicate that the macro should not be folded. +Each specifier may instead be a cons cell @code{(@var{spec} . @var{sig})}, +where @var{spec} is as above and @var{sig} controls how many arguments are +considered part of the macro to fold: +@itemize @bullet +@item +@code{nil}: no limit (default). +@item +Integer @var{n}: stop after @var{n} total arguments. +@item +Cons @code{(@var{p} . @var{q})}: stop after @var{p} optional and +@var{q} required arguments. +@item +Predicate function: called repeatedly with the list of argument blocks +encountered thus far. Returns non-@code{nil} to terminate scanning early. +See the doc string of @code{TeX-find-macro-boundaries} for details. +@end itemize + The placeholder is made by copying the text from the buffer together with its properties, i.e.@: its face as well. If fontification has not happened when this is done (e.g.@: because of lazy font locking) the diff --git a/latex.el b/latex.el index 757172d7..a8ed0127 100644 --- a/latex.el +++ b/latex.el @@ -6729,7 +6729,8 @@ char." "Accents"))) submenu))) (when (and (stringp tex-token) (integerp uchar) noargp) - `(,(char-to-string uchar) (,tex-token))))) + ;; Each of these macros accepts 0 total arguments. + `((,(char-to-string uchar) . 0) (,tex-token))))) `((nil "to" "" 8594) (nil "gets" "" 8592) ,@LaTeX-math-default))) diff --git a/tex-fold.el b/tex-fold.el index 5ff9a6b1..775381e3 100644 --- a/tex-fold.el +++ b/tex-fold.el @@ -72,65 +72,86 @@ macros, `math' for math macros and `comment' for comments." (const :tag "Math Macros" math) (const :tag "Comments" comment))) +(defconst TeX-fold--spec-type + '(choice + (string :tag "Display String") + (integer :tag "Number of argument" :value 1) + (function :tag "Function to execute") + (cons :tag "Spec with signature" + (choice (string :tag "Display String") + (integer :tag "Number of argument" :value 1) + (function :tag "Function to execute")) + (choice (const :tag "No restriction" nil) + (integer :tag "Max total arguments") + (cons :tag "Max optional and required" + (integer :tag "Max optional arguments") + (integer :tag "Max required arguments")) + (function :tag "Predicate function")))) + "Type spec used by TeX-fold defcustoms.") + (defcustom TeX-fold-macro-spec-list - '(("[f]" ("footnote" "marginpar")) - (TeX-fold-cite-display ("cite" "Cite")) - (TeX-fold-textcite-display ("textcite" "Textcite")) - (TeX-fold-parencite-display ("parencite" "Parencite")) - (TeX-fold-footcite-display ("footcite" "footcitetext")) - ("[l]" ("label")) - ("[r]" ("ref" "pageref" "eqref" "footref")) - ("[i]" ("index" "glossary")) - ("[1]:||*" ("item")) - ("..." ("dots")) - ("(C)" ("copyright")) - ("(R)" ("textregistered")) - ("TM" ("texttrademark")) - (TeX-fold-alert-display ("alert")) - (TeX-fold-textcolor-display ("textcolor")) + '((("[f]" . (1 . 1)) ("footnote" "marginpar")) + ((TeX-fold-cite-display . (2 . 1)) ("cite" "Cite")) + ((TeX-fold-textcite-display . (2 . 1)) ("textcite" "Textcite")) + ((TeX-fold-parencite-display . (2 . 1)) ("parencite" "Parencite")) + ((TeX-fold-footcite-display . (2 . 1)) ("footcite" "footcitetext")) + (("[l]" . TeX-fold-stop-after-first-required) ("label")) + (("[r]" . 1) ("ref" "pageref" "eqref" "footref")) + (("[i]" . (1 . 1)) ("index" "glossary")) + (("[1]:||*" . (1 . 0)) ("item")) + (("..." . 0) ("dots")) + (("(C)" . 0) ("copyright")) + (("(R)" . 0) ("textregistered")) + (("TM" . 0) ("texttrademark")) + ((TeX-fold-alert-display . 1) ("alert")) + ((TeX-fold-textcolor-display . (1 . 2)) ("textcolor")) (TeX-fold-begin-display ("begin")) - (TeX-fold-end-display ("end")) + ((TeX-fold-end-display . 1) ("end")) (1 ("part" "chapter" "section" "subsection" "subsubsection" "paragraph" "subparagraph" "part*" "chapter*" "section*" "subsection*" "subsubsection*" - "paragraph*" "subparagraph*" - "emph" "textit" "textsl" "textmd" "textrm" "textsf" "texttt" - "textbf" "textsc" "textup"))) + "paragraph*" "subparagraph*")) + ((1 . (0 . 1)) ("emph" "textit" "textsl" "textmd" "textrm" "textsf" "texttt" + "textbf" "textsc" "textup"))) "List of replacement specifiers and macros to fold. -The first element of each item can be a string, an integer or a -function symbol. The second element is a list of macros to fold -without the leading backslash. - -If the first element is a string, it will be used as a display -replacement for the whole macro. Numbers in braces, brackets, -parens or angle brackets will be replaced by the respective macro -argument. For example \"{1}\" will be replaced by the first -mandatory argument of the macro. One can also define -alternatives within the specifier which are used if an argument -is not found. Alternatives are separated by \"||\". They are -most useful with optional arguments. As an example, the default -specifier for \\item is \"[1]:||*\" which means that if there is -an optional argument, its value is shown followed by a colon. If -there is no optional argument, only an asterisk is used as the -display string. - -If the first element is an integer, the macro will be replaced by -the respective macro argument. - -If the first element is a function symbol, the function will be -called with all mandatory arguments of the macro and the result -of the function call will be used as a replacement for the macro. -Such functions typically return a string, but may also return the -symbol `abort' to indicate that the macro should not be folded. - -Setting this variable does not take effect immediately. Use -Customize or reset the mode." - :type '(repeat (group (choice (string :tag "Display String") - (integer :tag "Number of argument" :value 1) - (function :tag "Function to execute")) +The first element is of the form SPEC or (SPEC . SIG), where SPEC can be +a string, an integer or a function symbol and SIG is described below. +The second element is a list of macros to fold without the leading +backslash. + +If SPEC is a string, it will be used as a display replacement for the +whole macro. Numbers in braces, brackets, parens or angle brackets will +be replaced by the respective macro argument. For example \"{1}\" will +be replaced by the first mandatory argument of the macro. One can also +define alternatives within the specifier which are used if an argument +is not found. Alternatives are separated by \"||\". They are most +useful with optional arguments. As an example, the default specifier +for \\item is \"[1]:||*\" which means that if there is an optional +argument, its value is shown followed by a colon. If there is no +optional argument, only an asterisk is used as the display string. + +If SPEC is an integer, the macro will be replaced by the respective +macro argument. + +If SPEC is a function symbol, the function will be called with all +mandatory arguments of the macro and the result of the function call +will be used as a replacement for the macro. Such functions typically +return a string, but may also return the symbol `abort' to indicate that +the macro should not be folded. + +SIG optionally restricts how many macro arguments are consumed. It +should be of the form required by the SIGNATURE argument of +`TeX-find-macro-boundaries'. For example, if SIGNATURE is an integer n, +then at most n total arguments are consumed, while if it is a cons +cell (p . q), then at most p optional and q required arguments are +allowed. + +Setting this variable does not take effect immediately. Use Customize +or reset the mode." + :type `(repeat (group ,TeX-fold--spec-type (repeat :tag "Macros" (string)))) - :package-version '(auctex . "14.0.8")) + :package-version '(auctex . "14.0.9")) (defvar-local TeX-fold-macro-spec-list-internal nil "Internal list of display strings and macros to fold. @@ -156,9 +177,7 @@ and -fold-env-spec-list.") (defcustom TeX-fold-math-spec-list nil "List of display strings and math macros to fold." - :type '(repeat (group (choice (string :tag "Display String") - (integer :tag "Number of argument" :value 1) - (function :tag "Function to execute")) + :type `(repeat (group ,TeX-fold--spec-type (repeat :tag "Math Macros" (string))))) (defvar-local TeX-fold-math-spec-list-internal nil @@ -440,9 +459,14 @@ for macros and `math' for math macros." (string (char-after (match-end 0))))))) (let* ((item-start (match-beginning 0)) - (display-string-spec (cadr (assoc item-name - fold-list))) - (item-end (TeX-fold-item-end item-start type)) + (spec-sig? (cadr (assoc item-name fold-list))) + ;; spec-sig? is of the form SPEC or (SPEC . SIG). + (display-string-spec (if (consp spec-sig?) + (car spec-sig?) + spec-sig?)) + (sig (when (consp spec-sig?) + (cdr spec-sig?))) + (item-end (TeX-fold-item-end item-start type sig)) (ov (TeX-fold-make-overlay item-start item-end type display-string-spec))) (TeX-fold-hide-item ov)))))))))) @@ -539,7 +563,7 @@ Return non-nil if an item was found and folded, nil otherwise." TeX-fold-math-spec-list-internal) (t TeX-fold-macro-spec-list-internal))) fold-item - (display-string-spec + (spec-sig? (or (catch 'found (while fold-list (setq fold-item (car fold-list)) @@ -552,7 +576,13 @@ Return non-nil if an item was found and folded, nil otherwise." (if (eq type 'env) TeX-fold-unspec-env-display-string TeX-fold-unspec-macro-display-string)))) - (item-end (TeX-fold-item-end item-start type)) + ;; spec-sig? is of the form SPEC or (SPEC . SIG). + (display-string-spec (if (consp spec-sig?) + (car spec-sig?) + spec-sig?)) + (sig (when (consp spec-sig?) + (cdr spec-sig?))) + (item-end (TeX-fold-item-end item-start type sig)) (ov (TeX-fold-make-overlay item-start item-end type display-string-spec))) (TeX-fold-hide-item ov)))))) @@ -907,10 +937,12 @@ display property." (overlay-put ov 'display display-string)) ov)) -(defun TeX-fold-item-end (start type) +(defun TeX-fold-item-end (start type &optional signature) "Return the end of an item of type TYPE starting at START. TYPE can be either `env' for environments, `macro' for macros or -`math' for math macros." +`math' for math macros. +Optional SIGNATURE, as in `TeX-find-macro-boundaries', restricts the +allowed arguments of LaTeX macros." (save-excursion (cond ((and (eq type 'env) (eq major-mode 'ConTeXt-mode)) @@ -926,15 +958,9 @@ TYPE can be either `env' for environments, `macro' for macros or (goto-char (1+ start)) (LaTeX-find-matching-end) (point)) - ((eq type 'math) - (goto-char (1+ start)) - (if (zerop (skip-chars-forward "A-Za-z@")) - (forward-char) - (skip-chars-forward "*")) - (point)) (t (goto-char start) - (TeX-find-macro-end))))) + (TeX-find-macro-end signature))))) (defun TeX-fold-overfull-p (ov-start ov-end display-string) "Return t if an overfull line will result after adding an overlay. @@ -1095,6 +1121,9 @@ breaks will be replaced by spaces." (dolist (ov overlays) (TeX-fold-hide-item ov))))) +(defun TeX-fold-stop-after-first-required (args) + "Return nil when final element of ARGS starts with \"{\"." + (and args (string-prefix-p "{" (car (last args))))) ;;; Removal diff --git a/tex.el b/tex.el index 18438a81..cbd0bef1 100644 --- a/tex.el +++ b/tex.el @@ -5790,11 +5790,23 @@ If LIMIT is non-nil, do not search further up than this position in the buffer." (TeX-find-balanced-brace -1 depth limit)) -(defun TeX-find-macro-boundaries (&optional lower-bound) +(defun TeX-find-macro-boundaries (&optional lower-bound signature) "Return a cons containing the start and end of a macro. If LOWER-BOUND is given, do not search backward further than this point in buffer. Arguments enclosed in brackets or braces are -considered part of the macro." +considered part of the macro. + +If SIGNATURE is given, restrict the total number of arguments. If +SIGNATURE is an integer N, allow at most N total arguments. If +SIGNATURE is a cons cell (P . Q), allow at most P optional and Q +required arguments. + +Finally, SIGNATURE may be a function, called before each new argument is +consumed with a single list argument consisting of the argument blocks +encountered thus far. For example, with point before +\"\\begin{equation}\", it is called first with the empty list () and +then with the single element list (\"{equation}\"). If SIGNATURE +returns non-nil, then no further macro arguments are consumed." ;; FIXME: Pay attention to `texmathp-allow-detached-args' and ;; `reftex-allow-detached-macro-args'. ;; Should we handle cases like \"{o} and \\[3mm] (that is, a macro @@ -5839,16 +5851,17 @@ considered part of the macro." ;; Search forward for the end of the macro. (when start-point (save-excursion - (goto-char (TeX-find-macro-end-helper start-point)) + (goto-char (TeX-find-macro-end-helper start-point signature)) (if (< orig-point (point)) (cons start-point (point)) nil)))))) -(defun TeX-find-macro-end-helper (start) +(defun TeX-find-macro-end-helper (start &optional signature) "Find the end of a macro given its START. START is the position just before the starting token of the macro. If the macro is followed by square brackets or curly braces, -those will be considered part of it." +those will be considered part of it. SIGNATURE, as in +`TeX-find-macro-boundaries', restricts how many arguments are allowed." (save-excursion (save-match-data (catch 'found @@ -5856,43 +5869,67 @@ those will be considered part of it." (if (zerop (skip-chars-forward "A-Za-z@")) (forward-char) (skip-chars-forward "*")) - (while (not (eobp)) - (cond - ;; Skip over pairs of square brackets - ((or (looking-at "[ \t]*\n?[ \t]*\\(\\[\\)") ; Be conservative: Consider + (let* ((max-tot (and (integerp signature) signature)) + (max-opt (and (consp signature) (car signature))) + (max-req (and (consp signature) (cdr signature))) + (num-opt 0) + (num-req 0) + (sig-pred (when (functionp signature) signature)) + last-arg-start last-args) + (while (not (eobp)) + (when (or (and max-tot (>= (+ num-opt num-req) max-tot)) + (and sig-pred + (progn + (when last-arg-start + (let ((arg (buffer-substring-no-properties + last-arg-start (point)))) + (setq last-args (nconc last-args (list arg))))) + (funcall sig-pred last-args)))) + (throw 'found (point))) + (cond + ;; Skip over pairs of square brackets + ((or (looking-at "[ \t]*\n?[ \t]*\\(\\[\\)") ; Be conservative: Consider ; only consecutive lines. - (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp)) - (save-excursion - (forward-line 1) - (looking-at "[ \t]*\\(\\[\\)")))) - (goto-char (match-beginning 1)) - ;; Imitate `font-latex-find-matching-close', motivated by - ;; examples like \begin{enumerate}[a{]}]. - (let ((syntax (TeX-search-syntax-table ?\[ ?\])) - (parse-sexp-ignore-comments - (not (derived-mode-p 'docTeX-mode)))) - (modify-syntax-entry ?\{ "|" syntax) - (modify-syntax-entry ?\} "|" syntax) - (modify-syntax-entry ?\\ "/" syntax) - (condition-case nil - (with-syntax-table syntax - (forward-sexp)) - (scan-error (throw 'found (point)))))) - ;; Skip over pairs of curly braces - ((or (looking-at "[ \t]*\n?[ \t]*{") ; Be conservative: Consider + (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp)) + (save-excursion + (forward-line 1) + (looking-at "[ \t]*\\(\\[\\)")))) + (when (and max-opt (>= num-opt max-opt)) + (throw 'found (point))) + (cl-incf num-opt) + (goto-char (match-beginning 1)) + (setq last-arg-start (point)) + ;; Imitate `font-latex-find-matching-close', motivated by + ;; examples like \begin{enumerate}[a{]}]. + (let ((syntax (TeX-search-syntax-table ?\[ ?\])) + (parse-sexp-ignore-comments + (not (derived-mode-p 'docTeX-mode)))) + (modify-syntax-entry ?\{ "|" syntax) + (modify-syntax-entry ?\} "|" syntax) + (modify-syntax-entry ?\\ "/" syntax) + (condition-case nil + (with-syntax-table syntax + (forward-sexp)) + (scan-error (throw 'found (point)))))) + ;; Skip over pairs of curly braces + ((or (looking-at "[ \t]*\n?[ \t]*{") ; Be conservative: Consider ; only consecutive lines. - (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp)) - (save-excursion - (forward-line 1) - (looking-at "[ \t]*{")))) - (goto-char (match-end 0)) - (goto-char (or (TeX-find-closing-brace) - ;; If we cannot find a regular end, use the - ;; next whitespace. - (save-excursion (skip-chars-forward "^ \t\n") - (point))))) - (t - (throw 'found (point))))) + (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp)) + (save-excursion + (forward-line 1) + (looking-at "[ \t]*{")))) + (when (and max-req (>= num-req max-req)) + (throw 'found (point))) + (cl-incf num-req) + (goto-char (match-end 0)) + (setq last-arg-start (1- (point))) + (goto-char (or (TeX-find-closing-brace) + ;; If we cannot find a regular end, use the + ;; next whitespace. + (save-excursion (skip-chars-forward "^ \t\n") + (point))))) + (t + (throw 'found (point)))))) ;; Make sure that this function does not return nil, even ;; when the above `while' loop is totally skipped. (bug#35638) (throw 'found (point)))))) @@ -5904,11 +5941,12 @@ in buffer. Arguments enclosed in brackets or braces are considered part of the macro." (car (TeX-find-macro-boundaries limit))) -(defun TeX-find-macro-end () +(defun TeX-find-macro-end (&optional signature) "Return the end of a macro. -Arguments enclosed in brackets or braces are considered part of -the macro." - (cdr (TeX-find-macro-boundaries))) +Arguments enclosed in brackets or braces are considered part of the +macro. SIGNATURE, as in `TeX-find-macro-boundaries', restricts how many +arguments are allowed." + (cdr (TeX-find-macro-boundaries nil signature))) (defun TeX-search-forward-unescaped (string &optional bound noerror) "Search forward from point for unescaped STRING. -- 2.39.3 (Apple Git-145) --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 05 04:40:55 2025 Received: (at 78693) by debbugs.gnu.org; 5 Aug 2025 08:40:55 +0000 Received: from localhost ([127.0.0.1]:53646 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ujDE7-0005wu-1a for submit@debbugs.gnu.org; Tue, 05 Aug 2025 04:40:55 -0400 Received: from smtp1a.inetd.co.jp ([210.129.88.11]:48028) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ujDE1-0005wT-He for 78693@debbugs.gnu.org; Tue, 05 Aug 2025 04:40:52 -0400 Received: from localhost (42-144-37-89.rev.home.ne.jp [42.144.37.89]) by smtp1a.inetd.co.jp (Postfix) with ESMTPSA id E42FF5C; Tue, 5 Aug 2025 17:40:44 +0900 (JST) From: Ikumi Keita To: "Paul D. Nelson" Subject: Re: bug#78693: 14.0.9; Folding of math macros with a function spec is broken In-reply-to: References: <87bjr3nb8j.fsf@mailbox.org> Comments: In-reply-to "Paul D. Nelson" message dated "Sun, 03 Aug 2025 15:32:13 +0200." X-Mailer: MH-E 8.6+git; nmh 1.8; Emacs 30.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <36294.1754383244.1@localhost> Date: Tue, 05 Aug 2025 17:40:44 +0900 Message-ID: <36297.1754383244@localhost> X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org, Rahguzar X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi Paul, >>>>> "Paul D. Nelson" writes: > Thanks Raghuzar. Attaching an updated patch rebased to master. Since > it's a non-local change, I figure I'll wait for Arash or Ikumi to take a > quick sniff, then we can push and close. I have only limited time to have look at your proposal, sorry. Here is a very minor point I can say: (defcustom TeX-fold-macro-spec-list [...] - :package-version '(auctex . "14.0.8")) + :package-version '(auctex . "14.0.9")) The version number should be corrected since 14.1.0 is already released. Regards, Ikumi Keita #StandWithUkraine #StopWarInUkraine #Gaza #StopMassiveKilling #CeasefireNOW From debbugs-submit-bounces@debbugs.gnu.org Wed Sep 03 08:07:16 2025 Received: (at 78693) by debbugs.gnu.org; 3 Sep 2025 12:07:16 +0000 Received: from localhost ([127.0.0.1]:39081 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1utmGi-0005lX-0o for submit@debbugs.gnu.org; Wed, 03 Sep 2025 08:07:16 -0400 Received: from mout-p-201.mailbox.org ([80.241.56.171]:59554) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1utmGe-0005lI-Ia for 78693@debbugs.gnu.org; Wed, 03 Sep 2025 08:07:14 -0400 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4cH1Yz1nLyz9tWv; Wed, 3 Sep 2025 14:07:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1756901223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=TtMMZJp/Y1im31+aeNZESmMQHWmrM1qi9o2o3fYoZSg=; b=I90ih8lv28Ae5eTuCXkCFfRG9t1o1V0iApJRClLIZuti5Oa0xAsPr/SeIHhHZOb+iNbFiV cZ+/o4uY++4BSF3SZrGqiE3EW/+UIHBfUXINBGZ/MY80rXlhUGsidfGXjbHDK7Gq5iOosQ gofd8UKu1R06gcfHNK0kjvYDQGAfB/UuDxCexG8pRjbRyEkil9klij/F5EiJVeIAgsUYC/ LrZz8NuvZEBReb96kOhqtdDze74nYzJ+0UMNI/7Jf2cfeaLSWUslVmjXZustkVb7ni5sLq ZzPieDv5GnD0yuWtrfkXqYtQcckeDyDUbzxfZ/RVTAyHnwfvEtPXe2AhvDXWOA== From: Rahguzar To: "Paul D. Nelson" Subject: Re: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: (Paul D. Nelson's message of "Sun, 03 Aug 2025 15:32:13 +0200") References: Date: Wed, 03 Sep 2025 17:06:58 +0500 Message-ID: <87ecsnbuzh.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: text/plain X-MBO-RS-META: 9nqnszwmkkaybomaoaagijj4tsyo1zpa X-MBO-RS-ID: 1a087ab7584ffef2b02 X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Gentle ping, I hope the patch can be merged soon. Rahguzar "Paul D. Nelson" writes: > Rahguzar writes: > >> Hi Paul, >> >> "Paul D. Nelson" writes: >> >>> I can't think of any other edge cases. I think this patch is now ready >>> to ship, although I'd welcome any feedback. >> >> I also think that it is ready to ship. Thanks for all your work on this. > > Thanks Raghuzar. Attaching an updated patch rebased to master. Since > it's a non-local change, I figure I'll wait for Arash or Ikumi to take a > quick sniff, then we can push and close. > > Paul > > [2. text/x-patch; 0001-Add-signature-support-for-macro-folding.patch]... From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 18 04:03:44 2025 Received: (at 78693) by debbugs.gnu.org; 18 Sep 2025 08:03:44 +0000 Received: from localhost ([127.0.0.1]:59904 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uz9cF-0004v8-6h for submit@debbugs.gnu.org; Thu, 18 Sep 2025 04:03:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51852) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uz9cB-0004ul-Uq for 78693@debbugs.gnu.org; Thu, 18 Sep 2025 04:03:40 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uz9c6-0005qt-Ku; Thu, 18 Sep 2025 04:03:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=JISu3NPR1ARj3yjDEiWtVcPkewksIwqmcoJ0BUDG9cM=; b=dhrqfFAsuO1tngRUtecw YU4yQpnNIu62ARvAQafrFC/gpeCyWn3gvmUB/LHZLSlxDfgvEyflEpP4uLax/+WIQ6BPB4goJyoPF jTp0UoCg/DRIyLySK/ccLqxwsp2oH/UPvPQgjeP+uT0eD030fW4LjQmsXPRTa5aPwklLR7ZGp1/fq Lej0a4zawzxgb5LyBQu6vqDGXLNpprJThEJHPBeWkdVr8ZSNh5wts2AkhBJOJnub0b9T8Gr3jqi6n 7hjJX9yCVzyfg6SsH5eE6aYy8yuWlXnfc9RyLp1/IjXH5O3Trljh8iycywoKxJUeDk6/g5I66QEXb 4h+wpSsuMq8zHg==; From: Arash Esbati To: "Paul D. Nelson" Subject: Re: bug#78693: 14.0.9; Folding of math macros with a function spec is broken In-Reply-To: References: <87bjr3nb8j.fsf@mailbox.org> Date: Thu, 18 Sep 2025 10:03:29 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 78693 Cc: 78693@debbugs.gnu.org, Rahguzar X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi Paul, "Paul D. Nelson" writes: > Thanks Raghuzar. Attaching an updated patch rebased to master. Since > it's a non-local change, I figure I'll wait for Arash or Ikumi to take a > quick sniff, then we can push and close. Thanks for this and sorry for my late response. I have some minor comments (see below). I trust your patch works. > diff --git a/doc/auctex.texi b/doc/auctex.texi > index d0d2e41c..eb692f70 100644 > --- a/doc/auctex.texi > +++ b/doc/auctex.texi > @@ -2931,6 +2931,23 @@ as a replacement for the macro. Such functions typically return a string, > but may also return the symbol @code{abort} to indicate that the macro > should not be folded. > > +Each specifier may instead be a cons cell @code{(@var{spec} . @var{sig})}, > +where @var{spec} is as above and @var{sig} controls how many arguments are > +considered part of the macro to fold: > +@itemize @bullet > +@item > +@code{nil}: no limit (default). > +@item > +Integer @var{n}: stop after @var{n} total arguments. > +@item > +Cons @code{(@var{p} . @var{q})}: stop after @var{p} optional and > +@var{q} required arguments. I think the LaTeX parlance is "mandatory argument". > +@item > +Predicate function: called repeatedly with the list of argument blocks > +encountered thus far. Returns non-@code{nil} to terminate scanning early. > +See the doc string of @code{TeX-find-macro-boundaries} for details. > +@end itemize > [...] > + > (defcustom TeX-fold-macro-spec-list > - '(("[f]" ("footnote" "marginpar")) > - (TeX-fold-cite-display ("cite" "Cite")) > - (TeX-fold-textcite-display ("textcite" "Textcite")) > - (TeX-fold-parencite-display ("parencite" "Parencite")) > - (TeX-fold-footcite-display ("footcite" "footcitetext")) > - ("[l]" ("label")) > - ("[r]" ("ref" "pageref" "eqref" "footref")) > - ("[i]" ("index" "glossary")) > - ("[1]:||*" ("item")) > - ("..." ("dots")) > - ("(C)" ("copyright")) > - ("(R)" ("textregistered")) > - ("TM" ("texttrademark")) > - (TeX-fold-alert-display ("alert")) > - (TeX-fold-textcolor-display ("textcolor")) > + '((("[f]" . (1 . 1)) ("footnote" "marginpar")) > + ((TeX-fold-cite-display . (2 . 1)) ("cite" "Cite")) > + ((TeX-fold-textcite-display . (2 . 1)) ("textcite" "Textcite")) > + ((TeX-fold-parencite-display . (2 . 1)) ("parencite" "Parencite")) > + ((TeX-fold-footcite-display . (2 . 1)) ("footcite" "footcitetext")) > + (("[l]" . TeX-fold-stop-after-first-required) ("label")) > + (("[r]" . 1) ("ref" "pageref" "eqref" "footref")) > + (("[i]" . (1 . 1)) ("index" "glossary")) > + (("[1]:||*" . (1 . 0)) ("item")) > + (("..." . 0) ("dots")) > + (("(C)" . 0) ("copyright")) > + (("(R)" . 0) ("textregistered")) > + (("TM" . 0) ("texttrademark")) > + ((TeX-fold-alert-display . 1) ("alert")) > + ((TeX-fold-textcolor-display . (1 . 2)) ("textcolor")) > (TeX-fold-begin-display ("begin")) > - (TeX-fold-end-display ("end")) > + ((TeX-fold-end-display . 1) ("end")) > (1 ("part" "chapter" "section" "subsection" "subsubsection" > "paragraph" "subparagraph" > "part*" "chapter*" "section*" "subsection*" "subsubsection*" > - "paragraph*" "subparagraph*" > - "emph" "textit" "textsl" "textmd" "textrm" "textsf" "texttt" > - "textbf" "textsc" "textup"))) > + "paragraph*" "subparagraph*")) > + ((1 . (0 . 1)) ("emph" "textit" "textsl" "textmd" "textrm" "textsf" "texttt" > + "textbf" "textsc" "textup"))) > "List of replacement specifiers and macros to fold. > > -The first element of each item can be a string, an integer or a > -function symbol. The second element is a list of macros to fold > -without the leading backslash. > - > -If the first element is a string, it will be used as a display > -replacement for the whole macro. Numbers in braces, brackets, > -parens or angle brackets will be replaced by the respective macro > -argument. For example \"{1}\" will be replaced by the first > -mandatory argument of the macro. One can also define > -alternatives within the specifier which are used if an argument > -is not found. Alternatives are separated by \"||\". They are > -most useful with optional arguments. As an example, the default > -specifier for \\item is \"[1]:||*\" which means that if there is > -an optional argument, its value is shown followed by a colon. If > -there is no optional argument, only an asterisk is used as the > -display string. > - > -If the first element is an integer, the macro will be replaced by > -the respective macro argument. > - > -If the first element is a function symbol, the function will be > -called with all mandatory arguments of the macro and the result > -of the function call will be used as a replacement for the macro. > -Such functions typically return a string, but may also return the > -symbol `abort' to indicate that the macro should not be folded. > - > -Setting this variable does not take effect immediately. Use > -Customize or reset the mode." > - :type '(repeat (group (choice (string :tag "Display String") > - (integer :tag "Number of argument" :value 1) > - (function :tag "Function to execute")) > +The first element is of the form SPEC or (SPEC . SIG), where SPEC can be > +a string, an integer or a function symbol and SIG is described below. > +The second element is a list of macros to fold without the leading > +backslash. > + > +If SPEC is a string, it will be used as a display replacement for the > +whole macro. Numbers in braces, brackets, parens or angle brackets will > +be replaced by the respective macro argument. For example \"{1}\" will > +be replaced by the first mandatory argument of the macro. One can also > +define alternatives within the specifier which are used if an argument > +is not found. Alternatives are separated by \"||\". They are most > +useful with optional arguments. As an example, the default specifier > +for \\item is \"[1]:||*\" which means that if there is an optional > +argument, its value is shown followed by a colon. If there is no > +optional argument, only an asterisk is used as the display string. > + > +If SPEC is an integer, the macro will be replaced by the respective > +macro argument. > + > +If SPEC is a function symbol, the function will be called with all > +mandatory arguments of the macro and the result of the function call > +will be used as a replacement for the macro. Such functions typically > +return a string, but may also return the symbol `abort' to indicate that > +the macro should not be folded. > + > +SIG optionally restricts how many macro arguments are consumed. It > +should be of the form required by the SIGNATURE argument of > +`TeX-find-macro-boundaries'. For example, if SIGNATURE is an integer n, > +then at most n total arguments are consumed, while if it is a cons > +cell (p . q), then at most p optional and q required arguments are ^^^^^^^^ mandatory > +allowed. > + > +Setting this variable does not take effect immediately. Use Customize > +or reset the mode." > + :type `(repeat (group ,TeX-fold--spec-type > (repeat :tag "Macros" (string)))) > - :package-version '(auctex . "14.0.8")) > + :package-version '(auctex . "14.0.9")) :package-version '(auctex . "14.1.1")) > [...] > diff --git a/tex.el b/tex.el > index 18438a81..cbd0bef1 100644 > --- a/tex.el > +++ b/tex.el > @@ -5790,11 +5790,23 @@ If LIMIT is non-nil, do not search further up than this position > in the buffer." > (TeX-find-balanced-brace -1 depth limit)) > > -(defun TeX-find-macro-boundaries (&optional lower-bound) > +(defun TeX-find-macro-boundaries (&optional lower-bound signature) > "Return a cons containing the start and end of a macro. > If LOWER-BOUND is given, do not search backward further than this > point in buffer. Arguments enclosed in brackets or braces are > -considered part of the macro." > +considered part of the macro. > + > +If SIGNATURE is given, restrict the total number of arguments. If > +SIGNATURE is an integer N, allow at most N total arguments. If > +SIGNATURE is a cons cell (P . Q), allow at most P optional and Q > +required arguments. mandatory HTH. Best, Arash