From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: npostavs@users.sourceforge.net Newsgroups: gmane.emacs.bugs Subject: bug#5718: scroll-margin in buffer with small line count. Date: Tue, 13 Sep 2016 22:40:29 -0400 Message-ID: <874m5j19wi.fsf@users.sourceforge.net> References: <4B9D1C61.70903@gmail.com> <87mvkjy0l5.fsf@users.sourceforge.net> <83fuqbfhpb.fsf@gnu.org> <87a8ggwcoo.fsf@users.sourceforge.net> <83inv4cc0s.fsf@gnu.org> <87d1ka17dr.fsf@users.sourceforge.net> <834m5l9g1d.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1473820884 21580 195.159.176.226 (14 Sep 2016 02:41:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 14 Sep 2016 02:41:24 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: ahyatt@gmail.com, 5718@debbugs.gnu.org, gavenkoa@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Sep 14 04:41:19 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bk08R-0004Yu-Eb for geb-bug-gnu-emacs@m.gmane.org; Wed, 14 Sep 2016 04:41:15 +0200 Original-Received: from localhost ([::1]:52688 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bk08P-0000j7-49 for geb-bug-gnu-emacs@m.gmane.org; Tue, 13 Sep 2016 22:41:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bk08I-0000j1-Qb for bug-gnu-emacs@gnu.org; Tue, 13 Sep 2016 22:41:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bk08E-0005fD-Ik for bug-gnu-emacs@gnu.org; Tue, 13 Sep 2016 22:41:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:33087) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bk08E-0005f5-Eg for bug-gnu-emacs@gnu.org; Tue, 13 Sep 2016 22:41:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bk08E-0003Kf-4m for bug-gnu-emacs@gnu.org; Tue, 13 Sep 2016 22:41:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: npostavs@users.sourceforge.net Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 14 Sep 2016 02:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 5718 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 5718-submit@debbugs.gnu.org id=B5718.147382081412743 (code B ref 5718); Wed, 14 Sep 2016 02:41:02 +0000 Original-Received: (at 5718) by debbugs.gnu.org; 14 Sep 2016 02:40:14 +0000 Original-Received: from localhost ([127.0.0.1]:59032 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bk07S-0003JT-Bx for submit@debbugs.gnu.org; Tue, 13 Sep 2016 22:40:14 -0400 Original-Received: from mail-it0-f51.google.com ([209.85.214.51]:37621) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bk07Q-0003JA-NQ for 5718@debbugs.gnu.org; Tue, 13 Sep 2016 22:40:13 -0400 Original-Received: by mail-it0-f51.google.com with SMTP id 186so4735961itf.0 for <5718@debbugs.gnu.org>; Tue, 13 Sep 2016 19:40:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=pLN30J/bRnO6gdoGvxRXK0S15QqjBWbN0y+ySybJPdk=; b=aqjapFw6nKV/U/SGz3xGKAdl2gyU/S58I/iJB+ph5EqCVsfC0Q2zOXtpwDNDXo+pJf xGg1geca2mKK67jmmXD6B1/jYIKeiViU+b/8qF9GQ7E6DrjeC95ZnevaorvgdPtlVUKy w7adQl48ld8ZzwQfPET8urfDvvOz/dW4p+UPG+6HUQ+px7e35cCXbfRQ1QGU7Kdcb+BX NyOaAUubjKOvUhQEr4jj0m56N1Knr8MZN7PmGfxec9Q2dHNZi1lSva++F2gFRB2KywPj VnBHRriS62drxKfUu1vBLn0GF/ehLzplnESuyQqFiOEEluY2Fi186KzGIL8U1ocMqZ8S eYdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=pLN30J/bRnO6gdoGvxRXK0S15QqjBWbN0y+ySybJPdk=; b=MeACq1RRmIuLa7jAVQVQfVaIKNaozlWaIR7e4BLKFEmFD1LUriuCYwP1909T7H5eOw fZHYNvP6K/O8oqzfBNXZsfwW82lgBKxT7UMROiQCpwmELLXIASg2AR37SUYLfxOpojYf YtEZpLaZWZqNp4tvo9s+YbHSsjqL03NgbJxi+56+wSLRW3qsDcOKYydVwRIZv5AgjZuh 4WL2asCUKDIg4XYhaE3Ecvoq1pXoP9rup5pDQxJNVy7JPAolPX6wWJgJ6POCBr0wxFM6 ZyA3cV/hjqJXuujXFozQbZ0tUK9+UAr6g6CK51oNufAqokJpIcIV50SRDVh2U42oyFUd UNDw== X-Gm-Message-State: AE9vXwMtcBsWhGz/vbE1X0jXgh7J/dntPEhxgP1n974vRX9weCmOK3oEo9sSSBiowFJ77A== X-Received: by 10.107.11.101 with SMTP id v98mr13353ioi.145.1473820806963; Tue, 13 Sep 2016 19:40:06 -0700 (PDT) Original-Received: from zony ([45.2.7.130]) by smtp.googlemail.com with ESMTPSA id f68sm724293iod.35.2016.09.13.19.40.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Sep 2016 19:40:06 -0700 (PDT) In-Reply-To: <834m5l9g1d.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 12 Sep 2016 20:36:14 +0300") 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" Xref: news.gmane.org gmane.emacs.bugs:123277 Archived-At: Eli Zaretskii writes: >> I have a patch set for fixing this and allowing the user to change the >> maximum margin from 0.25. The latter doesn't quite work perfectly, for >> some reason when setting the maximum margin to 0.5 and scroll-margin to >> 100, `scroll-down-command' doesn't keep point centered in the window, >> even though other commands (e.g. `scroll-up-command') do. > > However, I think we need to solve those glitches as part of > introducing the feature. Setting a margin to half the window size > makes centering point difficult, but since some commands do succeed, > I'm guessing that those commands which succeed have a bug, i.e. they > leave point inside the margin. Is that indeed so? I'm not sure what you mean by "succeed" here. `next-line', `previous-line', and `scroll-up-command' are able to keep point ouside of the margin (thus keeping it centered); `scroll-down-command' leaves it one line down from where it should be. Actually, the above applies to windows with an odd number of lines, I realized I didn't account for the case of an even number of lines, which currently has 0 lines that are outside the margin. I need to change the cap on `max-scroll-margin' to account for this. > > Also, did you test these changes with scroll-conservatively set to > 101? If not, please do, as that setting activates some code parts > that no other option does. I hadn't; trying it out now, it seems to cause `next-line' to also have the bad behaviour of `scroll-down-command' where point is one line too far down. > > A few comments below. > >> @@ -16527,10 +16507,8 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) >> /* Some people insist on not letting point enter the scroll >> margin, even though this part handles windows that didn't >> scroll at all. */ >> - int window_total_lines >> - = WINDOW_TOTAL_LINES (w) * FRAME_LINE_HEIGHT (f) / frame_line_height; >> - int margin = min (scroll_margin, window_total_lines / 4); >> - int pixel_margin = margin * frame_line_height; >> + int margin = window_scroll_margin (w, MARGIN_IN_LINES); >> + int pixel_margin = margin * frame_line_height; >> bool header_line = WINDOW_WANTS_HEADER_LINE_P (w); > >> /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop >> @@ -16814,12 +16792,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) >> it.current_y = it.last_visible_y; >> if (centering_position < 0) >> { >> - int window_total_lines >> - = WINDOW_TOTAL_LINES (w) * FRAME_LINE_HEIGHT (f) / frame_line_height; >> - int margin >> - = scroll_margin > 0 >> - ? min (scroll_margin, window_total_lines / 4) >> - : 0; >> + int margin = window_scroll_margin (w, MARGIN_IN_LINES); >> ptrdiff_t margin_pos = CHARPOS (startp); >> Lisp_Object aggressive; >> bool scrolling_up; >> @@ -17063,10 +17036,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) >> { >> int window_total_lines >> = WINDOW_TOTAL_LINES (w) * FRAME_LINE_HEIGHT (f) / frame_line_height; >> - int margin = >> - scroll_margin > 0 >> - ? min (scroll_margin, window_total_lines / 4) >> - : 0; >> + int margin = window_scroll_margin (w, MARGIN_IN_LINES); >> bool move_down = w->cursor.vpos >= window_total_lines / 2; > > Here you call window_scroll_margin 3 times in the same function. Any > way of doing that only once and reusing the result? Yes, this seems to work: @@ -16173,7 +16173,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) int centering_position = -1; bool last_line_misfit = false; ptrdiff_t beg_unchanged, end_unchanged; - int frame_line_height; + int frame_line_height, margin; bool use_desired_matrix; void *itdata = NULL; @@ -16203,6 +16203,8 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) restart: reconsider_clip_changes (w); frame_line_height = default_line_pixel_height (w); + margin = window_scroll_margin (w, MARGIN_IN_LINES); + /* Has the mode line to be updated? */ update_mode_line = (w->update_mode_line @@ -16507,7 +16509,6 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) /* Some people insist on not letting point enter the scroll margin, even though this part handles windows that didn't scroll at all. */ - int margin = window_scroll_margin (w, MARGIN_IN_LINES); int pixel_margin = margin * frame_line_height; bool header_line = WINDOW_WANTS_HEADER_LINE_P (w); @@ -16792,7 +16793,6 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) it.current_y = it.last_visible_y; if (centering_position < 0) { - int margin = window_scroll_margin (w, MARGIN_IN_LINES); ptrdiff_t margin_pos = CHARPOS (startp); Lisp_Object aggressive; bool scrolling_up; @@ -17036,7 +17036,6 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) { int window_total_lines = WINDOW_TOTAL_LINES (w) * FRAME_LINE_HEIGHT (f) / frame_line_height; - int margin = window_scroll_margin (w, MARGIN_IN_LINES); bool move_down = w->cursor.vpos >= window_total_lines / 2; move_it_by_lines (&it, move_down ? margin + 1 : -(margin + 1)); > > >> @@ -17298,17 +17267,7 @@ try_window (Lisp_Object window, struct text_pos pos, int flags) >> if ((flags & TRY_WINDOW_CHECK_MARGINS) >> && !MINI_WINDOW_P (w)) >> { >> - int this_scroll_margin; >> - int window_total_lines >> - = WINDOW_TOTAL_LINES (w) * FRAME_LINE_HEIGHT (f) / frame_line_height; >> - >> - if (scroll_margin > 0) >> - { >> - this_scroll_margin = min (scroll_margin, window_total_lines / 4); >> - this_scroll_margin *= frame_line_height; >> - } >> - else >> - this_scroll_margin = 0; >> + int this_scroll_margin = window_scroll_margin (w, MARGIN_IN_PIXELS); > >> if ((w->cursor.y >= 0 /* not vscrolled */ >> && w->cursor.y < this_scroll_margin >> @@ -18592,15 +18551,8 @@ try_window_id (struct window *w) > >> /* Don't let the cursor end in the scroll margins. */ >> { >> - int this_scroll_margin, cursor_height; >> - int frame_line_height = default_line_pixel_height (w); >> - int window_total_lines >> - = WINDOW_TOTAL_LINES (w) * FRAME_LINE_HEIGHT (it.f) / frame_line_height; >> - >> - this_scroll_margin = >> - max (0, min (scroll_margin, window_total_lines / 4)); >> - this_scroll_margin *= frame_line_height; >> - cursor_height = MATRIX_ROW (w->desired_matrix, w->cursor.vpos)->height; >> + int this_scroll_margin = window_scroll_margin (w, MARGIN_IN_PIXELS); >> + int cursor_height = MATRIX_ROW (w->desired_matrix, w->cursor.vpos)->height; > >> if ((w->cursor.y < this_scroll_margin >> && CHARPOS (start) > BEGV) > > Same here (in another function). These are 2 different functions: try_window and try_window_id. >> + DEFVAR_LISP ("maximum-scroll-margin", Vmaximum_scroll_margin, >> + doc: /* Maximum effective value of `scroll-margin'. >> +Given as a fraction of the current window's lines. */); > > "as a fraction of the current window's height" sounds better, I > think. (It doesn't matter if the height is in lines or in pixels, > for this purpose.) Makes sense. > >> + Vmaximum_scroll_margin = make_float (0.25); >> + > > We usually call such variables "max-SOMETHING", not > "maximum-SOMETHING". > > Also, the actual value is limited by 0.5, but the doc string doesn't > tell that. It also doesn't say that any non-float value is ignored. > > Finally, the new variable needs to be documented in the user manual > and in NEWS. Okay.