From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.help Subject: Re: how to move the contents of the buffer one line up/down? Date: Mon, 14 Jul 2008 13:16:15 +0000 Message-ID: <20080714131615.GC3445@muc.de> References: <6e0qu9F4kpduU2@mid.individual.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1216039919 6675 80.91.229.12 (14 Jul 2008 12:51:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 14 Jul 2008 12:51:59 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Tamas K Papp Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jul 14 14:52:46 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KINX9-0007Ik-LF for geh-help-gnu-emacs@m.gmane.org; Mon, 14 Jul 2008 14:52:03 +0200 Original-Received: from localhost ([127.0.0.1]:51376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KINWH-00044k-Ky for geh-help-gnu-emacs@m.gmane.org; Mon, 14 Jul 2008 08:51:09 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KINVt-0003zf-3G for help-gnu-emacs@gnu.org; Mon, 14 Jul 2008 08:50:45 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KINVs-0003yr-Hs for help-gnu-emacs@gnu.org; Mon, 14 Jul 2008 08:50:44 -0400 Original-Received: from [199.232.76.173] (port=39838 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KINVs-0003yh-BB for help-gnu-emacs@gnu.org; Mon, 14 Jul 2008 08:50:44 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:3182 helo=mail.muc.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KINVr-0005PE-Ro for help-gnu-emacs@gnu.org; Mon, 14 Jul 2008 08:50:44 -0400 Original-Received: (qmail 4094 invoked by uid 3782); 14 Jul 2008 12:50:37 -0000 Original-Received: from acm.muc.de (pD9E53A92.dip.t-dialin.net [217.229.58.146]) by colin2.muc.de (tmda-ofmipd) with ESMTP; Mon, 14 Jul 2008 14:50:29 +0200 Original-Received: (qmail 5254 invoked by uid 1000); 14 Jul 2008 13:16:15 -0000 Content-Disposition: inline In-Reply-To: <6e0qu9F4kpduU2@mid.individual.net> User-Agent: Mutt/1.5.9i X-Delivery-Agent: TMDA/1.1.5 (Fettercairn) X-Primary-Address: acm@muc.de X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.6-4.9 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:55546 Archived-At: Hi, Tamas! On Mon, Jul 14, 2008 at 11:17:29AM +0000, Tamas K Papp wrote: > Hi, > I know that I can "center" my cursor with C-l. But sometimes it would be > really useful to do the following: have the contents of the buffer move > up or down a couple of lines, with the cursor staying in the same place. > What function would do that? Then I could bind it to a key. There isn't really a decent existing Emacs function, but it's very easy to write them. In fact, these commands were the first I ever wrote. Here they are: I've bound them to - and -, so they'll only work if you're in a GUI system (or you've already enhanced your terminal keyboard setup). Additionally, - moves point 6 lines up, and -- scrolls the screen 6 lines; just the same for .... And quite a few other goodies, too. Try them! Enjoy! ######################################################################### (defun scrollup-n (&optional n) "Scroll the text up n (default 1) lines." (interactive "p") (scroll-up (or n 1)) ) (global-set-key [S-down] 'scrollup-n) (defun scrolldown-n (&optional n) "Scroll the text down n (default 1) lines." (interactive "p") (scroll-down (or n 1)) ) (global-set-key [S-up] 'scrolldown-n) (defun scrollup-6n (&optional n) "Scroll the text up 6n (default 6) lines." (interactive "p") (scroll-up (* 6 (or n 1))) ) (global-set-key [C-S-down] 'scrollup-6n) (global-set-key [C-M-mouse-3] 'scrollup-6n) (defun scrolldown-6n (&optional n) "Scroll the text down 6n (default 6) lines." (interactive "p") (scroll-down (* 6 (or n 1))) ) (global-set-key [C-S-up] 'scrolldown-6n) (global-set-key [C-M-mouse-1] 'scrolldown-6n) (defun scrollup-other-n (&optional n) "Scroll the text in the other window n (default 1) lines up." (interactive "p") (scroll-other-window (or n 1))) (global-set-key [M-down] 'scrollup-other-n) (defun scrolldown-other-n (&optional n) "Scroll the text in the other window n (default 1) lines down." (interactive "p") (scroll-other-window-down (or n 1))) (global-set-key [M-up] 'scrolldown-other-n) (defun scrollup-other-6n (&optional n) "Scroll the text in the other window 6n (default 6) lines up." (interactive "p") (scroll-other-window (* 6 (or n 1)))) (global-set-key [C-M-down] 'scrollup-other-6n) (defun scrolldown-other-6n (&optional n) "Scroll the text in the other window 6n (default 6) lines down." (interactive "p") (scroll-other-window-down (* 6 (or n 1)))) (global-set-key [C-M-up] 'scrolldown-other-6n) (defun previous-line-6n (&optional n) "Move the cursor up 6n (default 6) lines." (interactive "p") (previous-line (* 6 (or n 1))) ) (global-set-key [C-up] 'previous-line-6n) (defun next-line-6n (&optional n) "Move the cursor down 6n (default 6) lines." (interactive "p") (next-line (* 6 (or n 1))) ) (global-set-key [C-down] 'next-line-6n) (defun screen-top () "Move the point to the top of the screen." (interactive) (move-to-window-line 0) ) (global-set-key [C-left] 'screen-top) (defun screen-bottom () "Move the point to the bottom of the screen." (interactive) (move-to-window-line -1) ) (global-set-key [C-right] 'screen-bottom) (defun scroll-to-top () "Scroll the current line to the top of the window" (interactive) (recenter 0)) (global-set-key [C-S-right] 'scroll-to-top) (defun scroll-to-bottom () "Scroll the current line to the bottom of the window" (interactive) (recenter -1)) (global-set-key [C-S-left] 'scroll-to-bottom) ######################################################################### > Thanks, > Tamas -- Alan Mackenzie (Nuremberg, Germany).