您如何在Spacemacs中定义和调用函数? [英] How do you define and call a function in Spacemacs?

查看:46
本文介绍了您如何在Spacemacs中定义和调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 defun dotspacemacs/user-config()中定义了emacs/lisp函数,如下所示:

 (defun clientdir()文档字符串"neotree-dir〜/Projects/Clients") 

如何执行?

解决方案

该函数将评估 neotree-dir 变量并丢弃结果,然后评估〜/Projects/Clients"字符串并返回它.

即您的函数无条件返回值〜/Projects/Clients" (除非未将 neotree-dir 绑定为变量,在这种情况下,它将触发错误)./p>

猜测,您想调用名为 neotree-dir 的函数,并将其作为〜/Projects/Clients" 传递给争论?看起来像这样:(neotree-dir〜/Projects/Clients")

如果要交互式调用函数 ,则必须将其声明为 interactive 函数:

 <代码>(defun clientdir()在〜/Projects/Clients上调用`neotree-dir'"(交互的)(neotree目录〜/Projects/Clients") 

然后可以使用 M-x clientdir RET 对其进行调用,或将其绑定到键序列,等等.

I've defined a emacs / lisp function within defun dotspacemacs/user-config () like so:

(defun clientdir ()
"docstring"
neotree-dir "~/Projects/Clients"
)

How do I execute it?

解决方案

That function will evaluate the neotree-dir variable and discard the result, then evaluate the "~/Projects/Clients" string and return it.

i.e. Your function unconditionally returns the value "~/Projects/Clients" (unless neotree-dir is not bound as a variable, in which case it will trigger an error).

I am guessing that you wanted to call a function called neotree-dir and pass it "~/Projects/Clients" as an argument? That would look like this: (neotree-dir "~/Projects/Clients")

If you want to call the function interactively you must declare it as an interactive function:

(defun clientdir ()
  "Invoke `neotree-dir' on ~/Projects/Clients"
  (interactive)
  (neotree-dir "~/Projects/Clients"))

You can then call it with M-x clientdir RET, or bind it to a key sequence, etc...

这篇关于您如何在Spacemacs中定义和调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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