2

私は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プロセスがあることに気付きました。

誰かがこれを修正する方法を教えてもらえますか?

助けてくれてありがとう。

4

1 に答える 1

2

私はこれがどのように機能するのか見当がつかないので、コードを読んでそれを理解する方法を文書化するだけです。

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の定義とドキュメントです。

関数:start-process name buffer-or-name program&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に指定するパラメーターを参照します。(n番目の2 oa)での'ファイルの出現がそれに置き換えられることに注意してください。今のところ、これを「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))))

パラメータのリストでは、各単語を1つの文字列として指定する必要があります。

于 2011-07-30T19:57:08.003 に答える