[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/multiple-cursors 9582c72 204/434: Add mc/insert-numbers
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/multiple-cursors 9582c72 204/434: Add mc/insert-numbers |
Date: |
Sat, 7 Aug 2021 09:20:26 -0400 (EDT) |
branch: elpa/multiple-cursors
commit 9582c7220bb106ee8a803a44ffe31753ec480f4f
Author: Magnar Sveen <magnars@gmail.com>
Commit: Magnar Sveen <magnars@gmail.com>
Add mc/insert-numbers
- adds increasing numbers for each cursor, top to bottom
---
README.md | 9 +++++---
features/insert-numbers.feature | 13 ++++++++++++
features/support/env.el | 1 +
mc-insert-numbers.el | 47 +++++++++++++++++++++++++++++++++++++++++
multiple-cursors-core.el | 26 +++++++++++++----------
multiple-cursors.el | 6 ++++++
6 files changed, 88 insertions(+), 14 deletions(-)
diff --git a/README.md b/README.md
index 7502326..fe873fc 100644
--- a/README.md
+++ b/README.md
@@ -62,6 +62,7 @@ You can [watch an intro to multiple-cursors at Emacs
Rocks](http://emacsrocks.co
- `set-rectangular-region-anchor`: Think of this one as `set-mark` except
you're marking a rectangular region.
- `mc/mark-sgml-tag-pair`: Mark the current opening and closing tag.
+ - `mc/insert-numbers`: Insert increasing numbers for each cursor, top to
bottom.
## Tips and tricks
@@ -72,14 +73,16 @@ You can [watch an intro to multiple-cursors at Emacs
Rocks](http://emacsrocks.co
- Sometimes you end up with cursors outside of your view. You can
scroll the screen to center on each cursor with `C-v` and `M-v`.
-- Try pressing `mc/mark-next-like-this` with no region selected. It will just
add a cursor
- on the next line.
+- Try pressing `mc/mark-next-like-this` with no region selected. It
+ will just add a cursor on the next line.
- Try pressing `mc/mark-all-like-this-dwim` on a tagname in html-mode.
- Notice that the number of cursors active can be seen in the modeline.
-- If you get out of multiple-cursors-mode and yank - it will yank only from
the kill-ring of main cursor. To yank from the kill-rings of every cursor use
yank-rectangle, normally found at C-x r y.
+- If you get out of multiple-cursors-mode and yank - it will yank only
+ from the kill-ring of main cursor. To yank from the kill-rings of
+ every cursor use yank-rectangle, normally found at C-x r y.
- If you would like to keep the global bindings clean, and get custom
keybindings
when the region is active, you can try
[region-bindings-mode](https://github.com/fgallina/region-bindings-mode).
diff --git a/features/insert-numbers.feature b/features/insert-numbers.feature
new file mode 100644
index 0000000..75f5665
--- /dev/null
+++ b/features/insert-numbers.feature
@@ -0,0 +1,13 @@
+Feature: Insert increasing numbers
+
+ Scenario: Three cursors, 0-1-2
+ Given I have cursors at "text" in "This text contains the word text thrice
(text)"
+ When I press "H-0"
+ And I press "SPC"
+ Then I should see "This 0 text contains the word 1 text thrice (2 text)"
+
+ Scenario: Three cursors, 9-10-11
+ Given I have cursors at "text" in "This text contains the word text thrice
(text)"
+ When I press "C-9 H-0"
+ And I press "SPC"
+ Then I should see "This 9 text contains the word 10 text thrice (11 text)"
diff --git a/features/support/env.el b/features/support/env.el
index 53edb3b..f6da1f5 100644
--- a/features/support/env.el
+++ b/features/support/env.el
@@ -25,6 +25,7 @@
(global-set-key (kbd "M-!") 'mc/mark-all-like-this)
(global-set-key (kbd "M-$") 'mc/mark-all-like-this-dwim)
(global-set-key (kbd "M-#") 'mc/mark-all-in-region)
+ (global-set-key (kbd "H-0") 'mc/insert-numbers)
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "H-SPC") 'set-rectangular-region-anchor)
(switch-to-buffer
diff --git a/mc-insert-numbers.el b/mc-insert-numbers.el
new file mode 100644
index 0000000..d226c69
--- /dev/null
+++ b/mc-insert-numbers.el
@@ -0,0 +1,47 @@
+;;; mc-insert-numbers.el
+
+;; Copyright (C) 2012 Magnar Sveen
+
+;; Author: Magnar Sveen <magnars@gmail.com>
+;; Keywords: editing cursors
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This file contains functions for adding increasing integers to
+;; each cursor.
+
+;; Please see multiple-cursors.el for more commentary.
+
+;;; Code:
+
+(require 'multiple-cursors-core)
+
+;;;###autoload
+(defun mc/insert-numbers (arg)
+ (interactive "P")
+ (setq mc--insert-numbers-number (or arg 0))
+ (mc/for-each-cursor-ordered
+ (mc/execute-command-for-fake-cursor 'mc--insert-number-and-increase
cursor)))
+
+(defvar mc--insert-numbers-number 0)
+
+(defun mc--insert-number-and-increase ()
+ (interactive)
+ (insert (number-to-string mc--insert-numbers-number))
+ (setq mc--insert-numbers-number (1+ mc--insert-numbers-number)))
+
+(provide 'mc-insert-numbers)
+;;; mc-insert-numbers.el ends here
diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el
index eba2417..0069bcf 100644
--- a/multiple-cursors-core.el
+++ b/multiple-cursors-core.el
@@ -72,12 +72,12 @@
(defmacro mc/for-each-cursor-ordered (&rest forms)
"Runs the body for each cursor, fake and real, bound to the name cursor"
- `(let ((real-cursor (mc/create-fake-cursor-at-point)))
+ `(let ((real-cursor-id (overlay-get (mc/create-fake-cursor-at-point)
'mc-id)))
(mapc #'(lambda (cursor)
(when (mc/fake-cursor-p cursor)
,@forms))
(sort (overlays-in (point-min) (point-max))
'mc--compare-by-overlay-start))
- (mc/pop-state-from-overlay real-cursor)))
+ (mc/pop-state-from-overlay (mc/cursor-with-id real-cursor-id))))
(defmacro mc/save-window-scroll (&rest forms)
"Saves and restores the window scroll position"
@@ -198,6 +198,17 @@ Saves the current state in the overlay to be restored
later."
(defvar mc--executing-command-for-fake-cursor nil)
+(defun mc/execute-command-for-fake-cursor (cmd cursor)
+ (let ((mc--executing-command-for-fake-cursor t)
+ (id (overlay-get cursor 'mc-id))
+ (annoying-arrows-mode nil)
+ (smooth-scroll-margin 0))
+ (mc/add-fake-cursor-to-undo-list
+ (mc/pop-state-from-overlay cursor)
+ (ignore-errors
+ (mc/execute-command cmd)
+ (mc/create-fake-cursor-at-point id)))))
+
(defun mc/execute-command-for-all-fake-cursors (cmd)
"Calls CMD interactively for each cursor.
It works by moving point to the fake cursor, setting
@@ -208,15 +219,7 @@ cursor with updated info."
(mc/save-window-scroll
(mc/for-each-fake-cursor
(save-excursion
- (let ((mc--executing-command-for-fake-cursor t)
- (id (overlay-get cursor 'mc-id))
- (annoying-arrows-mode nil)
- (smooth-scroll-margin 0))
- (mc/add-fake-cursor-to-undo-list
- (mc/pop-state-from-overlay cursor)
- (ignore-errors
- (mc/execute-command cmd)
- (mc/create-fake-cursor-at-point id))))))))
+ (mc/execute-command-for-fake-cursor cmd cursor)))))
(mc--reset-read-prompts))
;; Intercept some reading commands so you won't have to
@@ -561,6 +564,7 @@ for running commands with multiple cursors.")
mc/mark-all-symbols-like-this-in-defun
mc/mark-all-like-this-dwim
mc/mark-sgml-tag-pair
+ mc/insert-numbers
mc/cycle-forward
mc/cycle-backward
rrm/switch-to-multiple-cursors
diff --git a/multiple-cursors.el b/multiple-cursors.el
index 749b181..b618e3c 100644
--- a/multiple-cursors.el
+++ b/multiple-cursors.el
@@ -82,6 +82,7 @@
;; - `set-rectangular-region-anchor`: Think of this one as `set-mark` except
you're marking a rectangular region.
;; - `mc/mark-sgml-tag-pair`: Mark the current opening and closing tag.
+;; - `mc/insert-numbers`: Insert increasing numbers for each cursor, top to
bottom.
;; ## Tips and tricks
@@ -99,6 +100,10 @@
;; - Notice that the number of cursors active can be seen in the modeline.
+;; - If you get out of multiple-cursors-mode and yank - it will yank only
+;; from the kill-ring of main cursor. To yank from the kill-rings of
+;; every cursor use yank-rectangle, normally found at C-x r y.
+
;; - If you would like to keep the global bindings clean, and get custom
keybindings
;; when the region is active, you can try
[region-bindings-mode](https://github.com/fgallina/region-bindings-mode).
@@ -159,6 +164,7 @@
(require 'mc-cycle-cursors)
(require 'mc-mark-more)
(require 'rectangular-region-mode)
+(require 'mc-insert-numbers)
(provide 'multiple-cursors)
- [nongnu] elpa/multiple-cursors b912bf8 096/434: Always require multiple-cursors-core, (continued)
- [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, 2021/08/07
- [nongnu] elpa/multiple-cursors 9582c72 204/434: Add mc/insert-numbers,
ELPA Syncer <=
- [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
- [nongnu] elpa/multiple-cursors 6339657 192/434: Fix byte-compilation warnings, and avoid unnecessary use of "eval", ELPA Syncer, 2021/08/07