我不知道这是如何工作的,所以我只是记录了如何通过阅读代码来计算它:
openwith.el 中的重要代码是对 start-process 的调用:
(dolist (oa openwith-associations)
(let (match)
(save-match-data
(setq match (string-match (car oa) (car args))))
(when match
(let ((params (mapcar (lambda (x)
(if (eq x 'file)
(car args)
(format "%s" x))) (nth 2 oa))))
(apply #'start-process "openwith-process" nil
(cadr oa) params))
(kill-buffer nil)
(throw 'openwith-done t))))
在您的情况下 oa 将具有以下结构,并且 cadr 是“xfig”:
(cadr '("\.fig\'" "xfig" (file))) ;; expands to => xfig
这是 start-process 的定义和文档:
功能:启动-进程名buffer-or-name程序&rest args
http://www.gnu.org/software/emacs/elisp/html_node/Asynchronous-Processes.html
args, are strings that specify command line arguments for the program.
一个例子:
(start-process "my-process" "foo" "ls" "-l" "/user/lewis/bin")
现在我们需要弄清楚 params 是如何构造的。在您的示例中,mapcar 的参数是:
(nth 2 '("\.fig\'" "xfig" (file))) ;=> (file)
顺便说一句,您可以在 emacs 的暂存缓冲区中写入这些行并使用 CMx 运行它们。
(car args) 是指您提供给 openwith-association 的参数,请注意 (nth 2 oa) 中的 'file 的出现是如何被它替换的。我现在将其替换为“here.txt”:
(mapcar (lambda (x)
(if (eq x 'file)
"here.txt"
(format "%s" x))) (nth 2 '("\.fig\'" "xfig" (file)))) ;=> ("here.txt")
好的,现在我们看看应该如何构造参数:
(mapcar (lambda (x)
(if (eq x 'file)
"here.txt"
(format "%s" x)))
(nth 2 '("\.fig\'" "xfig"
("-specialtext" "-latexfont" "-startlatexFont" "default" file))))
; => ("-specialtext" "-latexfont" "-startlatexFont" "default" "here.txt")
尝试这个:
(setq openwith-associations
'(("\\.fig\\'" "xfig" ("-specialtext" "-latexfont" "-startlatexFont" "default" file))))
您必须在参数列表中将每个单词作为单个字符串提供。