Search code examples
emacselispemacs24

Emacs: Set writeroom mode as default


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!


Solution

  • 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.