Hi Arash, Thanks for the (always) helpful explanation and pointers!
So (since I'm not very competent in elisp) are you suggesting that one way to get what I want would be to write a function (perhaps starting from `TeX-current-defun-name') that returns only what I want and than set the `which-func-functions' variable to this function, like below with `add-log-current-defun-function'? All the best, Greg ------------------------------------------------------------------------------- On Wed 16 Oct 2024 at 07:31 Arash Esbati wrote: > > Hi Greg, > > Greg Bognar via General discussion about AUCTeX <[email protected]> writes: > > > I like to display the section (chapter, etc.) name on the modeline by using > > which-func. If I understand correctly, which-func uses imenu to get the > > function (section, etc.) names, and AUCTeX supports imenu by setting > > `imenu-create-index-function' to `LaTeX-imenu-create-index-function'. > > I only had a brief look, and IIUC, which-func uses the function > `which-function' to gather the current function name for the modeline: > > ,----[ C-h f which-function RET ] > | which-function is a interpreted-function in ‘which-func.el’. > | > | (which-function) > | > | Return current function name based on point. > | Uses ‘which-func-functions’, ‘add-log-current-defun’. > | or ‘imenu--index-alist’ > | If no function name is found, return nil. > | > `---- > > As you see, it uses `add-log-current-defun' before `imenu--index-alist'. > And latex.el contains: > > (setq-local add-log-current-defun-function #'TeX-current-defun-name) > > So what happens is that the value of `which-func-functions' is nil, so > `TeX-current-defun-name' is used for the current function, which indeed > returns things like "section{My Section}" or "chapter{My Chapter}". > > I think the way to change this is by adding an appropriate function to > `which-func-functions' which comes first. > > > Is there a way to modify `LaTeX-imenu-create-index-function' (if > > that's indeed the culprit) so that it only returns the section > > (chapter, etc.) name without the \-less section (chapter, etc.) > > command? > > That function works as expected. Take this example: > > --8<---------------cut here---------------start------------->8--- > \documentclass{article} > > \usepackage{titlesec} > > \titlespacing\section{0pt}{2\bigskipamount}{\parskip} > > \begin{document} > > \section{First section} > \label{sec:first-section} > > \subsection{This is a subsection} > \label{sec:this-subsection} > > > \section{Second section} > \label{sec:second-section} > > \end{document} > --8<---------------cut here---------------end--------------->8--- > > and do 'M-x (LaTeX-imenu-create-index-function) RET' which returns: > > --8<---------------cut here---------------start------------->8--- > (("article" . #<marker at 1 in xparse-test.tex>) > ("document" . #<marker at 104 in xparse-test.tex>) > (" First section" . #<marker at 122 in xparse-test.tex>) > (" This is a subsection" . #<marker at 173 in xparse-test.tex>) > (" Second section" . #<marker at 237 in xparse-test.tex>) > ("document" . #<marker at 290 in xparse-test.tex>)) > --8<---------------cut here---------------end--------------->8--- > > > And that it does not pick up things like \titlespacing\section{0pt}? > > See above. > > > (Interestingly, the items that appear in the imenu menu on the menubar are > > slightly different than the items that are displayed on the modeline.) > > See above. > > FWIW, the builtin latex-mode does exactly the same thing. > > Best, Arash
