是否可以在交互提示执行之前加载交互函数中的模式?

问题描述 投票:0回答:1

这是此原始问题的后续问题。

我尝试提供自定义交互功能,需要在Spacemacs启动后立即加载另一个包。我的问题是,交互式调用似乎总是在函数调用开始时执行,这阻止了我在交互式调用中使用尚未加载的模式变量。

示例:我想以交互方式访问(完成)我的 org-agenda-files,但 org-agenda-files 仅在加载 org-mode 后才定义。所以目前的想法是这样的:

;;;###autoload
(defun my/org-agenda-find-file(file-path)
  (require 'org)
  (interactive (list
                (completing-read "Choose agenda file: " org-agenda-files)))
  (find-file file-path)
  )

不幸的是,启动后交互调用此函数会导致:

列表:符号作为变量的值为空:org-agenda-files

就像没有“require”声明一样。

我从手册的这部分得到了启发,但没有找到专门针对交互功能的类似示例。

这里可以通过交互功能实现我想要的功能吗?

非常感谢您的贡献!

require org-mode interactive spacemacs
1个回答
0
投票

您可以向

interactive
添加任意数量的命令,只要它们位于返回必须传递给函数的参数的块内即可。在你的情况下,只需将所有内容包装到一个
progn
块中即可:

(defun my/org-agenda-find-file (file-path)
  (interactive
   (progn
     (require 'org)
     (list (completing-read "Choose agenda file: " org-agenda-files))))
  (find-file file-path))
© www.soinside.com 2019 - 2024. All rights reserved.