10

When navigating a source file with incremental search, I often find myself jumping into some context that is taller than the window. This raises the question: "Which class am I in?". Or, if the previous developer is prone to writing tall methods: "Which class and method am I in?"

I currently answer these questions by interrupting my search to start a new regex search in the reverse direction, then cancel this search with C g, then do whatever (usually resume the search). But, this happens to me so often, I feel like I should have a single command to just print the class/method context in the minibuffer. Or, even better, if that context was always visible. (I would give up a line of window for that.)

Is there some Emacs gadget that already scratches this itch? Or, am I just going about this in completely the wrong way? If it matters, I happen to be working in Python and Java.

davidrmcharles
  • 307
  • 1
  • 8

1 Answers1

12

which-function-mode displays the current method name.

The following configuration, which I got from Emacs Redux, displays the current method / function / orgmode heading in the top header line rather than the mode line:

;; Show the current function name in the header line
(which-function-mode)
(setq-default header-line-format
              '((which-func-mode ("" which-func-format " "))))
(setq mode-line-misc-info
            ;; We remove Which Function Mode from the mode line, because it's mostly
            ;; invisible here anyway.
            (assq-delete-all 'which-func-mode mode-line-misc-info))

Do check the linked article for a complete explanation of which-function-mode.

Juancho
  • 5,395
  • 15
  • 20
  • Thank you. I enabled `which-function-mode`, but I am not seeing anything in either Python or Java. However, I do see something for C++. (Perhaps my Emacs is too old.) – davidrmcharles Nov 25 '15 at 01:09
  • `which-function-mode` does not work in Jython mode. But, getting out of Jython mode and into Python mode is not so straightforward. – davidrmcharles Nov 26 '15 at 16:03