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
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)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I realized after merging that changing point-charpos breaks encapsulation.
I think it would be better to use line-end-p and character-offset instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll do it within 24h. Thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it still a problem with temporary point? Like (with-point ((point (copy-point point))) ...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but copy-point is not necessary because it is used automatically with-point.
(with-point ((point point)) ...)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(apropos "line-end-p") doesn't find anything. There's a struct line-end-item-p but I don't think it's what I need here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it was end-line-p.

(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
Loading