To disable global-linum-mode
for specific major-modes, see automatically disable a global minor mode for a specific major mode
[Inasmuch as olivetti-mode
is a minor-mode that is enabled subsequent to whatever major-mode is already present in the buffer, the original poster may wish to turn off linum-mode
locally in the current buffer by adding (linum-mode -1)
to the tail end of the function my-writing
(see below). That idea, however, assumes that the original poster wanted to have linum-mode
active in the current buffer just prior to calling my-writing
.]
The function my-writing
in the initial question contains an extra set of parenthesis that should be omitted, and the hook setting is not in proper form.
olivetti-set-width
is a function that takes one argument, so you cannot use setq
-- see function beginning at line 197: https://github.com/rnkn/olivetti/blob/master/olivetti.el setq
is used when setting a variable, not a function.
Although flyspell-mode
is generally buffer-local, it is a good idea to get in the habit of using an argument of 1
to turn on a minor-mode or a -1
or 0
to turn it off. When an argument is omitted, calling the minor-mode works as an on/off toggle.
Unless there are other items already attached to the olivetti-mode-hook
that require prioritization or special reasons for using a hook with buffer-local settings, you do not need the optional arguments for add-hook
-- i.e., APPEND and LOCAL.
There is no apparent reason to call (olivetti-mode)
as part of the olivetti-mode-hook
that gets called automatically at the tail end of initializing the minor-mode, so there is now a check to see whether that mode has already been enabled. The olivetti-mode-hook
is being included in this example to demonstrate how to format its usage. However, the original poster should consider eliminating (add-hook 'olivetti-mode-hook 'my-writing)
as it appears to serve no purpose if the user will be calling M-x my-writing
instead of M-x olivetti-mode
. The hook would be useful in the latter circumstance -- i.e., when typing M-x olivetti-mode
-- in which case, there is really no need to have (unless olivetti-mode (olivetti-mode 1))
as part of my-writing
.
#+BEGIN_SRC emacs-lisp
(defun my-writing ()
"Start olivetti mode, set the width to 120, turn on spell-check."
(interactive)
(unless olivetti-mode (olivetti-mode 1))
(linum-mode -1) ;; see comments above
(olivetti-set-width 120)
(flyspell-mode 1))
;; original poster to consider eliminating this hook
(add-hook 'olivetti-mode-hook 'my-writing)
#+END_SRC