Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start Emacs with cursor at the end of a given file?

Tags:

emacs

Is there a build-in in emacs to open a file at the end? So without using a wc first, and then using the output to do

emacs +nboflines filename

like image 481
MaVe Avatar asked Oct 27 '25 09:10

MaVe


2 Answers

Silly (but working) answwer:

emacs +10000000 filename

Adjust the 10000000 if you have files with more lines than that.

Another way of doing it:

 emacs filename --eval "(goto-char (point-max))"

Note that the --eval ... is after the filename, as order matters here.

like image 85
juanleon Avatar answered Oct 28 '25 22:10

juanleon


You can execute the following command to move the pointer to the end of the buffer:

M-x end-of-buffer

And you can also create the following function in your .emacs file, adding a hook on find-file-hook which will execute our function for every file opened. That will always open a file in emacs with the pointer at the bottom of the buffer:

;; Bottom-line function:
(defun bottom-line ()
  "Opens a file with the pointer at the bottom line."
  (interactive)
  (end-of-buffer))

;; Hook for every file opened, execute the bottom-line function:
(add-hook 'find-file-hook 'bottom-line)
like image 42
marcelfox Avatar answered Oct 29 '25 00:10

marcelfox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!