[Top][All Lists]

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

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

From: Drew Adams
Subject: RE: [PATCH] Make `C-x {' and `C-x }' repeatable
Date: Wed, 22 May 2013 10:44:54 -0700 (PDT)

Juri's suggestion is a good one.

There is another way to do this (which I have mentioned before):

;; Needs library `repeat.el'.  Either autoload it or add (require 'repeat)
;; to a command that needs it.
;;;### (autoload 'repeat-command "repeat" t nil)

(defun repeat-command (command) ; To be added to `repeat.el'.
  "Repeat COMMAND."
  (let ((repeat-message-function  'ignore))
    (setq last-repeatable-command  command)
    (repeat nil)))

You can then make a repeatable command from any ordinary command. 
E.g., window-sizing:

(defun window-widen (arg)
  (interactive "P")
  (repeat-command 'enlarge-window-horizontally))

(defun window-narrow (arg)
  (interactive "P")
  (repeat-command 'shrink-window-horizontally))

(defun window-heighten (arg)
  (interactive "P")
  (repeat-command 'enlarge-window))

(defun window-shorten (arg)
  (interactive "P")
  (repeat-command 'shrink-window))

Bind to any keys you like.  E.g., replace non-repeatable cmds:

(define-key ctl-x-map [(?})] 'window-widen)
(define-key ctl-x-map [(?{)] 'window-narrow)
(define-key ctl-x-map [(?^)] 'window-heighten)
(define-key ctl-x-map [(?-)] 'window-shorten)

And you can put them all on a `window-size-map' keymap, as Juri suggested:

(defvar window-size-map (make-sparse-keymap) "...")
(define-key window-size-map [right] 'window-widen)
(define-key window-size-map [left]  'window-narrow)
(define-key window-size-map [up]    'window-heighten)
(define-key window-size-map [down]  'window-shorten)
(global-set-key [f2] window-size-map)

Juri's suggestion too, of course, does not prevent you from having separate 
repeatable and non-repeatable commands.  E.g.,

(defun window-widen (arg) ; Repeatable `enlarge-window-horizontally'
  (interactive "p")
  (enlarge-window-horizontally arg)
  (set-temporary-overlay-map window-size-map))

An advantage of Juri's suggestion over the `repeat-command' approach is that it 
is not just for repeating a particular command.  You can easily switch from 
`right' to `left' or `down'.  E.g., `f2 right right down down left'.  With the 
`repeat-command' approach you cannot: it recognizes only one command; it is 
really about repetition.

An advantage of the `repeat-command' approach over Juri's suggestion is that 
the prefix arg that you give at the outset is used for each repeated step.

With Juri's suggestion, a prefix arg is available for only the first step.  
Typically you want to repeatedly increase/decrease by the same amount.  You 
cannot even provide a separate prefix arg for each step (which would be 
annoying in general but might have a use in some contexts).

With Juri's suggestion you can make the first use of a command use a step size 
of 6, but repeating it puts you back to a step size of 1.  Perhaps there is a 
simple fix to make Juri's suggestion behave better in this respect.


I take advantage of this thread to point out bug #14095, which I think is 
relevant here and which has so far gotten no response.  It is a regression 
introduced at the same time as that of bug #122232 (which was fixed).  The 
change that introduced both problems is the use of `set-temporary-overlay-map' 
(also pertinent to Juri's suggestion here).

I want to have a repeatable command bound to a key on `isearch-mode-map'.  
E.g., I bind repeatable command `isearchp-yank-line' to `C-y C-e', so I can 
successively yank multiple lines into the search string.  E.g., during Isearch:

  C-y C-e C-e C-e ...

That works with the older `repeat.el' code.  It is broken now because of a 
change to `repeat-repeat-char' so that it uses `set-temporary-overlay-map '.  
This is because the temporary (overlay) map is overruled by 
`overriding(-terminal)-local-map', which Isearch uses.

I would really like to see this bug fixed.  Users should be able to use 
repeatable keys on `isearch-mode-map'.

reply via email to

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