From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tak Kunihiro Newsgroups: gmane.emacs.bugs Subject: bug#28922: Pixel scrolling by frame-char-height Date: Sat, 21 Oct 2017 13:11:14 +0900 (JST) Message-ID: <20171021.131114.437162303416323549.tkk@misasa.okayama-u.ac.jp> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Sat_Oct_21_13_11_14_2017_108)--" Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1508559141 9648 195.159.176.226 (21 Oct 2017 04:12:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 21 Oct 2017 04:12:21 +0000 (UTC) Cc: tkk@misasa.okayama-u.ac.jp To: 28922@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Oct 21 06:12:16 2017 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 1e5l8o-0000PD-1y for geb-bug-gnu-emacs@m.gmane.org; Sat, 21 Oct 2017 06:12:06 +0200 Original-Received: from localhost ([::1]:56558 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5l8v-0000ba-Fz for geb-bug-gnu-emacs@m.gmane.org; Sat, 21 Oct 2017 00:12:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5l8o-0000bJ-El for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2017 00:12:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5l8l-0007b3-4o for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2017 00:12:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:44281) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e5l8k-0007ax-W2 for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2017 00:12:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1e5l8k-0007Y3-MZ for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2017 00:12:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tak Kunihiro Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 21 Oct 2017 04:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 28922 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.150855911328997 (code B ref -1); Sat, 21 Oct 2017 04:12:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 21 Oct 2017 04:11:53 +0000 Original-Received: from localhost ([127.0.0.1]:52962 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e5l8a-0007Xd-C1 for submit@debbugs.gnu.org; Sat, 21 Oct 2017 00:11:53 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:57694) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e5l8Y-0007XL-8v for submit@debbugs.gnu.org; Sat, 21 Oct 2017 00:11:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5l8Q-0007Qh-S5 for submit@debbugs.gnu.org; Sat, 21 Oct 2017 00:11:45 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:50677) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e5l8Q-0007Qa-Mo for submit@debbugs.gnu.org; Sat, 21 Oct 2017 00:11:42 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48665) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5l8N-0000Vs-QN for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2017 00:11:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5l8K-0007P2-ED for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2017 00:11:39 -0400 Original-Received: from mxl065v67.mxlogic.net ([208.81.65.67]:46816 helo=s14p02o144.mxlogic.net) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e5l8J-0007Mn-RN for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2017 00:11:36 -0400 Original-Received: from unknown [42.127.236.175] (EHLO mlsec.cc.okayama-u.ac.jp) by s14p02o144.mxlogic.net(mxl_mta-8.5.0-1883) over TLS secured channel with ESMTP id 9e8cae95.0.240046.00-380.529178.s14p02o144.mxlogic.net (envelope-from ); Fri, 20 Oct 2017 22:11:21 -0600 (MDT) X-MXL-Hash: 59eac8e955a58334-6e1d91eac04d617e847701948a231133d0d7f518 Original-Received: from alml002.ouadm.okayama-u.ac.jp (unknown [42.127.236.168]) by mlsec.cc.okayama-u.ac.jp with smtp id 557a_150b_0b25a152_7e99_4a37_8ced_121271d3f0b6; Sat, 21 Oct 2017 13:11:16 +0900 Original-Received: from localhost (p221050-ipngn200207tottori.tottori.ocn.ne.jp [153.182.220.50]) by alml002.ouadm.okayama-u.ac.jp (Postfix) with ESMTPSA id E88A44C0B21; Sat, 21 Oct 2017 13:11:16 +0900 (JST) X-Mailer: Mew version 6.7 on Emacs 25.2 / Mule 6.0 (HANACHIRUSATO) X-NAI-Spam-Flag: NO X-NAI-Spam-Level: ********** X-NAI-Spam-Threshold: 11 X-NAI-Spam-Score: 10.1 X-NAI-Spam-Rules: 6 Rules triggered TS_MSG_REP_80_512=10, RCVD_BAD_SIP=0.1, EDT_SA_AU_PASS=0, EDT_SA_DN_PASS=0, EDT_SA_TS_FAIL=0, RV6141=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6141> : inlines <6136> : streams <1767958> : uri <2519885> X-AnalysisOut: [v=2.2 cv=ReTgMxlv c=1 sm=1 tr=0 a=8LLPK8U+aGQ6qN8QlyMYtQ==] X-AnalysisOut: [:117 a=8LLPK8U+aGQ6qN8QlyMYtQ==:17 a=02M-m0pO-4AA:10 a=mDV] X-AnalysisOut: [3o1hIAAAA:8 a=AGiXjISicGG7unQC2uoA:9 a=tMdrc_7EhtSPX8LW:21] X-AnalysisOut: [ a=UxCDvUS7rngNiDu4:21 a=CjuIK1q_8ugA:10 a=X8loPEeh8VQA:10] X-AnalysisOut: [ a=ycPCe-mW7_IA:10 a=r17MaVuW6K30c_iCW24A:9 a=pUFvPn8ZPUSP] X-AnalysisOut: [O3uF:21 a=gz-eoENlyW9snX_y:21 a=wPNLvfGTeEIA:10 a=rb7arj-X] X-AnalysisOut: [aBZ-JXl8yCgA:9 a=_FVE-zBwftR9WsbkzFJk:22] X-Spam: [F=0.5000000000; CM=0.500; MH=0.500(2017102021); S=0.200(2015072901)] X-MAIL-FROM: X-SOURCE-IP: [42.127.236.175] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:138794 Archived-At: ----Next_Part(Sat_Oct_21_13_11_14_2017_108)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit I'm sending a patch for lisp/pixel-scroll.el. This patch lets mouse wheel scroll vertically by number of pixels returned by `frame-char-height' as suggested as below. https://lists.gnu.org/archive/html/emacs-devel/2017-09/msg00385.html Also, by considering response of display engine as suggested as below, this patch offers stable vertically scrolling even when window is horizontally scrolled. https://lists.gnu.org/archive/html/emacs-devel/2017-10/msg00621.html ChangeLog entry and patch to NEWS also are attached. * ChangeLog 2017-10-21 Tak Kunihiro Scroll vertically by number of pixels returned by `frame-char-height' with or without horizontally scrolled * lisp/pixel-scroll.el (pixel-resolution-fine-flag): When t, scroll pixels returned by `frame-char-height'. (pixel-scroll-up): Scroll by `frame-char-height'. Fix algorithm to move cursor to avoid unexpected jump. (pixel-scroll-down): Scroll by `frame-char-height'. (pixel-bob-at-top-p): Consider number of pixels that is about to scroll. (pixel-posn-y-at-point): Consider existence of an overlay string. Return nil when horizontally scrolled. (pixel-point-at-top-p): Consider number of pixels that is about to scroll. Use different algorithm when horizontally scrolled. (pixel-point-at-bottom-p): Consider number of pixels that is about to scroll. Return nil when horizontally scrolled. (pixel-scroll-pixel-down): Move cursor when horizontally scrolled. (pixel--whistlestop-line-up): Change cosmetics and move cursor when horizontally scrolled. (pixel-line-height): Call `pixel-visual-line-height' instead of `line-pixel-height'. (pixel-visual-line-height): New function to return height in pixels of text line where cursor is with or without horizontally scrolled, considering response of display engine. (pixel-visible-pos-in-window): New function to return position of a char shown on text line where cursor is on screen with or without horizontally scrolled. ----Next_Part(Sat_Oct_21_13_11_14_2017_108)-- Content-Type: Text/X-Patch; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="pixel-scroll.patch" diff --git a/lisp/pixel-scroll.el b/lisp/pixel-scroll.el old mode 100644 new mode 100755 index 4f183addaa..e5c1dad1eb --- a/cygdrive/c/Users/dream/Downloads/emacs/lisp/pixel-scroll.el +++ b/cygdrive/c/Users/dream/.emacs.d/site-lisp/pixel-scroll.el @@ -74,10 +74,13 @@ More wait will result in slow and gentle scroll.") = (defvar pixel-resolution-fine-flag nil - "Set 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 undoes the effect of the pixel-level -scroll.") + "Set scrolling resolution to pixels instead of a line. +When it is t, scrolling resolution is number of pixels obtained +by `frame-char-height' instead of a line. When it is number, +scrolling resolution is set to number of pixels specified. In +case you need scrolling resolution of a pixel, set to 1. After a +pixel scroll, typing C-n or C-p scrolls the window to make it +fully visible, and undoes the effect of the pixel-level scroll.") = ;;;###autoload (define-minor-mode pixel-scroll-mode @@ -102,13 +105,16 @@ This is an alternative of `scroll-up'. Scope mov= es downward." (interactive) (or arg (setq arg 1)) (dotimes (ii arg) ; move scope downward - (if (pixel-eob-at-top-p) ; when end-of-the-buffer is close - (scroll-up 1) ; relay on robust method - (when (pixel-point-at-top-p) ; prevent too late - (vertical-motion 1)) ; move point downward - (pixel-scroll-pixel-up (if pixel-resolution-fine-flag - 1 - (pixel-line-height)))))) ; move scope d= ownward + (let ((amt (if pixel-resolution-fine-flag + (if (integerp pixel-resolution-fine-flag) + pixel-resolution-fine-flag + (frame-char-height)) + (pixel-line-height)))) + (if (pixel-eob-at-top-p) ; when end-of-the-buffer is = close + (scroll-up 1) ; relay on robust method + (while (pixel-point-at-top-p amt) ; prevent too late (multi tr= ies) + (vertical-motion 1)) ; move point downward + (pixel-scroll-pixel-up amt))))) ; move scope downward = (defun pixel-scroll-down (&optional arg) "Scroll text of selected window down ARG lines. @@ -116,48 +122,61 @@ This is and alternative of `scroll-down'. Scope = moves upward." (interactive) (or arg (setq arg 1)) (dotimes (ii arg) - (if (or (pixel-bob-at-top-p) ; when beginning-of-the-buffer is see= n - (pixel-eob-at-top-p)) ; for file with a long line - (scroll-down 1) ; relay on robust method - (while (pixel-point-at-bottom-p) ; prevent too late (multi tries= ) - (vertical-motion -1)) - (pixel-scroll-pixel-down (if pixel-resolution-fine-flag - 1 - (pixel-line-height -1)))))) - -(defun pixel-bob-at-top-p () - "Return non-nil if beginning of buffer is at top of window." - (equal (window-start) (point-min))) + (let ((amt (if pixel-resolution-fine-flag + (if (integerp pixel-resolution-fine-flag) + pixel-resolution-fine-flag + (frame-char-height)) + (pixel-line-height -1)))) + (if (or (pixel-bob-at-top-p amt) ; when beginning-of-the-buffer = is seen + (pixel-eob-at-top-p)) ; for file with a long line + (scroll-down 1) ; relay on robust method + (while (pixel-point-at-bottom-p amt) ; prevent too late (multi= tries) + (vertical-motion -1)) + (pixel-scroll-pixel-down amt))))) + +(defun pixel-bob-at-top-p (amt) + "Return non-nil if beginning of buffer is at top of window on coming= scroll of AMT pixels." + (and (equal (window-start) (point-min)) + (< (window-vscroll nil t) amt))) = (defun pixel-eob-at-top-p () "Return non-nil if end of buffer is at top of window." (<=3D (count-lines (window-start) (window-end)) 2)) ; count-screen-l= ines = (defun pixel-posn-y-at-point () - "Return y coordinates of point in pixels of current window." - (let ((hscroll0 (window-hscroll)) - (y (cdr (posn-x-y (posn-at-point))))) - ;; when point is out of scope by hscroll - (unless y - (save-excursion - (set-window-hscroll nil (current-column)) - (setq y (cdr (posn-x-y (posn-at-point)))) - (set-window-hscroll nil hscroll0))) - y)) - -(defun pixel-point-at-top-p () - "Return if point is located at top of a window." - (let* ((y (pixel-posn-y-at-point)) - (top-margin y)) - (< top-margin (pixel-line-height)))) - -(defun pixel-point-at-bottom-p () - "Return if point is located at bottom of a window." - (let* ((y (pixel-posn-y-at-point)) - (edges (window-inside-pixel-edges)) + "Return y coordinates of point in pixels of current window. +This returns nil when horizontally scrolled." + (when (equal (window-hscroll) 0) + (save-excursion + ;; When there's an overlay string on a line, move + ;; point by (beginning-of-visual-line). + (beginning-of-visual-line) + ;; (- (cadr (pos-visible-in-window-p (point) nil t)) + ;; (line-pixel-height)) + (cdr (posn-x-y (posn-at-point)))))) + +(defun pixel-point-at-top-p (amt) + "Return if point is located at top of a window on coming scroll of A= MT pixels. +When location of point was not obtained, this returns if point is at t= op of window." + (let ((y (pixel-posn-y-at-point)) + top-margin) + (cond + (y + (setq top-margin y) + (< top-margin amt)) + (t + (<=3D (count-lines (window-start) (point)) 1))))) + +(defun pixel-point-at-bottom-p (amt) + "Return if point is located at bottom of a window on coming scroll o= f AMT pixels. +When location of point was not obtained, this returns nil." + (let* ((edges (window-inside-pixel-edges)) (height (- (nth 3 edges) (nth 1 edges))) ; (- bottom top) - (bottom-margin (- height (+ y (line-pixel-height))))) ; botto= m margin - (< bottom-margin (pixel-line-height -1)))) ; coming unseen line + (y (pixel-posn-y-at-point)) + bottom-margin) + (when y + (setq bottom-margin (- height (+ y (pixel-visual-line-height))))= + (< bottom-margin amt)))) ; coming unseen line = (defun pixel-scroll-pixel-up (amt) "Scroll text of selected windows up AMT pixels. @@ -173,8 +192,12 @@ Scope moves upward." (while (> amt 0) (let ((vs (window-vscroll nil t))) (if (equal vs 0) - (pixel-scroll-down-and-set-window-vscroll - (1- (pixel-line-height -1))) + (progn + ;; On horizontal scrolling, move cursor. + (when (> (window-hscroll) 0) + (vertical-motion -1)) + (pixel-scroll-down-and-set-window-vscroll + (1- (pixel-line-height -1)))) (set-window-vscroll nil (1- vs) t)) (setq amt (1- amt)) (sit-for pixel-wait)))) @@ -189,11 +212,16 @@ Scope moves downward. This function returns numb= er of pixels that was scrolled." (let* ((src (window-vscroll nil t)) ; EXAMPLE (initial) @0 @= 8 @88 (height (pixel-line-height)) ; 25 2= 5 23 - (line (1+ (/ src height))) ; catch up + one line =C41 = =C41 =C44 + (line (1+ (/ src height))) ; catch up + one line 1 = 1 4 (dst (* line height)) ; goal @25 @2= 5 @92 (delta (- dst src))) ; pixels to be scrolled 25 1= 7 4 (pixel--whistlestop-pixel-up (1- delta)) ; until one less @24 @2= 4 @91 - (scroll-up line) (sit-for pixel-wait) ; scroll 1 pixel @0 @= 0 @0 + (dotimes (ii line) + ;; On horizontal scrolling, move cursor. + (when (> (window-hscroll) 0) + (vertical-motion 1)) + (scroll-up 1)) + (sit-for pixel-wait) ; scroll 1 pixel @0 @= 0 @0 delta)) = (defun pixel--whistlestop-pixel-up (n) @@ -211,9 +239,60 @@ unseen line above the first line, respectively, is= provided." (or pos (setq pos (window-start))) (when (< pos 0) (setq pos (pixel-point-at-unseen-line))) - (save-excursion - (goto-char pos) - (line-pixel-height))) ; frame-char-height + (let ((vs1 (window-vscroll nil t)) + height) + (set-window-vscroll nil 0 t) + (save-excursion + (goto-char pos) + (setq height (pixel-visual-line-height))) ; line-pixel-height, f= rame-char-height + (set-window-vscroll nil vs1 t) + height)) + +(defun pixel-visual-line-height () + "Return height in pixels of text line where cursor is in the selecte= d window." + (let ((pos (pixel-visible-pos-in-window))) + (cond + ;; When a char of line is shown, obtain height by + ;; (line-pixel-height). + (pos (save-excursion (goto-char pos) (line-pixel-height))) + ;; When no char of line is shown but the line is at the top, + ;; obtain height by (line-pixel-height). This is based on + ;; expected response from display engine. See following + ;; discussion. + ;; https://lists.gnu.org/archive/html/emacs-devel/2017-10/msg0062= 1.html + ((equal (count-lines (window-start) (point)) 1) + (line-pixel-height)) + ;; No char of line is shown and the line is not at the top, + ;; obtain height by (frame-char-height). + (t (frame-char-height))))) + +(defun pixel-visible-pos-in-window () + "Return position of a char shown on text line where cursor is in the= selected window. +This will look for positions of point and end-of-visual-line, +then positions from beginning-of-visual-line to +end-of-visual-line. When no char in a line is shown, this +returns nil." + (let* ((beginning-of-visual-line-pos (save-excursion (beginning-of-v= isual-line) (point))) + (end-of-visual-line-pos (save-excursion (end-of-visual-line) = (point))) + (pos-list (number-sequence beginning-of-visual-line-pos end-o= f-visual-line-pos)) + (edges (window-inside-pixel-edges)) + (width (- (nth 2 edges) (nth 0 edges))) + posn-x + visible-pos) + ;; Optimize list of position to be surveyed. + (push end-of-visual-line-pos pos-list) + (push (point) pos-list) + (delete-dups pos-list) + ;; Find out a char with position X that is more than zero and less= than width of screen. + (while (and (not visible-pos) + pos-list) + (setq posn-x (car (pos-visible-in-window-p (car pos-list) nil t)= )) + (if (and posn-x + (<=3D 0 posn-x) + (< posn-x width)) + (setq visible-pos (car pos-list)) + (setq pos-list (cdr pos-list)))) + visible-pos)) = (defun pixel-point-at-unseen-line () "Return the character position of line above the selected window. ----Next_Part(Sat_Oct_21_13_11_14_2017_108)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="NEWS.patch" diff --git a/etc/NEWS b/etc/NEWS old mode 100644 new mode 100755 index 74d6e8bf1c..d9eb4f9462 --- a/cygdrive/c/Users/dream/Downloads/emacs/etc/NEWS +++ b/cygdrive/c/Users/dream/Dropbox/Downloads@TK/NEWS @@ -76,6 +76,12 @@ globally or for individual definitions. the XTerm window title. This feature is experimental and is disabled by default. +** Pixel-Scroll + +--- +*** Now scroll vertically by number of pixels returned by +'frame-char-height' when 'pixel-resolution-fine-flag' is set to t. + * New Modes and Packages in Emacs 27.1 ----Next_Part(Sat_Oct_21_13_11_14_2017_108)----