【问题标题】:specify window layout in emacs on commandline在命令行的emacs中指定窗口布局
【发布时间】:2012-04-10 22:23:20
【问题描述】:

我希望能够在从命令行启动 Emacs 时指定它的窗口布局。

更具体地说,我调用“emacs file1 file2 file3 file4”,例如,我会像看到

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

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

注意,我不想永久更改。这就是我要求命令行解决方案的原因。

【问题讨论】:

    标签: emacs


    【解决方案1】:

    将以下内容放入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)
    

    【讨论】:

    • 感谢您的帮助。而您提供的代码对我不起作用(而且我不明白要修复它)。但是,你所做的让我知道如何解决我的问题。我按照您的建议创建了“layout.el”,并添加了一行“(add-hook 'emacs-startup-hook (lambda () (other-window 1) (switch-to-buffer "bar")))”达到我原来的问题想要的效果。要进行其他修改,我可以按照您的建议使用 (split-window-horizo​​ntally) (split-window-vertically)。
    • 如果我使用给定的代码,那么我会得到四个窗口。最底部是最大的占据框架的下半部分,并包含“栏”,在其上方有三个窗口。其中最右边的占空间的右半部分并包含“foo”。左上部分分为“blah”和“*Scratch”,底部为“blah”,顶部为“*scratch”。如果我注释掉“(split-window-vertically)”,我会得到三个带有“blah”、“foo”和“bar”的窗口。如果另外我注释掉“(split-window-horizo​​ntally)”,我会在顶部得到“foo”,在底部得到“Buffer List”。
    • 似乎在启动时,emacs 会根据窗口的大小和打开的文件数量来拆分窗口。启动画面也干扰了窗口配置...在设置窗口配置之前(delete-other-window) 似乎可以解决这个问题。同时设置(setq inhibit-startup-screen t)
    • 感谢您的帮助!真的很有帮助。
    • 实际上不需要ordered-window-*函数。见walk-window-tree
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-29
    相关资源
    最近更新 更多