我正在使用emacs中的openwith包。我想用带有一些附加选项的xfig打开.fig文件,例如:
xfig -specialtext -latexfont -startlatexFont default file.fig在我不需要传递额外选项的其他文件关联中,openwith为我工作。我在我的.emacs文件中尝试了以下内容
(setq
openwith-associations
'(("\\.fig\\'" "xfig" (file))))这是可行的,但是
(setq
openwith-associations
'(("\\.fig\\'" "xfig -specialtext -latexfont -startlatexFont default" (file))))也不能使用(error: Wrong type argument: arrayp, nil)
(setq
openwith-associations
'(("\\.fig\\'" "xfig" (" -specialtext -latexfont -startlatexFont default " file))))不工作,尽管在这里我没有得到任何错误。它显示“在外部程序中打开file.fig”,但什么也没有发生。在本例中,我注意到有一个xfig进程正在使用所有这些选项运行。
有人能告诉我怎么解决这个问题吗?
谢谢你的帮助。
发布于 2011-07-31 03:57:08
我不知道这是如何工作的,所以我只记录了如何通过阅读代码来计算它:
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的定义和文档:
函数:启动-进程名-or- name程序&rest参数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的临时缓冲区中编写这样的代码行,然后用C-M-x运行它们。
(car args)指的是你给openwith-association的参数,注意(nth 20a)中'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))))您必须在参数列表中以单个字符串的形式提供每个单词。
https://stackoverflow.com/questions/6885570
复制相似问题