├── imgs └── torta-holandesa.jpg ├── run-tests.sh ├── docs ├── usage.md └── reference.md ├── README.md └── vilpy-test.el /imgs/torta-holandesa.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andre0991/vilpy/HEAD/imgs/torta-holandesa.jpg -------------------------------------------------------------------------------- /run-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | 4 | CURL="curl -fsSkL --retry 9 --retry-delay 9" 5 | GHRAW="https://raw.githubusercontent.com" 6 | WORKDIR=$(mktemp -d) 7 | 8 | cp vilpy.el "$WORKDIR" 9 | cp vilpy-test.el "$WORKDIR" 10 | 11 | cd "$WORKDIR" 12 | pwd "$WORKDIR" 13 | 14 | $CURL -O ${GHRAW}/abo-abo/avy/master/avy.el 15 | $CURL -O ${GHRAW}/clojure-emacs/clojure-mode/master/clojure-mode.el 16 | 17 | emacs -Q --batch -L . -f batch-byte-compile avy.el clojure-mode.el vilpy.el 18 | emacs -Q -L . -batch -l ert -l clojure-mode -l vilpy-test.el -f ert-run-tests-batch-and-exit 19 | -------------------------------------------------------------------------------- /docs/usage.md: -------------------------------------------------------------------------------- 1 | # Usage 2 | 3 | In all the following examples, the character `|` denotes the point. 4 | 5 | ## Example 1: Navigation, deletion, evaluation and basic transformation 6 | 7 | ### Commands 8 | 9 | | command | binding | 10 | |----------------------------|--------------------| 11 | | `vilpy-special` | backtab | 12 | | `vilpy-ace-paren` | q | 13 | | `vilpy-ace-subword` | - | 14 | | `vilpy-ace-symbol` | f | 15 | | `vilpy-beginning-of-defun` | I | 16 | | `vilpy-delete` | C-d | 17 | | `vilpy-down` | j | 18 | | `vilpy-eval-buffer` | B | 19 | | `vilpy-eval` | e | 20 | | `vilpy-step-in` | l | 21 | 22 | ### Code 23 | 24 | We will start with the following snippet: 25 | 26 | ``` 27 | (defun plus-one (n) 28 | (+ 1 n) 29 | (message "debug")) 30 | 31 | (plus-one 2) 32 | ``` 33 | 34 | This will be the final result: 35 | 36 | ``` 37 | (def plus-two (n) 38 | (+ 2 n)) 39 | ``` 40 | 41 | ### Steps 42 | 43 | We start with this code. Note that the point is in the middle of `defun`. 44 | 45 | ``` 46 | (de|fun plus-one (n) 47 | (+ 1 n) 48 | (message "done")) 49 | 50 | (plus-one 2) 51 | ``` 52 | 53 | **Evaluating `(plus-one 2)`** 54 | 55 | - Press backtab (that is, shift and tab) to move the point to the beginning of the defun and enter special mode. 56 | - First, evaluate the defun with e (`vilpy-eval`). 57 | - Then, use j (`vilpy-down`) and e for evaluating `(plus-one 2)` and getting 3. 58 | - Use k for getting back to the defun. Note that this entire sequence is equivalent to simply using B (`vilpy-eval-buffer`). 59 | 60 | **Change `plus-one` to `plus-two`** 61 | 62 | - With the point in the beginning of the defun, press - (`vilpy-ace-subword`). This will display a letter in each subword, alphabetically, like `(adefun bplus-cone ...)`. Press `c` for jumping to `one`, which will be marked. 63 | - Then, use C-d (`vilpy-delete`) for removing `one` and write `two`. 64 | - Press backtab for getting back to special mode. 65 | 66 | **Remove `message`** 67 | 68 | - Use l (`vilpy-step-in`) three times for getting to the `message` form. This is equivalent to 3l. Alternatively, use q (`vilpy-ace-paren`) and `d` for directly jumping to `message`. 69 | - Then, press C-d (`vilpy-delete`) twice for removing the form and the blank line. The point will jump to the beginning of the defun. 70 | 71 | **Change `(+ 1 n)` to `(+ 2 n)`** 72 | 73 | - Press f (`vilpy-ace-symbol`). This command will add a letter before each symbol. Use `e` for directly jumping to `1`. 74 | - Use C-d for deleting it and write `2`. 75 | - Use backtab for getting back to special mode. 76 | - I (`vilpy-beginning-of-defun`) for jumping to the beginning of the defun. 77 | - e for evaluating it. 78 | 79 | **Deleting `(plus-one 2)`** 80 | 81 | - Finally, press j for moving the point to `(plus-one 2)`. 82 | - C-d for deleting it. 83 | 84 | 85 | ## Example 2: Killing, copying and yanking 86 | 87 | ### Commands 88 | | command | binding | 89 | |-------------------------|--------------------| 90 | | `vilpy-step-in` | l | 91 | | `vilpy-clone` | w | 92 | | `vilpy-down` | j | 93 | | `vilpy-ace-subword` | - | 94 | | `vilpy-special` | backtab | 95 | | `vilpy-up` | k | 96 | | `forward-char` | a | 97 | | `vilpy-space` | SPC | 98 | | `vilpy-kill` | C-k | 99 | | `vilpy-step-out` | h | 100 | | `vilpy-open-line-below` | o | 101 | 102 | ### Code 103 | 104 | We will starting with this snippet of code: 105 | 106 | ``` 107 | (defun foo 108 | () 109 | (do-bar) 110 | (do-baz (a) (b) (c))) 111 | ``` 112 | 113 | This will be the result: 114 | 115 | ``` 116 | (defun foo 117 | () 118 | (with-foo do-bar) 119 | (do-foo) 120 | (do-baz (a)) 121 | (a))) 122 | ``` 123 | 124 | ### Steps 125 | 126 | Consider that the point starts just before `defun`, in special mode. 127 | 128 | **Insert `(do-foo)`** 129 | 130 | - First, let's insert `(do-foo)` by duplicating `(do-bar)` and replacing `bar`. 131 | - Use l (`vilpy-step-in`) twice for getting to `do-bar`. This is equivalent to 2l or qc (`vilpy-ace-paren` followed by `c`). 132 | - Then, press w (`vilpy-clone`), which will duplicate `(do-foo)`. 133 | - Use j (`vilpy-down`) for moving to the second `(do-bar)`. 134 | - Press -b for marking `bar` and delete it with C-d. Type `foo` 135 | - Use backtab for getting back to special mode (that is, shift and tab). 136 | 137 | **Change `(do-bar)` to `(with-foo do-bar)`** 138 | 139 | - Use k (`vilpy-up`) for getting to `do-bar`. 140 | - Then, press a (`forward-char`).This is equivalent to the usual `C-f` Emacs binding. The point will be just after the paren: `(|do-bar)`. 141 | - Press SPC (`vilpy-space`) for inserting a whitespace character and type `with-foo`. 142 | - Use backtab (`vilpy-special`) for getting back to special mode. The point will be just before the paren, like this: `|(with-foo do-bar)`. 143 | 144 | **Remove `(b)` and `(c)` from `do-baz`** 145 | 146 | - Press j for getting to `do-baz`. 147 | - Use l twice for getting to `(b)`. 148 | - Then, use C-k (`vilpy-kill`) for killing until the end of the parent sexp. 149 | 150 | **Copy `(a)` to the line below** 151 | 152 | - Use backtab for getting back to special mode. 153 | - y for copying `(a)`. 154 | - Press h (`vilpy-step-out`) for getting to the paren sexp. 155 | - Use backtab for switching to the matching paren and RET for opening a new line. This is equivalent to just using o (`vilpy-open-line-below`). 156 | - Finally, press C-y (the standard `yank` command) for pasting the previously copied sexp. 157 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vilpy 2 | 3 |

4 | vilpy logo 6 |

