emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/multiple-cursors 1cdd730 221/434: Automatically select wor


From: ELPA Syncer
Subject: [nongnu] elpa/multiple-cursors 1cdd730 221/434: Automatically select word/symbol
Date: Sat, 7 Aug 2021 09:20:30 -0400 (EDT)

branch: elpa/multiple-cursors
commit 1cdd73037fd3a0d789846da144bc16fb471d7b35
Author: Takafumi Arakaki <aka.tkf@gmail.com>
Commit: Takafumi Arakaki <aka.tkf@gmail.com>

    Automatically select word/symbol
---
 mc-mark-more.el | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/mc-mark-more.el b/mc-mark-more.el
index ca239e0..eba7bed 100644
--- a/mc-mark-more.el
+++ b/mc-mark-more.el
@@ -225,15 +225,28 @@ With zero ARG, skip the last one and mark next."
       (multiple-cursors-mode 1)
     (multiple-cursors-mode 0)))
 
+(defun mc--select-thing-at-point (thing)
+  (let ((bound (bounds-of-thing-at-point thing)))
+    (when bound
+      (set-mark (car bound))
+      (goto-char (cdr bound))
+      bound)))
+
+(defun mc--select-thing-at-point-or-bark (thing)
+  (unless (or (region-active-p) (mc--select-thing-at-point thing))
+    (error "Mark a region or set cursor on a %s." thing)))
+
 ;;;###autoload
 (defun mc/mark-all-words-like-this ()
   (interactive)
+  (mc--select-thing-at-point-or-bark 'word)
   (let ((mc/enclose-search-term 'words))
     (mc/mark-all-like-this)))
 
 ;;;###autoload
 (defun mc/mark-all-symbols-like-this ()
   (interactive)
+  (mc--select-thing-at-point-or-bark 'symbol)
   (let ((mc/enclose-search-term 'symbols))
     (mc/mark-all-like-this)))
 
@@ -355,6 +368,7 @@ With prefix, it behaves the same as original 
`mc/mark-all-like-this'"
 (defun mc/mark-all-words-like-this-in-defun ()
   "Mark all words like this in defun."
   (interactive)
+  (mc--select-thing-at-point-or-bark 'word)
   (if (mc--in-defun)
       (save-restriction
         (widen)
@@ -366,6 +380,7 @@ With prefix, it behaves the same as original 
`mc/mark-all-like-this'"
 (defun mc/mark-all-symbols-like-this-in-defun ()
   "Mark all symbols like this in defun."
   (interactive)
+  (mc--select-thing-at-point-or-bark 'symbol)
   (if (mc--in-defun)
       (save-restriction
         (widen)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]