unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* how to move the contents of the buffer one line up/down?
@ 2008-07-14 11:17 Tamas K Papp
  2008-07-14 11:49 ` Peter Dyballa
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Tamas K Papp @ 2008-07-14 11:17 UTC (permalink / raw)
  To: help-gnu-emacs

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.

Thanks,

Tamas


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to move the contents of the buffer one line up/down?
  2008-07-14 11:17 how to move the contents of the buffer one line up/down? Tamas K Papp
@ 2008-07-14 11:49 ` Peter Dyballa
  2008-07-14 11:51 ` Pascal J. Bourguignon
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Peter Dyballa @ 2008-07-14 11:49 UTC (permalink / raw)
  To: Tamas K Papp; +Cc: help-gnu-emacs


Am 14.07.2008 um 13:17 schrieb Tamas K Papp:

> 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.

(defun scroll-down-in-place (n)
   (interactive "p")
   (previous-line n)
   (scroll-down n))
(defun scroll-up-in-place (n)
   (interactive "p")
   (next-line n)
   (scroll-up n))

Far more on this list.

--
Greetings

   Pete     === -Q
              ==<__/% >>
_____________(_)____@_____________________________






^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to move the contents of the buffer one line up/down?
  2008-07-14 11:17 how to move the contents of the buffer one line up/down? Tamas K Papp
  2008-07-14 11:49 ` Peter Dyballa
@ 2008-07-14 11:51 ` Pascal J. Bourguignon
  2008-07-14 11:55   ` Tamas K Papp
  2008-07-14 12:11 ` B. T. Raven
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Pascal J. Bourguignon @ 2008-07-14 11:51 UTC (permalink / raw)
  To: help-gnu-emacs

Tamas K Papp <tkpapp@gmail.com> writes:

> 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.

scroll-up and scroll-down

C-u 3 M-x scroll-up RET

C-u 6 M-x scroll-down RET

Also, since they're often bound to <next> and <prior> you can just type:

C-3 <prior>  or C-6 <next>


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

There is no worse tyranny than to force a man to pay for what he does not
want merely because you think it would be good for him. -- Robert Heinlein


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to move the contents of the buffer one line up/down?
  2008-07-14 11:51 ` Pascal J. Bourguignon
@ 2008-07-14 11:55   ` Tamas K Papp
  2008-07-14 12:49     ` Pascal J. Bourguignon
  0 siblings, 1 reply; 9+ messages in thread
From: Tamas K Papp @ 2008-07-14 11:55 UTC (permalink / raw)
  To: help-gnu-emacs

On Mon, 14 Jul 2008 13:51:01 +0200, Pascal J. Bourguignon wrote:

> Tamas K Papp <tkpapp@gmail.com> writes:
> 
>> 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.
> 
> scroll-up and scroll-down
> 
> C-u 3 M-x scroll-up RET
> 
> C-u 6 M-x scroll-down RET
> 
> Also, since they're often bound to <next> and <prior> you can just type:
> 
> C-3 <prior>  or C-6 <next>

Thanks Peter and Pascal!

Sorry for my ignorance, but on most standard PC keyboards, <prior> and 
<next> would be PgUp and PgDown?

Tamas


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to move the contents of the buffer one line up/down?
  2008-07-14 11:17 how to move the contents of the buffer one line up/down? Tamas K Papp
  2008-07-14 11:49 ` Peter Dyballa
  2008-07-14 11:51 ` Pascal J. Bourguignon
@ 2008-07-14 12:11 ` B. T. Raven
  2008-07-14 13:16 ` Alan Mackenzie
       [not found] ` <mailman.14699.1216039847.18990.help-gnu-emacs@gnu.org>
  4 siblings, 0 replies; 9+ messages in thread
From: B. T. Raven @ 2008-07-14 12:11 UTC (permalink / raw)
  To: help-gnu-emacs

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.
> 
> Thanks,
> 
> Tamas

Look at C-h f scroll-up and scroll-down. For a demo try:

C-u 1 M-x scroll-up

Maybe this works, I don't know. Evaluate it and try it:


(global-set-key [(super q)] (lambda () (interactive) (scroll-up 1)))


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to move the contents of the buffer one line up/down?
  2008-07-14 11:55   ` Tamas K Papp
@ 2008-07-14 12:49     ` Pascal J. Bourguignon
  2008-07-14 20:14       ` Xah
  0 siblings, 1 reply; 9+ messages in thread
From: Pascal J. Bourguignon @ 2008-07-14 12:49 UTC (permalink / raw)
  To: help-gnu-emacs

