plexus / chemacs

Emacs profile switcher
652 stars 45 forks source link

Add examples of using emacsclient #34

Open NightMachinery opened 4 years ago

NightMachinery commented 4 years ago

I have tried:

(("default" . ((user-emacs-directory . "~/.emacs.d.doom")))
 ("spacemacs" . ((user-emacs-directory . "~/.emacs.d.spc")
                 (server-name . spcserver)
                 )))
emacs -nw --with-profile spacemacs --daemon
emacsclient -s spcserver --alternate-editor=vim -t

But I get:

emacsclient: can't find socket; have you started the server?
To start the server in Emacs, type "M-x server-start".
vv111y commented 3 years ago

+1, the docs don't give us the necessary steps. I think we start emacs with a given profile and then start the server with M-x start-server. However this also does not work, I get:

Debugger entered--Lisp error: (wrong-type-argument stringp ("spacemacs"))
  expand-file-name(("spacemacs") "/tmp/emacs1000")
  server-start(nil)
  funcall-interactively(server-start nil)
  call-interactively(server-start record nil)
  command-execute(server-start record)
  helm-M-x-execute-command(server-start)

ADD: emacs-profile.el

 ;; ("default" . ((user-emacs-directory . "~/.emacs.d")))
 ("spacemacs" . ((user-emacs-directory . "~/spacemacs")
                 (server-name "spacemacs")
                 (env . (("SPACEMACSDIR" . "~/.spacemacs.d")))))
 ("doom" . ((user-emacs-directory . "~/doom-emacs")
            (server-name . "doom")
            (env . (("DOOMDIR" . "~/.doom.d")))))
 )
vv111y commented 3 years ago

doh, just as I was entering above comment I spotted a couple of typos. Now it works. Corrected profile:

(
 ;; ("default" . ((user-emacs-directory . "~/.emacs.d")))
 ("spacemacs" . ((user-emacs-directory . "~/spacemacs")
                 (server-name . "spacemacs")
                 (env . (("SPACEMACSDIR" . "~/.spacemacs.d")))))
 ("doom" . ((user-emacs-directory . "~/doom-emacs")
            (server-name . "doom")
            (env . (("DOOMDIR" . "~/.doom.d")))))
 )

step 1: emacs --with-profile spacemacs --eval "(server-start)" step 2: emacsclient -nc -s spacemacs

However, the server does not remain after I close initial emacs. next step. ADD: okay now I see. Yes we want to start via a daemon. the situation remains.

anquegi commented 3 years ago

Thanks for writing this package is fantastic I finally can I try easilly other configurations in emacs, just for completion of notes I use this and worked pretty well:

In console:

~ via ⬢ v12.4.0
❯ emacs --with-profile doom --eval "(server-start)" --daemon=doom
Starting Emacs daemon.
Restarting server

~ via ⬢ v12.4.0
❯ emacsclient -nc -s doom 

my configuration:

~ via ⬢ v12.4.0
❯ cat ~/.emacs-profiles.el
(("default" . ((user-emacs-directory . "~/.emacs.default")))
 ("new" . ((user-emacs-directory . "~/.emacs.d.new")))
 ("empty" . ((user-emacs-directory . "~/.emacs.d.empty")))
 ("prelude" . ((user-emacs-directory . "~/.emacs.d.prelude")))
 ("doom" . ((user-emacs-directory . "~/doom-emacs")
            (server-name . "doom")
            (env . (("DOOMDIR" . "~/.doom.d"))))))
plexus commented 3 years ago

Some examples like this would be very welcome in the README (although preferrably then on https://github.com/plexus/chemacs2)

anquegi commented 3 years ago

At this moment, It worked well But I no have complet control about the server and the emacs, I think that also I will write an issue to doom to understand how things are working:

I also have my old emacs configuration in emacs in this file I have changed to use tcp server and the directory:

(("default" . ((user-emacs-directory . "~/.emacs.default")))
 ("new" . ((user-emacs-directory . "~/.emacs.d.new")))
 ("empty" . ((user-emacs-directory . "~/.emacs.d.empty")))
 ("prelude" . ((user-emacs-directory . "~/.emacs.d.prelude")))
 ("doom" . ((user-emacs-directory . "~/doom-emacs")
            (env . (("DOOMDIR" . "~/.doom.d"))))))

like this:

(require 'server)
(setq server-use-tcp t)
(setq server-socket-dir "~/.emacs.d/server-dir")
(or (server-running-p) (server-start))

so I started emacs daemon like this, (note that emacs itself do not put the server-file here I already marked):

~ via ☕ v11.0.9 via ⬢ v12.4.0 took 21s
❯ emacsclient --daemon=calimero
emacsclient: unrecognized option '--daemon=calimero'
Try 'emacsclient --help' for more information

the file is located here:

.emacs.default/server on  master [!?]
❯ cat calimero
127.0.0.1:49503 1813
3fwK\2>y*&j;GgrP0#b^8}yzz|HkyHK&9>3usPc(C[3u+9=N$bN!p~Zq'6E]51:]%

And I can connect using this:

.emacs.default/server on  master [!?]
❯ emacsclient -nc -f /Users/toni/.emacs.default/server/calimero

I tried the same in doomemacs, but it uses by deault unix sockets, and I couldnt' change the server file directory and to tcp. It put the file on the cache of applications,

~ via ☕ v11.0.9 via ⬢ v12.4.0
❯ ls /var/folders/zs/t9wnzpqj2bdgjjgjwb8pqxc80000gn/T//emacs501
doom 

emacs found it quickly, you can change the names and have different files:

~ via ☕ v11.0.9 via ⬢ v12.4.0
❯ emacs --with-profile doom --daemon=doom
Starting Emacs daemon.

~ via ☕ v11.0.9 via ⬢ v12.4.0
❯ emacsclient -nc -s doom

It would be nice to configure all emacs start as tcp and put the files in the same folder. but if you don't play reconfiguring doomemacs server-start I do not have any problem. Really I do not thing that using tcp or unix sockets will fbe a real issue except in windows but this also can be a solution for me now, I will investigate alittele more

paxperscientiam commented 2 years ago

To contribute another piece to a solution (i'm on v2 btw), here's a snippet from me:

# depends on chemacs
function spacemacs() {
    if [[ ! -S "${TMPDIR}/emacs${UID}/spacemacs" ]]; then
        command emacs --with-profile spacemacs "$@"
    else
        command emacsclient -t -s spacemacs "$@"
    fi
}

note: emacs${UID} evaluates to emacs501 for me.