reddit / emacs

Does Emacs provide the ability to separate your `.emacs.d` directory from your "working/project directory"?

vfclists · 2022-12-12 15:33
**UPDATE:** From a number of the replies I see my question is misunderstood. I have elaborated in this [additional comment](https://www.reddit.com/r/emacs/comments/zk28yg/does_emacs_provide_the_ability_to_separate_your/j0gfame/) When I'm running multiple instances of the same `.emacs.d` configuration on different projects simultaneously some of the settings files like `recentf` and the `history` file created by `savehist` can and do conflict with each other. Does Emacs have a way of enabling the user of a particular `.emacs.d` but allow the project or session settings to be separate? Creating doom profiles for each user account does get time consuming. I have been able to create some workarounds for such issues, such as this way of setting a separate `custom.el` file when I run a profile copied to different user accounts on different computers. (setq custom-file (format (expand-file-name "%s-%s-cukstom.el" user-emacs-directory) (getenv "USER") (getenv "HOST"))) I have noticed that Emacs has a command-line option `--user` that allows the usage an `.emacs.d` belonging to another user which would help avoiding replicating `.emacs.d` for different user accounts and going through whole doom compilations, but I need something for the particular `.emacs.d` as well as the project. Is there some package that makes such things easier? I already user Chemacs2 to keep the `.emacs.d` options separate, but this needs to be on a project or directory basis, ie profile + project/working directory
Alan_Shutko · 2022-12-12 15:56
Could you explain a bit more why you need to keep separate configurations for different projects? That is not something that is very common, and most people use the same configuration for all projects and have different mechanisms for setting things that need to be specific to a particular project.
White86ec · 2022-12-12 16:07
There is --init-directory flag in some of the recent emacs versions. Also, .dir-locals.el in the project root might help too
paretoOptimalDev · 2022-12-12 16:41
(setq custom-file (format (expand-file-name "%s-%s-cukstom.el" user-emacs-directory) (getenv "USER") (getenv "HOST"))) Put the above code in a .dir-locals.el file for each project? I'd recommend using `add-file-local-variable-prop-line` rather than making the file by hand as described in https://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html
vfclists · 2022-12-12 17:11
> Could you explain a bit more why you need to keep separate configurations for different projects? Actually it is the same `.emacs.d` configuration running in different projects at the same time, so some of the settings that default to some subdirectory under `user-emacs-directory` should not conflict Eg, when I press `C-x b` in one project I don't want to see the recent files from one show in other. The package configurations should be the same, but some of the runtime settings should not, but should go into the project directory. This post shows some similar config I created to manage `doom` profiles, but if I'm running multiple sessions of the same profile, some project related settings should not conflict.
FrozenOnPluto · 2022-12-12 17:15
Maybe you're just looking for projectile features.. I \_think\_ projectile has a 'open files recently visited within project' operation; I usually just use 'open file within project' operation to use my preferred completing-read handler on the file set within a project, but I think you can do that to recently opened files too. But if you're just using raw recentf... Maybe update (for example) recentf-save-file var to point to where you want the info to go, based on the project you're in (and what do you expect to happen if you open files from multiple projects while looking in one project?) Using multiple .emacs.d seems unusual to me, beyond experimentation with features or alternate emacs distributions, but you be you :)
eleven_cupfuls · 2022-12-12 17:42
Try `C-x p b` (`project-switch-to-buffer`) instead. For settings that vary between projects, you want [Directory variables](https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html). And in general, look into either project.el (the built in project system) and packages that extend it or projectile (a great external package for handling projects). In short, you don't need to change your base config; there are features to support working with projects.
gf3 · 2022-12-12 22:00
I’ll also add that along with project.el/projectile [persp-mode](https://github.com/Bad-ptr/persp-mode.el) can be configured to work as you desire. persp-mode allows you to create different perspectives (or groups) of buffers. I usually have a few different perspectives and a project open in each of them.
freegnu · 2022-12-12 23:35
This does what it says on the tin. Used it before to run Doom, Spacemacs, and vanilla simultaneously. https://systemcrafters.cc/emacs-tips/multiple-configurations-with-chemacs2
holgerschurig · 2022-12-13 12:33
You can have your emacs config also in `~/.config/emacs/` if you like.
hangingpawns · 2022-12-14 07:17
99% of the time, the user never gets the answer to his/her question. Instead, you get moronic answers of people telling you why what you're doing is wrong, instead of answering the question. The answer is: there's an --init-directory flag you can pass when you launch emacs.
hangingpawns · 2022-12-14 07:17
99% of the time, the user never gets the answer to his/her question. Instead, you get moronic answers of people telling you why what you're doing is wrong, instead of answering the question. The answer is: there's an --init-directory flag you can pass when you launch emacs.
vfclists · 2022-12-16 13:35
I think many responders have misunderstood my question. I don't want to use a different `.emacs.d` for each project, I need to run multiple emacs instances using the same `.emacs.d` in each one. For instance I am learning Django/Python and have two websites running so I have launched `emacs -nw --with-profile python` twice, each running in its own `screen` window. But some of the settings runtime related settings clobber each other. So if I do a `C-x b` in one session I have files from the other session appearing in it. I need to have a way of keeping some of the settings which generally go into the `.emacs.d` directory into a separate directory related to the project and I wonder if Emacs has some kind of switch which puts such files into a project related directory, such as the data from `history` data from `savehist`. For instance now that emacs 29 has the `--init-directory` which sets the `.emacs.d` for that session, (the native equivalent of the Chemacs2 `--with-profile profile-name` option), I also need a `--settings-directory` when starting a session using the same `--init-directory` so that settings related that emacs session, both runtime and after the session ends, don't conflict with settings related to other emacs sessions which may be running concurrently. I am a user of the Lazarus IDE and it handles this very well.