Tamas K Papp <tkpapp@gmail.com> writes:
> Sorry for my ignorance, but on most standard PC keyboards, <prior> and 
> <next> would be PgUp and PgDown?

I think so.  To confirm it, type C-h k PgUp and see if its name is <prior>

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

READ THIS BEFORE OPENING PACKAGE: According to certain suggested
versions of the Grand Unified Theory, the primary particles
constituting this product may decay to nothingness within the next
four hundred million years.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to move the contents of the buffer one line up/down?
  2008-07-14 11:17 how to move the contents of the buffer one line up/down? Tamas K Papp
                   ` (2 preceding siblings ...)
  2008-07-14 12:11 ` B. T. Raven
@ 2008-07-14 13:16 ` Alan Mackenzie
       [not found] ` <mailman.14699.1216039847.18990.help-gnu-emacs@gnu.org>
  4 siblings, 0 replies; 9+ messages in thread
From: Alan Mackenzie @ 2008-07-14 13:16 UTC (permalink / raw)
  To: Tamas K Papp; +Cc: help-gnu-emacs

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).




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to move the contents of the buffer one line up/down?
  2008-07-14 12:49     ` Pascal J. Bourguignon
@ 2008-07-14 20:14       ` Xah
  0 siblings, 0 replies; 9+ messages in thread
From: Xah @ 2008-07-14 20:14 UTC (permalink / raw)
  To: help-gnu-emacs

On Jul 14, 5:49 am, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> Tamas K Papp <tkp...@gmail.com> writes:
>
> > Sorry for my ignorance, but on most standard PC keyboards, <prior> and
> > <next> would be PgUp and PgDown?
>
> I think so.  To confirm it, type C-h k PgUp and see if its name is <prior>

One of emacs's problem that set back today's programers from adapting
it is obsolete terminologies. The key names such as <prior>, <next>,
RET, is one of them. (and Meta, of course)

It would be good, if a major new release of emacs, support and use
throughout names like <PageUp> or <return> etc instead (The <return>
is already supported by at least emacs 22, but not used or widely used
in emacs documentations). With this, user don't have to go “huh?” when
reading web pages, guides, blogs, or discussions about typing some
keystrokes or keybindings, etc. (whenever we get a question about
this, we can probably assume 10 or more users had the same question
but didn't bother to ask)

For some detail on changes i think that's more critical changes yet
easy to make, please see:

 http://xahlee.org/emacs/modernization.html

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to move the contents of the buffer one line up/down?
       [not found] ` <mailman.14699.1216039847.18990.help-gnu-emacs@gnu.org>
@ 2008-07-14 20:27   ` Xah
  0 siblings, 0 replies; 9+ messages in thread
From: Xah @ 2008-07-14 20:27 UTC (permalink / raw)
  To: help-gnu-emacs

Like Alan Mackenzie, i also defined a keystroke to scroll screen up or
down by just 1 line. Had this for like 10 years.

basically i just have this:

(global-set-key (kbd "C-<up>") (lambda () (interactive) (scroll-down
2)))
(global-set-key (kbd "C-<down>") (lambda () (interactive) (scroll-up
2)))

However, this week i actually took them off. :D
Relying on mouse scroll wheel instead, or recenter (default to C-l),
just for a fresh change. If mouse is not available, well possibly i
don't need to scroll screen in such way since as far as i looked, vast
majority of major editors (X-code, Visual Studio, Eclipse) don't have
it (i might be wrong since i haven't yet checked in detail). (so this
is to experiment)

Part of the other reason is that i can free up the modifier+arrow
keyspace for more consistent use for, say, sexp navigation or other,
havn't really decided what.

  Xah
∑ http://xahlee.org/

☄

On Jul 14, 6:16 am, Alan Mackenzie <a...@muc.de> wrote:
> 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)
>
> ...



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-07-14 20:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-14 11:17 how to move the contents of the buffer one line up/down? Tamas K Papp
2008-07-14 11:49 ` Peter Dyballa
2008-07-14 11:51 ` Pascal J. Bourguignon
2008-07-14 11:55   ` Tamas K Papp
2008-07-14 12:49     ` Pascal J. Bourguignon
2008-07-14 20:14       ` Xah
2008-07-14 12:11 ` B. T. Raven
2008-07-14 13:16 ` Alan Mackenzie
     [not found] ` <mailman.14699.1216039847.18990.help-gnu-emacs@gnu.org>
2008-07-14 20:27   ` Xah

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).