如何在 Spacemacs 中定义和调用函数?

Chr*_*ski 4 emacs spacemacs

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

(defun clientdir ()
"docstring"
neotree-dir "~/Projects/Clients"
)
Run Code Online (Sandbox Code Playgroud)

我该如何执行它?

phi*_*ils 5

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

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

你想调用一个名为neotree-dir并传递它的函数"~/Projects/Clients"作为参数传递?那看起来像这样:(neotree-dir "~/Projects/Clients")

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

(defun clientdir ()
  "Invoke `neotree-dir' on ~/Projects/Clients"
  (interactive)
  (neotree-dir "~/Projects/Clients"))
Run Code Online (Sandbox Code Playgroud)

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