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

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

[nongnu] elpa/iedit 8149b66ce6 140/301: Read-only text handling


From: ELPA Syncer
Subject: [nongnu] elpa/iedit 8149b66ce6 140/301: Read-only text handling
Date: Mon, 10 Jan 2022 22:58:57 -0500 (EST)

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

    Read-only text handling
    Set read-only occurrence in different face
    
    Add read-only occurrence to a separate list
    Add test case for read-only  occurrence handling
---
 iedit-lib.el   | 47 ++++++++++++++++++++++++++-------
 iedit-tests.el | 82 +++++++++++++++++++++++++++++++++++++++++-----------------
 iedit.el       |  2 +-
 3 files changed, 96 insertions(+), 35 deletions(-)

diff --git a/iedit-lib.el b/iedit-lib.el
index e8d8c01fd7..4e525cd06a 100644
--- a/iedit-lib.el
+++ b/iedit-lib.el
@@ -3,7 +3,7 @@
 
 ;; Copyright (C) 2010, 2011, 2012 Victor Ren
 
-;; Time-stamp: <2012-12-07 23:16:43 Victor Ren>
+;; Time-stamp: <2012-12-08 23:35:32 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Keywords: occurrence region simultaneous rectangle refactoring
 ;; Version: 0.97
@@ -50,6 +50,11 @@
   "*Face used for the occurrences' default values."
   :group 'iedit)
 
