branch: elpa/multiple-cursors
commit 0ee76bfad1cf368762e231484c2a0de974cc4797
Author: Magnar Sveen <[email protected]>
Commit: Magnar Sveen <[email protected]>
Add mc/add-cursor-on-click
---
README.md | 13 +++++++++++++
mc-mark-more.el | 17 +++++++++++++++++
multiple-cursors.el | 13 +++++++++++++
3 files changed, 43 insertions(+)
diff --git a/README.md b/README.md
index 2c2f24f..fea5eaf 100644
--- a/README.md
+++ b/README.md
@@ -46,6 +46,7 @@ You can [watch an intro to multiple-cursors at Emacs
Rocks](http://emacsrocks.co
- `mc/mark-previous-word-like-this`: Like `mc/mark-previous-like-this` but
only for whole words.
- `mc/mark-previous-symbol-like-this`: Like `mc/mark-previous-like-this` but
only for whole symbols.
- `mc/mark-more-like-this-extended`: Use arrow keys to quickly mark/skip
next/previous occurances.
+ - `mc/add-cursor-on-click`: Bind to a mouse event to add cursors by clicking.
See tips-section.
### Mark many occurrences
@@ -98,6 +99,18 @@ You can [watch an intro to multiple-cursors at Emacs
Rocks](http://emacsrocks.co
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`.
+### Binding mouse events
+
+To override a mouse event, you will likely have to also unbind the
+`down-mouse` part of the event. Like this:
+
+ (global-unset-key (kbd "M-<down-mouse-1>"))
+ (global-set-key (kbd "M-<mouse-1>") 'mc/add-cursor-on-click)
+
+Or you can do like me and find an unused, but less convenient, binding:
+
+ (global-set-key (kbd "C-S-<mouse-1>") 'mc/add-cursor-on-click)
+
## Unknown commands
Multiple-cursors uses two lists of commands to know what to do: the run-once
list
diff --git a/mc-mark-more.el b/mc-mark-more.el
index 6dffeb5..ca239e0 100644
--- a/mc-mark-more.el
+++ b/mc-mark-more.el
@@ -399,6 +399,23 @@ With prefix, it behaves the same as original
`mc/mark-all-like-this'"
(<= (point) end))))
;;;###autoload
+(defun mc/add-cursor-on-click (event)
+ "Add a cursor where you click."
+ (interactive "e")
+ (mouse-minibuffer-check event)
+ ;; Use event-end in case called from mouse-drag-region.
+ ;; If EVENT is a click, event-end and event-start give same value.
+ (let ((position (event-end event)))
+ (if (not (windowp (posn-window position)))
+ (error "Position not in text area of window"))
+ (select-window (posn-window position))
+ (if (numberp (posn-point position))
+ (save-excursion
+ (goto-char (posn-point position))
+ (mc/create-fake-cursor-at-point)))
+ (mc/maybe-multiple-cursors-mode)))
+
+;;;###autoload
(defun mc/mark-sgml-tag-pair ()
"Mark the tag we're in and its pair for renaming."
(interactive)
diff --git a/multiple-cursors.el b/multiple-cursors.el
index 7ea861a..518855c 100644
--- a/multiple-cursors.el
+++ b/multiple-cursors.el
@@ -66,6 +66,7 @@
;; - `mc/mark-previous-word-like-this`: Like `mc/mark-previous-like-this` but
only for whole words.
;; - `mc/mark-previous-symbol-like-this`: Like `mc/mark-previous-like-this`
but only for whole symbols.
;; - `mc/mark-more-like-this-extended`: Use arrow keys to quickly mark/skip
next/previous occurances.
+;; - `mc/add-cursor-on-click`: Bind to a mouse event to add cursors by
clicking. See tips-section.
;; ### Mark many occurrences
@@ -115,6 +116,18 @@
;; 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`.
+;; ### Binding mouse events
+
+;; To override a mouse event, you will likely have to also unbind the
+;; `down-mouse` part of the event. Like this:
+;;
+;; (global-unset-key (kbd "M-<down-mouse-1>"))
+;; (global-set-key (kbd "M-<mouse-1>") 'mc/add-cursor-on-click)
+;;
+;; Or you can do like me and find an unused, but less convenient, binding:
+;;
+;; (global-set-key (kbd "C-S-<mouse-1>") 'mc/add-cursor-on-click)
+
;; ## Unknown commands
;; Multiple-cursors uses two lists of commands to know what to do: the
run-once list