all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Deniz Dogan <deniz.a.m.dogan@gmail.com>
To: emacs-devel@gnu.org
Subject: Re: Suggestion to change the behavior of M-r
Date: Wed, 12 Aug 2009 20:51:59 +0200	[thread overview]
Message-ID: <7b501d5c0908121151h59753720iaf34c60f06a074af@mail.gmail.com> (raw)
In-Reply-To: <7b501d5c0904190940x24e9412fvb26dc531b096a62d@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2393 bytes --]

2009/4/19 Deniz Dogan <deniz.a.m.dogan@gmail.com>:
> 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
>

I'm guessing that no one is interested after all, but for convenience
I tried compiling a couple of patches for this change: one which adds
this functionality to lisp/window.el (and also binds it to M-r) and
one which updates etc/NEWS if it needs to be documented there.

-- 
Deniz Dogan

[-- Attachment #2: move-to-window-line-top-bottom.patch --]
[-- Type: application/octet-stream, Size: 1659 bytes --]

*** lisp/window.el	7 May 2009 09:21:31 -0000	1.180
--- lisp/window.el	12 Aug 2009 18:47:09 -0000
*************** Top and bottom destinations are actually
*** 1631,1636 ****
--- 1631,1669 ----
  	     (recenter (- -1 this-scroll-margin))))))))
  
  (define-key global-map [?\C-l] 'recenter-top-bottom)
+ 
+ (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)
+   "Position point relative to window.
+ 
+ With an argument, acts like `move-to-window-line'.
+ 
+ With no argument, positions point at center of window.
+ Successive calls positions point at the top, the bottom and again
+ at the center of the window."
+   (interactive "P")
+   (cond
+    (arg (move-to-window-line arg)) ; Always respect ARG.
+    ((or (not (eq this-command last-command))
+ 	(eq move-to-window-line-last-op 'bottom))
+     (setq move-to-window-line-last-op '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)
+ 	     (setq move-to-window-line-last-op 'top)
+ 	     (move-to-window-line this-scroll-margin))
+ 	    ((eq move-to-window-line-last-op 'top)
+ 	     (setq move-to-window-line-last-op 'bottom)
+ 	     (move-to-window-line (- -1 this-scroll-margin))))))))
+ 
+ (define-key global-map [?\M-r] 'move-to-window-line-top-bottom)
+ 
  \f
  (defvar mouse-autoselect-window-timer nil
    "Timer used by delayed window autoselection.")

[-- Attachment #3: move-to-window-line-top-bottom-NEWS.patch --]
[-- Type: application/octet-stream, Size: 408 bytes --]

*** etc/NEWS	8 Aug 2009 19:01:26 -0000	1.2059
--- etc/NEWS	12 Aug 2009 18:48:27 -0000
*************** variables to file-local variables in the
*** 93,98 ****
--- 93,101 ----
  +++
  ** The default value for `blink-matching-paren-distance' has been increased.
  
+ ---
+ ** M-r is now bound to `move-to-window-line-top-bottom' by default.
+ 
  \f
  * Changes in Specialized Modes and Packages in Emacs 23.2
  

  reply	other threads:[~2009-08-12 18:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-19 16:40 Suggestion to change the behavior of M-r Deniz Dogan
2009-08-12 18:51 ` Deniz Dogan [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7b501d5c0908121151h59753720iaf34c60f06a074af@mail.gmail.com \
    --to=deniz.a.m.dogan@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.