【问题标题】:I'm trying to shadow find-file in Emacs, why is this function yelling at me about arguments?我试图在 Emacs 中隐藏 find-file,为什么这个函数对我大喊大叫?
【发布时间】:2017-02-06 16:44:01
【问题描述】:

我最近从 Vim 转换为 Evil 模式,我正在努力让环境更加熟悉。我想念的一件事是 Vim 中的 find 命令。我试图通过将find-file 命令包装在一个函数中来在 Emacs 中设置类似的东西。到目前为止,我有这个:

(defun find nil
  "Shadow vim find command, with helm."
  (interactive)
  (find-file))

当我运行命令时,它对我大喊,Wrong number of arguments {doc string} 0 我尝试添加参数但没有成功。真正令人困惑的一点是,我以同样的方式隐藏了一个 helm 函数并且它起作用了,就像这样:

(defun buflist nil
  "List buffers in helm."
  (interactive)
  (helm-buffers-list))

有什么不同?我该如何解决这个问题?

【问题讨论】:

    标签: emacs elisp


    【解决方案1】:

    find-file 以文件名作为参数,您需要熟悉C-h f 以查找函数文档。

    interactive 可以带参数,例如,

    (defun find (filename)
      (interactive "F")
      (find-file filename))
    

    【讨论】:

    • 您可能希望使用(call-interactively #'find-file) 而不是自己获取和传递参数。
    【解决方案2】:

    find-file 需要参数,不能这样称呼它

    (find-file)
    

    调试器显示需要哪些参数:

    (filename &optional wildcards)
    

    您也可以调用帮助来查看它们:C-hf

    另一种选择是使用call-interactively

    (call-interactively 'find-file)
    

    【讨论】:

    • 非常感谢!我必须学习如何使用调试器。
    • (find-file)然后按C-xC-e
    猜你喜欢
    • 1970-01-01
    • 2021-07-30
    • 2018-12-21
    • 1970-01-01
    • 1970-01-01
    • 2019-04-10
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多