emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scroll-down with pixel transition


From: Tak Kunihiro
Subject: Re: scroll-down with pixel transition
Date: Sun, 16 Apr 2017 17:35:41 +0900 (JST)

I revised the code to respond to your comments.  I attach the revised
file and diff.

* REMAINED ISSUES

1. On Info, pixel-scroll-down-and-set-window-vscroll cannot
   scroll-down sometimes.  Please see detail below, and help
   me.

2. Name of a function was changed from pixel--sweep-pixel-up to
   pixel--scroll-pixel-up.  Still verb does not sound right.  Please
   see detail below, and suggest me.

* EACH RESPONSE:

>> The top-level functions need to be more robust.  For example, I see
>> glitches during scroll-down on Info.
> 
> Probably due to Info using fonts of different sizes.

This I cannot find out how to solve.  With emacs -Q, on top info page,
goto point-max, then I cannot scroll-down using
`pixel-scroll-down-and-set-window-vscroll' when larger font sits on
the top of window.  Can you solve this?

>> ;;; This file is NOT part of GNU Emacs
> 
> Should be changed once this is in core.

I changed to is to `part of GNU Emacs'.  This can be too early.

>> (defgroup pixel-scroll nil
>>   "Scroll pixel-by-pixel in Emacs."
>>   :group 'mouse
>>   :prefix "pixel-")
> 
> I see no need for a new group, please use the existing group
> 'scrolling'.

I changed all to :group 'scrolling.

