2012-04-10 68 views
2

我希望能夠從命令行啓動時指定Emacs的窗口布局。在命令行中指定emacs中的窗口布局

更具體地說,我調用 「emacs的文件1文件2文件3文件4」 和會,例如,像看

+---------+        +--------+ 
| file1 |        | buff | 
|   |        | list | 
+---------+ instead of the default +--------+ that I see currently 
|   |        |  | 
| file3 |        | file4 | 
+---------+        +--------+ 

我的Emacs的是GNU Emacs 24.0.91.1,我不使用emacsclient。

請注意,我不想讓更改永久。這就是爲什麼我要求命令行解決方案。

回答

2

放入layout.el

(setq inhibit-startup-screen t) 

(defun ordered-window-list-aux (tree) 
    (if (windowp tree) 
     (list tree) 
    (append (ordered-window-list-aux (nth 2 tree)) 
      (ordered-window-list-aux (nth 3 tree))))) 

(defun ordered-window-list() 
    "Lists windows from top to bottom, left to right." 
    (ordered-window-list-aux 
    (car (window-tree)))) 

(require 'cl) 

(defun fill-windows() 
    "Make window list display recent buffer." 
    (mapcar* 
    (lambda (win buf) 
    (set-window-buffer win buf)) 
    (nreverse (ordered-window-list)) 
    (buffer-list))) 

(delete-other-windows) 

;; your window configuration 
(split-window-horizontally) 
(split-window-vertically) 

;; Make window list display recent buffer 
(fill-windows) 

然後

emacs blah foo bar --load layout.el 

你需要做的是定製的佈局你想使用以下功能的組合方式的唯一的事情如下:

(split-window-horizontally) 
(split-window-vertically) 
(other-windows 1) 
+0

感謝您的幫助。而你提供的代碼不適合我(我不明白它來解決它)。然而,你做了什麼給了我一個想法如何解決我的問題。我按照你的建議創建了「layout.el」,並添加了一行「(add-hook'emacs-startup-hook(lambda()(other-window 1)(switch-to-buffer」bar「)))」以達到我原來想要的效果。爲了獲得額外的修改,我可以按照您的建議使用(拆分窗口 - 水平)(拆分窗口 - 垂直)。 – 2012-04-11 09:42:40

+0

這是行不通的? – thisirs 2012-04-11 12:03:11

+0

如果我使用給定的代碼,那麼我會得到四個窗口。最底部最大的是框架的下半部分,並且包含「欄」,在其上方有三個窗口。其中最右邊的部分佔據右半部分的空間幷包含「foo」。左上角分爲「blah」和「Scratch」,底部爲「blah」,頂部爲「* scratch」。如果我註釋掉「(split-window-vertical)」,我會得到三個帶有「blah」,「foo」和「bar」的窗口。如果我另外註釋掉「(split-window-horizo​​ntal)」,我會在頂部獲得「foo」,在底部獲得「緩衝區列表」。 – 2012-04-11 17:26:11