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

Small changes/fixes to vi-mode #1026

Merged
merged 5 commits into from
Aug 30, 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
15 changes: 13 additions & 2 deletions extensions/vi-mode/commands.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
(skip-whitespace-forward (current-point) t))

(define-operator vi-indent (start end) ("<r>")
(:restore-point t)
(:move-point nil)
(indent-points start end))

;; FIXME: support block
Expand Down Expand Up @@ -321,6 +321,12 @@
(define-operator vi-change (beg end type) ("<R>")
()
(vi-delete beg end type)
(when (eq type :line)
(let ((column (with-point ((p (current-point)))
(point-column (or (and (line-offset p 1)
(back-to-indentation p))
(line-start p))))))
(move-to-column (current-point) column t)))
(change-state 'insert))

(define-operator vi-change-line (beg end type) ("<R>")
Expand Down Expand Up @@ -693,7 +699,12 @@
(define-command vi-open-above () ()
(line-start (current-point))
(change-state 'insert)
(open-line 1))
(open-line 1)
(let ((column (with-point ((p (current-point)))
(point-column (or (and (line-offset p 1)
(back-to-indentation p))
(line-start p))))))
(move-to-column (current-point) column t)))

(define-command vi-jump-back (&optional (n 1)) ("p")
(dotimes (i n)
Expand Down
10 changes: 5 additions & 5 deletions extensions/vi-mode/core.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

(defvar *last-repeat-keys* '())

(defvar *default-cursor-color* nil)
(defvar *default-cursor-color* "#ffb472")

(defvar *enable-hook* '())
(defvar *disable-hook* '())
Expand Down Expand Up @@ -154,7 +154,8 @@
(let ((state (ensure-state name)))
(setf *current-state* state)
(state-enabled-hook state)
(set-attribute 'cursor :background (state-cursor-color state))))
(set-attribute 'cursor
:background (or (state-cursor-color state) *default-cursor-color*))))

(defmacro with-state (state &body body)
(with-gensyms (old-state)
Expand All @@ -175,9 +176,8 @@
(add-hook *post-command-hook* 'vi-post-command-hook)

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

(defun vi-this-command-keys ()
(append
Expand Down
3 changes: 1 addition & 2 deletions extensions/vi-mode/states.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
(define-state normal () ()
(:default-initargs
:name "NORMAL"
:cursor-color "IndianRed"
:cursor-type :box
:modeline-color 'state-modeline-yellow
:keymaps (list *normal-keymap*)))
Expand Down Expand Up @@ -76,7 +75,7 @@
;;
;; Operator-pending state

(define-state operator () ()
(define-state operator (normal) ()
(:default-initargs
:keymaps (list *operator-keymap* *normal-keymap*)))

Expand Down
4 changes: 3 additions & 1 deletion extensions/vi-mode/vi-mode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
:*normal-keymap*
:*insert-keymap*
:*inner-text-objects-keymap*
:*outer-text-objects-keymap*)
:*outer-text-objects-keymap*
:*operator-keymap*)
(:import-from :lem-vi-mode/visual
:*visual-keymap*)
(:import-from :alexandria
Expand All @@ -34,6 +35,7 @@
:*normal-keymap*
:*insert-keymap*
:*visual-keymap*
:*operator-keymap*
:*ex-keymap*
:*inner-text-objects-keymap*
:*outer-text-objects-keymap*
Expand Down