Mode line's %p displays the percentage of the current view of the buffer:

%p The percentage of the buffer text above the top of window, or ‘Top’, ‘Bottom’ or ‘All’. Note that the default mode line construct truncates this to three characters.

I don't like the Top/Bottom/All and I'd like to always display the percentage. Is there a way to achieve this?

  • 2
    I'm curious why. Top means 0%. Bottom means 100%. All means 100% and the top is visible too. You can do pretty much anything you like to the mode line, but in this case it would be a pain to monkey with this. Note that you can easily reverse the percentage direction - see %P (instead of %p).
    – Drew
    Mar 22, 2015 at 16:00
  • 3
    My brain will look for a number when I want to know where I am. When I have to occasionally remember that it could also be Top/Bottom, then I have to remember that. Mar 22, 2015 at 18:07
  • One idea would be to calculate the buffer-size -- i.e., number of points -- between point-min and window-start, and window-end and point-max, and if so desired, the size of the visible buffer could be factored in -- i.e., points between window-start to window-end -- those calculations could be done in a blink of an eye and would not affect performance because point does not move. Those buffer-size calculations could be turned into percentages. I believe that this is an answer, but I'll let someone else write it up because I have other projects on my plate today.
    – lawlist
    Mar 22, 2015 at 18:24
  • Never really found it useful to know percentage of buffer above :\ IMHO knowing the current_line/total_lines, and eventually, knowing that ALL the content buffer is displayed (when I'm on the first line) is more useful. Just my opinion, maybe it's my experience which is not wide enough.
    – Nsukami _
    Mar 25, 2015 at 13:54

2 Answers 2


Here's an example of how you can do something like this. Note, however, that it displays exactly what you asked for (percentage of text above the window), which is probably not what you actually want. For instance, it never displays 100%, since there will always be some text inside the window.

(setcar mode-line-position
        '(:eval (format "%3d%%" (/ (window-start) 0.01 (point-max)))))

You could also use window-end, which has the opposite disadvantage (it almost never displays 0).

(setcar mode-line-position
        '(:eval (format "%3d%%" (/ (window-end) 0.01 (point-max)))))

You may want to sorround these strings with spaces or some other padding.


The built-in code for %p just looks at window-start and point-max and computes the percentage that way. You can find this out using C-h f format-mode-line and then following the link to the Emacs C sources (assuming you have them around somewhere).

So, you can do this same thing using a :eval form in mode-line-format.

  • 8
    Can you expand your answer to provide the complete solution? Mar 23, 2015 at 1:39

Your Answer

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

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