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

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

[nongnu] elpa/iedit d2684ee774 099/301: Remove duplicate definations


From: ELPA Syncer
Subject: [nongnu] elpa/iedit d2684ee774 099/301: Remove duplicate definations
Date: Mon, 10 Jan 2022 22:58:54 -0500 (EST)

branch: elpa/iedit
commit d2684ee7743b7a99eedbcada428dfe819d6f1190
Author: Victor Ren <victorhge@gmail.com>
Commit: Victor Ren <victorhge@gmail.com>

    Remove duplicate definations
---
 iedit-lib.el   |  72 +++--
 iedit-rect.el  |  30 +--
 iedit-tests.el |   0
 iedit.el       | 833 +++++++++++++++++++++++++++++----------------------------
 4 files changed, 477 insertions(+), 458 deletions(-)

diff --git a/iedit-lib.el b/iedit-lib.el
old mode 100755
new mode 100644
index 85f4ed5553..75934dafee
--- a/iedit-lib.el
+++ b/iedit-lib.el
@@ -1,9 +1,9 @@
-;;; iedit-lib.el --- library for editting multiple regions in the same way
+;;; iedit-lib.el --- APIs for editting multiple regions in the same way
 ;;; simultaneously.
 
 ;; Copyright (C) 2010, 2011, 2012 Victor Ren
 
-;; Time-stamp: <2012-08-02 22:51:38 Victor Ren>
+;; Time-stamp: <2012-08-06 10:04:46 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Keywords: occurrence region simultaneous rectangle refactoring
 ;; Version: 0.97
@@ -28,9 +28,11 @@
 
 ;;; Commentary:
 
-;; This package is APIs library that allow you to write your own code.
+;; This package is APIs library that allow you to write your own minor mode.
 
 ;;; todo:
+;; - Update comments for APIs
+;; - Fix the problem of tow conjected occurences
 ;; - Add more easy access keys for whole occurrence
 ;; - More APIs: extend occurrences, add-next, add previous, add region
 
@@ -65,12 +67,6 @@
   :type 'boolean
   :group 'iedit)
 
