I really like the package sml-modeline (it is available on melpa): https://melpa.org/#/sml-modeline With it I replaced my vertical scrollbars.

But when opening large text files like this Raspbian-Package-List (warning: 38MB download) then Emacs gets realy slow. Disabling sml-modeline-mode instantly speeds up emacs.

So I had a look at sml-modelines source code. In function sml-modeline-create there is a call to widen and point-max, which I suspect to make sml-modeline-mode so slow (*1*).

If (*1*) is the case, is it possible to store those values in between calls of sml-modeline-create to speed things up, and how do it? I think those values need to be stored for every single buffer, or every time a call to switch-to-buffer is done.

If (*1*) is not the case, what operations make sml-modeline-mode so slow and how to speed this up?

This Package did not get an update since January 2012, so maybe it is already abandoned. :-(

  • The slow-down is due to line-number-at-pos that is called in a few places. For a fix/workaround, see this related thread entitled "A faster method to obtain line-number-at-pos in large buffers": emacs.stackexchange.com/questions/3821/… You may also wish to tell the author about this problem and workaround/fix. Essentially, you can use (save-excursion (goto-char ...)) with the answer by Constantine in the related thread.
    – lawlist
    Jun 12, 2017 at 23:47
  • @lawlist wow it is working. :) One need to replace (setq number-max (line-number-at-pos (point-max))) (setq number-beg (line-number-at-pos wstart)) (setq number-end (line-number-at-pos wend))) with (save-excursion (goto-char (point-max)) (setq number-max (string-to-number (format-mode-line "%l"))) (goto-char wstart) (setq number-beg (string-to-number (format-mode-line "%l"))) (goto-char wstart) (setq number-end (string-to-number (format-mode-line "%l"))))) if you write a answer I will accept it. Thank you!
    – jue
    Jun 13, 2017 at 0:25

2 Answers 2


The slow-down is caused by calls to line-number-at-pos. As mentioned in the answer by username Constantine in the related thread entitled "A faster method to obtain line-number-at-pos in large buffers" https://emacs.stackexchange.com/a/3822/2287, (string-to-number (format-mode-line "%l")) can be used to expeditiously extract the line number from a buffer that is visible. There are a few exceptions discussed in the answer and comments of the aforementioned thread that are certainly worth reading.

The general way to apply this approach is by using (save-excursion (goto-char ...) (string-to-number (format-mode-line "%l"))). If a string instead of a raw number is desired, then just remove the string-to-number statement from the above snippet.

The original poster has commented underneath the question applying this approach to the specific fact pattern of sml-modeline; however, @lawlist has not done any testing with said library and is unable to post a specific answer in relation thereto.


Just in case the author of sml-modeline is not updating, here a step by step guide:

1.) open sml-modeline.el from your install directory
(probably: ~/.emacs.d/elpa/sml-modeline-20120110.1240/sml-modeline.el)

2.) goto line 139 of the file and replace lines

 (setq number-max (line-number-at-pos (point-max)))
 (setq number-beg (line-number-at-pos wstart))
 (setq number-end (line-number-at-pos wend)))


(save-excursion (goto-char (point-max))
                (setq number-max (string-to-number (format-mode-line "%l")))
                (goto-char wstart)
                (setq number-beg (string-to-number (format-mode-line "%l")))
                (goto-char wstart)
                (setq number-end (string-to-number (format-mode-line "%l")))))

3.) save and do M-x byte-compile-file
4.) restart emacs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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