commit ef8718d8546ec990385f7b97482af85f323e6164
parent 15b90b5649a712688a8769f6956b170300467d78
Author: Alex Balgavy <alex@balgavy.eu>
Date: Wed, 16 Mar 2022 13:52:08 +0100
emacs: switch to using daemon
This commit includes various settings for the daemon. I can start or
connect to the Emacs server with `emacsclient -c -a ''`. On macOS, I
created an app via Automator to just run that as a shell script.
Diffstat:
2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/emacs/config.org b/emacs/config.org
@@ -277,8 +277,6 @@ And I'm not gonna be a heretic and open Vim inside of Emacs.
#+begin_src emacs-lisp
(use-package vterm
- :config
- (setq vterm-environment '("EDITOR=emacsclient"))
:hook
(vterm-mode . (lambda () (unless server-process (server-start)))))
#+end_src
@@ -1449,7 +1447,33 @@ So I create a keybinding to toggle dedicated on a window:
#+end_src
+* Daemon
+I want to have a way to kill the Emacs daemon.
+So, define a function that kills the frame, and with a prefix kills emacs.
+
+#+begin_src emacs-lisp
+ (defun za/emacsclient-c-x-c-c (&optional arg)
+ "If running in emacsclient, make C-x C-c exit frame, and C-u C-x C-c exit Emacs."
+ (interactive "P") ; prefix arg in raw form
+ (if arg
+ (save-buffers-kill-emacs)
+ (save-buffers-kill-terminal)))
+#+end_src
+
+Then, if I'm in an emacsclient, I want to bind C-x C-c to that function (if not, I just want the default keybinding):
+
+#+begin_src emacs-lisp
+ ;; If not running in emacsclient, use the default bindings
+ (if (daemonp)
+ (global-set-key (kbd "C-x C-c") #'za/emacsclient-c-x-c-c))
+#+end_src
+
+Furthermore, I want to set the theme correctly whenever I connect with 'emacsclient':
+#+begin_src emacs-lisp
+ (if (daemonp)
+ (add-hook 'after-make-frame-functions #'za/auto-select-theme))
+#+end_src
* Notmuch
Define some saved searches (i.e. mailboxes):
diff --git a/emacs/init.el b/emacs/init.el
@@ -5,7 +5,7 @@
;; Get rid of all bars
(setq org-src-tab-acts-natively t)
-(when window-system
+(when (or window-system (daemonp))
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)