12

I would like to make sure that scrollbars never show up on my windows, but I recently noticed that when I created a new frame with C-x 5 2 the new frame gets a scrollbar, even though the original frame does not. The lines that might be relevant from my init.el are below:

(scroll-bar-mode -1)
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))

I can still use M-x toggle-scroll-bar to turn it off in the new frame, but I feel like that shouldn't be necessary.

To clarify, I'm using emacsclient -c & to start Emacs on Ubuntu, and when I do this I get a scroll bar. C-h v scroll-bar-mode gives me:

scroll-bar-mode is a variable defined in `scroll-bar.el'.
Its value is nil
Original value was right

Documentation:
Specify whether to have vertical scroll bars, and on which side.
Possible values are nil (no scroll bars), `left' (scroll bars on left)
and `right' (scroll bars on right).
To set this variable in a Lisp program, use `set-scroll-bar-mode'
to make it take real effect.
Setting the variable with a customization buffer also takes effect.

You can customize this variable.

So the value of scroll-bar-mode is properly set to nil, but somehow Emacs is ignoring this to give me a scroll bar anyway.

Ryan
  • 3,989
  • 1
  • 26
  • 49

3 Answers3

9

I also ran into this issue, until I added the following code. (I believe I came across the snippet here on Stack Exchange, but sorry I don't recall the author.)

(defun my/disable-scroll-bars (frame)
  (modify-frame-parameters frame
                           '((vertical-scroll-bars . nil)
                             (horizontal-scroll-bars . nil))))
(add-hook 'after-make-frame-functions 'my/disable-scroll-bars)
Scott Weldon
  • 2,695
  • 1
  • 17
  • 31
InHarmsWay
  • 1,309
  • 7
  • 8
7

You can adjust the frame parameters in the default-frame-alist to tell Emacs you never want scroll bars. Add the following to your init file:

(add-to-list 'default-frame-alist
             '(vertical-scroll-bars . nil))
Dan
  • 32,584
  • 6
  • 98
  • 168
  • I feel like that should work, but it doesn't. Still get the scroll bar, but only on the second frame. – Ryan Jun 06 '16 at 14:33
  • @Ryan: strange! The above works for me. The only other thing in my init file that might be relevant is an old `(toggle-scroll-bar -1)` that I hadn't removed. You could try adding that as well, but beyond that, I'm out of guesses. – Dan Jun 06 '16 at 14:37
  • Okay, so it actually works on Ubuntu, but not on Windows. Next time I'm on the Windows side I'll check `(toggle-scroll-bar)`. – Ryan Jun 06 '16 at 14:41
  • Now I don't even know what to think. Rebooted, and now it's not working in Ubuntu, either. Every new frame is created with the scroll bar, and I have to `M-x toggle-scroll-bar` to get rid of it. – Ryan Jun 06 '16 at 20:04
  • Yes, MS Windows is particular in this. Other than that, I'd recommend *customizing option* `default-frame-alist`. There's a reason it's a user option. – Drew Jun 10 '16 at 04:40
3

Not everyone wants to use customize, but using it to disable scrollbars makes the issue disapear. The variables you want are: scroll-bar-mode and horizontal-scroll-bar-mode.

If not using a customize file, customize can still be utilized by putting these in your init:

;; disable scrollbars
(customize-set-variable 'scroll-bar-mode nil)
(customize-set-variable 'horizontal-scroll-bar-mode nil)

That will suffice to disable any and all scrollbars in any frame type.

bklaase
  • 66
  • 3