Emacs: Set writeroom mode as default

863 views Asked by At

I am new to emacs and I am wondering if I can set the writeroom-mode to always be on. I want it to be on as I start up emacs and as I open new buffers or switch between them.

All help is highly appreciated!

2

There are 2 answers

0
phils On BEST ANSWER

So now that you've provided a link (albeit in your other question), I can see that the library provides a global minor mode which only turns itself on for a specific configurable set of major modes.

The following will redefine the function which makes that decision, so that if the writeroom-major-modes is nil (empty list), it will turn on for any major mode.

I also changed the existing test to check for a derived mode match, rather than simply an exact match. That way the default value of '(text-mode) would match not only text-mode, but every mode derived from text-mode. Not strictly relevant to your question, but perhaps useful if you find the "all modes" approach overkill.

(eval-after-load 'writeroom-mode
  '(defun turn-on-writeroom-mode ()
     "Turn on `writeroom-mode'.
This function activates `writeroom-mode' in a buffer if that
buffer's major mode is a member of `writeroom-major-modes',
or derived from one of those modes.

If `writeroom-major-modes' is nil, activate `writeroom-mode'
in ALL buffers."
     (when (or (not writeroom-major-modes)
               (apply 'derived-mode-p writeroom-major-modes))
       (writeroom-mode 1))))

Whether you need to explicitly load/require the library depends on how you've installed it; but as you're using the library already, that's presumably been taken care of, meaning it's then just a case of:

(global-writeroom-mode 1)

Alternatively (to all of the above), you could ignore the global mode provided, and create your own alternative global minor mode, as described in How to enable a non-global minor mode by default, on emacs startup?

Edit: Well I've had a bit of a play with writeroom-mode, and it would seem there are very good reasons why its global mode was a bit conservative. You might still find the "derived mode" improvement useful, but I suspect trying to make this particular mode 100% global is not going to work very well at all.

0
Drew On
  • If write-room mode is a globalized minor mode, then just turn it on in your init file.

  • If write-room mode is a minor mode and there is no globalized version of it, you can use define-globalized-minor-mode to define such a globalized mode. Then turn that on in your init file.

  • If write-room is a major mode then you can customize option auto-mode-alist to turn it on for any number of file-name extensions.

  • If write-room is an ordinary function (not a major-mode function) then you can automatically turn it on by using add-hook to add it to the major modes you use.

And yes, if you specified what write-room is (in Lisp terms) then answering your question would be easier.