[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/iedit ad8fd96f86 215/301: Add support for markup tags
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/iedit ad8fd96f86 215/301: Add support for markup tags |
Date: |
Mon, 10 Jan 2022 22:59:03 -0500 (EST) |
branch: elpa/iedit
commit ad8fd96f8689f0ef7703482ddb9cbc554683e053
Author: Victor Ren <victorhge@gmail.com>
Commit: Victor Ren <victorhge@gmail.com>
Add support for markup tags
If the cursor is on a markup tag, only create occurrence
overlay on the opening and closing markup tag.
The code is adpated from `sgml-electric-tag-pair-before-change-function'.
---
iedit-tests.el | 27 ++++++++++++++++-
iedit.el | 92 +++++++++++++++++++++++++++++++++++++++++++---------------
2 files changed, 94 insertions(+), 25 deletions(-)
diff --git a/iedit-tests.el b/iedit-tests.el
index 748355fd52..46a420ce8e 100644
--- a/iedit-tests.el
+++ b/iedit-tests.el
@@ -2,7 +2,7 @@
;; Copyright (C) 2010, 2011, 2012 Victor Ren
-;; Time-stamp: <2016-06-17 10:38:46 Victor Ren>
+;; Time-stamp: <2016-06-18 18:00:27 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Version: 0.97
;; X-URL: http://www.emacswiki.org/emacs/Iedit
@@ -121,6 +121,31 @@ foo"
(iedit-mode 4)
(should (= 1 (length iedit-occurrences-overlays))))))
+(ert-deftest iedit-mode-with-tag-pair-test ()
+ (with-iedit-test-fixture
+ "<div> foo </div>
+<div> bar </div>
+<div> foobar </div>
+div
+foobar
+ foo
+ bar
+foo"
+ (lambda ()
+ (iedit-mode)
+ (goto-char 2)
+ (iedit-mode)
+ (should (= 2 (length iedit-occurrences-overlays)))
+ (should (string= iedit-initial-string-local "div"))
+ ;; (should (eq 'tag iedit-occurrence-type-local))
+ (iedit-mode)
+ (sgml-electric-tag-pair-mode t)
+ (iedit-mode)
+ (should (= 3 (length iedit-occurrences-overlays)))
+ (should (string= iedit-initial-string-local "<div>"))
+ (should (eq 'symbol iedit-occurrence-type-local))
+ (sgml-electric-tag-pair-mode))))
+
(ert-deftest iedit-move-conjointed-overlays-test ()
(with-iedit-test-fixture
"foobar
diff --git a/iedit.el b/iedit.el
index a624d110ae..de3172a2c1 100644
--- a/iedit.el
+++ b/iedit.el
@@ -2,7 +2,7 @@
;; Copyright (C) 2010, 2011, 2012 Victor Ren
-;; Time-stamp: <2016-06-17 11:28:45 Victor Ren>
+;; Time-stamp: <2016-06-18 19:05:54 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Keywords: occurrence region simultaneous refactoring
;; Version: 0.9.9
@@ -423,9 +423,22 @@ Keymap used within overlays:
(setq iedit-skip-modification-once t)
(setq iedit-unmatched-lines-invisible
iedit-unmatched-lines-invisible-default)
(setq iedit-initial-region (list beg end))
- (message "%d matches for \"%s\""
- (iedit-start2 occurrence-regexp beg end)
- (iedit-printable occurrence-regexp))
+ (let ((counter 0))
+ (when (null sgml-electric-tag-pair-mode)
+ (setq iedit-occurrence-keymap iedit-occurrence-keymap-default)
+ (setq counter (iedit-make-sgml-pair)))
+ (when (= 0 counter)
+ (setq iedit-occurrence-keymap iedit-mode-occurrence-keymap)
+ (setq counter (iedit-make-occurrences-overlays occurrence-regexp beg
end)))
+ (message "%d matches for \"%s\""
+ counter
+ (iedit-printable occurrence-regexp))
+ (setq iedit-mode
+ (propertize
+ (concat " Iedit:" (number-to-string counter))
+ 'face
+ 'font-lock-warning-face))
+ (force-mode-line-update))
(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)
@@ -463,16 +476,43 @@ Keymap used within overlays:
('word (concat "\\<" (regexp-quote exp) "\\>"))
( t (regexp-quote exp))))
-(defun iedit-start2 (occurrence-regexp beg end)
- "Refresh Iedit mode."
- (setq iedit-occurrence-keymap iedit-mode-occurrence-keymap)
- (let ((counter (iedit-make-occurrences-overlays occurrence-regexp beg end)))
- (setq iedit-mode
- (propertize
- (concat " Iedit:" (number-to-string counter))
- 'face
- 'font-lock-warning-face))
- (force-mode-line-update)
+(defun iedit-make-sgml-pair ()
+ "If the cursor is on a markup tag, only create occurrence
+overlay on the opening and closing markup tag.
+
+The code is adpated from `sgml-electric-tag-pair-before-change-function'.
+Return 2 if succeeded, 0 if failed."
+ (let ((counter 0))
+ (save-excursion
+ (skip-chars-backward "[:alnum:]-_.:")
+ (if (or (eq (char-before) ?<)
+ (and (eq (char-before) ?/)
+ (eq (char-before (1- (point))) ?<)))
+ (let* ((endp (eq (char-before) ?/))
+ (cl-start (point))
+ (cl-end (progn (skip-chars-forward "[:alnum:]-_.:") (point)))
+ (match
+ (if endp
+ (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)
+ (backward-sexp 1)
+ (forward-char 2)
+ t)))))
+ (when (and match
+ (/= cl-end cl-start)
+ (equal (buffer-substring cl-start cl-end)
+ (buffer-substring (point)
+ (save-excursion
+ (skip-chars-forward
"[:alnum:]-_.:")
+ (point))))
+ (or (not endp) (eq (char-after cl-end) ?>)))
+ (setq iedit-initial-string-local (buffer-substring cl-start
cl-end))
+ (push (iedit-make-occurrence-overlay cl-start cl-end)
iedit-occurrences-overlays)
+ (push (iedit-make-occurrence-overlay (point) (+ (point) (-
cl-end cl-start))) iedit-occurrences-overlays)
+ (setq counter 2)
+ ))))
counter))
(defun iedit-done ()
@@ -584,13 +624,12 @@ the initial string globally."
(if (= 1 (length iedit-occurrences-overlays)) "" "es")))
(defun iedit-expand-by-a-line (where amount)
- "After restricting iedit to the current line with
-`iedit-restrict-current-line', this function expands the top or
-bottom of the search region upwards or downwards by `amount'
-lines. The region being acted upon is controlled with
-`where' ('top to act on the top, anything else for the
-bottom). With a prefix, collapses the top or bottom of the search
-region by `amount' lines."
+ "After start iedit-mode with only current symbol or the active
+region, this function expands the top or bottom of the search
+region upwards or downwards by `amount' lines. The region being
+acted upon is controlled with `where' ('top to act on the top,
+anything else for the bottom). With a prefix, collapses the top
+or bottom of the search region by `amount' lines."
(interactive "P")
(let ((occurrence (iedit-current-occurrence-string)))
(iedit-cleanup)
@@ -687,7 +726,6 @@ prefix, bring the top of the region back down one
occurrence."
'face 'font-lock-warning-face))
(force-mode-line-update)))
-
(defun iedit-toggle-case-sensitive ()
"Toggle case-sensitive matching occurrences. "
(interactive)
@@ -701,13 +739,19 @@ prefix, bring the top of the region back down one
occurrence."
(let* ((occurrence-regexp (iedit-regexp-quote iedit-last-occurrence-local))
(begin (car iedit-initial-region))
(end (cadr iedit-initial-region))
- (counter (iedit-start2 occurrence-regexp begin end)))
+ (counter (iedit-make-occurrences-overlays occurrence-regexp begin
end)))
(message "iedit %s. %d matches for \"%s\""
(if iedit-case-sensitive
"is case sensitive"
"ignores case")
counter
- (iedit-printable occurrence-regexp)))))
+ (iedit-printable occurrence-regexp))
+ (setq iedit-mode
+ (propertize
+ (concat " Iedit:" (number-to-string counter))
+ 'face
+ 'font-lock-warning-face))
+ (force-mode-line-update))))
(provide 'iedit)
- [nongnu] elpa/iedit 5883f9af54 211/301: Avoid overriding user's key bindings, (continued)
- [nongnu] elpa/iedit 5883f9af54 211/301: Avoid overriding user's key bindings, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 95e7731a91 147/301: bugfix for when there are no occurrences, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 19abf6e871 247/301: Update URLs to emacswiki, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit ed52608a0d 268/301: Fix conjoined occurrences issues, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 890a11657c 226/301: Merge pull request #66 from pstray/master, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit a5ce38a9c3 123/301: fix deleting char at end of overlay with mirror at EOB, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 8219304d9c 051/301: Fix problem when iedit-stop-buffering is called when current point is at any occurrence., ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit d872cb77e5 058/301: Update comments for restricting, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 75552aa1c8 090/301: Rename, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 33d1b24e04 080/301: Fix compatible with Emacs 22 problem, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit ad8fd96f86 215/301: Add support for markup tags,
ELPA Syncer <=
- [nongnu] elpa/iedit 5b14cc9fca 241/301: Add a demo gif and update document, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 03b647be8b 234/301: Expand or collapse mutiple lines, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 88101571fe 288/301: Make it an option to save occurrence in the kill ring, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit ca844b40f4 265/301: Fix package URLs in commentaries, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 3a892bac38 277/301: Enhance a test case to compile iedit under clean environment, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit f79846e639 275/301: Fix issue #117, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit f74ae491f3 291/301: fix failed test cases, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 3bd4c15e3d 301/301: Add license file with GPLv3, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 344ff8de91 299/301: Add iedit-autoloads.el to .gitignore, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit f88df1072b 116/301: Merge branch 'master' of github.com:victorhge/iedit, ELPA Syncer, 2022/01/10