I'm trying to use a very simple minor mode I've written to personnalize the appearance of the buffer when I'm running R in ESS.

Basically, I've set the linespacing in my init file to increase it and want this line spacing be turned to nil when I load ESS.

Here is the .el file I've written so far.

(define-minor-mode ess_XXX-mode
  "Personal configuration of ESS'"
  :lighter " ess_XXX")

(setq line-spacing 1)
(set-face-attribute 'default nil :height 110)

(add-to-list 'minor-mode-alist '(ess_XXX-mode " ess_XXX"))

(provide 'ess_XXX-mode)

When I eval the buffer, this works but on all buffers. When I run Emacs, I'm not able to load the minor-mode...

I've added the following in my init file

(require 'ess_XXX-mode)
(add-hook 'iESS-mode-hook 'ess_XXX-mode)

but again this works on all the buffers without any restriction. It seems Emacs cannot find the minor mode (I've stored the .el file in my .emacs.d/ directory).


3 Answers 3


You don't need a minor mode to customize the appearance of a major mode. You can do that more simply with a function called from the mode hook:

(defun my-ess-hook ()
    (setq line-spacing 1))

(add-hook 'iESS-mode-hook 'my-ess-hook)

(set-face-attribute 'default ...) will change the default face for the whole Emacs frame, it doesn't apply to a single mode or buffer alone. I'm not sure there is a straightforward way to customize the default face for one buffer or mode only.


Your ess_XXX-mode.el file needs to be in a directory which is present in your C-hv load-path list.

Your ~/.emacs.d directory is not present in that list by default (and you should not add it).

If necessary, create a new directory such as ~/.emacs.d/lisp and add that to your load-path.

(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp"))
  • OK, now my minor mode loads every time I launch Emacs. It seems I'm not able to differentiate the loading to a specific mode.
    – Guillaume
    Oct 4, 2021 at 6:42
  • Of course -- require is for loading libraries. If you want to load-on-demand then use autoload.
    – phils
    Oct 4, 2021 at 9:26

See the doc string for define-minor-mode: (define-minor-mode MODE DOC [KEYWORD VAL ... &rest BODY]). IOW, the code that should be executed when the mode is enabled (and also when the mode is disabled) has to be included as the BODY in the define-minor-mode form. Something like this:

(define-minor-mode ess_XXX-mode
  "Personal configuration of ESS'"    ; DOC
  :lighter " ess_XXX"                 ; KEYWORD-VALUE pairs
  ;; here comes the BODY
     ;; mode was turned on
     ... code to execute when the mode is turned on ...
     ;; mode was turned off
     ... code to execute when the mode is turned off ...

Many minor modes do not need a BODY at all, but since you are modifying global variables, it seems to me that yours does.

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.