Emacs - Magit在切换窗口时重用不同项目的相同窗口

时间:2017-11-09 09:39:57

标签: emacs magit

我是magit的新用户,我目前正在使用单个窗口(magit-status)的单独框架中使用它。我希望这能显示最新访问缓冲区项目的git状态。想象一下,在另一个框架中,我有两个窗口,两个不同项目的文件缓冲区。我希望magit窗口向我显示项目的git状态,具体取决于当前选定的窗口。

        frame 1                  frame 2
***********************     ****************  
* window 1 * window 2 *     *    window3   *
*          *          *     *              *
*   file   *   file   *     * magit-status *
* of proj1 * of proj2 *     *              *
*          *          *     *              *
***********************     ****************

如果选择的窗口为window 1,我希望window 3显示项目1的状态,那么更清楚一点,那么如果我更改为window 2我想{{1}显示项目2的状态。

2 个答案:

答案 0 :(得分:0)

这里是我使用的最终解决方案,这要归功于答案:

https://emacs.stackexchange.com/questions/36718/magit-reuse-same-window-for-different-project-when-switching-window

(defun magit-status-autorefresh (callee)
  (interactive)
  (let ((project-previous (magit-toplevel)))
    (call-interactively callee)
    (let ((project (magit-toplevel)))
      (when (and project
                 (not (equal project-previous project)))
        (let ((status-win
               (cl-some (lambda (b)
                          (and (with-current-buffer b
                                 (derived-mode-p 'magit-status-mode))
                               (get-buffer-window b 'visible)))
                        (buffer-list)))
              (magit-display-buffer-noselect t)
              (magit-display-buffer-function
               (lambda (buffer)
                 (display-buffer buffer '(display-buffer-same-window)))))
          (when status-win
            (with-selected-frame (window-frame status-win)
              (with-selected-window status-win
                (magit-status-internal project))))))))
  )

(defun my/other-window ()
  (interactive)
  (magit-status-autorefresh 'other-window)
  )

(defun my/other-counsel-projectile-find-file ()
  (interactive)
  (magit-status-autorefresh 'counsel-projectile-find-file)
  )

(defun my/other-ace-window ()
  (interactive)
  (magit-status-autorefresh 'ace-window)
  )

答案 1 :(得分:-1)

您可以通过设置magit-status变量来实际自定义 Magit 显示magit-display-buffer-function的方式。

如果我正确理解了您的问题,您可能正在寻找设置为该变量的magit-display-buffer-same-window-except-diff-v1

您可以手动设置此变量,或按 C-h v magit-dispaly-buffer-function RET 并使用Easy Customization

仅供参考,您也可以通过自己的方式为 Magit 显示缓冲区:

(setq magit-display-buffer-function
      (lambda (buffer)          
       ;; Go on
      ))