4

コマンドライン引数を指定して、emacs に読み取り専用モードまたは自動復帰モードでファイルを開くように指示できるようにしたいと考えています。たとえば、次のようになります。

emacs -A file1 file2 file3 ...  

自動復元モードでファイルを開く必要があります

emacs -R file1 file2 file3 ... 

読み取り専用モードでファイルを開く必要があります

私は以下を見つけました:

(defun open-read-only (switch)
  (let ((file1 (expand-file-name (pop command-line-args-left))))
  (find-file-read-only file1)))
(add-to-list 'command-switch-alist '("-R" . open-read-only))

(defun open-tail-revert (switch)
  (let ((file1 (expand-file-name (pop command-line-args-left))))
  (find-file-read-only file1)
  (auto-revert-tail-mode t)))
(add-to-list 'command-switch-alist '("-A" . open-tail-revert))

これの問題は、一度に 1 つのファイルに対してしか機能しないことです。

すなわち

emacs -R file1 

動作しますが、

emacs -R file1 file2

動作しません。

指定されたモードで複数のファイルを同時に開くことができるように、上記の関数を変更するにはどうすればよいですか? 誰かがシンプルでエレガントなソリューションを提案できますか?

4

1 に答える 1

4

command-line-args-left次のスイッチまでのアイテムを消費するだけです:

(defun open-read-only (switch)
  (while (and command-line-args-left
              (not (string-match "^-" (car command-line-args-left))))
    (let ((file1 (expand-file-name (pop command-line-args-left))))
      (find-file-read-only file1))))

ところで、これにより、前のファイルのディレクトリに関連する各ファイルが開かれることに注意してください。

于 2012-06-06T09:35:23.483 に答える