From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Keith David Bershatsky Newsgroups: gmane.emacs.bugs Subject: bug#16475: 24.3.50; enhancement request: remove vertical scroll bar automatically when not needed Date: Thu, 11 Feb 2016 18:46:22 -0800 Message-ID: References: <8bfbddfb-237e-47b1-aed7-b28fc97d1f92@default> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (generated by - "") Content-Type: text/plain; charset=US-ASCII X-Trace: ger.gmane.org 1455245243 29378 80.91.229.3 (12 Feb 2016 02:47:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 12 Feb 2016 02:47:23 +0000 (UTC) To: 16475@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Feb 12 03:47:11 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aU3lG-0000th-Lp for geb-bug-gnu-emacs@m.gmane.org; Fri, 12 Feb 2016 03:47:10 +0100 Original-Received: from localhost ([::1]:55622 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aU3lF-0000XW-Uv for geb-bug-gnu-emacs@m.gmane.org; Thu, 11 Feb 2016 21:47:09 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aU3lB-0000XJ-TG for bug-gnu-emacs@gnu.org; Thu, 11 Feb 2016 21:47:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aU3l8-0003vi-MF for bug-gnu-emacs@gnu.org; Thu, 11 Feb 2016 21:47:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:56187) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aU3l8-0003vb-Iu for bug-gnu-emacs@gnu.org; Thu, 11 Feb 2016 21:47:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aU3l8-0002Dg-8Z for bug-gnu-emacs@gnu.org; Thu, 11 Feb 2016 21:47:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <8bfbddfb-237e-47b1-aed7-b28fc97d1f92@default> Resent-From: Keith David Bershatsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 12 Feb 2016 02:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16475 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 16475-submit@debbugs.gnu.org id=B16475.14552451938497 (code B ref 16475); Fri, 12 Feb 2016 02:47:02 +0000 Original-Received: (at 16475) by debbugs.gnu.org; 12 Feb 2016 02:46:33 +0000 Original-Received: from localhost ([127.0.0.1]:37095 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aU3kf-0002Cz-C3 for submit@debbugs.gnu.org; Thu, 11 Feb 2016 21:46:33 -0500 Original-Received: from cobb.liquidweb.com ([50.28.13.150]:43374) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aU3kd-0002Ck-6g for 16475@debbugs.gnu.org; Thu, 11 Feb 2016 21:46:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lawlist.com; s=default; h=Content-Type:MIME-Version:Subject:Cc:To:From:Message-ID:Date; bh=9Eyt8G4vbKEXbrd6JVlPfH8nTuhXSp7iDARQLqAEkLA=; b=BtCevH4GvwSc7rbVWV1lmckHvqt8ZrlCk3bxWN60hAGBNEHUG7WTwfWKkQIrjjlQnnnGA57cmu6SpblGkFybIjvuCKkspZhOEIa3qWpRrDYScXIsxi7NEnOBfq0GJfKY; Original-Received: from cpe-45-48-239-195.socal.res.rr.com ([45.48.239.195]:54379 helo=server.private.localhost) by cobb.liquidweb.com with esmtp (Exim 4.82) (envelope-from ) id 1aU3kT-0005yX-6M; Thu, 11 Feb 2016 21:46:21 -0500 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cobb.liquidweb.com X-AntiAbuse: Original Domain - debbugs.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lawlist.com X-Get-Message-Sender-Via: cobb.liquidweb.com: acl_c_relayhosts_text_entry: lawlist|lawlist.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:112913 Archived-At: If and when feature request 22404 ever comes to fruition (to accurately calculate window-start/window-end every command loop under all circumstances), the following is a minor mode that demonstrates how to add/remove scroll bars depending upon the length of the buffer. It can undoubtedly use some improvements, but I am already successfully using it for my own personal setup with the latest draft/patch for the `window-start-end-hook`. https://debbugs.gnu.org/cgi/bugreport.cgi?bug=22404 [NOTE: Eli has indicated that a `post-redisplay-hook' (which does not introduce user Lisp into the redisplay mix) would be a better alternative to the proposed `window-start-end-hook`, and I completely respect Eli's opinion in that regard. However, I wanted to get something working for my own personal use and I am enjoying familiarizing myself with some basic C language coding relating to feature 22404.] Thanks, Keith ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; sb-mode ;; https://github.com/kentaro/auto-save-buffers-enhanced ;; `sb-regexp-match-p` function modified by @sds on stackoverflow ;; http://stackoverflow.com/a/20343715/2112489 (defun sb-regexp-match-p (regexps string) (and string (catch 'matched (let ((inhibit-changing-match-data t)) ; small optimization (dolist (regexp regexps) (when (string-match regexp string) (throw 'matched t))))))) (defgroup sb nil "A group for the lawlist scroll-bar." :tag "Scroll Bar" :group 'convenience) (defvar regexp-always-scroll-bar '("\\.yes" "\\*Scroll-Bar\\*") "Regexp matching buffer names that will always have scroll bars.") (defvar regexp-never-scroll-bar '("\\.off" "\\.not" "\\*Calendar\\*") "Regexp matching buffer names that will never have scroll bars.") (defun lawlist-scroll-bar-fn (win start end pbol-start peol-end fully-p) (when (and (window-live-p win) (not (minibufferp))) (let* ( (buffer-size (buffer-size)) (point-min (point-min)) (point-max (point-max)) (window-scroll-bars (window-scroll-bars)) (buffer-name (buffer-name))) (cond ;; not regexp matches | not narrow-to-region ((and (not (sb-regexp-match-p regexp-always-scroll-bar buffer-name)) (not (sb-regexp-match-p regexp-never-scroll-bar buffer-name)) (equal (- point-max point-min) buffer-size)) (cond ;; Lines of text are less-than or equal-to window height, ;; and scroll bars are present (which need to be removed). ((and (<= (- point-max point-min) (- end start)) (or (equal window-scroll-bars '(15 2 right nil)) ;; GNU Emacs 24.5.1 of 2015-04-10 on builder10-6.porkrind.org (equal window-scroll-bars '(15 2 right 0 0 nil)) ;; 10/01/2014 (equal window-scroll-bars '(15 2 right nil 0 nil)) )) ;; 11/19/2014 (set-window-scroll-bars win 0 'right nil)) ;; Lines of text are greater-than window height, and ;; scroll bars are not present (which need to be added). ((and (> (- point-max point-min) (- end start)) (or (equal window-scroll-bars '(0 0 nil nil)) ;; GNU Emacs 24.5.1 of 2015-04-10 on builder10-6.porkrind.org (equal window-scroll-bars '(0 0 t nil)) ;; GNU Emacs 24.5.1 of 2015-04-10 on builder10-6.porkrind.org (equal window-scroll-bars '(0 0 t 0 0 t)) ;; windows-nt (default) (equal window-scroll-bars '(nil 0 t nil 0 nil)) ;; darwin (default) ;; 11/19/2014 (equal window-scroll-bars '(0 0 t 0 0 nil)) ;; darwin (default) ;; 10/01/2014 (equal window-scroll-bars '(0 0 nil nil 0 nil)) ;; 11/19/2014 (after scroll bars are removed) (equal window-scroll-bars '(0 0 nil 0 0 nil)))) ;; windows-nt / darwin (set-window-scroll-bars win 15 'right nil)))) ;; Narrow-to-region is active, and scroll bars are present ;; (which need to be removed). ((and (buffer-narrowed-p) (or (equal window-scroll-bars '(15 2 right nil)) ;; GNU Emacs 24.5.1 of 2015-04-10 on builder10-6.porkrind.org (equal window-scroll-bars '(15 2 right 0 0 nil)) ;; 10/01/2014 (equal window-scroll-bars '(15 2 right nil 0 nil)) )) ;; 11/19/2014 (set-window-scroll-bars win 0 'right nil)) ;; not narrow-to-region | regexp always scroll-bars ((and (equal (- point-max point-min) buffer-size) (eq major-mode 'calendar-mode) (sb-regexp-match-p regexp-always-scroll-bar buffer-name)) (set-window-scroll-bars win 15 'right nil)) ;; not narrow-to-region | regexp never scroll-bars ((and (equal (- point-max point-min) buffer-size) (sb-regexp-match-p regexp-never-scroll-bar buffer-name)) (set-window-scroll-bars win 0 'right nil)))))) (defvar sb-mode-display-hook nil "Hook used primarily for `lawlist-scroll-bar-fn'.") (define-minor-mode sb-mode "This is a minor-mode for lawlist-scroll-bar." :init-value nil :lighter " SB" :keymap nil :global nil :group 'sb (cond (sb-mode (add-hook 'window-start-end-hook 'lawlist-scroll-bar-fn nil t) (when (called-interactively-p 'any) (message "Globally turned ON `sb-mode`."))) (t (remove-hook 'window-start-end-hook 'lawlist-scroll-bar-fn t) (set-window-scroll-bars (selected-window) 0 'right nil) (when (called-interactively-p 'any) (message "Globally turned OFF `sb-mode`.") )))) (provide 'lawlist-sb)