Skip to content

Instantly share code, notes, and snippets.

@katspaugh
Last active August 29, 2015 14:20
Show Gist options
  • Save katspaugh/e4dab5ac4d704a81956f to your computer and use it in GitHub Desktop.
Save katspaugh/e4dab5ac4d704a81956f to your computer and use it in GitHub Desktop.
Show the beginning of defun at point

This is an attempt to replicate a feature found in WebStorm:

When you are in the end of a block, and the beginning of the block is outside the viewport, it shows you the beginning in a nice overlay.

In Emacs we can show the beginning of function definition at point in the header line.

(defun show-beginning-of-defun ()
"Display the beginning of defun in the header line."
(let (start end)
(save-excursion
(beginning-of-defun)
(setq start (line-beginning-position)
end (line-end-position)))
(if (>= start (window-start))
(setq header-line-format nil)
(setq header-line-format (buffer-substring-no-properties start end)))))
(add-hook 'prog-mode-hook
(lambda ()
(add-hook 'post-command-hook #'show-beginning-of-defun)))
@clemso
Copy link

clemso commented May 8, 2015

Another way:
(which-function-mode 1)
(setq-default header-line-format
'((which-func-mode ("" which-func-current " "))
b-narrow-mode-line))

@katspaugh
Copy link
Author

@clemso, cool, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment