Skip to content

Commit

Permalink
recenter-top-bottom (emacs-mode) (#1767)
Browse files Browse the repository at this point in the history
* recenter-top-bottom

Emacs default behavior of (C-l recenter-top-bottom)

* fix: window-recenter-top-bottom should return smt

* return prev keymap

* removed unused variable
  • Loading branch information
Prikaz98 authored Feb 10, 2025
1 parent bbc75f2 commit 791397f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/commands/window.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@
(redraw-display)
t)

(define-command recenter-top-bottom (p) (:universal-nil)
"Scroll so that the cursor is in the middle/top/bottom."
(clear-screens-of-window-list)
(unless p (window-recenter-top-bottom (current-window)))
(redraw-display)
t)

(define-command split-active-window-vertically (&optional n) (:universal-nil)
"Split the current window vertically."
(split-window-vertically (current-window) :height n)
Expand Down
1 change: 1 addition & 0 deletions src/internal-packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@
;; virtual-line
(:export
:window-recenter
:window-recenter-top-bottom
:window-cursor-x
:window-cursor-y
:backward-line-wrap
Expand Down
14 changes: 14 additions & 0 deletions src/window/virtual-line.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ If FROM-BOTTOM is T, start counting from the bottom."
(window-scroll window n)
n)))

(defun window-recenter-top-bottom (window)
"In first call recenter WINDOW to the middle line.
If cursor is already in the middle of WINDOW then move cursor in the top position.
If cursor is on top then move move WINDOW to the bottom."
(let* ((line (window-cursor-y window))
(window-height (window-height-without-modeline window))
(middle (floor window-height 2))
(scrolloff (min (floor (/ (window-height window) 2)) 0))
(top 0))
(cond
((= line middle) (window-recenter window :line scrolloff :from-bottom nil))
((= line top) (window-recenter window :line scrolloff :from-bottom t))
(t (window-recenter window :line nil :from-bottom nil)))))

(defun %calc-window-cursor-x (point window)
"Return (values cur-x next). the 'next' is a flag if the cursor goes to
next line because it is at the end of width."
Expand Down

0 comments on commit 791397f

Please sign in to comment.