topsy.el
topsy.el copied to clipboard
Customizable faces for header line, and improved display logic
Add two new customizable faces, topsy
and topsy-highlight
.
The topsy
face is used for the header-line when topsy-mode
is enabled. It inherits from the default face, so that the text in the header line matches the contents of the buffer. The topsy-highlight
face is applied (with low priority) when topsy is showing the first line of a defun (see below).
To go back to the previous appearance (using header-line face), customize the topsy
face to nil or remove its :inherit default
attribute.
Properly handle narrowed buffers
The first line of the defun is shown even if it is only partly within a narrowed buffer.
Improve logic for finding the first line of a defun
The first line of a defun is shown only if it is partially visible. If the defun is entirely outside the window, its first line is not shown.
Fixes #1
Show previous line when a defun starts at the top of a window
Finally, when there is no partially visible defun, show the line that is above the top of the window. This gives a smooth scrolling effect, where the header line looks and acts just like a normally scrolling part of the buffer. When you scroll up, the top line of text will appear in the header line, which then becomes sticky when you scroll past a defun.
Buffer text shown in this way doesn't have the topsy-highlight
face.
https://user-images.githubusercontent.com/552952/140688151-e99393ce-433d-4885-9e1d-d3001faddb72.mp4
Hi Roshan,
Thanks. Some of these changes are obviously correct, like the out-of-bounds bug fix. Others I may have some feedback on. It would be easier to review and apply if unrelated changes were in separate PRs. Would you be willing to refile this as separate ones? If not, I'll review and maybe cherry-pick some of the changes, but it will take a bit more work on my end.
Sure, I'll work to separate them out into separate PRs when I have some time. Perhaps the logical breakdown would be: (1) applying faces to the header line; (2) fallback to showing the line above the window when there's no header line; and (3) modifying the topsy--beginning-of-defun
function.
I've split apart the functionality of this PR into #16, #17, and #18. The combined effect can be seen in https://github.com/roshanshariff/topsy.el/tree/master. I'll close this PR now.