正视或垂直最大化Emacs Windows

时间:2017-05-04 12:24:21

标签: emacs maximize-window

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

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

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

请原谅ASCII艺术的可怕尝试!

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

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

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

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

有什么想法吗?

2 个答案:

答案 0 :(得分:2)

您可以使用库frame-cmds.eldescription)执行此操作。

它提供以下命令:

  • maximize-frame-horizontallymaximize-frame-verticallymax-frame
  • restore-frame-horizontallyrestore-frame-verticallyrestore-frame

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

命令maximize-framerestore-frame是通用的,可以像水平和垂直命令一样,给它们一个前缀arg:水平为负,垂直为非负。

答案 1 :(得分: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)))))))))