Skip to content

Commit

Permalink
Refactor copy and deletion helpers
Browse files Browse the repository at this point in the history
- Stop using custom yank handler for linewise yanking (always add
  newline like evil does)
- Properly propertize text for block and linewise yanks

Fixes #31.
  • Loading branch information
noctuid committed Feb 16, 2018
1 parent d9ae0dd commit 39d88b9
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 204 deletions.
2 changes: 1 addition & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ As an example, the following command will map the "operators" theme in the norma
~lispyville-set-key-theme~ will not reset lispyville's keymap, so it will not remove user-defined keybindings (unless they are overwritten by a key in one of the themes). The keybindings will be added in the order of the list, so if there is overlap between the listed themes, the one listed last will take precedence.

** Operators Key Theme
The corresponding symbol is =operators=. The default state is normal. These are safe versions of the corresponding evil operators that won't unbalance parentheses. Like with cleverparens, =dd= will bring closing delimiters that are on a line by themselves to the previous line while =cc= won't. To disable this behavior, =lispyville-dd-stay-with-closing= can be set to a non-nil value.
The corresponding symbol is =operators=. The default state is normal. These are safe versions of the corresponding evil operators that won't unbalance parentheses. Like with cleverparens, =dd= will bring closing delimiters that are on a line by themselves to the previous line while =cc= won't. To disable this behavior for =dd=, =lispyville-dd-stay-with-closing= can be set to a non-nil value.

| key | command |
|-------------------------------------+----------------------------------------------|
Expand Down
59 changes: 50 additions & 9 deletions lispyville-test.el
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
(require 'lispyville)

(setq lispyville-key-theme '(operators
s-operators
c-w
additional-movement
slurp/barf-cp
additional
mark-toggle))
(lispyville-set-key-theme)

(setq evil-move-cursor-back nil)

(defmacro lispyville-with (in &rest body)
"This is `lispy-with' modified for lispyville.
Note that | is considered to be \"on\" a character in normal/visual state,
Expand Down Expand Up @@ -57,7 +61,8 @@ character after it is not considered as part of the region."
(defun lispyville-replace-with-last-kill ()
"Replace buffer with last kill."
(delete-region (point-min) (point-max))
(yank))
(yank)
(goto-char (point-max)))

;;; Operators
(ert-deftest lispyville-yank ()
Expand All @@ -74,21 +79,21 @@ character after it is not considered as part of the region."
"y"
(lispyville-replace-with-last-kill))
"a { b [ c \"testing\"]}|"))
;; linewise
;; linewise (always ends with newline)
(should (string= (lispyville-with "((\n |(a b)))"
"yy"
(lispyville-replace-with-last-kill))
" (a b)|"))
" (a b)\n|"))
(should (string= (lispyville-with "(\n |(a b)\n (c d))"
"2yy"
(lispyville-replace-with-last-kill))
" (a b)\n (c d)|"))
" (a b)\n (c d)\n|"))
;; test that works at end of buffer
(should (string= (lispyville-with "|(a b)"
"yy"
(lispyville-replace-with-last-kill))
"(a b)|"))
;; test yank handler (pasting after linewise yank)
"(a b)\n|"))
;; test yank handler/pasting after linewise yank
(should (string= (lispyville-with "((\n |(a b)))"
"yyp")
"((\n (a b)))\n |(a b)"))
Expand All @@ -103,7 +108,12 @@ character after it is not considered as part of the region."
(should (string= (lispyville-with "~(a b)\n(|c d)"
(kbd "C-v y")
(lispyville-replace-with-last-kill))
"a\nc|")))
"a\nc|"))
;; test yank handler/pasting after yanking block
(should (string= (lispyville-with "~(a b)\n(|c d)"
(kbd "C-v y")
"p")
"(|aa b)\n(cc d)")))

(ert-deftest lispyville-yank-line ()
(should (string= (lispyville-with "(|a (b c) d)"
Expand Down Expand Up @@ -145,12 +155,33 @@ character after it is not considered as part of the region."
"d")
"(|)"))
;; linewise
;; after deletion, at closing delimiter(s)
(should (string= (lispyville-with "((\n |(a b)))"
"dd")
"|(())"))
(should (string= (lispyville-with "((\n |(a b)))\n"
"dd")
"(())\n|"))
(should (string= (lispyville-with "(\n |(a b)\n (c d))"
"2dd")
"|()"))
;; closing delimiter(s) but comment before
(should (string= (lispyville-with "((; comment\n |(a b)))"
"dd")
"((; comment\n |))"))
(let ((lispyville-dd-stay-with-closing t))
(should (string= (lispyville-with "((\n |(a b)))\n"
"dd")
"((\n |))")))
;; after deletion, at opening delimiter(s)
(should (string= (lispyville-with "|(a b\n c)"
"dd")
;; should remove whitespace
"|(c)"))
;; should delete final newline
(should (string= (lispyville-with "a\n|"
"dd")
"|a"))
;; test that works at end of buffer
(should (string= (lispyville-with "|(a b)" "dd")
"|"))
Expand All @@ -174,7 +205,14 @@ character after it is not considered as part of the region."
"|( b)\n( d)"))
;; test whether delimiters are pulled into comments
(should (string= (lispyville-with "(a\n ;; b\n |c)" "dd")
"(a\n ;; b\n |)")))
"(a\n ;; b\n |)"))
(should (string= (lispyville-with "(a\n ;;~ b\n c)|" "d")
"(a\n ;;|\n)"))
(should (string= (lispyville-with ";; ~a\n(b\n ;;| c\n d)" "d")
";; |\n(c\n d)"))
;; should pull into comment here since no unmatched delimiters
(should (string= (lispyville-with ";; ~a\nb| c" "d")
";; |c")))

(ert-deftest lispyville-delete-line ()
(should (string= (lispyville-with "(|a (b c) d)"
Expand All @@ -184,6 +222,9 @@ character after it is not considered as part of the region."
(should (string= (lispyville-with "((\n ~|(a b)))"
"D")
"|(())"))
(should (string= (lispyville-with "((\n ~|(a b)))\n"
"D")
"(())\n|"))
;; visual block
(should (string= (lispyville-with "((~a b)\n (c d|))"
(kbd "C-v D"))
Expand Down Expand Up @@ -263,7 +304,7 @@ character after it is not considered as part of the region."
"(\n |)"))
;; test that works at end of buffer
(should (string= (lispyville-with "|(a b)" "cc")
"|"))
"|\n"))
;; test that undo is one step (evil-want-fine-undo nil)
(should (string= (lispyville-with "(defvar foo\n bar baz)|"
(concat "cchello" (kbd "ESC") "u"))
Expand Down
Loading

0 comments on commit 39d88b9

Please sign in to comment.