* Patch for more useful C-x } and C-x { behavior
@ 2012-05-05 2:25 Deniz Dogan
2012-05-05 3:15 ` Drew Adams
2012-05-05 3:21 ` Leo
0 siblings, 2 replies; 7+ messages in thread
From: Deniz Dogan @ 2012-05-05 2:25 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 324 bytes --]
"Inspired" by C-x + and C-x -, I wrote a patch which lets the user
repeat the { or } character to continue enlarging/shrinking the selected
window's width.
The patch needs a much better docstring, I'm just too lazy to write one.
I have access to commit, but I wanted to check it with you guys first.
Comments?
Deniz
[-- Attachment #2: window-patch.patch --]
[-- Type: text/plain, Size: 1673 bytes --]
=== modified file 'lisp/window.el'
--- lisp/window.el 2012-05-04 23:16:47 +0000
+++ lisp/window.el 2012-05-05 02:23:30 +0000
@@ -5173,19 +5173,41 @@
(let ((window-min-height (min 2 height))) ; One text line plus a modeline.
(window-resize window delta)))))
+(defun enlarge-window-horizontally-1 (delta)
+ "Make selected window DELTA columns wider."
+ (let ((first t)
+ (step t)
+ (ev last-command-event)
+ (echo-keystrokes nil)
+ (enlarge-char (if (> delta 0) ?} ?{))
+ (shrink-char (if (> delta 0) ?{ ?})))
+ (while step
+ (let ((base (event-basic-type ev)))
+ (setq step (cond ((or first (eq base enlarge-char))
+ delta)
+ ((eq base shrink-char)
+ (- delta)))))
+ (when step
+ (if (> 0 step)
+ (enlarge-window step t)
+ (shrink-window (- step) t))
+ (setq first nil)
+ (setq ev (read-event "},{ for further adjustment: "))))
+ (push ev unread-command-events)))
+
(defun enlarge-window-horizontally (delta)
"Make selected window DELTA columns wider.
Interactively, if no argument is given, make selected window one
column wider."
(interactive "p")
- (enlarge-window delta t))
+ (enlarge-window-horizontally-1 delta))
(defun shrink-window-horizontally (delta)
"Make selected window DELTA columns narrower.
Interactively, if no argument is given, make selected window one
column narrower."
(interactive "p")
- (shrink-window delta t))
+ (enlarge-window-horizontally-1 (- delta)))
(defun count-screen-lines (&optional beg end count-final-newline window)
"Return the number of screen lines in the region.
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Patch for more useful C-x } and C-x { behavior
2012-05-05 2:25 Patch for more useful C-x } and C-x { behavior Deniz Dogan
@ 2012-05-05 3:15 ` Drew Adams
2012-05-05 13:16 ` Deniz Dogan
2012-05-05 3:21 ` Leo
1 sibling, 1 reply; 7+ messages in thread
From: Drew Adams @ 2012-05-05 3:15 UTC (permalink / raw)
To: 'Deniz Dogan', emacs-devel
> "Inspired" by C-x + and C-x -, I wrote a patch which lets the user
> repeat the { or } character to continue enlarging/shrinking
> the selected window's width.
I do that kind of thing in this generic way. The same function `repeat-command'
can be used to define any repeater command. And the prefix arg is passed
through as a bonus, in this case to set the increment (and direction) for the
repetitions.
(defun repeat-command (command)
"Repeat COMMAND."
(let ((repeat-message-function 'ignore))
(setq last-repeatable-command command)
(repeat nil)))
(defun enlarge-window-horiz-repeat (arg)
"..."
(interactive "P")
(require 'repeat)
(repeat-command 'enlarge-window-horizontally))
(defun shrink-window-horiz-repeat (arg)
"..."
(interactive "P")
(require 'repeat)
(repeat-command 'shrink-window-horizontally))
(global-set-key "\C-x{" 'shrink-window-horiz-repeat)
(global-set-key "\C-x}" 'enlarge-window-horiz-repeat)
Of course, there is no `repeat-command' function in vanilla Emacs, so I end up
redefining it in various libraries (`bmkp-repeat-command',
`thgcmd-repeat-command', `wide-n-repeat-command'...).
As an example, I use `bmkp-repeat-command' to define 30 different repeating
commands for cycling among different types of bookmarks and bookmark sort
orders.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Patch for more useful C-x } and C-x { behavior
2012-05-05 2:25 Patch for more useful C-x } and C-x { behavior Deniz Dogan
2012-05-05 3:15 ` Drew Adams
@ 2012-05-05 3:21 ` Leo
1 sibling, 0 replies; 7+ messages in thread
From: Leo @ 2012-05-05 3:21 UTC (permalink / raw)
To: emacs-devel
On 2012-05-05 10:25 +0800, Deniz Dogan wrote:
> "Inspired" by C-x + and C-x -, I wrote a patch which lets the user
> repeat the { or } character to continue enlarging/shrinking the
> selected window's width.
>
> The patch needs a much better docstring, I'm just too lazy to write
> one. I have access to commit, but I wanted to check it with you guys
> first.
>
> Comments?
FWIW, it is better to bring in a new function `make-command-repeatable'
possibly built on top of repeat.el that accepts a command and make it
repeatable.
Leo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Patch for more useful C-x } and C-x { behavior
2012-05-05 3:15 ` Drew Adams
@ 2012-05-05 13:16 ` Deniz Dogan
2012-05-05 14:21 ` Drew Adams
0 siblings, 1 reply; 7+ messages in thread
From: Deniz Dogan @ 2012-05-05 13:16 UTC (permalink / raw)
To: Drew Adams; +Cc: emacs-devel
On 2012-05-05 05:15, Drew Adams wrote:
>> "Inspired" by C-x + and C-x -, I wrote a patch which lets the user
>> repeat the { or } character to continue enlarging/shrinking
>> the selected window's width.
>
> I do that kind of thing in this generic way. The same function `repeat-command'
> can be used to define any repeater command. And the prefix arg is passed
> through as a bonus, in this case to set the increment (and direction) for the
> repetitions.
>
> (defun repeat-command (command)
> "Repeat COMMAND."
> (let ((repeat-message-function 'ignore))
> (setq last-repeatable-command command)
> (repeat nil)))
>
> (defun enlarge-window-horiz-repeat (arg)
> "..."
> (interactive "P")
> (require 'repeat)
> (repeat-command 'enlarge-window-horizontally))
>
> (defun shrink-window-horiz-repeat (arg)
> "..."
> (interactive "P")
> (require 'repeat)
> (repeat-command 'shrink-window-horizontally))
>
> (global-set-key "\C-x{" 'shrink-window-horiz-repeat)
> (global-set-key "\C-x}" 'enlarge-window-horiz-repeat)
>
> Of course, there is no `repeat-command' function in vanilla Emacs, so I end up
> redefining it in various libraries (`bmkp-repeat-command',
> `thgcmd-repeat-command', `wide-n-repeat-command'...).
>
> As an example, I use `bmkp-repeat-command' to define 30 different repeating
> commands for cycling among different types of bookmarks and bookmark sort
> orders.
>
That's great! Could we include it in Emacs?
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Patch for more useful C-x } and C-x { behavior
2012-05-05 13:16 ` Deniz Dogan
@ 2012-05-05 14:21 ` Drew Adams
2012-05-05 17:21 ` Deniz Dogan
0 siblings, 1 reply; 7+ messages in thread
From: Drew Adams @ 2012-05-05 14:21 UTC (permalink / raw)
To: 'Deniz Dogan'; +Cc: emacs-devel
> > (defun repeat-command (command)
> > "Repeat COMMAND."
> > (let ((repeat-message-function 'ignore))
> > (setq last-repeatable-command command)
> > (repeat nil)))
>
> That's great! Could we include it in Emacs?
Of course. I suggested it long ago, as part of this post (see #12):
http://lists.gnu.org/archive/html/emacs-devel/2009-08/msg01153.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Patch for more useful C-x } and C-x { behavior
2012-05-05 14:21 ` Drew Adams
@ 2012-05-05 17:21 ` Deniz Dogan
2012-05-05 17:47 ` Drew Adams
0 siblings, 1 reply; 7+ messages in thread
From: Deniz Dogan @ 2012-05-05 17:21 UTC (permalink / raw)
To: Drew Adams; +Cc: emacs-devel
On 2012-05-05 16:21, Drew Adams wrote:
>>> (defun repeat-command (command)
>>> "Repeat COMMAND."
>>> (let ((repeat-message-function 'ignore))
>>> (setq last-repeatable-command command)
>>> (repeat nil)))
>>
>> That's great! Could we include it in Emacs?
>
> Of course. I suggested it long ago, as part of this post (see #12):
> http://lists.gnu.org/archive/html/emacs-devel/2009-08/msg01153.html
>
I'll be honest and say I didn't read all of it, as I have a very short
attention span, but as I understand it you want to make this sort of
"global" to keybindings such as `C-x o' and others. Would it be
possible to include the generic code you have and then make use of it on
a case-by-case basis?
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Patch for more useful C-x } and C-x { behavior
2012-05-05 17:21 ` Deniz Dogan
@ 2012-05-05 17:47 ` Drew Adams
0 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2012-05-05 17:47 UTC (permalink / raw)
To: 'Deniz Dogan'; +Cc: emacs-devel
> >> That's great! Could we include it in Emacs?
> >
> > Of course. I suggested it long ago, as part of this post (see #12):
^^^^^^^^^
> > http://lists.gnu.org/archive/html/emacs-devel/2009-08/msg01153.html
>
> I'll be honest and say I didn't read all of it, as I have a
> very short attention span, but as I understand it you want to
> make this sort of "global" to keybindings such as `C-x o' and
> others.
No, I was only trying to point you to #12, the part of the message where I
mentioned such a `repeat-command' function.
> Would it be possible to include the generic code you have and then make
> use of it on a case-by-case basis?
Of course. `repeat-command' is a general function and entirely separable from
the rest of what was discussed in that mail thread.
Sorry for side-tracking you. I was not trying to revive that discussion, but
only point out that I already proposed this function (and so yes, from my point
of view it could be included in Emacs).
As I said, I use `repeat-command' a lot, myself. So I know that it can be used
in different contexts that are unrelated.
And the fact that it is not in Emacs means that I end up redefining it in
different files. No big deal - it's short. I do likewise for things like
`remove-if'. ;-) (No, not trying to revive that debate either.)
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-05-05 17:47 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-05 2:25 Patch for more useful C-x } and C-x { behavior Deniz Dogan
2012-05-05 3:15 ` Drew Adams
2012-05-05 13:16 ` Deniz Dogan
2012-05-05 14:21 ` Drew Adams
2012-05-05 17:21 ` Deniz Dogan
2012-05-05 17:47 ` Drew Adams
2012-05-05 3:21 ` Leo
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.