如何在Emacs抽象函数中传递arg

时间:2016-06-24 21:31:48

标签: emacs imenu emacs-helm

我尝试编写一个函数来抽象使用哪个helm-imenu变体:

(defun my/helm-menu ()
  "For Org mode buffers, show Org headlines.
For programming mode buffers, show functions, variables, etc."
  (interactive)
  (cond ((derived-mode-p 'org-mode)
           (helm-org-in-buffer-headings))
        (t
           (helm-semantic-or-imenu))))

但是,当在非Org模式缓冲区中使用它时,它会失败,说它需要一个参数。

确实,helm-semantic-or-imenu需要arg

我该如何通过?

为什么使用M-x helm-semantic-or-imenu:参数在哪里?

1 个答案:

答案 0 :(得分:0)

按照Drew的建议,这应该这样做:

(defun my/helm-menu (arg)
  "For Org mode buffers, show Org headlines.
For programming mode buffers, show functions, variables, etc."
  (interactive "P")
  (cond ((derived-mode-p 'org-mode)
           (helm-org-in-buffer-headings))
        (t
            (helm-semantic-or-imenu arg))))

至少,它有效!