[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-surround 440d391c89 130/175: Fix visible narrowing wh
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-surround 440d391c89 130/175: Fix visible narrowing when surrounding within a field (#135) |
Date: |
Mon, 9 Oct 2023 13:01:09 -0400 (EDT) |
branch: elpa/evil-surround
commit 440d391c89a7f6d5a7a0c9486b0e8ac4fc7f43aa
Author: Lionel Henry <lionel.hry@gmail.com>
Commit: Filipe Silva <ninrod@users.noreply.github.com>
Fix visible narrowing when surrounding within a field (#135)
* Fix visible narrowing when surrounding within a field
* Test that buffer is widened before reading char
---
evil-surround.el | 25 ++++++++++++++++++++-----
test/evil-surround-test.el | 27 ++++++++++++++++++++++++++-
2 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/evil-surround.el b/evil-surround.el
index fbcaee7203..d2e59ddfdc 100644
--- a/evil-surround.el
+++ b/evil-surround.el
@@ -102,6 +102,21 @@ Each item is of the form (OPERATOR . OPERATION)."
(evil-repeat-record res))
res))
+;; The operator state narrows the buffer to the current field. This
+;; function widens temporarily before reading a character so the
+;; narrowing is not visible to the user.
+(defun evil-surround-read-char ()
+ (if (evil-operator-state-p)
+ (save-restriction (widen) (read-char))
+ (read-char)))
+
+(defun evil-surround-input-char ()
+ (list (evil-surround-read-char)))
+
+(defun evil-surround-input-region-char ()
+ (append (evil-operator-range t)
+ (evil-surround-input-char)))
+
(defun evil-surround-function ()
"Read a functionname from the minibuffer and wrap selection in function call"
(let ((fname (evil-surround-read-from-minibuffer "" "")))
@@ -191,7 +206,7 @@ Alternatively, the text to delete can be represented with
the overlays OUTER and INNER, where OUTER includes the delimiters
and INNER excludes them. The intersection (i.e., difference)
between these overlays is what is deleted."
- (interactive "c")
+ (interactive (evil-surround-input-char))
(cond
((and outer inner)
(delete-region (overlay-start outer) (overlay-start inner))
@@ -213,11 +228,11 @@ between these overlays is what is deleted."
"Change the surrounding delimiters represented by CHAR.
Alternatively, the text to delete can be represented with the
overlays OUTER and INNER, which are passed to `evil-surround-delete'."
- (interactive "c")
+ (interactive (evil-surround-input-char))
(cond
((and outer inner)
(evil-surround-delete char outer inner)
- (let ((key (read-char)))
+ (let ((key (evil-surround-read-char)))
(evil-surround-region (overlay-start outer)
(overlay-end outer)
nil (if (evil-surround-valid-char-p key) key
char))))
@@ -315,7 +330,7 @@ Becomes this:
:thing
}"
- (interactive "<R>c")
+ (interactive (evil-surround-input-region-char))
(when (evil-surround-valid-char-p char)
(let* ((overlay (make-overlay beg end nil nil t))
(pair (or (and (boundp 'pair) pair) (evil-surround-pair char)))
@@ -371,7 +386,7 @@ Becomes this:
(evil-define-operator evil-Surround-region (beg end type char)
"Call surround-region, toggling force-new-line"
- (interactive "<R>c")
+ (interactive (evil-surround-input-region-char))
(evil-surround-region beg end type char t))
;;;###autoload
diff --git a/test/evil-surround-test.el b/test/evil-surround-test.el
index 120bac5bb0..df8a03f2bb 100644
--- a/test/evil-surround-test.el
+++ b/test/evil-surround-test.el
@@ -14,6 +14,18 @@
?\[ '("[ " . " ]")
?\{ '("{ " . " }"))
+(defmacro test-widened-buffer (start cmds exp)
+ (declare (indent 0))
+ `(let (widened)
+ (evil-test-buffer
+ ,start
+ (turn-on-evil-surround-mode)
+ (cl-letf (((symbol-function #'widen)
+ (lambda () (setq widened t))))
+ (execute-kbd-macro ,(car cmds)))
+ ,exp)
+ (should widened)))
+
(ert-deftest evil-surround-test ()
(ert-info ("basic surrounding")
(evil-test-buffer
@@ -169,4 +181,17 @@
(turn-on-evil-surround-mode)
("cs`)")
"[(]this_is_a_backtick_surrounded_word)"
- )))
+ ))
+ (ert-info ("buffer is widened before reading char")
+ (test-widened-buffer
+ "`[w]ord`"
+ ("cs`)")
+ "[(]word)")
+ (test-widened-buffer
+ "`[w]ord`"
+ ("ds`")
+ "[w]ord")
+ (test-widened-buffer
+ "[w]ord"
+ ("ysiwb")
+ "[(]word)")))
- [nongnu] elpa/evil-surround 5a8b3eac2c 114/175: update logo, (continued)
- [nongnu] elpa/evil-surround 5a8b3eac2c 114/175: update logo, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 757ddb93c7 122/175: add tests for @jusbur's pull #130 which fixes #125, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround a14856cd81 157/175: Bump version to 1.0.4, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 5a20c9757e 126/175: surround-function improvement for lisp modes (#134), ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 62255a9901 123/175: Fix regression for Emacs 26 caused by #125 fix, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 6e1da767ec 125/175: try same layout layout as evil, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 63ce018488 132/175: add license file, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 2d878b6cce 166/175: Enable lexical binding, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 6028c76399 131/175: readme: add missing link to `define-and-bind-text-object` macro, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 83c2e0f369 137/175: add a "make emacs" makefile option to fire up a clean emacs..., ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 440d391c89 130/175: Fix visible narrowing when surrounding within a field (#135),
ELPA Syncer <=
- [nongnu] elpa/evil-surround b11048d92a 173/175: Trim whitespace from delimeters before using for deletion/change, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 4d6cc94df0 146/175: Add surround text objects from local keymap (#165), ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 282a975bda 154/175: Typo fix, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround a3803cfb51 141/175: Add a test for surrounding with a tag in a macro, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 6d37e5c910 115/175: add melpa stable badge, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround f273821f57 165/175: Merge pull request #188 from skangas/nongnu-elpa-fixes, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 2bc8aa6425 160/175: Merge pull request #186 from leungbk/prefix-calls, ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 4a21d756b7 168/175: Revert "Enable lexical binding", ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround a3034c284d 049/175: Fix surrounding with invalid chars, like ESC (Fix #51), ELPA Syncer, 2023/10/09
- [nongnu] elpa/evil-surround 27eb4112db 050/175: Merge pull request #53 from hlissner/block-surround, ELPA Syncer, 2023/10/09