reddit / emacs

Working: Emacs Daemon and Client in Windows 11

RememberToBackupData · 2022-12-07 22:54
Just went through this, so I thought I'd document it for Google. What I wanted was a) for Emacs to open new files in the same frame where possible, and b) for my init.el to actually work in the new frames. ### 1. Put .emacs.d in user folder It saves a lot of messing around if your .emacs.d is in _C:\Users\[username]\AppData\Roaming_, but if you're like me, you actually keep it on Dropbox or something. So I made a symbolic link that points to it on Dropbox: - Start an elevated (admin) cmd prompt - `cd C:\Users\[username]\AppData\Roaming` - `mklink /D .emacs.d C:\Dropbox\Apps\emacs\.emacs.d` (for example) ### 2. Make a shortcut to start the Emacs Daemon 1. Make a shortcut to _emacs-28.1\bin\emacs.exe_ 2. Add ` --daemon` to the end of the **Target** (e.g. _C:\Dropbox\Apps\emacs\emacs-28.1\bin\emacs.exe --daemon_) 3. I didn't change **Start In**. 4. Put this shortcut into your Startup folder (_C:\Users\[username]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup_) so that a new server starts with Windows. 5. Run this now to start the server. ### 3. Make a shortcut to Emacs ClientW 1. Make a shortcut to _emacs-28.1\bin\emacsclientw.exe_ 2. Add ` -n -t -a ""` to the end of the **Target** (e.g. _C:\Dropbox\Apps\emacs\emacs-28.1\bin\emacsclientw.exe -n -t -a ""_) 3. I didn't change **Start In**. The presence of `-t` lets you run this shortcut to open a new Emacs client frame that starts at \*scratch\*. The *absence* of `-c` makes Emacs open files in an existing frame instead of _c_reating a new one. ## _This emacsclientw shortcut is what you point to when you're telling Windows what app to use to open text files etc._ ### 4. Make some changes to init.el ;; Set custom font here or else new frames won't see it (add-to-list 'default-frame-alist '(font . "Hack-12")) ;; You may want to have dired start in a specific folder (setq default-directory "C:/Dropbox/")
Thaodan · 2022-12-08 05:54
`;; Makes new files open in the same frame` `;; Works together with the omission of -c from the emacsclientw.exe shortcut.` `;; https://superuser.com/a/431601` `(setq ns-pop-up-frames nil)` That won't work on Windows.
RememberToBackupData · 2022-12-08 19:07
Ah you’re right!