Can use mc/reverse-regions w/o region or cursors

- will flip sexp at point with the one below it
This commit is contained in:
Magnar Sveen 2013-02-11 07:29:17 +01:00
parent 16add89d29
commit 641eb680ca
5 changed files with 34 additions and 20 deletions

View File

@ -89,6 +89,9 @@ You can [watch an intro to multiple-cursors at Emacs Rocks](http://emacsrocks.co
from the kill-ring of main cursor. To yank from the kill-rings of from the kill-ring of main cursor. To yank from the kill-rings of
every cursor use yank-rectangle, normally found at C-x r y. every cursor use yank-rectangle, normally found at C-x r y.
- You can use `mc/reverse-regions` with nothing selected and just one cursor.
It will then flip the sexp at point and the one below it.
- If you would like to keep the global bindings clean, and get custom keybindings - If you would like to keep the global bindings clean, and get custom keybindings
when the region is active, you can try [region-bindings-mode](https://github.com/fgallina/region-bindings-mode). when the region is active, you can try [region-bindings-mode](https://github.com/fgallina/region-bindings-mode).

View File

@ -57,16 +57,14 @@ line point is on."
"Add one cursor to the end of each line in the active region." "Add one cursor to the end of each line in the active region."
(interactive) (interactive)
(mc/edit-lines) (mc/edit-lines)
(mc/execute-command-for-all-fake-cursors 'end-of-line) (mc/execute-command-for-all-cursors 'end-of-line))
(end-of-line))
;;;###autoload ;;;###autoload
(defun mc/edit-beginnings-of-lines () (defun mc/edit-beginnings-of-lines ()
"Add one cursor to the beginning of each line in the active region." "Add one cursor to the beginning of each line in the active region."
(interactive) (interactive)
(mc/edit-lines) (mc/edit-lines)
(mc/execute-command-for-all-fake-cursors 'beginning-of-line) (mc/execute-command-for-all-cursors 'beginning-of-line))
(beginning-of-line))
(provide 'mc-edit-lines) (provide 'mc-edit-lines)

View File

@ -58,7 +58,7 @@
(defun mc--replace-region-strings-1 () (defun mc--replace-region-strings-1 ()
(interactive) (interactive)
(delete-region (region-beginning) (region-end)) (delete-region (region-beginning) (region-end))
(insert (car mc--strings-to-replace)) (save-excursion (insert (car mc--strings-to-replace)))
(setq mc--strings-to-replace (cdr mc--strings-to-replace))) (setq mc--strings-to-replace (cdr mc--strings-to-replace)))
(defun mc--replace-region-strings () (defun mc--replace-region-strings ()
@ -68,18 +68,23 @@
;;;###autoload ;;;###autoload
(defun mc/reverse-regions () (defun mc/reverse-regions ()
(interactive) (interactive)
(if (not (use-region-p)) (if (not multiple-cursors-mode)
(message "Mark regions to reverse first.") (progn
(mc/mark-next-lines 1)
(mc/reverse-regions)
(multiple-cursors-mode 0))
(unless (use-region-p)
(mc/execute-command-for-all-cursors 'mark-sexp))
(setq mc--strings-to-replace (nreverse (mc--ordered-region-strings))) (setq mc--strings-to-replace (nreverse (mc--ordered-region-strings)))
(mc--replace-region-strings))) (mc--replace-region-strings)))
;;;###autoload ;;;###autoload
(defun mc/sort-regions () (defun mc/sort-regions ()
(interactive) (interactive)
(if (not (use-region-p)) (unless (use-region-p)
(message "Mark regions to sort first.") (mc/execute-command-for-all-cursors 'mark-sexp))
(setq mc--strings-to-replace (sort (mc--ordered-region-strings) 'string<)) (setq mc--strings-to-replace (sort (mc--ordered-region-strings) 'string<))
(mc--replace-region-strings))) (mc--replace-region-strings))
(provide 'mc-separate-operations) (provide 'mc-separate-operations)
;;; mc-separate-operations.el ends here ;;; mc-separate-operations.el ends here

View File

@ -223,6 +223,11 @@ cursor with updated info."
(mc/execute-command-for-fake-cursor cmd cursor))))) (mc/execute-command-for-fake-cursor cmd cursor)))))
(mc--reset-read-prompts)) (mc--reset-read-prompts))
(defun mc/execute-command-for-all-cursors (cmd)
"Calls CMD interactively for the real cursor and all fakes."
(call-interactively cmd)
(mc/execute-command-for-all-fake-cursors cmd))
;; Intercept some reading commands so you won't have to ;; Intercept some reading commands so you won't have to
;; answer them for every single cursor ;; answer them for every single cursor

View File

@ -91,24 +91,27 @@
;; - To get out of multiple-cursors-mode, press `<return>` or `C-g`. The latter will ;; - To get out of multiple-cursors-mode, press `<return>` or `C-g`. The latter will
;; first disable multiple regions before disabling multiple cursors. If you want to ;; first disable multiple regions before disabling multiple cursors. If you want to
;; insert a newline in multiple-cursors-mode, use `C-j`. ;; insert a newline in multiple-cursors-mode, use `C-j`.
;;
;; - Sometimes you end up with cursors outside of your view. You can ;; - Sometimes you end up with cursors outside of your view. You can
;; scroll the screen to center on each cursor with `C-v` and `M-v`. ;; scroll the screen to center on each cursor with `C-v` and `M-v`.
;;
;; - Try pressing `mc/mark-next-like-this` with no region selected. It will just add a cursor ;; - Try pressing `mc/mark-next-like-this` with no region selected. It will just add a cursor
;; on the next line. ;; on the next line.
;;
;; - Try pressing `mc/mark-all-like-this-dwim` on a tagname in html-mode. ;; - Try pressing `mc/mark-all-like-this-dwim` on a tagname in html-mode.
;;
;; - Notice that the number of cursors active can be seen in the modeline. ;; - Notice that the number of cursors active can be seen in the modeline.
;;
;; - If you get out of multiple-cursors-mode and yank - it will yank only ;; - If you get out of multiple-cursors-mode and yank - it will yank only
;; from the kill-ring of main cursor. To yank from the kill-rings of ;; from the kill-ring of main cursor. To yank from the kill-rings of
;; every cursor use yank-rectangle, normally found at C-x r y. ;; every cursor use yank-rectangle, normally found at C-x r y.
;;
;; - You can use `mc/reverse-regions` with nothing selected and just one cursor.
;; It will then flip the sexp at point and the one below it.
;;
;; - If you would like to keep the global bindings clean, and get custom keybindings ;; - If you would like to keep the global bindings clean, and get custom keybindings
;; when the region is active, you can try [region-bindings-mode](https://github.com/fgallina/region-bindings-mode). ;; when the region is active, you can try [region-bindings-mode](https://github.com/fgallina/region-bindings-mode).
;;
;; BTW, I highly recommend adding `mc/mark-next-like-this` to a key binding that's ;; BTW, I highly recommend adding `mc/mark-next-like-this` to a key binding that's
;; right next to the key for `er/expand-region`. ;; right next to the key for `er/expand-region`.