I would like to know if it is possible, with a single command from bash, to open a file with emacs -nw
and execute a command in the same time, for example goto-line 20
.
1 Answer
Generic solution
Here's a generic solution to eval some elisp expression after launching emacs
emacs --eval="SEXP"
For your example, that will be
emacs -nw --eval="(goto-line 20)" FILE
Also check out the --load
option from the below referenced link if you want to load an elisp file instead of writing elisp at command line.
Solution specific for opening emacs at a particular position
From the command line, if you want to open a specific FILE and position the cursor at a specific LINE and COL, you would do
emacs +LINE:COL FILE
Of course, as you want to jump to a specific line number in terminal mode, you can do
emacs -nw +LINE FILE
Reference
-
Thank you for the answer. I need to run also different commands such as elisp script. Is there a general way to to this? May 10, 2015 at 13:20
-
-
The command with
goto-line
is not working for me (the file is opened with the cursor at the beginning of the file). Am I doing something wrong? May 10, 2015 at 13:52 -
The answer to this question seems to be this one stackoverflow.com/questions/18033190/… May 10, 2015 at 14:00
-
Was the fix changing the order of
--eval
andFILE
? I am not next to a computer currently. You can correct this solution, or I will when I get next to a computer. May 10, 2015 at 14:26