【问题标题】:emacs custom command line argumentsemacs 自定义命令行参数
【发布时间】:2012-06-06 07:15:38
【问题描述】:

我希望能够告诉 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))

问题在于它一次只适用于一个文件。

emacs -R file1 

有效,但是

emacs -R file1 file2

不工作。

如何更改上面的功能,以便它们可以 在指定模式下同时打开多个文件? 有人可以提出一个简单而优雅的解决方案吗?

【问题讨论】:

    标签: emacs elisp


    【解决方案1】:

    只消耗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))))
    

    顺便说一句,注意这将打开相对于前一个目录的每个文件。

    【讨论】:

      猜你喜欢
      • 2011-01-07
      • 2011-06-14
      • 1970-01-01
      • 2022-10-21
      • 1970-01-01
      • 2019-01-03
      • 1970-01-01
      • 1970-01-01
      • 2014-03-17
      相关资源
      最近更新 更多