7 | 8 | > creamy & even shorter lisp editing 9 | 10 | `vilpy` is a vi-like `paredit`. 11 | It is modal in the sense that when the point is exactly before or after a paren, keys run commands rather than inserting text. For more details, see [documentation](#documentation). 12 | 13 | `vilpy` is a stripped-down fork of the excellent [lispy](https://github.com/abo-abo/lispy). 14 | Think of it as a `lispy-core`, which is lighter, but no less sweet. 15 | `vilpy` keybindings are vimmier and it is considerably smaller (no refactoring and debugging features, fewer dependencies). 16 | For more differences with `lispy`, please consult the [alternatives](#alternatives) section. 17 | 18 | I prefer forking the original code because (1) the author is happy with the current approach of bundling everything in the same package, and that's perfectly fine ([issue](https://github.com/abo-abo/lispy/issues/74)) and (2) `lispy` is critical for getting things done in my job, but the Clojure-specific parts are not important for me and they do interfere with some projects. 19 | 20 | ## Supported languages & compatibility with other modes 21 | The navigation features are tested with emacs-lisp and Clojure, but they are likely to work with other lisps. 22 | 23 | emacs-lisp and Clojure (`cider` and `inf-clojure`) also support evaluation, describing the symbol at point and indentation. 24 | These features can be added to other languages by setting the proper handlers in the variable `vilpy--handlers-alist` (see the customization section). 25 | 26 | `vilpy` defines its own keybindings that might conflict with `parinfer`, `paredit` and other structural editing modes. 27 | 28 | ## Installation 29 | `vilpy` must be installed manually as of now. 30 | 31 | Note that `vilpy` requires [`avy`](https://github.com/abo-abo/avy). 32 | You might need to install it as well. 33 | 34 | ### Vanilla 35 | 36 | ``` emacs-lisp 37 | ;; replace `vilpy-load-path` by the directory that has `vilpy.el` 38 | (let ((vilpy-path "~/path/to/vilpy")) 39 | (add-to-list 'load-path vilpy-path) 40 | (require 'vilpy)) 41 | (add-hook 'emacs-lisp-mode-hook (lambda () (vilpy-mode 1))) 42 | (add-hook 'clojure-mode-hook (lambda () (vilpy-mode 1))) 43 | ; if using the treesitter version of clojure-mode: 44 | (add-hook 'clojure-ts-mode-hook (lambda () (vilpy-mode 1))) 45 | 46 | ;; recommended settings for `evil` users 47 | ;; those are the default keybindings, but they are overriden by `evil` 48 | (evil-define-key 'insert 'vilpy-mode-map (kbd "C-k") 'vilpy-kill) 49 | (evil-define-key 'insert 'vilpy-mode-map (kbd "C-d") 'vilpy-delete) 50 | ``` 51 | 52 | ### `use-package` 53 | 54 | ``` emacs-lisp 55 | (use-package vilpy 56 | :load-path 57 | "~/path/to/vilpy/" 58 | :hook 59 | ((emacs-lisp-mode clojure-mode clojure-ts-mode) . vilpy-mode)) 60 | ``` 61 | 62 | ## Documentation 63 | 64 | You can find workflow examples in [usage](/docs/usage.md). 65 | 66 | For a complete list of commands, see the [function reference](/docs/reference.md). 67 | 68 | ## Customization 69 | This section presents some common ways that `vilpy` can be configured. 70 | 71 | There is also the [wiki](https://github.com/Andre0991/vilpy/wiki), with additional configuration examples and tips. 72 | 73 | ### Adding support to other modes 74 | 75 | By default, `vilpy` supports Emacs Lisp and Clojure. 76 | These are the official supported modes because I use them everyday and the test suite ensures that their syntax is well handled by `vilpy`. 77 | That said, you can easily use `vilpy` with other languages (presumably lisps) and it should work without major issues. 78 | 79 | For example, for using `vilpy` with [sly](https://github.com/joaotavora/sly), customize `vilpy--handlers-alist` like this: 80 | 81 | ```emacs-lisp 82 | (add-to-list 'vilpy--handlers-alist 83 | '(:sly . ((:decider-fn . (lambda () (bound-and-true-p sly-mode))) 84 | (:eval-last-sexp . sly-eval-last-expression) 85 | (:eval-defun . sly-eval-defun) 86 | (:eval-region . sly-eval-region) 87 | (:eval-buffer . sly-eval-buffer) 88 | (:describe-symbol . sly-describe-symbol)))) 89 | ``` 90 | 91 | ### Keybindings 92 | #### Single-key bindings 93 | Use `vilpy-define-key` for overriding a default binding. 94 | 95 | For calling `my-function` with the key `H`, use 96 | 97 | ``` emacs-lisp 98 | (vilpy-define-key vilpy-mode-map "H" 'apt-vilpy-describe) 99 | ``` 100 | 101 | #### Multi-key bindings 102 | You may wish to override keybinding that reads two characters - for example, `wo`, which goes to the other window. 103 | 104 | There is no way to do that without modifying the whole prefix (`w`, in this example). 105 | 106 | That said, you can simply copy the current function that lists those bindings to your init file and modify it as you wish - and there is nothing wrong with that. 107 | 108 | For doing that, please consult `vilpy-mode-map-special` and check which function is called for the prefix you are going to change. Then, copy it to your configuration, as exemplified below. 109 | 110 | ``` emacs-lisp 111 | (defun vilpy-window-actions () 112 | (interactive) 113 | (cl-case (read-char-from-minibuffer "Actions:\n 114 | o: Select other window. 115 | h: Select left window. 116 | \n") 117 | (?o (other-window 1)) 118 | (?h (windmove-left)) 119 | (t (vilpy--complain-unrecognized-key)))) 120 | 121 | (vilpy-define-key map "w" 'vilpy-window-actions) 122 | ``` 123 | 124 | #### Overriding behavior 125 | You may want to override some default behavior based on some conditions. 126 | For example, suppose you want to change `H`, which is originally bound to `vilpy-foo`, to `my-function`, but only if `inf-clojure-minor-mode` is enabled. 127 | 128 | You would use this: 129 | 130 | ``` emacs-lisp 131 | (defun my-override-vilpy-describe () 132 | (interactive) 133 | (if (bound-and-true-p inf-clojure-minor-mode) 134 | (call-interactively 'my-function) 135 | (call-interactively 'vilpy-foo))) 136 | 137 | (vilpy-define-key vilpy-mode-map "H" 'my-override-vilpy-describe) 138 | ``` 139 | 140 | ## Alternatives 141 | ### [`lispy`](https://github.com/abo-abo/lispy/) 142 | `vilpy` has some important differences from its big brother. 143 | 144 | In particular, it attempts to respect the following design goals: 145 | - **Be vimmier**: the default keybindings resemble vim more than `lispy` (note that if you do not know vim, it's okay. `lispy` keybindings are arguably not super emacs-y either, so either way you would have to invest some time in learning some keys.) 146 | - **Reduce the feature set to navigation and evaluation functions**. We don't need debugging and tags features. Refactoring commands can be leveraged from other packages. This makes `vilypy` easier to maintain and understand. 147 | - **Have a reduced, but reliable set of commands that works well with all supported languages.** The original `lispy` has some nice refactoring tools, but they mostly works for Emacs Lisp. This adds confusion for people trying to use it, as it is not always clear if some command will work for a given language. 148 | - **Rely on fewer external dependencies**. This also makes `vilpy` easier to maintain. Currently, its only dependency is `avy`, which is essential for navigation commands. 149 | - **Drop support for non-lisps languages**. While the prospect of using `vilpy` in other languages is interesting, this is not very well tested and not a priority. That said, you can always invoke `vilpy-mode` manually and see what happens. 150 | - **Be less magic**. For example, in the original `lispy`, the function for evaluating the last sexp also uses `setq` when evaluating `defvars`. `vilpy` does not try to guess your intent. `vilpy` is intentionally dumber. 151 | - **Do not inject language-specific code**. For example, `lispy` loads `le-clojure.clj` when you use `cider` for providing some features such as getting bindings from `let` when evaluating forms. This relies on injecting dependencies to `cider` and will not work on some project setups (see https://github.com/abo-abo/lispy/issues/552). `vilpy` simple uses `cider-eval*` functions. 152 | 153 | That said, `lispy` has more features, including debugging and refactoring capabilities and support more languages. If you want a more featureful package, go for it. 154 | 155 | ### [`lispyville`](https://github.com/noctuid/lispyville) 156 | 157 | `lispyville` is a layer on top of `lispy` that adapts some `evil` commands for working consistently with `lispy`. 158 | Personally, I never felt the need for `lispyville` when using `evil`: using vim commands while in normal mode and `lispy` commands in insert mode worked fine for me. 159 | I found `lispyville` quite difficult to grasp, and I simply got used to the raw `lispy` commands, avoiding this extra indirection for `lispy` commands. 160 | 161 | That said, it's clear that `lispyville` is useful for lots of people., so would be great if it worked with `vilpy`. 162 | I believe this should not be too difficult: maybe simply forking it and renaming `lispy` to `vilpy` and fixing some renamed functions will do it. 163 | Another simpler possibility is aliasing `vilpy` functions to their `lispy` counterparts. 164 | However, I do not have the motivation for experimenting with this now. 165 | -------------------------------------------------------------------------------- /docs/reference.md: -------------------------------------------------------------------------------- 1 | ## Function reference (work in progress) 2 | 3 | ### Special mode 4 | `vilpy` commands operate when special mode is active. 5 | 6 | If you know `vi`, think of special mode as `vilpy`'s normal mode. 7 | 8 |
9 | Special-mode is activated when: 10 | 11 | - the point is before an open paren: `(`, `[` or `{` 12 | - the point is after a close paren: `)`, `]` or `}` 13 | - the region is active 14 | 15 | In the examples below, consider that the point is represented by `|`. 16 | 17 | As the point is just before the parenthesis, keys will invoke `vilpy` commands. 18 | If you press `A`, for example, it will call `vilpy-insert-at-end-of-sexp`. 19 | 20 | ``` 21 | |(foo) 22 | ``` 23 | 24 | After A: 25 | 26 | ``` 27 | (foo|) 28 | ``` 29 | 30 | However, if the point is not at a position that activates special-mode, pressing `A` will self-insert the letter `A`, as usual. 31 | 32 | ``` 33 | (|foo) 34 | ``` 35 | 36 | After A: 37 | ``` 38 | (A|foo) 39 | ``` 40 |
41 | 42 | #### Getting in special mode 43 | | command | binding | 44 | |-----------------|--------------------| 45 | | `vilpy-special` | backtab | 46 | 47 | Note that backtab is shift and tab. 48 | 49 |
50 | 51 | **If not in special mode** 52 | 53 | Move the point to the nearest leftmost paren. 54 | 55 | Starting with: 56 | 57 | ``` 58 | (foo |bar) 59 | ``` 60 | 61 | after backtab: 62 | 63 | ``` 64 | |(foo bar) 65 | ``` 66 | 67 | **If already in special mode** 68 | 69 | Cycle through parens. 70 | 71 | Starting with: 72 | 73 | ``` 74 | |(foo bar) 75 | ``` 76 | 77 | after backtab: 78 | 79 | ``` 80 | (foo bar)| 81 | ``` 82 | 83 | after backtab: 84 | 85 | ``` 86 | |(foo bar) 87 | ``` 88 | 89 |
90 | 91 | #### Getting out of special mode 92 | 93 | | command | binding | 94 | |-------------------------------|----------------| 95 | | `forward-char` | a | 96 | | `vilpy-insert-at-end-of-sexp` | A | 97 | | `vilpy-open-line-below` | o | 98 | | `vilpy-open-line-above` | O | 99 | | `backward-char` | C-b | 100 | | `forward-char` | C-f | 101 | 102 |
103 | 104 | ##### `forward-char` (a) 105 | Starting with 106 | 107 | ``` 108 | |(foo) 109 | ``` 110 | 111 | after a: 112 | 113 | ``` 114 | (|foo) 115 | ``` 116 | 117 | ##### `vilpy-insert-at-end-of-sexp` (A) 118 | Starting with 119 | 120 | ``` 121 | |(foo bar) 122 | ``` 123 | 124 | after A: 125 | ``` 126 | (foo bar|) 127 | ``` 128 | 129 | ##### `vilpy-open-line-below` (o) 130 | Starting with 131 | 132 | ``` 133 | |(foo) 134 | ``` 135 | 136 | after o: 137 | ``` 138 | (foo) 139 | | 140 | ``` 141 | 142 | ##### `vilpy-open-line-above` (O) 143 | Starting with 144 | 145 | ``` 146 | |(foo) 147 | ``` 148 | 149 | after O: 150 | ``` 151 | | 152 | (foo) 153 | ``` 154 | 155 |
156 | 157 | ### Navigation 158 | | command | binding | 159 | |----------------------------|---------------| 160 | | `vilpy-step-out` | h | 161 | | `vilpy-step-in` | l | 162 | | `vilpy-down` | j | 163 | | `vilpy-up` | k | 164 | | `vilpy-knight-down` | S | 165 | | `vilpy-knight-up` | W | 166 | | `vilpy-beginning-of-defun` | I | 167 | | `vilpy-back` | b | 168 | | `vilpy-right` | L | 169 | | `vilpy-go-to-first-defun` | gg | 170 | | `vilpy-go-to-last-defun` | G | 171 | 172 |
173 | 174 | #### `vilpy-step-out` (h) 175 | 176 | Starting with 177 | 178 | ``` 179 | (foo (bar |(baz)) 180 | ``` 181 | 182 | after h: 183 | 184 | ``` 185 | (foo |(bar (baz)) 186 | ``` 187 | 188 | after h: 189 | 190 | ``` 191 | |(foo (bar (baz)) 192 | ``` 193 | 194 | #### `vilpy-step-in` (l) 195 | 196 | Starting with 197 | 198 | ``` 199 | |(foo (bar (baz)) 200 | ``` 201 | 202 | after l: 203 | 204 | ``` 205 | (foo |(bar (baz)) 206 | ``` 207 | 208 | after l: 209 | 210 | ``` 211 | (foo (bar |(baz)) 212 | ``` 213 | 214 | #### `vilpy-down` (j) 215 | 216 | Starting with: 217 | 218 | ``` 219 | |(foo) 220 | (bar) 221 | ``` 222 | 223 | after j: 224 | 225 | ``` 226 | (foo) 227 | |(bar) 228 | ``` 229 | 230 | #### `vilpy-up` (k) 231 | 232 | Starting with: 233 | 234 | ``` 235 | (foo) 236 | |(bar) 237 | ``` 238 | 239 | after k: 240 | 241 | ``` 242 | |(foo) 243 | (bar) 244 | ``` 245 | 246 | #### `vilpy-knight-down` (S) 247 | Navigate to the next line disregarding syntax. 248 | 249 | Starting with: 250 | 251 | ``` 252 | |(foo (bar) 253 | (xum)) 254 | ``` 255 | 256 | after S: 257 | 258 | ``` 259 | (foo (bar) 260 | |(xum)) 261 | ``` 262 | 263 | #### `vilpy-knight-up` (W) 264 | Navigate to the previous line disregarding syntax. 265 | 266 | Starting with: 267 | 268 | ``` 269 | (foo (bar) 270 | |(xum)) 271 | ``` 272 | 273 | after W: 274 | 275 | ``` 276 | |(foo (bar) 277 | (xum)) 278 | ``` 279 | #### `vilpy-beginning-of-defun` (I) 280 | 281 | Starting with this top level form: 282 | 283 | ``` 284 | (defun abc () 285 | (interactive) 286 | |(foo)) 287 | ``` 288 | 289 | after Ias 290 | 291 | ``` 292 | |(defun abc () 293 | (interactive) 294 | (foo)) 295 | ``` 296 | 297 | #### `vilpy-back` (b) 298 | Moves the point to the previous position in `vilpy-back` history. The following functions write to this history: 299 | function name 300 | 301 | | command | binding | 302 | |-------------------|--------------| 303 | | `vilpy-step-out` | h | 304 | | `vilpy-step-in` | l | 305 | | `vilpy-down` | j | 306 | | `vilpy-up` | k | 307 | | `vilpy-right` | L | 308 | | `vilpy-mark-list` | v | 309 | | `vilpy-ace-paren` | q | 310 | 311 | #### `vilpy-right` (L) 312 | 313 | Moves forward out of arg (default 1) levels of parentheses. 314 | 315 | Works as replacement for the standard `up-list`. 316 | 317 | Takes a numeric prefix arg and moves up forward list arg times or until error. 318 | 319 | Unlike up-list, no error will be reported if it's not possible to move up arg times. It that case, move as many times as possible. 320 | 321 | Return point if could move arg times, otherwise return nil. 322 | 323 | Unlike up-list, parens in strings and comments are ignored. 324 | 325 | #### `vilpy-go-to-first-defun` (gg) 326 | Starting with 327 | 328 | ``` 329 | (a) 330 | (b |(c)) 331 | ``` 332 | 333 | after gg: 334 | 335 | ``` 336 | |(a) 337 | (b (c)) 338 | ``` 339 | 340 | #### `vilpy-go-to-last-defun` (G) 341 | Starting with 342 | 343 | ``` 344 | (a |(b)) 345 | (c) 346 | ``` 347 | 348 | after G: 349 | 350 | ``` 351 | (a (b)) 352 | |(c) 353 | ``` 354 | 355 |
356 | 357 | ### Code actions 358 | | command | binding | 359 | |---------------------|--------------| 360 | | `vilpy-eval` | e | 361 | | `vilpy-eval-defun` | D | 362 | | `vilpy-eval-buffer` | B | 363 | | `vilpy-tab` | = | 364 | | `vilpy-describe` | K | 365 | 366 |
367 | 368 | #### `vilpy-eval` (e) 369 | Eval current region or sexp. 370 | 371 | Emacs Lisp and Clojure (`cider` and `inf-clojure`) are supported. 372 | 373 | The evaluation function is defined in `vilpy--handlers-alist`. 374 | 375 | #### `vilpy-eval-defun` (D) 376 | Eval top level form. 377 | 378 | Emacs Lisp and Clojure (`cider` and `inf-clojure`) are supported. 379 | 380 | The evaluation function is defined in `vilpy--handlers-alist`. 381 | 382 | #### `vilpy-eval-buffer` (B) 383 | Eval buffer. 384 | 385 | Emacs Lisp and Clojure (`cider` and `inf-clojure`) are supported. 386 | 387 | The evaluation function is defined in `vilpy--handlers-alist`. 388 | 389 | #### `vilpy-tab` (=) 390 | If before left paren or after right paren, indent the current sexp. 391 | 392 | Emacs Lisp and Clojure (`cider` and `inf-clojure`) are supported. 393 | 394 | The indentation function is defined in `vilpy--handlers-alist`. 395 | 396 | #### `vilpy-describe` (K) 397 | Describe the symbol at point. 398 | 399 | Emacs Lisp and Clojure (`cider` and `inf-clojure`) are supported. 400 | 401 | The function for describing the symbol is defined in `vilpy--handlers-alist`. 402 | 403 |
404 | 405 | ### Transformation 406 | 407 | | command | binding | 408 | |--------------------------------|--------------| 409 | | `vilpy-raise` | r | 410 | | `vilpy-raise-some` | R | 411 | | `vilpy-move-up` | p | 412 | | `vilpy-move-down` | n | 413 | | `vilpy-slurp` | > | 414 | | `vilpy-barf` | < | 415 | | `vilpy-move-and-slurp-actions` | / | 416 | | `vilpy-splice` | x | 417 | | `vilpy-join` | + | 418 | | `vilpy-convolute` | C | 419 | | `vilpy-oneline` | J | 420 | | `vilpy-alt-multiline` | M | 421 | | `vilpy-teleport` | t | 422 | 423 |
424 | 425 | #### `vilpy-raise` (r) 426 | Starting with 427 | 428 | ``` 429 | (foo |(bar)) 430 | ``` 431 | 432 | after r: 433 | 434 | ``` 435 | (bar) 436 | ``` 437 | #### `vilpy-raise-some` (R) 438 | 439 | Starting with: 440 | 441 | ``` 442 | (foo 443 | |(bar) 444 | (xum)) 445 | ``` 446 | 447 | after R: 448 | 449 | ``` 450 | (bar) 451 | (xum) 452 | ``` 453 | 454 | #### `vilpy-move-up` (p) 455 | 456 | Starting with: 457 | 458 | ``` 459 | (foo) 460 | |(bar) 461 | ``` 462 | 463 | after p: 464 | 465 | ``` 466 | |(bar) 467 | (foo) 468 | ``` 469 | 470 | #### `vilpy-move-down`(n) 471 | 472 | Starting with: 473 | 474 | ``` 475 | |(foo) 476 | (bar) 477 | ``` 478 | 479 | after n: 480 | 481 | ``` 482 | (bar) 483 | |(foo) 484 | ``` 485 | 486 | #### `vilpy-splice`(x) 487 | 488 | Starting with: 489 | 490 | ``` 491 | (foo |(bar)) 492 | ``` 493 | 494 | after x: 495 | 496 | ``` 497 | (foo bar) 498 | ``` 499 | 500 | #### `vilpy-join`(+) 501 | 502 | Starting with: 503 | 504 | ``` 505 | (foo) 506 | |(bar) 507 | ``` 508 | 509 | after +: 510 | 511 | ``` 512 | |(foo 513 | bar) 514 | ``` 515 | 516 | #### `vilpy-convolute`(C) 517 | 518 | Starting with: 519 | 520 | ``` 521 | (foo 522 | (bar 523 | |(xum))) 524 | ``` 525 | 526 | after C: 527 | 528 | ``` 529 | (bar 530 | (foo 531 | (xum))) 532 | ``` 533 | 534 | after C: 535 | 536 | 537 | ``` 538 | (foo 539 | (bar 540 | |(xum))) 541 | ``` 542 | 543 | #### `vilpy-oneline`(J) 544 | 545 | Starting with: 546 | 547 | ``` 548 | |(foo 549 | (bar 550 | (xum))) 551 | ``` 552 | 553 | after J: 554 | 555 | ``` 556 | (foo (bar (xum))) 557 | ``` 558 | 559 | #### `vilpy-split` (M-j) 560 | #### `vilpy-join` (M-J) 561 | 562 |
563 | 564 | ### Barfage & Slurpage 565 | 566 | | command | binding | 567 | |--------------------|---------------| 568 | | `vilpy-slurp` | > | 569 | | `vilpy-barf` | < | 570 | | `vilpy-move-left` | sh | 571 | | `vilpy-move-right` | sl | 572 | | `vilpy-down-slurp` | sj | 573 | | `vilpy-up-slurp` | sk | 574 | 575 |
576 | 577 | #### `vilpy-slurp`(>) 578 | 579 | Starting with: 580 | 581 | ``` 582 | (foo)| (bar) (xum) 583 | ``` 584 | 585 | after >: 586 | 587 | ``` 588 | (foo (bar))| (xum) 589 | ``` 590 | 591 | after >: 592 | 593 | ``` 594 | (foo (bar) (xum)) 595 | ``` 596 | 597 | #### `vilpy-barf` (<) 598 | 599 | Starting with: 600 | 601 | ``` 602 | (foo) (bar) |(xum) 603 | ``` 604 | 605 | after <: 606 | 607 | ``` 608 | (foo) |((bar) xum) 609 | ``` 610 | 611 | after <: 612 | 613 | ``` 614 | |((foo) (bar) xum) 615 | ``` 616 | 617 | 618 | #### `vilpy-move-left` (sh) 619 | 620 | Move current expression to the left, outside the current list. 621 | 622 | ``` 623 | (require 'ob-python) 624 | (let ((color "Blue")) 625 | |(message "What... is your favorite color?") 626 | (message "%s. No yel..." color)) 627 | ``` 628 | 629 | after /h: 630 | 631 | ``` 632 | (require 'ob-python) 633 | |(message "What... is your favorite color?") 634 | (let ((color "Blue")) 635 | (message "%s. No yel..." color)) 636 | ``` 637 | 638 | #### `vilpy-move-right` (sl) 639 | 640 | Move current expression to the right, outside the current list. 641 | 642 | ``` 643 | (require 'ob-python) 644 | (message "What... is your favorite color?") 645 | (let ((color "Blue")) 646 | (message color) 647 | |(message "Go on. Off you go.")) 648 | ``` 649 | 650 | after /l: 651 | 652 | ``` 653 | (require 'ob-python) 654 | (message "What... is your favorite color?") 655 | (let ((color "Blue")) 656 | (message color)) 657 | |(message "Go on. Off you go.") 658 | ``` 659 | 660 | #### `vilpy-down-slurp` (sj) 661 | Move current expression to become the first element of the first list below. 662 | 663 | ``` 664 | (list 'my-sword 665 | 'my-bow) 666 | |(my-axe) 667 | ``` 668 | 669 | after /j: 670 | 671 | ``` 672 | '(|(first!) 673 | foo bar) 674 | ``` 675 | 676 |
677 | 678 | ### Acing 679 | | command | binding | 680 | |---------------------------------------|--------------| 681 | | `vilpy-ace-symbol` | f | 682 | | `vilpy-ace-subword` | - | 683 | | `vilpy-ace-symbol-beginning-of-defun` | F | 684 | | `vilpy-ace-paren` | q | 685 | | `vilpy-ace-char` | Q | 686 | 687 |
688 | 689 | #### `vilpy-ace-symbol` (f) 690 | Marks symbol in the current form. 691 | This can be followed up with eval, raise, deletion etc. 692 | For unmarking the symbol afterwards, as usual, press C-g. 693 | 694 | Starting with: 695 | 696 | ``` 697 | (foo bar baz) 698 | ``` 699 | 700 | After f, each symbol will be annotated with a character: 701 | 702 | ``` 703 | (afoo bbar cbaz) 704 | ``` 705 | 706 | In this example, say you press `c`. Then, the cursor will jump to `baz` and it will be marked. 707 | 708 | #### `vilpy-ace-subword` (-) 709 | 710 | Marks subword. 711 | 712 | Starting with: 713 | 714 | ``` 715 | (foo-bar-baz) 716 | ``` 717 | 718 | After -: 719 | 720 | ``` 721 | (afoo-bbaz-cbaz) 722 | ``` 723 | 724 | In this example, use `a`, `b` or `c` for jumping and marking a subword. 725 | 726 | #### `vilpy-ace-symbol-beginning-of-defun` (F) 727 | 728 | Same as `vilpy-ace-symbol`, but the range of acing is the current defun rather than the current form. 729 | 730 | #### `vilpy-ace-paren` (q) 731 | 732 | Marks form. 733 | 734 | Starting with: 735 | 736 | ``` 737 | (a (b) (c) d) 738 | ``` 739 | 740 | After q: 741 | 742 | ``` 743 | a((bb) (cc) d) 744 | ``` 745 | 746 | In this example, use `a`, `b` or `c` for jumping and marking a form. 747 | 748 | #### `vilpy-ace-char` (Q) 749 | 750 | Asks for a char and jumps to it in the current form. 751 | 752 | 753 | 754 |
755 | 756 | ### Deleting & killing 757 | | command | binding | 758 | |-------------------------|------------------| 759 | | `vilpy-delete` | C-d | 760 | | `vilpy-kill` | C-k | 761 | | `vilpy-kill-word` | M-DEL | 762 | | `vilpy-delete-backward` | DEL | 763 | 764 |
765 | 766 | #### `vilpy-delete` (C-d) 767 | 768 | Deletes region, form or string, depending on the position of the point. Accepts numerical argument. 769 | 770 | For the complete list of behaviours, please refer to the `lispy` [documentation](http://oremacs.com/lispy/#lispy-delete). 771 | 772 | **Example 1: In region** 773 | 774 | Starting with (`~` denotes a marked region): 775 | 776 | ``` 777 | (~foo~) 778 | ``` 779 | 780 | After C-d: 781 | 782 | ``` 783 | () 784 | ``` 785 | 786 | **Example 2: Before form** 787 | 788 | Starting with 789 | 790 | ``` 791 | |(foo) (bar) 792 | ``` 793 | 794 | after C-d: 795 | 796 | ``` 797 | |(bar) 798 | ``` 799 | 800 | #### `vilpy-kill` (C-k) 801 | 802 | Similar to `kill-line`, but keeps parens balanced. 803 | 804 | **Example 1: Before form** 805 | 806 | Starting with: 807 | 808 | ``` 809 | (foo |(bar) (baz)) 810 | ``` 811 | 812 | after C-k: 813 | 814 | ``` 815 | (foo ) 816 | ``` 817 | 818 | **Example 2: In string** 819 | 820 | Starting with: 821 | 822 | ``` 823 | "foo |bar" 824 | ``` 825 | 826 | after C-k: 827 | 828 | ``` 829 | "foo " 830 | ``` 831 | 832 | #### `vilpy-kill-word` (M-DEL) 833 | 834 | Kill words. Accepts numerical argument. 835 | 836 | Starting with: 837 | 838 | ``` 839 | |(foo bar) 840 | ``` 841 | 842 | After M-DEL: 843 | 844 | ``` 845 | (| bar) 846 | ``` 847 | 848 | After M-DEL: 849 | 850 | ``` 851 | (|) 852 | ``` 853 | 854 | #### `vilpy-delete-backward` (DEL) 855 | 856 | Bound to DEL. 857 | 858 | Replaces `backward-delete-char`, keeping parens balanced. 859 | 860 | The result depends on the following conditions, each tried one by one until one that holds true is found: 861 | 862 | **Active region** 863 | 864 | Delete region. 865 | 866 | **At first char of the string** 867 | 868 | Move to the end of the string. This allows to delete the whole string with the next DEL. 869 | 870 | ``` 871 | (message "|more gold is required") 872 | ``` 873 | 874 | after DEL: 875 | 876 | ``` 877 | (message "more gold is required"|) 878 | ``` 879 | 880 | **In string near `\\(` or `\\)`** 881 | 882 | Remove `\\(` and `\\)`. 883 | 884 | Starting with: 885 | ``` 886 | (looking-at "\\([a-z]+\\)|") 887 | ``` 888 | 889 | After DEL: 890 | 891 | ``` 892 | (looking-at "[a-z]+") 893 | 894 | ``` 895 | 896 | Starting with: 897 | 898 | ``` 899 | (looking-at "\\(|[a-z]+\\)") 900 | ``` 901 | 902 | after DEL: 903 | 904 | ``` 905 | (looking-at "|[a-z]+") 906 | ``` 907 | 908 | **In string or comment** 909 | 910 | Call `backward-delete-char`. 911 | 912 | **After right paren** 913 | 914 | Delete arg sexps. 915 | 916 | Starting with: 917 | 918 | ``` 919 | (foo (bar) (baz)|) 920 | ``` 921 | 922 | after 2 DEL: 923 | 924 | ``` 925 | (foo) 926 | ``` 927 | 928 | **After left paren** 929 | 930 | Delete containing sexp. 931 | 932 | ``` 933 | (foo (|bar) (baz)) 934 | ``` 935 | 936 | After DEL: 937 | 938 | ``` 939 | (foo| (bar)) 940 | ``` 941 | 942 | **After a string** 943 | 944 | Delete string. 945 | 946 | ``` 947 | (message "more gold is required"|) 948 | ``` 949 | 950 | After DEL: 951 | 952 | ``` 953 | (message |) 954 | ``` 955 | 956 | **Otherwise** 957 | 958 | Call `backward-delete-char`. 959 | 960 |
961 | 962 | ### Copying & yanking 963 | 964 | | command | binding | 965 | |---------------|--------------| 966 | | `vilpy-copy` | y | 967 | | `vilpy-clone` | w | 968 | | `vilpy-paste` | P | 969 | 970 |
971 | 972 | #### `vilpy-copy`(y) 973 | 974 | Copy the current sexp or region to kill ring. 975 | 976 | #### `vilpy-clone` (w) 977 | 978 | Copy current sexp or region and paste it below. 979 | With a numerical argument, copy that many times. 980 | 981 | Starting with: 982 | 983 | ``` 984 | |(foo) 985 | ``` 986 | 987 | after w: 988 | 989 | ``` 990 | |(foo) 991 | (foo) 992 | ``` 993 | 994 | #### `vilpy-paste` (P) 995 | 996 | When region is active, replace it with current kill. Otherwise, forward to yank. 997 | 998 |
999 | 1000 | ### Marking 1001 | | command | binding | 1002 | |---------------------|------------------| 1003 | | `vilpy-mark-list` | m | 1004 | | `vilpy-mark-symbol` | M-m | 1005 | | `vilpy-mark` | C-M-, | 1006 | 1007 |
1008 | 1009 | #### `vilpy-mark-list` (m) 1010 | 1011 | Mark the current sexp. When the mark is already active, deactivate it instead. 1012 | 1013 | #### `vilpy-mark-symbol` (M-m) 1014 | 1015 | Marks the symbol at point, comment or symbol in the next or previous list. 1016 | 1017 | **Point is under symbol** 1018 | 1019 | Mark the symbol. 1020 | 1021 | **In comment** 1022 | 1023 | Mark the comment. 1024 | 1025 | **In special mode, before paren** 1026 | 1027 | Marks the next symbol. 1028 | 1029 | **In special mode, after paren** 1030 | 1031 | Marks the previous symbol. 1032 | 1033 | **Region is active** 1034 | 1035 | Call `forward-sexp`. 1036 | 1037 | **Otherwise** 1038 | 1039 | Forward to `lispy-mark`. 1040 | 1041 | #### `vilpy-mark` (C-M-,) 1042 | 1043 | Mark the smallest comment, string or sexp that includes point. 1044 | 1045 |
1046 | 1047 | ### Misc 1048 | | command | binding | 1049 | |-------------------------------|----------------| 1050 | | `vilpy-comment` | ; | 1051 | | `vilpy-space` | SPC | 1052 | | `vilpy-narrow` | gn | 1053 | | `vilpy-widen` | gw | 1054 | | `vilpy-undo` | u | 1055 | | `vilpy-scroll-line-to-top` | zt | 1056 | | `vilpy-scroll-line-to-center` | zz | 1057 | | `vilpy-scroll-line-to-bottom` | zb | 1058 | | `vilpy-repeat` | . | 1059 | 1060 | ### Magic 1061 | | command | binding | 1062 | |------------------|--------------| 1063 | | `vilpy-teleport` | t | 1064 | 1065 |
1066 | 1067 | #### `vilpy-teleport`(t) 1068 | 1069 |
1070 | 1071 | -------------------------------------------------------------------------------- /vilpy-test.el: -------------------------------------------------------------------------------- 1 | (when (require 'undercover nil t) 2 | (undercover "vilpy.el" "vilpy-inline.el")) 3 | (require 'vilpy nil t) 4 | (require 'clojure-mode nil t) 5 | (if (version< emacs-version "24.4.1") 6 | (load-library "cl-indent") 7 | (require 'cl-indent)) 8 | (custom-set-variables 9 | '(indent-tabs-mode nil)) 10 | (setq lisp-indent-function 'common-lisp-indent-function) 11 | (put 'if 'common-lisp-indent-function 2) 12 | (transient-mark-mode 1) 13 | 14 | ;;* Infrastructure 15 | (defmacro vilpy-with (in &rest body) 16 | (let ((mode 'emacs-lisp-mode) 17 | (mark-str "~")) 18 | (when (symbolp in) 19 | (setq mode 20 | (intern 21 | (concat (symbol-name in) "-mode"))) 22 | (setq in (car body)) 23 | (setq body (cdr body)) 24 | (when (eq mode 'clojure-mode) 25 | (setq mark-str "&"))) 26 | `(let ((temp-buffer (generate-new-buffer " *temp*"))) 27 | (save-window-excursion 28 | (unwind-protect 29 | (progn 30 | (switch-to-buffer temp-buffer) 31 | (,mode) 32 | (transient-mark-mode 1) 33 | (vilpy-mode) 34 | (insert ,in) 35 | (goto-char (point-min)) 36 | (when (search-forward ,mark-str nil t) 37 | (backward-delete-char 1) 38 | (set-mark (point))) 39 | (goto-char (point-max)) 40 | (search-backward "|") 41 | (delete-char 1) 42 | (setq current-prefix-arg nil) 43 | ,@(mapcar (lambda (x) 44 | (cond ((equal x '(kbd "C-u")) 45 | `(setq current-prefix-arg (list 4))) 46 | ((or (stringp x) 47 | (and (listp x) 48 | (eq (car x) 'kbd))) 49 | `(vilpy-unalias ,x)) 50 | (t x))) body) 51 | (insert "|") 52 | (when (region-active-p) 53 | (exchange-point-and-mark) 54 | (insert ,mark-str)) 55 | (buffer-substring-no-properties 56 | (point-min) 57 | (point-max))) 58 | (and (buffer-name temp-buffer) 59 | (kill-buffer temp-buffer)) 60 | (setq last-command nil)))))) 61 | 62 | (defmacro vilpy-with-v (mode-ext in &rest body) 63 | (declare (indent 2)) 64 | (let ((mode (cdr (assoc mode-ext '((py . python-mode) 65 | (el . emacs-lisp-mode) 66 | (scm . scheme-mode) 67 | (clj . clojure-mode)))))) 68 | `(with-temp-buffer 69 | (,mode) 70 | (vilpy-mode) 71 | (insert ,in) 72 | (when (search-backward "~" nil t) 73 | (delete-char 1) 74 | (set-mark (point)) 75 | (goto-char (point-max))) 76 | (search-backward "|") 77 | (delete-char 1) 78 | ,@(mapcar (lambda (x) (if (stringp x) `(vilpy-unalias ,x) x)) body)))) 79 | 80 | (defun vilpy-decode-keysequence (str) 81 | "Decode STR from e.g. \"23ab5c\" to '(23 \"a\" \"b\" 5 \"c\")" 82 | (let ((table (copy-sequence (syntax-table)))) 83 | (cl-loop for i from ?0 to ?9 do 84 | (modify-syntax-entry i "." table)) 85 | (cl-loop for i from ? to ? do 86 | (modify-syntax-entry i "w" table)) 87 | (cl-loop for i in '(? ?\( ?\) ?\[ ?\] ?{ ?} ?\" ?\' ?\ ) 88 | do (modify-syntax-entry i "w" table)) 89 | (cl-mapcan (lambda (x) 90 | (let ((y (ignore-errors (read x)))) 91 | (if (numberp y) 92 | (list y) 93 | (mapcar #'string x)))) 94 | (with-syntax-table table 95 | (split-string str "\\b" t))))) 96 | 97 | (ert-deftest vilpy-decode-keysequence () 98 | (should (equal (vilpy-decode-keysequence "23ab50c") 99 | '(23 "a" "b" 50 "c"))) 100 | (should (equal (vilpy-decode-keysequence "3\C-d") 101 | '(3 ""))) 102 | (should (equal (vilpy-decode-keysequence "3\C-?") 103 | '(3 "")))) 104 | 105 | (defun vilpy-unalias (seq) 106 | "Emulate pressing keys decoded from SEQ." 107 | (if (vectorp seq) 108 | (vilpy--unalias-key seq) 109 | (let ((lkeys (vilpy-decode-keysequence seq)) 110 | key) 111 | (while (setq key (pop lkeys)) 112 | (if (numberp key) 113 | (let ((current-prefix-arg (list key))) 114 | (when lkeys 115 | (vilpy--unalias-key (pop lkeys)))) 116 | (vilpy--unalias-key key)))))) 117 | 118 | (defun vilpy--unalias-key (key) 119 | "Call command that corresponds to KEY. 120 | Insert KEY if there's no command." 121 | (let ((cmd (cdr (or (assoc 'vilpy-mode (minor-mode-key-binding key)) 122 | (assoc 'vilpy-other-mode (minor-mode-key-binding key)))))) 123 | (if (or (and cmd (or (looking-at vilpy-left) 124 | (vilpy-looking-back vilpy-right) 125 | (looking-at vilpy-outline) 126 | (looking-at ";;") 127 | (region-active-p) 128 | (and (bolp) (looking-at ";")))) 129 | (progn 130 | (setq cmd (key-binding key)) 131 | (not (cond ((eq cmd 'self-insert-command)) 132 | ((string-match "^special" (symbol-name cmd))))))) 133 | (progn 134 | (setq last-command-event (aref key 0)) 135 | (call-interactively cmd) 136 | (setq last-command cmd)) 137 | (insert key)))) 138 | 139 | ;;* Tests 140 | (ert-deftest vilpy-forward () 141 | (should (string= (vilpy-with "(|(a) (b) (c))" (vilpy-forward 1)) 142 | "((a)| (b) (c))")) 143 | (should (string= (vilpy-with "((|a) (b) (c))" (vilpy-forward 1)) 144 | "((a)| (b) (c))")) 145 | (should (string= (vilpy-with "((a) |(b) (c))" (vilpy-forward 1)) 146 | "((a) (b)| (c))")) 147 | (should (string= (vilpy-with "(|(a) (b) (c))" (progn (vilpy-forward 1) 148 | (vilpy-forward 1))) 149 | "((a) (b)| (c))")) 150 | (should (string= (vilpy-with "(|(a) (b) (c))" (vilpy-forward 3)) 151 | "((a) (b) (c)|)")) 152 | (should (string= (vilpy-with "(|(a) (b) (c))" (progn (vilpy-forward 1) 153 | (vilpy-forward 1) 154 | (vilpy-forward 1) 155 | (vilpy-forward 1))) 156 | "((a) (b) (c))|")) 157 | (should (string= (vilpy-with "(|(a) (b) (c))" (vilpy-forward 4)) 158 | "((a) (b) (c)|)")) 159 | (should (string= (vilpy-with "(|(a) (b) (c))" (vilpy-forward 40)) 160 | "((a) (b) (c)|)")) 161 | (should (string= (vilpy-with "(|(a) (b) (c))" 162 | (set-mark (point)) 163 | (vilpy-forward 1) 164 | (call-interactively 'kill-region)) 165 | "(~| (b) (c))")) 166 | (should (string= (vilpy-with "(|(a) (b) (c))" 167 | (set-mark (point)) 168 | (vilpy-forward 2) 169 | (call-interactively 'kill-region)) 170 | "(~| (c))")) 171 | (should (vilpy-with-v el "(|(a) (b) (c))" 172 | (set-mark (point)) 173 | (progn (vilpy-forward 1) 174 | (vilpy-forward 1) 175 | (vilpy-forward 1)) 176 | (region-active-p))) 177 | (should (not (vilpy-with-v el "(a) (b) (c)| " (vilpy-forward 1)))) 178 | (should (not (vilpy-with-v el "(a) (b) (c)|" (vilpy-forward 1)))) 179 | ;; break active region when exiting list 180 | (should (not (vilpy-with-v el "(|(a) (b) (c))" 181 | (set-mark (point)) 182 | (progn (vilpy-forward 1) 183 | (vilpy-forward 1) 184 | (vilpy-forward 1) 185 | (vilpy-forward 1)) 186 | (and mark-active (not deactivate-mark))))) 187 | (should (vilpy-with-v el "(a)| (b)\n" (vilpy-forward 2)))) 188 | 189 | (ert-deftest vilpy-backward () 190 | (should (string= (vilpy-with "(|(a) (b) (c))" (vilpy-backward 1)) 191 | "|((a) (b) (c))")) 192 | (should (string= (vilpy-with "((a)|)" (vilpy-backward 1)) 193 | "(|(a))")) 194 | (should (string= (vilpy-with "((|a) (b) (c))" (vilpy-backward 1)) 195 | "(|(a) (b) (c))")) 196 | (should (string= (vilpy-with "((a) |(b) (c))" (vilpy-backward 1)) 197 | "(|(a) (b) (c))")) 198 | (should (string= (vilpy-with "(|(a) (b) (c))" (progn (vilpy-backward 1) 199 | (vilpy-backward 1))) 200 | "|((a) (b) (c))")) 201 | (should (string= (vilpy-with "(|(a) (b) (c))" (vilpy-backward 3)) 202 | "|((a) (b) (c))")) 203 | (should (string= (vilpy-with "((a) (b) (c)|)" (vilpy-backward 1)) 204 | "((a) (b) |(c))")) 205 | (should (string= (vilpy-with "((a) (b) (c)|)" (vilpy-backward 4)) 206 | "(|(a) (b) (c))")) 207 | (should (string= (vilpy-with "((a) (b) (c)|)" (vilpy-backward 40)) 208 | "(|(a) (b) (c))")) 209 | (should (string= (vilpy-with "((b)|\"foo\")" (vilpy-backward 1)) 210 | "(|(b)\"foo\")")) 211 | (should (string= (vilpy-with "(bar)\n;; (foo baar)|" (vilpy-backward 1)) 212 | "|(bar)\n;; (foo baar)")) 213 | (should (string= (vilpy-with "(foo)\n;; (foo bar\n;; tanf)|" (vilpy-backward 1)) 214 | "|(foo)\n;; (foo bar\n;; tanf)"))) 215 | 216 | (ert-deftest vilpy-right () 217 | (should (string= (vilpy-with "(|(a) (b) (c))" (vilpy-right 1)) 218 | "((a) (b) (c))|")) 219 | (should (string= (vilpy-with "(|(a) (b) (c))" (vilpy-right 2)) 220 | "((a) (b) (c))|")) 221 | (should (string= (vilpy-with "(|(a) (b) (c))" (vilpy-right 1)) 222 | "((a) (b) (c))|")) 223 | (should (string= (vilpy-with "(|(a) (b) (c))" 224 | (vilpy-right 1) 225 | (vilpy-right 1)) 226 | "((a) (b) (c))|")) 227 | (should (string= (vilpy-with "((|a) (b) (c))" (vilpy-right 1)) 228 | "((a)| (b) (c))")) 229 | (should (string= (vilpy-with "((|a) (b) (c))" 230 | (vilpy-right 1) 231 | (vilpy-right 1)) 232 | "((a) (b) (c))|")) 233 | (should (string= (vilpy-with "((|a) (b) (c))" (vilpy-right 2)) 234 | "((a) (b) (c))|")) 235 | (should (string= (vilpy-with "((a) \"(|foo)\" (c))" (vilpy-right 2)) 236 | "((a) \"(foo)\" (c))|")) 237 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something)|)))" (vilpy-right 1)) 238 | "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something))|))")) 239 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something)|)))" (vilpy-right 2)) 240 | "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something)))|)")) 241 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something)|)))" (vilpy-right 3)) 242 | "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something))))|")) 243 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something)|)))" (vilpy-right 9)) 244 | 245 | "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something))))|")) 246 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n |(something))))" (vilpy-right 1)) 247 | "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something))|))")) 248 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n |(something))))" (vilpy-right 2)) 249 | "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something)))|)")) 250 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n |(something))))" (vilpy-right 3)) 251 | "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something))))|")) 252 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n |(something))))" (vilpy-right 9)) 253 | "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something))))|")) 254 | (should (string= (vilpy-with "|(foo)~" (vilpy-right 1)) 255 | "~(foo)|")) 256 | (should (string= (vilpy-with "~(foo)|" (vilpy-right 1)) 257 | "~(foo)|")) 258 | (should (string= (vilpy-with "(|asdf ?\\ )" 259 | (vilpy-right 1)) 260 | "(asdf ?\\ )|"))) 261 | 262 | (ert-deftest vilpy-move-right () 263 | (should (string= (vilpy-with "(defn |exclaim~ [exclamation]\n (str exclamation \"!\"))" (progn (vilpy-clone 1) 264 | (vilpy-move-right 1))) 265 | "(defn exclaim [exclamation]\n (str exclamation \"!\"))\n|exclaim~")) 266 | (should (string= (vilpy-with "(progn\n\n |(sexp1)\n (sexp2))" (vilpy-move-right 1)) 267 | "(progn\n\n (sexp2))\n|(sexp1)"))) 268 | 269 | (ert-deftest vilpy-move-left () 270 | (should (string= (vilpy-with "(progn\n |(sexp1)\n (sexp2))" (vilpy-move-left 1)) 271 | "|(sexp1)\n(progn\n (sexp2))"))) 272 | 273 | (ert-deftest vilpy-down-slurp () 274 | (should (string= (vilpy-with "(progn\n\n |(sexp1)\n (sexp2))" (vilpy-down-slurp)) 275 | "(progn\n\n (|(sexp1)\n sexp2))")) 276 | (should (string= (vilpy-with "|(fee) (fi) [fo]" (vilpy-down-slurp)) 277 | "(|(fee)\n fi) [fo]")) 278 | (should (string= (vilpy-with "(fee) |(fi) [fo]" (vilpy-down-slurp)) 279 | "(fee) [|(fi)\n fo]"))) 280 | 281 | (ert-deftest vilpy-step-out () 282 | (should (string= (vilpy-with "(|(a) (b) (c))" (vilpy-step-out 1)) 283 | "|((a) (b) (c))")) 284 | (should (string= (vilpy-with "(|(a) (b) (c))" (vilpy-step-out 2)) 285 | "|((a) (b) (c))")) 286 | (should (string= (vilpy-with "((a)| (b) (c))" (vilpy-step-out 1)) 287 | "|((a) (b) (c))")) 288 | (should (string= (vilpy-with "((a) (b)| (c))" (vilpy-step-out 1)) 289 | "|((a) (b) (c))")) 290 | (should (string= (vilpy-with "((a) |(b) (c))" (vilpy-step-out 1)) 291 | "|((a) (b) (c))")) 292 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something)|)))" (vilpy-step-out 1)) 293 | "(defun foo ()\n (let ((a 1))\n |(let ((b 2))\n (something))))")) 294 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something)|)))" (vilpy-step-out 2)) 295 | "(defun foo ()\n |(let ((a 1))\n (let ((b 2))\n (something))))")) 296 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something)|)))" (vilpy-step-out 3)) 297 | "|(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something))))")) 298 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something)|)))" (vilpy-step-out 9)) 299 | "|(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something))))")) 300 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n |(something))))" (vilpy-step-out 1)) 301 | "(defun foo ()\n (let ((a 1))\n |(let ((b 2))\n (something))))")) 302 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n |(something))))" (vilpy-step-out 2)) 303 | "(defun foo ()\n |(let ((a 1))\n (let ((b 2))\n (something))))")) 304 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n |(something))))" (vilpy-step-out 3)) 305 | "|(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something))))")) 306 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n |(something))))" (vilpy-step-out 9)) 307 | "|(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something))))")) 308 | (should (equal (vilpy-with-v el "|(foo)" (vilpy-backward 1)) nil)) 309 | (should (equal (vilpy-with "((foo \"(\"))\n((foo \")\"))\n\"un|expected\"" (vilpy-backward 1)) 310 | "((foo \"(\"))\n|((foo \")\"))\n\"unexpected\"")) 311 | (should (equal (vilpy-with "(defun charge! ()\n|(run-away))" (vilpy-step-out 1)) 312 | "|(defun charge! ()\n (run-away))")) 313 | (should (string= (vilpy-with "|(foo)~" (vilpy-step-out 1)) 314 | "|(foo)~")) 315 | (should (string= (vilpy-with "~(foo)|" (vilpy-step-out 1)) 316 | "|(foo)~"))) 317 | 318 | (ert-deftest vilpy-step-in () 319 | (should (string= (vilpy-with "(|(a) (b) (c))" (vilpy-step-in 1)) 320 | "((a) |(b) (c))")) 321 | (should (string= (vilpy-with "(|(a) (b) (c))" (vilpy-step-in 2)) 322 | "((a) (b) |(c))")) 323 | (should (string= (vilpy-with "((a)| (b) (c))" (vilpy-step-in 1)) 324 | "((a)| (b) (c))")) 325 | (should (string= (vilpy-with "((a) (b)| (c))" (vilpy-step-in 1)) 326 | "((a)| (b) (c))")) 327 | (should (string= (vilpy-with "((a) |(b) (c))" (vilpy-step-in 1)) 328 | "((a) (b) |(c))")) 329 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something)|)))" (vilpy-step-in 1)) 330 | "(defun foo ()\n (let ((a 1))\n (let ((b 2))|\n (something))))")) 331 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something)|)))" (vilpy-step-in 2)) 332 | "(defun foo ()\n (let ((a 1))\n (let ((b 2)|)\n (something))))")) 333 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something)|)))" (vilpy-step-in 3)) 334 | "(defun foo ()\n (let ((a 1))|\n (let ((b 2))\n (something))))")) 335 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n (something)|)))" (vilpy-step-in 9)) 336 | "(defun foo ()|\n (let ((a 1))\n (let ((b 2))\n (something))))")) 337 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n |(something))))" (vilpy-step-in 1)) 338 | "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n |(something))))")) 339 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n |(something))))" (vilpy-step-in 2)) 340 | "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n |(something))))")) 341 | (should (string= (vilpy-with "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n |(something))))" (vilpy-step-in 3)) 342 | "(defun foo ()\n (let ((a 1))\n (let ((b 2))\n |(something))))")) 343 | (should (string= (vilpy-with "|;; herp\n;; (foo)\n;; \n(derp)" (vilpy-step-in 1)) 344 | ";; herp\n;; (foo)\n;; \n|(derp)"))) 345 | 346 | (ert-deftest vilpy-down () 347 | (should (string= (vilpy-with "(|(a) (b) (c))" "j") 348 | "((a) |(b) (c))")) 349 | (should (string= (vilpy-with "(|(a) (b) (c))" "jj") 350 | "((a) (b) |(c))")) 351 | (should (string= (vilpy-with "(|(a) (b) (c))" "2j") 352 | "((a) (b) |(c))")) 353 | (should (string= (vilpy-with "(|(a) (b) (c))" "jjj") 354 | "((a) (b) |(c))")) 355 | (should (string= (vilpy-with "(|(a) (b) (c))" "3j") 356 | "((a) (b) |(c))")) 357 | (should (string= (vilpy-with "(|(a) (b) (c))" "jjjj") 358 | "((a) (b) |(c))")) 359 | (should (string= (vilpy-with "(|(a) (b) (c))" "4j") 360 | "((a) (b) |(c))")) 361 | (should (string= (vilpy-with "(a)| (b)\n" "2j") 362 | "(a) (b)|\n")) 363 | (should (string= (vilpy-with "(foo\n |(one)\n two\n (three)\n (four))" "j") 364 | "(foo\n (one)\n two\n |(three)\n (four))")) 365 | (should (string= (vilpy-with "(foo\n |(one)\n two\n (three)\n (four))" "jj") 366 | "(foo\n (one)\n two\n (three)\n |(four))")) 367 | (should (string= (vilpy-with "(foo\n |(one)\n two\n (three)\n (four))" "jjj") 368 | "(foo\n (one)\n two\n (three)\n |(four))")) 369 | (should (string= (vilpy-with "(foo\n (one)|\n two\n (three)\n (four))" "j") 370 | "(foo\n (one)\n two\n (three)|\n (four))")) 371 | (should (string= (vilpy-with "(foo\n (one)|\n two\n (three)\n (four))" "jj") 372 | "(foo\n (one)\n two\n (three)\n (four)|)")) 373 | (should (string= (vilpy-with "(foo\n (one)|\n two\n (three)\n (four))" "jjj") 374 | "(foo\n (one)\n two\n (three)\n (four)|)")) 375 | (should (string= (vilpy-with "(progn\n |foo-bar~-baz-flip-flop)" (vilpy-down 1)) 376 | "(progn\n foo-|bar-baz~-flip-flop)")) 377 | (should (string= (vilpy-with "(progn\n |foo-bar~-baz-flip-flop)" (vilpy-down 5)) 378 | "(progn\n foo-bar-baz-|flip-flop~)")) 379 | (should (string= (vilpy-with "(progn\n ~foo-bar|-baz-flip-flop)" (vilpy-down 1)) 380 | "(progn\n foo-~bar-baz|-flip-flop)")) 381 | (should (string= (vilpy-with "(progn\n ~foo-bar|-baz-flip-flop)" (vilpy-down 5)) 382 | "(progn\n foo-bar-baz-~flip-flop|)")) 383 | (should (string= (vilpy-with "(eval-when-~compile|\n (require 'cl))" (vilpy-down 1)) 384 | "(eval-when-~compile|\n (require 'cl))")) 385 | (should (string= (vilpy-with "~;; foo|\n(bar)" (vilpy-down 1)) 386 | ";; foo\n~(bar)|")) 387 | (should (string= (vilpy-with "~(foo)|\n;; comment\n(bar)" "j") 388 | "(foo)\n~;; comment|\n(bar)")) 389 | (should (string= (vilpy-with "~(foo)|\n;; comment\n(bar)" "jj") 390 | "(foo)\n;; comment\n~(bar)|"))) 391 | 392 | (ert-deftest vilpy-up () 393 | (should (string= (vilpy-with "((a) (b) (c)|)" "k") 394 | "((a) (b)| (c))")) 395 | (should (string= (vilpy-with "((a) (b) (c)|)" "kk") 396 | "((a)| (b) (c))")) 397 | (should (string= (vilpy-with "((a) (b) (c)|)" "2k") 398 | "((a)| (b) (c))")) 399 | (should (string= (vilpy-with "((a) (b) (c)|)" "kkk") 400 | "((a)| (b) (c))")) 401 | (should (string= (vilpy-with "((a) (b) (c)|)" "3k") 402 | "((a)| (b) (c))")) 403 | (should (string= (vilpy-with "((a) (b) (c)|)" "kkkk") 404 | "((a)| (b) (c))")) 405 | (should (string= (vilpy-with "((a) (b) (c)|)" "4k") 406 | "((a)| (b) (c))")) 407 | (should (string= (vilpy-with ";; \n(foo)\n|(bar)" "2k") 408 | ";; \n|(foo)\n(bar)")) 409 | (should (string= (vilpy-with "(foo\n |(one)\n two\n (three)\n (four))" "k") 410 | "(foo\n |(one)\n two\n (three)\n (four))")) 411 | (should (string= (vilpy-with "(foo\n |(one)\n two\n (three)\n (four))" "kk") 412 | "(foo\n |(one)\n two\n (three)\n (four))")) 413 | (should (string= (vilpy-with "(foo\n (one)|\n two\n (three)\n (four))" "k") 414 | "(foo\n (one)|\n two\n (three)\n (four))")) 415 | (should (string= (vilpy-with "(foo\n (one)\n two\n (three)|\n (four))" "k") 416 | "(foo\n (one)|\n two\n (three)\n (four))")) 417 | (should (string= (vilpy-with "(foo\n (one)\n two\n (three)|\n (four))" "kk") 418 | "(foo\n (one)|\n two\n (three)\n (four))")) 419 | (should (string= (vilpy-with "(foo\n (one)\n two\n (three)\n (four)|)" "k") 420 | "(foo\n (one)\n two\n (three)|\n (four))")) 421 | (should (string= (vilpy-with "(foo\n (one)\n two\n (three)\n (four)|)" "kk") 422 | "(foo\n (one)|\n two\n (three)\n (four))")) 423 | (should (string= (vilpy-with "(foo\n (one)\n two\n (three)\n (four)|)" "kk") 424 | "(foo\n (one)|\n two\n (three)\n (four))")) 425 | (should (string= (vilpy-with "(progn\n foo-bar-baz-~flip-flop|)" (vilpy-up 1)) 426 | "(progn\n foo-bar-~baz-flip|-flop)")) 427 | (should (string= (vilpy-with "(progn\n foo-bar-baz-~flip-flop|)" (vilpy-up 5)) 428 | "(progn\n ~foo-bar|-baz-flip-flop)")) 429 | (should (string= (vilpy-with "(progn\n foo-bar-baz-|flip-flop~)" (vilpy-up 1)) 430 | "(progn\n foo-bar-|baz-flip~-flop)")) 431 | (should (string= (vilpy-with "(progn\n foo-bar-baz-|flip-flop~)" (vilpy-up 5)) 432 | "(progn\n |foo-bar~-baz-flip-flop)")) 433 | (should (string= (vilpy-with "(foo)\n;; comment\n~(bar)|" "k") 434 | "(foo)\n~;; comment|\n(bar)")) 435 | (should (string= (vilpy-with "(foo)\n;; comment\n~(bar)|" "kk") 436 | "~(foo)|\n;; comment\n(bar)")) 437 | (should (string= (vilpy-with "(foo)\n;; comment\n|(bar)~" "k") 438 | "(foo)\n|;; comment~\n(bar)")) 439 | (should (string= (vilpy-with "(foo)\n;; comment\n|(bar)~" "kk") 440 | "|(foo)~\n;; comment\n(bar)")) 441 | (should (string= (vilpy-with "(~foo| bar)" "k") 442 | "(~foo| bar)"))) 443 | 444 | (ert-deftest vilpy-other () 445 | (should (string= (vilpy-with "((a) (b) (c)|)" (vilpy-other)) 446 | "((a) (b) |(c))")) 447 | (should (string= (vilpy-with "((a) (b) (c)|)" (progn (vilpy-other) (vilpy-other))) 448 | "((a) (b) (c)|)")) 449 | (should (string= (vilpy-with "((a) (b) (c))|" (vilpy-other)) 450 | "|((a) (b) (c))"))) 451 | 452 | (ert-deftest vilpy-go-to-first-defun () 453 | (should (string= (vilpy-with "|(a)" (vilpy-go-to-first-defun)) 454 | "|(a)")) 455 | (should (string= (vilpy-with "(a) (b) (c |(d))" (vilpy-go-to-first-defun)) 456 | "|(a) (b) (c (d))")) 457 | (should (string= (vilpy-with "(a) (b) (c)|" (vilpy-go-to-first-defun)) 458 | "|(a) (b) (c)")) 459 | (should (string= (vilpy-with "((a) (b) (c)|)" (vilpy-go-to-first-defun)) 460 | "|((a) (b) (c))"))) 461 | 462 | (ert-deftest vilpy-go-to-last-defun () 463 | (should (string= (vilpy-with "|(a)" (vilpy-go-to-last-defun)) 464 | "|(a)")) 465 | (should (string= (vilpy-with "(a) (b) (c |(d))" (vilpy-go-to-last-defun)) 466 | "(a) (b) |(c (d))")) 467 | (should (string= (vilpy-with "|(a) (b) (c)" (vilpy-go-to-last-defun)) 468 | "(a) (b) |(c)")) 469 | (should (string= (vilpy-with "((a) (b) (c)|)" (vilpy-go-to-last-defun)) 470 | "|((a) (b) (c))"))) 471 | 472 | (ert-deftest vilpy-kill () 473 | (should (string= (vilpy-with "\n\n|(defun foo ()\n )" (vilpy-kill)) 474 | "\n\n|")) 475 | ;; while ahead of defun, and there's a comment before, move there 476 | (should (string= (vilpy-with "\n;comment\n|(defun foo ()\n )" (vilpy-kill)) 477 | "\n;comment\n|")) 478 | (should (string= (vilpy-with "(|(a) (b) (c))" "\C-k") 479 | "(|)")) 480 | (should (string= (vilpy-with "((a)\n| (b)\n (c))" "\C-k") 481 | "((a)\n|\n (c))")) 482 | (should (string= (vilpy-with "((a) |(b) (c))" "\C-k") 483 | "((a) |)")) 484 | (should (string= (vilpy-with "((a) (b) |(c))" "\C-k") 485 | "((a) (b) |)")) 486 | (should (string= (vilpy-with "((a)|\n (b) (c))" "\C-k") 487 | "((a)| (b) (c))")) 488 | (should (string= (vilpy-with "((a)|\n (b) (c))" "\C-k\C-k") 489 | "((a)|)")) 490 | (should (string= (vilpy-with "(a b c)\n(|)" "\C-k") 491 | "(a b c)\n|")) 492 | (should (string= (vilpy-with "(foo\nbar | baz )" "\C-k") 493 | "(foo\nbar |)")) 494 | (should (string= (vilpy-with "[1 |2 3]" "\C-k") 495 | "[1 |]")) 496 | (should (string= (vilpy-with "(looking-at |\"foo\")" "\C-k") 497 | "(looking-at |)")) 498 | (should (string= (vilpy-with "(looking-at |\"foo\" (bar))" "\C-k") 499 | "(looking-at |)")) 500 | (should (string= (vilpy-with "(list |\"foo\"\n (bar))" "\C-k") 501 | "(list |\n (bar))")) 502 | (should (string= (vilpy-with "(looking-at \"|;\")" "\C-k") 503 | "(looking-at \"|\")")) 504 | (should (string= (vilpy-with "(foo)| ;bar\n(baz)" "\C-k") 505 | "(foo)|\n(baz)")) 506 | (should (string= (vilpy-with "|#[foo\n bar]" "\C-k") 507 | "|")) 508 | (should (string= (vilpy-with "|#(foo\n bar)" "\C-k") 509 | "|")) 510 | (should (string= (vilpy-with clojure "{:a 1 |:b 2}" "\C-k") 511 | "{:a 1 |}")) 512 | (should (string= (vilpy-with "|\"multiline\nstring\"\n(expr)" "\C-k") 513 | "|\n(expr)")) 514 | (should (string= (vilpy-with "(defun vilpy-kill-test ()\n |(foo\n bar baz)\n (1 2 3)\n (a b c))" "\C-k") 515 | "(defun vilpy-kill-test ()\n |\n (1 2 3)\n (a b c))")) 516 | (should (string= (vilpy-with "(defun test ()\n |(foo)) ;; comment" "\C-k") 517 | "(defun test ()\n |) ;; comment")) 518 | (should (string= (vilpy-with "(progn\n |(looking-at-p \"\\(\"))" "\C-k") 519 | "(progn\n |)")) 520 | (should (string= (vilpy-with "(progn\n| ;; Comment\n (new-code))" "\C-k") 521 | "(progn\n|\n (new-code))")) 522 | (should (equal (vilpy-with "(progn\n |\"test\" \n (bar))" 523 | "\C-k") 524 | "(progn\n |\n (bar))")) 525 | (should (equal (vilpy-with "(progn\n| \"docs\" ;; 0\n (one) ;; 1\n )" 526 | "\C-k") 527 | "(progn\n|\n (one) ;; 1\n )"))) 528 | 529 | (ert-deftest vilpy-delete () 530 | (should (string= (vilpy-with "(|(a) (b) (c))" "\C-d") 531 | "(|(b) (c))")) 532 | (should (string= (vilpy-with "(|(a) (b) (c))" "2\C-d") 533 | "(|(c))")) 534 | (should (string= (vilpy-with "(|(a) (b) (c))" "3\C-d") 535 | "(|)")) 536 | (should (string= (vilpy-with "(|(a) (b) (c))" "3\C-d\C-d") 537 | "|()")) 538 | (should (string= (vilpy-with "(|(a) \"foo\")" "\C-d") 539 | "(|\"foo\")")) 540 | (should (string= (vilpy-with "(|(a)\"foo\")" "\C-d") 541 | "(|\"foo\")")) 542 | (should (string= (vilpy-with "(|(a) b (c))" "\C-d") 543 | "(|b (c))")) 544 | (should (string= (vilpy-with "((a) |\"foo\" (c))" "\C-d") 545 | "((a) |(c))")) 546 | (should (string= (vilpy-with "((a) (|) (c))" "\C-d") 547 | "((a) |() (c))")) 548 | (should (string= (vilpy-with "(a (|) c)" "\C-d") 549 | "(a |() c)")) 550 | (should (string= (vilpy-with "(foo \"bar|\")" "\C-d") 551 | "(foo |\"bar\")")) 552 | (should (string= (vilpy-with "\"foo|\\\"\\\"\"" "\C-d") 553 | "\"foo|\\\"\"")) 554 | (should (string= (vilpy-with "\"|\\\\(foo\\\\)\"" "\C-d") 555 | "\"|foo\"")) 556 | (should (string= (vilpy-with "\"\\\\(foo|\\\\)\"" "\C-d") 557 | "\"foo|\"")) 558 | (should (string= (vilpy-with "(looking-at \"\\\\([a-z]+|\\\\)\")" "\C-d") 559 | "(looking-at \"[a-z]+|\")")) 560 | (should (string= (vilpy-with "(progn `|(foobar) (foo))" "\C-d") 561 | "(progn |(foo))")) 562 | (should (string= (vilpy-with "(require 'foo)\n\n|(require 'bar)\n\n(require 'baz)" "\C-d") 563 | "(require 'foo)\n\n|(require 'baz)")) 564 | (should (string= (vilpy-with "|\n(foo)" "\C-d") 565 | "|(foo)")) 566 | (should (string= (vilpy-with "\"\\|\"\"" "\C-d") 567 | "\"|\"")) 568 | (should (string= (vilpy-with "|(require 'foo)\n\n;; comment" "\C-d") 569 | "|\n\n;; comment")) 570 | (should (string= (vilpy-with "(progn\n |;; a comment\n (test))" "\C-d") 571 | "(progn\n |\n (test))")) 572 | (should (string= (vilpy-with "|;; a comment\n(test))" "\C-d") 573 | "|\n(test))")) 574 | (should (string= (vilpy-with "(defun foobar |() \n (this-and-that))" "\C-d") 575 | "(defun foobar |\n (this-and-that))")) 576 | (should (string= (vilpy-with "(defun foobar |\n (this-and-that))" "\C-d") 577 | "(defun foobar |(this-and-that))")) 578 | (should (string= (vilpy-with "((a) |\"foo\" (c))" 579 | (vilpy-delete -1)) 580 | "(|\"foo\" (c))")) 581 | (should (string= (vilpy-with "(a)'|(b)" "\C-d") "(a)|")) 582 | ;; test that quotes also get deleted 583 | (should (string= (vilpy-with "'|()" "\C-d") 584 | "|")) 585 | (should (string= (vilpy-with "(,@|())" "\C-d") 586 | "(|)")) 587 | (should (string= (vilpy-with "#2A|((a b) (0 1))" "\C-d") 588 | "|")) 589 | (let ((vilpy-safe-delete t)) 590 | ;; region is already safe 591 | (should (string= (vilpy-with "((a) ~(b (c (d)))|)" "\C-d") 592 | "((a) ~|)")) 593 | ;; region cannot be made safe 594 | (should (string= (vilpy-with "~(|a)" "\C-d") 595 | "~(|a)")) 596 | ;; region can be safely dealt with 597 | (should (string= (vilpy-with "(~a) |" "\C-d") 598 | "(~)|")) 599 | (should (string= (vilpy-with "~ (a|)" "\C-d") 600 | "~(|)")) 601 | (should (string= (vilpy-with "(a ~((b)|))" "\C-d") 602 | "(a ~(|))")) 603 | (should (string= (vilpy-with "(a~ b)\n(c |d)" "\C-d") 604 | "(a~)(|d)")) 605 | (should (string= (vilpy-with "(a~ b) (c d) (e |f)" "\C-d") 606 | "(a~)(|f)")) 607 | (should (string= (vilpy-with "((((a ~b))))\n ((((c| d))))" "\C-d") 608 | "((((a ~))))((((| d))))")) 609 | (should (string= (vilpy-with "(((a\n ~(b c))))|" "\C-d") 610 | "(((a\n ~)))|")) 611 | (should (string= (vilpy-with "~((((a b)|\n c)))" "\C-d") 612 | "~(((|\n c)))")) 613 | (should (string= (vilpy-with "(((a\n ~(b c)\n d)|))" "\C-d") 614 | "(((a\n ~)|))")) 615 | (should (string= (vilpy-with "((~(a\n (b c)|\n d)))" "\C-d") 616 | "((~(|\n d)))")) 617 | ;; strings 618 | (should (string= (vilpy-with "~\"I am your |king.\"" "\C-d") 619 | "~\"|king.\"")) 620 | (should (string= (vilpy-with "\"elder~berries\" \"a |witch\"" "\C-d") 621 | "\"elder~\"\"|witch\"")) 622 | (should (string= (vilpy-with "~(1 (2 (3 \"a |duck\")))" "\C-d") 623 | "~(((\"|duck\")))")) 624 | (should (string= (vilpy-with "(((\"a ~duck\" 3) 2) 1)|" "\C-d") 625 | "(((\"a ~\")))|")) 626 | ;; test ignoring delimiters in strings 627 | (should (string= (vilpy-with "\"~( is a left paren.|\"" "\C-d") 628 | "\"~|\"")) 629 | (should (string= (vilpy-with "~a \"([[{b |c\"" "\C-d") 630 | "~\"|c\"")) 631 | (should (string= (vilpy-with "\"a ~b)]}\" c|" "\C-d") 632 | "\"a ~\"|")) 633 | (should (string= (vilpy-with "~a \"(b {c]\" d|" "\C-d") 634 | "~|")) 635 | (should (string= (vilpy-with "a \"~(\"\"]\" \"((|)\" b" "\C-d") 636 | "a \"~\"\"|)\" b")) 637 | ;; test that a right quote at end of the region is not deleted 638 | (should (string= (vilpy-with "\"a ~string\"|" "\C-d") 639 | "\"a ~\"|")) 640 | ;; mixed 641 | (should (string= (vilpy-with "~{[(a b \"(c|\" d)]}" "\C-d") 642 | "~{[(\"|\" d)]}")) 643 | ;; test ignoring delimiters in comments 644 | (should (string= (vilpy-with "~;; ([[{{|" "\C-d") 645 | "~|")) 646 | (should (string= (vilpy-with ";; ~([[{{\n a|" "\C-d") 647 | ";; ~|")) 648 | (should (string= (vilpy-with "~{[(a\n b\n ;; ]{](\n| d)]}" "\C-d") 649 | "~{[(| d)]}")) 650 | (should (string= (vilpy-with "{[(a~\n b\n ;; ]{](\n d)]}|" "\C-d") 651 | "{[(a~)]}|")) 652 | ;; delimiters before comments shouldn't be considered part of the comment 653 | (should (string= (vilpy-with "~(;; a\n |b)" "\C-d") 654 | "~(|b)")) 655 | ;; both mixed 656 | (should (string= (vilpy-with "{[(a\n~ b \"c [(d e}\"\n ;;({]\n| f)]}" 657 | "\C-d") 658 | "{[(a\n~| f)]}")) 659 | (let ((vilpy-safe-actions-no-pull-delimiters-into-comments t)) 660 | (should (string= (vilpy-with "(a\n;; foo~bar\n|b)" "\C-d") 661 | "(a\n;; foo~\n|b)")) 662 | (should (string= (vilpy-with "(a\n;; foo~bar\nb|)" "\C-d") 663 | "(a\n;; foo~\n|)")) 664 | (should (string= (vilpy-with "(a\n;; foo~bar\nb)|" "\C-d") 665 | "(a\n;; foo~\n)|")) 666 | ;; test that full comments are deleted with their newlines 667 | (should (string= (vilpy-with ";; foo\n~;;bar\n|(baz)" "\C-d") 668 | ";; foo\n~|(baz)")) 669 | (should (string= (vilpy-with ";; foo\n~;;bar\n|(baz\n qux)" "\C-d") 670 | ";; foo\n~|(baz\n qux)")))) 671 | 672 | (let ((vilpy-delete-sexp-from-within t)) 673 | (should (string= (vilpy-with "(|)" "\C-d") "|")) 674 | (should (string= (vilpy-with "(foo|)" "\C-d") "|")) 675 | (should (string= (vilpy-with "\"|\"" "\C-d") "|")) 676 | (should (string= (vilpy-with "\"foo|\"" "\C-d") "|")))) 677 | 678 | (ert-deftest vilpy-delete-backward () 679 | (should (string= (vilpy-with "((a) (b) (c)|)" "\C-?") 680 | "((a) (b)|)")) 681 | (should (string= (vilpy-with "(list)(foo)|" "\C-?") 682 | "(list)|")) 683 | (should (string= (vilpy-with "((a) (b) (c)|)" "2\C-?") 684 | "((a)|)")) 685 | (should (string= (vilpy-with "((a) (b) (c)|)" "3\C-?") 686 | "(|)")) 687 | (should (string= (vilpy-with "(a (b)| c)" "\C-?") 688 | "(a| c)")) 689 | (should (string= (vilpy-with "(a (|) c)" "\C-?") 690 | "(a| c)")) 691 | (should (string= (vilpy-with "(foo \"|bar\")" "\C-?") 692 | "(foo \"bar\"|)")) 693 | (should (string= (vilpy-with "(a \"\"| c)" "\C-?") 694 | "(a| c)")) 695 | (should (string= (vilpy-with "(a \"\"| c)" "\C-?") 696 | "(a| c)")) 697 | (should (string= (vilpy-with ";|" "\C-?") 698 | "|")) 699 | (should (string= (vilpy-with "\"\\\\(|foo\\\\)\"" "\C-?") 700 | "\"|foo\"")) 701 | (should (string= (vilpy-with "\"\\\\(foo\\\\)|\"" "\C-?") 702 | "\"foo|\"")) 703 | (should (string= (vilpy-with "\"\\\\(|foo\"" "\C-?") 704 | "\"\\\\|foo\"")) 705 | (should (string= (vilpy-with "(foo)\n;; ()|" "\C-?") 706 | "(foo)\n;; (|")) 707 | (should (string= (vilpy-with "(~\"foo\"|)" "\C-?") 708 | "(~|)")) 709 | (should (string= (vilpy-with "(|\"foo\"~)" "\C-?") 710 | "(~|)")) 711 | (should (string= (vilpy-with "(foo bar)\n;; comment\n(foo bar)|" "\C-?") 712 | "(foo bar)\n;; comment\n|")) 713 | (should (string= (vilpy-with "(require 'foo)\n\n(require 'bar)|\n\n(require 'baz)" "\C-?") 714 | "(require 'foo)\n\n|\n\n(require 'baz)")) 715 | (should (string= (vilpy-with "(list\n (foo)\n |(bar))" "\C-?") 716 | "(list\n (foo) |(bar))")) 717 | (should (string= (vilpy-with "(list\n (foo)\n |\"bar\")" "\C-?") 718 | "(list\n (foo) |\"bar\")")) 719 | (should (string= (vilpy-with " |(foo)" "\C-?") 720 | "|(foo)")) 721 | (should (string= (vilpy-with "(foo (bar) |)" "\C-?") 722 | "(foo (bar)|)")) 723 | (should (string= (vilpy-with "(bar)\n;; bar\n|(baz)" "\C-?") 724 | "(bar)\n|(baz)")) 725 | (should (string= (vilpy-with "(bar)\n;; bar\n |(baz)" "\C-?") 726 | "(bar)\n|(baz)")) 727 | (should (string= (vilpy-with "(\n |(a))" "\C-?") 728 | "(|(a))")) 729 | (should (string= (vilpy-with "(list (foo) |(bar))" "\C-?") 730 | "(list |(bar))")) 731 | (should (string= (vilpy-with "(list (foo) |\"bar\")" "\C-?") 732 | "(list |\"bar\")")) 733 | (should (string= (vilpy-with "\"We want...\" |\"a shrubbery!\"" "\C-?") 734 | "\"We want...\" |\"a shrubbery!\"")) 735 | (should (string= (vilpy-with "\"\\C|-j\"" "\C-?") 736 | "\"|-j\"")) 737 | (should (string= (vilpy-with "(progn\n (foo)\n\n |;; upcoming magic\n (magic))" "\C-?") 738 | "(progn\n (foo)\n |;; upcoming magic\n (magic))")) 739 | (should (string= (vilpy-with "(list \"foo\" |)" "\C-?") 740 | "(list \"foo\"|)")) 741 | (should (string= (vilpy-with "\"a\\n|\"" "\C-?") 742 | "\"a|\"")) 743 | (should (string= (vilpy-with "\"\\\\n|\"" "\C-?") 744 | "\"\\\\|\"")) 745 | (should (string= (vilpy-with "((a) |(b) (c))" 746 | (vilpy-delete-backward -1)) 747 | "((a) |(c))")) 748 | (should (string= (vilpy-with ";; foo\n|\n(bar)" "\C-?") 749 | ";; foo|\n(bar)")) 750 | (should (string= (vilpy-with "(foo ?{|)" "\C-?") 751 | "(foo ?|)")) 752 | (should (string= (vilpy-with "(foo ?}|)" "\C-?") 753 | "(foo ?|)")) 754 | (should (string= (vilpy-with "(list \"string\" |[1 2])" "\C-?") 755 | "(list |[1 2])")) 756 | (should (string= (vilpy-with "#2A((a b) (0 1))|" "\C-?") 757 | "|")) 758 | (should (string= (vilpy-with clojure "(partial filter neg?)|" "\C-?") 759 | "|")) 760 | (let ((vilpy-delete-sexp-from-within t)) 761 | (should (string= (vilpy-with "(|)" "\C-?") "|")) 762 | (should (string= (vilpy-with "(|foo)" "\C-?") "|")) 763 | (should (string= (vilpy-with "\"|\"" "\C-?") "|")) 764 | (should (string= (vilpy-with "\"|foo\"" "\C-?") "|"))) 765 | 766 | (should (string= (vilpy-with "(foo ; |\n)" "\C-?") 767 | "(foo|)")) 768 | (should (string= (vilpy-with "(foo\n ;; |\n)" "\C-?") "(foo\n |\n)")) 769 | (should (string= (vilpy-with "(foo) ;; |" "\C-?") "(foo)|")) 770 | (should (string= (vilpy-with "(foo ;; |\n)" "\C-?") "(foo|)")) 771 | (should (string= (vilpy-with " |;;" "\C-?") 772 | "|;;")) 773 | (should (string= (vilpy-with " |;;" "\C-?") 774 | "|;;")) 775 | (should (string= (vilpy-with clojure "(foo bar?)|" "\C-?") "|"))) 776 | 777 | (ert-deftest vilpy-pair () 778 | (should (string= (vilpy-with "\"\\\\|\"" "(") 779 | "\"\\\\(|\\\\)\"")) 780 | (should (string= (vilpy-with "\"\\\\|\"" "{") 781 | "\"\\\\{|\\\\}\"")) 782 | (should (string= (vilpy-with "|foo bar~" "(") 783 | "|(foo bar)")) 784 | (should (string= (vilpy-with "~foo bar|" "(") 785 | "|(foo bar)")) 786 | (should (string= (vilpy-with "(progn\n|\n (foo))" "1(") 787 | "(progn\n (|\n (foo)))")) 788 | (should (string= (vilpy-with "a| b c" (kbd "C-u") "(") 789 | "(| a) b c")) 790 | (should (string= (vilpy-with "a| b c" (setq current-prefix-arg 1) "(") 791 | "(| a) b c")) 792 | (should (string= (vilpy-with "a| b c" (setq current-prefix-arg 2) "(") 793 | "(| a b) c")) 794 | (should (string= (vilpy-with "a| b c" (setq current-prefix-arg 3) "(") 795 | "(| a b c)")) 796 | (should (string= (vilpy-with "a| b c" (setq current-prefix-arg 0) "(") 797 | "(| a b c)")) 798 | (should (string= (vilpy-with "a| b c" (setq current-prefix-arg -1) "(") 799 | "(| a b c)")) 800 | (should (string= (vilpy-with "|(a b c)\n(d e f)" (setq current-prefix-arg -1) "(") 801 | "(| (a b c))\n(d e f)")) 802 | (should (string= (vilpy-with "|(a b c)\n(d e f)" (setq current-prefix-arg 0) "(") 803 | "(| (a b c)\n (d e f))")) 804 | (should (string= (vilpy-with "|" (setq current-prefix-arg -1) "(") 805 | "(|)")) 806 | (should (string= (vilpy-with "(|)" (setq current-prefix-arg -1) "(") 807 | "((|))")) 808 | (should (string= (vilpy-with "(a |)" (setq current-prefix-arg -1) "(") 809 | "(a (|))")) 810 | (should (string= (vilpy-with "(| a)" (setq current-prefix-arg -1) "(") 811 | "((| a))")) 812 | (should (string= (vilpy-with "(a | b)" (setq current-prefix-arg -1) "(") 813 | "(a (| b))")) 814 | (should (string= (vilpy-with "(a |\n )" (setq current-prefix-arg -1) "(") 815 | "(a (|)\n )")) 816 | (should (string= (vilpy-with "(|\n )" (setq current-prefix-arg -1) "(") 817 | "((|)\n )")) 818 | (should (string= (vilpy-with "(a\n |)" (setq current-prefix-arg -1) "(") 819 | "(a\n (|))")) 820 | (should (string= (vilpy-with "(a '|)" (setq current-prefix-arg -1) "(") 821 | "(a '(|))")) 822 | (should (string= (vilpy-with "(a |) " (setq current-prefix-arg -1) "(") 823 | "(a (|)) ")) 824 | (let (vilpy-insert-space-after-wrap) 825 | (should (string= (vilpy-with "a| b c" (kbd "C-u") "(") 826 | "(|a) b c")))) 827 | 828 | (ert-deftest vilpy--sub-slurp-forward () 829 | (should (eq (vilpy-with-v el "(progn\n ~foo|-bar-baz-flip-flop)" 830 | (vilpy--sub-slurp-forward 1)) 1)) 831 | (should (eq (vilpy-with-v el "(progn\n ~foo|-bar-baz-flip-flop)" 832 | (vilpy--sub-slurp-forward 4)) 4)) 833 | (should (eq (vilpy-with-v el "(progn\n ~foo|-bar-baz-flip-flop)" 834 | (vilpy--sub-slurp-forward 5)) 4)) 835 | (should (eq (vilpy-with-v el "(progn\n ~foo|-bar-baz-flip-flop)" 836 | (vilpy--sub-slurp-forward 10)) 4)) 837 | (should (eq (vilpy-with-v el "(progn\n ~foo|-bar-baz-flip-flop)" 838 | (vilpy--sub-slurp-forward 5) 839 | (vilpy--sub-slurp-forward 1)) nil))) 840 | 841 | (ert-deftest vilpy--sub-slurp-backward () 842 | (should (eq (vilpy-with-v el "(progn\n foo-bar-baz-flip-|flop~)" 843 | (vilpy--sub-slurp-backward 1)) 1)) 844 | (should (eq (vilpy-with-v el "(progn\n foo-bar-baz-flip-|flop~)" 845 | (vilpy--sub-slurp-backward 4)) 4)) 846 | (should (eq (vilpy-with-v el "(progn\n foo-bar-baz-flip-|flop~)" 847 | (vilpy--sub-slurp-backward 5)) 4)) 848 | (should (eq (vilpy-with-v el "(progn\n foo-bar-baz-flip-|flop~)" 849 | (vilpy--sub-slurp-backward 5) 850 | (vilpy--sub-slurp-backward 1)) nil))) 851 | 852 | (ert-deftest vilpy-slurp () 853 | (should (string= (vilpy-with "()|(a) (b) (c)" ">") 854 | "((a))| (b) (c)")) 855 | (should (string= (vilpy-with "()|(a) (b) (c)" ">>") 856 | "((a) (b))| (c)")) 857 | (should (string= (vilpy-with "()|(a) (b) (c)" ">>>") 858 | "((a) (b) (c))|")) 859 | (should (string= (vilpy-with "()|(a) (b) (c)" ">>>>") 860 | "((a) (b) (c))|")) 861 | (should (string= (vilpy-with "(a) (b) (c)|()" ">") 862 | "(a) (b) (c ())|")) 863 | (should (string= (vilpy-with "(a) (b) (c) |()" ">>") 864 | "(a) |((b) (c) )")) 865 | (should (string= (vilpy-with "(a) (b) (c) |()" ">>>") 866 | "|((a) (b) (c) )")) 867 | (should (string= (vilpy-with "(a) (b) (c) |()" ">>>>") 868 | "|((a) (b) (c) )")) 869 | (should (string= (vilpy-with "(insert)|\"foo\"" ">") 870 | "(insert \"foo\")|")) 871 | (should (string= (vilpy-with "(foo) #_~(bar)| (baz)" ">") 872 | "(foo) #_~(bar) (baz)|")) 873 | (should (string= (vilpy-with "(foo) #_|(bar)~ (baz)" ">") 874 | "(foo) |#_(bar)~ (baz)")) 875 | (should (string= (vilpy-with "|(a) (b) (c)" "m>") 876 | "~(a) (b)| (c)")) 877 | (should (string= (vilpy-with "(progn\n ~foo|-bar-baz-flip-flop)" (vilpy-slurp 1)) 878 | "(progn\n ~foo-bar|-baz-flip-flop)")) 879 | (should (string= (vilpy-with "(progn\n ~foo|-bar-baz-flip-flop)" (vilpy-slurp 2)) 880 | "(progn\n ~foo-bar-baz|-flip-flop)")) 881 | (should (string= (vilpy-with "(progn\n ~foo|-bar-baz-flip-flop)" (vilpy-slurp 3)) 882 | "(progn\n ~foo-bar-baz-flip|-flop)")) 883 | (should (string= (vilpy-with "(progn\n ~foo|-bar-baz-flip-flop)" (vilpy-slurp 4)) 884 | "(progn\n ~foo-bar-baz-flip-flop|)")) 885 | (should (string= (vilpy-with "(progn\n ~foo|-bar-baz-flip-flop)" (vilpy-slurp 5)) 886 | "(progn\n ~foo-bar-baz-flip-flop|)")) 887 | (should (string= (vilpy-with "(progn\n foo-bar-baz-flip-|flop~)" (vilpy-slurp 1)) 888 | "(progn\n foo-bar-baz-|flip-flop~)")) 889 | (should (string= (vilpy-with "(progn\n foo-bar-baz-flip-|flop~)" (vilpy-slurp 2)) 890 | "(progn\n foo-bar-|baz-flip-flop~)")) 891 | (should (string= (vilpy-with "(progn\n foo-bar-baz-flip-|flop~)" (vilpy-slurp 3)) 892 | "(progn\n foo-|bar-baz-flip-flop~)")) 893 | (should (string= (vilpy-with "(progn\n foo-bar-baz-flip-|flop~)" (vilpy-slurp 4)) 894 | "(progn\n |foo-bar-baz-flip-flop~)")) 895 | (should (string= (vilpy-with "(progn\n foo-bar-baz-flip-|flop~)" (vilpy-slurp 5)) 896 | "(progn\n |foo-bar-baz-flip-flop~)")) 897 | (should (string= (vilpy-with "(progn\n |foo-bar~-baz-flip-flop)" (vilpy-slurp 1)) 898 | "(progn\n |foo-bar~-baz-flip-flop)")) 899 | (should (string= (vilpy-with "()| foo" (vilpy-slurp 1)) 900 | "(foo)|")) 901 | (should (string= (vilpy-with "(progn\n ~(foo)|\n ;; comment 1\n ;; comment 2\n (bar))" ">") 902 | "(progn\n ~(foo)\n ;; comment 1\n ;; comment 2|\n (bar))")) 903 | (should (string= (vilpy-with "(progn\n (foo)\n ;; comment 1\n ;; comment 2\n |(bar)~)" ">") 904 | "(progn\n (foo)\n |;; comment 1\n ;; comment 2\n (bar)~)")) 905 | (should (string= (vilpy-with "((a)| b c)" (vilpy-slurp -1)) 906 | "((a b c)|)")) 907 | (should (string= (vilpy-with "()|(a) (b)\n(c) (d)" (vilpy-slurp -1)) 908 | "((a) (b))|\n(c) (d)")) 909 | (should (string= (vilpy-with "(a (b (c)| d) e)" (vilpy-slurp -1)) 910 | "(a (b (c d)|) e)")) 911 | (should (string= (vilpy-with "(a b |(c))" (vilpy-slurp -1)) 912 | "(|(a b c))")) 913 | (should (string= (vilpy-with "(a) (b)\n(c) (d) |((e))" (vilpy-slurp -1)) 914 | "(a) (b)\n|((c) (d) (e))")) 915 | (should (string= (vilpy-with "(a (b |(c) d) e)" (vilpy-slurp -1)) 916 | "(a (|(b c) d) e)")) 917 | (should (string= (vilpy-with "()|(a) (b)\n(c) (d)" (vilpy-slurp 0)) 918 | "((a) (b)\n (c) (d))|")) 919 | (should (string= (vilpy-with "(()|(a) (b)\n (c) (d))\n(e) (f)" (vilpy-slurp 0)) 920 | "(((a) (b)\n (c) (d))|)\n(e) (f)")) 921 | (should (string= (vilpy-with "(a (b (c)| d) e)" (vilpy-slurp 0)) 922 | "(a (b (c d)|) e)")) 923 | (should (string= (vilpy-with "(a) (b)\n(c) (d) |((e))" (vilpy-slurp 0)) 924 | "|((a) (b)\n (c) (d) (e))")) 925 | (should (string= (vilpy-with "(a) (b)\n((c) (d)\n (e) |((f)))" (vilpy-slurp 0)) 926 | "(a) (b)\n(|((c) (d)\n (e) (f)))")) 927 | (should (string= (vilpy-with "(a (b |(c) d) e)" (vilpy-slurp 0)) 928 | "(a (|(b c) d) e)")) 929 | (should (string= (vilpy-with "(~|a (b c) d\n e f)" (vilpy-slurp -1)) 930 | "(~a (b c) d|\n e f)")) 931 | (should (string= (vilpy-with "(~|a (b c) d\n e f)" (vilpy-slurp 0)) 932 | "(~a (b c) d\n e f|)")) 933 | (should (string= (vilpy-with "(a b\n c (d e) |f~)" (vilpy-slurp -1)) 934 | "(a b\n |c (d e) f~)")) 935 | (should (string= (vilpy-with "(a b\n c (d e) |f~)" (vilpy-slurp 0)) 936 | "(|a b\n c (d e) f~)")) 937 | (should (string= (vilpy-with "(a (~|b c) d)" (vilpy-slurp -1)) 938 | "(a (~b c|) d)")) 939 | (should (string= (vilpy-with "(a (~|b c) d)" (vilpy-slurp 0)) 940 | "(a (~b c|) d)")) 941 | (should (string= (vilpy-with "(a (b |c~) d)" (vilpy-slurp -1)) 942 | "(a (|b c~) d)")) 943 | (should (string= (vilpy-with "(a (b |c~) d)" (vilpy-slurp 0)) 944 | "(a (|b c~) d)")) 945 | (should (string= (vilpy-with "~|a b c" (vilpy-slurp -1)) 946 | "~a b c|")) 947 | (should (string= (vilpy-with "~|a b c" (vilpy-slurp 0)) 948 | "~a b c|")) 949 | (should (string= (vilpy-with "a b |c~" (vilpy-slurp -1)) 950 | "|a b c~")) 951 | (should (string= (vilpy-with "a b |c~" (vilpy-slurp 0)) 952 | "|a b c~")) 953 | ;; before a multi-line list 954 | (should (string= (vilpy-with "()| (a\n b)" (vilpy-slurp -1)) 955 | "((a\n b))|")) 956 | (should (string= (vilpy-with "~|(a\n b)" (vilpy-slurp -1)) 957 | "~(a\n b)|"))) 958 | 959 | (ert-deftest vilpy-barf () 960 | (should (string= (vilpy-with "((a) (b) (c))|" "<") 961 | "((a) (b))| (c)")) 962 | (should (string= (vilpy-with "((a) (b) (c))|" "<<") 963 | "((a))| (b) (c)")) 964 | (should (string= (vilpy-with "((a) (b) (c))|" "<<<") 965 | "()|(a) (b) (c)")) 966 | (should (string= (vilpy-with "((a) (b) (c))|" "<<<<") 967 | "()|(a) (b) (c)")) 968 | (should (string= (vilpy-with "|((a) (b) (c))" "<") 969 | "(a) |((b) (c))")) 970 | (should (string= (vilpy-with "|((a) (b) (c))" "<<") 971 | "(a) (b) |((c))")) 972 | (should (string= (vilpy-with "|((a) (b) (c))" "<<<") 973 | "(a) (b) (c)|()")) 974 | (should (string= (vilpy-with "|((a) (b) (c))" "<<<<") 975 | "(a) (b) (c)|()")) 976 | (should (string= (vilpy-with "(progn\n ~foo-bar-baz-flip-flop|)" (vilpy-barf 1)) 977 | "(progn\n ~foo-bar-baz-flip|-flop)")) 978 | (should (string= (vilpy-with "(progn\n ~foo-bar-baz-flip-flop|)" (vilpy-barf 2)) 979 | "(progn\n ~foo-bar-baz|-flip-flop)")) 980 | (should (string= (vilpy-with "(progn\n ~foo-bar-baz-flip-flop|)" (vilpy-barf 3)) 981 | "(progn\n ~foo-bar|-baz-flip-flop)")) 982 | (should (string= (vilpy-with "(progn\n ~foo-bar-baz-flip-flop|)" (vilpy-barf 4)) 983 | "(progn\n ~foo|-bar-baz-flip-flop)")) 984 | (should (string= (vilpy-with "(progn\n ~foo-bar-baz-flip-flop|)" (vilpy-barf 5)) 985 | "(progn\n ~foo|-bar-baz-flip-flop)")) 986 | (should (string= (vilpy-with "(progn\n |foo-bar-baz-flip-flop~)" (vilpy-barf 1)) 987 | "(progn\n foo-|bar-baz-flip-flop~)")) 988 | (should (string= (vilpy-with "(progn\n |foo-bar-baz-flip-flop~)" (vilpy-barf 2)) 989 | "(progn\n foo-bar-|baz-flip-flop~)")) 990 | (should (string= (vilpy-with "(progn\n |foo-bar-baz-flip-flop~)" (vilpy-barf 3)) 991 | "(progn\n foo-bar-baz-|flip-flop~)")) 992 | (should (string= (vilpy-with "(progn\n |foo-bar-baz-flip-flop~)" (vilpy-barf 4)) 993 | "(progn\n foo-bar-baz-flip-|flop~)")) 994 | (should (string= (vilpy-with "(progn\n |foo-bar-baz-flip-flop~)" (vilpy-barf 5)) 995 | "(progn\n foo-bar-baz-flip-|flop~)")) 996 | (should (string= (vilpy-with "(progn\n ~(foo)\n ;; comment 1\n ;; comment 2|\n (bar))" "<") 997 | "(progn\n ~(foo)|\n ;; comment 1\n ;; comment 2\n (bar))")) 998 | (should (string= (vilpy-with "(progn\n (foo)\n ~;; bar|\n (baz))" "<") 999 | "(progn\n (foo)\n ~;; bar|\n (baz))"))) 1000 | 1001 | (ert-deftest vilpy-splice () 1002 | (should (string= (vilpy-with "(|(a) (b) (c))" (vilpy-splice 1)) 1003 | "(a |(b) (c))")) 1004 | (should (string= (vilpy-with "((a) |(b) (c))" (vilpy-splice 1)) 1005 | "((a) b |(c))")) 1006 | (should (string= (vilpy-with "(|(a) (b) (c))" (progn (vilpy-splice 1) 1007 | (vilpy-splice 1) 1008 | (vilpy-splice 1))) 1009 | "|(a b c)")) 1010 | (should (string= (vilpy-with "((a) (b) (c)|)" (vilpy-splice 1)) 1011 | "((a) (b)| c)")) 1012 | (should (string= (vilpy-with "((a) (b) (c)|)" (progn (vilpy-splice 1) 1013 | (vilpy-splice 1))) 1014 | "((a)| b c)")) 1015 | (should (string= (vilpy-with "((a) (b) (c)|)" (progn (vilpy-splice 1) 1016 | (vilpy-splice 1) 1017 | (vilpy-splice 1))) 1018 | "(a b c)|")) 1019 | (should (string= (vilpy-with "|(a b c)" (vilpy-splice 1)) 1020 | "|a b c")) 1021 | (should (string= (vilpy-with "(a b c)|" (vilpy-splice 1)) 1022 | "a b c|")) 1023 | (should (string= (vilpy-with "(a ~'(b c)|)" (vilpy-splice 1)) 1024 | "(a ~b c|)")) 1025 | (should (string= (vilpy-with "(a |'(b c)~)" (vilpy-splice 1)) 1026 | "(a |b c~)")) 1027 | (should (string= (vilpy-with "(a '(b c)|)" (vilpy-splice 1)) 1028 | "(a b c)|")) 1029 | (should (string= (vilpy-with "(asdf)\n(progn\n |(foo)\n (bar))\n(asdf)" 1030 | (progn (vilpy-splice 1) 1031 | (vilpy-splice 1))) 1032 | "(asdf)\n|(progn\n foo\n bar)\n(asdf)")) 1033 | (should (string= (vilpy-with "(asdf)\n(progn\n (foo)\n (bar)|)\n(asdf)" 1034 | (progn (vilpy-splice 1) 1035 | (vilpy-splice 1))) 1036 | "(asdf)\n(progn\n foo\n bar)|\n(asdf)")) 1037 | ;; test that quotes also get deleted 1038 | (should (string= (vilpy-with "'|(a)" (vilpy-splice 1)) 1039 | "|a")) 1040 | (should (string= (vilpy-with "(,@|(a))" (vilpy-splice 1)) 1041 | "|(a)")) 1042 | (should (string= (vilpy-with "#2A|((a b) (0 1))" (vilpy-splice 1)) 1043 | "|(a b) (0 1)")) 1044 | ;; let splicing 1045 | (should (string= (vilpy-with "(let (foo)\n |(let ((bar (point)))\n (baz)))" (vilpy-splice 1)) 1046 | "(let (foo\n |(bar (point)))\n (baz))")) 1047 | (should (string= (vilpy-with "(let ((foo (point)))\n |(let ((bar (1+ foo)))\n (baz)))" (vilpy-splice 1)) 1048 | "(let* ((foo (point))\n |(bar (1+ foo)))\n (baz))")) 1049 | (should (string= (vilpy-with "|(let (foo)\n (let ((bar (point)))\n (baz)))" (vilpy-splice 1)) 1050 | "let |(foo)\n (let ((bar (point)))\n (baz))")) 1051 | (should (string= (vilpy-with clojure "(let [foo 10]\n |(let [bar 20]\n (baz)))" (vilpy-splice 1)) 1052 | "|(let [foo 10\n bar 20]\n (baz))"))) 1053 | 1054 | (ert-deftest vilpy-raise () 1055 | (should (string= (vilpy-with "(if (and |(pred1) (pred2))\n (thing1)\n (thing2))" "r") 1056 | "(if |(pred1)\n (thing1)\n (thing2))")) 1057 | (should (string= (vilpy-with "(if (and (pred1) |(pred2))\n (thing1)\n (thing2))" "r") 1058 | "(if |(pred2)\n (thing1)\n (thing2))")) 1059 | (should (string= (vilpy-with "(if (and (pred1)| (pred2))\n (thing1)\n (thing2))" "r") 1060 | "(if (pred1)|\n (thing1)\n (thing2))")) 1061 | (should (string= (vilpy-with "(if (and (pred1) (pred2)|)\n (thing1)\n (thing2))" "r") 1062 | "(if (pred2)|\n (thing1)\n (thing2))")) 1063 | (should (string= (vilpy-with "(if (and (pred1) (pred2))\n |(thing1)\n (thing2))" "r") 1064 | "|(thing1)")) 1065 | (should (string= (vilpy-with "(if (and (pred1) (pred2))\n (thing1)|\n (thing2))" "r") 1066 | "(thing1)|")) 1067 | (should (string= (vilpy-with "(if (and (pred1) (pred2))\n (thing1)\n |(thing2))" "r") 1068 | "|(thing2)")) 1069 | (should (string= (vilpy-with "(if (and (pred1) (pred2))\n (thing1)\n (thing2)|)" "r") 1070 | "(thing2)|")) 1071 | (should (string= (vilpy-with "(foo (bar |(baz)))" "r") 1072 | "(foo |(baz))")) 1073 | (should (string= (vilpy-with "(foo (bar |(baz)))" "2r") 1074 | "|(baz)")) 1075 | (should (string= (vilpy-with "(foo (bar |(baz)~))" "r") 1076 | "(foo |(baz)~)")) 1077 | (should (string= (vilpy-with "(foo (bar |(baz)~))" "2r") 1078 | "|(baz)~")) 1079 | (should (string= (vilpy-with "(a (f~oob|ar) c)" "r") "(a ~oob| c)")) 1080 | (should (string= (vilpy-with "(a (f|oob~ar) c)" "r") "(a |oob~ c)")) 1081 | (should (string= (vilpy-with "(\n |(foo))" "r") "|(foo)")) 1082 | ;; a bug in `indent-sexp' http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16852 1083 | ;; (should (string= (vilpy-with "(|(\n progn\n ))" "r") "|(\n progn\n )")) 1084 | ) 1085 | 1086 | (ert-deftest vilpy-raise-some () 1087 | (should (string= (vilpy-with "(if (and |(pred1) (pred2))\n (thing1)\n (thing2))" "R") 1088 | "(if |(pred1) (pred2)\n (thing1)\n (thing2))")) 1089 | (should (string= (vilpy-with "(if (and (pred1) |(pred2))\n (thing1)\n (thing2))" "R") 1090 | "(if |(pred2)\n (thing1)\n (thing2))")) 1091 | (should (string= (vilpy-with "(if (and (pred1) (pred2))\n |(thing1)\n (thing2))" "R") 1092 | "|(thing1)\n(thing2)")) 1093 | (should (string= (vilpy-with "(progn\n |(foo)\n nil)" "R") 1094 | "|(foo)\nnil")) 1095 | (should (string= (vilpy-with "(a\n b\n (foo)|\n c)" "R") 1096 | "a\nb\n(foo)|")) 1097 | (should (string= (vilpy-with "|(foo)" "R") 1098 | "|(foo)")) 1099 | (should (string= (vilpy-with "(foo)|" "R") 1100 | "(foo)|"))) 1101 | 1102 | (ert-deftest vilpy-convolute () 1103 | (should (string= (vilpy-with "(when (pred)\n (let ((x 1))\n |(foo)\n (bar)))" "C") 1104 | "(let ((x 1))\n (when (pred)\n |(foo))\n (bar))")) 1105 | (should (string= (vilpy-with "(when (pred)\n (let ((x 1))\n |(foo)\n (bar)))" "CC") 1106 | "(when (pred)\n (let ((x 1))\n |(foo)\n (bar)))")) 1107 | (should (string= (vilpy-with "(+ 1 (* 2 ~3|))" "C") 1108 | "(* 2 (+ 1 ~3|))")) 1109 | (should (string= (vilpy-with "(+ 1 (* 2 |3~))" "C") 1110 | "(* 2 (+ 1 |3~))")) 1111 | (should (string= (vilpy-with "(asdf\n (when (pred)\n (let ((x 1))\n (foo)\n |(bar))))" 1112 | "2C") 1113 | "(when (pred)\n (let ((x 1))\n (foo)\n (asdf\n |(bar))))")) 1114 | (should (string= (vilpy-with "(takes-two\n (takes-three\n |(takes-four 1 2 3 4)\n second\n third)\n other-second)" 1115 | "C") 1116 | "(takes-three\n (takes-two\n |(takes-four 1 2 3 4)\n other-second)\n second\n third)")) 1117 | (should (string= (vilpy-with "(with-current-buffer buf\n (let ((beg x)\n (end y))\n |(insert \" \")\n (delete-region beg end)\n (point)))" 1118 | "0C") 1119 | "(let ((beg x)\n (end y))\n (with-current-buffer buf\n |(insert \" \")\n (delete-region beg end)\n (point)))"))) 1120 | 1121 | (ert-deftest vilpy-join () 1122 | (should (string= (vilpy-with "(foo) |(bar)" "+") 1123 | "(foo |bar)")) 1124 | (should (string= (vilpy-with "(foo)| (bar)" "+") 1125 | "(foo bar)|")) 1126 | (should (string= (vilpy-with "\"a series\"\n \" of st|rings\"" (kbd "M-J")) 1127 | "\"a series of st|rings\"")) 1128 | (should (string= (vilpy-with "\"a series\"\n |\" of strings\"" (kbd "M-J")) 1129 | "\"a series| of strings\"")) 1130 | (should (string= (vilpy-with "\"a series|\"\n \" of strings\"" (kbd "M-J")) 1131 | "\"a series| of strings\"")) 1132 | (should (string= (vilpy-with "\"a series|\"\n \" of strings\"" (kbd "M-J")) 1133 | "\"a series| of strings\"")) 1134 | (should (string= (vilpy-with "|\"a series\"\n \" of strings\"" (kbd "M-J")) 1135 | "|\"a series of strings\""))) 1136 | 1137 | (ert-deftest vilpy-split () 1138 | (should (string= (vilpy-with "(foo |bar)" (kbd "M-j")) 1139 | "(foo)\n|(bar)")) 1140 | (should (string= (vilpy-with "\"five |is right out\"" (kbd "M-j")) 1141 | "\"five \"\n|\"is right out\"")) 1142 | (should (string= (vilpy-with "|\"five is right out\"" (kbd "M-j")) 1143 | "\n|\"five is right out\"")) 1144 | (should (string= (vilpy-with "|\"five is right out\"" 1145 | (kbd "M-f") (kbd "M-j") 1146 | (kbd "M-f") (kbd "M-j") 1147 | (kbd "M-f") (kbd "M-j")) 1148 | "\"five\"\n\" is\"\n\" right\"\n|\" out\"")) 1149 | (should (string= (vilpy-with "|\"five is right out\"" 1150 | (kbd "M-f") (kbd "M-j") 1151 | (kbd "M-f") (kbd "M-j") 1152 | (kbd "M-f") (kbd "M-j") 1153 | (kbd "M-J") (kbd "M-J") (kbd "M-J")) 1154 | "\"five is right| out\"")) 1155 | (should (string= (vilpy-with "(defun charge! ()\n (message \"[mayham]\")\n |(run-away))" (kbd "M-j")) 1156 | "(defun charge! ()\n (message \"[mayham]\"))\n|((run-away))")) 1157 | (should (string= (vilpy-with "(defun charge! ()\n |(message \"[mayham]\")\n (run-away))" (kbd "M-j")) 1158 | "(defun charge! ())\n|((message \"[mayham]\")\n (run-away))")) 1159 | (should (string= (vilpy-with "\"this|\nand that\"" (kbd "M-j")) 1160 | "\"this\"\n|\"and that\"")) 1161 | (should (string= (vilpy-with "(let ((a 1)\n |(b 2)\n (c 3))\n (+ a b c))" (kbd "M-j")) 1162 | "(let ((a 1))\n |(let ((b 2)\n (c 3))\n (+ a b c)))")) 1163 | (should (string= (vilpy-with "(let ((a 1)\n (b 2)\n |(c 3))\n (+ a b c))" (kbd "M-j")) 1164 | "(let ((a 1)\n (b 2))\n |(let ((c 3))\n (+ a b c)))")) 1165 | (should (string= (vilpy-with clojure "[1 2 |5]" (kbd "M-j")) 1166 | "[1 2]\n|[5]")) 1167 | (should (string= (vilpy-with clojure "{:chapter 2 |:verse 9}" (kbd "M-j")) 1168 | "{:chapter 2}\n|{:verse 9}")) 1169 | (should (string= (vilpy-with "(let ((x 1))\n (setq y 2|\n z 3))" (kbd "M-j")) 1170 | "(let ((x 1))\n (setq y 2)\n |(\n z 3))"))) 1171 | 1172 | 1173 | 1174 | (ert-deftest vilpy-move-up-region () 1175 | (should (string= (vilpy-with "(lisp sugar-~free|)" (vilpy-move-up 1)) 1176 | "(lisp |free~-sugar)")) 1177 | (should (string= (vilpy-with "(lisp sugar-~free|)" (progn (vilpy-move-up 1) 1178 | (vilpy-move-up 1))) 1179 | "(lisp |free~-sugar)")) 1180 | (should (string= (vilpy-with "sugar-~free|-lisp" (vilpy-move-up 1)) 1181 | "|free~-sugar-lisp")) 1182 | (should (string= (vilpy-with "sugar-free-|lisp~" (vilpy-move-up 1)) 1183 | "sugar-~lisp|-free")) 1184 | (should (string= (vilpy-with "sugar-free-|lisp~" (progn (vilpy-move-up 1) 1185 | (vilpy-move-up 1))) 1186 | "|lisp~-sugar-free"))) 1187 | 1188 | (ert-deftest vilpy-move-down-region () 1189 | (should (string= (vilpy-with "(~sugar|-free lisp)" (vilpy-move-down 1)) 1190 | "(free-~sugar| lisp)")) 1191 | (should (string= (vilpy-with "(|sugar~-free lisp)" (vilpy-move-down 1)) 1192 | "(free-|sugar~ lisp)")) 1193 | (should (string= (vilpy-with "(|sugar~-free lisp)" (progn (vilpy-move-down 1) 1194 | (vilpy-move-down 1))) 1195 | "(free-|sugar~ lisp)")) 1196 | (should (string= (vilpy-with clojure "(list\n {&:bar \"foo\"|\n :foo \"bar\"})" (vilpy-move-down 2)) 1197 | "(list\n {:foo \"bar\"\n &:bar \"foo\"|})"))) 1198 | 1199 | 1200 | 1201 | (ert-deftest vilpy-clone () 1202 | (should (string= (vilpy-with "(foo)|" (vilpy-clone 1)) 1203 | "(foo)\n(foo)|")) 1204 | (should (string= (vilpy-with "(list\n (foo)|)" (vilpy-clone 1)) 1205 | "(list\n (foo)\n (foo)|)")) 1206 | (should (string= (vilpy-with "|(foo)" (vilpy-clone 1)) 1207 | "|(foo)\n(foo)")) 1208 | (should (string= (vilpy-with "(list\n |(foo))" (vilpy-clone 1)) 1209 | "(list\n |(foo)\n (foo))")) 1210 | (should (string= (vilpy-with "(foo ~(bar)|)" (vilpy-clone 1)) 1211 | "(foo ~(bar)|\n (bar))")) 1212 | (should (string= (vilpy-with "(foo |(bar)~)" (vilpy-clone 1)) 1213 | "(foo |(bar)~\n (bar))")) 1214 | (should (string= (vilpy-with "(progn '|(foo))" (vilpy-clone 1)) 1215 | "(progn '|(foo)\n '(foo))")) 1216 | (should (string= (vilpy-with "(progn '(foo)|)" (vilpy-clone 1)) 1217 | "(progn '(foo)\n '(foo)|)")) 1218 | (should (string= (vilpy-with "(defun ~function-name| ()\n (bar))" (vilpy-clone 1)) 1219 | "(defun ~function-name|\n function-name ()\n (bar))")) 1220 | (should (string= (vilpy-with "|(+ 1 2)\n;; => 3" (vilpy-clone 1)) 1221 | "(+ 1 2)\n;; => 3\n|(+ 1 2)"))) 1222 | 1223 | (ert-deftest vilpy-oneline () 1224 | (should (string= (vilpy-with "|(defun abc (x)\n \"def.\"\n (+ x\n x\n x))" (vilpy-oneline)) 1225 | "|(defun abc (x) \"def.\" (+ x x x))")) 1226 | (should (string= (vilpy-with "(defun abc (x)\n \"def.\"\n (+ x\n x\n x))|" (vilpy-oneline)) 1227 | "(defun abc (x) \"def.\" (+ x x x))|")) 1228 | (should (string= (vilpy-with "|(defun foo ()\n ;; comment\n (bar)\n (baz))" (vilpy-oneline)) 1229 | ";; comment\n|(defun foo () (bar) (baz))")) 1230 | (should (string= (vilpy-with "(progn\n |;; comment 1\n ;; comment 2\n (foo))" (vilpy-oneline)) 1231 | "(progn\n |;; comment 1 comment 2\n (foo))")) 1232 | (should (string= (vilpy-with "|(defun test ()\n ;; comment 1\n ;; comment 2\n ;; comment 3\n (foo))" (vilpy-oneline)) 1233 | ";; comment 1\n;; comment 2\n;; comment 3\n|(defun test () (foo))")) 1234 | (should (string= (vilpy-with "[1\n 2\n 3\n 4\n 5]|" (vilpy-oneline)) 1235 | "[1 2 3 4 5]|"))) 1236 | 1237 | (ert-deftest vilpy-multiline () 1238 | (should (string= (vilpy-with "|(defun abc (x) \"def.\" (+ x x x) (foo) (bar))" 1239 | (vilpy-multiline)) 1240 | "|(defun abc (x)\n \"def.\" (+ x x x)\n (foo)\n (bar))")) 1241 | (should (string= (vilpy-with "|(defun abc(x)\"def.\"(+ x x x)(foo)(bar))" 1242 | (vilpy-multiline)) 1243 | "|(defun abc(x)\n \"def.\"(+ x x x)\n (foo)\n (bar))")) 1244 | (should (string= (vilpy-with "|(\"King Arthur\" \"Sir Lancelot\" \"Sir Robin\")" 1245 | (vilpy-multiline)) 1246 | "|(\"King Arthur\"\n \"Sir Lancelot\"\n \"Sir Robin\")"))) 1247 | 1248 | (ert-deftest vilpy-alt-multiline () 1249 | (let ((vilpy-multiline-threshold nil)) 1250 | (should (string= (vilpy-with "|(defvar knights '(lancelot robin galahad bedevere) \"We're knights of the round table...\")" "M") 1251 | "|(defvar knights '(lancelot\n robin\n galahad\n bedevere)\n \"We're knights of the round table...\")")) 1252 | (should (string= (vilpy-with "|(defun abc (x) \"def.\" (+ x x x) (foo) (bar))" "M") 1253 | "|(defun abc (x)\n \"def.\"\n (+\n x\n x\n x)\n (foo)\n (bar))")) 1254 | (should (string= (vilpy-with "|(defun abc(x)\"def.\"(+ x x x)(foo)(bar))" "M") 1255 | "|(defun abc (x)\n \"def.\"\n (+\n x\n x\n x)\n (foo)\n (bar))")) 1256 | (should (string= (vilpy-with "|(\"King Arthur\" \"Sir Lancelot\" \"Sir Robin\")" "M") 1257 | "|(\"King Arthur\"\n \"Sir Lancelot\"\n \"Sir Robin\")")) 1258 | (should (string= (vilpy-with clojure "|{:king \"Arthur\" :knight \"Lancelot\"}" "M") 1259 | "|{:king \"Arthur\"\n :knight \"Lancelot\"}")) 1260 | (should (string= (vilpy-with clojure "#|{:king \"Arthur\" :knight \"Lancelot\"}" "M") 1261 | "#|{:king \"Arthur\"\n :knight \"Lancelot\"}")) 1262 | (should (string= (vilpy-with clojure "|(let [name \"Launcelot\" quest 'grail color 'blue] (print \"Right. Off you go\"))" "M") 1263 | "|(let [name \"Launcelot\"\n quest 'grail\n color 'blue]\n (print\n \"Right. Off you go\"))")) 1264 | (should (string= (vilpy-with clojure "|(when long-enough-line #:car{:name \"a-name\" :type \"a-type\"} #:bike{:name \"a-name\" :type \"a-type\"})" "M") 1265 | "|(when\n long-enough-line\n #:car{:name \"a-name\"\n :type \"a-type\"}\n #:bike{:name \"a-name\"\n :type \"a-type\"})")) 1266 | (should (string= (vilpy-with "(eval-when-compile(require'cl)(require'org))|" "M") 1267 | "(eval-when-compile\n (require 'cl)\n (require 'org))|")) 1268 | (should (string= (vilpy-with "|(defgroup vilpy nil \"List navigation and editing for the Lisp family.\" :group 'bindings :prefix \"vilpy-\")" "M") 1269 | "|(defgroup vilpy nil\n \"List navigation and editing for the Lisp family.\"\n :group 'bindings\n :prefix \"vilpy-\")")) 1270 | (should (string= (vilpy-with "|(setq expr '(defvar defun defcustom defface))" "M") 1271 | "|(setq expr\n '(defvar\n defun\n defcustom\n defface))")) 1272 | (should (string= (vilpy-with "|(setq expr `(defvar defun defcustom defface))" "M") 1273 | "|(setq expr\n `(defvar\n defun\n defcustom\n defface))")) 1274 | (should (string= (vilpy-with "|(defun foo (bar) \"Doc.\"(interactive \"p\") (let ((var1 (foo-1 bar 1)) (var2 1) (var-3 (foo (foo bar)))) (baz bar)))" "M") 1275 | "|(defun foo (bar)\n \"Doc.\"\n (interactive \"p\")\n (let ((var1 (foo-1\n bar\n 1))\n (var2 1)\n (var-3 (foo\n (foo\n bar))))\n (baz\n bar)))")) 1276 | (should (string= (vilpy-with "|(if (and (string= ,left \"(\")\n ;; (= ?\\( (aref (this-command-keys-vector) 0))\n )\n (insert \"(\")\n (insert ,left ,right)\n (backward-char 1))" "M") 1277 | "|(if (and (string=\n ,left\n \"(\")\n ;; (= ?\\( (aref (this-command-keys-vector) 0))\n )\n (insert\n \"(\")\n (insert\n ,left\n ,right)\n (backward-char\n 1))")) 1278 | (should (string= (vilpy-with "|(foo . bar)" "M") 1279 | "|(foo . bar)")) 1280 | (should (string= (vilpy-with "|(defvar knights-alist '((\"Sir Launcelot\" . \"the Brave\") (\"Sir Galahad\" . \"the Pure\") (\"Sir Robin\" . \"Not-quite-so-brave-as-Sir-Launcelot\")) \"The wise Sir Bedemir was the first to join King Arthur's\\n knights, but other illustrious names were soon to follow:\")" "M") 1281 | "|(defvar knights-alist '((\"Sir Launcelot\" . \"the Brave\")\n (\"Sir Galahad\" . \"the Pure\")\n (\"Sir Robin\" . \"Not-quite-so-brave-as-Sir-Launcelot\"))\n \"The wise Sir Bedemir was the first to join King Arthur's\n knights, but other illustrious names were soon to follow:\")")) 1282 | (should (string= (vilpy-with "|(foo\n ;; bar\n bar)" "M") 1283 | "|(foo\n ;; bar\n bar)")) 1284 | (should (string= (vilpy-with "|(vilpy--multiline-1 '(let let*) t)" "M") 1285 | "|(vilpy--multiline-1\n '(let\n let*)\n t)")) 1286 | (should (string= (vilpy-with "|(format\n #(\"error: [h]: first, [j]: next, [k]: prev, [SPC]: rep.\"\n 8 9 (face hydra-face-red)\n 20 21 (face hydra-face-red)\n 31 32 (face hydra-face-red)\n 42 45 (face hydra-face-red)))" "M") 1287 | "|(format\n #(\"error: [h]: first, [j]: next, [k]: prev, [SPC]: rep.\"\n 8 9 (face\n hydra-face-red)\n 20 21 (face\n hydra-face-red)\n 31 32 (face\n hydra-face-red)\n 42 45 (face\n hydra-face-red)))")) 1288 | (should (string= (vilpy-with "[1 2 3 4 5]|" "M") 1289 | "[1\n 2\n 3\n 4\n 5]|")))) 1290 | 1291 | (ert-deftest vilpy-comment () 1292 | (should (string= (vilpy-with "(defun foo ()\n (let (a b c)\n (cond ((s1)\n |(s2)\n (s3)))))" ";") 1293 | "(defun foo ()\n (let (a b c)\n (cond ((s1)\n ;; (s2)\n |(s3)))))")) 1294 | (should (string= (vilpy-with "(defun foo ()\n (let (a b c)\n (cond ((s1)\n |(s2)\n (s3)))))" ";;") 1295 | "(defun foo ()\n (let (a b c)\n (cond |((s1)\n ;; (s2)\n ;; (s3)\n ))))")) 1296 | (should (string-match "(defun foo ()\n (let (a b c)\n |(cond ;; ((s1)\n ;; ;; (s2)\n ;; ;; (s3)\n ;; )\n *)))" 1297 | (vilpy-with "(defun foo ()\n (let (a b c)\n (cond ((s1)\n |(s2)\n (s3)))))" ";;;"))) 1298 | (should (string-match "(defun foo ()\n |(let (a b c)\n ;; (cond ;; ((s1)\n ;; ;; ;; (s2)\n ;; ;; ;; (s3)\n ;; ;; )\n ;; *)\n *))" 1299 | (vilpy-with "(defun foo ()\n (let (a b c)\n (cond ((s1)\n |(s2)\n (s3)))))" ";;;;"))) 1300 | (should (string-match "|(defun foo ()\n ;; (let (a b c)\n ;; ;; (cond ;; ((s1)\n ;; ;; ;; ;; (s2)\n ;; ;; ;; ;; (s3)\n ;; ;; ;; )\n ;; ;; *)\n ;; )\n )" 1301 | (vilpy-with "(defun foo ()\n (let (a b c)\n (cond ((s1)\n |(s2)\n (s3)))))" ";;;;;"))) 1302 | (should (string-match "|;; (defun foo ()\n;; ;; (let (a b c)\n;; ;; ;; (cond ;; ((s1)\n;; ;; ;; ;; ;; (s2)\n;; ;; ;; ;; ;; (s3)\n;; ;; ;; ;; )\n;; ;; ;; *)\n;; ;; )\n;; )" 1303 | (vilpy-with "(defun foo ()\n (let (a b c)\n (cond ((s1)\n |(s2)\n (s3)))))" ";;;;;;"))) 1304 | (should (string= (vilpy-with ";; line| 1\n;; line 2\n (a b c)\n ;; line 3" (vilpy-comment 2)) 1305 | "line| 1\nline 2\n (a b c)\n ;; line 3")) 1306 | (should (string= (vilpy-with ";; line 1\n;; line 2|\n (a b c)\n ;; line 3" (vilpy-comment 2)) 1307 | "line 1\nline 2|\n (a b c)\n ;; line 3")) 1308 | (should (string= (vilpy-with "(|\"foo\"\n (bar)\n baz)" ";") 1309 | "(;; \"foo\"\n |(bar)\n baz)")) 1310 | (should (string= (vilpy-with "(foo|)" ";") 1311 | "(foo\n ;; |\n )")) 1312 | (should (string= (vilpy-with "((foo)| (bar))" ";") 1313 | "((foo)\n ;; |\n (bar))")) 1314 | (should (string= (vilpy-with "((foo) (bar)|)" ";") 1315 | "((foo) (bar)\n ;; |\n )")) 1316 | (should (string= (vilpy-with "|\n(defun foo ())" ";;;") 1317 | ";;;###autoload\n|(defun foo ())")) 1318 | (should (string= (vilpy-with "(list\n |foo)" ";") 1319 | "(list\n |;; foo\n )")) 1320 | (should (string= (vilpy-with "(list\n| foo)" ";") 1321 | "(list\n |;; foo\n )")) 1322 | (should (string= (vilpy-with "(list\n |foo\n bar)" ";") 1323 | "(list\n |;; foo\n bar)")) 1324 | (should (string= (vilpy-with "|foo bar\nbaz" ";") 1325 | "|;; foo bar\nbaz")) 1326 | (should (string= (vilpy-with "(list\n foo\n |1 (2\n 3)\n bar)" ";") 1327 | "(list\n foo\n |;; 1 (2\n ;; 3)\n bar)")) 1328 | (should (string= (vilpy-with "(defun foo ()|\n (bar))" ";") 1329 | "(defun foo ()\n ;; |\n (bar))")) 1330 | (should (string= (vilpy-with "(list \\|)" ";") 1331 | "(list \\;|)")) 1332 | (should (string= (vilpy-with "(list #|)" ";") 1333 | "(list #;|)")) 1334 | ;; With single semicolons 1335 | (let ((vilpy-comment-use-single-semicolon t)) 1336 | (should (string= (vilpy-with "(foo)|" ";") 1337 | "(foo) ; |")) 1338 | (should (string= (vilpy-with "(foo) ; |" ";") 1339 | "(foo) ;; |")) 1340 | (should (string= (vilpy-with "((a)| (b))" ";") 1341 | "((a) ; |\n (b))")) 1342 | (should (string= (vilpy-with "((a) ; |\n (b))" ";") 1343 | "((a) ;; |\n (b))")) 1344 | (should (string= (vilpy-with "(foo|)" ";") 1345 | "(foo ; |\n )")) 1346 | (should (string= (vilpy-with "(foo ; |\n )" ";") 1347 | "(foo ;; |\n )")))) 1348 | 1349 | (ert-deftest vilpy-string-oneline () 1350 | (should (string= (vilpy-with "\"foo\nb|ar\n\"" (vilpy-string-oneline)) 1351 | "\"foo\\nbar\\n\"|"))) 1352 | 1353 | (ert-deftest vilpy-stringify () 1354 | (should (string= (vilpy-with "(a\n b\n (foo)\n c)|" (vilpy-stringify)) 1355 | "\"(a\n b\n (foo)\n c)|\"")) 1356 | (should (string= (vilpy-with "(progn |(1 2 3))" (vilpy-stringify)) 1357 | "(progn \"|(1 2 3)\")")) 1358 | (should (string= (vilpy-with "(foo |(bar #\\x \"baz \\\\ quux\") zot)" (vilpy-stringify)) 1359 | "(foo \"|(bar #\\\\x \\\"baz \\\\\\\\ quux\\\")\" zot)")) 1360 | (should (string= (vilpy-with "(list ~one|\n two\n five)" (vilpy-stringify)) 1361 | "(list ~\"one\"|\n two\n five)")) 1362 | (should (string= (vilpy-with "(list ~one|\n two\n five)" (progn (vilpy-stringify) 1363 | (vilpy-down 1) 1364 | (vilpy-stringify) 1365 | (vilpy-down 1) 1366 | (vilpy-stringify))) 1367 | "(list \"one\"\n \"two\"\n ~\"five\"|)"))) 1368 | 1369 | (ert-deftest vilpy-teleport () 1370 | ;; should be able to cancel 1371 | (should (string= (vilpy-with "(a |(b))" 1372 | (execute-kbd-macro (kbd "t ESC"))) 1373 | "(a |(b))")) 1374 | (should (string= (vilpy-with "(a (b)|)" 1375 | (execute-kbd-macro (kbd "t ESC"))) 1376 | "(a (b)|)")) 1377 | (should (string= (vilpy-with "((a) ~b|)" 1378 | (execute-kbd-macro (kbd "t ESC"))) 1379 | "((a) ~b|)")) 1380 | (should (string= (vilpy-with "(let ((x))\n '|(foo bar)\n (baz))" 1381 | (execute-kbd-macro (kbd "tc ESC"))) 1382 | "(let ((x '|(foo bar)))\n (baz))")) 1383 | 1384 | (should (string= (vilpy-with "((a) |b~)" 1385 | (execute-kbd-macro (kbd "t ESC"))) 1386 | "((a) |b~)"))) 1387 | 1388 | (ert-deftest vilpy-eval () 1389 | (should (= 4 (vilpy-with-v el "(+ 2 2)|" (vilpy-eval)))) 1390 | (should (= 4 (vilpy-with-v el "|(+ 2 2)" (vilpy-eval)))) 1391 | (should (= 4 (vilpy-with-v el "~(+ 2 2)|" (vilpy-eval)))) 1392 | (should (= 4 (vilpy-with-v el "(+ ~2 2)|" (vilpy-eval))))) 1393 | 1394 | (ert-deftest vilpy-eval-defun () 1395 | (should (= 5 (vilpy-with-v el "(+ 1 (+ 2 2))|" (vilpy-eval-defun)))) 1396 | (should (= 5 (vilpy-with-v el "(+ 1 (+ 2 2)|)" (vilpy-eval-defun)))) 1397 | (should (= 5 (vilpy-with-v el "(+ 1 |(+ 2 2))" (vilpy-eval-defun))))) 1398 | 1399 | (ert-deftest vilpy-quotes () 1400 | (should (string= (vilpy-with "(frob grovel |full lexical)" "\"") 1401 | "(frob grovel \"|\" full lexical)")) 1402 | (should (string= (vilpy-with "(foo \"bar |baz\" quux)" "\"") 1403 | "(foo \"bar \\\"|\\\"baz\" quux)")) 1404 | (should (string= (vilpy-with "\"(fo|o)\"" (vilpy-quotes 1)) 1405 | "(fo|o)")) 1406 | (should (string= (vilpy-with "\"(foo)\"\n|(bar)" "mk2\"") 1407 | "~(foo)|\n(bar)")) 1408 | (should (string= (vilpy-with "(message \"say |hi~\")" "\"") 1409 | "(message \"say |\\\"hi\\\"~\")")) 1410 | (should (string= (vilpy-with "|\"foo\"" "\"") 1411 | "\"|\" \"foo\"")) 1412 | (should (string= (vilpy-with "(list exp|erts)" (kbd "C-u") (kbd "\"")) 1413 | "(list \"exp|erts\")")) 1414 | (should (string= (vilpy-with "(list \"exp|erts\")" 1415 | (kbd "C-u") (kbd "\"")) 1416 | "(list exp|erts)")) 1417 | (should (string= (vilpy-with "(list ~\"experts\"|)" "\"") 1418 | "(list ~\"\\\"experts\\\"\"|)")) 1419 | (should (string= (vilpy-with "(list |\"experts\"~)" "\"") 1420 | "(list |\"\\\"experts\\\"\"~)"))) 1421 | 1422 | (ert-deftest vilpy--prettify-1 () 1423 | (should (string= (vilpy-with "|(foo (bar)baz)" (vilpy--prettify-1)) 1424 | "|(foo (bar) baz)")) 1425 | (should (string= (vilpy-with "(foo (bar)baz)|" (vilpy--prettify-1)) 1426 | "(foo (bar) baz)|")) 1427 | (should (string= (vilpy-with "|(bar\n foo )" (vilpy--prettify-1)) 1428 | "|(bar\n foo)")) 1429 | (should (string= (vilpy-with "|(foo \")\")" (vilpy--prettify-1)) 1430 | "|(foo \")\")")) 1431 | (should (string= (vilpy-with "|(foo \n bar)" (vilpy--prettify-1)) 1432 | "|(foo\n bar)")) 1433 | (should (string= (vilpy-with "|(require' foo)" (vilpy--prettify-1)) 1434 | "|(require 'foo)")) 1435 | (should (string= (vilpy-with clojure 1436 | "|(expr ~(expr) ~'expr '~(expr) ~'(expr) ~@(expr))" 1437 | (vilpy--prettify-1)) 1438 | "|(expr ~(expr) ~'expr '~(expr) ~'(expr) ~@(expr))"))) 1439 | 1440 | (ert-deftest vilpy-open-line-below () 1441 | (should (string= (vilpy-with "|(foo)" (vilpy-open-line-below)) 1442 | "(foo)\n|")) 1443 | (should (string= (vilpy-with "(foo)|" (vilpy-open-line-below)) 1444 | "(foo)\n|")) 1445 | (should (string= (vilpy-with "(foo\n|(bar)\n(baz)" (vilpy-open-line-below)) 1446 | "(foo\n(bar)\n|\n(baz)"))) 1447 | 1448 | (ert-deftest vilpy-open-line-above () 1449 | (let ((result (vilpy-with "(foo\n|(bar))" (vilpy-open-line-above))) 1450 | (expected "(foo\n |\n(bar))")) 1451 | (should (string= (vilpy-with "(foo\n|(bar))" (vilpy-open-line-above)) 1452 | "(foo\n |\n(bar))")) 1453 | (should (string= (vilpy-with "(foo\n(bar)|)" (vilpy-open-line-above)) 1454 | "(foo\n |\n(bar))")))) 1455 | 1456 | (ert-deftest vilpy--sexp-normalize () 1457 | (should (equal 1458 | (vilpy--sexp-normalize 1459 | '(progn 1460 | (ly-raw comment "foo") 1461 | (ly-raw newline))) 1462 | '(progn 1463 | (ly-raw comment "foo") 1464 | (ly-raw newline))))) 1465 | 1466 | (ert-deftest vilpy--remove-gaps () 1467 | (should (string= (vilpy-with "((a) |(c))" (vilpy--remove-gaps)) 1468 | "((a) |(c))"))) 1469 | 1470 | (ert-deftest vilpy-mark () 1471 | (should (string= (vilpy-with "|;; abc\n;; def\n;; ghi" (kbd "C-M-,")) 1472 | "~;; abc\n;; def\n;; ghi|")) 1473 | (should (string= (vilpy-with ";; a|bc\n;; def\n;; ghi" (kbd "C-M-,")) 1474 | "~;; abc\n;; def\n;; ghi|")) 1475 | (should (string= (vilpy-with ";; abc\n|;; def\n;; ghi" (kbd "C-M-,")) 1476 | "~;; abc\n;; def\n;; ghi|")) 1477 | (should (string= (vilpy-with ";; abc\n;; def\n;; ghi|" (kbd "C-M-,")) 1478 | "~;; abc\n;; def\n;; ghi|"))) 1479 | 1480 | (ert-deftest vilpy-mark-symbol () 1481 | (should (string= (vilpy-with "(foo |\"bar\")" (kbd "M-m")) 1482 | "(foo ~\"bar\"|)")) 1483 | (should (string= (vilpy-with "(foo \"bar|\")" (kbd "M-m")) 1484 | "(foo ~\"bar\"|)")) 1485 | (should (string= (vilpy-with "(mapc #'ta|unt knights)" (kbd "M-m")) 1486 | "(mapc ~#'taunt| knights)")) 1487 | (should (string= (vilpy-with "|(foo)" (kbd "M-m")) 1488 | "(~foo|)")) 1489 | (should (string= (vilpy-with "(foo|)" (kbd "M-m")) 1490 | "(~foo|)")) 1491 | (should (string= (vilpy-with "|[foo]" (kbd "M-m")) 1492 | "[~foo|]")) 1493 | (should (string= (vilpy-with clojure "|{foo}" (kbd "M-m")) 1494 | "{&foo|}")) 1495 | (should (string= (vilpy-with "(foo \"|bar\")" (kbd "M-m")) 1496 | "(foo \"~bar|\")")) 1497 | (should (string= (vilpy-with "\"See `plu|mage'.\"" (kbd "M-m")) 1498 | "\"See ~`plumage'|.\"")) 1499 | (should (string= (vilpy-with ";; See `plu|mage'." (kbd "M-m")) 1500 | ";; See ~`plumage'|.")) 1501 | (should (string= (vilpy-with "(list {:key args})|" (kbd "M-m")) 1502 | "(list {:key |args~})")) 1503 | (should (string= (vilpy-with "|[\"string with spaces\"]" (kbd "M-m")) 1504 | "[\"~string| with spaces\"]")) 1505 | (should (string= (vilpy-with clojure "|{\"string with spaces\"}" (kbd "M-m")) 1506 | "{\"&string| with spaces\"}")) 1507 | (should (string= (vilpy-with "(defn fname \"string\"| )" (kbd "M-m")) 1508 | "(defn fname ~\"string\"| )")) 1509 | (should (string= (vilpy-with "(defn fname \"string\"| [] (symbols in a form))" (kbd "M-m")) 1510 | "(defn fname ~\"string\"| [] (symbols in a form))")) 1511 | (should (string= (vilpy-with "|(\"a\")" (kbd "M-m")) 1512 | "(\"~a|\")")) 1513 | (should (string= (vilpy-with "(\"string\" |)" (kbd "M-m")) 1514 | "(~\"string\"| )")) 1515 | (should (string= (vilpy-with "(:keyword| (form))" (kbd "M-m")) 1516 | "(~:keyword| (form))"))) 1517 | 1518 | (ert-deftest vilpy--read () 1519 | (should (equal (vilpy--read "(mu4e-mail)") 1520 | '(mu4e-mail))) 1521 | (should (equal (vilpy--read "(progn 1522 | #'foo 1523 | (ly-raw function foo) 1524 | (function foo) 1525 | \"#'bar\" 1526 | \"(ly-raw)\" 1527 | #'bar)") 1528 | '(progn (ly-raw newline) 1529 | (ly-raw function foo) 1530 | (ly-raw newline) 1531 | (ly-raw raw function foo) 1532 | (ly-raw newline) 1533 | #'foo 1534 | (ly-raw newline) 1535 | (ly-raw string "\"#'bar\"") 1536 | (ly-raw newline) 1537 | (ly-raw string "\"(ly-raw)\"") 1538 | (ly-raw newline) 1539 | (ly-raw function bar)))) 1540 | (should (equal (vilpy--read "(helm :sources 1541 | `((name . \"this defun\") 1542 | (match-strict . 1543 | (lambda (x)))))") 1544 | '(helm :sources (ly-raw newline) 1545 | (ly-raw \` ((name (ly-raw dot) 1546 | (ly-raw string "\"this defun\"")) 1547 | (ly-raw newline) 1548 | (match-strict (ly-raw dot) 1549 | (ly-raw newline) 1550 | (lambda (x)))))))) 1551 | ;; (should (equal 1552 | ;; (vilpy-with clojure 1553 | ;; "|(fn* [p1__7041#] (+ 1 p1__7041#))" "i") 1554 | ;; "|(fn* [p1__7041#] (+ 1 p1__7041#))")) 1555 | (should (equal 1556 | (vilpy-with clojure 1557 | "|(s/? ::spec)" (vilpy-tab)) 1558 | "|(s/? ::spec)")) 1559 | (should (equal 1560 | (vilpy--prin1-to-string 1561 | (vilpy--read "#") 1562 | 0 'emacs-lisp-mode) 1563 | "#")) 1564 | (should (equal 1565 | (vilpy--prin1-to-string 1566 | (vilpy--read "(1 2 3 1 2 . #2)") 1567 | 0 'emacs-lisp-mode) 1568 | "(1 2 3 1 2 . #2)")) 1569 | (let ((major-mode 'emacs-lisp-mode)) 1570 | (should (equal (vilpy--read "(progn `(lambda () ,(+ 2 2) ,@(number-sequence 1 3)))") 1571 | '(progn 1572 | (ly-raw \` (lambda (ly-raw empty) (ly-raw \, (+ 2 2)) (ly-raw comma-splice (number-sequence 1 3)))))))) 1573 | (should (equal 1574 | (vilpy--read "#(\"]\" 0 1 (face hydra-face-red))") 1575 | '(ly-raw clojure-lambda ((ly-raw string "\"]\"") 1576 | 0 1 (face hydra-face-red))))) 1577 | (should (equal 1578 | (vilpy--read "#p\"path\"") 1579 | '(ly-raw lisp-macro "#p\"path\""))) 1580 | (should (equal 1581 | (vilpy--read "#m(foo bar)") 1582 | '(ly-raw lisp-macro "#m(foo bar)"))) 1583 | (should (equal 1584 | (vilpy--read ",(or body)") 1585 | '(ly-raw \, (or body)))) 1586 | (should (equal (vilpy-with-v clj 1587 | "|(list \\a \\b \\. \\, \\c \\space \\tab \\u03A9)" 1588 | (vilpy--read (vilpy--string-dwim))) 1589 | '((ly-raw clojure-symbol "list") 1590 | (ly-raw clojure-char "\\a") 1591 | (ly-raw clojure-char "\\b") 1592 | (ly-raw clojure-char "\\.") 1593 | (ly-raw clojure-char "\\,") 1594 | (ly-raw clojure-char "\\c") 1595 | (ly-raw clojure-char "\\space") 1596 | (ly-raw clojure-char "\\tab") 1597 | (ly-raw clojure-char "\\u03A9")))) 1598 | (should (equal (vilpy-with-v clj 1599 | "|(str \\! \\@ \\# \\$ \\% \\& \\*)" 1600 | (vilpy--read (vilpy--string-dwim))) 1601 | '((ly-raw clojure-symbol "str") 1602 | (ly-raw clojure-char "\\!") 1603 | (ly-raw clojure-char "\\@") 1604 | (ly-raw clojure-char "\\#") 1605 | (ly-raw clojure-char "\\$") 1606 | (ly-raw clojure-char "\\%") 1607 | (ly-raw clojure-char "\\&") 1608 | (ly-raw clojure-char "\\*")))) 1609 | (should (equal (vilpy-with-v clj 1610 | "|(foo \"#_(bar)\")" 1611 | (vilpy--read (vilpy--string-dwim))) 1612 | '((ly-raw clojure-symbol "foo") 1613 | (ly-raw string "\"#_(bar)\"")))) 1614 | (should (equal (vilpy-with-v clj 1615 | "|{:a {:nested \"map\"}}" 1616 | (vilpy--read (vilpy--string-dwim))) 1617 | '(ly-raw clojure-map 1618 | ((ly-raw clojure-symbol ":a") 1619 | (ly-raw clojure-map 1620 | ((ly-raw clojure-symbol ":nested") 1621 | (ly-raw string "\"map\""))))))) 1622 | (should (equal (vilpy-with-v clj 1623 | "|#(swap! foo assoc :bar (. % .-value))" 1624 | (vilpy--read (vilpy--string-dwim))) 1625 | '(ly-raw clojure-lambda 1626 | ((ly-raw clojure-symbol "swap!") 1627 | (ly-raw clojure-symbol "foo") 1628 | (ly-raw clojure-symbol "assoc") 1629 | (ly-raw clojure-symbol ":bar") 1630 | ((ly-raw clojure-symbol ".") % (ly-raw clojure-symbol ".-value")))))) 1631 | (should (equal (vilpy--read ":.name") 1632 | '(ly-raw clojure-keyword ":.name")))) 1633 | 1634 | (ert-deftest vilpy-tick () 1635 | (should (string= (vilpy-with "|" "'") "'|")) 1636 | (should (string= (vilpy-with "|" "`") "`|")) 1637 | (should (string= (vilpy-with "~\"right\"|" "'") 1638 | "~right|")) 1639 | (should (string= (vilpy-with "|\"right\"~" "'") 1640 | "|right~")) 1641 | (should (string= (vilpy-with clojure "foo|" "'") 1642 | "foo '|")) 1643 | (should (string= (vilpy-with clojure "foo|" " ~'") 1644 | "foo ~'|")) 1645 | (should (string= (vilpy-with "(setq foo ~bar|)" "'") 1646 | "(setq foo ~'bar|)")) 1647 | (should (string= (vilpy-with "(setq foo ~'bar|)" "'") 1648 | "(setq foo ~bar|)"))) 1649 | 1650 | (ert-deftest vilpy-underscore () 1651 | (should (string= (vilpy-with clojure "(list |[1 2 3]\n [3 4 5])" "_") 1652 | "(list #_|[1 2 3]\n [3 4 5])")) 1653 | (should (string= (vilpy-with clojure "(list #_|[1 2 3]\n [3 4 5])" "_") 1654 | "(list |[1 2 3]\n [3 4 5])")) 1655 | (should (string= (vilpy-with clojure "(list [1 2 3]|\n [3 4 5])" "_") 1656 | "(list #_[1 2 3]|\n [3 4 5])")) 1657 | (should (string= (vilpy-with clojure "(list #_[1 2 3]|\n [3 4 5])" "_") 1658 | "(list [1 2 3]|\n [3 4 5])"))) 1659 | 1660 | (ert-deftest vilpy-parens () 1661 | (should (string= (vilpy-with "'|(foo bar)" "1(") 1662 | "(| '(foo bar))")) 1663 | (should (string= (vilpy-with "'(foo bar)|" "1(") 1664 | "(| '(foo bar))")) 1665 | (should (string= (vilpy-with "\"a regex \\\\|\"" "(") 1666 | "\"a regex \\\\(|\\\\)\"")) 1667 | (let (vilpy-parens-only-left-in-string-or-comment) 1668 | (should (string= (vilpy-with "\"|\"" "(") 1669 | "\"(|)\"")) 1670 | (should (string= (vilpy-with ";; |" "(") 1671 | ";; (|)"))) 1672 | (should (string= (vilpy-with "~(foo) (bar)|" "(") 1673 | "(| (foo) (bar))")) 1674 | (should (string= (vilpy-with "~foo (bar)|" "(") 1675 | "|(foo (bar))")) 1676 | (should (string= (vilpy-with "~foo (bar)|" "1(") 1677 | "(| foo (bar))")) 1678 | (should (string= (vilpy-with "(foo bar|)" "1(") 1679 | "(foo (| bar))")) 1680 | (should (string= (vilpy-with "(foo bar| )" "1(") 1681 | "(foo (| bar) )")) 1682 | (should (string= (vilpy-with "{|}" "(") 1683 | "{(|)}")) 1684 | (should (string= (vilpy-with "(defun foo (x)\n |)" "1(") 1685 | "(defun foo (x)\n (|))")) 1686 | ;; test space-unless behavior 1687 | (should (string= (vilpy-with "a|" "(") 1688 | "a (|)")) 1689 | (should (string= (vilpy-with ",@|" "(") 1690 | ",@(|)")) 1691 | (should (string= (vilpy-with clojure "#|" "(") 1692 | "#(|)")) 1693 | (should (string= (vilpy-with clojure "#?@|" "(") 1694 | "#?@(|)")) 1695 | (should (string= (vilpy-with clojure "(map #|(+ % 1) '(1 2 3))" "2(") 1696 | "(map #(| (+ % 1)) '(1 2 3))"))) 1697 | 1698 | (ert-deftest vilpy-braces () 1699 | (should (string= (vilpy-with "\"a regex \\\\|\"" "{") 1700 | "\"a regex \\\\{|\\\\}\"")) 1701 | (should (string= (vilpy-with "\"a string |" "{") 1702 | "\"a string {|}")) 1703 | ;; test space-unless behavior 1704 | (should (string= (vilpy-with clojure "`|" "{") 1705 | "`{|}")) 1706 | (should (string= (vilpy-with clojure "^|" "{") 1707 | "^{|}")) 1708 | (should (string= (vilpy-with clojure "#my.record|" "{") 1709 | "#my.record{|}")) 1710 | (should (string= (vilpy-with clojure "symbol|" "{") 1711 | "symbol {|}"))) 1712 | 1713 | (ert-deftest vilpy-up-slurp () 1714 | (should (string= (vilpy-with "(progn\n (foo))\n|(bar)" (vilpy-up-slurp)) 1715 | "(progn\n (foo)\n |(bar))")) 1716 | (should (string= (vilpy-with "(progn\n (foo))\n(bar)|" (vilpy-up-slurp)) 1717 | "(progn\n (foo)\n (bar)|)")) 1718 | (should (string= (vilpy-with "(progn\n (foo))\n~(bar)|" (vilpy-up-slurp)) 1719 | "(progn\n (foo)\n ~(bar)|)")) 1720 | (should (string= (vilpy-with "(progn\n (foo))\n|(bar)~" (vilpy-up-slurp)) 1721 | "(progn\n (foo)\n |(bar)~)")) 1722 | (should (string= (vilpy-with "(progn\n (foo))\n|(bar)\n(baz)~" (vilpy-up-slurp)) 1723 | "(progn\n (foo)\n |(bar)\n (baz)~)")) 1724 | (should (string= (vilpy-with "[foo] |(bar)" (vilpy-up-slurp)) 1725 | "[foo |(bar)]")) 1726 | (should (string= (vilpy-with "(progn\n (foo))\n~(bar)\n(baz)|" (vilpy-up-slurp)) 1727 | "(progn\n (foo)\n ~(bar)\n (baz)|)")) 1728 | (should (string= (vilpy-with "(let ((a (1+))))\n|" (vilpy-up-slurp)) 1729 | "(let ((a (1+)))\n |)")) 1730 | (should (string= (vilpy-with "(let ((a (1+)))\n |)" (vilpy-up-slurp)) 1731 | "(let ((a (1+))\n |))")) 1732 | (should (string= (vilpy-with "(let ((a (1+))\n |))" (vilpy-up-slurp)) 1733 | "(let ((a (1+)\n |)))")) 1734 | (should (string= (vilpy-with "(let ((a (1+)\n |)))" (vilpy-up-slurp)) 1735 | "(let ((a (1+\n |))))")) 1736 | ;; no change should be made here 1737 | (should (string= (vilpy-with "(let ((a (1+\n |))))" (vilpy-up-slurp)) 1738 | "(let ((a (1+\n |))))"))) 1739 | 1740 | (ert-deftest vilpy-tab () 1741 | (should (string= (vilpy-with "|(defun test? (x) x)" (vilpy-tab)) 1742 | "|(defun test? (x) x)")) 1743 | (should (string= (vilpy-with "|(list '{foobar)" (vilpy-tab)) 1744 | "|(list '{foobar)")) 1745 | (should (string= (vilpy-with "|(setq x '(\n \n ))" (vilpy-tab)) 1746 | "|(setq x '())")) 1747 | (should (string= (vilpy-with "|(eq (char-before) ?\\()" (vilpy-tab)) 1748 | "|(eq (char-before) ?\\()")) 1749 | (should (string= (vilpy-with "`|[1 2 3]" (vilpy-tab)) 1750 | "`|[1 2 3]")) 1751 | (should (string= (vilpy-with " |(defun)" (vilpy-tab)) 1752 | "|(defun)")) 1753 | (should (string= (vilpy-with "|;; comment 1\n;; comment 2" (vilpy-tab)) 1754 | "|;; comment 1\n;; comment 2")) 1755 | (should (string= (vilpy-with "|(list \"\\\"\")" (vilpy-tab)) 1756 | "|(list \"\\\"\")")) 1757 | (should (string= (vilpy-with "|(modify-syntax-entry ?' \"\\\"\" table)" (vilpy-tab)) 1758 | "|(modify-syntax-entry ?' \"\\\"\" table)")) 1759 | (should (string= (vilpy-with clojure "|(let [:foo :bar\n:bax :xum])" (vilpy-tab)) 1760 | "|(let [:foo :bar\n :bax :xum])")) 1761 | (should (equal (vilpy-with "|(pcase :bar\n (`,pat pat))" (vilpy-tab)) 1762 | "|(pcase :bar\n (`,pat pat))")) 1763 | (should (equal (vilpy-with "'|(27 ?\\C-g)" (vilpy-tab)) 1764 | "'|(27 ?\\C-g)"))) 1765 | 1766 | (defun vilpy-test-normalize () 1767 | (interactive) 1768 | (goto-char (point-min)) 1769 | (catch 'break 1770 | (let ((pt (point))) 1771 | (while (not (buffer-modified-p)) 1772 | (setq pt (max pt (point))) 1773 | (vilpy-down 1) 1774 | (if (< (point) pt) 1775 | (throw 'break nil)) 1776 | (vilpy-tab))))) 1777 | 1778 | (ert-deftest vilpy-mark-list () 1779 | (should (string= (vilpy-with "|;; foo\n(bar)" (vilpy-mark-list 1)) 1780 | "~;; foo|\n(bar)")) 1781 | (should (string= (vilpy-with "~;; foo|\n(bar)" (vilpy-mark-list 1)) 1782 | "|;; foo\n(bar)")) 1783 | (should (string= (vilpy-with "~(foo bar)|" (vilpy-mark-list 0)) 1784 | "(~foo bar|)")) 1785 | (should (string= (vilpy-with "(progn ,@(cdr re)|)" (vilpy-mark-list 1)) 1786 | "(progn |,@(cdr re)~)")) 1787 | (should (string= (vilpy-with "(progn ,@(cdr re)|)" (progn (vilpy-mark-list 1) 1788 | (vilpy-mark-list 1))) 1789 | "(progn ,@|(cdr re))")) 1790 | (should (string= (vilpy-with "(progn ,@|(cdr re))" (vilpy-mark-list 1)) 1791 | "(progn ~,@(cdr re)|)")) 1792 | (should (string= (vilpy-with "(progn ,@|(cdr re))" (progn (vilpy-mark-list 1) 1793 | (vilpy-mark-list 1))) 1794 | "(progn ,@(cdr re)|)")) 1795 | (should (string= (vilpy-with clojure "#|{:bar 'baz}" (vilpy-mark-list 0)) 1796 | "#{&:bar 'baz|}")) 1797 | (should (string= (vilpy-with "#2A|((a b) (0 1))" (vilpy-mark-list 1)) 1798 | "~#2A((a b) (0 1))|"))) 1799 | 1800 | (ert-deftest vilpy-mark-car () 1801 | (should (string= (vilpy-with "|\"foo\"~" (vilpy-tab)) 1802 | "\"~foo|\"")) 1803 | (should (string= (vilpy-with "~'(\n foo)|" (vilpy-tab)) 1804 | "'(\n ~foo|)")) 1805 | (should (string= (vilpy-with "|'(\n foo)~" (vilpy-tab)) 1806 | "'(\n ~foo|)")) 1807 | (should (string= (vilpy-with 1808 | "|(add-to-list 'auto-mode-alist '(\"\\\\.cache\\\\'\" . emacs-lisp-mode))" 1809 | (progn (vilpy-mark-list 1) 1810 | (vilpy-tab))) 1811 | "(~add-to-list| 'auto-mode-alist '(\"\\\\.cache\\\\'\" . emacs-lisp-mode))")) 1812 | (should (string= (vilpy-with 1813 | "|(add-to-list 'auto-mode-alist '(\"\\\\.cache\\\\'\" . emacs-lisp-mode))" 1814 | (progn (vilpy-mark-list 1) 1815 | (vilpy-tab) 1816 | (vilpy-down 1) 1817 | (vilpy-tab))) 1818 | "(add-to-list '~auto-mode-alist| '(\"\\\\.cache\\\\'\" . emacs-lisp-mode))")) 1819 | (should (string= (vilpy-with "\"See ~`plumage'|.\"" (vilpy-tab)) 1820 | "\"See `~plumage|'.\"")) 1821 | (should (string= (vilpy-with "(list ~\"one\" \"two\"|)" (vilpy-tab)) 1822 | "(list ~\"one\"| \"two\")"))) 1823 | 1824 | (ert-deftest vilpy-beginning-of-defun () 1825 | (should (string= (vilpy-with "(baz)\n(foo (b|ar))" 1826 | (vilpy-beginning-of-defun)) 1827 | "(baz)\n|(foo (bar))")) 1828 | (should (string= (vilpy-with "(baz)\n(foo |(bar))" (vilpy-beginning-of-defun)) 1829 | "(baz)\n|(foo (bar))")) 1830 | ;; (should (string= (vilpy-with "(baz)\n(foo |(bar))" "AA") 1831 | ;; "(baz)\n(foo |(bar))")) 1832 | (should (string= (vilpy-with "(baz)\n(foo (|bar~))" (vilpy-beginning-of-defun)) 1833 | "(baz)\n|(foo (bar))")) 1834 | ;; (should (string= (vilpy-with "(baz)\n(foo (|bar~))" "AA") 1835 | ;; "(baz)\n(foo (|bar~))")) 1836 | ) 1837 | 1838 | (ert-deftest vilpy-space () 1839 | (should (string= (vilpy-with "(|foo" " ") 1840 | "(| foo")) 1841 | (should (string= (vilpy-with "(| foo)" " ") 1842 | "(|foo)")) 1843 | (should (string= (vilpy-with "|(foo bar)" "2 ") 1844 | "(| foo bar)")) 1845 | (should (string= (vilpy-with "(foo bar)|" "2 ") 1846 | "(foo bar |)")) 1847 | (should (string= (vilpy-with "|(foo bar)" "3 ") 1848 | "(foo bar |)")) 1849 | (should (string= (vilpy-with "(foo bar)|" "3 ") 1850 | "(| foo bar)")) 1851 | (should (string= (vilpy-with "(foo (bar)|)" " ") 1852 | "(foo (bar) |)")) 1853 | (should (string= (vilpy-with "(foo (bar)|)" "4 ") 1854 | "(foo (bar\n |))")) 1855 | (should (string= (vilpy-with "(foo |(bar))" "4 ") 1856 | "(foo (bar\n |))")) 1857 | (should (string= (vilpy-with "|(progn\n (foo)\n )" "4 ") 1858 | "(progn\n (foo)\n |)")) 1859 | (should (string= (vilpy-with "(progn\n (foo)\n )|" "4 ") 1860 | "(progn\n (foo)\n |)")) 1861 | (should (string= (vilpy-with "[|()]" " ") 1862 | "[| ()]")) 1863 | (should (string= (vilpy-with "{|()}" " ") 1864 | "{| ()}")) 1865 | (should (string= (vilpy-with "|(cdr )" "3 ") 1866 | "(cdr |)")) 1867 | (should (string= (vilpy-with "foo\"[|]\"" " ") 1868 | "foo\"[ |]\"")) 1869 | (should (string= (vilpy-with clojure "(list \\(|)" " ") 1870 | "(list \\( |)"))) 1871 | 1872 | (ert-deftest vilpy-kill-word () 1873 | (should (string= (vilpy-with "| (require 'cl)" (kbd "M-d")) 1874 | " (| 'cl)")) 1875 | (should (string= (vilpy-with "| \"(require 'cl)\"" (kbd "M-d")) 1876 | " \"(| 'cl)\"")) 1877 | (should (string= (vilpy-with "\"(require |'cl)\"" (kbd "M-d")) 1878 | "\"(require '|)\"")) 1879 | (should (string= (vilpy-with "\"(require '|)\"" (kbd "M-d")) 1880 | "\"(require ')\"|")) 1881 | (should (string= (vilpy-with "(foo \"|bar\")" (kbd "M-d")) 1882 | "(foo \"|\")")) 1883 | (should (string= (vilpy-with "(foo |\"bar\")" (kbd "M-d")) 1884 | "(foo \"|\")")) 1885 | (should (string= (vilpy-with "\"(require |'cl)\"" (vilpy-kill-word -1)) 1886 | "\"(|'cl)\"")) 1887 | (should (string= (vilpy-with "(defun |test)" (kbd "M-d")) 1888 | "(defun |)")) 1889 | (should (string= (vilpy-with "\"this is a |test\"" (kbd "M-d")) 1890 | "\"this is a |\""))) 1891 | 1892 | (ert-deftest vilpy-backward-kill-word () 1893 | (should (string= (vilpy-with "(require 'cl)|" (kbd "M-DEL")) 1894 | "(require '|)")) 1895 | (should (string= (vilpy-with "(require 'cl)|" (kbd "M-DEL") (kbd "C-y")) 1896 | "(require 'cl|)")) 1897 | (should (string= (vilpy-with "(eval-after-load |)" (kbd "M-DEL")) 1898 | "(eval-after-|)")) 1899 | (should (string= (vilpy-with "(eval-after-load |)" 1900 | (kbd "M-DEL") (kbd "M-DEL")) 1901 | "(eval-|)")) 1902 | (should (string= (vilpy-with "(eval-after-load |)" 1903 | (kbd "M-DEL") (kbd "M-DEL") (kbd "C-y")) 1904 | "(eval-after-load |)")) 1905 | (should (string= (vilpy-with "(eval-after-load \"foo\")|" (kbd "M-DEL")) 1906 | "(eval-after-load \"|\")")) 1907 | (should (string= (vilpy-with "(eval-after-load \"|\")" (kbd "M-DEL")) 1908 | "(eval-after-| \"\")")) 1909 | (should (string= (vilpy-with "\"foo bar \"|" (kbd "M-DEL")) 1910 | "\"foo |\"")) 1911 | (should (string= (vilpy-with "\"\\nfoo\"|" (kbd "M-DEL")) 1912 | "\"|\"")) 1913 | (should (string= (vilpy-with "\"\\nfoo\"|" (kbd "M-DEL")) 1914 | "\"|\"")) 1915 | (should (string= (vilpy-with "\"Five is right| out\"" (kbd "M-DEL")) 1916 | "\"Five is | out\"")) 1917 | (should (string= (vilpy-with "\"Five is right| out\"" 1918 | (kbd "M-DEL") 1919 | (kbd "M-DEL")) 1920 | "\"Five | out\"")) 1921 | (should (string= (vilpy-with "(nil nil |:color blue)" (kbd "M-DEL")) 1922 | "(nil |:color blue)")) 1923 | (should (string= (vilpy-with "\"\\n |\"" (kbd "M-DEL")) 1924 | "\"|\""))) 1925 | 1926 | (ert-deftest vilpy-hash () 1927 | (should (string= (vilpy-with clojure "foo|" "#") 1928 | "foo #|")) 1929 | (should (string= (vilpy-with clojure "foo|" "##") 1930 | "foo#|"))) 1931 | 1932 | (ert-deftest vilpy-newline-and-indent-plain () 1933 | (message "vilpy-newline-and-indent-plain") 1934 | (should (string= (vilpy-with "(mapc #'|say-ni\n knights)" (kbd "RET")) 1935 | "(mapc\n #'|say-ni\n knights)")) 1936 | (should (string= (vilpy-with "(mapc #'|say-ni\n knights)" (kbd "C-j")) 1937 | "(mapc\n #'|say-ni\n knights)"))) 1938 | 1939 | (ert-deftest vilpy-knight-down () 1940 | (should (string= (vilpy-with "|(defun foo ()\n (bar)\n (baz))" 1941 | (vilpy-knight-down)) 1942 | "(defun foo ()\n |(bar)\n (baz))"))) 1943 | 1944 | (ert-deftest vilpy-knight-up () 1945 | (should (string= (vilpy-with "(defun foo ()\n |(bar)\n (baz))" 1946 | (vilpy-knight-up)) 1947 | "|(defun foo ()\n (bar)\n (baz))"))) 1948 | 1949 | (ert-deftest vilpy-ace-char () 1950 | (should (string= (vilpy-with "|(cons 'norwegian 'blue)" 1951 | (execute-kbd-macro (kbd "Qob"))) 1952 | "(cons 'n|orwegian 'blue)"))) 1953 | 1954 | (ert-deftest vilpy-ace-paren () 1955 | (should (string= (vilpy-with "|(progn (setq type 'norwegian-blue)\n (setq plumage-type 'lovely))" 1956 | (execute-kbd-macro (kbd "qb"))) 1957 | "(progn |(setq type 'norwegian-blue)\n (setq plumage-type 'lovely))")) 1958 | (should (string= (vilpy-with "|(progn (setq type 'norwegian-blue)\n (setq plumage-type 'lovely))" 1959 | (execute-kbd-macro (kbd "qc"))) 1960 | "(progn (setq type 'norwegian-blue)\n |(setq plumage-type 'lovely))")) 1961 | (should (string= (vilpy-with "(progn (setq type 'norwegian-blue)\n |(setq plumage-type 'lovely))" 1962 | (execute-kbd-macro (kbd "qa"))) 1963 | "|(progn (setq type 'norwegian-blue)\n (setq plumage-type 'lovely))"))) 1964 | 1965 | (ert-deftest vilpy-ace-symbol () 1966 | (let ((avy-keys-alist nil)) 1967 | (should (string= (vilpy-with "|(progn (setq type 'norwegian-blue)\n (setq plumage-type 'lovely))" 1968 | (execute-kbd-macro (kbd "fb"))) 1969 | "(progn (~setq| type 'norwegian-blue)\n (setq plumage-type 'lovely))")) 1970 | (should (string= (vilpy-with "|(progn (setq type 'norwegian-blue)\n (setq plumage-type 'lovely))" 1971 | (execute-kbd-macro (kbd "fc"))) 1972 | "(progn (setq ~type| 'norwegian-blue)\n (setq plumage-type 'lovely))")) 1973 | (should (string= (vilpy-with "(progn (setq type 'norwegian-blue)\n |(setq plumage-type 'lovely))" 1974 | (execute-kbd-macro (kbd "fa"))) 1975 | "(progn (setq type 'norwegian-blue)\n (~setq| plumage-type 'lovely))")))) 1976 | 1977 | (ert-deftest vilpy-ace-subword () 1978 | (should (string= (vilpy-with "|foo-bar-baz~" (vilpy-ace-subword 1)) 1979 | "~foo|-bar-baz")) 1980 | (should (string= (vilpy-with "|(progn (setq type 'norwegian-blue)\n (setq plumage-type 'lovely))" 1981 | (execute-kbd-macro (kbd "-g"))) 1982 | "(progn (setq type 'norwegian-blue)\n (setq |plumage~-type 'lovely))")) 1983 | (should (string= (vilpy-with "|(progn (setq type 'norwegian-blue)\n (setq plumage-type 'lovely))" 1984 | (execute-kbd-macro (kbd "-e"))) 1985 | "(progn (setq type 'norwegian-|blue~)\n (setq plumage-type 'lovely))")) 1986 | ;; should be able to cancel 1987 | (should (string= (vilpy-with "|(a b c)" 1988 | (execute-kbd-macro (kbd "- ESC"))) 1989 | "|(a b c)"))) 1990 | 1991 | (ert-deftest vilpy-paste () 1992 | (should (string= (vilpy-with "|(a witch)" 1993 | (progn (vilpy-copy) 1994 | (vilpy-paste 2))) 1995 | "(a (a witch)| witch)")) 1996 | (should (string= (vilpy-with "|(a witch)" 1997 | (progn (vilpy-copy) 1998 | (vilpy-paste 3))) 1999 | "(a witch (a witch)|)")) 2000 | (should (string= (vilpy-with "(progn\n |(one)\n (two)\n (three))" 2001 | (progn (vilpy-copy) 2002 | (vilpy-down 1) 2003 | (vilpy-paste 1))) 2004 | "(progn\n (one)\n (one)|\n (two)\n (three))")) 2005 | (should (string= (vilpy-with "(progn\n |(one)\n (two)\n (three))" 2006 | (progn (vilpy-copy) 2007 | (vilpy-down 2) 2008 | (vilpy-paste 1))) 2009 | "(progn\n (one)\n (two)\n (one)|\n (three))")) 2010 | (should (string= (vilpy-with "(progn\n (one)|\n (two)\n (three))" 2011 | (progn (vilpy-copy) 2012 | (vilpy-down 1) 2013 | (vilpy-paste 1))) 2014 | "(progn\n (one)\n (two)\n (one)|\n (three))")) 2015 | (should (string= (vilpy-with "(progn\n (one)|\n (two)\n (three))" 2016 | (progn (vilpy-copy) 2017 | (vilpy-down 2) 2018 | (vilpy-paste 1))) 2019 | "(progn\n (one)\n (two)\n (three)\n (one)|)"))) 2020 | 2021 | (ert-deftest vilpy--balance () 2022 | (should (string= (vilpy--balance "(a") 2023 | "(a)")) 2024 | (should (string= (vilpy--balance "a)") 2025 | "(a)")) 2026 | (should (string= (vilpy--balance "a)(b") 2027 | "(a)(b)")) 2028 | (should (string= (vilpy--balance "({[a b] c") 2029 | "({[a b] c})")) 2030 | (should (string= (vilpy--balance "a [b c]})") 2031 | "({a [b c]})")) 2032 | (should (string= (vilpy--balance "a)]}({[b") 2033 | "{[(a)]}({[b]})"))) 2034 | 2035 | (ert-deftest vilpy-repeat () 2036 | (should (string= (vilpy-with "(message \"a witch\")|" 2037 | "2w..") 2038 | "(message \"a witch\")\n(message \"a witch\")\n(message \"a witch\")\n(message \"a witch\")\n(message \"a witch\")|"))) 2039 | 2040 | (ert-deftest vilpy-interleave () 2041 | (should (equal (vilpy-interleave 0 '(1 2 3)) 2042 | '(1 0 2 0 3))) 2043 | (should (equal (vilpy-interleave 1 '(1 2 3)) 2044 | '(1 2 1 3))) 2045 | (should (equal (vilpy-interleave 2 '(1 2 3)) 2046 | '(1 2 3))) 2047 | (should (equal (vilpy-interleave 3 '(1 2 3)) 2048 | '(1 3 2 3))) 2049 | (should (equal (vilpy-interleave 0 '(1 2 3 4 5 6 7 8 9 10) 2) 2050 | '(1 2 0 3 4 0 5 6 0 7 8 0 9 10))) 2051 | (should (equal (vilpy-interleave 0 '(1 2 3 4 5 6 7 8 9 10) 3) 2052 | '(1 2 3 0 4 5 6 0 7 8 9 0 10))) 2053 | (should (equal (vilpy-interleave 3 '(1 2 3 4 5 6 7 8 9 10) 3) 2054 | '(1 2 3 4 5 6 3 7 8 9 3 10)))) 2055 | 2056 | (ert-deftest vilpy-eval-str-racket () 2057 | (let ((geiser-active-implementations '(racket))) 2058 | (should (equal (vilpy-with-v scm 2059 | "(list #hash|((1 . 2) (3 . 4)))" 2060 | (vilpy--string-dwim)) 2061 | "#hash((1 . 2) (3 . 4))")) 2062 | (should (equal (vilpy-with-v scm 2063 | "(list #hash((1 . 2) (3 . 4))| foo)" 2064 | (vilpy--string-dwim)) 2065 | "#hash((1 . 2) (3 . 4))")))) 2066 | 2067 | ;; Quarentine - these tests fail even without any modification to vilpy 2068 | 2069 | ;; (ert-deftest vilpy-move-down () 2070 | ;; (should (string= (vilpy-with "(|(a) (b) (c))" "s") 2071 | ;; "((b) |(a) (c))")) 2072 | ;; (should (string= (vilpy-with "(|(a) (b) (c))" "ss") 2073 | ;; "((b) (c) |(a))")) 2074 | ;; (should (string= (vilpy-with "(|(a) (b) (c))" "sss") 2075 | ;; "((b) (c) |(a))")) 2076 | ;; (should (string= (vilpy-with "((a)| (b) (c))" "s") 2077 | ;; "((b) (a)| (c))")) 2078 | ;; (should (string= (vilpy-with "((a)| (b) (c))" "ss") 2079 | ;; "((b) (c) (a)|)")) 2080 | ;; (should (string= (vilpy-with "((a)| (b) (c))" "sss") 2081 | ;; "((b) (c) (a)|)")) 2082 | ;; (should (string= (vilpy-with "(|(a) (b) (c))" "m]s") 2083 | ;; "((c) ~(a) (b)|)")) 2084 | ;; (should (string= (vilpy-with "(f|oo bar)" 2085 | ;; (kbd "M-m") 2086 | ;; "s") 2087 | ;; "(bar ~foo|)")) 2088 | ;; (should (string= (vilpy-with "(foo ~bar|)" "s") 2089 | ;; "(foo ~bar|)")) 2090 | ;; (should (string= (vilpy-with "(put :foo 1\n ~:baz '(1 2 3)|\n :bar 2)" 2091 | ;; (vilpy-move-down 2)) 2092 | ;; "(put :foo 1\n :bar 2\n ~:baz '(1 2 3)|)")) 2093 | ;; (should (string= (vilpy-with "(put :foo 1\n |:baz '(1 2 3)~\n :bar 2)" 2094 | ;; (vilpy-move-down 2)) 2095 | ;; "(put :foo 1\n :bar 2\n |:baz '(1 2 3)~)")) 2096 | ;; (should (string= (vilpy-with "(foo |(bar) baz)" "s") 2097 | ;; "(foo baz |(bar))")) 2098 | ;; (should (string= (vilpy-with "('|(a) '(b) '(c))" "s") 2099 | ;; "('(b) '|(a) '(c))")) 2100 | ;; (should (string= (vilpy-with "('(a)| '(b) '(c))" "s") 2101 | ;; "('(b) '(a)| '(c))")) 2102 | ;; (should (string= (vilpy-with "(a)\n|(b)" "s") 2103 | ;; "(a)\n|(b)")) 2104 | ;; (unless (version<= emacs-version "24.3.1") 2105 | ;; (should (string= (vilpy-with "|;;; a\n(foo)\n;;; b\n(bar)\n;;; c\n(baz)" "s") 2106 | ;; ";;; b\n(bar)\n|;;; a\n(foo)\n;;; c\n(baz)")) 2107 | ;; (should (string= (vilpy-with "|;;; a\n(foo)\n;;; b\n(bar)\n;;; c\n(baz)" "2s") 2108 | ;; ";;; b\n(bar)\n;;; c\n(baz)\n|;;; a\n(foo)")))) 2109 | 2110 | ;; (ert-deftest vilpy-move-up () 2111 | ;; (should (string= (vilpy-with "((a) (b) |(c))" "w") 2112 | ;; "((a) |(c) (b))")) 2113 | ;; (should (string= (vilpy-with "((a) (b) |(c))" "ww") 2114 | ;; "(|(c) (a) (b))")) 2115 | ;; (should (string= (vilpy-with "((a) (b) |(c))" "www") 2116 | ;; "(|(c) (a) (b))")) 2117 | ;; (should (string= (vilpy-with "((a) (b) (c)|)" "w") 2118 | ;; "((a) (c)| (b))")) 2119 | ;; (should (string= (vilpy-with "((a) (b) (c)|)" "ww") 2120 | ;; "((c)| (a) (b))")) 2121 | ;; (should (string= (vilpy-with "((a) (b) (c)|)" "www") 2122 | ;; "((c)| (a) (b))")) 2123 | ;; (should (string= (vilpy-with "((a) |(b) (c))" "m>w") 2124 | ;; "(~(b) (c)| (a))")) 2125 | ;; (should (string= (vilpy-with "((a) |(b) (c))" "mjw") 2126 | ;; "((a) ~(c)| (b))")) 2127 | ;; (should (string= (vilpy-with "(foo b|ar)" 2128 | ;; (kbd "M-m") 2129 | ;; "w") 2130 | ;; "(~bar| foo)")) 2131 | ;; (should (string= (vilpy-with "(~foo| bar)" "w") 2132 | ;; "(~foo| bar)")) 2133 | ;; (should (string= (vilpy-with clojure "{&foo| bar}" "w") 2134 | ;; "{&foo| bar}")) 2135 | ;; (should (string= (vilpy-with clojure "[&foo| bar]" "w") 2136 | ;; "[&foo| bar]")) 2137 | ;; (should (string= (vilpy-with "(put :foo 1\n :bar 2\n |:baz '(1 2 3)~)" 2138 | ;; (vilpy-move-up 2)) 2139 | ;; "(put :foo 1\n |:baz '(1 2 3)~\n :bar 2)")) 2140 | ;; (should (string= (vilpy-with "(put :foo 1\n :bar 2\n ~:baz '(1 2 3)|)" 2141 | ;; (vilpy-move-up 2)) 2142 | ;; "(put :foo 1\n ~:baz '(1 2 3)|\n :bar 2)")) 2143 | ;; (should (string= (vilpy-with "(foo baz |(bar))" "w") 2144 | ;; "(foo |(bar) baz)")) 2145 | ;; (should (string= (vilpy-with "('(b) '|(a) '(c))" "w") 2146 | ;; "('|(a) '(b) '(c))")) 2147 | ;; (should (string= (vilpy-with "('(b) '(a)| '(c))" "w") 2148 | ;; "('(a)| '(b) '(c))")) 2149 | ;; (unless (version<= emacs-version "24.3.1") 2150 | 2151 | ;; (should (string= (vilpy-with ";;; b\n(bar)\n;;; c\n(baz)\n|;;; a\n(foo)" "w") 2152 | ;; ";;; b\n(bar)\n|;;; a\n(foo)\n;;; c\n(baz)")) 2153 | ;; (should (string= (let ((vilpy-outline ";;;")) 2154 | ;; (vilpy-with ";;; b\n(bar)\n;;; c\n(baz)\n|;;; a\n(foo)" "2w")) 2155 | ;; "|;;; a\n(foo)\n;;; b\n(bar)\n;;; c\n(baz)"))) 2156 | ;; (should (string= (vilpy-with "(sexp (one)\n ;; comment\n |(two))" "w") 2157 | ;; "(sexp (one)\n |(two)\n ;; comment\n )"))) 2158 | 2159 | (provide 'vilpy-test) 2160 | 2161 | ;;; vilpy-test.el ends here 2162 | --------------------------------------------------------------------------------