[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/multiple-cursors 1074c88 178/434: Added mc/mark-all-like-t
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/multiple-cursors 1074c88 178/434: Added mc/mark-all-like-this-dwim |
Date: |
Sat, 7 Aug 2021 09:20:21 -0400 (EDT) |
branch: elpa/multiple-cursors
commit 1074c88c99da4696585b98983cfebba4b568d02a
Author: unknown <Matus@.(none)>
Commit: unknown <Matus@.(none)>
Added mc/mark-all-like-this-dwim
---
mc-mark-more.el | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/mc-mark-more.el b/mc-mark-more.el
index d5fe4a7..7a0f519 100644
--- a/mc-mark-more.el
+++ b/mc-mark-more.el
@@ -308,6 +308,60 @@ is one of the above."
(setq ev (read-event "Use arrow keys for more marks: "))))
(push ev unread-command-events)))
+(defun mc/mark-all-like-this-dwim (arg)
+ "Uses some sane defaults to guess what the user want to do:
+
+- If inside a defun, find and mark all the parts of current defun matchign
+the currently active region. If no region is active, activate the word
+under cursor.
+- If in SGML/HTML mode and inside a tag, select the tag and its pair
+
+With prefix, it behaves the same as original `mc/mark-all-like-this'"
+ (interactive "P")
+ (if arg
+ (mc/mark-all-like-this)
+ (let ((mode (with-current-buffer (current-buffer) major-mode)))
+ (cond ((and (member mode '(sgml-mode html-mode))
+ (mc/mark-tags)) t)
+ ((bounds-of-thing-at-point 'defun)
+ (mc/select-under-cursor)
+ (save-restriction
+ (widen)
+ (narrow-to-defun)
+ (mc/mark-all-like-this)))
+ (t (mc/select-under-cursor) (mc/mark-all-like-this))))))
+
+(defun mc/select-under-cursor ()
+ "Select the word under cursor"
+ (interactive)
+ (when (not (use-region-p))
+ (let ((b (bounds-of-thing-at-point 'word)))
+ (goto-char (car b))
+ (set-mark (cdr b)))))
+
+(defun mc/mark-tags ()
+ "Mark the tag we're in and its pair for renaming."
+ (interactive)
+ (let ((context (car (last (save-excursion (sgml-get-context))))))
+ (when (and context
+ (> (point) (aref context 2))
+ (< (point) (aref context 3)))
+ (let* ((tag-position (aref context 1))
+ (tag-length (length (aref context 4)))
+ (main-start (- (aref context 3) 1 tag-length))
+ (mirror-start (save-excursion
+ (if (eq tag-position 'open)
+ (sgml-skip-tag-forward 1)
+ (sgml-skip-tag-backward 1)
+ (forward-sexp))
+ (- (point) 1 tag-length))))
+ (goto-char main-start)
+ (set-mark (+ main-start tag-length))
+ (mc/save-excursion (goto-char mirror-start)
+ (push-mark (+ mirror-start tag-length))
+ (mc/create-fake-cursor-at-point))
+ (mc/maybe-multiple-cursors-mode)))))
+
(provide 'mc-mark-more)
;;; mc-mark-more.el ends here
- [nongnu] elpa/multiple-cursors f42e467 090/434: Added mc-version of mark-all-in-region, (continued)
- [nongnu] elpa/multiple-cursors f42e467 090/434: Added mc-version of mark-all-in-region, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors b912bf8 096/434: Always require multiple-cursors-core, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 0233ba8 092/434: Add commands to run-once-list, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors ef2226b 116/434: Consolidate kill-ring entries when exiting multiple-cursors-mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors d5a9d57 132/434: Add minibuffer-complete-and-exit to default run-once list., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors b48e2b7 137/434: mc/edit-lines: Don't include the 'invisible' line, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors ae0033f 140/434: Protect post-command-hook from errors to avoids undead cursors, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors fcbb7a4 152/434: Make mc/cycle-forward and mc/cycle-backward loop around by default., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 876937b 153/434: Use (interactive "P") instead of the weird (but equivalent) (interactive (list prefix-arg)), ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 1ec78e1 162/434: Don't let mc/mark-lines create 'double' cursors., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 1074c88 178/434: Added mc/mark-all-like-this-dwim,
ELPA Syncer <=
- [nongnu] elpa/multiple-cursors 9582c72 204/434: Add mc/insert-numbers, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors d534132 122/434: Remove todo.org - use issues instead, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors f7d393d 128/434: Don't use next-line and previous-line in non-interactive ways., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors fc59b63 131/434: Fix typo, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors d98b85b 138/434: Bump to 1.1.2, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 6e9ea1a 149/434: Merge pull request #20 from tkf/diff-friendly-save-lists, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 6d4979d 144/434: Bump to 1.1.3, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors b3ca408 171/434: Have to require 'cl for now, because of count-if., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors a6984a1 203/434: Merge pull request #53 from oneself/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors a37e02b 177/434: Add new mc-commands to default run-once list., ELPA Syncer, 2021/08/07