From unknown Sun Aug 17 01:22:56 2025 X-Loop: help-debbugs@gnu.org Subject: bug#35052: [PATCH] `tex-current-defun-name' matches the wrong title Resent-From: Arash Esbati Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 30 Mar 2019 20:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 35052 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 35052@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.155397789510984 (code B ref -1); Sat, 30 Mar 2019 20:32:02 +0000 Received: (at submit) by debbugs.gnu.org; 30 Mar 2019 20:31:35 +0000 Received: from localhost ([127.0.0.1]:37603 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hAKda-0002r5-MC for submit@debbugs.gnu.org; Sat, 30 Mar 2019 16:31:34 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47065) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hAKdZ-0002qu-Bo for submit@debbugs.gnu.org; Sat, 30 Mar 2019 16:31:33 -0400 Received: from lists.gnu.org ([209.51.188.17]:48813) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hAKdU-0002cw-6k for submit@debbugs.gnu.org; Sat, 30 Mar 2019 16:31:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hAKdT-00074J-2a for bug-gnu-emacs@gnu.org; Sat, 30 Mar 2019 16:31:28 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_20, URIBL_BLOCKED autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:470:142:3::e]:46846) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hAKdS-0002cW-P3 for bug-gnu-emacs@gnu.org; Sat, 30 Mar 2019 16:31:27 -0400 Received: from p4fe3e1a1.dip0.t-ipconnect.de ([79.227.225.161]:51274 helo=MUTANT) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1hAKdS-0004kJ-CP for bug-gnu-emacs@gnu.org; Sat, 30 Mar 2019 16:31:26 -0400 From: Arash Esbati Date: Sat, 30 Mar 2019 21:30:02 +0100 Message-ID: <86h8bk85rp.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Spam-Score: 0.0 (/) 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 all, please consider this LaTeX file with the latex-mode provided by Emacs (not AUCTeX). --8<---------------cut here---------------start------------->8--- \documentclass{article} \begin{document} \section{Emacs} \subsection*[Emacs is the extensible, customizable, self-documenting real-time display editor]{Emacs is the extensible, customizable, self-documenting real-time display editor} \end{document} --8<---------------cut here---------------end--------------->8--- In that buffer, eval (goto-char 68) and hit `C-x 4 a'. Emacs enters the first section (section{Emacs}) into the ChangeLog buffer. I think `tex-current-defun-name' could be more cautious like `lisp-current-defun-name' is. A possible patch is attached. I will add something like this also to AUCTeX since it currently doesn't set `add-log-current-defun-function' at all. Any comments welcome. Best, Arash --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Match-the-correct-sectioning-command.patch >From 97394551775c27e3de77cd9f07b319cefb72ccad Mon Sep 17 00:00:00 2001 From: Arash Esbati Date: Sat, 30 Mar 2019 21:05:06 +0100 Subject: [PATCH] Match the correct sectioning command * lisp/textmodes/tex-mode.el (tex-current-defun-name): Select the current sectioning command when point is on the command itself. --- lisp/textmodes/tex-mode.el | 42 +++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index 9c91d27b94..88134603b9 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el @@ -442,13 +442,41 @@ latex-outline-level (defun tex-current-defun-name () "Return the name of the TeX section/paragraph/chapter at point, or nil." (save-excursion - (when (re-search-backward - "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" - nil t) - (goto-char (match-beginning 0)) - (buffer-substring-no-properties - (1+ (point)) ; without initial backslash - (line-end-position))))) + (let (s1 e1 s2 e2) + ;; If we are now precisely at the beginning of a sectioning + ;; command, move forward and make sure `re-search-backward' + ;; finds this one rather than the previous one: + (or (eobp) (progn + (when (looking-at-p "\\\\") + (forward-char)) + (unless (eolp) + (forward-sexp)))) + (when (re-search-backward + "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)\\*?" + nil t) + ;; Skip over the backslash: + (setq s1 (1+ (point))) + ;; Skip over the sectioning command, incl. the *: + (setq e1 (goto-char (match-end 0))) + ;; Skip over the optional argument, if any: + (when (looking-at-p "[ \t]*\\[") + (forward-sexp)) + ;; Skip over any chars until the mandatory argument: + (skip-chars-forward "^{") + ;; Remember the points for the mandatory argument: + (setq s2 (point)) + (setq e2 (progn (forward-sexp) + (point))) + ;; Now pick the content: For one-line title, return it + ;; incl. the closing brace. For multi-line, return the first + ;; line of the mandatory argument incl. ellipsis and a brace + (concat + (buffer-substring-no-properties s1 e1) + (buffer-substring-no-properties + (goto-char s2) + (min (line-end-position) e2)) + (when (> e2 (line-end-position)) + (concat "..." "}"))))))) ;;;; ;;;; Font-Lock support -- 2.21.0 --=-=-=-- From unknown Sun Aug 17 01:22:56 2025 X-Loop: help-debbugs@gnu.org Subject: bug#35052: [PATCH] `tex-current-defun-name' matches the wrong title Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 31 Mar 2019 14:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35052 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Arash Esbati Cc: 35052@debbugs.gnu.org Received: via spool by 35052-submit@debbugs.gnu.org id=B35052.155404269330155 (code B ref 35052); Sun, 31 Mar 2019 14:32:02 +0000 Received: (at 35052) by debbugs.gnu.org; 31 Mar 2019 14:31:33 +0000 Received: from localhost ([127.0.0.1]:38381 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hAbUi-0007qI-Pe for submit@debbugs.gnu.org; Sun, 31 Mar 2019 10:31:33 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34901) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hAbUg-0007q1-Pw for 35052@debbugs.gnu.org; Sun, 31 Mar 2019 10:31:31 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:56674) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hAbUa-0003jT-MZ for 35052@debbugs.gnu.org; Sun, 31 Mar 2019 10:31:25 -0400 Received: from [176.228.60.248] (port=4377 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hAbUZ-0001Uh-9h; Sun, 31 Mar 2019 10:31:23 -0400 Date: Sun, 31 Mar 2019 17:31:31 +0300 Message-Id: <834l7ji08s.fsf@gnu.org> From: Eli Zaretskii In-reply-to: <86h8bk85rp.fsf@gnu.org> (message from Arash Esbati on Sat, 30 Mar 2019 21:30:02 +0100) References: <86h8bk85rp.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: 0.0 (/) 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 (-) > From: Arash Esbati > Date: Sat, 30 Mar 2019 21:30:02 +0100 > > --8<---------------cut here---------------start------------->8--- > \documentclass{article} > > \begin{document} > > \section{Emacs} > > \subsection*[Emacs is the extensible, customizable, self-documenting > real-time display editor]{Emacs is the extensible, customizable, > self-documenting real-time display editor} > > \end{document} > --8<---------------cut here---------------end--------------->8--- > > In that buffer, eval (goto-char 68) and hit `C-x 4 a'. Emacs enters the > first section (section{Emacs}) into the ChangeLog buffer. I think > `tex-current-defun-name' could be more cautious like > `lisp-current-defun-name' is. A possible patch is attached. I don't use TeX mode, so I don't really mind, but please note that the current behavior is consistent with Texinfo mode's equivalent: it also detects only the @node in which point is located. From unknown Sun Aug 17 01:22:56 2025 X-Loop: help-debbugs@gnu.org Subject: bug#35052: [PATCH] `tex-current-defun-name' matches the wrong title Resent-From: Arash Esbati Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 31 Mar 2019 20:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35052 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Eli Zaretskii Cc: 35052@debbugs.gnu.org Received: via spool by 35052-submit@debbugs.gnu.org id=B35052.155406430314671 (code B ref 35052); Sun, 31 Mar 2019 20:32:02 +0000 Received: (at 35052) by debbugs.gnu.org; 31 Mar 2019 20:31:43 +0000 Received: from localhost ([127.0.0.1]:38522 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hAh7H-0003oZ-Iq for submit@debbugs.gnu.org; Sun, 31 Mar 2019 16:31:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:57606) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hAh7G-0003oM-Gz for 35052@debbugs.gnu.org; Sun, 31 Mar 2019 16:31:42 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:33241) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hAh7B-0001us-87 for 35052@debbugs.gnu.org; Sun, 31 Mar 2019 16:31:37 -0400 Received: from p4fe3e65b.dip0.t-ipconnect.de ([79.227.230.91]:50384 helo=MUTANT) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1hAh7A-0004dB-DR; Sun, 31 Mar 2019 16:31:36 -0400 From: Arash Esbati References: <86h8bk85rp.fsf@gnu.org> <834l7ji08s.fsf@gnu.org> Date: Sun, 31 Mar 2019 22:29:43 +0200 In-Reply-To: <834l7ji08s.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 31 Mar 2019 17:31:31 +0300") Message-ID: <86o95q3hzc.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: 0.0 (/) 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 (-) Eli Zaretskii writes: > I don't use TeX mode, so I don't really mind, but please note that the > current behavior is consistent with Texinfo mode's equivalent: it also > detects only the @node in which point is located. Thanks for your response. You are right, the behavior in Texinfo mode is the same, but I think the better implementation is in `lisp-current-defun-name' which I tried to follow. I don't use TeX mode either, so I'm fine if you say "keep it as is" and we close this one. While we're at it: "bug#34790: LaTeX mode \href bug" is actually an AUCTeX issue which is already resolved. I didn't want to close it as I'm not a regular in this list (not even sure if I could do it). Can you please close that report as well? TIA. Best, Arash From unknown Sun Aug 17 01:22:56 2025 X-Loop: help-debbugs@gnu.org Subject: bug#35052: [PATCH] `tex-current-defun-name' matches the wrong title Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 01 Apr 2019 04:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35052 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Arash Esbati Cc: 35052@debbugs.gnu.org Received: via spool by 35052-submit@debbugs.gnu.org id=B35052.155409176332019 (code B ref 35052); Mon, 01 Apr 2019 04:10:02 +0000 Received: (at 35052) by debbugs.gnu.org; 1 Apr 2019 04:09:23 +0000 Received: from localhost ([127.0.0.1]:38739 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hAoGB-0008KN-F0 for submit@debbugs.gnu.org; Mon, 01 Apr 2019 00:09:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59670) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hAoGA-0008KB-4c for 35052@debbugs.gnu.org; Mon, 01 Apr 2019 00:09:22 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:39641) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hAoG2-0001Vh-LO for 35052@debbugs.gnu.org; Mon, 01 Apr 2019 00:09:16 -0400 Received: from [176.228.60.248] (port=3263 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hAoFt-0000pU-Qj; Mon, 01 Apr 2019 00:09:06 -0400 Date: Mon, 01 Apr 2019 07:09:14 +0300 Message-Id: <83ftr2gydx.fsf@gnu.org> From: Eli Zaretskii In-reply-to: <86o95q3hzc.fsf@gnu.org> (message from Arash Esbati on Sun, 31 Mar 2019 22:29:43 +0200) References: <86h8bk85rp.fsf@gnu.org> <834l7ji08s.fsf@gnu.org> <86o95q3hzc.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: 0.0 (/) 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 (-) > From: Arash Esbati > Cc: 35052@debbugs.gnu.org > Date: Sun, 31 Mar 2019 22:29:43 +0200 > > While we're at it: "bug#34790: LaTeX mode \href bug" is actually an > AUCTeX issue which is already resolved. I didn't want to close it as > I'm not a regular in this list (not even sure if I could do it). Can > you please close that report as well? TIA. You can always close a bug by sending email to NNNN-done@debbugs.gnu.org, where NNNN is the bug number. From unknown Sun Aug 17 01:22:56 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Arash Esbati Subject: bug#35052: closed (Re: bug#35052: [PATCH] `tex-current-defun-name' matches the wrong title) Message-ID: References: <86o95p4jm1.fsf@gnu.org> <86h8bk85rp.fsf@gnu.org> X-Gnu-PR-Message: they-closed 35052 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 35052@debbugs.gnu.org Date: Mon, 01 Apr 2019 19:23:03 +0000 Content-Type: multipart/mixed; boundary="----------=_1554146583-5696-1" This is a multi-part message in MIME format... ------------=_1554146583-5696-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #35052: [PATCH] `tex-current-defun-name' matches the wrong title which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 35052@debbugs.gnu.org. --=20 35052: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D35052 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1554146583-5696-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 35052-done) by debbugs.gnu.org; 1 Apr 2019 19:22:12 +0000 Received: from localhost ([127.0.0.1]:39908 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hB2VY-0001SO-AZ for submit@debbugs.gnu.org; Mon, 01 Apr 2019 15:22:12 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36314) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hB2VU-0001Ry-JN for 35052-done@debbugs.gnu.org; Mon, 01 Apr 2019 15:22:08 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:52683) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hB2VP-0001RK-Di for 35052-done@debbugs.gnu.org; Mon, 01 Apr 2019 15:22:03 -0400 Received: from p5b326365.dip0.t-ipconnect.de ([91.50.99.101]:52569 helo=MUTANT) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1hB2VO-0002Hi-F1; Mon, 01 Apr 2019 15:22:02 -0400 From: Arash Esbati To: Eli Zaretskii Subject: Re: bug#35052: [PATCH] `tex-current-defun-name' matches the wrong title References: <86h8bk85rp.fsf@gnu.org> <834l7ji08s.fsf@gnu.org> <86o95q3hzc.fsf@gnu.org> <83ftr2gydx.fsf@gnu.org> Date: Mon, 01 Apr 2019 21:21:26 +0200 In-Reply-To: <83ftr2gydx.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 01 Apr 2019 07:09:14 +0300") Message-ID: <86o95p4jm1.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 35052-done Cc: 35052-done@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 (-) Eli Zaretskii writes: >> From: Arash Esbati >> Cc: 35052@debbugs.gnu.org >> Date: Sun, 31 Mar 2019 22:29:43 +0200 >> >> While we're at it: "bug#34790: LaTeX mode \href bug" is actually an >> AUCTeX issue which is already resolved. I didn't want to close it as >> I'm not a regular in this list (not even sure if I could do it). Can >> you please close that report as well? TIA. > > You can always close a bug by sending email to > NNNN-done@debbugs.gnu.org, where NNNN is the bug number. I wasn't sure if *I*'m allowed to that. I've closed #34790 and I'm closing this one as well. Again, thanks for your attention. Best, Arash ------------=_1554146583-5696-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 30 Mar 2019 20:31:35 +0000 Received: from localhost ([127.0.0.1]:37603 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hAKda-0002r5-MC for submit@debbugs.gnu.org; Sat, 30 Mar 2019 16:31:34 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47065) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hAKdZ-0002qu-Bo for submit@debbugs.gnu.org; Sat, 30 Mar 2019 16:31:33 -0400 Received: from lists.gnu.org ([209.51.188.17]:48813) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hAKdU-0002cw-6k for submit@debbugs.gnu.org; Sat, 30 Mar 2019 16:31:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hAKdT-00074J-2a for bug-gnu-emacs@gnu.org; Sat, 30 Mar 2019 16:31:28 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_20, URIBL_BLOCKED autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:470:142:3::e]:46846) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hAKdS-0002cW-P3 for bug-gnu-emacs@gnu.org; Sat, 30 Mar 2019 16:31:27 -0400 Received: from p4fe3e1a1.dip0.t-ipconnect.de ([79.227.225.161]:51274 helo=MUTANT) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1hAKdS-0004kJ-CP for bug-gnu-emacs@gnu.org; Sat, 30 Mar 2019 16:31:26 -0400 From: Arash Esbati To: bug-gnu-emacs@gnu.org Subject: [PATCH] `tex-current-defun-name' matches the wrong title Date: Sat, 30 Mar 2019 21:30:02 +0100 Message-ID: <86h8bk85rp.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: submit 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 all, please consider this LaTeX file with the latex-mode provided by Emacs (not AUCTeX). --8<---------------cut here---------------start------------->8--- \documentclass{article} \begin{document} \section{Emacs} \subsection*[Emacs is the extensible, customizable, self-documenting real-time display editor]{Emacs is the extensible, customizable, self-documenting real-time display editor} \end{document} --8<---------------cut here---------------end--------------->8--- In that buffer, eval (goto-char 68) and hit `C-x 4 a'. Emacs enters the first section (section{Emacs}) into the ChangeLog buffer. I think `tex-current-defun-name' could be more cautious like `lisp-current-defun-name' is. A possible patch is attached. I will add something like this also to AUCTeX since it currently doesn't set `add-log-current-defun-function' at all. Any comments welcome. Best, Arash --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Match-the-correct-sectioning-command.patch >From 97394551775c27e3de77cd9f07b319cefb72ccad Mon Sep 17 00:00:00 2001 From: Arash Esbati Date: Sat, 30 Mar 2019 21:05:06 +0100 Subject: [PATCH] Match the correct sectioning command * lisp/textmodes/tex-mode.el (tex-current-defun-name): Select the current sectioning command when point is on the command itself. --- lisp/textmodes/tex-mode.el | 42 +++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index 9c91d27b94..88134603b9 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el @@ -442,13 +442,41 @@ latex-outline-level (defun tex-current-defun-name () "Return the name of the TeX section/paragraph/chapter at point, or nil." (save-excursion - (when (re-search-backward - "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" - nil t) - (goto-char (match-beginning 0)) - (buffer-substring-no-properties - (1+ (point)) ; without initial backslash - (line-end-position))))) + (let (s1 e1 s2 e2) + ;; If we are now precisely at the beginning of a sectioning + ;; command, move forward and make sure `re-search-backward' + ;; finds this one rather than the previous one: + (or (eobp) (progn + (when (looking-at-p "\\\\") + (forward-char)) + (unless (eolp) + (forward-sexp)))) + (when (re-search-backward + "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)\\*?" + nil t) + ;; Skip over the backslash: + (setq s1 (1+ (point))) + ;; Skip over the sectioning command, incl. the *: + (setq e1 (goto-char (match-end 0))) + ;; Skip over the optional argument, if any: + (when (looking-at-p "[ \t]*\\[") + (forward-sexp)) + ;; Skip over any chars until the mandatory argument: + (skip-chars-forward "^{") + ;; Remember the points for the mandatory argument: + (setq s2 (point)) + (setq e2 (progn (forward-sexp) + (point))) + ;; Now pick the content: For one-line title, return it + ;; incl. the closing brace. For multi-line, return the first + ;; line of the mandatory argument incl. ellipsis and a brace + (concat + (buffer-substring-no-properties s1 e1) + (buffer-substring-no-properties + (goto-char s2) + (min (line-end-position) e2)) + (when (> e2 (line-end-position)) + (concat "..." "}"))))))) ;;;; ;;;; Font-Lock support -- 2.21.0 --=-=-=-- ------------=_1554146583-5696-1--