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

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

[nongnu] elpa/iedit f09b675c67 249/301: Add an option 'iedit-auto-narrow


From: ELPA Syncer
Subject: [nongnu] elpa/iedit f09b675c67 249/301: Add an option 'iedit-auto-narrow'
Date: Mon, 10 Jan 2022 22:59:07 -0500 (EST)

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

    Add an option 'iedit-auto-narrow'
    
    If no-nil, the buffer is narrowed temporairily if iedit-mode is enabled on
    current defun.
---
 iedit-tests.el |  7 +++++--
 iedit.el       | 45 +++++++++++++++++++++++++++++++++++----------
 2 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/iedit-tests.el b/iedit-tests.el
index cc65378710..6b90e20078 100644
--- a/iedit-tests.el
+++ b/iedit-tests.el
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2010, 2011, 2012 Victor Ren
 
-;; Time-stamp: <2018-09-19 11:11:07 Victor Ren>
+;; Time-stamp: <2018-11-14 17:48:26 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Version: 0.9.9.9
 ;; X-URL: https://www.emacswiki.org/emacs/Iedit
@@ -613,11 +613,14 @@ arfoo
       (emacs-lisp-mode)
       (goto-char 5)
       (iedit-mode)
+      (setq iedit-auto-narrow t)
       (iedit-restrict-function)
       (should (= 1 (length iedit-occurrences-overlays)))
+      (should (equal (buffer-narrowed-p) iedit-is-narrowed))
       (iedit-mode)
       (goto-char 13)
-      (iedit-mode-toggle-on-function)
+      (setq iedit-auto-narrow nil)
+      (call-interactively 'iedit-mode-toggle-on-function)
       (should (= 4 (length iedit-occurrences-overlays)))
       (iedit-mode)
       (iedit-mode)
diff --git a/iedit.el b/iedit.el
index 444c8f520a..8612abfcc4 100644
--- a/iedit.el
+++ b/iedit.el
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2010, 2011, 2012 Victor Ren
 
-;; Time-stamp: <2018-11-09 14:17:05 Victor Ren>
+;; Time-stamp: <2018-11-14 17:49:13 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Keywords: occurrence region simultaneous refactoring
 ;; Version: 0.9.9.9
@@ -111,6 +111,16 @@ isearch-mode-map, esc-map and help-map."
 
 (defvar iedit-mode nil) ;; Name of the minor mode
 
+(defcustom iedit-auto-narrow nil
+  "If no-nil, the buffer is narrowed temporairily if iedit-mode
+is enabled on current defun."
+  :type 'boolean
+  :group 'iedit)
+
+(defvar iedit-is-narrowed nil
+  "This is buffer local variable which indicates if the buffer is
+  narrowed by iedit temporarily.")
+
 (defvar iedit-use-symbol-boundaries t
   "If no-nil, matches have to start and end at symbol boundaries. Otherwise,
 matches starts and end at word boundaries.")
@@ -182,6 +192,7 @@ This should be set before Iedit is loaded."
 (make-variable-buffer-local 'iedit-initial-string-local)
 (make-variable-buffer-local 'iedit-initial-region)
 (make-variable-buffer-local 'iedit-default-occurrence-local)
+(make-variable-buffer-local 'iedit-is-narrowed)
 
 (or (assq 'iedit-mode minor-mode-alist)
     (nconc minor-mode-alist
@@ -393,7 +404,10 @@ Keymap used within overlays:
                 (deactivate-mark t)
                  (mark-defun)
                  (setq beg (region-beginning))
-                 (setq end (region-end))))
+                 (setq end (region-end)))
+              (when (and iedit-auto-narrow (not (buffer-narrowed-p)))
+                (narrow-to-region beg end)
+                (setq iedit-is-narrowed t)))
               ((and (= 1 (prefix-numeric-value arg))
                     (not (iedit-region-active)))
                (let ((region (bounds-of-thing-at-point 'symbol)))
@@ -562,6 +576,9 @@ the initial string globally."
 
   (iedit-cleanup)
 
+  (when iedit-is-narrowed
+    (widen)
+    (setq iedit-is-narrowed nil))
   (setq iedit-initial-string-local nil)
   (setq iedit-mode nil)
   (force-mode-line-update)
@@ -573,10 +590,12 @@ the initial string globally."
 
 (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)
-      (iedit-restrict-region (region-beginning) (region-end) arg)
-    (iedit-done)))
-
+  (cond ((iedit-region-active)
+        (iedit-restrict-region (region-beginning) (region-end) arg))
+       ((and arg
+             (= 0 (prefix-numeric-value arg)))
+        (iedit-restrict-function nil))
+       (t (iedit-done))))
 
 ;;;###autoload
 (defun iedit-mode-toggle-on-function ()
@@ -636,10 +655,16 @@ the initial string globally."
   (interactive "P")
   (let (beg end)
     (save-excursion
+      (deactivate-mark t)
       (mark-defun)
       (setq beg (region-beginning))
       (setq end (region-end)))
-    (iedit-restrict-region beg end arg))
+    (iedit-restrict-region beg end arg)
+    (when (and (not arg)
+              iedit-auto-narrow
+              (not (buffer-narrowed-p)))
+      (narrow-to-region beg end)
+      (setq iedit-is-narrowed t)))
   (message "Restricted in current function, %d matches."
            (length iedit-occurrences-overlays)))
 
@@ -729,9 +754,9 @@ prefix, bring the top of the region back down one 
occurrence."
       (goto-char pos)
       (force-mode-line-update))))
 
-(defun iedit-restrict-region (beg end &optional inclusive)
+(defun iedit-restrict-region (beg end &optional exclusive)
   "Restricting Iedit mode in a region."
-  (if (null (iedit-find-overlay beg end 'iedit-occurrence-overlay-name 
inclusive))
+  (if (null (iedit-find-overlay beg end 'iedit-occurrence-overlay-name 
exclusive))
       (iedit-done)
     (when iedit-buffering
       (iedit-stop-buffering))
@@ -739,7 +764,7 @@ prefix, bring the top of the region back down one 
occurrence."
     (setq mark-active nil)
     (run-hooks 'deactivate-mark-hook)
     (iedit-show-all)
-    (iedit-cleanup-occurrences-overlays beg end inclusive)
+    (iedit-cleanup-occurrences-overlays beg end exclusive)
     (if iedit-unmatched-lines-invisible
         (iedit-hide-unmatched-lines iedit-occurrence-context-lines))
     (force-mode-line-update)))



reply via email to

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