I have certain org files (scientific manuscripts) that I want to automatically show in Olivetti mode with a specified width upon opening. Is it possible to enable Olivetti (or generally, any minor mode) with something like this? #+STARTUP: indent linum

Here's what I'm currently using at the top of the file, but of course I have to evaluate it with C-c C-c...

#+BEGIN_SRC elisp :exports none :results none
(olivetti-set-width 110)


3 Answers 3


As @Lorem Ipsum suggested, you can use file variables to customize things when a particular file is opened. There are a few ways to store file variables (see Specifying File Variables in the Emacs manual for details), but you can let Emacs insert them for you so you don't have to worry about the exact syntax.

The command add-file-local-variable-prop-line will add a variable to a property line at the top of the file that Emacs will process when the file is opened.

I was able to get your specific case working with the following at the top of an org file:

# -*- olivetti-body-width: 110; eval: (turn-on-olivetti-mode); -*-

It should be as simple as specifying the file variables at the top of your file. However, it's not. I suspect you're getting stuck on what variables.

The following enables olivetti mode, but doesn't seem to set the width properly:

;; -*- mode: olivetti; olivetti-set-width: 110; -*-

Such a line at the top of the file specifies file variables. Since olivetti-set-width is a function, not a variable, the line above doesn't work how we want it to.

So, what variable does olivetti-set-width set? Looking at C-h f olivetti-set-width and peeking at the source code yields olivetti-body-width. However, the following doesn't work for me either:

;; -*- mode: olivetti; olivetti-body-width: 110; -*-

I'm not sure why it doesn't work as expected. It probably has something to do with when file variables are assigned. I do notice that calling (setq olivetti-body-width 110) after the buffer has loaded changes the width. If the mode has a hook, we could just call it after the mode is loaded. Checking C-h olivetti--hook, I find olivetti-mode-hook. So...

A solution

Put the following at the top of any documents you want to open in olivetti mode. This will enable olivetti mode.

;; -*- mode: olivetti; -*-

In your init.el, put the following. This will change the body width whenever olivetti mode is enabled.

(add-hook 'olivetti-mode-hook (lambda () (interactive) (setq olivetti-body-width 110)))
  • Thanks. Putting that on the first line does invoke olivetti minor mode, however the major mode becomes fundamental instead of org. Commented Feb 21, 2019 at 19:25
  • 1
    I would use # rather than ;; -- that is, the org comment prefix rather then the elisp one. You can also let Emacs add the line for you in expected syntax: M-x add-file-local-variable-prop-line will prompt you for the variable to set and add it.
    – glucas
    Commented Feb 21, 2019 at 20:11
  • Setting mode in a file variable like this sets the major-mode, which is why you're ending up in fundamental. You should instead be able to set olivetti-mode: t to enable the minor mode while still letting Emacs pick the major mode. However, there is an issue here, which may be specific to olivettii... The mode gets enabled as expected, but then the window gets reset.
    – glucas
    Commented Feb 21, 2019 at 20:30
  • 1
    Ok, this seems to be working for me: # -*- olivetti-body-width: 110; eval: (turn-on-olivetti-mode); -*-
    – glucas
    Commented Feb 21, 2019 at 20:33
  • @glucas, nice! I feel like you should make a response so that you get the cred you deserve! :) Commented Feb 21, 2019 at 20:38

The other solutions are correct in the general sense, but to solve the problem you describe, specific to olivetti, this is what I would do:

(defun setup-olivetti (width)
  (unless olivetti-mode
    (setq olivetti-body-width width)
    (olivetti-mode 1)))

(dolist (mode '((bibtex-mode . 120)
                (emms-lyrics-mode . 80)
                (dired-mode . 120)
                (gnus-article-mode . 120)
                (LaTeX-mode . 120)
                (mu4e-compose-mode . 70)
                (mu4e-view-mode . 100)
                (nov-mode . 80)
                (org-mode . 110)
                (prog-mode . 120)
                (ess-mode . 120)))
  (add-hook (intern (concat (symbol-name (car mode)) "-hook"))
            (apply-partially #'setup-olivetti (cdr mode))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.