-(defvar iedit-last-initial-string-global nil
-  "This is a global variable which is the last initial occurrence string.")
-
-(defvar iedit-initial-string-local nil
-  "This is buffer local variable which is the initial string to start Iedit 
mode.")
-
 (defvar iedit-occurrences-overlays nil
   "The occurrences slot contains a list of overlays used to
 indicate the position of each occurrence.  In addition, the
@@ -89,14 +85,6 @@ If no-nil, matching is case sensitive.")
   "This is buffer local variable which indicates whether
 unmatched lines are hided.")
 
-(defvar iedit-last-occurrence-local nil
-  "This is buffer local variable which is the occurrence when
-Iedit mode is turned off last time.")
-
-(defvar iedit-last-occurrence-global nil
-  "This is global variable which is the occurrence when
-Iedit mode is turned off last time.")
-
 (defvar iedit-forward-success t
   "This is buffer local variable which indicates the moving
 forward or backward successful")
@@ -125,8 +113,8 @@ insertion against a zero-width occurrence.")
 buffering, which means the modification to the current occurrence
 is not applied to other occurrences when it is true.")
 
-(defvar iedit-occurrence-keymap 'iedit-occurrence-keymap-default
-  "The current keymap, `iedit-occurrence-keymap'")
+;; (defvar iedit-occurrence-keymap 'iedit-occurrence-keymap
+;;   "The current keymap, `iedit-occurrence-keymap'")
 
 (defvar iedit-occurrence-context-lines 1
   "The number of lines before or after the occurrence.")
@@ -134,14 +122,13 @@ is not applied to other occurrences when it is true.")
 (make-variable-buffer-local 'iedit-occurrences-overlays)
 (make-variable-buffer-local 'iedit-unmatched-lines-invisible)
 (make-variable-buffer-local 'iedit-case-sensitive-local)
-(make-variable-buffer-local 'iedit-last-occurrence-local)
 (make-variable-buffer-local 'iedit-forward-success)
 (make-variable-buffer-local 'iedit-before-modification-string)
 (make-variable-buffer-local 'iedit-before-modification-undo-list)
 (make-variable-buffer-local 'iedit-skipped-modification-once)
 (make-variable-buffer-local 'iedit-aborting)
 (make-variable-buffer-local 'iedit-buffering)
-(make-variable-buffer-local 'iedit-occurrence-keymap)
+;; (make-variable-buffer-local 'iedit-occurrence-keymap)
 (make-variable-buffer-local 'iedit-occurrence-context-lines)
 
 (defconst iedit-occurrence-overlay-name 'iedit-occurrence-overlay-name)
@@ -217,7 +204,7 @@ This is like `describe-bindings', but displays only Iedit 
keys."
     map)
   "Keymap used while Iedit mode is enabled.")
 
-(defvar iedit-occurrence-keymap-default
+(defvar iedit-occurrence-keymap
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map iedit-lib-keymap)
     (define-key map (kbd "M-U") 'iedit-upcase-occurrences)
@@ -234,9 +221,8 @@ This is like `describe-bindings', but displays only Iedit 
keys."
     map)
   "Keymap used within overlays in Iedit mode.")
 
-
 (defun iedit-help-for-occurrences ()
-  "Display `iedit-occurrence-keymap-default'"
+  "Display `iedit-occurrence-keymap'"
   (interactive)
   (message (concat (substitute-command-keys "\\[iedit-upcase-occurrences]") "/"
                    (substitute-command-keys "\\[iedit-downcase-occurrences]") 
":up/downcase "
@@ -251,7 +237,8 @@ This is like `describe-bindings', but displays only Iedit 
keys."
                    )))
 
 (defun iedit-make-occurrences-overlays (occurrence-exp beg end)
-  "Refresh Iedit mode."
+  "Create occurrence overlays for `occurrence-exp' in a region.
+Return the number of occurrences."
   (setq iedit-aborting nil)
   (setq iedit-occurrences-overlays nil)
   ;; Find and record each occurrence's markers and add the overlay to the 
occurrences
@@ -270,8 +257,29 @@ This is like `describe-bindings', but displays only Iedit 
keys."
             (iedit-hide-unmatched-lines iedit-occurrence-context-lines))))
     counter))
 
+(defun iedit-add-region-as-occurrence (beg end)
+  "Add region as an occurrence.
+The length of the region must the same as other occurrences if
+there are."
+  (or (= beg end)
+      (error "No region"))
+  (if (null iedit-occurrences-overlays)
+      (push
+       (iedit-make-occurrence-overlay beg end)
+       iedit-occurrences-overlays)
+    (or (= (- end beg) (iedit-occurrence-string-length))
+        (error "Wrong region."))
+    (if (or (iedit-find-overlay-at-point beg 'iedit-occurrence-overlay-name)
+            (iedit-find-overlay-at-point end 'iedit-occurrence-overlay-name))
+        (error "Conflict region."))
+    (push (iedit-make-occurrence-overlay beg end)
+          iedit-occurrences-overlays)
+    (sort iedit-occurrences-overlays
+          (lambda (left right)
+            (< (overlay-start left) (overlay-start right)))))) ;; todo test 
this function
+
 (defun iedit-clearup ()
-  "clear up"
+  "Clear up occurrence overlay, invisible overlay and local variables."
   ;; (when iedit-buffering
   ;;     (iedit-stop-buffering))
   ;; (setq iedit-last-occurrence-local (iedit-current-occurrence-string))
@@ -333,7 +341,7 @@ This modification hook is triggered when a user edits any
 occurrence and is responsible for updating all other occurrences.
 Current supported edits are insertion, yank, deletion and
 replacement.  If this modification is going out of the
-occurrence, it will exit Iedit mode."
+occurrence, it will abort Iedit mode."
   (when (and (not iedit-aborting )
              (not undo-in-progress)) ; undo will do all the update
     ;; before modification
@@ -506,7 +514,8 @@ value of `iedit-occurrence-context-lines' is used for this 
time."
   (remove-overlays nil nil iedit-invisible-overlay-name t))
 
 (defun iedit-hide-unmatched-lines (context-lines)
-  "Hide unmatched lines using invisible overlay."
+  "Hide unmatched lines using invisible overlay.
+This function depends on the order of iedit-occurrences-overlays. TODO"
   (let ((prev-occurrence-end 1)
         (unmatched-lines nil))
     (save-excursion
@@ -535,7 +544,7 @@ value of `iedit-occurrence-context-lines' is used for this 
time."
          (end (overlay-end ov)))
     (let ((inhibit-modification-hooks t))
       (save-excursion
-        (dolist (occurrence  iedit-occurrences-overlays)
+        (dolist (occurrence iedit-occurrences-overlays)
           (apply function (overlay-start occurrence) (overlay-end occurrence) 
args))))))
 
 (defun iedit-upcase-occurrences ()
@@ -726,6 +735,11 @@ Return nil if occurrence string is empty string."
         (buffer-substring-no-properties beg end)
       nil)))
 
+(defun iedit-occurrence-string-length ()
+  "Return the length of current occurrence string."
+  (let (ov (car iedit-occurrences-overlays))
+    (- (overlay-end ov) (overlay-start ov))))
+
 (defun iedit-find-overlay (beg end property &optional exclusive)
   "Return a overlay with property in region, or out of the region if EXCLUSIVE 
is not nil."
   (if exclusive
diff --git a/iedit-rect.el b/iedit-rect.el
old mode 100755
new mode 100644
index 5d7f462d8b..23de2a22f6
--- a/iedit-rect.el
+++ b/iedit-rect.el
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2010, 2011, 2012 Victor Ren
 
-;; Time-stamp: <2012-08-02 22:57:04 Victor Ren>
+;; Time-stamp: <2012-08-06 08:42:23 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Keywords: occurrence region simultaneous rectangle refactoring
 ;; Version: 0.97
@@ -69,7 +69,7 @@ current mode is iedit-rect. Otherwise it is nil.
 ;;; Define Iedit rect mode map
 (defvar iedit-rect-keymap
   (let ((map (make-sparse-keymap)))
-    (set-keymap-parent map iedit-occurrence-keymap-default)
+    (set-keymap-parent map iedit-occurrence-keymap)
     (define-key map (kbd "M-K") 'iedit-kill-rectangle)
     map)
   "Keymap used within overlays in iedit-RECT mode.")
@@ -96,26 +96,12 @@ current mode is iedit-rect. Otherwise it is nil.
           (set-mark nil)
           (iedit-rectangle-start beg end)))))
 
-(defun iedit-rectangle-done ()
-  "Exit Iedit mode.
-Save the current occurrence string locally and globally.  Save
-the initial string globally."
-  (when iedit-buffering
-      (iedit-stop-buffering))
-  (iedit-clearup)
-  (setq iedit-rectangle-mode nil)
-  (force-mode-line-update)
-  (remove-hook 'kbd-macro-termination-hook 'iedit-rectangle-done t)
-  (remove-hook 'change-major-mode-hook 'iedit-rectangle-done t)
-  (remove-hook 'iedit-aborting-hook 'iedit-rectangle-done t))
-
 (defun iedit-rectangle-start (beg end)
   "Start Iedit mode for the region as a rectangle."
   (barf-if-buffer-read-only)
   (setq iedit-occurrences-overlays nil)
   (setq iedit-rectangle (list beg end))
   (setq iedit-initial-string-local 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))))
@@ -142,6 +128,18 @@ the initial string globally."
   (add-hook 'change-major-mode-hook 'iedit-rectangle-done nil t)
   (add-hook 'iedit-aborting-hook 'iedit-rectangle-done nil t))
 
+(defun iedit-rectangle-done ()
+  "Exit Iedit mode.
+Save the current occurrence string locally and globally.  Save
+the initial string globally."
+  (when iedit-buffering
+      (iedit-stop-buffering))
+  (iedit-clearup)
+  (setq iedit-rectangle-mode nil)
+  (force-mode-line-update)
+  (remove-hook 'kbd-macro-termination-hook 'iedit-rectangle-done t)
+  (remove-hook 'change-major-mode-hook 'iedit-rectangle-done t)
+  (remove-hook 'iedit-aborting-hook 'iedit-rectangle-done t))
 
 (defun iedit-kill-rectangle(&optional fill)
   "Kill the rectangle.
diff --git a/iedit-tests.el b/iedit-tests.el
old mode 100755
new mode 100644
diff --git a/iedit.el b/iedit.el
old mode 100755
new mode 100644
index f178db55cd..f0a7533779
--- a/iedit.el
+++ b/iedit.el
@@ -1,413 +1,420 @@
-;;; iedit.el --- Edit multiple regions in the same way simultaneously.
-
-;; Copyright (C) 2010, 2011, 2012 Victor Ren
-
-;; Time-stamp: <2012-08-09 17:04:37 Victor Ren>
-;; Author: Victor Ren <victorhge@gmail.com>
-;; Keywords: occurrence region simultaneous rectangle refactoring
-;; Version: 0.97
-;; X-URL: http://www.emacswiki.org/emacs/Iedit
-;; Compatibility: GNU Emacs: 22.x, 23.x, 24.x
-
-;; This file is not part of GNU Emacs, but it is distributed under
-;; the same terms as GNU Emacs.
-
-;; GNU Emacs 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.
-
-;; GNU Emacs 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 GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; This package is an Emacs minor mode and allows you to edit one occurrence of
-;; some text in a buffer (possibly narrowed) or region, and simultaneously have
-;; other occurrences edited in the same way.
-;;
-;; Normal scenario of iedit-mode is like:
-;;
-;; - Highlight certain contents - by press C-;
-;;   All occurrences of a symbol, string or a rectangle in the buffer or a
-;;   region may be highlighted corresponding to current mark, point and prefix
-;;   argument.  Refer to the document of `iedit-mode' for details.
-;;
-;; - Edit one of the occurrences
-;;   The change is applied to other occurrences simultaneously.
-;;
-;; - Finish - by pressing C-; again
-;;
-;; This package also provides rectangle support with *visible rectangle*
-;; highlighting, which is similar with cua mode rectangle support, but still
-;; quite different.
-
-;; 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
-;; effect of a temporary `keep-lines' or `occur'.  To get this effect, hit C-'
-;; when in Iedit mode - it toggles hiding non-matching lines.
-;;
-;; Renaming refactoring is convenient in Iedit mode
-;;
-;; - The symbol under point is selected as occurrence by default and only
-;;   complete symbols are matched
-;; - With digit prefix argument 0, only symbols in current function are matched
-;; - Restricting symbols in current region can be done by pressing C-; again
-;; - Last renaming refactoring is remembered and can be applied to other 
buffers
-;;   later
-;;
-;; There are also some other facilities you may never think about.  Refer to 
the
-;; document of function `iedit-mode' (C-h f iedit-mode RET) for more details.
-
-;; The code was developed and fully tested on Gnu Emacs 24.0.93, partially
-;; tested on Gnu Emacs 22. If you have any compatible problem, please let me
-;; know.
-
-;;; todo:
-;; - Add more easy access keys for whole occurrence
-
-;;; Contributors
-;; Adam Lindberg <eproxus@gmail.com> added a case sensitivity option that can 
be toggled.
-
-;; Tassilo Horn <tassilo@member.fsf.org> added an option to match only complete
-;; words, not inside words
-
-;; Le Wang <l26wang@gmail.com> proposed to match only complete symbols,  not
-;; inside symbols, contributed rectangle support
-
-;;; Code:
-
-(eval-when-compile (require 'cl))
-(require 'rect) ;; kill rectangle
-(require 'iedit-lib)
-
-(defgroup iedit nil
-  "Edit multiple regions in the same way simultaneously."
-  :prefix "iedit-"
-  :group 'replace
-  :group 'convenience)
-
-(defcustom iedit-current-symbol-default t
-  "If no-nil, use current symbol by default for the occurrence."
-  :type 'boolean
-  :group 'iedit)
-
-(defcustom iedit-only-at-symbol-boundaries t
-  "If no-nil, matches have to start and end at symbol boundaries.
-For example, when invoking command `iedit-mode' on the \"in\" in the
-  sentence \"The king in the castle...\", the \"king\" is not
-  edited."
-  :type 'boolean
-  :group 'iedit)
-
-(defvar iedit-mode-hook nil
-  "Function(s) to call after starting up an iedit.")
-
-(defvar iedit-mode-end-hook nil
-  "Function(s) to call after terminating an iedit.")
-
-(defvar iedit-only-complete-symbol-local nil
-  "This is buffer local variable which indicates the occurrence
-only matches complete symbol.")
-
-(defvar iedit-only-complete-symbol-global nil
-  "This is global variable which indicates the last global occurrence
-only matches complete symbol.")
-
-
-(defvar iedit-mode-hook nil
-  "Function(s) to call after starting up an iedit.")
-
-(defvar iedit-mode-end-hook nil
-  "Function(s) to call after terminating an iedit.")
-
-(defvar iedit-mode nil) ;; Name of the minor mode
-
-(make-variable-buffer-local 'iedit-mode)
-(make-variable-buffer-local 'iedit-only-complete-symbol-local)
-
-(or (assq 'iedit-mode minor-mode-alist)
-    (nconc minor-mode-alist
-           (list '(iedit-mode iedit-mode))))
-
-(defun iedit-describe-mode ()
-  "Display documentation of Iedit mode."
-  (interactive)
-  (let (same-window-buffer-names same-window-regexps)
-    (describe-function 'iedit-mode)))
-
-;;; Default key bindings:
-(define-key global-map (kbd "C-;") 'iedit-mode)
-(define-key isearch-mode-map (kbd "C-;") 'iedit-mode)
-(define-key esc-map (kbd "C-;") 'iedit-execute-last-modification)
-(define-key help-map (kbd "C-;") 'iedit-mode-toggle-on-function)
-
-;; Avoid to restore Iedit mode when restoring desktop
-(add-to-list 'desktop-minor-mode-handlers
-             '(iedit-mode . nil))
-
-;;; Define iedit help map.
-(eval-when-compile (require 'help-macro))
-
-(defvar iedit-mode-keymap
-  (let ((map (make-sparse-keymap)))
-    (set-keymap-parent map iedit-occurrence-keymap-default)
-    (define-key map (kbd "M-H") 'iedit-restrict-function)
-    (define-key map (kbd "M-C") 'iedit-toggle-case-sensitive)
-    map)
-  "Keymap used within overlays in Iedit mode.")
-
-
-;;; Define Iedit mode map
-(or (assq 'iedit-mode minor-mode-map-alist)
-    (setq minor-mode-map-alist
-          (cons (cons 'iedit-mode iedit-mode-keymap) minor-mode-map-alist)))
-
-;; Avoid to restore Iedit mode when restoring desktop
-(add-to-list 'desktop-minor-mode-handlers
-             '(iedit-mode . nil))
-
-;;;###autoload
-(defun iedit-mode (&optional arg)
-  "Toggle Iedit mode.
-This command behaves differently, depending on the mark, point,
-prefix argument and variable `iedit-transient-mark-sensitive'.
-
-If Iedit mode is off, turn Iedit mode on.
-
-When Iedit mode is turned on, all the occurrences of the current
-region in the buffer (possibly narrowed) or a region are
-highlighted.  If one occurrence is modified, the change are
-propagated to all other occurrences simultaneously.
-
-If region is not active, the current symbol (returns from
-`current-word') is used as the occurrence by default.  The
-occurrences of the current symbol, but not include occurrences
-that are part of other symbols, are highlighted.  If you still
-want to match all the occurrences, even though they are parts of
-other symbols, you may have to mark the symbol first.
-
-In the above two situations, with digit prefix argument 0, only
-occurrences in current function are matched.  This is good for
-renaming refactoring in programming.
-
-You can also switch to Iedit mode from isearch mode directly. The
-current search string is used as occurrence.  All occurrences of
-the current search string are highlighted.
-
-With an universal prefix argument, the occurrence when Iedit mode
-is turned off last time in current buffer is used as occurrence.
-This is intended to recover last Iedit mode which is turned off.
-If region active, Iedit mode is limited within the current
-region.
-
-With repeated universal prefix argument, the occurrence when
-Iedit mode is turned off last time (might be in other buffer) is used
-as occurrence.  If region active, Iedit mode is limited within
-the current region.
-
-If Iedit mode is on and region is active, Iedit mode is
-restricted in the region, e.g. the occurrences outside of the region
-is excluded.
-
-If Iedit mode is on and region is active, with an universal
-prefix argument, Iedit mode is restricted outside of the region,
-e.g. the occurrences in the region is excluded.
-
-Turn off Iedit mode in other situations.
-
-Commands:
-\\{iedit-occurrence-keymap}"
-  (interactive "P")
-  (if iedit-mode
-      (progn
-        (iedit-mode-on-action arg)
-        (setq iedit-only-complete-symbol-global 
iedit-only-complete-symbol-local))
-    (iedit-barf-if-lib-active)
-    (let (occurrence
-          complete-symbol
-          (beg (if (eq major-mode 'occur-edit-mode) ; skip the first occurrence
-                   (next-single-char-property-change 1 'read-only)
-                 (point-min)))
-          (end (point-max)))
-      (cond ((and arg
-                  (= 4 (prefix-numeric-value arg))
-                  iedit-last-occurrence-local)
-             (setq occurrence iedit-last-occurrence-local)
-             (setq complete-symbol iedit-only-complete-symbol-local))
-            ((and arg
-                  (= 16 (prefix-numeric-value arg))
-                  iedit-last-initial-string-global)
-             (setq occurrence iedit-last-initial-string-global)
-             (setq complete-symbol iedit-only-complete-symbol-global))
-            ((iedit-region-active)
-             (setq occurrence  (buffer-substring-no-properties
-                                (mark) (point))))
-            ((and isearch-mode (not (string= isearch-string "")))
-             (setq occurrence  (buffer-substring-no-properties
-                                (point) isearch-other-end))
-             (isearch-exit))
-            ((and iedit-current-symbol-default (current-word t))
-             (setq occurrence  (current-word))
-             (when iedit-only-at-symbol-boundaries
-               (setq complete-symbol t)))
-            (t (error "No candidate of the occurrence, cannot enable Iedit 
mode")))
-      (when arg
-        (if (= 0 (prefix-numeric-value arg))
-            (save-excursion
-              (mark-defun)
-              (setq beg (region-beginning))
-              (setq end (region-end)))
-          (when (iedit-region-active)
-            (setq beg (region-beginning))
-            (setq end (region-end)))))
-      (setq iedit-only-complete-symbol-local complete-symbol)
-      (set-mark nil)
-      (setq iedit-case-sensitive-local iedit-case-sensitive-default)
-      (iedit-start occurrence beg end))))
-
-(defun iedit-start (occurrence-exp beg end)
-  "Start Iedit mode for the OCCURRENCE-EXP in the current buffer."
-  (setq iedit-unmatched-lines-invisible 
iedit-unmatched-lines-invisible-default)
-  (setq iedit-initial-string-local occurrence-exp)
-  (iedit-refresh occurrence-exp beg end)
-  (run-hooks 'iedit-mode-hook)
-  (add-hook 'kbd-macro-termination-hook 'iedit-done nil t)
-  (add-hook 'change-major-mode-hook 'iedit-done nil t)
-  (add-hook 'iedit-aborting-hook 'iedit-done nil t))
-
-(defun iedit-done ()
-  "Exit Iedit mode.
-Save the current occurrence string locally and globally.  Save
-the initial string globally."
-  (when iedit-buffering
-      (iedit-stop-buffering))
-  (setq iedit-last-occurrence-local (iedit-current-occurrence-string))
-  (setq iedit-last-occurrence-global iedit-last-occurrence-local)
-  (setq iedit-last-initial-string-global iedit-initial-string-local)
-  (setq iedit-case-sensitive-global iedit-case-sensitive-local)
-
-  (iedit-clearup)
-
-  (setq iedit-mode nil)
-  (force-mode-line-update)
-  (remove-hook 'kbd-macro-termination-hook 'iedit-done t)
-  (remove-hook 'change-major-mode-hook 'iedit-done t)
-  (remove-hook 'iedit-aborting-hook 'iedit-done t)
-  (run-hooks 'iedit-mode-end-hook))
-
-(defun iedit-refresh (occurrence-exp beg end)
-  "Refresh Iedit mode."
-  (setq occurrence-exp (regexp-quote occurrence-exp))
-  (when iedit-only-complete-symbol-local
-    (setq occurrence-exp (concat "\\_<" occurrence-exp "\\_>")))
-  (setq iedit-mode
-        (propertize
-         (concat " Iedit:"
-                 (number-to-string
-                  (iedit-make-occurrences-overlays occurrence-exp beg end)))
-         'face
-         'font-lock-warning-face))
-  (force-mode-line-update))
-
-(defun iedit-mode-on-action (&optional arg)
-  "Turn off Iedit mode or restrict it in a region if region is active."
-  (if (iedit-region-active)
-      ;; Restrict iedit-mode
-      (let ((beg (region-beginning))
-            (end (region-end)))
-        (if (null (iedit-find-overlay beg end 'iedit-occurrence-overlay-name 
arg))
-            (iedit-done)
-          (iedit-restrict-region beg end arg)
-          (iedit-first-occurrence)))
-    (iedit-done)))
-
-
-;;;###autoload
-(defun iedit-mode-toggle-on-function ()
-  "Toggle Iedit mode on current function."
-  (interactive)
-  (iedit-mode 0))
-
-(defun iedit-execute-last-modification (&optional arg)
-  "Apply last modification in Iedit mode to the current buffer or an active 
region."
-  (interactive "*P")
-  (or (and iedit-last-initial-string-global
-           (not (string= iedit-last-initial-string-global 
iedit-last-occurrence-global)))
-      (error "No modification available"))
-  (let ((occurrence-exp (regexp-quote iedit-last-initial-string-global))
-        (replacement  iedit-last-occurrence-global)
-        (case-fold-search (not iedit-case-sensitive-global))
-        beg end)
-    (when case-fold-search
-      (setq occurrence-exp (downcase occurrence-exp))
-      (setq replacement (downcase replacement)))
-    (if iedit-only-complete-symbol-global
-        (setq occurrence-exp (concat "\\_<"  occurrence-exp "\\_>")))
-    (when (iedit-region-active)
-      (setq beg (region-beginning))
-      (setq end (region-end)))
-    (perform-replace occurrence-exp replacement t t nil nil nil beg end)))
-
-(defun iedit-apply-global-modification ()
-  "Apply last global modification."
-  (interactive "*")
-  (if (and iedit-last-initial-string-global
-           (string= iedit-initial-string-local 
iedit-last-initial-string-global)
-           (not (string= iedit-last-initial-string-global 
iedit-last-occurrence-global)))
-      (iedit-replace-occurrences iedit-last-occurrence-global)
-    (message "No global modification available.")))
-
-
-(defun iedit-restrict-function(&optional arg)
-  "Restricting Iedit mode in current function."
-  (interactive "P")
-  (save-excursion
-    (mark-defun)
-    (iedit-restrict-region (region-beginning) (region-end) arg)))
-
-(defun iedit-restrict-region (beg end &optional inclusive)
-  "Restricting Iedit mode in a region."
-  (when iedit-buffering
-    (iedit-stop-buffering))
-  (setq iedit-last-occurrence-local (iedit-current-occurrence-string))
-  (set-mark nil)
-  (iedit-show-all)
-  (iedit-cleanup-occurrences-overlays beg end inclusive)
-  (if iedit-unmatched-lines-invisible
-      (iedit-hide-unmatched-lines iedit-occurrence-context-lines))
-  (setq iedit-mode (propertize
-                    (concat " Iedit:" (number-to-string
-                                       (length iedit-occurrences-overlays)))
-                    'face 'font-lock-warning-face))
-  (force-mode-line-update))
-
-(defun iedit-toggle-case-sensitive ()
-  "Toggle case-sensitive matching occurrences.
-Todo: how about region"
-  (interactive)
-  (setq iedit-case-sensitive-local (not iedit-case-sensitive-local))
-  (if iedit-buffering
-      (iedit-stop-buffering))
-  (setq iedit-last-occurrence-local (iedit-current-occurrence-string))
-  (when iedit-last-occurrence-local
-    (remove-overlays nil nil iedit-occurrence-overlay-name t)
-    (iedit-show-all)
-    (iedit-refresh iedit-last-occurrence-local (point-min) (point-max))))
-
-(provide 'iedit)
-
-;;; iedit.el ends here
-
-;;  LocalWords:  iedit el MERCHANTABILITY kbd isearch todo ert Lindberg Tassilo
-;;  LocalWords:  eval rect defgroup defcustom boolean defvar assq alist nconc
-;;  LocalWords:  substring cadr keymap defconst purecopy bkm defun princ prev
-;;  LocalWords:  iso lefttab backtab upcase downcase concat setq autoload arg
-;;  LocalWords:  refactoring propertize cond goto nreverse progn rotatef eq elp
-;;  LocalWords:  dolist pos unmatch args ov sReplace iedit's cdr quote'ed
->>>>>>> Split iedit into three files: iedit.el, iedit-lib.el, iedit-rect.el
+;;; iedit.el --- Edit multiple regions in the same way simultaneously.
+
+;; Copyright (C) 2010, 2011, 2012 Victor Ren
+
+;; Time-stamp: <2012-08-09 17:08:52 Victor Ren>
+;; Author: Victor Ren <victorhge@gmail.com>
+;; Keywords: occurrence region simultaneous rectangle refactoring
+;; Version: 0.97
+;; X-URL: http://www.emacswiki.org/emacs/Iedit
+;; Compatibility: GNU Emacs: 22.x, 23.x, 24.x
+
+;; This file is not part of GNU Emacs, but it is distributed under
+;; the same terms as GNU Emacs.
+
+;; GNU Emacs 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.
+
+;; GNU Emacs 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 GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This package is an Emacs minor mode and allows you to edit one occurrence of
+;; some text in a buffer (possibly narrowed) or region, and simultaneously have
+;; other occurrences edited in the same way.
+;;
+;; Normal scenario of iedit-mode is like:
+;;
+;; - Highlight certain contents - by press C-;
+;;   All occurrences of a symbol, string or a rectangle in the buffer or a
+;;   region may be highlighted corresponding to current mark, point and prefix
+;;   argument.  Refer to the document of `iedit-mode' for details.
+;;
+;; - Edit one of the occurrences
+;;   The change is applied to other occurrences simultaneously.
+;;
+;; - Finish - by pressing C-; again
+;;
+;; This package also provides rectangle support with *visible rectangle*
+;; highlighting, which is similar with cua mode rectangle support, but still
+;; quite different.
+
+;; 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
+;; effect of a temporary `keep-lines' or `occur'.  To get this effect, hit C-'
+;; when in Iedit mode - it toggles hiding non-matching lines.
+;;
+;; Renaming refactoring is convenient in Iedit mode
+;;
+;; - The symbol under point is selected as occurrence by default and only
+;;   complete symbols are matched
+;; - With digit prefix argument 0, only symbols in current function are matched
+;; - Restricting symbols in current region can be done by pressing C-; again
+;; - Last renaming refactoring is remembered and can be applied to other 
buffers
+;;   later
+;;
+;; There are also some other facilities you may never think about.  Refer to 
the
+;; document of function `iedit-mode' (C-h f iedit-mode RET) for more details.
+
+;; The code was developed and fully tested on Gnu Emacs 24.0.93, partially
+;; tested on Gnu Emacs 22. If you have any compatible problem, please let me
+;; know.
+
+;;; todo:
+;; - Add more easy access keys for whole occurrence
+
+;;; Contributors
+;; Adam Lindberg <eproxus@gmail.com> added a case sensitivity option that can 
be toggled.
+
+;; Tassilo Horn <tassilo@member.fsf.org> added an option to match only complete
+;; words, not inside words
+
+;; Le Wang <l26wang@gmail.com> proposed to match only complete symbols,  not
+;; inside symbols, contributed rectangle support
+
+;;; Code:
+
+(eval-when-compile (require 'cl))
+(require 'rect) ;; kill rectangle
+(require 'iedit-lib)
+
+(defgroup iedit nil
+  "Edit multiple regions in the same way simultaneously."
+  :prefix "iedit-"
+  :group 'replace
+  :group 'convenience)
+
+(defcustom iedit-current-symbol-default t
+  "If no-nil, use current symbol by default for the occurrence."
+  :type 'boolean
+  :group 'iedit)
+
+(defcustom iedit-only-at-symbol-boundaries t
+  "If no-nil, matches have to start and end at symbol boundaries.
+For example, when invoking command `iedit-mode' on the \"in\" in the
+  sentence \"The king in the castle...\", the \"king\" is not
+  edited."
+  :type 'boolean
+  :group 'iedit)
+
+(defvar iedit-mode-hook nil
+  "Function(s) to call after starting up an iedit.")
+
+(defvar iedit-mode-end-hook nil
+  "Function(s) to call after terminating an iedit.")
+
+(defvar iedit-mode nil) ;; Name of the minor mode
+
+(defvar iedit-only-complete-symbol-local nil
+  "This is buffer local variable which indicates the occurrence
+only matches complete symbol.")
+
+(defvar iedit-only-complete-symbol-global nil
+  "This is global variable which indicates the last global occurrence
+only matches complete symbol.")
+
+(defvar iedit-last-occurrence-local nil
+  "This is buffer local variable which is the occurrence when
+Iedit mode is turned off last time.")
+
+(defvar iedit-last-occurrence-global nil
+  "This is global variable which is the occurrence when
+Iedit mode is turned off last time.")
+
+(defvar iedit-last-initial-string-global nil
+  "This is a global variable which is the last initial occurrence string.")
+
+(defvar iedit-initial-string-local nil
+  "This is buffer local variable which is the initial string to start Iedit 
mode.")
+
+(make-variable-buffer-local 'iedit-mode)
+(make-variable-buffer-local 'iedit-only-complete-symbol-local)
+(make-variable-buffer-local 'iedit-last-occurrence-local)
+
+(or (assq 'iedit-mode minor-mode-alist)
+    (nconc minor-mode-alist
+           (list '(iedit-mode iedit-mode))))
+
+(defun iedit-describe-mode ()
+  "Display documentation of Iedit mode."
+  (interactive)
+  (let (same-window-buffer-names same-window-regexps)
+    (describe-function 'iedit-mode)))
+
+;;; Default key bindings:
+(define-key global-map (kbd "C-;") 'iedit-mode)
+(define-key isearch-mode-map (kbd "C-;") 'iedit-mode)
+(define-key esc-map (kbd "C-;") 'iedit-execute-last-modification)
+(define-key help-map (kbd "C-;") 'iedit-mode-toggle-on-function)
+
+;; Avoid to restore Iedit mode when restoring desktop
+(add-to-list 'desktop-minor-mode-handlers
+             '(iedit-mode . nil))
+
+;;; Define iedit help map.
+(eval-when-compile (require 'help-macro))
+
+(defvar iedit-mode-keymap
+  (let ((map (make-sparse-keymap)))
+    (set-keymap-parent map iedit-occurrence-keymap)
+    (define-key map (kbd "M-H") 'iedit-restrict-function)
+    (define-key map (kbd "M-C") 'iedit-toggle-case-sensitive)
+    map)
+  "Keymap used within overlays in Iedit mode.")
+
+
+;;; Define Iedit mode map
+(or (assq 'iedit-mode minor-mode-map-alist)
+    (setq minor-mode-map-alist
+          (cons (cons 'iedit-mode iedit-mode-keymap) minor-mode-map-alist)))
+
+;; Avoid to restore Iedit mode when restoring desktop
+(add-to-list 'desktop-minor-mode-handlers
+             '(iedit-mode . nil))
+
+;;;###autoload
+(defun iedit-mode (&optional arg)
+  "Toggle Iedit mode.
+This command behaves differently, depending on the mark, point,
+prefix argument and variable `iedit-transient-mark-sensitive'.
+
+If Iedit mode is off, turn Iedit mode on.
+
+When Iedit mode is turned on, all the occurrences of the current
+region in the buffer (possibly narrowed) or a region are
+highlighted.  If one occurrence is modified, the change are
+propagated to all other occurrences simultaneously.
+
+If region is not active, the current symbol (returns from
+`current-word') is used as the occurrence by default.  The
+occurrences of the current symbol, but not include occurrences
+that are part of other symbols, are highlighted.  If you still
+want to match all the occurrences, even though they are parts of
+other symbols, you may have to mark the symbol first.
+
+In the above two situations, with digit prefix argument 0, only
+occurrences in current function are matched.  This is good for
+renaming refactoring in programming.
+
+You can also switch to Iedit mode from isearch mode directly. The
+current search string is used as occurrence.  All occurrences of
+the current search string are highlighted.
+
+With an universal prefix argument, the occurrence when Iedit mode
+is turned off last time in current buffer is used as occurrence.
+This is intended to recover last Iedit mode which is turned off.
+If region active, Iedit mode is limited within the current
+region.
+
+With repeated universal prefix argument, the occurrence when
+Iedit mode is turned off last time (might be in other buffer) is used
+as occurrence.  If region active, Iedit mode is limited within
+the current region.
+
+If Iedit mode is on and region is active, Iedit mode is
+restricted in the region, e.g. the occurrences outside of the region
+is excluded.
+
+If Iedit mode is on and region is active, with an universal
+prefix argument, Iedit mode is restricted outside of the region,
+e.g. the occurrences in the region is excluded.
+
+Turn off Iedit mode in other situations.
+
+Commands:
+\\{iedit-occurrence-keymap}"
+  (interactive "P")
+  (if iedit-mode
+      (progn
+        (iedit-mode-on-action arg)
+        (setq iedit-only-complete-symbol-global 
iedit-only-complete-symbol-local))
+    (iedit-barf-if-lib-active)
+    (let (occurrence
+          complete-symbol
+          (beg (if (eq major-mode 'occur-edit-mode) ; skip the first occurrence
+                   (next-single-char-property-change 1 'read-only)
+                 (point-min)))
+          (end (point-max)))
+      (cond ((and arg
+                  (= 4 (prefix-numeric-value arg))
+                  iedit-last-occurrence-local)
+             (setq occurrence iedit-last-occurrence-local)
+             (setq complete-symbol iedit-only-complete-symbol-local))
+            ((and arg
+                  (= 16 (prefix-numeric-value arg))
+                  iedit-last-initial-string-global)
+             (setq occurrence iedit-last-initial-string-global)
+             (setq complete-symbol iedit-only-complete-symbol-global))
+            ((iedit-region-active)
+             (setq occurrence  (buffer-substring-no-properties
+                                (mark) (point))))
+            ((and isearch-mode (not (string= isearch-string "")))
+             (setq occurrence  (buffer-substring-no-properties
+                                (point) isearch-other-end))
+             (isearch-exit))
+            ((and iedit-current-symbol-default (current-word t))
+             (setq occurrence  (current-word))
+             (when iedit-only-at-symbol-boundaries
+               (setq complete-symbol t)))
+            (t (error "No candidate of the occurrence, cannot enable Iedit 
mode")))
+      (when arg
+        (if (= 0 (prefix-numeric-value arg))
+            (save-excursion
+              (mark-defun)
+              (setq beg (region-beginning))
+              (setq end (region-end)))
+          (when (iedit-region-active)
+            (setq beg (region-beginning))
+            (setq end (region-end)))))
+      (setq iedit-only-complete-symbol-local complete-symbol)
+      (set-mark nil)
+      (setq iedit-case-sensitive-local iedit-case-sensitive-default)
+      (iedit-start occurrence beg end))))
+
+(defun iedit-start (occurrence-exp beg end)
+  "Start Iedit mode for the OCCURRENCE-EXP in the current buffer."
+  (setq iedit-unmatched-lines-invisible 
iedit-unmatched-lines-invisible-default)
+  (setq iedit-initial-string-local occurrence-exp)
+  (iedit-refresh occurrence-exp beg end)
+  (run-hooks 'iedit-mode-hook)
+  (add-hook 'kbd-macro-termination-hook 'iedit-done nil t)
+  (add-hook 'change-major-mode-hook 'iedit-done nil t)
+  (add-hook 'iedit-aborting-hook 'iedit-done nil t))
+
+(defun iedit-refresh (occurrence-exp beg end)
+  "Refresh Iedit mode."
+  (setq occurrence-exp (regexp-quote occurrence-exp))
+  (when iedit-only-complete-symbol-local
+    (setq occurrence-exp (concat "\\_<" occurrence-exp "\\_>")))
+  (setq iedit-mode
+        (propertize
+         (concat " Iedit:"
+                 (number-to-string
+                  (iedit-make-occurrences-overlays occurrence-exp beg end)))
+         'face
+         'font-lock-warning-face))
+  (force-mode-line-update))
+
+(defun iedit-done ()
+  "Exit Iedit mode.
+Save the current occurrence string locally and globally.  Save
+the initial string globally."
+  (when iedit-buffering
+      (iedit-stop-buffering))
+  (setq iedit-last-occurrence-local (iedit-current-occurrence-string))
+  (setq iedit-last-occurrence-global iedit-last-occurrence-local)
+  (setq iedit-last-initial-string-global iedit-initial-string-local)
+  (setq iedit-case-sensitive-global iedit-case-sensitive-local)
+
+  (iedit-clearup)
+
+  (setq iedit-mode nil)
+  (force-mode-line-update)
+  (remove-hook 'kbd-macro-termination-hook 'iedit-done t)
+  (remove-hook 'change-major-mode-hook 'iedit-done t)
+  (remove-hook 'iedit-aborting-hook 'iedit-done t)
+  (run-hooks 'iedit-mode-end-hook))
+
+(defun iedit-mode-on-action (&optional arg)
+  "Turn off Iedit mode or restrict it in a region if region is active."
+  (if (iedit-region-active)
+      ;; Restrict iedit-mode
+      (let ((beg (region-beginning))
+            (end (region-end)))
+        (if (null (iedit-find-overlay beg end 'iedit-occurrence-overlay-name 
arg))
+            (iedit-done)
+          (iedit-restrict-region beg end arg)
+          (iedit-first-occurrence)))
+    (iedit-done)))
+
+
+;;;###autoload
+(defun iedit-mode-toggle-on-function ()
+  "Toggle Iedit mode on current function."
+  (interactive)
+  (iedit-mode 0))
+
+(defun iedit-execute-last-modification (&optional arg)
+  "Apply last modification in Iedit mode to the current buffer or an active 
region."
+  (interactive "*P")
+  (or (and iedit-last-initial-string-global
+           (not (string= iedit-last-initial-string-global 
iedit-last-occurrence-global)))
+      (error "No modification available"))
+  (let ((occurrence-exp (regexp-quote iedit-last-initial-string-global))
+        (replacement  iedit-last-occurrence-global)
+        (case-fold-search (not iedit-case-sensitive-global))
+        beg end)
+    (when case-fold-search
+      (setq occurrence-exp (downcase occurrence-exp))
+      (setq replacement (downcase replacement)))
+    (if iedit-only-complete-symbol-global
+        (setq occurrence-exp (concat "\\_<"  occurrence-exp "\\_>")))
+    (when (iedit-region-active)
+      (setq beg (region-beginning))
+      (setq end (region-end)))
+    (perform-replace occurrence-exp replacement t t nil nil nil beg end)))
+
+(defun iedit-apply-global-modification ()
+  "Apply last global modification."
+  (interactive "*")
+  (if (and iedit-last-initial-string-global
+           (string= iedit-initial-string-local 
iedit-last-initial-string-global)
+           (not (string= iedit-last-initial-string-global 
iedit-last-occurrence-global)))
+      (iedit-replace-occurrences iedit-last-occurrence-global)
+    (message "No global modification available.")))
+
+
+(defun iedit-restrict-function(&optional arg)
+  "Restricting Iedit mode in current function."
+  (interactive "P")
+  (save-excursion
+    (mark-defun)
+    (iedit-restrict-region (region-beginning) (region-end) arg)))
+
+(defun iedit-restrict-region (beg end &optional inclusive)
+  "Restricting Iedit mode in a region."
+  (when iedit-buffering
+    (iedit-stop-buffering))
+  (setq iedit-last-occurrence-local (iedit-current-occurrence-string))
+  (set-mark nil)
+  (iedit-show-all)
+  (iedit-cleanup-occurrences-overlays beg end inclusive)
+  (if iedit-unmatched-lines-invisible
+      (iedit-hide-unmatched-lines iedit-occurrence-context-lines))
+  (setq iedit-mode (propertize
+                    (concat " Iedit:" (number-to-string
+                                       (length iedit-occurrences-overlays)))
+                    'face 'font-lock-warning-face))
+  (force-mode-line-update))
+
+(defun iedit-toggle-case-sensitive ()
+  "Toggle case-sensitive matching occurrences.
+Todo: how about region"
+  (interactive)
+  (setq iedit-case-sensitive-local (not iedit-case-sensitive-local))
+  (if iedit-buffering
+      (iedit-stop-buffering))
+  (setq iedit-last-occurrence-local (iedit-current-occurrence-string))
+  (when iedit-last-occurrence-local
+    (remove-overlays nil nil iedit-occurrence-overlay-name t)
+    (iedit-show-all)
+    (iedit-refresh iedit-last-occurrence-local (point-min) (point-max))))
+
+(provide 'iedit)
+
+;;; iedit.el ends here
+
+;;  LocalWords:  iedit el MERCHANTABILITY kbd isearch todo ert Lindberg Tassilo
+;;  LocalWords:  eval rect defgroup defcustom boolean defvar assq alist nconc
+;;  LocalWords:  substring cadr keymap defconst purecopy bkm defun princ prev
+;;  LocalWords:  iso lefttab backtab upcase downcase concat setq autoload arg
+;;  LocalWords:  refactoring propertize cond goto nreverse progn rotatef eq elp
+;;  LocalWords:  dolist pos unmatch args ov sReplace iedit's cdr quote'ed



reply via email to

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