0

Is there a way of calling (end-of-buffer) that excludes trailing empty lines?

2

We can go to the end of the buffer, then move backwards over whitespace:

(progn (goto-char (point-max))
       (skip-chars-backward "\n[:space:]"))

If you want to call this interactively, make it into a command:

(defun end-of-buffer-before-whitespace ()
  "Move point to after the last non-whitespace character in the buffer."
  (interactive)
  (goto-char (point-max))
  (skip-chars-backward "\n[:space:]"))
| improve this answer | |
  • 2
    Better use "\n[:space:]" instead of "\n\t " in skip-chars-backward. – Tobias Jun 17 '19 at 21:45
  • Note, if you don't want the cursor to be at the line end, add (move-beginning-of-line nil) – ideasman42 Jun 18 '19 at 6:55

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.