[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/iedit 0ef1410ec5 259/301: Add iedit-show/hide-occurrence-l
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/iedit 0ef1410ec5 259/301: Add iedit-show/hide-occurrence-lines |
Date: |
Mon, 10 Jan 2022 22:59:08 -0500 (EST) |
branch: elpa/iedit
commit 0ef1410ec5ef914d091dd3b5fa5497380a0ac589
Author: victor <victorhge@gmail.com>
Commit: Victor <victorhge@gmail.com>
Add iedit-show/hide-occurrence-lines
The lines containing occurrence can be hidden.
The default keybinding is C-".
---
iedit-lib.el | 129 +++++++++++++++++++++++++++++++++++++--------------------
iedit-tests.el | 48 ++++++++++++++++-----
iedit.el | 6 +--
3 files changed, 125 insertions(+), 58 deletions(-)
diff --git a/iedit-lib.el b/iedit-lib.el
index 236a3f5a29..3bd9f6c979 100644
--- a/iedit-lib.el
+++ b/iedit-lib.el
@@ -3,7 +3,7 @@
;; Copyright (C) 2010, 2011, 2012 Victor Ren
-;; Time-stamp: <2020-04-12 14:56:30 Victor Ren>
+;; Time-stamp: <2020-07-16 12:17:46 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Keywords: occurrence region simultaneous rectangle refactoring
;; Version: 0.9.9.9
@@ -38,10 +38,15 @@
;; - Other basic support APIs
;;
;; A few concepts that help you understand what this is about:
-;; Occurrence
-;; Occurrence overlay
-;; Unmatched lines
-;; Context lines
+;;
+;; Occurrence - one of the regions that are selected, highlighted, usually the
+;; same and about to be modified.
+;;
+;; Occurrence overlay - overlay used to provide a different face for occurrence
+;;
+;; Occurrence line - the line that has at least one occurrence
+;;
+;; Context line - the line that doesn't have occurrences
;;; todo:
;; - Update comments for APIs
@@ -121,10 +126,8 @@ configurable via `iedit-ready-only-occurrence'.")
"This is buffer local variable.
If no-nil, matching is case sensitive.")
-(defvar iedit-unmatched-lines-invisible nil
- "This is buffer local variable which indicates whether
-unmatched lines are hided.
-Unmatched lines are the lines that don't have occurrences.")
+(defvar iedit-hiding nil
+ "This is buffer local variable which indicates whether buffer lines are
hided. ")
(defvar iedit-forward-success t
"This is buffer local variable which indicates the moving
@@ -175,7 +178,7 @@ 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-variable-buffer-local 'iedit-hiding)
(make-local-variable 'iedit-case-sensitive)
(make-variable-buffer-local 'iedit-forward-success)
(make-variable-buffer-local 'iedit-before-modification-string)
@@ -202,7 +205,8 @@ occurrence.")
(define-key map (kbd "<S-tab>") 'iedit-prev-occurrence)
(define-key map (kbd "<S-iso-lefttab>") 'iedit-prev-occurrence)
(define-key map (kbd "<backtab>") 'iedit-prev-occurrence)
- (define-key map (kbd "C-'") 'iedit-show/hide-unmatched-lines)
+ (define-key map (kbd "C-'") 'iedit-show/hide-context-lines)
+ (define-key map (kbd "C-\"") 'iedit-show/hide-occurrence-lines)
map)
"Keymap used while Iedit mode is enabled.")
@@ -363,9 +367,9 @@ Return the start position of the new occurrence if
successful."
iedit-occurrences-overlays)
(iedit-update-index point)
(message "Add one match for \"%s\"." (iedit-printable occurrence-exp))
- (when iedit-unmatched-lines-invisible
+ (when iedit-hiding
(iedit-show-all)
- (iedit-hide-unmatched-lines iedit-occurrence-context-lines))
+ (iedit-hide-context-lines iedit-occurrence-context-lines))
))
pos))
@@ -397,7 +401,8 @@ there are."
(setq iedit-read-only-occurrences-overlays nil)
(setq iedit-aborting nil)
(setq iedit-before-modification-string "")
- (setq iedit-before-buffering-undo-list nil))
+ (setq iedit-before-buffering-undo-list nil)
+ (setq iedit-hiding nil))
(defun iedit-make-occurrence-overlay (begin end)
"Create an overlay for an occurrence in Iedit mode.
@@ -422,13 +427,13 @@ occurrences if the user starts typing."
(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)))
- (overlay-put unmatched-lines-overlay iedit-invisible-overlay-name t)
- (overlay-put unmatched-lines-overlay 'invisible
'iedit-invisible-overlay-name)
- ;; (overlay-put unmatched-lines-overlay 'intangible t)
- unmatched-lines-overlay))
+(defun iedit-make-invisible-overlay (begin end)
+ "Create an invisible overlay from `begin` to `end`."
+ (let ((invisible-overlay (make-overlay begin end (current-buffer) nil t)))
+ (overlay-put invisible-overlay iedit-invisible-overlay-name t)
+ (overlay-put invisible-overlay 'invisible 'iedit-invisible-overlay-name)
+ ;; (overlay-put invisible-overlay 'intangible t)
+ invisible-overlay))
(defun iedit-post-undo ()
"Check if it is time to abort iedit after undo command is executed.
@@ -621,68 +626,103 @@ the buffer."
(setq pos (previous-single-char-property-change pos
'iedit-occurrence-overlay-name)))
pos))
-(defun iedit-show/hide-unmatched-lines (&optional arg)
- "Show or hide unmatched lines.
+(defun iedit-show/hide-context-lines (&optional arg)
+ "Show or hide context lines.
A prefix ARG specifies how many lines before and after the
-occurrences are not hided; negative is treated the same as zero.
+occurrences are not hidden; negative is treated the same as zero.
If no prefix argument, the prefix argument last time or default
value of `iedit-occurrence-context-lines' is used for this time."
(interactive "P")
(if (null arg)
;; toggle visible
- (progn (setq iedit-unmatched-lines-invisible (not
iedit-unmatched-lines-invisible))
- (if iedit-unmatched-lines-invisible
- (iedit-hide-unmatched-lines iedit-occurrence-context-lines)
+ (progn (setq iedit-hiding (not iedit-hiding))
+ (if iedit-hiding
+ (iedit-hide-context-lines iedit-occurrence-context-lines)
(iedit-show-all)))
;; reset invisible lines
(setq arg (prefix-numeric-value arg))
(if (< arg 0)
(setq arg 0))
- (unless (and iedit-unmatched-lines-invisible
+ (unless (and iedit-hiding
(= arg iedit-occurrence-context-lines))
- (when iedit-unmatched-lines-invisible
+ (when iedit-hiding
(remove-overlays nil nil iedit-invisible-overlay-name t))
- (setq iedit-occurrence-context-lines arg)
- (setq iedit-unmatched-lines-invisible t)
- (iedit-hide-unmatched-lines iedit-occurrence-context-lines))))
+ (setq iedit-occurrence-context-lines arg)
+ (setq iedit-hiding t)
+ (iedit-hide-context-lines iedit-occurrence-context-lines))))
(defun iedit-show-all()
- "Show hided lines."
+ "Show hidden lines."
(setq line-move-ignore-invisible nil)
(remove-from-invisibility-spec '(iedit-invisible-overlay-name . t))
(remove-overlays nil nil iedit-invisible-overlay-name t))
-(defun iedit-hide-unmatched-lines (context-lines)
- "Hide unmatched lines using invisible overlay."
+(defun iedit-hide-context-lines (visible-context-lines)
+ "Hide context lines using invisible overlay."
(let ((prev-occurrence-end 1)
- (unmatched-lines nil))
+ (hidden-regions nil))
(save-excursion
(goto-char (iedit-first-occurrence))
(while (/= (point) (point-max))
;; Now at the beginning of an occurrence
(let ((current-start (point)))
- (forward-line (- context-lines))
+ (forward-line (- visible-context-lines))
(let ((line-beginning (line-beginning-position)))
(if (> line-beginning prev-occurrence-end)
- (push (list prev-occurrence-end (1- line-beginning))
unmatched-lines)))
+ (push (list prev-occurrence-end (1- line-beginning))
hidden-regions)))
;; goto the end of the occurrence
(goto-char (next-single-char-property-change current-start
'iedit-occurrence-overlay-name)))
(let ((current-end (point)))
- (forward-line context-lines)
+ (forward-line visible-context-lines)
(setq prev-occurrence-end (1+ (line-end-position)))
;; goto the beginning of next occurrence
(goto-char (next-single-char-property-change current-end
'iedit-occurrence-overlay-name))))
(if (< prev-occurrence-end (point-max))
- (push (list prev-occurrence-end (point-max)) unmatched-lines))
- (when unmatched-lines
+ (push (list prev-occurrence-end (point-max)) hidden-regions))
+ (when hidden-regions
(set (make-local-variable 'line-move-ignore-invisible) t)
(add-to-invisibility-spec '(iedit-invisible-overlay-name . t))
- (dolist (unmatch unmatched-lines)
- (iedit-make-unmatched-lines-overlay (car unmatch) (cadr unmatch)))))
- unmatched-lines))
+ (dolist (region hidden-regions)
+ (iedit-make-invisible-overlay (car region) (cadr region)))))
+ hidden-regions))
;;;; functions for overlay keymap
+(defun iedit-hide-occurrence-lines ()
+ "Hide occurrence lines using invisible overlay."
+ (let ((hidden-regions nil)
+ (beginning nil)
+ (end nil))
+ (save-excursion
+ (goto-char (iedit-first-occurrence))
+ ;; Now at the beginning of an occurrence
+ (setq beginning (line-beginning-position))
+ (while (/= (point) (point-max))
+ ;; goto the end of the occurrence
+ (goto-char (next-single-char-property-change (point)
'iedit-occurrence-overlay-name))
+ (setq end (line-end-position))
+ ;; goto the next beginning of the occurrence
+ (goto-char (next-single-char-property-change (point)
'iedit-occurrence-overlay-name))
+ (when (or (> (line-beginning-position) (1+ end))
+ (= (line-end-position) (point-max)))
+ (push (list beginning end) hidden-regions)
+ (setq beginning (line-beginning-position)))))
+ (when hidden-regions
+ (set (make-local-variable 'line-move-ignore-invisible) t)
+ (add-to-invisibility-spec '(iedit-invisible-overlay-name . t))
+ (dolist (region hidden-regions)
+ (iedit-make-invisible-overlay (car region) (cadr region))))
+ ;; Value returned is for ert
+ hidden-regions))
+
+(defun iedit-show/hide-occurrence-lines ()
+ "Show or hide occurrence lines using invisible overlay."
+ (interactive "*")
+ (setq iedit-hiding (not iedit-hiding))
+ (if (not iedit-hiding)
+ (iedit-show-all)
+ (iedit-hide-occurrence-lines)))
+
(defun iedit-apply-on-occurrences (function &rest args)
"Call function for each occurrence."
(let ((inhibit-modification-hooks t))
@@ -891,7 +931,6 @@ FORMAT."
(goto-char (next-single-char-property-change (point)
'iedit-occurrence-overlay-name))
(goto-char (next-single-char-property-change (point)
'iedit-occurrence-overlay-name))))))
-
;;; help functions
(defun iedit-find-current-occurrence-overlay ()
"Return the current occurrence overlay at point or point - 1.
diff --git a/iedit-tests.el b/iedit-tests.el
index 44beff9102..5f84b0b24d 100644
--- a/iedit-tests.el
+++ b/iedit-tests.el
@@ -2,7 +2,7 @@
;; Copyright (C) 2010, 2011, 2012 Victor Ren
-;; Time-stamp: <2019-04-19 16:01:33 Victor Ren>
+;; Time-stamp: <2020-07-16 22:32:42 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Version: 0.9.9.9
;; X-URL: https://www.emacswiki.org/emacs/Iedit
@@ -35,9 +35,9 @@
(require 'iedit-rect)
(ert-deftest iedit-compile-test ()
- (let ((byte-compile-error-on-warn t ))
- (should (byte-compile-file "./iedit.el"))
- (delete-file "./iedit.elc" nil)))
+ (let ((byte-compile-error-on-warn t))
+ (should (byte-compile-file (locate-library "iedit.el")))
+ (delete-file (byte-compile-dest-file "iedit.el") nil)))
(defmacro with-iedit-test-buffer (buffer-name &rest body)
(declare (indent 1) (debug t))
@@ -730,8 +730,8 @@ abcd"
"12345678901234567890123456789012345678901234567890...")))
(dolist (test iedit-printable-test-lists)
(should (string= (iedit-printable (car test)) (cadr test)))))
-(ert-deftest iedit-hide-unmatched-lines-test ()
- "Test function iedit-hide-unmatched-lines."
+(ert-deftest iedit-hide-context-lines-test ()
+ "Test function iedit-hide-context-lines."
(with-iedit-test-fixture
"foo
foo
@@ -756,13 +756,41 @@ a
a
foo"
(lambda ()
- (should (equal (iedit-hide-unmatched-lines 0) '((64 73) (47 54) (33 38)
(21 24) (9 10))))
+ (should (equal (iedit-hide-context-lines 0) '((64 73) (47 54) (33 38) (21
24) (9 10))))
(iedit-show-all)
- (should (equal (iedit-hide-unmatched-lines 1) '((66 71) (49 52) (35 36))))
+ (should (equal (iedit-hide-context-lines 1) '((66 71) (49 52) (35 36))))
(iedit-show-all)
- (should (equal (iedit-hide-unmatched-lines 2) '((68 69)) ))
+ (should (equal (iedit-hide-context-lines 2) '((68 69)) ))
(iedit-show-all)
- (should (equal (iedit-hide-unmatched-lines 3) nil)))))
+ (should (equal (iedit-hide-context-lines 3) nil)))))
+
+(ert-deftest iedit-hide-occurrence-lines-test ()
+ "Test function iedit-hide-occurrence-lines."
+ (with-iedit-test-fixture
+ "foo
+foo
+a
+ foo bar
+a
+a
+bar foo
+a
+a
+a
+bar foo
+a
+a
+a
+a
+ foo bar
+a
+a
+a
+a
+a
+foo"
+ (lambda ()
+ (should (equal (iedit-hide-occurrence-lines) '((74 77) (55 63) (39 46)
(25 32) (11 20) (1 8)))))))
;; todo add a auto performance test
(setq elp-function-list '(;; insert-and-inherit
diff --git a/iedit.el b/iedit.el
index e21291cb68..84e09b509f 100644
--- a/iedit.el
+++ b/iedit.el
@@ -2,7 +2,7 @@
;; Copyright (C) 2010, 2011, 2012 Victor Ren
-;; Time-stamp: <2020-07-05 21:59:22 Victor Ren>
+;; Time-stamp: <2020-07-16 13:14:05 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Keywords: occurrence region simultaneous refactoring
;; Version: 0.9.9.9
@@ -771,8 +771,8 @@ prefix, bring the top of the region back down one
occurrence."
(run-hooks 'deactivate-mark-hook)
(iedit-show-all)
(iedit-cleanup-occurrences-overlays beg end exclusive)
- (if iedit-unmatched-lines-invisible
- (iedit-hide-unmatched-lines iedit-occurrence-context-lines))
+ (if iedit-hiding
+ (iedit-hide-context-lines iedit-occurrence-context-lines))
(force-mode-line-update)))
(defun iedit-toggle-case-sensitive ()
- [nongnu] elpa/iedit 4884f61a3b 188/301: Merge branch 'master' of github.com:victorhge/iedit, (continued)
- [nongnu] elpa/iedit 4884f61a3b 188/301: Merge branch 'master' of github.com:victorhge/iedit, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 607e82c7b0 208/301: rename `iedit-current-symbol` to `iedit-default-occurrence`, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 1eabaa061a 210/301: Merge branch 'master' of github.com:victorhge/iedit, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit a6d8568379 161/301: Merge pull request #35 from lewang/ensure-skip-mofication-once, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 54b2495af7 214/301: More default occurrence types, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 5b0b618a20 219/301: Quit iedit-mode in `before-revert-hook', ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 7a6a0d65ab 252/301: Replace deprecated cl with cl-lib, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit c1b672cfc9 270/301: Fix bug #115. Now properly disable iedit-mode during desktop restore., ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 76ff4aa6b9 218/301: Merge pull request #64 from justbur/sgml-error, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 2221a517a8 227/301: Fix comments, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 0ef1410ec5 259/301: Add iedit-show/hide-occurrence-lines,
ELPA Syncer <=
- [nongnu] elpa/iedit 326b6f7787 263/301: Merge `iedit-number-occurrences' and `iedit-increment-occurrences', ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 02bad3e3b9 240/301: Fix compile warnings, ELPA Syncer, 2022/01/10
- [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