mirror of
https://github.com/magnars/multiple-cursors.el.git
synced 2025-10-14 13:23:06 +00:00
Add word/symbol limiting mark-more functions:
- mc/mark-next-word-like-this - mc/mark-next-symbol-like-this - mc/mark-previous-word-like-this - mc/mark-previous-symbol-like-this - mc/mark-all-words-like-this - mc/mark-all-symbols-like-this Fixes #24
This commit is contained in:
parent
1afbb9317c
commit
fe211c018c
@ -85,9 +85,18 @@
|
|||||||
(multiple-cursors-mode 1)
|
(multiple-cursors-mode 1)
|
||||||
(multiple-cursors-mode 0)))
|
(multiple-cursors-mode 0)))
|
||||||
|
|
||||||
|
(defvar mc/enclose-search-term nil
|
||||||
|
"How should mc/mark-more-* search for more matches?
|
||||||
|
|
||||||
|
Match everything: nil
|
||||||
|
Match only whole words: 'words
|
||||||
|
Match only whole symbols: 'symbols
|
||||||
|
|
||||||
|
Use like case-fold-search, don't recommend setting it globally.")
|
||||||
|
|
||||||
(defun mc/mark-more-like-this (skip-last direction)
|
(defun mc/mark-more-like-this (skip-last direction)
|
||||||
(let ((case-fold-search nil)
|
(let ((case-fold-search nil)
|
||||||
(re (regexp-opt (mc/region-strings)))
|
(re (regexp-opt (mc/region-strings) mc/enclose-search-term))
|
||||||
(point-out-of-order (ecase direction
|
(point-out-of-order (ecase direction
|
||||||
(forwards (< (point) (mark)))
|
(forwards (< (point) (mark)))
|
||||||
(backwards (not (< (point) (mark))))))
|
(backwards (not (< (point) (mark))))))
|
||||||
@ -128,6 +137,18 @@ With zero ARG, skip the last one and mark next."
|
|||||||
(mc/mark-lines arg 'forwards))
|
(mc/mark-lines arg 'forwards))
|
||||||
(mc/maybe-multiple-cursors-mode))
|
(mc/maybe-multiple-cursors-mode))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun mc/mark-next-word-like-this (arg)
|
||||||
|
(interactive "p")
|
||||||
|
(let ((mc/enclose-search-term 'words))
|
||||||
|
(mc/mark-next-like-this arg)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun mc/mark-next-symbol-like-this (arg)
|
||||||
|
(interactive "p")
|
||||||
|
(let ((mc/enclose-search-term 'symbols))
|
||||||
|
(mc/mark-next-like-this arg)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun mc/mark-previous-like-this (arg)
|
(defun mc/mark-previous-like-this (arg)
|
||||||
"Find and mark the previous part of the buffer matching the currently active region
|
"Find and mark the previous part of the buffer matching the currently active region
|
||||||
@ -141,6 +162,18 @@ With zero ARG, skip the last one and mark next."
|
|||||||
(mc/mark-lines arg 'backwards))
|
(mc/mark-lines arg 'backwards))
|
||||||
(mc/maybe-multiple-cursors-mode))
|
(mc/maybe-multiple-cursors-mode))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun mc/mark-previous-word-like-this (arg)
|
||||||
|
(interactive "p")
|
||||||
|
(let ((mc/enclose-search-term 'words))
|
||||||
|
(mc/mark-previous-like-this arg)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun mc/mark-previous-symbol-like-this (arg)
|
||||||
|
(interactive "p")
|
||||||
|
(let ((mc/enclose-search-term 'symbols))
|
||||||
|
(mc/mark-previous-like-this arg)))
|
||||||
|
|
||||||
(defun mc/mark-lines (num-lines direction)
|
(defun mc/mark-lines (num-lines direction)
|
||||||
(dotimes (i num-lines)
|
(dotimes (i num-lines)
|
||||||
(mc/create-fake-cursor-at-point)
|
(mc/create-fake-cursor-at-point)
|
||||||
@ -184,7 +217,7 @@ With zero ARG, skip the last one and mark next."
|
|||||||
(let ((master (point))
|
(let ((master (point))
|
||||||
(case-fold-search nil)
|
(case-fold-search nil)
|
||||||
(point-first (< (point) (mark)))
|
(point-first (< (point) (mark)))
|
||||||
(re (regexp-opt (mc/region-strings))))
|
(re (regexp-opt (mc/region-strings) mc/enclose-search-term)))
|
||||||
(mc/save-excursion
|
(mc/save-excursion
|
||||||
(goto-char 0)
|
(goto-char 0)
|
||||||
(while (search-forward-regexp re nil t)
|
(while (search-forward-regexp re nil t)
|
||||||
@ -197,6 +230,18 @@ With zero ARG, skip the last one and mark next."
|
|||||||
(multiple-cursors-mode 1)
|
(multiple-cursors-mode 1)
|
||||||
(multiple-cursors-mode 0)))
|
(multiple-cursors-mode 0)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun mc/mark-all-words-like-this ()
|
||||||
|
(interactive)
|
||||||
|
(let ((mc/enclose-search-term 'words))
|
||||||
|
(mc/mark-all-like-this)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun mc/mark-all-symbols-like-this ()
|
||||||
|
(interactive)
|
||||||
|
(let ((mc/enclose-search-term 'symbols))
|
||||||
|
(mc/mark-all-like-this)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun mc/mark-all-in-region (beg end)
|
(defun mc/mark-all-in-region (beg end)
|
||||||
"Find and mark all the parts in the region matching the given search"
|
"Find and mark all the parts in the region matching the given search"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user