Skip to content

Commit

Permalink
Merge pull request #1160 from ilya-fiveisky/vi-broad-word-text-object
Browse files Browse the repository at this point in the history
Vi `WORD` text object.
  • Loading branch information
fukamachi authored Nov 18, 2023
2 parents 1c0db48 + 0939d02 commit b479da1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions extensions/vi-mode/binds.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@

(define-key *outer-text-objects-keymap* "w" 'vi-a-word)
(define-key *inner-text-objects-keymap* "w" 'vi-inner-word)
(define-key *outer-text-objects-keymap* "W" 'vi-a-broad-word)
(define-key *inner-text-objects-keymap* "W" 'vi-inner-broad-word)
(define-key *outer-text-objects-keymap* "\"" 'vi-a-double-quote)
(define-key *inner-text-objects-keymap* "\"" 'vi-inner-double-quote)
(define-key *outer-text-objects-keymap* "(" 'vi-a-paren)
Expand Down
11 changes: 11 additions & 0 deletions extensions/vi-mode/commands.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@
:vi-jump-back
:vi-jump-next
:vi-a-word
:vi-a-word
:vi-a-broad-word
:vi-inner-word
:vi-inner-broad-word
:vi-a-double-quote
:vi-inner-double-quote
:vi-a-paren
Expand Down Expand Up @@ -858,6 +861,14 @@
(:expand-selection t)
(inner-range-of 'word-object (current-state) count))

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

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

(define-text-object-command vi-a-double-quote () ()
()
(a-range-of 'double-quoted-object (current-state) 1))
Expand Down
9 changes: 9 additions & 0 deletions extensions/vi-mode/tests/text-objects.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
(cmd "viw")
(ok (buf= #?"abc\n< [ ]>def\n")))))

(deftest broad-word-object
(with-fake-interface ()
(with-vi-buffer (#?"abc [d]ef.ghi \n")
(cmd "viW")
(ok (buf= #?"abc <def.gh[i]> \n"))
(cmd "vvaW")
(ok (buf= #?"abc <def.ghi[ ]>\n"))
)))

(deftest double-quoted
(with-fake-interface ()
(with-vi-buffer ("[ ]\"foo\" \"bar\"")
Expand Down
19 changes: 18 additions & 1 deletion extensions/vi-mode/text-objects.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
:visual-range
:vi-visual-char)
(:import-from :lem-vi-mode/word
:word-char-type)
:word-char-type
:broad-word-char-type)
(:export :text-object
:function-text-object
:surrounded-text-object
Expand All @@ -22,6 +23,7 @@
:inner-range-of

:word-object
:broad-word-object
:paren-object
:double-quoted-object))
(in-package :lem-vi-mode/text-objects)
Expand Down Expand Up @@ -350,6 +352,21 @@
(unless (visual-char-p)
(vi-visual-char)))

;;
;; broad-word-object

(defclass broad-word-object (function-text-object) ()
(:default-initargs
:function #'broad-word-char-type))

(defmethod a-range-of :before ((object broad-word-object) (state visual) count)
(unless (visual-char-p)
(vi-visual-char)))

(defmethod inner-range-of :before ((object broad-word-object) (state visual) count)
(unless (visual-char-p)
(vi-visual-char)))

;;
;; paren-object

Expand Down

0 comments on commit b479da1

Please sign in to comment.