How do you define and call a function in Spacemacs?

☆樱花仙子☆ 提交于 2021-02-07 18:36:38

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/44042620/how-do-you-define-and-call-a-function-in-spacemacs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!