|
6 | 6 | (:import-from :lem-vi-mode/visual |
7 | 7 | :visual-p |
8 | 8 | :visual-line-p |
| 9 | + :visual-block-p |
9 | 10 | :apply-visual-range |
10 | 11 | :vi-visual-end) |
11 | 12 | (:import-from :lem/common/command |
|
89 | 90 | (t (values arg-list '("P") nil)))) |
90 | 91 |
|
91 | 92 | (defmacro define-vi-motion (name arg-list (&key type jump) &body body) |
92 | | - (check-type type (or null (member :inclusive :exclusive :line))) |
| 93 | + (check-type type (or null (member :inclusive :exclusive :line :block))) |
93 | 94 | (check-type jump boolean) |
94 | 95 | (multiple-value-bind (arg-list arg-descriptor default-n-arg) |
95 | 96 | (parse-vi-motion-arg-list arg-list) |
|
161 | 162 | (command-motion-type command)))))))))) |
162 | 163 |
|
163 | 164 | (defun call-vi-operator (n fn &key motion keep-visual restore-point) |
164 | | - (with-point ((*vi-origin-point* (current-point))) |
165 | | - (unwind-protect |
166 | | - (if *vi-operator-arguments* |
167 | | - (apply fn *vi-operator-arguments*) |
168 | | - (multiple-value-bind (start end type) |
169 | | - (vi-operator-region n motion) |
170 | | - (when (point< end start) |
171 | | - (rotatef start end)) |
172 | | - (ecase type |
173 | | - (:line (unless (visual-p) |
174 | | - (line-start start) |
175 | | - (line-end end))) |
176 | | - (:inclusive |
177 | | - (unless (point= start end) |
178 | | - (character-offset end 1))) |
179 | | - (:exclusive)) |
180 | | - (let ((*vi-operator-arguments* (list start end type))) |
181 | | - (funcall fn start end type)))) |
182 | | - (when restore-point |
183 | | - (move-point (current-point) *vi-origin-point*)) |
184 | | - (unless keep-visual |
185 | | - (when (visual-p) |
186 | | - (vi-visual-end)))))) |
| 165 | + (flet ((call-with-region (fn start end type) |
| 166 | + (when (point< end start) |
| 167 | + (rotatef start end)) |
| 168 | + (ecase type |
| 169 | + (:line (unless (visual-p) |
| 170 | + (line-start start) |
| 171 | + (line-end end))) |
| 172 | + (:block) |
| 173 | + (:inclusive |
| 174 | + (unless (point= start end) |
| 175 | + (character-offset end 1))) |
| 176 | + (:exclusive)) |
| 177 | + (let ((*vi-operator-arguments* (list start end type))) |
| 178 | + (funcall fn start end type)))) |
| 179 | + (with-point ((*vi-origin-point* (current-point))) |
| 180 | + (unwind-protect |
| 181 | + (if *vi-operator-arguments* |
| 182 | + (apply fn *vi-operator-arguments*) |
| 183 | + (if (visual-block-p) |
| 184 | + (apply-visual-range |
| 185 | + (lambda (start end) |
| 186 | + (call-with-region fn start end :block))) |
| 187 | + (multiple-value-bind (start end type) |
| 188 | + (vi-operator-region n motion) |
| 189 | + (call-with-region fn start end type)))) |
| 190 | + (when restore-point |
| 191 | + (move-point (current-point) *vi-origin-point*)) |
| 192 | + (unless keep-visual |
| 193 | + (when (visual-p) |
| 194 | + (vi-visual-end))))))) |
187 | 195 |
|
188 | 196 | (defmacro define-vi-operator (name arg-list (&key motion keep-visual restore-point) &body body) |
189 | 197 | (with-gensyms (n extra-args) |
|
0 commit comments