Skip to content

Commit

Permalink
Merge pull request #1559 from naryl/vi-fixes
Browse files Browse the repository at this point in the history
Vi fixes
  • Loading branch information
cxxxr authored Oct 4, 2024
2 parents 23640ee + 426573a commit c3c2ce7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
4 changes: 2 additions & 2 deletions extensions/vi-mode/binds.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
(define-key *motion-keymap* "H" 'vi-move-to-window-top)
(define-key *motion-keymap* "M" 'vi-move-to-window-middle)
(define-key *motion-keymap* "L" 'vi-move-to-window-bottom)
(define-key *motion-keymap* "C-d" 'next-page)
(define-key *motion-keymap* "C-u" 'previous-page)
(define-key *motion-keymap* "C-d" 'vi-scroll-down)
(define-key *motion-keymap* "C-u" 'vi-scroll-up)
(define-key *motion-keymap* "^" 'vi-back-to-indentation)
(define-key *motion-keymap* "_" 'vi-back-to-indentation)
(define-key *motion-keymap* "{" 'backward-paragraph)
Expand Down
29 changes: 27 additions & 2 deletions extensions/vi-mode/commands.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
:vi-scroll-line-to-bottom-back-to-indentation
:vi-scroll-bottom-line-to-top
:vi-scroll-top-line-to-bottom
:vi-scroll-down
:vi-scroll-up
:vi-back-to-indentation
:vi-indent
:vi-substitute
Expand Down Expand Up @@ -188,6 +190,20 @@
(:type :line)
(previous-line n))

(define-motion vi-scroll-down (&optional (n nil)) (:universal-nil)
(:type :inclusive :default-n-arg nil)
(unless n
(setf n (floor (window-height (current-window)) 2)))
(next-line n)
(scroll-down n))

(define-motion vi-scroll-up (&optional (n nil)) (:universal-nil)
(:default-n-arg nil)
(unless n
(setf n (floor (window-height (current-window)) 2)))
(previous-line n)
(scroll-up n))

(defun on-only-space-line-p (point)
(with-point ((p point))
(line-end p)
Expand Down Expand Up @@ -689,14 +705,23 @@ Move the cursor to the first non-blank character of the line."
(defun vi-forward-matching-paren (window point &optional (offset -1))
(declare (ignore window))
(with-point ((point point))
(loop :until (or (syntax-open-paren-char-p (character-at point))
(syntax-closed-paren-char-p (character-at point))
(= (point-charpos point) (length (line-string point))))
:do (incf (point-charpos point)))
(when (syntax-open-paren-char-p (character-at point))
(when (scan-lists point 1 0 t)
(character-offset point offset)))))

(defun vi-backward-matching-paren (window point &optional (offset -1))
(declare (ignore window offset))
(when (syntax-closed-paren-char-p (character-at point))
(scan-lists (character-offset (copy-point point :temporary) 1) -1 0 t)))
(with-point ((point point))
(loop :until (or (syntax-open-paren-char-p (character-at point))
(syntax-closed-paren-char-p (character-at point))
(= (point-charpos point) (length (line-string point))))
:do (incf (point-charpos point)))
(when (syntax-closed-paren-char-p (character-at point))
(scan-lists (character-offset (copy-point point :temporary) 1) -1 0 t))))

(define-motion vi-move-to-matching-item (&optional n) (:universal-nil)
(:type :inclusive
Expand Down

0 comments on commit c3c2ce7

Please sign in to comment.