From: Arash Esbati <arash@gnu.org>
To: 35052@debbugs.gnu.org
Subject: bug#35052: [PATCH] `tex-current-defun-name' matches the wrong title
Date: Sat, 30 Mar 2019 21:30:02 +0100 [thread overview]
Message-ID: <86h8bk85rp.fsf@gnu.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 892 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Match-the-correct-sectioning-command.patch --]
[-- Type: text/x-patch, Size: 2640 bytes --]
From 97394551775c27e3de77cd9f07b319cefb72ccad Mon Sep 17 00:00:00 2001
From: Arash Esbati <arash@gnu.org>
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 "..." "}")))))))
\f
;;;;
;;;; Font-Lock support
--
2.21.0
next reply other threads:[~2019-03-30 20:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-30 20:30 Arash Esbati [this message]
2019-03-31 14:31 ` bug#35052: [PATCH] `tex-current-defun-name' matches the wrong title Eli Zaretskii
2019-03-31 20:29 ` Arash Esbati
2019-04-01 4:09 ` Eli Zaretskii
2019-04-01 19:21 ` Arash Esbati
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86h8bk85rp.fsf@gnu.org \
--to=arash@gnu.org \
--cc=35052@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.