emacs-devel
[Top][All Lists]
Advanced

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

[PATCH] Make `C-x {' and `C-x }' repeatable


From: Gauthier Östervall
Subject: [PATCH] Make `C-x {' and `C-x }' repeatable
Date: Mon, 20 May 2013 21:59:06 +0200

Ever since I started using emacs and tried to say good bye to my
mouse, I have felt that the resizing of windows with `C-x }' and
`C-x {' is too cumbersome to use.

- Typing `C-x }' several times in a row is not practical.
- I always undershoot when using things of the form `M-10 C-x }'
- I alway overshoot when using `C-x } C-x zzzzz'

This branch makes `C-x {' and `C-x }' behave similarly to `C-x
C-+' (text-scale-adjust).  After the original `C-x }' (or `C-x
{'), additional `{' and `}' continue to resize the window, until
the user enters another character.

The change is in lisp/window.el, which has dynamic scoping.  I
understand that this new function would be better with lexical
binding, allowing for a clean closure.  However I do not feel
confident enough (yet) with dynamic scoping to change the file's
binding mode by myself.

Please tell me if I should have done that differently, and I'll
try to implement it.  I'd be happy to see window.el get lexical
binding, and use a closure instead of a macro.   If the patch is
acceptable as is, it would be very nice to see it integrated.

Note that this is my first patch to GNU Emacs and with bzr.  I
might for example have missed indentation conventions (no tabs in
the new function, only spaces), but I could not find info about
tabbing conventions on the wiki or gnu.org (a link would be
welcome, if available).  Please guide me if I missed other
standard things.

https://code.launchpad.net/~gauthier-i/emacs/resize-window-repeat
lp:~gauthier-i/emacs/resize-window-repeat
Launchpad says that the branch is "Updating" and "empty", and has
been saying so for days.  Weeks, really.  The code seems to be
there though.  Tell me if it's not reachable for you, and if you
have suggestions for how to fix it, it'd be nice.

Otherwise, here's the bundle:

# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: address@hidden
# target_branch: file:///media/sf_prog/emacs/trunk/
# testament_sha1: 6d88925597179e2c8c55153d5f9c62703d6ecd68
# timestamp: 2013-05-20 21:51:05 +0200
# base_revision_id: address@hidden
#
# Begin patch
=== modified file 'lisp/ChangeLog' (properties changed: -x to +x)
--- lisp/ChangeLog      2013-04-29 20:09:18 +0000
+++ lisp/ChangeLog      2013-05-20 19:36:32 +0000
@@ -1,3 +1,7 @@
+2013-05-20  Gauthier Ostervall  <address@hidden>
+
+       * window.el (window-size-adjust): New function.
+
 2013-04-29  Leo Liu  <address@hidden>

        * progmodes/octave.el (octave-font-lock-keywords): Handle 'end' in

=== modified file 'lisp/window.el' (properties changed: -x to +x)
--- lisp/window.el      2013-04-13 14:37:20 +0000
+++ lisp/window.el      2013-05-07 12:13:36 +0000
@@ -6025,6 +6025,48 @@
   (interactive "p")
   (shrink-window delta t))

+;;;###autoload (define-key ctl-x-map [(?{)] 'window-size-adjust)
+;;;###autoload (define-key ctl-x-map [(?})] 'window-size-adjust)
+;;;###autoload
+(defun window-size-adjust (inc)
+  "Adjust the width or height of the current window by INC.
+
+INC may be passed as a numeric prefix argument.
+
+The actual adjustment made depends on the final component of the
+key-binding used to invoke the command, with all modifiers removed:
+
+   {      Decrease the window width by one step
+   }      Increase the window width by one step
+
+When adjusting with `{' or `}', continue to read input events and
+further adjust the windows width as long as the input event read
+\(with all modifiers removed) is `{' or `}'.
+
+This command is a special-purpose wrapper around the
+`enlarge-window-horizontally' command which makes repetition convenient
+even when it is bound in a non-top-level keymap.  For binding in
+a top-level keymap, `enlarge-window-horzontally' or
+`shrink-window-horizontally' may be more appropriate."
+  (interactive "p")
+  (let ((ev last-command-event)
+        (echo-keystrokes nil))
+    (let* ((base (event-basic-type ev))
+           (step
+            (pcase base
+              (?{ (- inc))
+              (?} inc)
+              (t inc))))
+      (enlarge-window-horizontally step)
+      (message "Use {,} for further adjustment")
+      (set-temporary-overlay-map
+       (let ((map (make-sparse-keymap)))
+         (dolist (mods '(()))
+           (dolist (key '(?{ ?}))
+             (define-key map (vector (append mods (list key)))
+               `(lambda () (interactive) (window-size-adjust (abs ,inc))))))
+         map)))))
+
 (defun count-screen-lines (&optional beg end count-final-newline window)
   "Return the number of screen lines in the region.
 The number of screen lines may be different from the number of actual lines,
@@ -6734,8 +6776,8 @@
 (define-key ctl-x-map "3" 'split-window-right)
 (define-key ctl-x-map "o" 'other-window)
 (define-key ctl-x-map "^" 'enlarge-window)
-(define-key ctl-x-map "}" 'enlarge-window-horizontally)
-(define-key ctl-x-map "{" 'shrink-window-horizontally)
+(define-key ctl-x-map "}" 'window-size-adjust)
+(define-key ctl-x-map "{" 'window-size-adjust)
 (define-key ctl-x-map "-" 'shrink-window-if-larger-than-buffer)
 (define-key ctl-x-map "+" 'balance-windows)
 (define-key ctl-x-4-map "0" 'kill-buffer-and-window)

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWUR/XcIAA/JfgH74WPf///+n
ho7////6YAkK7fS3YOIhVusmxkEqACmjWEiiJkxDKPTRppPVHpPU/VGQZI0GRoMIMCB5QSiJk0MS
aegonoQ0NDQNAAaAAGQGg5hNAaA0aMI0GI0xMmJoMI0DIBkwEpoUKaNT1N6gGpg0hgABqZkIwhoZ
oTAOYTQGgNGjCNBiNMTJiaDCNAyAZMBJEEyCMJNT01PJpMmNQT0k2EnpkgNAAabRK6mNCpOOvNw/
OIe/dNMDz+/5GP6nDKPHn45+VmllrIPBUm1m4uQt3tbOqpYhDglwOvchbLk+9SIm0crpRhHhgZOW
rUZ5CqssSQoh2dsEB87ObMs5sMOy89x49p/GqG68xIs5uTEfC1Corm0aJWgQjKwBYkxGVuVmTJKS
Cpdmy+RTBmujjTpNTI7nJnUYsLmtuZuvHyK+Z838rpjofnMsh9ll/PXruCQbxjgNl+MjHWYjPbrL
PfdaRrhyhImt5hzK2llPVWWRxFs3y0ZYWaKXZWFm/hatpRXPCLCOFQTb+nLm+VmkqxarFbdAZB0I
FUBRx02V7TN3ZYrYWwO/bn3ddT0w34eo85PfOmnZ8xSnlBmSZgY+S+IuCyJKxBcQX1txgdQTA5fe
9evXaqhvFX+RyaH5XsYcr6davd/jjFG5uMV56sspl3mea+iIUz4SRdObCF8uEtVk1vb+Z8u8tMjD
6RWiSsPDocggnpan18xfNB7A9h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