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

[DRAFT] feature: recenter line if jump target point is not inside window. (vi-mode) #1695

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 9 additions & 3 deletions extensions/vi-mode/commands.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,22 +1019,28 @@ on the same line or at eol if there are none."
(line-start p))))))
(move-to-column (current-point) column t)))

(defun recenter-line-if-point-not-inside-window (point &optional (window (current-window)))
(when point
(unless (lem-vi-mode/window::point-inside-window-p point window)
(vi-scroll-line-to-center))))

(define-command vi-jumps () ()
(line-end (current-point))
(lem:message-buffer (with-output-to-string (s)
(lem-vi-mode/jumplist::print-jumplist (current-jumplist) s))))

(define-command vi-jump-back (&optional (n 1)) (:universal)
(dotimes (i n)
(jump-back)))
;; The return value of jump-back is target jump point.
(recenter-line-if-point-not-inside-window (jump-back))))

(define-command vi-jump-next (&optional (n 1)) (:universal)
(dotimes (i n)
(jump-next)))
(recenter-line-if-point-not-inside-window (jump-next))))

(define-motion vi-jump-previous () ()
(:jump t)
(jump-back))
(vi-jump-back))

(define-command vi-repeat (n) (:universal-nil)
(when *last-repeat-keys*
Expand Down
9 changes: 9 additions & 0 deletions extensions/vi-mode/window.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
(move-to-next-virtual-line point (1- (window-height* window)) window)
point))

(defun line-inside-window-p (line &optional (window (current-window)))
(let ((start-line-num (line-number-at-point (window-start-point window)))
(end-line-num (line-number-at-point (window-end-point window))))
(and (>= line start-line-num)
(<= line end-line-num))))

(defun point-inside-window-p (point &optional (window (current-window)))
(line-inside-window-p (line-number-at-point point) window))

(defun window-has-following-lines-p (&optional (window (current-window)))
(let ((end-point (window-end-point window)))
(with-point ((p end-point))
Expand Down
Loading