Can we open up a file in emacs with a given mode (e.g. for90-mode) from the command line? I want to start this way from a script (bash) function.

  • 1
    emacs usually accept the -e option that causes it to evaluate its arguments as elisp expressions. You could use this to evaluate an expression that switches to a specific mode and then opens a file (or the other way around). – Claudius Nov 13 '12 at 17:23

Use the -eval option to run whatever commands you want.

For example, this opens emacs in the terminal, opens a new named buffer, and switches to ruby-mode:

emacs -nw -eval '(progn (switch-to-buffer "new_script") (ruby-mode))"

If your filename is named correctly (usually the extension) then auto-mode-alist should handle this for you.

If needed you may need to add to auto-mode-alist in order to make for90-mode be the one that is started for you.

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.