[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/iedit 02b4a6553e 243/301: Add the index of the current occ
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/iedit 02b4a6553e 243/301: Add the index of the current occurrence on mode-line |
Date: |
Mon, 10 Jan 2022 22:59:07 -0500 (EST) |
branch: elpa/iedit
commit 02b4a6553e3056c1d96e81d95c7ad98a48991f3d
Author: Victor Ren <victorhge@gmail.com>
Commit: Victor <victorhge@gmail.com>
Add the index of the current occurrence on mode-line
A buffer local variable `iedit-occurrence-index' is added to trace the
index.
It is initialized when iedit-mode is activated and updated when navitation
functions are called.
Test cases are also updated.
A few comile warnings are fixed.
---
iedit-lib.el | 39 ++++++++++++++++++++++++++++++++++++---
iedit-tests.el | 11 ++++++++++-
iedit.el | 14 ++++++++------
3 files changed, 54 insertions(+), 10 deletions(-)
diff --git a/iedit-lib.el b/iedit-lib.el
index cffe14e5d5..a5d3386017 100644
--- a/iedit-lib.el
+++ b/iedit-lib.el
@@ -3,12 +3,12 @@
;; Copyright (C) 2010, 2011, 2012 Victor Ren
-;; Time-stamp: <2018-02-06 14:08:13 Victor Ren>
+;; Time-stamp: <2018-02-07 18:11:06 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Keywords: occurrence region simultaneous rectangle refactoring
;; Version: 0.9.9
;; X-URL: http://www.emacswiki.org/emacs/Iedit
-;; Compatibility: GNU Emacs: 22.x, 23.x, 24.x
+;; Compatibility: GNU Emacs: 22.x, 23.x, 24.x, 25.x
;; This file is not part of GNU Emacs, but it is distributed under
;; the same terms as GNU Emacs.
@@ -85,6 +85,13 @@ mode, set it as nil."
:type 'integer
:group 'iedit)
+(defcustom iedit-index-update-limit 200
+ "If the number of occurrence is great than this, the
+`iedit-occurrence-index' will not be updated to avoid the
+traverse of the long `iedit-occurrences-overlays' list."
+ :type 'integer
+ :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
@@ -141,6 +148,11 @@ is not applied to other occurrences when it is true.")
(defvar iedit-occurrence-context-lines 1
"The number of lines before or after the occurrence.")
+(defvar iedit-occurrence-index 0
+ "The index of the current occurrence, counted from the beginning of the
buffer.
+Used in mode-line to indicate the position of the current
+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)
@@ -153,6 +165,7 @@ is not applied to other occurrences when it is true.")
(make-variable-buffer-local 'iedit-buffering)
(make-variable-buffer-local 'iedit-post-undo-hook-installed)
(make-variable-buffer-local 'iedit-occurrence-context-lines)
+(make-variable-buffer-local 'iedit-occurrence-index)
(defconst iedit-occurrence-overlay-name 'iedit-occurrence-overlay-name)
(defconst iedit-invisible-overlay-name 'iedit-invisible-overlay-name)
@@ -277,8 +290,21 @@ Return the number of occurrences."
(push (iedit-make-occurrence-overlay beginning ending)
iedit-occurrences-overlays))
(setq counter (1+ counter))))))
+ (iedit-update-index)
counter))
+(defun iedit-update-index (&optional point)
+ "Update `iedit-occurrence-index' with the current occurrence,
+if the total number of occurrences is less than
+`iedit-index-update-limit'."
+ (if (< (length iedit-occurrences-overlays) iedit-index-update-limit)
+ (let ((pos (or point (point)))
+ (index 0))
+ (dolist (occurrence iedit-occurrences-overlays)
+ (if (>= pos (overlay-start occurrence))
+ (setq index (1+ index))))
+ (setq iedit-occurrence-index index))))
+
(defun iedit-add-next-occurrence-overlay (occurrence-exp &optional point)
"Create next occurrence overlay for `occurrence-exp'."
(iedit-add-occurrence-overlay occurrence-exp point t))
@@ -307,6 +333,7 @@ Return the start position of the new occurrence if
successful."
(push (iedit-make-occurrence-overlay (match-beginning 0)
(match-end 0))
iedit-occurrences-overlays)
+ (iedit-update-index point)
(message "Add one match for \"%s\"." (iedit-printable occurrence-exp))
(when iedit-unmatched-lines-invisible
(iedit-show-all)
@@ -331,6 +358,7 @@ there are."
(error "Conflict region"))
(push (iedit-make-occurrence-overlay beg end)
iedit-occurrences-overlays)
+ (iedit-update-index)
)) ;; todo test this function
(defun iedit-cleanup ()
@@ -501,6 +529,7 @@ beginning of the buffer."
(setq iedit-forward-success t)
(message "Located the first occurrence."))))
(when iedit-forward-success
+ (iedit-update-index pos)
(goto-char pos))))
(defun iedit-prev-occurrence ()
@@ -530,6 +559,7 @@ the buffer."
(message "Located the last occurrence.")))
(setq iedit-forward-success t))
(when iedit-forward-success
+ (iedit-update-index pos)
(goto-char pos))))
(defun iedit-goto-first-occurrence ()
@@ -537,6 +567,7 @@ the buffer."
(interactive)
(goto-char (iedit-first-occurrence))
(setq iedit-forward-success t)
+ (setq iedit-occurrence-index 1)
(message "Located the first occurrence."))
(defun iedit-first-occurrence ()
@@ -551,6 +582,7 @@ the buffer."
(interactive)
(goto-char (iedit-last-occurrence))
(setq iedit-forward-success t)
+ (setq iedit-occurrence-index (length iedit-occurrences-overlays))
(message "Located the last occurrence."))
(defun iedit-last-occurrence ()
@@ -902,7 +934,8 @@ Return nil if occurrence string is empty string."
(dolist (overlay iedit-occurrences-overlays)
(if (overlay-buffer overlay)
(push overlay overlays)))
- (setq iedit-occurrences-overlays overlays)))
+ (setq iedit-occurrences-overlays overlays)
+ (iedit-update-index)))
(defun iedit-printable (string)
"Return a omitted substring that is not longer than 50.
diff --git a/iedit-tests.el b/iedit-tests.el
index a83f438949..b60cfa12ce 100644
--- a/iedit-tests.el
+++ b/iedit-tests.el
@@ -2,7 +2,7 @@
;; Copyright (C) 2010, 2011, 2012 Victor Ren
-;; Time-stamp: <2017-09-14 23:49:18 Victor Ren>
+;; Time-stamp: <2018-02-07 18:08:22 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Version: 0.97
;; X-URL: http://www.emacswiki.org/emacs/Iedit
@@ -275,23 +275,32 @@ fob")))))
(lambda ()
(iedit-goto-last-occurrence)
(should (= (point) 24))
+ (should (= iedit-occurrence-index 3))
(iedit-goto-first-occurrence)
(should (= (point) 1))
+ (should (= iedit-occurrence-index 1))
(iedit-next-occurrence)
(should (= (point) 7))
+ (should (= iedit-occurrence-index 2))
(iedit-next-occurrence)
(should (= (point) 24))
+ (should (= iedit-occurrence-index 3))
(iedit-next-occurrence)
(should (= (point) 24)) ;; (should (string= (current-message) "This is
the last occurrence."))
+ (should (= iedit-occurrence-index 3))
(iedit-next-occurrence)
(should (= (point) 1)) ;; (should (string= (current-message) "Located the
first occurrence."))
+ (should (= iedit-occurrence-index 1))
(iedit-next-occurrence)
(should (= (point) 7))
+ (should (= iedit-occurrence-index 2))
(goto-char (point-max))
(iedit-prev-occurrence)
(should (= (point) 27))
+ (should (= iedit-occurrence-index 3))
(iedit-prev-occurrence)
(should (= (point) 24))
+ (should (= iedit-occurrence-index 3))
(iedit-prev-occurrence)
(should (= (point) 7))
(iedit-prev-occurrence)
diff --git a/iedit.el b/iedit.el
index 7dd6415066..16d768536c 100644
--- a/iedit.el
+++ b/iedit.el
@@ -2,7 +2,7 @@
;; Copyright (C) 2010, 2011, 2012 Victor Ren
-;; Time-stamp: <2017-09-16 21:05:28 Victor Ren>
+;; Time-stamp: <2018-02-07 18:08:39 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Keywords: occurrence region simultaneous refactoring
;; Version: 0.9.9.9
@@ -167,8 +167,8 @@ use this variable:
'$%@*' will be included in the occurrences in perl mode.")
(defcustom iedit-mode-line
- `(" Iedit:" (:eval (format ,(propertize "%d" 'face 'font-lock-warning-face)
- (iedit-counter))))
+ `(" Iedit:" (:eval (format ,(propertize "%d/%d" 'face
'font-lock-warning-face)
+ iedit-occurrence-index (iedit-counter))))
"Mode-line format for Iedit.
This should be set before Iedit is loaded."
:group 'iedit)
@@ -406,11 +406,13 @@ Keymap used within overlays:
;; (message "No matches found for %s" (iedit-regexp-quote occurrence))
(iedit-done)))))
+(unless (boundp 'isearch-regexp-function)
+ (defvaralias 'isearch-regexp-function 'isearch-word))
(defun iedit-mode-from-isearch (regexp)
"Start Iedit mode using last search string as the regexp."
(interactive
(let ((regexp (cond
- ((functionp isearch-regexp-function)
+ ((functionp isearch-regexp-function)
(funcall isearch-regexp-function isearch-string))
(isearch-regexp-function (word-search-regexp isearch-string))
(isearch-regexp isearch-string)
@@ -519,10 +521,10 @@ Return the tag if succeeded, nil if failed."
(cl-end (progn (skip-chars-forward "[:alnum:]-_.:") (point)))
(match
(if endp
- (when (sgml-skip-tag-backward 1) (forward-char 1) t)
+ (with-no-warnings (when (sgml-skip-tag-backward 1)
(forward-char 1) t))
(with-syntax-table sgml-tag-syntax-table
(up-list -1)
- (when (sgml-skip-tag-forward 1)
+ (with-no-warnings (when (sgml-skip-tag-forward 1))
(backward-sexp 1)
(forward-char 2)
t)))))
- [nongnu] elpa/iedit abb577e447 236/301: Merge pull request #77 from EdwardBetts/spelling, (continued)
- [nongnu] elpa/iedit abb577e447 236/301: Merge pull request #77 from EdwardBetts/spelling, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 39919478f9 230/301: fix C-R-RET key binding problem in term, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 77e1661134 246/301: Readme.org: add melpa/stable version badges, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit f566ade5e4 264/301: Workaround for slow `c-before-change', ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 64c3505d04 235/301: correct spelling mistake, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 2f0c484817 283/301: Move iedit-buffering related to `iedit-lib', ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 7e277119fc 221/301: Fix doc string for markup tag, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 50b7da10ac 251/301: Add option `iedit-auto-buffering`, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 3211c2ee6c 228/301: Merge branch 'master' of github.com:victorhge/iedit, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 93b642f0a8 286/301: A few small fixes, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 02b4a6553e 243/301: Add the index of the current occurrence on mode-line,
ELPA Syncer <=
- [nongnu] elpa/iedit 06e600aae2 222/301: Fix: use return value of iedit-default-occurrence-mode-local, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit abcc27a9f0 231/301: Add Installation instruction, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 8b620efacb 262/301: Replace `inhibit-modification-hooks' with `iedit-updating', ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 6d2694356c 253/301: Move "declare-function" invocations outside of "when" statement., ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit f6682186f0 242/301: Replace eval-after-load with require check, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 14376a97e0 223/301: Ignore error in `iedit-mark-sgml-pair', ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 9fd1b43170 229/301: Fix failed test cases for Emacs 25.1, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 658c10a249 244/301: fix issue of iedit-restrict-function doesn't update mode-line text correctly, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 06f1f50939 224/301: Merge pull request #65 from pstray/master, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit c11ecd9080 273/301: Update copyright notice, ELPA Syncer, 2022/01/10