unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#35052: [PATCH] `tex-current-defun-name' matches the wrong title
@ 2019-03-30 20:30 Arash Esbati
  2019-03-31 14:31 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Arash Esbati @ 2019-03-30 20:30 UTC (permalink / raw)
  To: 35052

[-- 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#35052: [PATCH] `tex-current-defun-name' matches the wrong title
  2019-03-30 20:30 bug#35052: [PATCH] `tex-current-defun-name' matches the wrong title Arash Esbati
@ 2019-03-31 14:31 ` Eli Zaretskii
  2019-03-31 20:29   ` Arash Esbati
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2019-03-31 14:31 UTC (permalink / raw)
  To: Arash Esbati; +Cc: 35052

> From: Arash Esbati <arash@gnu.org>
> 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.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#35052: [PATCH] `tex-current-defun-name' matches the wrong title
  2019-03-31 14:31 ` Eli Zaretskii
@ 2019-03-31 20:29   ` Arash Esbati
  2019-04-01  4:09     ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Arash Esbati @ 2019-03-31 20:29 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 35052

Eli Zaretskii <eliz@gnu.org> 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





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#35052: [PATCH] `tex-current-defun-name' matches the wrong title
  2019-03-31 20:29   ` Arash Esbati
@ 2019-04-01  4:09     ` Eli Zaretskii
  2019-04-01 19:21       ` Arash Esbati
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2019-04-01  4:09 UTC (permalink / raw)
  To: Arash Esbati; +Cc: 35052

> From: Arash Esbati <arash@gnu.org>
> 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.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#35052: [PATCH] `tex-current-defun-name' matches the wrong title
  2019-04-01  4:09     ` Eli Zaretskii
@ 2019-04-01 19:21       ` Arash Esbati
  0 siblings, 0 replies; 5+ messages in thread
From: Arash Esbati @ 2019-04-01 19:21 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 35052-done

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Arash Esbati <arash@gnu.org>
>> 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





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-04-01 19:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-30 20:30 bug#35052: [PATCH] `tex-current-defun-name' matches the wrong title Arash Esbati
2019-03-31 14:31 ` Eli Zaretskii
2019-03-31 20:29   ` Arash Esbati
2019-04-01  4:09     ` Eli Zaretskii
2019-04-01 19:21       ` Arash Esbati

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).