branch: elpa/iedit commit b13f05b9f11017ccf2c2529404163160a9004e00 Author: Victor Ren <victor...@gmail.com> Commit: Victor Ren <victor...@gmail.com>
New feature: switch from rectangle-mark-mode to iedit-rect mode The default key binding is changed to C-x r ; --- README.org | 11 ++++++----- iedit-rect.el | 54 ++++++++++++++++++++++++------------------------------ iedit-tests.el | 4 ++-- iedit.el | 13 +++++++------ 4 files changed, 39 insertions(+), 43 deletions(-) diff --git a/README.org b/README.org index 42ec044a7c..3bef865ea9 100644 --- a/README.org +++ b/README.org @@ -1,4 +1,4 @@ -* Iedit - Edit multiple regions in the same way simultaneously +* Iedit - Edit multiple occurrences in the same way simultaneously [[http://melpa.org/#/iedit][file:http://melpa.org/packages/iedit-badge.svg]] [[http://stable.melpa.org/#/iedit][file:http://stable.melpa.org/packages/iedit-badge.svg]] @@ -18,10 +18,11 @@ other occurrences changed in the same way, with visual feedback as you type. Normal work flow of Iedit mode is like: - - Move to certain point and press C-; (The default key binding) to enable - `iedit-mode'. All occurrences of a symbol, string or a region in the buffer - are highlighted corresponding to the thing under the point, current mark and - prefix argument. Refer to the document of `iedit-mode' for details. + - Move point to a target by `isearch' or other moving commands + + - Press C-;(The default key binding) to enable Iedit mode. The thing under + the point is recognized as an occurrence, and all the occurrences in the + buffer are highlighted - Edit one of the occurrences The change is applied to other occurrences simultaneously. diff --git a/iedit-rect.el b/iedit-rect.el index 689dfe0931..6bbb608ff5 100644 --- a/iedit-rect.el +++ b/iedit-rect.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2010 - 2019, 2020 Victor Ren -;; Time-stamp: <2021-01-06 11:17:35 Victor Ren> +;; Time-stamp: <2022-01-12 13:22:55 Victor Ren> ;; Author: Victor Ren <victor...@gmail.com> ;; Keywords: occurrence region simultaneous rectangle refactoring ;; Version: 0.9.9.9 @@ -55,14 +55,16 @@ ;;; Default key bindings: (when (null (where-is-internal 'iedit-rectangle-mode)) - (let ((key-def (lookup-key ctl-x-r-map "\r"))) + (let ((key-def (lookup-key ctl-x-r-map ";"))) (if key-def (display-warning 'iedit (format "Iedit rect default key %S is occupied by %s." (key-description [C-x r RET]) key-def) :warning) - (define-key ctl-x-r-map "\r" 'iedit-rectangle-mode) - (message "Iedit-rect default key binding is %s" (key-description [C-x r RET]))))) + (define-key ctl-x-r-map "\r" 'iedit-rectangle-mode) + (define-key ctl-x-r-map ";" 'iedit-rectangle-mode) + (define-key rectangle-mark-mode-map ";" 'iedit-rectangle-mode) + (message "Iedit-rect default key binding is %s" (key-description [C-x r \;]))))) (defvar iedit-rectangle nil "This buffer local variable which is the rectangle geometry if @@ -77,6 +79,7 @@ current mode is iedit-rect. Otherwise it is nil. (let ((map (make-sparse-keymap))) (set-keymap-parent map iedit-occurrence-keymap-default) (define-key map (kbd "M-K") 'iedit-kill-rectangle) + (define-key map (kbd "C-;") 'iedit-rectangle-mode) ; to exit iedit-rect mode map) "Keymap used within overlays in Iedit-rect mode.") @@ -102,7 +105,6 @@ Commands: (interactive (when (iedit-region-active) (list (region-beginning) (region-end)))) - ;; enforce skip modification once, errors may happen to cause this to be ;; unset. (setq iedit-skip-modification-once t) @@ -110,36 +112,30 @@ Commands: (iedit-rectangle-done) (iedit-barf-if-lib-active) (if (and beg end) - (progn (setq mark-active nil) - (run-hooks 'deactivate-mark-hook) - (iedit-rectangle-start beg end)) + (progn + (iedit-rectangle-start beg end)) (error "no region available.")))) +(defun iedit-rectangle-line (startcol endcol) + (push (iedit-make-occurrence-overlay + (progn + (move-to-column startcol t) + (point)) + (progn + (move-to-column endcol t) + (point))) + iedit-occurrences-overlays)) + (defun iedit-rectangle-start (beg end) "Start Iedit mode for the region as a rectangle." (barf-if-buffer-read-only) - (setq beg (copy-marker beg)) - (setq end (copy-marker end t)) + (setq iedit-rectangle (list (copy-marker beg) (copy-marker end t))) (setq iedit-occurrences-overlays nil) (setq iedit-occurrence-keymap iedit-rect-keymap) - (save-excursion - (let ((beg-col (progn (goto-char beg) (current-column))) - (end-col (progn (goto-char end) (current-column)))) - (when (< end-col beg-col) - (cl-rotatef beg-col end-col)) - (goto-char beg) - (while - (progn - (push (iedit-make-occurrence-overlay - (progn - (move-to-column beg-col t) - (point)) - (progn - (move-to-column end-col t) - (point))) - iedit-occurrences-overlays) - (and (< (point) end) (forward-line 1)))))) - (setq iedit-rectangle (list beg end)) + (goto-char + (apply-on-rectangle 'iedit-rectangle-line beg end)) + (setq mark-active nil) + (run-hooks 'deactivate-mark-hook) (setq iedit-rectangle-mode (propertize (concat " Iedit-rect:" @@ -153,8 +149,6 @@ Commands: "Exit Iedit mode. Save the current occurrence string locally and globally. Save the initial string globally." - (when iedit-buffering - (iedit-stop-buffering)) (iedit-lib-cleanup) (setq iedit-rectangle-mode nil) (force-mode-line-update)) diff --git a/iedit-tests.el b/iedit-tests.el index 51801e4bb3..b842cccacd 100644 --- a/iedit-tests.el +++ b/iedit-tests.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2010 - 2019, 2020 Victor Ren -;; Time-stamp: <2021-12-23 19:28:33 Victor Ren> +;; Time-stamp: <2022-01-12 11:48:28 Victor Ren> ;; Author: Victor Ren <victor...@gmail.com> ;; Version: 0.9.9.9 ;; X-URL: https://github.com/victorhge/iedit @@ -39,7 +39,7 @@ (with-temp-buffer (call-process-shell-command "emacs -L . -Q --batch -f batch-byte-compile *.el" nil (current-buffer)) (should (string= (buffer-string) "Iedit default key binding is C-; -Iedit-rect default key binding is <C-x> <r> <RET> +Iedit-rect default key binding is <C-x> <r> <;> ")) (delete-file (byte-compile-dest-file "iedit-lib.el") nil) (delete-file (byte-compile-dest-file "iedit-rect.el") nil) diff --git a/iedit.el b/iedit.el index 4846a60099..703cd64554 100755 --- a/iedit.el +++ b/iedit.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2010 - 2019, 2020, 2021 Victor Ren -;; Time-stamp: <2022-01-01 00:44:47 skangas> +;; Time-stamp: <2022-01-12 13:43:27 Victor Ren> ;; Author: Victor Ren <victor...@gmail.com> ;; Keywords: occurrence region simultaneous refactoring ;; Version: 0.9.9.9 @@ -41,10 +41,11 @@ ;; Normal work flow of Iedit mode is like: -;; - Move to certain point and press C-; (The default key binding). All -;; occurrences of a symbol, string or a region in the buffer are highlighted -;; corresponding to the thing under the point, current mark and prefix argument. -;; Refer to the document of `iedit-mode' for details. +;; - Move point to a target by `isearch' or other moving commands +;; +;; - Press C-;(The default key binding) to enable Iedit mode. The thing under +;; the point is recognized as an occurrence, and all the occurrences in the +;; buffer are highlighted ;; - Edit one of the occurrences ;; The change is applied to other occurrences simultaneously. @@ -52,7 +53,7 @@ ;; - Finish - by pressing C-; again ;; Many other work flows to highlight occurrences are possible, for example, -;; activation from isearch, incremental selection and markup tag pair selection. +;; rectangle selection, incremental selection and markup tag pair selection. ;; You can also use Iedit mode as a quick way to temporarily show only the ;; buffer lines that match the current text being edited. This gives you the