reddit / emacs
How do you manage several similar emacs configs?
fluffy_rock_70 · 2022-07-22 05:59
Like, if your work and personal .emacs.d are mostly the same, but some parts you only want in your personal config, some only in your work config, how do you manage this?
(reasons for the differences might be: some info is personal, you have different versions of emacs or different OS at work/home, or you use emacs for different things at work/home, etc.)
jackson15j · 2022-07-22 06:18
I do two things:
* OS agnostic config, or explicit platform checks to set OS specific config. I use `use-package`, which supports this.
* For anything that I don’t want to push to my public dot files repo, I’ll dump into a separate file that is read at the end of my `.emacs` file. Eg
```
;; ========================
;; Finally; Load extra dot files (if they exist)
;; ========================
(make-directory "~/configs" t)
(use-package cus-edit
:custom (custom-file "~/configs/emacs/custom_set_variables.el" "Moved custom-set-variables to it's own file")
)
(let () (dolist (dot_emacs '("~/configs/emacs/custom_set_variables.el"
"~/configs/emacs/private_dot_emacs.el"
"~/configs/emacs/unstable_config_dot_emacs.el"
"~/configs/emacs/work_specific_dot_emacs.el"))
"Loading my extra emacs dot files if they exist."
(when (file-exists-p dot_emacs)
(message (concat "Loading external dot file: " dot_emacs))
(load-file dot_emacs))))
```
7890yuiop · 2022-07-22 07:05
An approach I don't use myself, but really liked when I saw it:
`~/.emacs.d` is its own repository with its own `init.el` and all of your shared config (as you probably have already).
`~/.emacs` is independent (potentially in other environment-specific repositories for dotfiles), and it evaluates `(load-file "~/.emacs.d/init.el")` and any environment-specific things you want to do.
The shared config will work with or without an environment-specific `~/.emacs` file, and it's all pretty seamless.
podtatranec · 2022-07-22 07:16
Because my setups are 99.9% identical I don't actually use any elaborate system. In 1 or 2 places I have something like:
```
(when (equal (system-name) "<hostname>") <do stuff>)
```
If I had more differences I'd do the above and call some
```(load "<host specific overrides file>")```
dm_g · 2022-07-22 08:13
My approach is to use environment variables or determine the hostname of the computer and/or OS where emacs is running. This sets various variables. Then optional configurations are wrapped with if-statements:
(defvar dmg-local-host (string-trim-right (shell-command-to-string "hostname -s"))
"What is the name of the host?")
(defvar dmg-os (string-trim-right (shell-command-to-string "uname"))
"What os are we running on?")
(defvar dmg-email? (or
(string-equal dmg-local-host "silver")
(string-equal dmg-local-host "iodine")
(string-equal dmg-local-host "vanadium"))
)
(if dmg-email?
(progn
(run whatever...)))
I also use vcsh and mr-repos to distribute files (and optional files) to different computers.
deaddyfreddy · 2022-07-22 09:52
`use-package` `:if` is enough
h-m-b-tu · 2022-07-22 10:13
I split my configuration into several files for different topics. Then, I use `command-switch-alist` to react to command switches like `--Email` and `--Emacs` to load different lists of configuration files.
sadomaru · 2022-07-22 10:57
Theres a package called "modular-config"
snubbyJspreaker · 2022-07-22 12:43
plus 1! I was gonna suggest both modular-config and chemacs and note that I like modular-config, but you beat me too it.
Schievel1 · 2022-07-22 14:39
There’s this
https://github.com/plexus/chemacs2
Which does exactly what you ask for.
But I guess if only a few lines are different it a bit overpowered for you
redblobgames · 2022-07-22 15:56
Long ago, I did this:
(require (intern (user-login-name)))
(require (intern (subst-char-in-string ?/ ?-
(format "platform-%s" system-type))))
(require (intern (format "window-%s" (window-system))))
So if I'm username `fred` on a Linux/X11 system, it will run
(require 'fred)
(require 'platform-gnu-linux)
(require 'window-x)
You can add `nil t` to the arguments to skip files that don't exist. I also had some more things like this to load a package named the same as the current machine name, and all of its roots (so if my machine was `foo.bar.ibm.com` it would try loading `foo.bar.ibm.com.el`, `bar.ibm.com.el`, `ibm.com.el`, `com.el`)
I haven't kept this part of my configuration up to date so I should probably go back and update it, or remove it.
EricIO · 2022-07-22 16:23
My solution is that I have my system configuration in a got repo. My master branch is my personal configuration and then I have a branch for my work computer. Works well and is super simple.
[deleted] · 2022-07-22 20:04
[deleted]
dpoggio · 2022-07-23 00:07
I’ve been recently recording Emacs tutorials. What do I do to record and get back to my config? Pretty straightforward: I’ve something like `.emacs.d.me` and `.emacs.d.yt`. `.emacs.d` is a symlink. Small bash aliases do the trick, like `alias yt='rm .emacs.d; ln -s .emacs.d.yt .emacs.d'`. This way, Emacs is always looking to a symlink really, and I point it to wherever I want, like `~/src/emacs/conf-yt`.
EppoTheGod · 2022-07-23 23:01
I sync my configs using `git`. I have a common `.emacs` with `(load-file "path/to/my-variables.el")`, an ignored file where I set some variables. The config uses `if`s to sort out what to do based on those variables. Primitive, but good enough for me.
PuercoPop · 2022-07-24 03:28
https://tychoish.com/post/running-emacs/ I follow the pattern explained in this post, where you start multiple emacs daemons under different names and use that id to tweak.
fluffy_rock_70 · 2022-07-25 00:32
Thanks everyone for the helpful replies!
I think I'll mainly use the method 7890yuiop and jackson15j mentioned, involving putting a common configuration in .emacs.d and using .emacs for things specific to the machine.
modular-config also looks quite nice. (link: https://github.com/SidharthArya/modular-config.el )
perkinslr · 2022-07-25 07:20
Depends on if you need to support terrible OSes, and if you have admin rights on the machines (or have a sane sysadmin). Things that are specific to the machine (like the wanderlust config for work email) should go in the emacs site file (usually `/etc/emacs/site-start.el` or similar). Personally, that's all the more per-machine customization I need.
Then, you put your `~/.emacs.d` under version control (git or similar), and share it between machines. If you *need* more than `site-start.el`, have your `.emacs.d/init.el` do a `(load-file "~/.local/config/site-emacs.el")` and put the rest of your customizations there. As it is outside `.emacs.d`, it won't get included in your git repo.
zenspider · 2022-07-26 10:40
I've got mine to selectively load `os/*`, `domain/*`, and `host/*` so I can tweak at whatever layer makes the most sense.
github-alphapapa · 2022-07-28 21:56
See also https://github.com/alphapapa/makem.sh, which is much simpler to use.