如何检查Emacs下的功能(例如服务器运行-p)是否可用? [英] How to check if a function (e.g. server-running-p) is available under Emacs?

查看:96
本文介绍了如何检查Emacs下的功能(例如服务器运行-p)是否可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检查我的.emacs文件中是否提供了 server-running-p 。我已经有以下内容:

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

但是在使用Emacs的某些电脑上,调用(server- running-p)给出错误,因为所述呼叫不可用。所以我想在调用之前检查 server-running-p 是否可用。我认为 boundp 会尝试,但调用(boundp'server-running-p) return nil 即使(server-running-p)调用成功。检查调用 server-running-p 的正确方法将不会失败...或者至少在所述调用失败时抑制错误。 (还有什么样的奇怪对象是 server-running-p 无论如何 boundp 返回 nil ,但是调用成功?)

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?)

这是在Emacs 23.2.1上,如果有任何区别。

This is on Emacs 23.2.1, if it makes any difference.

其实找到答案。由于某种原因,您必须使用 fboundp 而不是 boundp

Actually found the answer. You have to use fboundp for this instead of boundp, for some reason.

推荐答案

boundp 检查是否绑定了一个变量。由于 server-running-p 是一个函数,您将需要使用 fboundp 。像这样:

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

这篇关于如何检查Emacs下的功能(例如服务器运行-p)是否可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