【问题标题】:Maximize Emacs Windows Horizonatally or Vertically横向或纵向最大化 Emacs Windows
【发布时间】:2017-05-04 12:24:20
【问题描述】:

我知道 C-x 1,它将在水平和垂直方向上最大化当前窗口。

但是,我的问题是,是否可以仅在一个方向上将当前窗口扩展到框架边缘?

所以在下面我想将窗口 A 扩展到框架的右边框,占用 B 和 C 当前占用的空间。但我希望 D 和 E 保持不变......我想做它在一个命令中。

请原谅我对 ASCII 艺术的糟糕尝试!

 _______________________
| AAAAAA |BBBBBB |CCCC  |
|________|_______|______|
| DDDDD  | EEEEEEEEEE   |
|________|______________|

我知道您一次可以水平移动 1 个字符,并且您可以使用重复 n 次命令多次执行此操作,但是两者都很笨重,当我真正想说的是展开到右侧边界时,我不在乎那有多远。

我想出的最接近的方法是去占据你想要的空间并调用 C-X 0 的每一帧,但这仍然有点笨重。

我需要它在终端模式(emacs -nw)而不是图形/X-Windows 模式下工作。

有什么想法吗?

【问题讨论】:

    标签: emacs maximize-window


    【解决方案1】:

    您可以使用库 frame-cmds.el (description) 来做到这一点。

    它提供了这些命令:

    • maximize-frame-horizontally、maximize-frame-vertically 和 max-frame
    • restore-frame-horizontally、restore-frame-vertically 和 restore-frame

    “恢复”命令实际上是在最大化和恢复之间交替的切换。 (它们是命令toggle-max-frame* 的别名。)

    命令maximize-frame 和restore-frame 是通用的,可以通过给它们一个前缀arg 来像水平和垂直命令一样发挥作用:负表示水平,非负表示垂直。

    【讨论】:

    • 谢谢。我应该添加 - 我需要在文本模式下进行这项工作,而不是图形/X-Windows 模式。我会更新我的问题。看起来这在文本模式下不起作用?
    • 我认为您的意思是终端模式,而不是文本模式。不,它在终端模式下不起作用 - 它适用于图形显示中的帧。我将把答案留在这里,以防它帮助正在使用图形显示的其他人。谢谢。
    【解决方案2】:

    我有同样的问题:我想水平最大化一个窗口,而不是垂直最大化。在网上搜索无济于事后,我决定编写自己的函数。我想在这里分享它,以防将来对某人有所帮助。

    (require 'cl-lib)
    (defun durand-maximize-window-horizontally (&optional window)
      "Make WINDOW have the same width as the frame.
    WINDOW defaults to the selected window.
    Other windows are retained, but moved to the top."
      (let* ((window (or window (selected-window)))
             ;; the list of windows to the left
             (left-windows-list (let ((temp-window window)
                                      window-list)
                                  (cl-loop while (window-in-direction
                                                  'left temp-window t)
                                           do (let ((left-win
                                                     (window-in-direction
                                                      'left temp-window t)))
                                                (push left-win window-list)
                                                (setf temp-window left-win)))
                                  window-list))
             ;; the list of windows to the right
             (right-windows-list (let ((temp-window window)
                                       window-list)
                                   (cl-loop while (window-in-direction
                                                   'right temp-window t)
                                            do (let ((right-win
                                                      (window-in-direction
                                                       'right temp-window t)))
                                                 (setf window-list
                                                       (append window-list
                                                               (list right-win)))
                                                 (setf temp-window right-win)))
                                   window-list))
             ;; the list of windows to the left and to the right
             ;; the order is from left to the right.
             (same-level-list (append left-windows-list right-windows-list))
             ;; save all parameters: the car is the buffer, and the cadr is a list
             ;; of parameters.
             (window-parameters-list
              (cl-loop for win in same-level-list
                       collect (list (window-buffer win)
                                     ;; (window-width win)
                                     (window-parameters win)))))
        (cl-loop for win in same-level-list
                 do (delete-window win))
        ;; now our window is the only window horizontally speaking.
        ;; now we shall create them once again, if they exist.
        (when same-level-list
          (let* ((split-base-window
                  (split-window window nil 'above))
                 (new-windows (list split-base-window))
                 newly-created-window)
            (cl-loop
             for ind from 1 to (1- (length same-level-list))
             do
             (setf newly-created-window
                   (split-window split-base-window
                                 nil 'right)
                   ;; NOTE: it is important this list also follows the order
                   ;; of going from the left to the right
                   new-windows (append new-windows
                                       (list newly-created-window))
                   split-base-window newly-created-window))
            (cl-loop for index from 0 to (1- (length same-level-list))
                     do
                     (let ((buf (car (nth index window-parameters-list)))
                           (paras (cadr (nth index window-parameters-list))))
                       (set-window-buffer
                        (nth index new-windows) buf)
                       (cl-loop for para-pair in paras
                                do (set-window-parameter
                                    (nth index new-windows)
                                    (car para-pair)
                                    (cdr para-pair)))))))))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-29
      相关资源
      最近更新 更多