0

I have run into issues using the emacs server started when I log in and emacsclient. Specifically, I use the same emacs server for different R projects things get ugly and commands from different projects end up going to the same R session.

My work around is to invoke a second server with /usr/bin/emacs --daemon=Rmd-1 when I log in. I have a bash script written such that the first .Rmd file I work with attaches to this daemon and then the command /usr/bin/emacs --daemon=Rmd-2 is issued. If I end up working with a second .Rmd file, then this server is used and a third server is started with /usr/bin/emacs --daemon=Rmd-3 and ready to work with another .Rmd file if needed.

This works pretty well except for one thing. Because after many years I am hard wired to end my emacs session using C-x C-c by the end of the day I have many emacs servers running. I'm looking for a way to trigger save-buffers-kill-emacs when the C-x C-c command is given in an emacsclient running on a daemon matching "Rmd-[0-9]+". I can't see any emacsclient options that would do that and I'm at a loss as to how to edit my custom.el file.

Can some one help me?

(note I'm running GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.30) on Ubuntu 22.04)

mikemtnbikes
  • 393
  • 2
  • 11
  • Why not just rebind C-x C-c to save-buffers-kill-emacs? `(global-set-key (kbd "C-x C-c") 'save-buffers-kill-emacs)` – McNisse Oct 30 '22 at 19:29
  • That's 50% of the solution, I need to set it up so it only uses the remapping if the for the session "daemon==R-md-[0-9]+". Any suggestions or hints would be appreciated. – mikemtnbikes Oct 31 '22 at 15:44

1 Answers1

0

Drawing on McNisse's suggestion, adding the following to my personal.el file seems to give me the desired behavior.

;; Remap C-c C-x if daemon name matches "Rmd-[0-9]+"
;;  
(cond
 ((string-prefix-p "Rmd-" (daemonp))
  (global-set-key (kbd "C-x C-c") 'save-buffers-kill-emacs)
  )
 )
mikemtnbikes
  • 393
  • 2
  • 11