2012-06-06 2 views
4

나는 예를 들어, 명령 줄 인수를 제공하여 모드 또는 자동 되돌리기 모드에서 읽기 전용 파일을 열 수 이맥스를 말할 수 있어야합니다 자동 되돌리기 모드에서 파일을이맥스 사용자 지정 명령 줄 인수

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)) 

이 문제는 한 번에 하나의 파일에 대해서만 작동한다는 것입니다.

emacs -R file1 

작동하지만

emacs -R file1 file2 

이 작동하지 않습니다.

위의 기능을 변경하여 지정된 모드에서 동시에 여러 파일을 열 수 있습니까? 누군가 간단하고 우아한 해결책을 제안 할 수 있습니까?

답변

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)))) 

BTW, 통지이 이전의 디렉토리에 각 파일의 상대를 열 것입니다.