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?

alper
  • 1,238
  • 11
  • 30
  • 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: https://emacs.stackexchange.com/questions/13757/distinguish-between-blank-lines-at-end-of-buffer-and-bottom-of-window – lawlist Jul 27 '20 at 01: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 01: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 01:35
  • On a larger screen it kind of make it center the jump location at bottom – alper Jul 27 '20 at 01:42
  • If the second condition at the tail end of `end-of-buffer` is not kicking in (which can be tested by placing a message inside that second condition), then one idea would be to create a third catch-all condition; e.g., `(t (recenter -1))` *inside* the `cond` statement *at the very end* -- and create a new function `my-end-of-buffer` containing that new catch-all statement. You can also modify the second condition at the tail end to use `-1` instead of `-3` if that is visually more appealing when the second condition kicks in. – lawlist Jul 27 '20 at 01:46
  • Thanks I will try it. What do you mean by `new catch-all statement`? – alper Jul 27 '20 at 02:21
  • 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 02:32
  • 1
    I wrote some page up/down commands that avoid this https://emacs.stackexchange.com/a/57639/2418 – ideasman42 Jul 27 '20 at 11:02
  • But I am not doing page-down just directly jump to bottom section , could it be combined with your code? @ ideasman42 – alper Jul 27 '20 at 11:54
  • Thanks @lawlist for the guide. I wasn't able make it work but I understand the idea, I will update if I can make it work – alper Jul 27 '20 at 12:12

1 Answers1

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

(global-set-key "\C-x\ ."  'my-bottom)
ideasman42
  • 8,375
  • 1
  • 28
  • 105
alper
  • 1,238
  • 11
  • 30
  • @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