设置undo-tree-visualizer-diff后, 使用一次undo tree再退出就失效了

文字缩进 4 格
(use-package undo-tree
  :ensure t
        :diminish ""
        :config
        (global-undo-tree-mode)
        (setq undo-tree-visualizer-diff t))

这个diff window只能使用一次,C-x u进入undo tree,显示diff window,按q退出,再按C-x u,就没有diff window了。

这是为什么

bug, try this work around

这是个 issue,这样能解决

(defun undo-tree-visualizer-show-diff (&optional node)
    ;; show visualizer diff display
    (setq-local undo-tree-visualizer-diff t)
    (let ((buff (with-current-buffer undo-tree-visualizer-parent-buffer
                  (undo-tree-diff node)))
          (display-buffer-mark-dedicated 'soft)
          win)
      (setq win (split-window))
      (set-window-buffer win buff)
      (shrink-window-if-larger-than-buffer win)))

(defun undo-tree-visualizer-hide-diff ()
  ;; hide visualizer diff display
  (setq-local undo-tree-visualizer-diff nil)
  (let ((win (get-buffer-window undo-tree-diff-buffer-name)))
    (when win (with-selected-window win (kill-buffer-and-window)))))

或者更简单的方案:

  (make-variable-buffer-local 'undo-tree-visualizer-diff)
  (setq-default undo-tree-visualizer-diff t)

谢两位,已解决。简单方案很好用。