3

Using emacs 25.2.2 on Kubuntu 18.04.

I have customized several variables using M-x customize-variable. So, there is a large custom-set-variables section at the very beginning of my init.el. Moreover, there are several key-bindings, etc. in the same file.

Now, I want to separate my customizations across different files. So, all org-related customizations (variables and key-bindings) will go in org-settings.el, etc.

So, I created org-settings.el with the

(custom-set-variables
 '(org-agenda-follow-indirect t)
 '(org-agenda-show-inherited-tags nil)
 '(org-agenda-skip-scheduled-if-done t)
 '(org-agenda-span (quote day))
)
;; Useful key bindings
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cc" 'org-capture)
(global-set-key "\C-cl" 'org-store-link)

In my init.el I then added (load "org-settings.el").

Funny thing is, every time I restart emacs, all org custom variables from org-settings.el are copied back to init.el.

How do I solve this? I would love to have a clean init.el.

4

It seems to be possible with an extra package.

Initsplit

Initsplit (initially written by John Wiegley — one of the co-maintainers of Emacs) was designed for exactly this purpose. Unfortunately, it doesn't seem to be actively maintained, but it still works and appears to be used by people. Also unfortunately it's not on ELPA or MELPA, so you'll need to download it manually.

In a terminal:

mkdir -p ~/.emacs.d/lisp/
cd ~/.emacs.d/lisp/
git clone https://github.com/dabrahams/initsplit

and add the following to your init.el:

(add-to-list 'load-path "~/.emacs.d/lisp/initsplit/")
(require 'initsplit)

(Obviously, you could download initsplit.el by some other method and you could place it wherever you wish.)

Now you need to configure initsplit to place your org-related customisations in the right place, which is done by setting the value of initsplit-customizations-alist (it has a relatively comprehensive docstring). This can be done either with setq or via customize, as for most variables.

As stated in the docstring, initsplit-customizations-alist should be a list of lists of the form:

'((REGEXP1 FILE1 BYTECOMP PRE-LOAD)
  (REGEXP2 FILE2 BYTECOMP PRE-LOAD)
  [...] )

I haven't managed to get the automatic "pre-load" to work and byte-compiling "customize" is probably overkill, so I recommend setting the two last elements to nil. In your case, assuming that you only want to separate out org-related customizations, and that you used customize, you should have the following lines in your main custom-set-variables block:

'(initsplit-customizations-alist
  (quote
   (("\\`org-" "~/.emacs.d/lisp/org-settings.el" nil nil))))

(The escaped backquote in the "\\`org-" regexp is used for matching only the start of the variable name, so that, say foobar-org-variable isn't matched.)

Finally, you need to ensure that lisp/org-settings.el is loaded (though again obviously you can use whatever paths you wish):

(add-to-list 'load-path "~/.emacs.d/lisp/")
(load "org-settings")

Alternatives (use-package with :custom)

If you use use-package, you could try moving the relevant variables to a section of the form:

(use-package org
  :custom
  (org-agenda-follow-indirect t)
  (org-agenda-show-inherited-tags nil)
  (org-agenda-skip-scheduled-if-done t)
  (org-agenda-span (quote day)))

However, this has the considerable disadvantage that if you make further customisations, with customize-variable, these will still be added to the main custom-set-variables block (and these changes might not have a permanent effect...).

Here there is some discussion on combining use-package's :custom with initsplit, to overcome the disadvantage, but it hasn't been integrated into use-package.

More alternatives

You may already be aware of this, but there's an option to save all (unfortunately) your customizations in a file other than .emacs/init.el:

(setq custom-file "~/.emacs-custom.el")
(load custom-file)

In this case, your customizations would be sourced from and saved to ~/.emacs-custom.el, rather than from the init file. (Example taken from the manual, which has some further details.)

This has the advantage that your init file would be kept clean, but the disadvantage that your customizations would not be grouped by package/mode/topic but still clumped all together.

1

I have this in my configuration:

(setq custom-file "~/.emacs.d/garbage.el")

and I don't (load custom-file) at all. Instead, I use the customize interface to try out new settings, but whenever I decide to keep a customization I put it by hand in the proper spot in my init.el.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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