I configured Emacs (28.1) to open an index file (index.org) at startup. Now I would like this file to be opened in view-mode. I tried

(setq initial-buffer-choice "~/PATH/index.org")
(view-mode t)

but index.org doesn't open in view-mode. How could I achieve this?


2 Answers 2


You need to turn view-mode on in the buffer of index.org. What you are doing is turning it on in whatever buffer is current when the view-mode call is evaluated. Try

(setq initial-buffer-choice "~/PATH/index.org")
(with-current-buffer (find-file-noselect "~/PATH/index.org")
   (view-mode t))
  • Thanks, it works perfectly!
    – crocefisso
    Jul 12 at 12:30

If you aren't comfortable with emacs-lisp, you can add the following three lines to the very bottom of your ~/PATH/index.org, and save it. Next time when you open that file in Emacs, it will be read-only.

# Local Variables:
# eval: (view-mode 1)
# End:

If you don't want to close Emacs, you can try re-visiting the file in same session with M-x revert-buffer RET. Now try editing the file, and see what happens.

The above suggestion will work only for org files.

You can add the above 3 lines with

  1. M-x add-file-local-variable <return> eval <return> ( view-mode SPC 1) <return>
  2. C-x C-s
  3. C-x C-v <return>

This will add the 3 lines that I suggested previously. Remember to save the file.

Above 3 steps will work for any file.

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.