I'm trying to check if server-running-p is available in my .emacs file before calling it. I already have the following:
(if (not (server-running-p))
(server-start))
But on some computers where I use Emacs, calling (server-running-p) gives an error because said call is not available. So I want to check if server-running-p is available before calling it. I thought boundp would do the try, but calling (boundp 'server-running-p) return nil even though the (server-running-p) call succeeds. What's the right way to check that calling server-running-p won't fail... or at least to suppress the error if said call fails. (And what kind of weird object is server-running-p anyway that boundp returns nil, but calling it succeeds?)
This is on Emacs 23.2.1, if it makes any difference.
Actually found the answer. You have to use fboundp for this instead of boundp, for some reason.
boundp checks to see if a variable is bound. Since server-running-p is a function you'll want to use fboundp. Like so:
(if (and (fboundp 'server-running-p)
(not (server-running-p)))
(server-start))
A simpler way is to use "require" to make sure the server code is loaded. Here's what I use:
(require 'server)
(unless (server-running-p)
(server-start))
ryuslash’s suggestion was really helpful, but I modified it for my .emacs:
(unless (and (fboundp 'server-running-p)
(server-running-p))
(server-start))
This gets the server running even if server.el hasn't been loaded—server-running-p is only defined when server.el is loaded, and server-start is autoloaded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With