Shell 使用参数调用自定义emacs函数
我的.bash\u rc中有一个函数:Shell 使用参数调用自定义emacs函数,shell,emacs,elisp,Shell,Emacs,Elisp,我的.bash\u rc中有一个函数: 函数ForwardSearchXdvi{ latex-src*.tex; 用于*.dvi;do xdvi-sourceposition“$1${i/.dvi/.tex}”$i;完成; } 它是有效的。。。我用$1参数(我的文件.tex中的目标行号)通过命令行调用它,结果很好 我想直接从emacs运行它,因此我发出以下命令: (defun ForwardXdviSearch() (交互式) (shell命令(格式为“bash-ic%s”(shell引用参数“
函数ForwardSearchXdvi{
latex-src*.tex;
用于*.dvi;do xdvi-sourceposition“$1${i/.dvi/.tex}”$i;完成;
}
它是有效的。。。我用$1参数(我的文件.tex中的目标行号)通过命令行调用它,结果很好
我想直接从emacs运行它,因此我发出以下命令:
(defun ForwardXdviSearch()
(交互式)
(shell命令(格式为“bash-ic%s”(shell引用参数“latex-src J[HCI]*.tex;for i in J[HCI]*.dvi;do xdvi-sourceposition\”$1${i/.dvi/.tex}\“$i;done;”)
)
当我用“M-x函数”调用参数$1时,如何将其传递给函数?您需要使用特殊的形式
交互式
来读取参数。类似于以下未经测试的代码:
(defun forward-xdvi-search (line-number)
(interactive "nForward to line: ")
(shell-command
(format "bash -ic %s"
(shell-quote-argument
(format "latex -src J[HCI]\*.tex; for i in J[HCI]\*.dvi; do xdvi -sourceposition \"%d ${i/.dvi/.tex}\" $i; done ;"
line-number)))))
按照@phils建议的改进进行编辑,
interactive
有一个读取数字的代码,因此您可以使用“nForward”来行:“
这对我不起作用。我获得:错误数量的参数:(lambda(line)(交互式)(shell命令(格式为“bash-ic%s”(shell引号参数“latex-src J[HCI]*.tex;对于J[HCI]*.dvi中的I;do xdvi-sourceposition\“$1${I/.dvi/.tex}\”$I;done;”),0
@phils Right!我本应该阅读C-h f interactive
我自己:-)用你的建议更新了代码。@GabrieleNicolardi,似乎你没有正确地复制代码,你复制了(interactive)
,而不是(interactive“nForward to line:)
,所以emacs无法理解如何读取第一个参数。@juanleon,非常感谢您的帮助,但我复制了正确的代码,它不工作。我想知道如何将参数传递给函数。我试过C-u“number”M-x函数。我尝试了M-x函数。不可能。我不是程序员,所以请不要怪我。一定要阅读C-hfinteractive