最大化Emacs窗口水平或垂直显示

3
我知道 C-x 1 可以将当前窗口在水平和垂直方向上最大化。
然而,我的问题是,是否有可能仅在一个方向上将当前窗口扩展到框架的边缘?
因此,在下面的示例中,我想将窗口 A 扩展到框架的右边框,占用 B 和 C 目前占用的空间。但我希望 D 和 E 保持不变...并且我想用单个命令完成它。
请原谅糟糕的 ASCII 艺术尝试!
 _______________________
| AAAAAA |BBBBBB |CCCC  |
|________|_______|______|
| DDDDD  | EEEEEEEEEE   |
|________|______________|

我知道你可以水平移动一次一个字符,也可以使用重复 n 次的命令来多次执行此操作,但两者都有些繁琐,而我真正想要说的是扩展到右边框,我不在乎那有多远。
我最接近的解决办法是进入每个占用你想要的空间的帧,并调用 C-X 0,但这还是有点麻烦。
我需要在终端模式下(emacs -nw),而不是图形/X-Windows模式下运行。
有什么好主意吗?
2个回答

2
您可以使用库frame-cmds.el说明)来完成此操作。
它提供以下命令:
  • maximize-frame-horizontallymaximize-frame-verticallymax-frame
  • restore-frame-horizontallyrestore-frame-verticallyrestore-frame
“恢复”命令实际上是切换最大化和还原的开关。(它们被别名为命令toggle-max-frame*。)
命令maximize-framerestore-frame是通用的,可以通过给它们一个前缀参数来像水平和垂直命令一样工作:负数表示水平方向,非负数表示垂直方向。

谢谢。我应该补充一下 - 我需要这个工作在文本模式下,而不是图形/X窗口模式下。我会更新我的问题。看起来这在文本模式下不起作用? - Phil
我想你指的是终端模式,而不是文本模式。不,它在终端模式下不起作用 - 它是用于图形显示器中的帧。我会把答案留在这里,以防对使用图形显示器的其他人有所帮助。谢谢。 - Drew

0

我有同样的问题:我想水平最大化一个窗口,但不是垂直方向。在互联网上搜索无果后,我决定编写自己的函数。我想在这里分享它,以防将来有人需要。

(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)))))))))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接