From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Arash Esbati Newsgroups: gmane.emacs.bugs Subject: bug#35052: [PATCH] `tex-current-defun-name' matches the wrong title Date: Sat, 30 Mar 2019 21:30:02 +0100 Message-ID: <86h8bk85rp.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="193266"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 To: 35052@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Mar 30 21:32:11 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hAKeB-000o9T-KF for geb-bug-gnu-emacs@m.gmane.org; Sat, 30 Mar 2019 21:32:11 +0100 Original-Received: from localhost ([127.0.0.1]:42258 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hAKeA-0007dj-KU for geb-bug-gnu-emacs@m.gmane.org; Sat, 30 Mar 2019 16:32:10 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:33271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hAKe3-0007Uz-Va for bug-gnu-emacs@gnu.org; Sat, 30 Mar 2019 16:32:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hAKe2-0002m6-Ra for bug-gnu-emacs@gnu.org; Sat, 30 Mar 2019 16:32:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52292) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hAKe2-0002lu-Ky for bug-gnu-emacs@gnu.org; Sat, 30 Mar 2019 16:32:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hAKe2-0002ro-Di for bug-gnu-emacs@gnu.org; Sat, 30 Mar 2019 16:32:02 -0400 X-Loop: help-debbugs@gnu.org 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 X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.155397789510984 (code B ref -1); Sat, 30 Mar 2019 20:32:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 30 Mar 2019 20:31:35 +0000 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:156956 Archived-At: --=-=-= 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 --=-=-=--