7

Q: how can I get a visual indicator distinguishing between the end of the buffer and the bottom of the window?

Use case: I've got a buffer with some blank lines at the bottom. However, the bottom of the window beyond the blank lines is also, well, blank. I'd like to be able to tell, visually, where the buffer ends/blank lines stop.

Vim does this with non-text characters at the bottom of a window (ie, the tildes) to indicate that there is nothing in the buffer (such as of blank lines) in that space, as in the screenshot below:

Vim tildes

How would one get the analog of this Vim feature in Emacs?

EDIT: @glucas's answer looks correct, but I'd love to see an answer that does not use the fringe, as I set mine to nil to save screen space on a small laptop screen.

1
  • How about using the empty-line component of the fringe-indicator-list to indicate where the end of the buffer begins? For example, (setq fringe-indicator-alist '((empty-line . empty-line))) Add additional components to the alist as desired. This method, however, requires a fringe to be visible. See also: reddit.com/r/emacs/comments/2kdztw/…
    – lawlist
    Commented Jul 6, 2015 at 23:10

3 Answers 3

8

You can customize indicate-empty-lines to enable a fringe marker on lines after the end of the file, or call toggle-indicate-empty-lines to turn it on and off interactively.

There's a package on MELPA that replaces the default fringe indicator with a ~ for a look that is closer to what you get with vi. See vi-tilde-fringe.

Updated

An alternative approach would be to use whitespace mode to make line breaks visible. Try whitespace-newline-mode, possibly tweaking the whitespace-newline face. Visually this approach is busier then what vi does since you're marking all lines in the buffer except the empty lines after the content, but it achieves a similar result. (It may also be possible to configure whitespace mode or a custom derived mode to only highlight empty lines at the end of the buffer content.)

1
  • +1 as this is probably going to be the answer. However, I don't use the fringe, so I'll leave the question open for a bit longer to see if anyone has a non-fringe solution.
    – Dan
    Commented Jul 7, 2015 at 10:44
4

Someone wrote a package that manages an overlay spanning the area after the end of the file:

https://github.com/jmickelin/vim-empty-lines-mode

Keep in mind though that while this solution behaves more correctly and works in terminals as well, it will necessarily be less performant and more buggy than the fringe indicator one.

4
  • Just a note: this minor mode does what I was looking to do, but users should be aware that it updates overlays at the end of the buffer after each command, so it may be a little heavier than one would like.
    – Dan
    Commented Jul 7, 2015 at 12:46
  • D'oh... and it turns out it's buggy and doesn't seem to play nicely with narrowing.
    – Dan
    Commented Jul 7, 2015 at 12:48
  • Oh noes, the answer got unaccepted ._.
    – wasamasa
    Commented Jul 7, 2015 at 13:21
  • Yeah, sorry, it's a good find, but I'm going to hold off on accepting for now for the reasons cited in my comments until I get a chance to test it out more rigorously.
    – Dan
    Commented Jul 7, 2015 at 13:25
4

I've written a package, char-font-lock, that (among else) highlight empty lines at the end of a buffer.

It also highlights the last line (in case it doesn't end with a newline), space at the end of lines, tab characters, and non-ascii characters. You can cherry pick which of the things you would like to highlight.

For example: enter image description here

5
  • 1
    Hmm, that doesn't sound really related as the question is about putting things in the window where no lines are...
    – wasamasa
    Commented Jul 7, 2015 at 16:04
  • 1
    No, the question was "how can I get a visual indicator distinguishing between the end of the buffer and the bottom of the window?" My package does this by highlighting empty lines at the end of a buffer. If you don't get any highlighting then you know that the file is correctly formatted with a single newline at the end of the last non-empty list. Admittedly, it doesn't highlight things like vi does, but that was not part of the question. Commented Jul 7, 2015 at 16:15
  • I think that the OP asked for empty screen lines to be indicated. According to your screenshot, however, your package seems to highlight empty physical lines.
    – user227
    Commented Jul 7, 2015 at 20:29
  • @lunaryorn, I read it as though the OP doesn't like the fact that empty lines at the end of a buffer isn't visible. ("I'd like to be able to tell, visually, where the buffer ends/blank lines stop.") Commented Jul 7, 2015 at 20:42
  • 1
    Agreed, the point of this question seems to be how to tell where the buffer content ends. Highlighting the last line(s) of that content seems just as valid an approach as highlighting the space after the content.
    – glucas
    Commented Jul 8, 2015 at 2:53

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.