[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-surround 68f7033322 138/175: optionally keep xml attr
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-surround 68f7033322 138/175: optionally keep xml attributes |
Date: |
Mon, 9 Oct 2023 13:01:09 -0400 (EDT) |
branch: elpa/evil-surround
commit 68f7033322dcba3781dddb48465878e896a9f57b
Author: tam5 <arimiller92@gmail.com>
Commit: tam5 <arimiller92@gmail.com>
optionally keep xml attributes
---
evil-surround.el | 35 ++++++++++++++++++++++++++++++-----
test/evil-surround-test.el | 10 ++++++++++
2 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/evil-surround.el b/evil-surround.el
index 91b6d1c6cc..6eb3a119e9 100644
--- a/evil-surround.el
+++ b/evil-surround.el
@@ -88,13 +88,23 @@ Each item is of the form (OPERATOR . OPERATION)."
(defvar evil-surround-read-tag-map
(let ((map (copy-keymap minibuffer-local-map)))
- (define-key map ">" 'exit-minibuffer)
+ (define-key map ">" (lambda ()
+ (interactive)
+ (call-interactively 'self-insert-command)
+ (run-at-time nil nil
+ (lambda ()
+ (when (active-minibuffer-window)
+ (select-window
(active-minibuffer-window))
+ (exit-minibuffer))))))
map)
"Keymap used by `evil-surround-read-tag'.")
(defvar evil-surround-record-repeat nil
"Flag to indicate we're manually recording repeat info.")
+(defvar evil-surround-last-deleted-left ""
+ "The previously deleted LEFT region.")
+
(defun evil-surround-read-from-minibuffer (&rest args)
(when evil-surround-record-repeat
(evil-repeat-keystrokes 'post))
@@ -124,13 +134,27 @@ Each item is of the form (OPERATOR . OPERATION)."
(cons (format "%s(" (or fname ""))
")")))
+(defconst evil-surround-tag-name-re "\\([0-9a-z-]+\\)"
+ "Regexp matching an XML tag name.")
+
+(defun evil-surround-tag-p (string)
+ "Return t if `STRING' looks like a tag."
+ (string-match-p evil-surround-tag-name-re string))
+
(defun evil-surround-read-tag ()
"Read a XML tag from the minibuffer."
(let* ((input (evil-surround-read-from-minibuffer "<" ""
evil-surround-read-tag-map))
- (match (string-match "\\([0-9a-z-]+\\)\\(.*?\\)[>]*$" input))
+ (match (string-match (concat evil-surround-tag-name-re
"\\(.*?\\)\\([>]*\\)$") input))
(tag (match-string 1 input))
- (rest (match-string 2 input)))
- (cons (format "<%s%s>" (or tag "") (or rest ""))
+ (rest (match-string 2 input))
+ (keep-attributes (not (string-match-p ">" input)))
+ (original-tag (when (evil-surround-tag-p
evil-surround-last-deleted-left)
+ (substring evil-surround-last-deleted-left
+ (string-match (concat "<"
evil-surround-tag-name-re) evil-surround-last-deleted-left)
+ (match-end 0))))
+ (original-attributes (when (and keep-attributes original-tag)
+ (substring evil-surround-last-deleted-left
(length original-tag)))))
+ (cons (format "<%s%s%s" (or tag "") (or rest "") (or original-attributes
">"))
(format "</%s>" (or tag "")))))
(defun evil-surround-valid-char-p (char)
@@ -217,7 +241,8 @@ between these overlays is what is deleted."
(interactive (evil-surround-input-char))
(cond
((and outer inner)
- (delete-region (overlay-start outer) (overlay-start inner))
+ (setq evil-surround-last-deleted-left
+ (delete-and-extract-region (overlay-start outer) (overlay-start
inner)))
(delete-region (overlay-end inner) (overlay-end outer))
(goto-char (overlay-start outer)))
(t
diff --git a/test/evil-surround-test.el b/test/evil-surround-test.el
index df71b11647..c70f1813ad 100644
--- a/test/evil-surround-test.el
+++ b/test/evil-surround-test.el
@@ -93,6 +93,16 @@
"<a>tag1</a> tag2"
("W.")
"<a>tag1</a> <a>tag2</a>"))
+ (ert-info ("optionally keep xml attributes")
+ (evil-test-buffer
+ :visual-start nil
+ :visual-end nil
+ "<div class=\"foo\">Bar</div>"
+ (turn-on-evil-surround-mode)
+ ("cst<span")
+ "<span class=\"foo\">Bar</span>"
+ ("cst<p>")
+ "<p>Bar</p>"))
(ert-info ("repeat surrounding")
(evil-test-buffer
"[o]ne two three"
- [nongnu] elpa/evil-surround 0eeef7a3a9 070/175: Merge pull request #68 from hlissner/master, (continued)
- [nongnu] elpa/evil-surround 0eeef7a3a9 070/175: Merge pull request #68 from hlissner/master, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 8b2ca83b7c 068/175: Fix #52, #39, and #5 (linewise surrounding), ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 78eddc8077 063/175: Merge pull request #50 from yangguang760/master, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 06071c3425 060/175: let* => let, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround a70e34164e 069/175: Don't indent first line on inline linewise surround, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 5c07befaf7 090/175: Merge pull request #89 from LemmingAvalanche/execute-permissions, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 7a0358ce3e 095/175: update readme, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround a4fc4483df 103/175: add credits to Tim C. Harper, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround cb4f0be9b4 119/175: add backquote delimiter test, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 822a0f61c3 111/175: Make `ysw` work like `cw`, not `ce`, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 68f7033322 138/175: optionally keep xml attributes,
ELPA Syncer <=
- [nongnu] elpa/evil-surround 31b895f1e1 128/175: fix #143: add readme entry on how to add new pairs through evil, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 5ad01dfa86 139/175: optionally keep xml attrs: add more tests, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround b670e5f338 143/175: Checking minibuffer window doesn't seem to make a difference either, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround f6162a7b5a 117/175: closes #112, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 4fbe6bf9ca 161/175: Limit global activation to text-, prog- and comint-mode, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 0d860be741 174/175: Fix get-delims to allow functions as values, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 648da3c544 159/175: Merge pull request #190 from MintSoup/master, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 0f629b8f9c 133/175: tweak implementation file header, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround c96499e91e 030/175: Extract surround-operator-alist to a customizeable variable, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround bd3909bc3e 152/175: update make emacs, ELPA Syncer, 2023/10/09