Hi Mandar, >>>>> Mandar Mitra <mandar.mi...@gmail.com> writes: > When preparing a presentation using Beamer, I'd like the frame > titles to be listed in imenu, along with section names. I use > the \begin{frame}[optionals]{Frame title here} form, rather than > a separate \frametitle (and would rather not change that habit > if I can help it).
> So I customised TeX-outline-extra to > '(("^\\\\begin{frame}\\(\\[[a-z,]+\\]\\)?" 3)) > As far as I can tell, LaTeX-outline-name (called from > LaTeX-imenu-create-index-function to "Guess a name for the > current header line.") starts from the beginning of the > match and skips forward to the first "{". It thus ends up > picking "frame" as the header line which is not useful. > I suppose I could use imenu-generic-expression with > imenu-default-create-index-function -- that allows me to > explicitly say which part of the match I want to pick out > as the header -- but then I'd have to convert > latex-outline-regexp to the structure used by > imenu-generic-expression. > Is there any other easy workaround that I'm missing? > Grateful for any help, thanks! Considerting bug#32062 [1] as well, it might be nice if AUCTeX offers a way to customize `LaTeX-outline-name'. I incorporated the idea of Omar, the reporter of bug#32062, to make up the attached patch. With this change, you can prepare your own function to extract titles of \section etc. or \begin{frame} depending on the context, and use it for `LaTeX-outline-name-function' like this: (defun my-LaTeX-section-or-frame-title () ... SOME FUNCTION TO EXTRACT TITLES OF section OR frame ... ) (setq LaTeX-outline-name-function #'my-LaTeX-section-or-frame-title) I didn't test my patch. I'm sorry if it doesn't work. Regards, Ikumi Keita [1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=32062
diff --git a/latex.el b/latex.el index 923d27ab..21e7243f 100644 --- a/latex.el +++ b/latex.el @@ -358,12 +358,25 @@ If so, return the second element, otherwise return nil." (LaTeX-outline-offset)))) (t (outline-level))))))) +(defvar LaTeX-outline-name-function 'LaTeX-default-outline-name) (defun LaTeX-outline-name () "Guess a name for the current header line." + (funcall LaTeX-outline-name-function)) + +(defun LaTeX-default-outline-name () + "Default function for `LaTeX-outline-name'." (save-excursion - (if (re-search-forward "{\\([^\}]*\\)}" (+ (point) fill-column 10) t) - (match-string 1) - (buffer-substring (point) (min (point-max) (+ 20 (point))))))) + (if (search-forward "{" nil t) + (let ((beg (point))) + (forward-char -1) + (condition-case nil + (progn + (forward-sexp 1) + (forward-char -1)) + (error (forward-sentence 1))) + (buffer-substring-no-properties beg (point))) + (buffer-substring-no-properties + (point) (min (point-max) (+ 20 (point))))))) (add-hook 'TeX-remove-style-hook (lambda () (setq LaTeX-largest-level nil)))