How to check if a function (e.g. server-running-p) is available under Emacs?

后端 未结 3 570
予麋鹿
予麋鹿 2021-01-01 17:28

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-runnin         


        
相关标签:
3条回答
  • 2021-01-01 18:08

    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))
    
    0 讨论(0)
  • 2021-01-01 18:21

    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.

    0 讨论(0)
  • 2021-01-01 18:24

    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))
    
    0 讨论(0)
提交回复
热议问题