From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Scrolling commands (was: scroll-top-bottom) Date: Wed, 31 Mar 2010 01:27:16 +0300 Organization: JURTA Message-ID: <877hota22z.fsf_-_@mail.jurta.org> References: <87ocitw2dl.fsf@stupidchicken.com> <201003130001.o2D01FFQ003489@godzilla.ics.uci.edu> <87vdd1yqe4.fsf@stupidchicken.com> <87eijjzrkd.fsf_-_@mail.jurta.org> <8BDB38B3CCBC481CB014CB3DA9FA1948@us.oracle.com> <87y6hq39rk.fsf_-_@mail.jurta.org> <9B30E5E474524F4092443C23D37B92CC@us.oracle.com> <8739zxgx0v.fsf@gnu.org> <87zl25e31f.fsf@mail.jurta.org> <878w9nn4el.fsf_-_@mail.jurta.org> <87iq8qjzu1.fsf@mail.jurta.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1269989205 24592 80.91.229.12 (30 Mar 2010 22:46:45 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 30 Mar 2010 22:46:45 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Mar 31 00:46:41 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1NwkCl-00070k-95 for ged-emacs-devel@m.gmane.org; Wed, 31 Mar 2010 00:46:39 +0200 Original-Received: from localhost ([127.0.0.1]:38003 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NwkCk-00011N-Nl for ged-emacs-devel@m.gmane.org; Tue, 30 Mar 2010 18:46:38 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NwkAn-0008R4-Sm for emacs-devel@gnu.org; Tue, 30 Mar 2010 18:44:37 -0400 Original-Received: from [140.186.70.92] (port=48300 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NwkAk-0008Q6-52 for emacs-devel@gnu.org; Tue, 30 Mar 2010 18:44:36 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NwkAh-000284-0w for emacs-devel@gnu.org; Tue, 30 Mar 2010 18:44:33 -0400 Original-Received: from smtp-out1.starman.ee ([85.253.0.3]:39830 helo=mx1.starman.ee) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NwkAg-00027f-Mb for emacs-devel@gnu.org; Tue, 30 Mar 2010 18:44:30 -0400 X-Virus-Scanned: by Amavisd-New at mx1.starman.ee Original-Received: from mail.starman.ee (82.131.68.10.cable.starman.ee [82.131.68.10]) by mx1.starman.ee (Postfix) with ESMTP id A30EE3F4098; Wed, 31 Mar 2010 01:44:23 +0300 (EEST) In-Reply-To: <87iq8qjzu1.fsf@mail.jurta.org> (Juri Linkov's message of "Sun, 21 Mar 2010 02:14:14 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:122943 Archived-At: >>> This feature is implemented by CUA mode, but it would be very useful >>> for users who don't use CUA. To support it in the core, I've implemented >>> a new user option `scroll-top-bottom' (that defines the scrolling behavior >>> at the top/bottom of the buffer). >> >> When scrolling by a page at a time, this makes sense, but when scrolling >> only by a single line at a time, it's very odd for point to suddenly >> jump several lines at a time. So I think the behavior should be refined >> so it doesn't just "move to BEGV or ZV" but instead "when scrolling by >> N lines can't be done, move by N lines instead". This scrolling behavior is now implemented by the patch below based on `cua-scroll-up' and `cua-scroll-down'. > And `cua-scroll-up' and `cua-scroll-down' have the same problem. > I'll try to create new commands based on `cua-scroll-up' and > `cua-scroll-down' but without these problems. > >> And yes, I think this would be better done at the Lisp level by >> introducing new commands so it doesn't affect other code that calls >> scroll-(up|down). > > I see what you mean. These new commands should be a wrapper > like `next-line' for `forward-line'. When looking for the command names, I discovered that XEmacs has such wrapper commands: `scroll-up-command' and `scroll-down-command'. I think these are good names. From XEmacs I took only command names. The code is from `cua-scroll-up' and `cua-scroll-down'. Also there were requests for commands that scroll only one line. Actually such commands already exist in Emacs, but are hidden in emulation/ws-mode.el. This patch moves them to simple.el with some modifications: === modified file 'lisp/emulation/ws-mode.el' --- lisp/emulation/ws-mode.el 2010-01-13 08:35:10 +0000 +++ lisp/emulation/ws-mode.el 2010-03-30 22:17:38 +0000 @@ -339,16 +339,6 @@ (defun wordstar-center-line () (+ left-margin (/ (- fill-column left-margin line-length) 2)))))) -(defun scroll-down-line () - "Scroll one line down." - (interactive) - (scroll-down 1)) - -(defun scroll-up-line () - "Scroll one line up." - (interactive) - (scroll-up 1)) - ;;;;;;;;;;; ;; wordstar special variables: === modified file 'lisp/simple.el' --- lisp/simple.el 2010-03-30 18:30:35 +0000 +++ lisp/simple.el 2010-03-30 22:12:17 +0000 @@ -4870,6 +4870,81 @@ (define-globalized-minor-mode global-vis visual-line-mode turn-on-visual-line-mode :lighter " vl") +;;; Scrolling commands. + +(defun scroll-up-command (&optional arg) + "Scroll text of selected window upward ARG lines; or near full screen if no ARG. +If `scroll-up' cannot scroll window further, move cursor to the bottom line. +A near full screen is `next-screen-context-lines' less than a full screen. +Negative ARG means scroll downward. +If ARG is the atom `-', scroll downward by nearly full screen." + (interactive "^P") + (cond + ((eq arg '-) (scroll-down-command nil)) + ((< (prefix-numeric-value arg) 0) + (scroll-down-command (- (prefix-numeric-value arg)))) + ((eobp) + (scroll-up arg)) ; signal error + (t + (condition-case nil + (scroll-up arg) + (end-of-buffer + (if arg + ;; When scrolling by ARG lines can't be done, + ;; move by ARG lines instead. + (forward-line arg) + ;; When ARG is nil for full-screen scrolling, + ;; move to the bottom of the buffer. + (goto-char (point-max)))))))) + +(put 'scroll-up-command 'isearch-scroll t) + +(defun scroll-down-command (&optional arg) + "Scroll text of selected window down ARG lines; or near full screen if no ARG. +If `scroll-down' cannot scroll window further, move cursor to the top line. +A near full screen is `next-screen-context-lines' less than a full screen. +Negative ARG means scroll upward. +If ARG is the atom `-', scroll upward by nearly full screen." + (interactive "^P") + (cond + ((eq arg '-) (scroll-up-command nil)) + ((< (prefix-numeric-value arg) 0) + (scroll-up-command (- (prefix-numeric-value arg)))) + ((bobp) + (scroll-down arg)) ; signal error + (t + (condition-case nil + (scroll-down arg) + (beginning-of-buffer + (if arg + ;; When scrolling by ARG lines can't be done, + ;; move by ARG lines instead. + (forward-line (- arg)) + ;; When ARG is nil for full-screen scrolling, + ;; move to the top of the buffer. + (goto-char (point-min)))))))) + +(put 'scroll-down-command 'isearch-scroll t) + +(defun scroll-up-line (&optional arg) + "Scroll text of selected window upward ARG lines; or one line if no ARG. +If ARG is omitted or nil, scroll upward by one line. +This is different from `scroll-up-command' that scrolls a full screen." + (interactive "p") + (scroll-up (or arg 1))) + +(put 'scroll-up-line 'isearch-scroll t) + +(defun scroll-down-line (&optional arg) + "Scroll text of selected window down ARG lines; or one line if no ARG. +If ARG is omitted or nil, scroll down by one line. +This is different from `scroll-down-command' that scrolls a full screen." + (interactive "p") + (scroll-down (or arg 1))) + +(put 'scroll-down-line 'isearch-scroll t) + + (defun scroll-other-window-down (lines) "Scroll the \"other window\" down. For more details, see the documentation for `scroll-other-window'." === modified file 'lisp/bindings.el' --- lisp/bindings.el 2010-01-13 08:35:10 +0000 +++ lisp/bindings.el 2010-03-30 22:14:02 +0000 @@ -873,8 +873,8 @@ (define-key global-map [left] 'backward (define-key global-map [up] 'previous-line) (define-key global-map [right] 'forward-char) (define-key global-map [down] 'next-line) -(define-key global-map [prior] 'scroll-down) -(define-key global-map [next] 'scroll-up) +(define-key global-map [prior] 'scroll-down-command) +(define-key global-map [next] 'scroll-up-command) (define-key global-map [C-up] 'backward-paragraph) (define-key global-map [C-down] 'forward-paragraph) (define-key global-map [C-prior] 'scroll-right) -- Juri Linkov http://www.jurta.org/emacs/