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

* Re: Suggestion to change the behavior of M-r
  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
  0 siblings, 1 reply; 10+ messages in thread
From: Deniz Dogan @ 2009-08-12 18:51 UTC (permalink / raw)
  To: emacs-devel

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

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

* Re: Suggestion to change the behavior of M-r
  2009-08-12 18:51 ` Deniz Dogan
@ 2009-08-12 20:52   ` Juri Linkov
  2009-08-12 23:20     ` Deniz Dogan
  0 siblings, 1 reply; 10+ messages in thread
From: Juri Linkov @ 2009-08-12 20:52 UTC (permalink / raw)
  To: Deniz Dogan; +Cc: emacs-devel

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

I think M-r is a bad key for window-related functionality.  It is
usually associated with search.  For example, we have a plan to use M-r
in comint mode to start Isearch (see bug#3746).

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

* Re: Suggestion to change the behavior of M-r
  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
  0 siblings, 2 replies; 10+ messages in thread
From: Deniz Dogan @ 2009-08-12 23:20 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

2009/8/12 Juri Linkov <juri@jurta.org>:
>> 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.
>
> I think M-r is a bad key for window-related functionality.  It is
> usually associated with search.  For example, we have a plan to use M-r
> in comint mode to start Isearch (see bug#3746).
>

M-r is already bound to move-to-window-line by default, my patch
merely overrides it with a binding to move-to-window-line-top-bottom.

-- 
Deniz Dogan




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

* Re: Suggestion to change the behavior of M-r
  2009-08-12 23:20     ` Deniz Dogan
@ 2009-08-12 23:26       ` Deniz Dogan
  2009-08-13 23:17       ` Juri Linkov
  1 sibling, 0 replies; 10+ messages in thread
From: Deniz Dogan @ 2009-08-12 23:26 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

