unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Suggestion to change the behavior of M-r
@ 2009-04-19 16:40 Deniz Dogan
  2009-08-12 18:51 ` Deniz Dogan
  0 siblings, 1 reply; 10+ messages in thread
From: Deniz Dogan @ 2009-04-19 16:40 UTC (permalink / raw)
  To: emacs-devel

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




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

end of thread, other threads:[~2009-11-23  5:38 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-19 16:40 Suggestion to change the behavior of M-r Deniz Dogan
2009-08-12 18:51 ` Deniz Dogan
2009-08-12 20:52   ` Juri Linkov
2009-08-12 23:20     ` Deniz Dogan
2009-08-12 23:26       ` Deniz Dogan
2009-08-13 23:17       ` Juri Linkov
2009-10-04 16:51         ` Deniz Dogan
2009-10-05 21:33           ` Juri Linkov
2009-11-23  3:57           ` Stefan Monnier
2009-11-23  5:38             ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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