emacs-devel
[Top][All Lists]
Advanced

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

RE: New keybinding suggestion: C-x _ for `shrink-window'


From: Drew Adams
Subject: RE: New keybinding suggestion: C-x _ for `shrink-window'
Date: Thu, 1 Nov 2007 09:54:22 -0700

>     Actually, I'd prefer to deprecate those bindings (along with
>     C-x ^) and replace them with a binding that allows the user to do:
>        M-x window-resize RET
>     (which we'd of course bind to some key) and then
>        ^ ^ ^ } } } } } { { { { } } ...
>     or  left left left up up up up up up up
>
> I think that is worth trying.  To make it convenient we need
> a key binding for window-resize.  How about C-x _?

FWIW - This is trivial to do with Do Re Mi. Function `doremi' lets you
increment or decrement anything repeatedly, using the arrow keys or a mouse
wheel (or both). It is made for this kind of thing.

In this case, we define two commands, `window-resize' and
`window-resize-horizontally', that use `doremi' to increment the height and
width, respectively. Left and right arrows are used for horizontal; up and
down arrows are used for vertical. Each command calls the other whenever the
arrow-key type changes (horizontal vs vertical). Only one of the commands
needs to be bound to a key - e.g. bind `window-resize' to `C-x _'.

Try it. You can get `doremi' here:
http://www.emacswiki.org/cgi-bin/wiki/doremi.el. Some doc is here:
http://www.emacswiki.org/cgi-bin/wiki/DoReMi. You can end either command by
hitting any key besides an arrow or the mouse wheel (e.g. `C-g').

These definitions are trivial, even if they might not appear trivial to
someone unfamiliar with `doremi' - they are typical. The first arg to
`doremi' is an incrementation (growth) function. The second arg is the
initial value. The third arg is the increment to pass to the growth
function. The growth function returns the new value, so that it can be
echoed to the user at each arrow key press.

(defun window-resize (&optional increment window)
  "Change height WINDOW incrementally.
INCREMENT is the size increment.
WINDOW is selected.  WINDOW defaults to the selected window."
  (interactive "p")
  (select-window (or window (selected-window)))
  (doremi (lambda (incr) (shrink-window incr) (window-height))
          (window-height) (- increment) t)
  (when (member (car unread-command-events)
                '(left right M-left M-right))
    (window-resize-horizontally increment window)))

(defun window-resize-horizontally (&optional increment window)
  "Change width of WINDOW incrementally.
INCREMENT is the size increment.
WINDOW is selected.  WINDOW defaults to the selected window."
  (interactive "p")
  (select-window (or window (selected-window)))
  (let ((doremi-up-key 'left)
        (doremi-boost-up-key 'M-left)
        (doremi-down-key 'right)
        (doremi-boost-down-key 'M-right))
    (doremi (lambda (incr) (shrink-window-horizontally incr)
                    (window-width))
            (window-width) nil t))
  (when (member (car unread-command-events)
                (list doremi-up-key doremi-down-key
                      doremi-boost-up-key doremi-boost-down-key))
    (window-resize increment window)))







reply via email to

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