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.

1 Answer 1


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
(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.

  • 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.) Commented Nov 25, 2015 at 1:09
  • which-function-mode does not work in Jython mode. But, getting out of Jython mode and into Python mode is not so straightforward. Commented Nov 26, 2015 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.