[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/iedit e575cbf569 256/301: Allow adding a incremented numbe
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/iedit e575cbf569 256/301: Allow adding a incremented number in each occurence |
Date: |
Mon, 10 Jan 2022 22:59:08 -0500 (EST) |
branch: elpa/iedit
commit e575cbf5695ecea6df75a1d9f65fe3a588485c88
Author: Thierry Volpiatto <thierry.volpiatto@gmail.com>
Commit: Victor <victorhge@gmail.com>
Allow adding a incremented number in each occurence
At any place.
Added a new user variable that allow configuring the default format string
used by `iedit-increment-occurences`.
Additionally allow editing the format string when calling
`iedit-increment-occurences` with a prefix arg.
---
iedit-lib.el | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/iedit-lib.el b/iedit-lib.el
index f448ebd47e..236a3f5a29 100644
--- a/iedit-lib.el
+++ b/iedit-lib.el
@@ -99,6 +99,12 @@ the traverse of the long `iedit-occurrences-overlays' list."
:type 'integer
:group 'iedit)
+(defcustom iedit-increment-format-string "%03d"
+ "Format string used to format incremented numbers.
+This is used by `iedit-increment-occurences'."
+ :type 'string
+ :group 'iedit)
+
(defvar iedit-occurrences-overlays nil
"The occurrences slot contains a list of overlays used to
indicate the position of each editable occurrence. In addition, the
@@ -214,6 +220,7 @@ occurrence.")
(define-key map (kbd "M-SPC") 'iedit-blank-occurrences)
(define-key map (kbd "M-D") 'iedit-delete-occurrences)
(define-key map (kbd "M-N") 'iedit-number-occurrences)
+ (define-key map (kbd "M-V") 'iedit-increment-occurences)
(define-key map (kbd "M-B") 'iedit-toggle-buffering)
(define-key map (kbd "M-<") 'iedit-goto-first-occurrence)
(define-key map (kbd "M->") 'iedit-goto-last-occurrence)
@@ -689,14 +696,35 @@ value of `iedit-occurrence-context-lines' is used for
this time."
(iedit-barf-if-buffering)
(iedit-apply-on-occurrences 'upcase-region))
-
-
(defun iedit-downcase-occurrences()
"Covert occurrences to lower case."
(interactive "*")
(iedit-barf-if-buffering)
(iedit-apply-on-occurrences 'downcase-region))
+(defun iedit-increment-occurences (&optional arg)
+ "Replace placeholder \"\\#\" by incremented number in each occurrence.
+Called with a prefix arg, allow editing the format string used, which
+default to `iedit-increment-format-string'."
+ (interactive "*P")
+ (iedit-barf-if-buffering)
+ (let ((inhibit-modification-hooks t)
+ (fmt-str (if arg
+ (read-string
+ (format "Format incremented numbers (default '%s'): "
+ iedit-increment-format-string)
+ nil nil iedit-increment-format-string)
+ iedit-increment-format-string)))
+ (save-excursion
+ (cl-loop for occurrence in (reverse iedit-occurrences-overlays)
+ for counter from 1
+ for beg = (overlay-start occurrence)
+ for end = (overlay-end occurrence)
+ do (progn
+ (goto-char beg)
+ (when (re-search-forward "\\\\#" end t)
+ (replace-match (format fmt-str counter) t)))))))
+
;;; Don't downcase from-string to allow case freedom!
(defun iedit-replace-occurrences(&optional to-string)
"Replace occurrences with STRING."
- [nongnu] elpa/iedit 6e6d4bc478 151/301: Merge branch 'master' of https://github.com/mbneedham/iedit, (continued)
- [nongnu] elpa/iedit 6e6d4bc478 151/301: Merge branch 'master' of https://github.com/mbneedham/iedit, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 06bdb68bbf 203/301: Add iedit-switch-to-mc-mode, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit b2bffd978c 184/301: Merge pull request #54 from Vifon/iedit-replace-occurences_default-case, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit d2f08e8862 163/301: Provide functions to narrow around current-line, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 27dbbdda0b 162/301: Split iedit-occurrence-update into two functions, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 9a40f6fa36 205/301: check if mc present, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 97ad9d0600 254/301: removed downcasing the from-string in iedit-lib.el/iedit-replace-occurrences to allow case sensitivity., ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 7a3725cd04 267/301: Small optimizations, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 42654ba7ed 266/301: iedit-rect.el: Don't set iedit-initial-string-local, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit d335d6842a 183/301: Check if the default keybinding of iedit-mode is taken, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit e575cbf569 256/301: Allow adding a incremented number in each occurence,
ELPA Syncer <=
- [nongnu] elpa/iedit 796ee5298d 237/301: fix the key conflict with yas-minor-mode, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit e1decb37e5 245/301: Fix verion numbers, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit f09b675c67 249/301: Add an option 'iedit-auto-narrow', ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 44601e01fa 269/301: fix an issue with electric pair, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 3f9eed229e 232/301: Allow custom mode-line, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 9c08a48c88 281/301: Remove the workaround for slow c-before-change, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 01767ddca3 258/301: Fix a failed testcase in batch mode, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 7e507b370b 255/301: Set the FIXEDCASE argument of replace-match in iedit-replace-occurrences to T to allow preserving case., ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 745ea6f812 239/301: Rename iedit-toggle-unmatched-lines-visible to iedit-show/hide-unmatched-lines, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit dfed75064e 285/301: Save and restore `line-move-ignore-invisible', ELPA Syncer, 2022/01/10