When I jump to bottom part of the buffer using vi
I does not show any empty lines.
On emacs
when I got to bottom of the buffer I see empty lines even there is no new lines exist.
Is is possible to accomplish same behavior of vim
on emacs
?
This answer uses following answer's code with a small change Can page-down clamp the last line to the bottom of the window?. I just replaced (my-scroll-and-clamp--forward-line height)
with (end-of-buffer)
that is followed by the set-window-start
section.
(defun my-bottom ()
(interactive)
(let* ((height (window-height)))
(end-of-buffer)
;; Move window.
(set-window-start
(selected-window)
(min
(save-excursion ;; new point.
(forward-line (- (/ height 2)))
(point))
(save-excursion ;; max point.
(goto-char (point-max))
(beginning-of-line)
(forward-line (- (- height (+ 1 (* 2 scroll-margin)))))
(point)))))
(redisplay)
(end-of-visual-line)
(forward-line (/ (window-height
(selected-window)) 2)))
(global-set-key "\C-x\ ." 'my-bottom)
~
// is it possible to don't show them when we jump to end of the buffer so last location will be the very last lineend-of-buffer
contains two conditions at the tail end of the function, the second of which calls in part(recenter -3)
. Provided that a user callsend-of-buffer
without specifying a certain number of lines from the end (see doc-string), and provided that the file is lengthier than the visible window, the second condition should kick in and recenter the end of the buffer so that it is 3 blank empty screen lines from the bottom of the window. Your screenshot depicts lots of empty screen lines.cond
statement withinend-of-buffer
, adding messages to see what is happening and adding a new catch-all condition:(cond ((and arg (not (consp arg))) (message "This is the first condition.") (forward-line 1)) ((and (eq (current-buffer) (window-buffer)) (> (point) (window-end nil t))) (message "This is the second condition.") (overlay-recenter (point)) (recenter -3)) (t (message "This is the new catch-all condition.") (recenter -1)))
. In my setup, the second condition is triggered without the need for any changes toend-of-buffer
.