[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX-devel] Setting `add-log-current-defun-function'

From: Arash Esbati
Subject: [AUCTeX-devel] Setting `add-log-current-defun-function'
Date: Sun, 07 Apr 2019 13:34:45 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50

Hi all,

AUCTeX doesn't have a function to set `add-log-current-defun-function'.
Hence, hitting `C-x 4 a' in .tex file puts only the file name in the
ChangeLog.  I suggest to add something like this to tex.el:

--8<---------------cut here---------------start------------->8---
(defun TeX-current-defun-name ()
  "Return the name of the TeX section/paragraph/chapter at point, or nil."
    (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 "\\\\")
                   (unless (eolp)
      ;; Search backward for sectioning command.  If
      ;; `LaTeX-section-label' is buffer-local, assume that a style
      ;; has changed the value and recalculate the string.  Otherwise
      ;; take the standard one:
      (when (re-search-backward
             (if (local-variable-p 'LaTeX-section-label)
                 (concat (regexp-opt
                          (remove "part" (mapcar #'car LaTeX-section-label)))
             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]*\\[")
        ;; 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)
        ;; 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;
         (buffer-substring-no-properties s1 e1)
          (goto-char s2)
          (min (line-end-position) e2))
         (when (> e2 (line-end-position))
           (concat "..." TeX-grcl)))))))
--8<---------------cut here---------------end--------------->8---
And the activate it in latex.el by adding this to

(setq-local add-log-current-defun-function #'TeX-current-defun-name)

Any comments welcome.

Best, Arash

reply via email to

[Prev in Thread] Current Thread [Next in Thread]