[
    {
        "role": "user",
        "content": "I%27m%20running%20emacs%20with%20--init-directory%20option%20but%20it%20doesn%27t%20seem%20to%20be%20reading%20init.el%20from%20there"
    },
    {
        "role": "assistant",
        "content": "If `emacs --init-directory /path/to/dir` doesn\u2019t seem to load the `init.el` under that directory, this is expected behavior under certain conditions. Here's a breakdown of how `--init-directory` works, what it *doesn't* do, and how to get it to do what you want.\n\n---\n\n## What `--init-directory` *is* and *does*\n\n- Emacs version 29 added an `--init-directory` (also called `--init-dir`) command-line option that sets `user-emacs-directory` to the specified directory. ([gnu.org](https://www.gnu.org/software/emacs/manual/html_node/emacs/Initial-Options.html?utm_source=openai))  \n- `user-emacs-directory` is used for locating \u201cother per-user Emacs files\u201d, like package files, elc caches, etc. ([gnu.org](https://www.gnu.org/software/emacs/manual/html_node/emacs/Initial-Options.html?utm_source=openai))\n\n---\n\n## What `--init-directory` *does not do*\n\n- It does **not** force Emacs to load `init.el` from the provided directory if that file doesn\u2019t exist there. If no `init.el` (or `.emacs`, etc.) is found in the specified directory, Emacs will fall back to its usual places for the init file (your home directory, `.emacs.d/init.el`, `~/.config/emacs/init.el`, etc.). ([gnu.org](https://www.gnu.org/software/emacs/manual/html_node/emacs/Initial-Options.html?utm_source=openai))  \n- Even when `--init-directory` is used, Emacs first searches for init files using its standard order. Only if the appropriate file is present under the directory pointed to by `--init-directory` will it use that. If not, it continues searching as before. ([gnu.org](https://www.gnu.org/software/emacs/manual/html_node/emacs/Initial-Options.html?utm_source=openai))\n\n---\n\n## How Emacs normally finds the init file\n\nAccording to GNU\u2019s manual:\n\nEmacs searches for your init file in roughly this order:\n\n1. `~/.emacs`\n2. `~/.emacs.el`\n3. `~/.emacs.d/init.el`\n4. `~/.config/emacs/init.el`\n\nWhichever one it finds first (and which is a file, not directory) gets loaded. ([gnu.org](https://www.gnu.org/s/emacs/manual/html_node/elisp/Init-File.html?utm_source=openai))\n\n---\n\n## Why your `init.el` might not be loading even with `--init-directory`\n\nPutting together the behavior rules above, here are the likely explanations if you're seeing your `init.el` not being used from the directory you gave with `--init-directory`:\n\n- There is **no** `init.el` (or `.emacs` etc.) in the target directory. In that case, Emacs falls back to standard locations.  \n- There **is** another init file earlier in the search order (for example, `~/.emacs` or `~/.emacs.el`) that is found first, causing Emacs to skip over both the file in `--init-directory` and possibly other standard locations.  \n- You're accidentally invoking Emacs in a way that ignores init files (for instance, using `emacs -q` or `--quick`). These flags explicitly skip loading your user init. ([gnu.org](https://www.gnu.org/software/emacs/manual/html_node/emacs/Initial-Options.html?utm_source=openai))\n\n---\n\n## What you can do to ensure the `init.el` under `--init-directory` is used\n\nHere are steps you can take to make sure Emacs picks up `init.el` from your specified directory:\n\n1. **Make sure there is a valid init file in that directory**  \n   Put `init.el` there (or `.emacs`) and ensure it has content that produces visible behavior (e.g. `(message \"Hello from custom init\")`) to verify it's being loaded.\n\n2. **Remove other init files**  \n   Temporarily move or rename `~/.emacs` and `~/.emacs.el` so they can\u2019t mask the one in your `--init-directory` directory. Because of the order, a file named `.emacs` in your home directory will take precedence over `init.el` elsewhere. ([gnu.org](https://www.gnu.org/s/emacs/manual/html_node/emacs/Init-File.html?utm_source=openai))\n\n3. **Invoke Emacs with `--init-directory` alone and no conflicting flags**  \n   Don\u2019t use `-q` or `--quick` together; those suppress user init files. E.g.:\n\n   ```\n   emacs --init-directory /path/to/dir\n   ```\n\n4. **Check what Emacs thinks its init file is**  \n   Once Emacs is started, you can check the variables:\n\n   - `user-init-file` \u2014 which path Emacs has chosen as the init file  \n   - `user-emacs-directory` \u2014 where Emacs thinks its \u201cuser\u201d directory is\n\n   You can check these with `C-h v user-init-file RET` and `C-h v user-emacs-directory RET`.\n\n5. **Use `--debug-init` to see startup behavior**  \n   Launch Emacs with `--debug-init` to catch any errors during startup that might prevent the rest of your init from executing without obvious error messages.\n\n---\n\nIf you tell me which version of Emacs you\u2019re using, what platform (Linux/macOS/Windows), and exactly how you ran the `--init-directory` command (what directory, what flags), I can help you debug more specifically."
    }
]