1

I load multiple daemons service at startup with systemd. The purpose of this is to have each one for different applications, one for C coding, one for Ocaml, one for Org...

I have a configuration file for each client which is passed to -e with load-file when running the daemon. I want to set the dedault major mode of the scratch buffer for each one of them, so in the config file I have, for the ocaml config as example :

 (setq initial-major-mode 'tuareg-mode)
 (setq initial-scratch-message "\
 (* This buffer is for notes you don't want to save, and for OCaml code.
 * If you want to create a file, visit that file with C-x C-f,
 * then enter the text in that file's own buffer. *)")

The message is written but the major mode is still lisp.

What happens and how I can I fix that ?

  • Apparently the scratch buffer already exists by the time the command line arguments are evaluates. It seems that you have to change this setting in your init file. – lunaryorn Dec 18 '15 at 7:26
  • I can kill it and then restart it... I also could start the scratch buffer after load. Is there a proper variable to start the scratch buffer after load ? – Nicolas Scotto Di Perto Dec 18 '15 at 8:03
  • No I don't think so. Emacs must create an initial buffer early, there's no way to delay that. Why can't you set the option in your init file? – lunaryorn Dec 18 '15 at 8:22
  • Because like I said I want to have different configurations for each daemon, e.g. the daemon called ocaml will have an OCaml scratch buffer, the Perl daemon will have a Perl scratch buffer, etc... So each daemon needs a different configuration. Off course, they share the same .init, but they also includes a proper configuration file. Does that make sense ? – Nicolas Scotto Di Perto Dec 19 '15 at 11:40
  • Well, just pass the daemon name to your Emacs and inspect it in your init file, e.g. set a custom environment variable in the systemd unit file and check the value with getenv. – lunaryorn Dec 19 '15 at 11:45
1

You cannot change initial-major-mode in a file loaded with -l, because by the time it's loaded the initial buffer was already created.

You need to set this variable in your init file. To create different scratch buffer in different Emacs daemons, pass an environment variable while you start that daemon instance, e.g.

$ export MY_EMACS_DAEMON="ocaml"
$ emacs --daemon …

In your init file inspect the value of the variable and set initial-major-mode accordingly, e.g.

(when (string= (getenv "MY_EMACS_DAEMON") "ocaml")
  (setq initial-buffer-choice 'tuareg-mode))

To set this variable in a systemd unit file use the Environment= option, as in:

Environment=MY_EMACS_DAEMON=tuareg
  • Actually I don't know why but this cause the service fails to start. I have added the Environment in systemd, theres another Environment for ssh but I've put it in two lines like how it should be. My wm login take about 4sec instead of 0s and then I can't start clients. I have tried both executing the correct mode and loading the config file when the environment is right but it fails at some points and I have no clue why... I should mention that the daemons are running. I have encountered the same kind of behaviour when there was some bad lisp in my .init but I have checked it like 10 times. – Nicolas Scotto Di Perto Dec 19 '15 at 22:14
  • @NicolasScottoDiPerto I don't know, you should probably ask a separate question on superuser about your systemd configuration. It's long since I used Linux, and I'm afraid I can't help you with this strange problem. – lunaryorn Dec 19 '15 at 22:16
  • The line (when (string= (getenv "MY_EMACS_DAEMON") "ocaml") (setq initial-buffer-choice 'tuareg-mode)) in the .emacs cause the service failing to start. I have tried to replace it with something a simple (when (string= (getenv "MY_EMACS_DAEMON") "ocaml") (message "hello ocaml !") and it fails too. I guess I need another trick if there is one but thank you. Having separate config is a bit trickier than I expected. – Nicolas Scotto Di Perto Dec 21 '15 at 9:49
  • That would happen when the variable isn't set. Try to replace string= with equal, and make sure that the variable is properly exported, i.e. inspect process-environment in your daemon instance. – lunaryorn Dec 21 '15 at 10:03
  • Ok finally I did some good testing and I have found the source of problems, both functions string= and equal work well, in fact it's (setq initial-major-mode 'tuareg-mode) who fails with the damon. It works without the daemon but fails with it... I'm stuck. – Nicolas Scotto Di Perto Dec 21 '15 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.