jdtsmith / mlscroll

Lightweight scrollbar for the Emacs mode line
GNU General Public License v3.0
94 stars 7 forks source link

MLScroll - Modeline Scrollbar for Emacs

A lightweight scrollbar for the Emacs mode line.

For graphical window systems:

    mlscroll

and terminals too:

    mlscroll-terminal

Why?

Emacs has so many great ways to navigate, I really only ever used scroll-bars as a visual indication of position and file size. But recently, to save space, I added (scroll-bar-mode -1) to my init. Immediately I missed having that information at a glance. A percentage in the mode line (like 25%) is not very glanceable, and also gives no information about the currently visible content relative to the total line length (i.e. from the length of the bar). I wanted something very fast and very lightweight, plus I'm not so into rainbow cats. Hence MLScroll.

Info

Installing

Get it from MELPA, and arrange to have:

(mlscroll-mode 1)

called at init time (or whenever you are feeling scrolly). Toggle on or off anytime.

Example for use-package:

(use-package mlscroll
  :ensure t
  :config
  (setq mlscroll-shortfun-min-width 11) ; truncate which-func
  (mlscroll-mode 1))

Alternatively, if you start emacs using the command line --daemon command (see below):

(use-package mlscroll
   :ensure t
   :hook (server-after-make-frame . mlscroll-mode))

Setup

Customization

Use M-x customize-group mlscroll to change background colors, overall scroll bar width, minimum current "thumb" width, border size, and other settings.

Position

By default, MLScroll disables the XX% position mode line indication, and puts itself in the mode line variable mode-line-end-spaces, prepending a spacer to right-align itself. Optionally, it can instead replace the XX% indicator (or be placed anywhere in your mode line). See mlscroll-alter-percent-position and mlscroll-right-align.

Which-function mode

The builtin which-function-mode by default puts [full-function-name] on the right side of the mode line. With long names and the default placement, this can push the MLScroll bar partially or fully off the mode line. Set mlscroll-shortfun-min-width to a minimum width, and MLScroll will truncate the which-function name to at least that many trailing characters (e.g. […function-name] or similar), to make room for the scrollbar. The amount of truncation can be adjusted using mlscroll-shortfun-extra-width.

Integrating with the mode-line

Note that MLScroll is most visually compatible with "plain" mode line formats that don't use :box bordering. It will warn you if you try to use a border with a :box-full format enabled. It also doesn't inherit :underline and :overline mode line properties unless mlscroll-border is set to 0 (these don't work with the combination of specified space and :box).

See the suggestions for configuring moody for some config ideas.

For users of modus-themes, (setq modus-themes-mode-line '(moody borderless)) is recommended, or, in more recent versions (>v4):

(setq modus-themes-common-palette-overrides
      '((border-mode-line-active unspecified)
        (border-mode-line-inactive unspecified)))

Scroll-bar width: Lines vs. Characters

The MLScroll bar widths are based on the number of lines visible in the window (+ lines before and after it). The normal scroll bar is based on characters shown. Both tend to change as very long/wrapped lines come into view, but in the opposite sense: MLScroll sees fewer lines shown and shrinks the current thumb; the default scrollbar sees many characters come in view, and grows it. I find the lines approach to be more sensible, and it has the advantage that with truncate-lines on, the thumb doesn't change size as you scroll. If you'd like to see the difference, evaluate (insert (make-string 5000 ?a) "\n") in the *scratch* buffer amidst other normal text, and scroll through before and after toggle-truncate-lines. On the other hand, highly folded documents like org-mode docs will show a changing "thumb size" as you scroll through, as the current window could contain many (hidden) lines. I find that pretty convenient actually.

FAQ's

Other tips

MLScroll takes up a decent (configurable) chunk of your mode line. To save space for it even when the window is somewhat narrow, I use: