[英]Select other window in Emacs at startup
假設我有兩個文本文件A.txt
和B.txt
。 我選擇使用從Emacs打開兩個
emacs -no-splash -mm A.txt B.txt
現在,框架被垂直分為兩部分,文件A在左側窗口中顯示,文件B在右側窗口中顯示。 但是,文件B由Emacs自動選擇。 我可以通過輸入Cx o
或ESC-: (other-window 1)
將點移動到另一個窗口。 但是我想自動執行此操作,例如在命令行或.emacs
文件中。
我試過了
emacs -no-splash -mm --eval `(other-window 1)` A.txt B.txt
但這沒用..
將以下內容放入~/.emacs
文件:
(add-hook 'emacs-startup-hook '(lambda () (select-first-buffer-in-list command-line-args)))
(defun select-first-buffer-in-list (list)
(let (buffer)
(while list
(if (setq buffer (get-file-buffer (car list)))
(progn (select-window (get-buffer-window buffer))
(setq list nil))
(setq list (cdr list))))))
它將檢查哪個命令行參數與緩沖區相對應。 它選擇一個顯示第一個此類參數的緩沖區的窗口。
似乎可以正常工作:輸入.emacs
:
(add-hook 'emacs-startup-hook '(lambda () (other-window 1)))
與命令行參數的順序無關,此方法找到最左側,最上方的窗口並選擇它。 將以下代碼放入.emacs文件中:
(add-hook 'emacs-startup-hook '(lambda () (select-upper-left-window)))
(defun select-upper-left-window ()
(let (window)
(while (setq window (window-in-direction 'above nil t))
(select-window window))
(while (setq window (window-in-direction 'left nil t))
(select-window window))))
這將使用“ B.txt”保留一個窗口
emacs --find-file A.txt B.txt -Q -eval "(delete-other-windows)"
您是否有理由不想在命令行上顛倒文件名的順序?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.