Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions extensions/vi-mode/commands.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -721,21 +721,27 @@
(fall-within-line (current-point))))))

(define-text-object-command vi-a-word (count) ("p")
(:expand-selection t)
(a-range-of 'word-object (current-state) count))

(define-text-object-command vi-inner-word (count) ("p")
(:expand-selection t)
(inner-range-of 'word-object (current-state) count))

(define-text-object-command vi-a-double-quote () ()
()
(a-range-of 'double-quoted-object (current-state) 1))

(define-text-object-command vi-inner-double-quote () ()
()
(inner-range-of 'double-quoted-object (current-state) 1))

(define-text-object-command vi-a-paren (count) ("p")
(:expand-selection t)
(a-range-of 'paren-object (current-state) count))

(define-text-object-command vi-inner-paren (count) ("p")
(:expand-selection t)
(inner-range-of 'paren-object (current-state) count))

(define-command vi-normal () ()
Expand Down
13 changes: 9 additions & 4 deletions extensions/vi-mode/commands/utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
:keep-visual ,keep-visual
:restore-point ,restore-point)))

(defun call-define-text-object-command (fn)
(defun call-define-text-object-command (fn &key expand-selection)
(flet ((expand-visual-range (range)
(let ((p1 (range-beginning range))
(p2 (range-end range)))
Expand All @@ -271,11 +271,16 @@
(return-from call-define-text-object-command)))))
(let ((range (funcall fn)))
(when (visual-p)
(expand-visual-range range))
(if expand-selection
(expand-visual-range range)
(setf (visual-range)
(list (range-beginning range) (range-end range)))))
range))))

(defmacro define-text-object-command (name arg-list arg-descriptors
(defmacro define-text-object-command (name arg-list arg-descriptors (&key expand-selection)
&body body)
`(define-command (,name (:advice-classes vi-text-object)) ,arg-list
(,(parse-arg-descriptors arg-descriptors))
(call-define-text-object-command (lambda () ,@body))))
(call-define-text-object-command
(lambda () ,@body)
:expand-selection ,expand-selection)))
1 change: 1 addition & 0 deletions extensions/vi-mode/lem-vi-mode.asd
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
(:file "operator")
(:file "visual")
(:file "commands")
(:file "text-objects")
(:file "options")))
(:file "utils"
:pathname "tests/utils"))
Expand Down
34 changes: 34 additions & 0 deletions extensions/vi-mode/tests/text-objects.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(defpackage :lem-vi-mode/tests/text-objects
(:use :cl
:lem
:rove
:lem-vi-mode/tests/utils)
(:import-from :lem-fake-interface
:with-fake-interface)
(:import-from :named-readtables
:in-readtable))
(in-package :lem-vi-mode/tests/text-objects)

(in-readtable :interpol-syntax)

(deftest double-quoted
(with-fake-interface ()
(with-vi-buffer ("[ ]\"foo\" \"bar\"")
(cmd "va\"")
(ok (buf= " <\"foo\"[ ]>\"bar\"")))
(with-vi-buffer (" [\"]foo\" \"bar\"")
(cmd "va\"")
(ok (buf= " <\"foo\"[ ]>\"bar\"")))
(with-vi-buffer (" \"f[o]o\" \"bar\"")
(cmd "va\"")
(ok (buf= " <\"foo\"[ ]>\"bar\"")))
(with-vi-buffer (" \"foo[\"] \"bar\"")
(cmd "va\"")
(ok (buf= " <\"foo\"[ ]>\"bar\"")))
(with-vi-buffer (" \"foo\"[ ]\"bar\"")
(cmd "va\"")
;; NOTE: This behavior is not same as Vim
(ok (buf= " \"foo\"< \"bar[\"]>")))
(with-vi-buffer (" \"foo\" \"bar[\"]")
(cmd "va\"")
(ok (buf= " \"foo\"< \"bar[\"]>")))))
3 changes: 3 additions & 0 deletions extensions/vi-mode/tests/visual.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
(deftest text-objects
(with-fake-interface ()
(testing "vaw"
(with-vi-buffer (#?" [f]oo\n")
(cmd "vaw")
(ok (buf= #?" <fo[o]>\n")))
(with-vi-buffer (#?" [ ]foo bar baz \n")
(cmd "vaw")
(ok (buf= #?"< fo[o]> bar baz \n")))
Expand Down
Loading