+(defface iedit-read-only-occurrence
+  '((t :inherit region))
+  "*Face used for the read-only occurrences' default values."
+  :group 'iedit)
+
 (defcustom iedit-case-sensitive-default t
   "If no-nil, matching is case sensitive."
   :type 'boolean
@@ -70,10 +75,16 @@ mode, set it as nil."
 
 (defvar iedit-occurrences-overlays nil
   "The occurrences slot contains a list of overlays used to
-indicate the position of each occurrence.  In addition, the
+indicate the position of each editable occurrence.  In addition, the
+occurrence overlay is used to provide a different face
+configurable via `iedit-occurrence'.  The list is sorted by
+the position of overlays.")             ;todo remove sort
+
+(defvar iedit-read-only-occurrences-overlays nil
+  "The occurrences slot contains a list of overlays used to
+indicate the position of each read-only occurrence.  In addition, the
 occurrence overlay is used to provide a different face
-configurable via `iedit-occurrence-face'.  The list is sorted by
-the position of overlays.")
+configurable via `iedit-ready-only-occurrence'.")
 
 (defvar iedit-case-sensitive iedit-case-sensitive-default
   "This is buffer local variable.
@@ -120,6 +131,7 @@ is not applied to other occurrences when it is true.")
   "The number of lines before or after the occurrence.")
 
 (make-variable-buffer-local 'iedit-occurrences-overlays)
+(make-variable-buffer-local 'iedit-read-only-occurrences-overlays)
 (make-variable-buffer-local 'iedit-unmatched-lines-invisible)
 (make-local-variable 'iedit-case-sensitive)
 (make-variable-buffer-local 'iedit-forward-success)
@@ -188,17 +200,23 @@ It should be set before occurrence overlay is created.")
 Return the number of occurrences."
   (setq iedit-aborting nil)
   (setq iedit-occurrences-overlays nil)
+  (setq iedit-read-only-occurrences-overlays nil)
   ;; Find and record each occurrence's markers and add the overlay to the 
occurrences
   (let ((counter 0)
         (case-fold-search (not iedit-case-sensitive)))
     (save-excursion
       (goto-char beg)
       (while (re-search-forward occurrence-regexp end t)
-        (push (iedit-make-occurrence-overlay (match-beginning 0) (match-end 0))
-              iedit-occurrences-overlays)
-        (setq counter (1+ counter)))
+        (let ((beginning (match-beginning 0))
+              (ending (match-end 0)))
+          (if (text-property-not-all beginning ending 'read-only nil)
+              (push (iedit-make-read-only-occurrence-overlay beginning ending)
+                    iedit-read-only-occurrences-overlays)
+            (push (iedit-make-occurrence-overlay beginning ending)
+                  iedit-occurrences-overlays))
+          (setq counter (1+ counter))))
       (message "%d matches for \"%s\"" counter (iedit-printable 
occurrence-regexp))
-      (when (/= 0 counter)
+      (when (/= 0 counter)              ;todo: remove nreverse
         (setq iedit-occurrences-overlays (nreverse iedit-occurrences-overlays))
         (if iedit-unmatched-lines-invisible
             (iedit-hide-unmatched-lines iedit-occurrence-context-lines))))
@@ -262,6 +280,7 @@ there are."
   (remove-overlays nil nil iedit-occurrence-overlay-name t)
   (iedit-show-all)
   (setq iedit-occurrences-overlays nil)
+  (setq iedit-read-only-occurrences-overlays nil)
   (setq iedit-aborting nil)
   (setq iedit-before-modification-string "")
   (setq iedit-before-modification-undo-list nil))
@@ -280,6 +299,13 @@ occurrences if the user starts typing."
     (overlay-put occurrence 'modification-hooks '(iedit-occurrence-update))
     occurrence))
 
+(defun iedit-make-read-only-occurrence-overlay (begin end)
+  "Create an overlay for an read-only occurrence in Iedit mode."
+  (let ((occurrence (make-overlay begin end (current-buffer) nil t)))
+    (overlay-put occurrence iedit-occurrence-overlay-name t)
+    (overlay-put occurrence 'face 'iedit-read-only-occurrence)
+    occurrence))
+
 (defun iedit-make-unmatched-lines-overlay (begin end)
   "Create an overlay for lines between two occurrences in Iedit mode."
   (let ((unmatched-lines-overlay (make-overlay begin end (current-buffer) nil 
t)))
@@ -814,8 +840,9 @@ it just means mark is active."
        mark-active (not (equal (mark) (point)))))
 
 (defun iedit-barf-if-lib-active()
-  "Signal error if `iedit-occurrences-overlays' is not nil."
-  (or (null iedit-occurrences-overlays )
+  "Signal error if Iedit lib is active."
+  (or (and (null iedit-occurrences-overlays)
+           (null iedit-read-only-occurrences-overlays))
       (error "Iedit lib is active.")))
 
 (provide 'iedit-lib)
diff --git a/iedit-tests.el b/iedit-tests.el
index 916457d156..9a68798550 100644
--- a/iedit-tests.el
+++ b/iedit-tests.el
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2010, 2011, 2012 Victor Ren
 
-;; Time-stamp: <2012-10-22 14:01:57 Victor Ren>
+;; Time-stamp: <2012-12-08 23:40:48 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Version: 0.97
 ;; X-URL: http://www.emacswiki.org/emacs/Iedit
@@ -285,6 +285,32 @@ fob")))))
    barfoo
    1")))))
 
+(ert-deftest iedit-occurrence-update-with-read-only-test ()
+  (with-iedit-test-fixture
+"foo
+  foo
+   barfoo
+   foo"
+   (lambda ()
+     (iedit-mode)
+     (put-text-property 1 2 'read-only t)
+     (iedit-mode)
+     (goto-char 2)
+     (should-error (insert "1"))
+     (should (string= (buffer-string)
+"foo
+  foo
+   barfoo
+   foo"))
+     (goto-char 7)
+     (insert "1")
+     (should (string= (buffer-string)
+"foo
+  1foo
+   barfoo
+   1foo"))
+     )))
+
 (ert-deftest iedit-aborting-test ()
   (with-iedit-test-fixture
 "foo
@@ -420,12 +446,12 @@ fob")))))
   barfoo
     foo"
    (lambda ()
-   (iedit-mode)
-   (set-mark-command nil)
-   (forward-char 3)
-   (forward-line 3)
-   (iedit-rectangle-mode)
-   (should (equal iedit-rectangle '(1 19))))))
+     (iedit-mode)
+     (set-mark-command nil)
+     (forward-char 3)
+     (forward-line 3)
+     (iedit-rectangle-mode)
+     (should (equal iedit-rectangle '(1 19))))))
 
 (ert-deftest iedit-kill-rectangle-error-test ()
   (with-iedit-test-fixture
@@ -434,16 +460,16 @@ fob")))))
   barfoo
     foo"
    (lambda ()
-   (iedit-mode)
-   (set-mark-command nil)
-   (goto-char 22)
-   (iedit-rectangle-mode)
-   (should (iedit-same-column))
-   (should (equal iedit-rectangle '(1 22)))
-   (iedit-prev-occurrence)
-   (delete-char -1)
-   (should (not (iedit-same-column)))
-   (should-error (iedit-kill-rectangle)))))
+     (iedit-mode)
+     (set-mark-command nil)
+     (goto-char 22)
+     (iedit-rectangle-mode)
+     (should (iedit-same-column))
+     (should (equal iedit-rectangle '(1 22)))
+     (iedit-prev-occurrence)
+     (delete-char -1)
+     (should (not (iedit-same-column)))
+     (should-error (iedit-kill-rectangle)))))
 
 (ert-deftest iedit-kill-rectangle-test ()
   (with-iedit-test-fixture
@@ -531,14 +557,22 @@ abcd" 
"12345678901234567890123456789012345678901234567890...")))
     (should (string= (iedit-printable (car test)) (cadr test)))))
 
 
-;; (elp-instrument-list '(insert-and-inherit
-;;                        delete-region
-;;                        goto-char
-;;                        iedit-occurrence-update
-;;                        buffer-substring-no-properties
-;;                        string=
+;; (elp-instrument-list '(;; insert-and-inherit
+;;                        ;; delete-region
+;;                        ;; goto-char
+;;                        ;; iedit-occurrence-update
+;;                        ;; buffer-substring-no-properties
+;;                        ;; string=
 ;;                        re-search-forward
-;;                        replace-match))
+;;                        ;; replace-match
+;;                        text-property-not-all
+;;                        iedit-make-occurrence-overlay
+;;                        nreverse
+;;                        iedit-make-occurrences-overlays
+;;                        match-beginning
+;;                        match-end
+;;                        push
+;;                        ))
 
 
 ;;; iedit-tests.el ends here
diff --git a/iedit.el b/iedit.el
index e114d78771..d17fa4a55d 100644
--- a/iedit.el
+++ b/iedit.el
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2010, 2011, 2012 Victor Ren
 
-;; Time-stamp: <2012-12-08 14:17:05 Victor Ren>
+;; Time-stamp: <2012-12-08 23:57:42 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Keywords: occurrence region simultaneous refactoring
 ;; Version: 0.97



reply via email to

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