From: Juri Linkov <juri@jurta.org>
To: Deniz Dogan <deniz.a.m.dogan@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Suggestion to change the behavior of M-r
Date: Tue, 06 Oct 2009 00:33:07 +0300 [thread overview]
Message-ID: <871vlhplv0.fsf@mail.jurta.org> (raw)
In-Reply-To: <7b501d5c0910040951i9855c08iadd859644d6db118@mail.gmail.com> (Deniz Dogan's message of "Sun, 4 Oct 2009 18:51:42 +0200")
>> 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/
next prev parent reply other threads:[~2009-10-05 21:33 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
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 [this message]
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871vlhplv0.fsf@mail.jurta.org \
--to=juri@jurta.org \
--cc=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 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).