Improved mc/mark-more-like-this-extended

- support for terminal
 - more instructive message
 - keymap that can be rebound

Fixes #84
This commit is contained in:
Magnar Sveen 2013-06-07 23:18:01 +02:00
parent 94af07453d
commit cc45842384
2 changed files with 81 additions and 42 deletions

View File

@ -49,6 +49,14 @@ You can [watch an intro to multiple-cursors at Emacs Rocks](http://emacsrocks.co
- `mc/add-cursor-on-click`: Bind to a mouse event to add cursors by clicking. See tips-section. - `mc/add-cursor-on-click`: Bind to a mouse event to add cursors by clicking. See tips-section.
- `mc/pop-mark`: Set a cursor at the current point and move to the next (different) position on the mark stack. This allows for fine grained control over the placement of cursors. - `mc/pop-mark`: Set a cursor at the current point and move to the next (different) position on the mark stack. This allows for fine grained control over the placement of cursors.
### Juggle around with the current cursors
- `mc/unmark-next-like-this`: Remove the cursor furthest down in the buffer.
- `mc/unmark-previous-like-this`: Remove the cursor furthest up in the buffer.
- `mc/skip-to-next-like-this`: Remove the cursor furthest down, marking the next occurance down.
- `mc/skip-to-previous-like-this`: Remove the cursor furthest up, marking the next occurance up.
- `mc/mark-next-like-this-extended`: Temporarily bind the arrow keys to mark/unmark/skip cursors.
### Mark many occurrences ### Mark many occurrences
- `mc/edit-lines`: Adds one cursor to each line in the current region. - `mc/edit-lines`: Adds one cursor to each line in the current region.

View File

@ -191,17 +191,29 @@ With zero ARG, skip the last one and mark next."
(mc/maybe-multiple-cursors-mode)) (mc/maybe-multiple-cursors-mode))
;;;###autoload ;;;###autoload
(defun mc/unmark-next-like-this (arg) (defun mc/unmark-next-like-this ()
"Deselect next part of the buffer matching the currently active region." "Deselect next part of the buffer matching the currently active region."
(interactive) (interactive)
(mc/mark-next-like-this -1)) (mc/mark-next-like-this -1))
;;;###autoload ;;;###autoload
(defun mc/unmark-previous-like-this (arg) (defun mc/unmark-previous-like-this ()
"Deselect prev part of the buffer matching the currently active region." "Deselect prev part of the buffer matching the currently active region."
(interactive) (interactive)
(mc/mark-previous-like-this -1)) (mc/mark-previous-like-this -1))
;;;###autoload
(defun mc/skip-to-next-like-this ()
"Skip the current one and select the next part of the buffer matching the currently active region."
(interactive)
(mc/mark-next-like-this 0))
;;;###autoload
(defun mc/skip-to-previous-like-this ()
"Skip the current one and select the prev part of the buffer matching the currently active region."
(interactive)
(mc/mark-previous-like-this 0))
;;;###autoload ;;;###autoload
(defun mc/mark-all-like-this () (defun mc/mark-all-like-this ()
"Find and mark all the parts of the buffer matching the currently active region" "Find and mark all the parts of the buffer matching the currently active region"
@ -272,49 +284,68 @@ With zero ARG, skip the last one and mark next."
;;;###autoload ;;;###autoload
(defun mc/mark-more-like-this-extended () (defun mc/mark-more-like-this-extended ()
"Like mark-more-like-this, but then lets you adjust with arrows key. "Like mark-more-like-this, but then lets you adjust with arrows key.
The actual adjustment made depends on the final component of the The adjustments work like this:
key-binding used to invoke the command, with all modifiers removed:
<up> Mark previous like this <up> Mark previous like this and set direction to 'up
<down> Mark next like this <down> Mark next like this and set direction to 'down
<left> If last was previous, skip it
If last was next, remove it
<right> If last was next, skip it
If last was previous, remove it
Then, continue to read input events and further add or move marks If direction is 'up:
as long as the input event read (with all modifiers removed)
is one of the above." <left> Skip past the cursor furthest up
<right> Remove the cursor furthest up
If direction is 'down:
<left> Remove the cursor furthest down
<right> Skip past the cursor furthest down
The bindings for these commands can be changed. See `mc/mark-more-like-this-extended-keymap'."
(interactive) (interactive)
(let ((first t) (mc/mmlte--down)
(ev last-command-event) (set-temporary-overlay-map mc/mark-more-like-this-extended-keymap t))
(cmd 'mc/mark-next-like-this)
(arg 1) (defvar mc/mark-more-like-this-extended-direction nil
last echo-keystrokes) "When using mc/mark-more-like-this-extended are we working on the next or previous cursors?")
(while cmd
(let ((base (event-basic-type ev))) (make-variable-buffer-local 'mc/mark-more-like-this-extended)
(cond ((eq base 'left)
(if (eq last 'mc/mark-previous-like-this) (defun mc/mmlte--message ()
(setq cmd last arg 0) (if (eq mc/mark-more-like-this-extended-direction 'up)
(setq cmd 'mc/mark-next-like-this arg -1))) (message "<up> to mark previous, <left> to skip, <right> to remove, <down> to mark next")
((eq base 'up) (message "<down> to mark next, <right> to skip, <left> to remove, <up> to mark previous")))
(setq cmd 'mc/mark-previous-like-this arg 1))
((eq base 'right) (defun mc/mmlte--up ()
(if (eq last 'mc/mark-next-like-this) (interactive)
(setq cmd last arg 0) (mc/mark-previous-like-this 1)
(setq cmd 'mc/mark-previous-like-this arg -1))) (setq mc/mark-more-like-this-extended-direction 'up)
((eq base 'down) (mc/mmlte--message))
(setq cmd 'mc/mark-next-like-this arg 1))
(first (defun mc/mmlte--down ()
(setq cmd 'mc/mark-next-like-this arg 1)) (interactive)
(t (mc/mark-next-like-this 1)
(setq cmd nil)))) (setq mc/mark-more-like-this-extended-direction 'down)
(when cmd (mc/mmlte--message))
(ignore-errors
(funcall cmd arg)) (defun mc/mmlte--left ()
(setq first nil last cmd) (interactive)
(setq ev (read-event "Use arrow keys for more marks: ")))) (if (eq mc/mark-more-like-this-extended-direction 'down)
(push ev unread-command-events))) (mc/unmark-next-like-this)
(mc/skip-to-previous-like-this))
(mc/mmlte--message))
(defun mc/mmlte--right ()
(interactive)
(if (eq mc/mark-more-like-this-extended-direction 'up)
(mc/unmark-previous-like-this)
(mc/skip-to-next-like-this))
(mc/mmlte--message))
(defvar mc/mark-more-like-this-extended-keymap (make-sparse-keymap))
(define-key mc/mark-more-like-this-extended-keymap (kbd "<up>") 'mc/mmlte--up)
(define-key mc/mark-more-like-this-extended-keymap (kbd "<down>") 'mc/mmlte--down)
(define-key mc/mark-more-like-this-extended-keymap (kbd "<left>") 'mc/mmlte--left)
(define-key mc/mark-more-like-this-extended-keymap (kbd "<right>") 'mc/mmlte--right)
(defvar mc--restrict-mark-all-to-symbols nil) (defvar mc--restrict-mark-all-to-symbols nil)