emacs-devel
[Top][All Lists]
Advanced

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

Suggestion to change the behavior of M-r


From: Deniz Dogan
Subject: Suggestion to change the behavior of M-r
Date: Sun, 19 Apr 2009 18:40:31 +0200

Hi

I recently found out about the M-r keybinding, which by default is
bound to move-to-window-line. Already knowing about the C-l keybinding
(recenter-top-bottom) I was a bit thrown off when I found out that M-r
doesn't behave in the same way. This got me thinking that the behavior
of M-r should be changed to behave somewhat like C-l. So I basically
stole the code for recenter-top-bottom and modified it to work with
move-to-window-line instead.

This is the result:

(defvar move-to-window-line-last-op nil
  "Indicates the last move-to-window-line operation performed.
Possible values: `top', `middle', `bottom'.")

(defun move-to-window-line-top-bottom (&optional arg)
  (interactive "P")
  (cond
   (arg (move-to-window-line arg))                      ; Always respect ARG.
   ((or (not (eq this-command last-command))            ; If this is
not a repetition
        (eq move-to-window-line-last-op 'bottom))       ; or if the last one
put us at the bottom
    (setq move-to-window-line-last-op 'middle)          ; then move it
to the middle
    (call-interactively 'move-to-window-line))
   (t
    (let ((this-scroll-margin
           (min (max 0 scroll-margin)
                (truncate (/ (window-body-height) 4.0)))))
      (cond ((eq move-to-window-line-last-op 'middle)   ; If we're at the middle
             (setq move-to-window-line-last-op 'top)    ; then move to the top
             (move-to-window-line this-scroll-margin))
            ((eq move-to-window-line-last-op 'top)      ; If we're at the top
             (setq move-to-window-line-last-op 'bottom) ; then move to the 
bottom
             (move-to-window-line (- -1 this-scroll-margin))))))))

Please, do consider changing the behavior of M-r, of course not
necessarily using the code above. If the code became a bit obfuscated
on its way to the mailing list, I pasted it on lisp.org as well:
http://paste.lisp.org/display/78841

Thanks,
Deniz Dogan




reply via email to

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