help-gnu-emacs
[Top][All Lists]
Advanced

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

RE: Indenting paragraphs manually


From: Drew Adams
Subject: RE: Indenting paragraphs manually
Date: Mon, 7 Mar 2011 07:04:13 -0800 (PST)

 (let ((repeat-message-function 'ignore))
   (setq last-repeatable-command 'indent-rigidly)
   (repeat nil)))
                
> Wow, this repeat bit is a /COOL/ trick.  I'll have to file this
> snippet away.  Region stays active, and deactivates when
> repeating stops (no mucking with deactivate-mark manually)
> ... very cool.  Thanks for sharing!

You're welcome.  It dawned on me one day, and I've used it a lot ever since.

Actually, I define a repeatabilizer function like this:

(defun bmkp-repeat-command (command)
  "Repeat COMMAND."
  (let ((repeat-message-function  'ignore))
    (setq last-repeatable-command  command)
    (repeat nil)))

Then I pass any number of ordinary, non-repeatable commands to that, to create
repeatable versions of them.  Then I bind the repeatable ones.  Example (from
Bookmark+):

(defun bmkp-next-bookmark-repeat (arg)  ; `C-x p right', `C-x p f'
  "Jump to the Nth-next bookmark in the bookmark navigation list.
This is a repeatable version of `bmkp-next-bookmark'.
N defaults to 1, meaning the next bookmark.
Plain `C-u' means start over at the first bookmark (and no repeat)."
  (interactive "P")
  (require 'repeat)
  (bmkp-repeat-command 'bmkp-next-bookmark))

(define-key bookmark-map [right] 'bmkp-next-bookmark-repeat)
(define-key bookmark-map "f"     'bmkp-next-bookmark-repeat)

You can put a repeatable command on a prefix key, to save keys.  For example, in
Bookmark+ `bookmark-map' is bound to the prefix key `C-x p' - it is available by
default for all bookmark commands.

There are several repeatable commands on this prefix key: `C-x p f', `C-x p
right', `C-x p down', etc.  So you can use `C-x p f f f f f f f'... to cycle one
thing, `C-x p down down down'... to cycle another, etc., and still have lots of
other, non-repeatable keys on the same prefix `C-x p'.

You can even put (repeatable) mouse-wheel rotations on a prefix key:

(define-key bookmark-map (vector (list mouse-wheel-up-event))
            'bmkp-next-bookmark-this-buffer-repeat)

Using a common prefix key gives users a quick way to see all of the related
default key bindings: `C-x p C-h'.  (They can always define shortcut keys if
they want.)

Here is an example where `s' is both a prefix key and a suffix for the prefix
key (different keymap here):

(defun bmkp-bmenu-change-sort-order-repeat (arg) ; `s s'... in bookmark list
  "Cycle to the next sort order.
With a prefix arg, reverse current sort order.
This is a repeatable version of `bmkp-bmenu-change-sort-order'."
  (interactive "P")
  (require 'repeat)
  (bmkp-repeat-command 'bmkp-bmenu-change-sort-order))

(define-key bookmark-bmenu-mode-map "ss" 
            'bmkp-bmenu-change-sort-order-repeat)

Here is a related thread based on this idea of using a prefix key as its own
suffix:
http://lists.gnu.org/archive/html/emacs-devel/2009-08/msg01153.html






reply via email to

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