Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete a message when switching vi-mode state #1020

Merged
merged 2 commits into from
Aug 29, 2023
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
17 changes: 5 additions & 12 deletions extensions/vi-mode/core.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@
((name :initarg :name
:initform nil
:reader state-name)
(message
:initarg :message
:initform nil
:reader state-message)
(cursor-type
:initarg :cursor-type
:initform :box
Expand Down Expand Up @@ -119,12 +115,8 @@
(defgeneric post-command-hook (state)
(:method ((state vi-state))))

(defgeneric state-enabled-hook (state))

(defmethod state-enabled-hook ((state vi-state))
(let ((msg (state-message state)))
(unless (null msg)
(message msg))))
(defgeneric state-enabled-hook (state)
(:method ((state vi-state))))

(defgeneric state-disabled-hook (state))

Expand Down Expand Up @@ -183,8 +175,9 @@
(add-hook *post-command-hook* 'vi-post-command-hook)

(defmethod state-enabled-hook :after ((state vi-state))
(lem-if:update-cursor-shape (lem:implementation)
(state-cursor-type state)))
(when (state-cursor-type state)
(lem-if:update-cursor-shape (lem:implementation)
(state-cursor-type state))))

(defun vi-this-command-keys ()
(append
Expand Down
1 change: 0 additions & 1 deletion extensions/vi-mode/states.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
(define-vi-state insert () ()
(:default-initargs
:name "INSERT"
:message "-- INSERT --"
:cursor-color "IndianRed"
:cursor-type :bar
:modeline-color 'state-modeline-aqua
Expand Down
156 changes: 75 additions & 81 deletions extensions/vi-mode/tests/visual.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
:lem
:rove
:lem-vi-mode/tests/utils)
(:import-from :lem/common/timer
:with-timer-manager)
(:import-from :lem-core
:lem-timer-manager)
(:import-from :lem-fake-interface
:with-fake-interface)
(:import-from :named-readtables
Expand All @@ -16,82 +12,80 @@
(in-readtable :interpol-syntax)

(deftest visual-switch
(with-timer-manager (make-instance 'lem-timer-manager)
(with-fake-interface ()
(with-vi-buffer (#?"[a]bc\ndef\n")
(cmd "v")
(ok (buf= #?"<[a]>bc\ndef\n"))
(cmd "l")
(ok (buf= #?"<a[b]>c\ndef\n"))
(cmd "v")
(ok (buf= #?"a[b]c\ndef\n"))
(cmd "v")
(ok (buf= #?"a<[b]>c\ndef\n"))
(cmd "V")
(ok (buf= #?"<a[b]c>\ndef\n"))
(cmd "j")
(ok (buf= #?"<abc\nd[e]f>\n"))
(cmd "l<C-v>")
(ok (buf= #?"a<bc>\nd<e[f]>\n"))
(cmd "v")
(ok (buf= #?"a<bc\nde[f]>\n"))
(cmd "v")
(ok (buf= #?"abc\nde[f]\n"))))))
(with-fake-interface ()
(with-vi-buffer (#?"[a]bc\ndef\n")
(cmd "v")
(ok (buf= #?"<[a]>bc\ndef\n"))
(cmd "l")
(ok (buf= #?"<a[b]>c\ndef\n"))
(cmd "v")
(ok (buf= #?"a[b]c\ndef\n"))
(cmd "v")
(ok (buf= #?"a<[b]>c\ndef\n"))
(cmd "V")
(ok (buf= #?"<a[b]c>\ndef\n"))
(cmd "j")
(ok (buf= #?"<abc\nd[e]f>\n"))
(cmd "l<C-v>")
(ok (buf= #?"a<bc>\nd<e[f]>\n"))
(cmd "v")
(ok (buf= #?"a<bc\nde[f]>\n"))
(cmd "v")
(ok (buf= #?"abc\nde[f]\n")))))

(deftest text-objects
(with-timer-manager (make-instance 'lem-timer-manager)
(with-fake-interface ()
(testing "vaw"
(with-vi-buffer (#?" [ ]foo bar baz \n")
(cmd "vaw")
(ok (buf= #?"< fo[o]> bar baz \n")))
(with-vi-buffer (#?" < [ ]> foo bar baz \n")
(cmd "aw")
(ok (buf= #?" < fo[o]> bar baz \n")))
(with-vi-buffer (#?" < [ ]>foo bar baz \n")
(cmd "aw")
(ok (buf= #?" < foo[ ]>bar baz \n")))
(with-vi-buffer (#?" <[ ] > foo bar baz \n")
(cmd "aw")
(ok (buf= #?"<[ ] > foo bar baz \n")))
(with-vi-buffer (#?" f[o]o bar \n")
(cmd "vaw")
(ok (buf= #?" <foo[ ]>bar \n")))
(with-vi-buffer (#?" f[o]o bar \n")
(cmd "v2aw")
(ok (buf= #?" <foo bar[ ]>\n")))
(with-vi-buffer (#?" f[o]o bar \n")
(cmd "v3aw")
(ok (buf= #?" <foo bar [\n]>")))
(with-vi-buffer (#?" foo b[a]r \n")
(cmd "Vaw")
(ok (buf= #?" foo <bar[ ]>\n")))
(with-vi-buffer (#?" foo b[a]r\n")
(cmd "vaw")
(ok (buf= #?" foo< ba[r]>\n"))))
(testing "viw"
(with-vi-buffer (#?" [ ] foo bar\n")
(cmd "viw")
(ok (buf= #?"< [ ]>foo bar\n")))
(with-vi-buffer (#?"f[o]o bar\n")
(cmd "viw")
(ok (buf= #?"<fo[o]> bar\n")))
(with-vi-buffer (#?"f[o]o bar\n")
(cmd "v3iw")
(ok (buf= #?"<foo ba[r]>\n"))))
(testing "va\""
(with-vi-buffer (#?' "f[o]o" "bar" ')
(cmd "va\"")
(ok (buf= #?' <"foo"[ ]>"bar" '))
(cmd "a\"")
(ok (buf= #?' <"foo" "bar"[ ]>')))
(with-vi-buffer (#?' <"f[o]>o" ')
(cmd "a\"")
(ok (buf= #?' <"foo"[ ]>')))
(with-vi-buffer (#?' "f<[o]o"> ')
(cmd "a\"")
(ok (buf= #?'<[ ]"foo"> '))))
(testing "vi\""
(with-vi-buffer (#?' "f[o]o" ')
(cmd "vi\"")
(ok (buf= #?' "<fo[o]>" ')))))))
(with-fake-interface ()
(testing "vaw"
(with-vi-buffer (#?" [ ]foo bar baz \n")
(cmd "vaw")
(ok (buf= #?"< fo[o]> bar baz \n")))
(with-vi-buffer (#?" < [ ]> foo bar baz \n")
(cmd "aw")
(ok (buf= #?" < fo[o]> bar baz \n")))
(with-vi-buffer (#?" < [ ]>foo bar baz \n")
(cmd "aw")
(ok (buf= #?" < foo[ ]>bar baz \n")))
(with-vi-buffer (#?" <[ ] > foo bar baz \n")
(cmd "aw")
(ok (buf= #?"<[ ] > foo bar baz \n")))
(with-vi-buffer (#?" f[o]o bar \n")
(cmd "vaw")
(ok (buf= #?" <foo[ ]>bar \n")))
(with-vi-buffer (#?" f[o]o bar \n")
(cmd "v2aw")
(ok (buf= #?" <foo bar[ ]>\n")))
(with-vi-buffer (#?" f[o]o bar \n")
(cmd "v3aw")
(ok (buf= #?" <foo bar [\n]>")))
(with-vi-buffer (#?" foo b[a]r \n")
(cmd "Vaw")
(ok (buf= #?" foo <bar[ ]>\n")))
(with-vi-buffer (#?" foo b[a]r\n")
(cmd "vaw")
(ok (buf= #?" foo< ba[r]>\n"))))
(testing "viw"
(with-vi-buffer (#?" [ ] foo bar\n")
(cmd "viw")
(ok (buf= #?"< [ ]>foo bar\n")))
(with-vi-buffer (#?"f[o]o bar\n")
(cmd "viw")
(ok (buf= #?"<fo[o]> bar\n")))
(with-vi-buffer (#?"f[o]o bar\n")
(cmd "v3iw")
(ok (buf= #?"<foo ba[r]>\n"))))
(testing "va\""
(with-vi-buffer (#?' "f[o]o" "bar" ')
(cmd "va\"")
(ok (buf= #?' <"foo"[ ]>"bar" '))
(cmd "a\"")
(ok (buf= #?' <"foo" "bar"[ ]>')))
(with-vi-buffer (#?' <"f[o]>o" ')
(cmd "a\"")
(ok (buf= #?' <"foo"[ ]>')))
(with-vi-buffer (#?' "f<[o]o"> ')
(cmd "a\"")
(ok (buf= #?'<[ ]"foo"> '))))
(testing "vi\""
(with-vi-buffer (#?' "f[o]o" ')
(cmd "vi\"")
(ok (buf= #?' "<fo[o]>" '))))))
7 changes: 2 additions & 5 deletions extensions/vi-mode/visual.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

(define-vi-state visual (vi-state) ()
(:default-initargs
:message "-- VISUAL --"
:modeline-color 'state-modeline-orange
:keymaps (list *visual-keymap* *motion-keymap* *normal-keymap*)))

Expand All @@ -46,13 +45,11 @@

(define-vi-state visual-line (visual) ()
(:default-initargs
:name "V-LINE"
:message "-- VISUAL LINE --"))
:name "V-LINE"))

(define-vi-state visual-block (visual) ()
(:default-initargs
:name "V-BLOCK"
:message "-- VISUAL BLOCK --"))
:name "V-BLOCK"))

(defmethod state-enabled-hook :after ((state visual))
(setf *start-point* (copy-point (current-point))))
Expand Down