help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: how to move the contents of the buffer one line up/down?


From: Alan Mackenzie
Subject: Re: how to move the contents of the buffer one line up/down?
Date: Mon, 14 Jul 2008 13:16:15 +0000
User-agent: Mutt/1.5.9i

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 <shift>-<up> and <shift>-<down>, so
they'll only work if you're in a GUI system (or you've already enhanced
your terminal keyboard setup).

Additionally, <ctrl>-<up> moves point 6 lines up, and
<ctrl>-<shift>-<up> scrolls the screen 6 lines; just the same for
...<down>.  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).




reply via email to

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