I want to write a function that does one thing if erc is running and starts erc (using command erc) if not.
I tried to write it myself, but I couldn't find out how to check if erc is running. How can I do this in elisp?
I want to write a function that does one thing if erc is running and starts erc (using command erc) if not.
I tried to write it myself, but I couldn't find out how to check if erc is running. How can I do this in elisp?
There are two aspects: is there an erc process running in the buffer? and if there is such a process, is there an established network connection to the server?
If you look in erc.el, you will see how erc itself determines the process status to add to the mode line (line 6438 in the file):
...
(let ( ...
(process-status (cond ((and (erc-server-process-alive)
(not erc-server-connected))
":connecting")
((erc-server-process-alive)
"")
(t
": CLOSED")))
IOW, it uses the function erc-server-process-alive to check whether the process is alive and the value of the variable erc-server-connected to see if it is connected to the server: if it is alive but not connected to the server, it reports "connecting"; else if it is alive, it reports nothing (i.e. everything is good); else it reports "CLOSED".
You should check the doc strings of the function above (C-h f erc-server-process-alive) and the variable (C-h v erc-server-connected) and read them carefully, but this should allow you to determine the state of erc.