Update documentation.

This commit is contained in:
Magnar Sveen 2012-09-24 13:26:55 +02:00
parent bdc4d9aff5
commit f73569fe13
3 changed files with 21 additions and 8 deletions

View File

@ -250,14 +250,14 @@ cursor with updated info."
(overlays-in (point-min) (point-max))))) (overlays-in (point-min) (point-max)))))
(defun mc/execute-this-command-for-all-cursors () (defun mc/execute-this-command-for-all-cursors ()
"Used with post-command-hook to execute supported commands for "Used with post-command-hook to execute supported commands for all cursors.
all cursors. It also checks a list of explicitly unsupported
commands that is prevented even for the original cursor, to
inform about the lack of support.
Commands that are neither supported nor explicitly unsupported It uses two lists of commands to know what to do: the run-once
is executed normally for point, but skipped for the fake list and the run-for-all list. If a command is in neither of these lists,
cursors." it will prompt for the proper action and then save that preference.
Some commands are so unsupported that they are even prevented for
the original cursor, to inform about the lack of support."
(if (eq 1 (mc/num-cursors)) ;; no fake cursors? disable mc-mode (if (eq 1 (mc/num-cursors)) ;; no fake cursors? disable mc-mode
(multiple-cursors-mode 0) (multiple-cursors-mode 0)
(let ((original-command (or (command-remapping this-original-command) (let ((original-command (or (command-remapping this-original-command)
@ -306,6 +306,7 @@ multiple cursors editing.")
(define-key mc/keymap (kbd "<return>") 'multiple-cursors-mode)) (define-key mc/keymap (kbd "<return>") 'multiple-cursors-mode))
(defun mc--all-equal (entries) (defun mc--all-equal (entries)
"Are all these entries equal?"
(let ((first (car entries)) (let ((first (car entries))
(all-equal t)) (all-equal t))
(while (and all-equal entries) (while (and all-equal entries)
@ -314,12 +315,16 @@ multiple cursors editing.")
all-equal)) all-equal))
(defun mc--kill-ring-entries () (defun mc--kill-ring-entries ()
"Return the latest kill-ring entry for each cursor.
The entries are returned in the order they are found in the buffer."
(let (entries) (let (entries)
(mc/for-each-cursor-ordered (mc/for-each-cursor-ordered
(setq entries (cons (car (overlay-get cursor 'kill-ring)) entries))) (setq entries (cons (car (overlay-get cursor 'kill-ring)) entries)))
(reverse entries))) (reverse entries)))
(defun mc--maybe-set-killed-rectangle () (defun mc--maybe-set-killed-rectangle ()
"Add the latest kill-ring entry for each cursor to killed-rectangle.
So you can paste it in later with `yank-rectangle'."
(let ((entries (mc--kill-ring-entries))) (let ((entries (mc--kill-ring-entries)))
(unless (mc--all-equal entries) (unless (mc--all-equal entries)
(setq killed-rectangle entries)))) (setq killed-rectangle entries))))
@ -382,6 +387,7 @@ from being executed if in multiple-cursors-mode."
for running commands with multiple cursors.") for running commands with multiple cursors.")
(defun mc/save-lists () (defun mc/save-lists ()
"Saves preferences for running commands with multiple cursors to `mc/list-file'"
(with-temp-file mc/list-file (with-temp-file mc/list-file
(emacs-lisp-mode) (emacs-lisp-mode)
(insert ";; This file is automatically generated by the multiple-cursors extension.") (insert ";; This file is automatically generated by the multiple-cursors extension.")

View File

@ -125,7 +125,6 @@
;; ;;
;;; Code: ;;; Code:
(require 'multiple-cursors-core)
(require 'mc-edit-lines) (require 'mc-edit-lines)
(require 'mc-cycle-cursors) (require 'mc-cycle-cursors)
(require 'mc-mark-more) (require 'mc-mark-more)

View File

@ -39,6 +39,7 @@
(define-key rectangular-region-mode-map (kbd "<return>") 'rrm/switch-to-multiple-cursors) (define-key rectangular-region-mode-map (kbd "<return>") 'rrm/switch-to-multiple-cursors)
(defun rrm/keyboard-quit () (defun rrm/keyboard-quit ()
"Exit rectangular-region-mode."
(interactive) (interactive)
(rectangular-region-mode 0) (rectangular-region-mode 0)
(rrm/remove-rectangular-region-overlays) (rrm/remove-rectangular-region-overlays)
@ -47,12 +48,17 @@
;; Bind this to a key (for instance H-SPC) to start rectangular-region-mode ;; Bind this to a key (for instance H-SPC) to start rectangular-region-mode
;;;###autoload ;;;###autoload
(defun set-rectangular-region-anchor () (defun set-rectangular-region-anchor ()
"Anchors the rectangular region at point.
Think of this one as `set-mark' except you're marking a rectangular region. It is
an exceedingly quick way of adding multiple cursors to multiple lines."
(interactive) (interactive)
(set-marker rrm/anchor (point)) (set-marker rrm/anchor (point))
(push-mark (point)) (push-mark (point))
(rectangular-region-mode 1)) (rectangular-region-mode 1))
(defun rrm/remove-rectangular-region-overlays () (defun rrm/remove-rectangular-region-overlays ()
"Remove all rectangular-region overlays."
(mc/remove-fake-cursors) (mc/remove-fake-cursors)
(mapc #'(lambda (o) (mapc #'(lambda (o)
(when (eq (overlay-get o 'type) 'additional-region) (when (eq (overlay-get o 'type) 'additional-region)
@ -60,6 +66,7 @@
(overlays-in (point-min) (point-max)))) (overlays-in (point-min) (point-max))))
(defun rrm/repaint () (defun rrm/repaint ()
"Start from the anchor and draw a rectangle between it and point."
(rrm/remove-rectangular-region-overlays) (rrm/remove-rectangular-region-overlays)
(let* ((annoying-arrows-mode nil) (let* ((annoying-arrows-mode nil)
(point-column (current-column)) (point-column (current-column))
@ -83,6 +90,7 @@
(mc/create-fake-cursor-at-point))))))) (mc/create-fake-cursor-at-point)))))))
(defun rrm/switch-to-multiple-cursors (&rest forms) (defun rrm/switch-to-multiple-cursors (&rest forms)
"Switch from rectangular-region-mode to multiple-cursors-mode."
(interactive) (interactive)
(rectangular-region-mode 0) (rectangular-region-mode 0)
(multiple-cursors-mode 1)) (multiple-cursors-mode 1))