使用参数调用自定义emacs函数

时间:2013-07-16 10:06:15

标签: shell emacs elisp

我的.bash_rc中有这个功能:

function ForwardSearchXdvi {
latex -src *.tex;
    for i in *.dvi; do xdvi -sourceposition "$1 ${i/.dvi/.tex}" $i; done ;
}

它的工作原理...我用命令行用$ 1参数(我的file.tex中的目标行号)调用它,它很好。

我想直接从emacs运行它,所以我发了这个命令:

(defun ForwardXdviSearch ()
(interactive)
  (shell-command (format "bash -ic %s" (shell-quote-argument "latex -src J[HCI]*.tex; for i in J[HCI]*.dvi; do xdvi -sourceposition \"$1 ${i/.dvi/.tex}\" $i; done ;")))
)

当我用“M-x函数”调用它时,如何将参数$ 1传递给函数?

1 个答案:

答案 0 :(得分:2)

您需要使用特殊形式interactive来读取参数。像这个未经测试的代码:

(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建议的改进