6

I use emacs in the terminal. One thing that I miss sometimes from a more traditional GUI editor are scrollbars. Sure, there's the percentage in the modeline, but sometimes you just want a visualization. Also, the percentage doesn't visualize how large the document is relative to the visible buffer like a scrollbar would.

What are my options for scrollbars in terminal emacs? scroll-bar-mode seems to be completely absent (I built emacs with --without-x).

  • 1
    Sounds like something one could write a silly package for which abuses the right margin... – wasamasa Nov 4 '15 at 21:13
  • There is also the mini-map package that may interest you. emacswiki.org/emacs/MiniMap I.e., you could create a thin window that tracks the current position relative to the overall buffer length. – lawlist Nov 4 '15 at 21:29
  • 1
    Yeah, I haven't tested it, but I'm pretty sure MiniMap won't work in the terminal emacs. – asmeurer Nov 4 '15 at 21:31
7

This project is a good alternative: https://github.com/m2ym/yascroll-el because it works with and without GUI. Don't forget the cl require in your .emacs

(require 'cl) ;; build-in librairie
(require 'yascroll)
(global-yascroll-bar-mode)
  • Do you really need to add (require 'cl)? (yascroll should be requireing any libraries it needs). – npostavs Nov 30 '15 at 15:53
  • I agree but it doesn't work for me without this require (emacs 25) – djangoliv Nov 30 '15 at 15:56
  • Hmm, yeah it's a bug in yascroll I think, see github.com/m2ym/yascroll-el/issues/18 – npostavs Nov 30 '15 at 18:12
  • I was hoping for something better than yascroll. I've tried it, but it seems to be quite buggy. – asmeurer Dec 1 '15 at 21:03
  • 1
    I've tried it again and I guess it's not as bad as I remember. It does have issues with long lines, though. Also, I guess it's not really a bug, but it doesn't seem to be very configurable. What's particularly annoying is that the scrollbar appears about 5 characters from the right of the buffer, instead of completely on the right, and it doesn't seem to be configurable. – asmeurer Dec 26 '15 at 6:23
2

You could also use the sml-modeline package. It works pretty well in the terminal (imo) and is a nice alternative when yascroll doesn't work so well. However, you might want to apply the following monkey patch to sml-modeline-mode if you don't want it messing with stuff that's already in your modeline:

(require 'sml-modeline)
(defun sml-modeline-mode
    (&optional arg)
  "Show buffer size and position like scrollbar in mode line.
You can customize this minor mode, see option `sml-modeline-mode'.

    Note: If you turn this mode on then you probably want to turn off
option `scroll-bar-mode'."
  (interactive
   (list
    (or current-prefix-arg 'toggle)))
  (let
      ((last-message
        (current-message)))
    (setq-default sml-modeline-mode
                  (if
                      (eq arg 'toggle)
                      (not
                       (default-value 'sml-modeline-mode))
                    (>
                     (prefix-numeric-value arg)
                     0)))
    (if sml-modeline-mode
        (progn
          (unless sml-modeline-old-car-mode-line-position
            (setq sml-modeline-old-car-mode-line-position
                  (car mode-line-position)))
          (add-to-list 'mode-line-position ;; this line is patched and...
                       '(:eval
                         (list
                          (sml-modeline-create)))))
      (add-to-list 'mode-line-position sml-modeline-old-car-mode-line-position)) ;; this line is patched
                                                                                 ;; (they use `add-to-list' instead of `setcar')
    (run-hooks 'sml-modeline-mode-hook
               (if
                   (default-value 'sml-modeline-mode)
                   'sml-modeline-mode-on-hook 'sml-modeline-mode-off-hook))
    (if
        (called-interactively-p 'any)
        (progn
          (customize-mark-as-set 'sml-modeline-mode)
          (unless
              (and
               (current-message)
               (not
                (equal last-message
                       (current-message))))
            (let
                ((local ""))
              (message "Sml-Modeline mode %sabled%s"
                       (if
                           (default-value 'sml-modeline-mode)
                           "en" "dis")
                       local))))))
  (force-mode-line-update)
  (default-value 'sml-modeline-mode))

As you can see, only two lines there are patched which just make sure that it uses add-to-list instead of setcar (this keeps it from overriding anything that's the car of mode-line-position). Also, I have the following settings in my Custom file for sml-modeline:

(custom-set-variables
...
 '(sml-modeline-borders (quote ("[" . "] ")))
 '(sml-modeline-len 17)
 '(sml-modeline-numbers (quote percentage))
 ...)

The only real quirks I've seen for this mode are that it's not really accurate in things like Info-mode (because it seems that Info-mode buffers are actually one big buffer given the illusion of being multiple ones) and sometimes the "scrollbar" disappears between the percent symbol and the number adjacent to it when the "scrollbar" is really small. Other than that, sml-modeline works pretty nicely.

EDIT:

I just found two hacky "fixes" for the aforementioned bugs. For the bug regarding Info-mode et al. scrolling, if you remove the (widen) invocations from sml-modeline-create, you'll get the expected behavior. Note that I've only tested this in Info-mode, so don't expect this "fix" to give desired behavior everywhere. For the other bug regarding the "scrollbar" disappearing, you can eliminate this effect by not setting the sml-modeline-borders variable. Not exactly sure why that works, but it does so whatever.

  • Interesting. It's not really a scrollbar in the traditional sense. I don't get the point of your patch. For me, the only thing it replaces is the default percent indicator, which it duplicates anyway. – asmeurer Jan 13 '17 at 6:44
  • @asmeurer Ok, well then that's fine. For me, it was replacing some useful whitespace from the smart-mode-line package, so I figured it would be useful to add that patch for anyone who might have something similar set up. – GDP2 Jan 14 '17 at 4:04

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.