2009/8/13 Deniz Dogan <deniz.a.m.dogan@gmail.com>:
> 2009/8/12 Juri Linkov <juri@jurta.org>:
>>> 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.
>>
>> I think M-r is a bad key for window-related functionality.  It is
>> usually associated with search.  For example, we have a plan to use M-r
>> in comint mode to start Isearch (see bug#3746).
>>
>
> M-r is already bound to move-to-window-line by default, my patch
> merely overrides it with a binding to move-to-window-line-top-bottom.
>

Which reminds me that none of the patches in my original post removes
the M-r binding from the original move-to-window-line... If anyone
decides that this patch is a good idea should try to remember to
remove that binding.

-- 
Deniz Dogan




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

* Re: Suggestion to change the behavior of M-r
  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
  1 sibling, 1 reply; 10+ messages in thread
From: Juri Linkov @ 2009-08-13 23:17 UTC (permalink / raw)
  To: Deniz Dogan; +Cc: emacs-devel

>>> 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.
>>
>> I think M-r is a bad key for window-related functionality.  It is
>> usually associated with search.  For example, we have a plan to use M-r
>> in comint mode to start Isearch (see bug#3746).
>
> M-r is already bound to move-to-window-line by default, my patch
> merely overrides it with a binding to move-to-window-line-top-bottom.

Yes, this is a separate question.  As for move-to-window-line-top-bottom,
I agree it should follow recenter-top-bottom.

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

* Re: Suggestion to change the behavior of M-r
  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
  0 siblings, 2 replies; 10+ messages in thread
From: Deniz Dogan @ 2009-10-04 16:51 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

2009/8/14 Juri Linkov <juri@jurta.org>:
>>>> 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.
>>>
>>> I think M-r is a bad key for window-related functionality.  It is
>>> usually associated with search.  For example, we have a plan to use M-r
>>> in comint mode to start Isearch (see bug#3746).
>>
>> M-r is already bound to move-to-window-line by default, my patch
>> merely overrides it with a binding to move-to-window-line-top-bottom.
>
> Yes, this is a separate question.  As for move-to-window-line-top-bottom,
> I agree it should follow recenter-top-bottom.
>
> --
> Juri Linkov
> http://www.jurta.org/emacs/
>

Can we conclude that this change is a reasonable one which should be
put into Emacs? The original message was posted about half a year ago
and since then no one has objected to this change.

-- 
Deniz Dogan




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

* Re: Suggestion to change the behavior of M-r
  2009-10-04 16:51         ` Deniz Dogan
@ 2009-10-05 21:33           ` Juri Linkov
  2009-11-23  3:57           ` Stefan Monnier
  1 sibling, 0 replies; 10+ messages in thread
From: Juri Linkov @ 2009-10-05 21:33 UTC (permalink / raw)
  To: Deniz Dogan; +Cc: emacs-devel

>> Yes, this is a separate question.  As for move-to-window-line-top-bottom,
>> I agree it should follow recenter-top-bottom.
>
> Can we conclude that this change is a reasonable one which should be
> put into Emacs? The original message was posted about half a year ago
> and since then no one has objected to this change.

While I agree that adding move-to-window-line-top-bottom for consistency
with recenter-top-bottom is reasonable, I don't think recenter-top-bottom
itself has a reasonable implementation now.

The problem is that currently the cycling order `middle -> top -> bottom'
is hard-coded in `recenter-top-bottom'.  I see no reason to impose this
order on users.

Below is a patch that adds a new customizable variable
`recenter-destinations' with the default value '(middle top bottom)
corresponding to the current hard-coded cycling order.  In addition to
possible values `top', `middle', `bottom', it's possible also to specify
integers to move to the absolute window-line.  And float numbers define
the percentage between 0.0 and 1.0 from the top.

As for `move-to-window', we could also do the same for it
and rename it accordingly to something like
move-to-window-line-top-bottom-or-anywhere-in-the-middle ;-)

Index: lisp/window.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/window.el,v
retrieving revision 1.183
diff -c -r1.183 window.el
*** lisp/window.el	4 Oct 2009 00:41:23 -0000	1.183
--- lisp/window.el	5 Oct 2009 21:30:46 -0000
***************
*** 1609,1646 ****
  
  (defvar recenter-last-op nil
    "Indicates the last recenter operation performed.
! Possible values: `top', `middle', `bottom'.")
  
  (defun recenter-top-bottom (&optional arg)
!   "Move current line to window center, top, and bottom, successively.
! With no prefix argument, the first call redraws the frame and
!  centers point vertically within the window.  Successive calls
!  scroll the window, placing point on the top, bottom, and middle
!  consecutively.  The cycling order is middle -> top -> bottom.
  
  A prefix argument is handled like `recenter':
   With numeric prefix ARG, move current line to window-line ARG.
!  With plain `C-u', move current line to window center.
! 
! Top and bottom destinations are actually `scroll-margin' lines
!  the from true window top and bottom."
    (interactive "P")
    (cond
!    (arg (recenter arg))                 ; Always respect ARG.
!    ((or (not (eq this-command last-command))
! 	(eq recenter-last-op 'bottom))
!     (setq recenter-last-op 'middle)
!     (recenter))
     (t
      (let ((this-scroll-margin
  	   (min (max 0 scroll-margin)
  		(truncate (/ (window-body-height) 4.0)))))
        (cond ((eq recenter-last-op 'middle)
! 	     (setq recenter-last-op 'top)
! 	     (recenter this-scroll-margin))
  	    ((eq recenter-last-op 'top)
! 	     (setq recenter-last-op 'bottom)
! 	     (recenter (- -1 this-scroll-margin))))))))
  
  (define-key global-map [?\C-l] 'recenter-top-bottom)
  \f
--- 1609,1667 ----
  
  (defvar recenter-last-op nil
    "Indicates the last recenter operation performed.
! Possible values: `top', `middle', `bottom', integer or float numbers.")
! 
! (defcustom recenter-destinations '(middle top bottom)
!   "Cycling order for `recenter-top-bottom'.
! A list of elements with possible values `top', `middle', `bottom',
! integer or float numbers that define the cycling order for
! the command `recenter-top-bottom'.
! 
! Top and bottom destinations are `scroll-margin' lines the from true
! window top and bottom.  Middle redraws the frame and centers point
! vertically within the window.  Integer number moves current line to
! the specified absolute window-line.  Float number between 0.0 and 1.0
! means the percentage of the screen space from the top.  The default
! cycling order is middle -> top -> bottom."
!   :type '(repeat (choice
! 		  (const :tag "Top" top)
! 		  (const :tag "Middle" middle)
! 		  (const :tag "Bottom" bottom)
! 		  (integer :tag "Line number")
! 		  (float :tag "Percentage")))
!   :version "23.2"
!   :group 'windows)
  
  (defun recenter-top-bottom (&optional arg)
!   "Move current buffer line to the specified window line.
! With no prefix argument, successive calls place point according
! to the cycling order defined by `recenter-destinations'.
  
  A prefix argument is handled like `recenter':
   With numeric prefix ARG, move current line to window-line ARG.
!  With plain `C-u', move current line to window center."
    (interactive "P")
    (cond
!    (arg (recenter arg)) ; Always respect ARG.
     (t
+     (setq recenter-last-op
+ 	  (if (eq this-command last-command)
+ 	      (car (or (cdr (member recenter-last-op recenter-destinations))
+ 		       recenter-destinations))
+ 	    (car recenter-destinations)))
      (let ((this-scroll-margin
  	   (min (max 0 scroll-margin)
  		(truncate (/ (window-body-height) 4.0)))))
        (cond ((eq recenter-last-op 'middle)
! 	     (recenter))
  	    ((eq recenter-last-op 'top)
! 	     (recenter this-scroll-margin))
! 	    ((eq recenter-last-op 'bottom)
! 	     (recenter (- -1 this-scroll-margin)))
! 	    ((integerp recenter-last-op)
! 	     (recenter recenter-last-op))
! 	    ((floatp recenter-last-op)
! 	     (recenter (round (* recenter-last-op (window-height))))))))))
  
  (define-key global-map [?\C-l] 'recenter-top-bottom)
  \f

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

* Re: Suggestion to change the behavior of M-r
  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
  1 sibling, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2009-11-23  3:57 UTC (permalink / raw)
  To: Deniz Dogan; +Cc: Juri Linkov, emacs-devel

>>>>> 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.
>>>> 
>>>> I think M-r is a bad key for window-related functionality.  It is
>>>> usually associated with search.  For example, we have a plan to use M-r
>>>> in comint mode to start Isearch (see bug#3746).
>>> 
>>> M-r is already bound to move-to-window-line by default, my patch
>>> merely overrides it with a binding to move-to-window-line-top-bottom.
>> 
>> Yes, this is a separate question.  As for move-to-window-line-top-bottom,
>> I agree it should follow recenter-top-bottom.
>> 
>> --
>> Juri Linkov
>> http://www.jurta.org/emacs/
>> 

> Can we conclude that this change is a reasonable one which should be
> put into Emacs? The original message was posted about half a year ago
> and since then no one has objected to this change.

Yes, it's a good change, thank you and sorry for not replying earlier.
Could someone install that patch?
It seems to just barely fit within the "tiny patch", tho, so any further
contribution from you wil require some paperwork.


        Stefan




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

* Re: Suggestion to change the behavior of M-r
  2009-11-23  3:57           ` Stefan Monnier
@ 2009-11-23  5:38             ` Stefan Monnier
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2009-11-23  5:38 UTC (permalink / raw)
  To: Deniz Dogan; +Cc: Juri Linkov, emacs-devel

> Could someone install that patch?

Done,


        Stefan




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