winner-mode bug

两个bug fix,大家看看对不对

;; bug 1, too many window configuration saved, even ephemeral ones, suggested fix:
(defvar my-win-config-save-delay 2)

(defun my-reset-winner-last-command (BUFFER-OR-NAME)
  (let ((last-buffer-switched-into (get-buffer BUFFER-OR-NAME)))
    ;; run with a delay after set buffer, to check if the target buffer is still current
    (when (eq last-buffer-switched-into (current-buffer))
      ;; reset winner-last-command, see winner-save-old-configurations
      ;; in winner repeat the same command doesn't insert new config
      ;; winner also save win configs before winner undo
      (setq winner-last-command nil)
      (winner-save-conditionally))))

(defun my-winner-defer-save (WINDOW BUFFER-OR-NAME &optional KEEP-MARGINS)
  "Make winner-mode only save window configuration that has stay unchanged for a specified period"
  (run-at-time my-win-config-save-delay nil #'my-reset-winner-last-command BUFFER-OR-NAME))

(advice-add 'set-window-buffer :after #'my-winner-defer-save)

; bug 2, wrong window focus, ie. focused wrong window on winner-undo, suggested fix:
(defun my-winner-set (conf)
  "Fix window focus loss"
  (let ((bufs (mapcar #'cdr (cdr conf)))
         (not-found t))
    (while (and not-found bufs)
      (let ((win (get-buffer-window (pop bufs)))))
      (when (window-live-p win)
        (select-window win)
        (setq not-found nil)))))

(advice-add 'winner-set :after 'my-winner-set)

你说的具体是什么bug?

在上面标注出来了 :grinning: