0

When I jump to bottom part of the buffer using vi I does not show any empty lines.

enter image description here

On emacs when I got to bottom of the buffer I see empty lines even there is no new lines exist.

enter image description here

Is is possible to accomplish same behavior of vim on emacs?

10
  • 1
    Here is a link to a related thread, that helps the user visualize where the buffer ends and whether there are any blank lines prior to the end of the buffer: emacs.stackexchange.com/questions/13757/… – lawlist Jul 27 '20 at 1:02
  • Hm they can highlight or replace empty lines with ~ // is it possible to don't show them when we jump to end of the buffer so last location will be the very last line – alper Jul 27 '20 at 1:09
  • The function end-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 calls end-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. – lawlist Jul 27 '20 at 1:35
  • 1
    Here is an example modification to the cond statement within end-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 to end-of-buffer. – lawlist Jul 27 '20 at 2:32
  • 1
    I wrote some page up/down commands that avoid this emacs.stackexchange.com/a/57639/2418 – ideasman42 Jul 27 '20 at 11:02
1

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)
  (next-line (/ (window-height
                 (selected-window)) 2)))

(global-set-key "\C-x\ ."  'my-bottom)
2
  • @ideasman42 , please feel free to update my anwer or make a new one since I am just using your answer. Your code solved my issue. – alper Jul 27 '20 at 12:11
  • @i I also added ` (end-of-visual-line) (next-line (/ (window-height (selected-window)) 2))) ` to bottom section which helps to move cursor location to the very last char – alper Jul 27 '20 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.