Sync to HEAD
[bpt/emacs.git] / lisp / scroll-bar.el
index 609bea4..2d2921e 100644 (file)
@@ -54,6 +54,23 @@ that scroll bar position."
   ;; with a large scroll bar portion can easily overflow a lisp int.
   (truncate (/ (* (float (car num-denom)) whole) (cdr num-denom))))
 
+(defun scroll-bar-columns (side)
+  "Return the width, measured in columns, of the vertical scrollbar on SIDE.
+SIDE must be the symbol `left' or `right'."
+  (let* ((wsb   (window-scroll-bars))
+         (vtype (nth 2 wsb))
+         (cols  (nth 1 wsb)))
+    (cond
+     ((not (memq side '(left right)))
+      (error "`left' or `right' expected instead of %S" side))
+     ((and (eq vtype side) cols))
+     ((eq (frame-parameter nil 'vertical-scroll-bars) side)
+      ;; nil means it's a non-toolkit scroll bar, and its width in
+      ;; columns is 14 pixels rounded up.
+      (ceiling (or (frame-parameter nil 'scroll-bar-width) 14)
+               (frame-char-width)))
+     (0))))
+
 \f
 ;;;; Helpful functions for enabling and disabling scroll bars.
 
@@ -87,10 +104,7 @@ This is nil while loading `scroll-bar.el', and t afterward.")
         (list (cons 'vertical-scroll-bars scroll-bar-mode)))
        (setq frames (cdr frames))))))
 
-(defcustom scroll-bar-mode
-  (cond ((eq system-type 'windows-nt) 'right)
-       ((featurep 'mac-carbon) 'right)
-       (t 'left))
+(defcustom scroll-bar-mode default-frame-scroll-bars
   "*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).
@@ -117,14 +131,13 @@ created in the future.
 With a numeric argument, if the argument is negative,
 turn off scroll bars; otherwise, turn on scroll bars."
   (interactive "P")
-  (if flag (setq flag (prefix-numeric-value flag)))
 
   ;; Tweedle the variable according to the argument.
-  (set-scroll-bar-mode (if (null flag) (not scroll-bar-mode)
-                        (and (or (not (numberp flag)) (>= flag 0))
-                             (cond ((eq system-type 'windows-nt) 'right)
-                                   ((featurep 'mac-carbon) 'right)
-                                   (t 'left))))))
+  (set-scroll-bar-mode (if (if (null flag) 
+                              (not scroll-bar-mode)
+                            (setq flag (prefix-numeric-value flag))
+                            (or (not (numberp flag)) (>= flag 0)))
+                          default-frame-scroll-bars)))
 
 (defun toggle-scroll-bar (arg)
   "Toggle whether or not the selected frame has vertical scroll bars.
@@ -142,10 +155,7 @@ when they are turned on; if it is nil, they go on the left."
    (selected-frame)
    (list (cons 'vertical-scroll-bars
               (if (> arg 0)
-                  (or scroll-bar-mode
-                      (cond ((eq system-type 'windows-nt) 'right)
-                            ((featurep 'mac-carbon) 'right)
-                            (t 'left))))))))
+                  (or scroll-bar-mode default-frame-scroll-bars))))))
 
 (defun toggle-horizontal-scroll-bar (arg)
   "Toggle whether or not the selected frame has horizontal scroll bars.
@@ -358,4 +368,5 @@ EVENT should be a scroll bar click."
 \f
 (provide 'scroll-bar)
 
+;;; arch-tag: 6f1d01d0-0b1e-4bf8-86db-d491e0f399f3
 ;;; scroll-bar.el ends here