From Newsgroup: gnu.emacs.help
Dear Alex,
Axel Reichert <
mail@axel-reichert.de> a |-crit :
Thomas Dupond <thomas@dupond.eu> writes:
Axel Reichert <mail@axel-reichert.de> a |-crit :
What I am doing wrong or how do I get which-func-mode activated in my
derived mode automatically?
Pointers much appreciated!
I do not know really the issue, however I think that it has to do with
imenu. It looks like which-functions-mode uses imenu to understand
where begins and ends a function. Trying to use imenu in Text Mode
throws an error.
I had this suspicion as well, but discarded it because the second
M-x mini-mode
succeeds, as does setting which-func-mode to t manually. However, just
for the sake of testing, I have now based my mini-mode not on text-mode,
but on c-mode, and, heureka, the "XXX" is shown in the mode line!
Now I will search the docs about Imenu and try to find out how to teach
it that text-mode is not a no-go. Let's see.
I delved a little bit deeper and apparently you should be able to do
what you want after you have defined the variable
imenu-generic-expression or the variable imenu-create-index-function.
Fortran mode uses the former and Org mode the latter (respectively in fortran-mode.el and org-compat.el).
For example I wrote this based on your first message and it displays
the current markdown-like title (only for lines beginning
with one or two stars) with which-func:
(add-to-list 'auto-mode-alist '("\\.mini\\'" . mini-mode))
(define-derived-mode mini-mode
text-mode "Mini"
"Major mode for editing .mini files."
(which-function-mode 1)
(defvar mini-imenu-generic-expression
(list
(list
nil
"^\*\\ \\(.*\\)$"
1)
(list
nil
"^\*\*\\ \\(.*\\)$"
1)))
(set (make-local-variable 'imenu-generic-expression)
mini-imenu-generic-expression))
(provide 'mini)
--
Regards,
Thomas
--- Synchronet 3.21d-Linux NewsLink 1.2