0

I was looking around in foreign but public init.el files and setup a which-function-mode that use the headline instead of the modeline for it's content.

I couldn't find a use-package example for that and I am still not clear with lisp code. The which-function-mode now is used in nearly every buffer. But I want it only for pyhton (emacs in build).

How do I have to modify the use-package to achieve this goal?

;; =========
;; Which Function Mode
;; =========
(use-package which-func
  :config
  (add-hook 'prog-mode-hook
        (lambda()
          (which-func-mode)))
  ;; replace nothing found symbol "???"
  (setq which-func-unknown "∅")
  ;; add to headline
  (setq-default header-line-format
        '((which-func-mode ("" which-func-format " "))))
  ;; remove from modeline
  (setq mode-line-misc-info
    (delete '(which-function-mode (which-func-mode
                       ("" which-func-format " ")))
       mode-line-misc-info))
)
buhtz
  • 679
  • 4
  • 22

1 Answers1

1

If you want it only for python, just change prog-mode-hook to python-mode-hook

(use-package which-func
  :config
  (add-hook 'python-mode-hook 'which-func-mode)
  ;; replace nothing found symbol "???"
  (setq which-func-unknown "∅")
  ;; add to headline
  (setq-default header-line-format
                '((which-func-mode ("" which-func-format " "))))
  ;; remove from modeline
  (setq mode-line-misc-info
        (delete '(which-function-mode (which-func-mode
                                       ("" which-func-format " ")))
                mode-line-misc-info)))
Tianshu Wang
  • 1,724
  • 4
  • 7
  • Mhm... When `python-mode` is entered this activates the `which-func-mode` **but** for all buffers and not Python exclusive. I opened a [new question](https://emacs.stackexchange.com/q/71002/12999) about that. – buhtz Mar 18 '22 at 10:01
  • @buhtz You can take a look at https://stackoverflow.com/questions/62080587/make-a-global-minor-mode-buffer-local – Tianshu Wang Mar 18 '22 at 10:39