>> (defcustom pixel-wait 0.001
>>   "Idle time on pixel scroll specified in second."
>>   :group 'pixel-scroll
>>   :type 'float)
> 
> The doc string should say a bit more to explain the user-visible
> effect of the value.

I revised the doc string to "Idle time on a pixel scroll specified in
second.  More wait will retult in slow and gentle scroll."

> Also, please add a ':version' tag to each defcustom.

I put each defcustom :version "26.1".

>> (defcustom pixel-amount '(1 ((shift) . 5) ((control)))
>>   "Amount to scroll by when spinning the mouse wheel."
>>   :group 'pixel-scroll)
> 
> Do we really need a separate defcustom for this?  Why not use
> mouse-wheel-scroll-amount?

It is not necessary.  I removed it.

>> (defcustom pixel-resolution-fine-p nil
>>   "Enhance scrolling resolution to pixel-to-pixel instead of
>> line-to-line."
>>   :group 'pixel-scroll
>>   :type 'boolean)
> 
> Not sure this should be advertised, as the functionality has issues.
> At the very least those issues should be described in the doc string.

I changed it to defvar and revised the doc string to "Increase
scrolling resolution to a pixel instead of a line.  After a pixel
scroll, typing C-n or C-p scrolls the window to make it fully visible,
and undos the effect of the pixel-level scroll."

>>         (vertical-motion -2))) ; FIXME: -1 gives glitch
> 
> What glitch is that?

This was related to implementation of pixel-point-at-bottom-p.  Now
the glitch disappeared (at least I think).

>> (defun pixel-point-at-top-p ()
>>   "Return if point is at top of a window."
>>   (equal (save-excursion (beginning-of-visual-line)
>>                          (point-at-bol))
>>          (window-start)))
> 
> I think this will fail with bidirectional text, if the first character
> in the logical order is not displayed at the leftmost screen position
> of the first line of the window.
> 
> I suggest to use posn-at-point instead.

Thank you for such good suggestion!  I revised as shown below.

(defun pixel-point-at-top-p ()
  "Return if point is at top of a window."
  (<= (cdr (posn-x-y (posn-at-point)))
      (line-pixel-height)))

>> (defun pixel-point-at-bottom-p ()
>>   "Return if point is at bottom of a window."
>>   (<= (count-lines (save-excursion
>>                      (beginning-of-visual-line)
>>                      (point-at-bol))
>>                    (pixel-window-end)) 1))
> 
> Likewise here, I suggest to use window-end and posn-at-point.

I revised as suggested, as shown below.  I used
window-inside-pixel-edges instead of window-end.  Correct me if
something is not correct.

(defun pixel-point-at-bottom-p ()
  "Return if point is at bottom of a window."
  (let* ((edges (window-inside-pixel-edges))
         (height (- (nth 3 edges) (nth 1 edges))) ; bottom - top
         (mergin (- height (cdr (posn-x-y (posn-at-point))))))
    (<= mergin
        (* 2 (line-pixel-height)))))

>> (defun pixel--catch-line-up ()
>>   "Flush text upward a line with pixel transition.  When `vscroll' is 
>> non-zero,
>> complete scrolling a line.  When `vscroll' is larger than height
>> of multiple lines, for example 88, this flushes multiple lines.
>> At the end, `vscroll' will be zero.  This assumes that the lines
>> are with the same height.  Scope moves downward.  This function
>> returns number of pixels that were scrolled."
> 
> I'm not sure what you mean by "flush" here.  And why the function's
> name uses 'catch' if you mean 'flush'?

Inconsistent expression was removed.  Now the name is just
pixel--scroll-line-up.  I put two hyphens because this should be
regarded as lower level one.

>> (defun pixel--sweep-pixel-up (n)
>>   "Sweep text upward to N pixels.  Scope moves downward."
> 
> Maybe I'm misunderstanding what this does, but "sweep" doesn't seem to
> describe it.

This is because I cannot find a good verb to describe its
functionality.  I change pixel--sweep-pixel-up to
pixel--scroll-pixel-up for now.  Note that there is
pixel-scroll-pixel-up already and the new name is source of confusion.
Can you read the code suggest a name (or verb)?

>> (defun pixel-window-end ()
>>   "Return position of the last character of fully-visible line in
>> WINDOW.  This is similar to `window-end' but see a full visible
>> line."
>>   (let ((pos (window-end)))
>>     (if (pos-visible-in-window-p pos nil t)
>>         pos
>>       (save-excursion
>>         (goto-char pos)
>>         (vertical-motion -2)
>>         (point-at-bol)))))
> 
> I don't understand the 'else' part here.  What situation does it
> handle?  AFAIU, if pos-visible-in-window-p returns nil in this case,
> the window-end position is completely invisible, which is something
> that cannot happen, I think.

Since pixel-point-at-bottom-p was improved, this disappeared.

>> (defun pixel-line-height (&optional pos)
>>   "Measure line height of POS in pixel.  When height of all lines
>> are equal, you don't need this function but `frame-char-height'.
>> See Info node `(elisp) Line Height'."
>>   (or pos (setq pos (window-start)))
>             ^^^^^^^^^^^^^^^^^^^^^^^^
> This part is not mentioned in the doc string, so the situation where
> POS is unspecified is left undefined.

I revised the doc string to "Return height in pixels of text line
of POS in the selected window.  When POS is nil, height of the first
line of the window is provided.  When height of all lines are equal,
you don't need this function but `frame-char-height'.  See Info node
`(elisp) Line Height'."

>> (defun pixel-scroll-down-and-set-window-vscroll (vscroll)
>>   "Scroll down a line and set VSCROLL in pixel.  This is written
>> by Eli Zaretskii.  It is important to call `set-window-start' to
>> force the display engine use that particular position as the
>> window-start point.  Otherwise, redisplay will reset the window's
>> vscroll."
> 
> We don't put such information in the doc strings, certainly not
> authorship.  Comments are more appropriate, and you could simply cite
> the emacs-devel message by its URL.

I revise the doc string to "Scroll down a line and set VSCROLL in
pixels.  This is code is presented at
https://lists.gnu.org/archive/html/emacs-devel/2017-04/msg00366.html.
It is important to call `set-window-start' to force the display engine
use that particular position as the window-start point.  Otherwise,
redisplay will reset the window's vscroll."
;;; pixel-scroll.el --- Scroll a line smoothly

;; Package-Requires: ((emacs "24.5"))
;; Version: 1.0.0
;; Package-Version: 20170416.1713
;; Keywords: convenience, usability

;;; This file is part of GNU Emacs

;;; License

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.

;;; Commentary:

;; To interactively toggle the mode on / off:
;;
;;   M-x pixel-scroll-mode
;;
;; To make the mode permanent, put this in your init file:
;;
;;   (require 'pixel-scroll)
;;   (pixel-scroll-mode 1)
;;
;; This package offers a global minor mode which makes Emacs scroll
;; vertically with feel of modern applications.  This minor mode
;; offers pixel-by-pixel scroll upward by mouse wheel using
;; `set-window-vscroll', `window-vscroll', and `scroll-up'.  The minor
;; mode overwrites parameters defined in `mwheel.el' to refer
;; `pixel-scroll-up' and `pixel-scroll-down' instead of `scroll-up'
;; and `scroll-down'.

;;; Principle of vertical scroll:

;; Scrolling text upward a line by pixels using `set-window-vscroll'
;; and by a line using `scroll-up' gives similar visual feedback when
;; vscroll location is @0.  Note vscroll location is vertical shift
;; obtained by `window-vscroll'.  Line height by pixel is obtained by
;; `frame-char-height' (to be exact, this is true for buffer with
;; mono-sized font).  Following two lines scroll text in similar
;; fashion, visually.
;;
;;   (scroll-up 1)
;;   (set-window-vscroll nil (frame-char-height) t)
;;
;; Scrolling text upward by a pixel and a line yields similar result
;; when vscroll location is at the last pixel.  Following two lines
;; scroll text in similar fashion, visually.
;;
;;   (scroll-up 1)
;;   (set-window-vscroll nil (1- (frame-char-height) t)) (scroll-up 1)
;;
;; When vscroll gets larger and as soon as point is beyond beginning
;; of a window, vscroll is set to zero.  To user, scope is changed
;; suddenly without point moved.  This package tries to scroll text
;; upward by a line with pixel-by-pixel transition by following
;; sequences.
;;
;;   (progn
;;     (vertical-motion 1)
;;     (dolist (vs (number-sequence 1 (1- (frame-char-height))))
;;       (set-window-vscroll nil vs t) (sit-for 0.001))
;;     (scroll-up 1))


;;; Change Log:

;; 20170319.1153
;;  - Replace `frame-char-height' by `line-pixel-height'.
;; 20170414.0958
;;  - Algorithm to scroll-down is offered by Eli Zaretskii.
;;  - Implement scroll pixel-by-pixel upward.

;;; Todo:
;; - Estimate height of unseen line at the top, on scrolling down.
;; - Handle error to scroll stable For now, Scroll does not well in Info.

;;; Long term concern:
;; - Allowing pixel-level scrolling in Emacs requires a thorough
;;   review of the related functionalities, to make sure none of them
;;   zeroes out vscroll where users won't want that.

;;; Code:

(require 'mwheel)

(defcustom pixel-wait 0.001
  "Idle time on a pixel scroll specified in second.  More wait
will retult in slow and gentle scroll."
  :group 'scrolling
  :version "26.1"
  :type 'float)

(defvar pixel-resolution-fine-p nil
  "Increase scrolling resolution to a pixel instead of a line.
After a pixel scroll, typing C-n or C-p scrolls the window to
make it fully visible, and undos the effect of the pixel-level
scroll.")

(define-minor-mode pixel-scroll-mode
  "A minor mode to scroll text pixel-by-pixel.  With a prefix argument ARG,
enable Pixel Scroll mode if ARG is positive, and disable it
otherwise.  If called from Lisp, enable Pixel Scroll mode if ARG
is omitted or nil."
  :init-value nil
  :group 'scrolling
  :global t

  (if pixel-scroll-mode
      (progn (setq mwheel-scroll-up-function 'pixel-scroll-up)
             (setq mwheel-scroll-down-function 'pixel-scroll-down))
    (setq mwheel-scroll-up-function 'scroll-up)
    (setq mwheel-scroll-down-function 'scroll-down)))

(defun pixel-scroll-up (&optional arg)
  "Scroll text of selected window up ARG lines.  This is
alternative of `scroll-up'.  Scope moves downward."
  (interactive)
  (or arg (setq arg 1))
  (dotimes (ii arg) ; move scope downward
    (if (<= (count-lines (window-start) (window-end)) 2)
        (scroll-up 1) ; when end of scroll is close, relay on robust guy
      (when (or (pixel-point-at-top-p) ; prevent too late
                (and scroll-preserve-screen-position
                     (not (pixel-point-at-bottom-p)))) ; prevent too fast
        (vertical-motion 1)) ; move point downward
      (pixel-scroll-pixel-up (if pixel-resolution-fine-p
                                 1
                               (pixel-line-height)))))) ; move scope downward

(defun pixel-scroll-down (&optional arg)
  "Scroll text of selected window down ARG lines.  This is
alternative of `scroll-down'.  Scope moves upward."
  (interactive)
  (or arg (setq arg 1))
  (dotimes (ii arg)
    (if (equal (window-start) (point-min))
        (scroll-down 1) ; when beginning-of-buffer is seen, relay on robust guy
      (when (or (pixel-point-at-bottom-p) ; prevent too late
                (and scroll-preserve-screen-position
                     (not (pixel-point-at-top-p)))) ; prevent too fast
        (vertical-motion -1)))
    (pixel-scroll-pixel-down (if pixel-resolution-fine-p
                                 1
                               (pixel-line-height)))))

(defun pixel-point-at-top-p ()
  "Return if point is at top of a window."
  (<= (cdr (posn-x-y (posn-at-point)))
      (line-pixel-height)))

(defun pixel-point-at-bottom-p ()
  "Return if point is at bottom of a window."
  (let* ((edges (window-inside-pixel-edges))
         (height (- (nth 3 edges) (nth 1 edges))) ; bottom - top
         (mergin (- height (cdr (posn-x-y (posn-at-point))))))
    (<= mergin
        (* 2 (line-pixel-height)))))

(defun pixel-scroll-pixel-up (amt)
  "Scroll text of selected windows up AMT pixels.  Scope moves
downward."
  (while (>= (+ (window-vscroll nil t) amt)
             (pixel-line-height))
    (setq amt (- amt (pixel--scroll-line-up)))) ; major scroll
  (pixel--scroll-pixel-up amt)) ; minor scroll

(defun pixel-scroll-pixel-down (amt)
  "Scroll text of selected windows down AMT pixels.  Scope moves
upward."
  ;; FIXME: Cannot scroll down on Info sometimes
  (while (> amt 0)
    (let ((vs (window-vscroll nil t)))
      (if (equal vs 0)
          (pixel-scroll-down-and-set-window-vscroll (1- (pixel-line-height)))
        (set-window-vscroll nil (1- vs) t))
      (setq amt (1- amt))
      (sit-for pixel-wait))))

(defun pixel--scroll-line-up ()
  "Scroll text upward a line with pixel transition.  When `vscroll' is non-zero,
complete scrolling a line.  When `vscroll' is larger than height
of multiple lines, for example 88, this flushes multiple lines.
At the end, `vscroll' will be zero.  This assumes that the lines
are with the same height.  Scope moves downward.  This function
returns number of pixels that were scrolled."
  (let* ((src (window-vscroll nil t))  ; EXAMPLE (initial)      @0   @8  @88
         (height (pixel-line-height))  ;                        25   25   23
         (line (1+ (/ src height)))    ; catch up + one line    Δ1   Δ1   Δ4
         (dst (* line height))         ; goal                  @25  @25  @92
         (delta (- dst src)))          ; pixels to be scrolled  25   17    4
    (pixel--scroll-pixel-up (1- delta)) ; sweep until one less  @24  @24  @91
    (scroll-up line) (sit-for pixel-wait) ; scroll 1 pixel      @0   @0   @0
    delta))

(defun pixel--scroll-pixel-up (n)
  "Scroll text upward to N pixels with pixel transition.  Scope
moves downward."
  (when (> n 0)
    (let ((vs0 (window-vscroll nil t)))
      (dolist (vs (number-sequence (1+ vs0) (+ vs0 n)))
        (set-window-vscroll nil vs t) (sit-for pixel-wait)))))

(defun pixel-line-height (&optional pos)
  "Return height in pixels of text line of POS in the selected
window.  When POS is nil, height of the first line of the window
is provided.  When height of all lines are equal, you don't need
this function but `frame-char-height'.  See Info node `(elisp)
Line Height'."
  (or pos (setq pos (window-start)))
  (save-excursion
    (goto-char pos)
    (line-pixel-height)))

(defun pixel-scroll-down-and-set-window-vscroll (vscroll)
  "Scroll down a line and set VSCROLL in pixels.  This is code is
presented at
https://lists.gnu.org/archive/html/emacs-devel/2017-04/msg00366.html.
It is important to call `set-window-start' to force the display
engine use that particular position as the window-start point.
Otherwise, redisplay will reset the window's vscroll."
  (let ((pos
         (save-excursion
           (goto-char (window-start))
           (beginning-of-visual-line 0))))
    (set-window-start nil pos t)
    (set-window-vscroll nil vscroll t)))

(provide 'pixel-scroll)
;;; pixel-scroll.el ends here
--- pixel-scroll.20170415.el    2017-04-15 07:22:47.387221900 +0900
+++ pixel-scroll.el     2017-04-16 17:13:55.185671600 +0900
@@ -2,10 +2,10 @@
 
 ;; Package-Requires: ((emacs "24.5"))
 ;; Version: 1.0.0
-;; Package-Version: 20170415.0722
+;; Package-Version: 20170416.1713
 ;; Keywords: convenience, usability
 
-;;; This file is NOT part of GNU Emacs
+;;; This file is part of GNU Emacs
 
 ;;; License
 
@@ -75,12 +75,6 @@
 ;;       (set-window-vscroll nil vs t) (sit-for 0.001))
 ;;     (scroll-up 1))
 
-;;; Remarks:
-
-;; If you want to try pixel-level scrolling, that is in the middle of
-;; implementation, also include following in your init file:
-;;
-;;   (setq pixel-resolution-fine-p t)
 
 ;;; Change Log:
 
@@ -95,32 +89,26 @@
 ;; - Handle error to scroll stable For now, Scroll does not well in Info.
 
 ;;; Long term concern:
-;; - After a pixel scroll, typing C-n or C-p scrolls the window to make
-;;   it fully visible, and undos the effect of the pixel-level scroll.
+;; - Allowing pixel-level scrolling in Emacs requires a thorough
+;;   review of the related functionalities, to make sure none of them
+;;   zeroes out vscroll where users won't want that.
 
 ;;; Code:
 
 (require 'mwheel)
 
-(defgroup pixel-scroll nil
-  "Scroll pixel-by-pixel in Emacs."
-  :group 'mouse
-  :prefix "pixel-")
-
 (defcustom pixel-wait 0.001
-  "Idle time on pixel scroll specified in second."
-  :group 'pixel-scroll
+  "Idle time on a pixel scroll specified in second.  More wait
+will retult in slow and gentle scroll."
+  :group 'scrolling
+  :version "26.1"
   :type 'float)
 
-(defcustom pixel-amount '(1 ((shift) . 5) ((control)))
-  "Amount to scroll by when spinning the mouse wheel."
-  :group 'pixel-scroll)
-
-(defcustom pixel-resolution-fine-p nil
-  "Enhance scrolling resolution to pixel-to-pixel instead of
-line-to-line."
-  :group 'pixel-scroll
-  :type 'boolean)
+(defvar pixel-resolution-fine-p nil
+  "Increase scrolling resolution to a pixel instead of a line.
+After a pixel scroll, typing C-n or C-p scrolls the window to
+make it fully visible, and undos the effect of the pixel-level
+scroll.")
 
 (define-minor-mode pixel-scroll-mode
   "A minor mode to scroll text pixel-by-pixel.  With a prefix argument ARG,
@@ -128,19 +116,14 @@
 otherwise.  If called from Lisp, enable Pixel Scroll mode if ARG
 is omitted or nil."
   :init-value nil
-  :group 'pixel-scroll
+  :group 'scrolling
   :global t
 
   (if pixel-scroll-mode
       (progn (setq mwheel-scroll-up-function 'pixel-scroll-up)
-             (setq mwheel-scroll-down-function 'pixel-scroll-down)
-             (setq mouse-wheel-scroll-amount pixel-amount)
-             (setq mouse-wheel-progressive-speed pixel-resolution-fine-p))
+             (setq mwheel-scroll-down-function 'pixel-scroll-down))
     (setq mwheel-scroll-up-function 'scroll-up)
-    (setq mwheel-scroll-down-function 'scroll-down)
-    (dolist (var '(mouse-wheel-scroll-amount
-                   mouse-wheel-progressive-speed))
-      (custom-reevaluate-setting var))))
+    (setq mwheel-scroll-down-function 'scroll-down)))
 
 (defun pixel-scroll-up (&optional arg)
   "Scroll text of selected window up ARG lines.  This is
@@ -169,31 +152,31 @@
       (when (or (pixel-point-at-bottom-p) ; prevent too late
                 (and scroll-preserve-screen-position
                      (not (pixel-point-at-top-p)))) ; prevent too fast
-        (vertical-motion -2))) ; FIXME: -1 gives glitch
+        (vertical-motion -1)))
     (pixel-scroll-pixel-down (if pixel-resolution-fine-p
                                  1
                                (pixel-line-height)))))
 
 (defun pixel-point-at-top-p ()
   "Return if point is at top of a window."
-  (equal (save-excursion (beginning-of-visual-line)
-                         (point-at-bol))
-         (window-start)))
+  (<= (cdr (posn-x-y (posn-at-point)))
+      (line-pixel-height)))
 
 (defun pixel-point-at-bottom-p ()
   "Return if point is at bottom of a window."
-  (<= (count-lines (save-excursion
-                     (beginning-of-visual-line)
-                     (point-at-bol))
-                   (pixel-window-end)) 1))
+  (let* ((edges (window-inside-pixel-edges))
+         (height (- (nth 3 edges) (nth 1 edges))) ; bottom - top
+         (mergin (- height (cdr (posn-x-y (posn-at-point))))))
+    (<= mergin
+        (* 2 (line-pixel-height)))))
 
 (defun pixel-scroll-pixel-up (amt)
   "Scroll text of selected windows up AMT pixels.  Scope moves
 downward."
   (while (>= (+ (window-vscroll nil t) amt)
              (pixel-line-height))
-    (setq amt (- amt (pixel--catch-line-up)))) ; major scroll
-  (pixel--sweep-pixel-up amt)) ; minor scroll
+    (setq amt (- amt (pixel--scroll-line-up)))) ; major scroll
+  (pixel--scroll-pixel-up amt)) ; minor scroll
 
 (defun pixel-scroll-pixel-down (amt)
   "Scroll text of selected windows down AMT pixels.  Scope moves
@@ -207,8 +190,8 @@
       (setq amt (1- amt))
       (sit-for pixel-wait))))
 
-(defun pixel--catch-line-up ()
-  "Flush text upward a line with pixel transition.  When `vscroll' is non-zero,
+(defun pixel--scroll-line-up ()
+  "Scroll text upward a line with pixel transition.  When `vscroll' is 
non-zero,
 complete scrolling a line.  When `vscroll' is larger than height
 of multiple lines, for example 88, this flushes multiple lines.
 At the end, `vscroll' will be zero.  This assumes that the lines
@@ -219,44 +202,36 @@
          (line (1+ (/ src height)))    ; catch up + one line    Δ1   Δ1   Δ4
          (dst (* line height))         ; goal                  @25  @25  @92
          (delta (- dst src)))          ; pixels to be scrolled  25   17    4
-    (pixel--sweep-pixel-up (1- delta)) ; sweep until one less  @24  @24  @91
+    (pixel--scroll-pixel-up (1- delta)) ; sweep until one less  @24  @24  @91
     (scroll-up line) (sit-for pixel-wait) ; scroll 1 pixel      @0   @0   @0
     delta))
 
-(defun pixel--sweep-pixel-up (n)
-  "Sweep text upward to N pixels.  Scope moves downward."
+(defun pixel--scroll-pixel-up (n)
+  "Scroll text upward to N pixels with pixel transition.  Scope
+moves downward."
   (when (> n 0)
     (let ((vs0 (window-vscroll nil t)))
       (dolist (vs (number-sequence (1+ vs0) (+ vs0 n)))
         (set-window-vscroll nil vs t) (sit-for pixel-wait)))))
 
-(defun pixel-window-end ()
-  "Return position of the last character of fully-visible line in
-WINDOW.  This is similar to `window-end' but see a full visible
-line."
-  (let ((pos (window-end)))
-    (if (pos-visible-in-window-p pos nil t)
-        pos
-      (save-excursion
-        (goto-char pos)
-        (vertical-motion -2)
-        (point-at-bol)))))
-
 (defun pixel-line-height (&optional pos)
-  "Measure line height of POS in pixel.  When height of all lines
-are equal, you don't need this function but `frame-char-height'.
-See Info node `(elisp) Line Height'."
+  "Return height in pixels of text line of POS in the selected
+window.  When POS is nil, height of the first line of the window
+is provided.  When height of all lines are equal, you don't need
+this function but `frame-char-height'.  See Info node `(elisp)
+Line Height'."
   (or pos (setq pos (window-start)))
   (save-excursion
     (goto-char pos)
     (line-pixel-height)))
 
 (defun pixel-scroll-down-and-set-window-vscroll (vscroll)
-  "Scroll down a line and set VSCROLL in pixel.  This is written
-by Eli Zaretskii.  It is important to call `set-window-start' to
-force the display engine use that particular position as the
-window-start point.  Otherwise, redisplay will reset the window's
-vscroll."
+  "Scroll down a line and set VSCROLL in pixels.  This is code is
+presented at
+https://lists.gnu.org/archive/html/emacs-devel/2017-04/msg00366.html.
+It is important to call `set-window-start' to force the display
+engine use that particular position as the window-start point.
+Otherwise, redisplay will reset the window's vscroll."
   (let ((pos
          (save-excursion
            (goto-char (window-start))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]