1

I would like to know if it is possible, with a single command from bash, to open a file with emacs -nwand execute a command in the same time, for example goto-line 20.

4

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 FILE +LINE:COL 

Of course, as you want to jump to a specific line number in terminal mode, you can do

emacs -nw FILE +LINE

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? – falematte May 10 '15 at 13:20
  • Updated my answer with the generic solution as well – Kaushal Modi May 10 '15 at 13:22
  • 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? – falematte May 10 '15 at 13:52
  • The answer to this question seems to be this one stackoverflow.com/questions/18033190/… – falematte May 10 '15 at 14:00
  • Was the fix changing the order of --eval and FILE? I am not next to a computer currently. You can correct this solution, or I will when I get next to a computer. – Kaushal Modi May 10 '15 at 14:26

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.