unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#16475: 24.3.50; enhancement request: remove vertical scroll bar automatically when not needed
@ 2014-01-17  4:42 Drew Adams
  2014-01-17 14:35 ` Stefan Monnier
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Drew Adams @ 2014-01-17  4:42 UTC (permalink / raw)
  To: 16475

This was either reported as a bug/enhancement request long ago, or
else it was discussed in emacs-devel long ago.  I don't recall.

I seem to remember, though, that the answer was that this couldn't be
done, at least on MS Windows.  I don't recall the particulars, so
forgive me if I misunderstood or don't remember right.

Anyway, while fiddling a bit, in response to this request on
StackOverflow:
http://stackoverflow.com/questions/21175099/how-to-automatically-add-remove-scroll-bars-on-the-fly

I found something that seems to work OK.  I do not claim that this is a
good way to implement the feature - at all!  But it perhaps shows that
something could maybe be done for this.

I repeat here what I tried, but again, I am not proposing that a
solution would be along these lines.  Just asking that you maybe think a
bit more about whether it is feasible to come up with a satisfactory
solution.

One thing I notice is that if you shrink the text by scaling it that
does not seem to be taken into account by the code I tried: even if all
of the text is easily displayed in the window (because it is small), the
scroll bar does not seem to disappear.

Anyway, this is the code I tried, which seems to "work":

(setq-default
 mode-line-position
 '(:eval
   (progn
     (if (> (count-lines (point-min) (point-max)) (window-height))
	 (set-window-scroll-bars nil 20 t)
       (set-window-scroll-bars nil 1 t)) ; IF TRY ZERO, GET BUG #16474
     `((-3 ,(propertize
	     "%p"
	     'local-map mode-line-column-line-number-mode-map
	     'mouse-face 'mode-line-highlight
	     'help-echo "Buffer position, mouse-1: Line/col menu"))
       (line-number-mode
	((column-number-mode
	  (10 ,(propertize
		" (%l,%c)"
		'face (and (> (current-column)
			      modelinepos-column-limit)
			   'modelinepos-column-warning)
		'local-map mode-line-column-line-number-mode-map
		'mouse-face 'mode-line-highlight
		'help-echo "Line and column, mouse-1: Line/col menu"))
	  (6 ,(propertize
	       " L%l"
	       'local-map mode-line-column-line-number-mode-map
	       'mouse-face 'mode-line-highlight
	       'help-echo "Line number, mouse-1: Line/col menu"))))
	((column-number-mode
	  (5 ,(propertize
	       " C%c"
	       'face (and (> (current-column)
			     modelinepos-column-limit)
			  'modelinepos-column-warning)
	       'local-map mode-line-column-line-number-mode-map
	       'mouse-face 'mode-line-highlight
	       'help-echo "Column number, mouse-1: Line/col menu")))))))))

[BTW, another thing I noticed, after scaling the text smaller in a
buffer that was shown in two windows of the same frame, one above
the other: After evaluating the above code, the mode lines disappeared
temporarily.  I grabbed the area that should have been the mode line of
the top window and dragged it up a bit, and the mode lines showed up
again.  Seems like some redisplay was not happening immediately or
something.]


In GNU Emacs 24.3.50.1 (i686-pc-mingw32)
 of 2014-01-07 on ODIEONE
Bzr revision: 115916 bzg@gnu.org-20140107233629-du2solx6tmxnx0np
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --prefix=/c/Devel/emacs/binary --enable-checking=yes,glyphs
 'CFLAGS=-O0 -g3' LDFLAGS=-Lc:/Devel/emacs/lib
 CPPFLAGS=-Ic:/Devel/emacs/include'





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#16475: 24.3.50; enhancement request: remove vertical scroll bar automatically when not needed
  2014-01-17  4:42 bug#16475: 24.3.50; enhancement request: remove vertical scroll bar automatically when not needed Drew Adams
@ 2014-01-17 14:35 ` Stefan Monnier
  2016-02-12  2:46 ` Keith David Bershatsky
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 15+ messages in thread
From: Stefan Monnier @ 2014-01-17 14:35 UTC (permalink / raw)
  To: Drew Adams; +Cc: 16475

> Anyway, while fiddling a bit, in response to this request on
> StackOverflow:
> http://stackoverflow.com/questions/21175099/how-to-automatically-add-remove-scroll-bars-on-the-fly
[...]
> One thing I notice is that if you shrink the text by scaling it that
> does not seem to be taken into account by the code I tried: even if all

Duh!  Had you followed the link from the above page to http://stackoverflow.com/questions/20923655/how-to-test-whether-lines-of-text-are-greater-than-the-window-height
and read my answer in there, you'd know why.


        Stefan





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#16475: 24.3.50; enhancement request: remove vertical scroll bar automatically when not needed
  2014-01-17  4:42 bug#16475: 24.3.50; enhancement request: remove vertical scroll bar automatically when not needed Drew Adams
  2014-01-17 14:35 ` Stefan Monnier
@ 2016-02-12  2:46 ` Keith David Bershatsky
  2017-10-25  5:27 ` bug#16475: " Keith David Bershatsky
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 15+ messages in thread
From: Keith David Bershatsky @ 2016-02-12  2:46 UTC (permalink / raw)
  To: 16475

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)





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#16475: enhancement request: remove vertical scroll bar automatically when not needed
  2014-01-17  4:42 bug#16475: 24.3.50; enhancement request: remove vertical scroll bar automatically when not needed Drew Adams
  2014-01-17 14:35 ` Stefan Monnier
  2016-02-12  2:46 ` Keith David Bershatsky
@ 2017-10-25  5:27 ` Keith David Bershatsky
  2017-10-25  7:47   ` martin rudalics
  2017-10-25 22:25 ` Keith David Bershatsky
  2017-10-26 16:03 ` Keith David Bershatsky
  4 siblings, 1 reply; 15+ messages in thread
From: Keith David Bershatsky @ 2017-10-25  5:27 UTC (permalink / raw)
  To: 16475

[-- Attachment #1: Type: text/plain, Size: 177 bytes --]

Resending/forwarding message to the correct tracking number; i.e., it should have been 16475 instead of 28936.

;;;;;;;;;;;;;;;;;;;;;; FORWARDED MESSAGE ;;;;;;;;;;;;;;;;;;;;;;


[-- Attachment #2: Type: message/rfc822, Size: 1455 bytes --]

From: Keith David Bershatsky <esq@lawlist.com>
To: 28936@debbugs.gnu.org
Cc: Drew Adams <drew.adams@oracle.com>
Subject: enhancement request: remove vertical scroll bar automatically when not needed
Date: Tue, 24 Oct 2017 20:46:06 -0700
Message-ID: <m21slrc2kh.wl%esq@lawlist.com>

Here is a first draft with a simple test (modifying xdisp.c), which probably nukes more than just the selected window's scroll bars when removing them, but it may be sufficient to revive this enhancement request in the event anyone is interested.

 finish_scroll_bars:

   if ((WINDOW_HAS_VERTICAL_SCROLL_BAR (w) || WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w))
        && ZV - BEGV > BUF_Z (XBUFFER (w->contents)) - w->window_end_pos - marker_position (w->start))
    {
      if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w))
	/* Set the thumb's position and size.  */
	set_vertical_scroll_bar (w);

      if (WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w))
	/* Set the thumb's position and size.  */
	set_horizontal_scroll_bar (w);

      /* Note that we actually used the scroll bar attached to this
	 window, so it shouldn't be deleted at the end of redisplay.  */
      if (FRAME_TERMINAL (f)->redeem_scroll_bar_hook)
        (*FRAME_TERMINAL (f)->redeem_scroll_bar_hook) (w);
    }
    else
      {
        (*FRAME_TERMINAL (f)->condemn_scroll_bars_hook) (f);
        (*FRAME_TERMINAL (f)->judge_scroll_bars_hook) (f);
      }


Keith

^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#16475: enhancement request: remove vertical scroll bar automatically when not needed
  2017-10-25  5:27 ` bug#16475: " Keith David Bershatsky
@ 2017-10-25  7:47   ` martin rudalics
  2017-10-25 14:40     ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: martin rudalics @ 2017-10-25  7:47 UTC (permalink / raw)
  To: Keith David Bershatsky, 16475

 > Here is a first draft with a simple test (modifying xdisp.c), which
 > probably nukes more than just the selected window's scroll bars when
 > removing them, but it may be sufficient to revive this enhancement
 > request in the event anyone is interested.

Thanks for looking into this.  The test for the vertical scroll bar case
is whether the buffer beginning and its end are both visible in the
window, taking into account visibility, overlays and the like.  I'm not
sure whether

         && ZV - BEGV > BUF_Z (XBUFFER (w->contents)) - w->window_end_pos - marker_position (w->start))

can handle that.

Auto-removal of horizontal scroll bars is more complicated.  Basically,
we could remove the horizontal scroll bar when no line in the window had
to be truncated.  But then we have space to display the next buffer line
and that line could be awfully long.  So some lookahead is needed which
will consume processing time.  Obviously, we could just use the check
whether the entire buffer is visible as for the vertical case but that's
not what other applications usually do.

Also, the state of a window is usually reflected in its variables and
parameters.  The question with auto-removal of scroll bars is how we
reflect a new state in functions like ‘window-scroll-bars’ and
‘set-window-scroll-bars’.

Personally I never cared much about this auto-removal because when space
to display things is scarce, usually a buffer cannot be displayed in its
entirety and scroll bars are needed.  When space abandons I don't mind a
scroll bar being present anyway.  But since most applications usually
remove scroll bars when they are not needed we should probably conform.

Thanks again, martin







^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#16475: enhancement request: remove vertical scroll bar automatically when not needed
  2017-10-25  7:47   ` martin rudalics
@ 2017-10-25 14:40     ` Eli Zaretskii
  2017-10-26  7:56       ` martin rudalics
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2017-10-25 14:40 UTC (permalink / raw)
  To: martin rudalics; +Cc: 16475, esq

> Date: Wed, 25 Oct 2017 09:47:00 +0200
> From: martin rudalics <rudalics@gmx.at>
> 
>  > Here is a first draft with a simple test (modifying xdisp.c), which
>  > probably nukes more than just the selected window's scroll bars when
>  > removing them, but it may be sufficient to revive this enhancement
>  > request in the event anyone is interested.
> 
> Thanks for looking into this.  The test for the vertical scroll bar case
> is whether the buffer beginning and its end are both visible in the
> window, taking into account visibility, overlays and the like.  I'm not
> sure whether
> 
>          && ZV - BEGV > BUF_Z (XBUFFER (w->contents)) - w->window_end_pos - marker_position (w->start))
> 
> can handle that.

It at least should be consistent about using BEGV/ZV vs
BUF_BEGV/BUF_ZV.  Either the code assumes that W displays the current
buffer, or it doesn't.

Also, I don't understand the need for this part:

>     else
>       {
>         (*FRAME_TERMINAL (f)->condemn_scroll_bars_hook) (f);
>         (*FRAME_TERMINAL (f)->judge_scroll_bars_hook) (f);
>       }

We already call condemn_scroll_bars_hook at the beginning of a
redisplay cycle, and call judge_scroll_bars_hook at its end.  So why
did you need to do it here again, for each window separately?

More importantly, removing the scroll bar resizes the external
dimensions of the frame, to keep the windows' dimensions unchanged
(otherwise, we couldn't remove the scroll bars at the very end of the
window's redisplay).  You can see this in action if you toggle
scroll-bar-mode on and off.  So when the window shows _almost_ all the
text of the buffer, the frame would annoyingly oscillate in its
horizontal dimension.  This could be caused, for example, by echo-area
messages that resize the mini-window from time to time, or by the user
adjusting the window size.

By contrast, other applications I saw that remove the scroll bar when
it is not needed leave the frame's dimensions alone, and instead leave
more space for text display.  That is much better, but doing this in
Emacs would require to restructure the code that deals with the scroll
bars, because we cannot change window dimensions after all the
redisplay decisions were made, without requiring one more redisplay
cycle.

> Auto-removal of horizontal scroll bars is more complicated.  Basically,
> we could remove the horizontal scroll bar when no line in the window had
> to be truncated.  But then we have space to display the next buffer line
> and that line could be awfully long.

Actually, I think what happens with the removal of the horizontal
scroll bar mirrors the vertical scroll bar, just in the other
dimension.  Namely, the frame's height is modified to leave the
windows' dimensions unaltered.  But again, this could easily cause
annoying "oscillations" of the frame borders.

So if we want to have this feature, it must be an opt-in, and I'd be
interested how many people will like it.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#16475: enhancement request: remove vertical scroll bar automatically when not needed
  2014-01-17  4:42 bug#16475: 24.3.50; enhancement request: remove vertical scroll bar automatically when not needed Drew Adams
                   ` (2 preceding siblings ...)
  2017-10-25  5:27 ` bug#16475: " Keith David Bershatsky
@ 2017-10-25 22:25 ` Keith David Bershatsky
  2017-10-26 16:30   ` Eli Zaretskii
  2017-10-26 16:03 ` Keith David Bershatsky
  4 siblings, 1 reply; 15+ messages in thread
From: Keith David Bershatsky @ 2017-10-25 22:25 UTC (permalink / raw)
  To: Eli Zaretskii, Martin Rudalics; +Cc: 16475

Thank you, Eli and Martin:

I have incorporated the comment of Eli about being consistent by using BEGV/ZV vs BUF_BEGV/BUF_ZV.

I have created a second draft based (in part) on the comment of Martin:  "The test for the vertical scroll bar case is whether the buffer beginning and its end are both visible in the window, taking into account visibility, overlays and the like."

The visibility test for the beginning/ending points can be added in future drafts.

Scroll bars are not immediately removed, however, when `window_contents_visible_p` is true and this-command is a keyboard stroke.  I encountered the same problem with the first draft, and that is why I looked for a means to force immediate removal of the scroll bars by using the condemn/judge combination.  Subsequently using the mouse scroll wheel *does* trigger scroll bar removal.

Any ideas on how to immediately remove scroll bars from the target window when `window_contents_visible_p` is true?  [I have chosen the end of `redisplay_window` to perform the test because window start/end *should be* accurate at that location of the code.]

  ptrdiff_t bob_disregard_narrow = BUF_BEG (buffer);
  ptrdiff_t eob_disregard_narrow = BUF_Z (buffer);

  ptrdiff_t bob_respect_narrow = BUF_BEGV (buffer);
  ptrdiff_t eob_respect_narrow = BUF_ZV (buffer);

  ptrdiff_t window_start = marker_position (w->start);
  ptrdiff_t window_end = eob_disregard_narrow - w->window_end_pos;

  ptrdiff_t buffer_size = eob_disregard_narrow - bob_disregard_narrow;

  bool buffer_narrowed_p = (eob_respect_narrow - bob_respect_narrow != buffer_size);

  bool window_contents_visible_p = (bob_respect_narrow == window_start
                                    && eob_respect_narrow == window_end);

 finish_scroll_bars:

   if ((WINDOW_HAS_VERTICAL_SCROLL_BAR (w) || WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w))
        && !window_contents_visible_p)
    {
      if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w))
	/* Set the thumb's position and size.  */
	set_vertical_scroll_bar (w);

      if (WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w))
	/* Set the thumb's position and size.  */
	set_horizontal_scroll_bar (w);

      /* Note that we actually used the scroll bar attached to this
	 window, so it shouldn't be deleted at the end of redisplay.  */
      if (FRAME_TERMINAL (f)->redeem_scroll_bar_hook)
        (*FRAME_TERMINAL (f)->redeem_scroll_bar_hook) (w);
    }

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DATE:  [10-25-2017 07:40:24] <25 Oct 2017 17:40:24 +0300>
FROM:  Eli Zaretskii <eliz@gnu.org>
> 
> * * *
> 
> It at least should be consistent about using BEGV/ZV vs
> BUF_BEGV/BUF_ZV.  Either the code assumes that W displays the current
> buffer, or it doesn't.
> 
> Also, I don't understand the need for this part:
> 
> >     else
> >       {
> >         (*FRAME_TERMINAL (f)->condemn_scroll_bars_hook) (f);
> >         (*FRAME_TERMINAL (f)->judge_scroll_bars_hook) (f);
> >       }
> 
> We already call condemn_scroll_bars_hook at the beginning of a
> redisplay cycle, and call judge_scroll_bars_hook at its end.  So why
> did you need to do it here again, for each window separately?





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#16475: enhancement request: remove vertical scroll bar automatically when not needed
  2017-10-25 14:40     ` Eli Zaretskii
@ 2017-10-26  7:56       ` martin rudalics
  2017-10-26 15:59         ` Eli Zaretskii
  2017-10-27  2:44         ` Richard Stallman
  0 siblings, 2 replies; 15+ messages in thread
From: martin rudalics @ 2017-10-26  7:56 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 16475, esq

 > More importantly, removing the scroll bar resizes the external
 > dimensions of the frame, to keep the windows' dimensions unchanged
 > (otherwise, we couldn't remove the scroll bars at the very end of the
 > window's redisplay).  You can see this in action if you toggle
 > scroll-bar-mode on and off.  So when the window shows _almost_ all the
 > text of the buffer, the frame would annoyingly oscillate in its
 > horizontal dimension.  This could be caused, for example, by echo-area
 > messages that resize the mini-window from time to time, or by the user
 > adjusting the window size.

Obviously, an equivalent of ‘set-window-scroll-bars’ would have to be
used here.

 > By contrast, other applications I saw that remove the scroll bar when
 > it is not needed leave the frame's dimensions alone, and instead leave
 > more space for text display.  That is much better, but doing this in
 > Emacs would require to restructure the code that deals with the scroll
 > bars, because we cannot change window dimensions after all the
 > redisplay decisions were made, without requiring one more redisplay
 > cycle.

We cannot simply remove scroll bars by "clearing" the unused space with
the window's background whatever that is.  There might be a highlighted
region or some other background that extends to the end of the line on
any line displayed in that window.  And obviously we have to "move" the
fringes and the margins to the right and I didn't even talk about scroll
bars on the left ...

 >> Auto-removal of horizontal scroll bars is more complicated.  Basically,
 >> we could remove the horizontal scroll bar when no line in the window had
 >> to be truncated.  But then we have space to display the next buffer line
 >> and that line could be awfully long.
 >
 > Actually, I think what happens with the removal of the horizontal
 > scroll bar mirrors the vertical scroll bar, just in the other
 > dimension.  Namely, the frame's height is modified to leave the
 > windows' dimensions unaltered.  But again, this could easily cause
 > annoying "oscillations" of the frame borders.

Again ‘set-window-scroll-bars’ would take care of that.

martin






^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#16475: enhancement request: remove vertical scroll bar automatically when not needed
  2017-10-26  7:56       ` martin rudalics
@ 2017-10-26 15:59         ` Eli Zaretskii
  2017-10-27  8:25           ` martin rudalics
  2017-10-27  2:44         ` Richard Stallman
  1 sibling, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2017-10-26 15:59 UTC (permalink / raw)
  To: martin rudalics; +Cc: 16475, esq

> Date: Thu, 26 Oct 2017 09:56:59 +0200
> From: martin rudalics <rudalics@gmx.at>
> CC: esq@lawlist.com, 16475@debbugs.gnu.org
> 
>  > More importantly, removing the scroll bar resizes the external
>  > dimensions of the frame, to keep the windows' dimensions unchanged
>  > (otherwise, we couldn't remove the scroll bars at the very end of the
>  > window's redisplay).  You can see this in action if you toggle
>  > scroll-bar-mode on and off.  So when the window shows _almost_ all the
>  > text of the buffer, the frame would annoyingly oscillate in its
>  > horizontal dimension.  This could be caused, for example, by echo-area
>  > messages that resize the mini-window from time to time, or by the user
>  > adjusting the window size.
> 
> Obviously, an equivalent of ‘set-window-scroll-bars’ would have to be
> used here.

I agree, but then the right place to call this is not from redisplay,
but from keyboard.c, before it calls read_char (which calls
redisplay).  set-window-scroll-bars triggers a redisplay cycle, so
calling it from (the end of) redisplay is not very wise, IMO.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#16475: enhancement request: remove vertical scroll bar automatically when not needed
  2014-01-17  4:42 bug#16475: 24.3.50; enhancement request: remove vertical scroll bar automatically when not needed Drew Adams
                   ` (3 preceding siblings ...)
  2017-10-25 22:25 ` Keith David Bershatsky
@ 2017-10-26 16:03 ` Keith David Bershatsky
  2017-10-26 17:07   ` Eli Zaretskii
  4 siblings, 1 reply; 15+ messages in thread
From: Keith David Bershatsky @ 2017-10-26 16:03 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 16475

The values for window-start and window-end will not necessarily be accurate until somewhere towards the end of redisplay.  A test that relies upon those values to add/remove scroll bars will often fail.

Keith

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DATE:  [10-26-2017 08:59:02] <26 Oct 2017 18:59:02 +0300>
FROM:  Eli Zaretskii <eliz@gnu.org>
> 
> * * *
> 
> I agree, but then the right place to call this is not from redisplay,
> but from keyboard.c, before it calls read_char (which calls
> redisplay).  set-window-scroll-bars triggers a redisplay cycle, so
> calling it from (the end of) redisplay is not very wise, IMO.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#16475: enhancement request: remove vertical scroll bar automatically when not needed
  2017-10-25 22:25 ` Keith David Bershatsky
@ 2017-10-26 16:30   ` Eli Zaretskii
  0 siblings, 0 replies; 15+ messages in thread
From: Eli Zaretskii @ 2017-10-26 16:30 UTC (permalink / raw)
  To: Keith David Bershatsky; +Cc: 16475

> Date:  Wed, 25 Oct 2017 15:25:40 -0700
> From:  Keith David Bershatsky <esq@lawlist.com>
> Cc:  16475@debbugs.gnu.org
> 
> Scroll bars are not immediately removed, however, when `window_contents_visible_p` is true and this-command is a keyboard stroke.

Most probably because some redisplay optimization bypasses your code.

> Any ideas on how to immediately remove scroll bars from the target window when `window_contents_visible_p` is true?  [I have chosen the end of `redisplay_window` to perform the test because window start/end *should be* accurate at that location of the code.]

Like I said: I think the way this works will cause annoying visual
effects, so I propose to call set-window-scroll-bars from keyboard.c,
before we enter redisplay.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#16475: enhancement request: remove vertical scroll bar automatically when not needed
  2017-10-26 16:03 ` Keith David Bershatsky
@ 2017-10-26 17:07   ` Eli Zaretskii
  2017-10-27  8:26     ` martin rudalics
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2017-10-26 17:07 UTC (permalink / raw)
  To: Keith David Bershatsky; +Cc: 16475

> Date:  Thu, 26 Oct 2017 09:03:10 -0700
> From:  Keith David Bershatsky <esq@lawlist.com>
> Cc:  16475@debbugs.gnu.org,Martin Rudalics <rudalics@gmx.at>
> 
> The values for window-start and window-end will not necessarily be accurate until somewhere towards the end of redisplay.  A test that relies upon those values to add/remove scroll bars will often fail.

We have the ability to check whether the entire buffer fits in the
window without actually displaying it.  The move_it_to function can be
used for that.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#16475: enhancement request: remove vertical scroll bar automatically when not needed
  2017-10-26  7:56       ` martin rudalics
  2017-10-26 15:59         ` Eli Zaretskii
@ 2017-10-27  2:44         ` Richard Stallman
  1 sibling, 0 replies; 15+ messages in thread
From: Richard Stallman @ 2017-10-27  2:44 UTC (permalink / raw)
  To: martin rudalics; +Cc: 16475, esq

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

I would find it annoying for the scroll bar to appear and disappear.
I have nothing against offering that feature
but I'd like to turn it off.

-- 
Dr Richard Stallman
President, Free Software Foundation (gnu.org, fsf.org)
Internet Hall-of-Famer (internethalloffame.org)
Skype: No way! See stallman.org/skype.html.






^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#16475: enhancement request: remove vertical scroll bar automatically when not needed
  2017-10-26 15:59         ` Eli Zaretskii
@ 2017-10-27  8:25           ` martin rudalics
  0 siblings, 0 replies; 15+ messages in thread
From: martin rudalics @ 2017-10-27  8:25 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 16475, esq

 >> Obviously, an equivalent of ‘set-window-scroll-bars’ would have to be
 >> used here.
 >
 > I agree, but then the right place to call this is not from redisplay,
 > but from keyboard.c, before it calls read_char (which calls
 > redisplay).  set-window-scroll-bars triggers a redisplay cycle, so
 > calling it from (the end of) redisplay is not very wise, IMO.

It's ecologically questionable in any case: After every change affecting
the buffer (insertion/deletion, overlays, visibility) we'd have to check
whether its text still fits into its window(s) and then either add or
remove the scroll bar(s).  And note that we may scroll lines out of view
(and thus implicitly should show a vertical scroll bar) even when the
text would entirely fit into its window.

martin






^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#16475: enhancement request: remove vertical scroll bar automatically when not needed
  2017-10-26 17:07   ` Eli Zaretskii
@ 2017-10-27  8:26     ` martin rudalics
  0 siblings, 0 replies; 15+ messages in thread
From: martin rudalics @ 2017-10-27  8:26 UTC (permalink / raw)
  To: Eli Zaretskii, Keith David Bershatsky; +Cc: 16475

 > We have the ability to check whether the entire buffer fits in the
 > window without actually displaying it.  The move_it_to function can be
 > used for that.

Or ‘window-text-pixel-size’.

martin






^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2017-10-27  8:26 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-17  4:42 bug#16475: 24.3.50; enhancement request: remove vertical scroll bar automatically when not needed Drew Adams
2014-01-17 14:35 ` Stefan Monnier
2016-02-12  2:46 ` Keith David Bershatsky
2017-10-25  5:27 ` bug#16475: " Keith David Bershatsky
2017-10-25  7:47   ` martin rudalics
2017-10-25 14:40     ` Eli Zaretskii
2017-10-26  7:56       ` martin rudalics
2017-10-26 15:59         ` Eli Zaretskii
2017-10-27  8:25           ` martin rudalics
2017-10-27  2:44         ` Richard Stallman
2017-10-25 22:25 ` Keith David Bershatsky
2017-10-26 16:30   ` Eli Zaretskii
2017-10-26 16:03 ` Keith David Bershatsky
2017-10-26 17:07   ` Eli Zaretskii
2017-10-27  8:26     ` martin rudalics

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).