Compare commits

2 Commits

Author SHA1 Message Date
adacbd6e9a Simplify and speed up update-buffer-list 2025-04-22 14:05:04 -10:00
2034ec7a44 Limit buffer history size 2025-04-22 14:05:04 -10:00

View File

@ -185,6 +185,12 @@ If t, ask for confirmation."
:type 'boolean :type 'boolean
:group 'eyebrowse) :group 'eyebrowse)
(defcustom eyebrowse-buffer-list-count 20
"How many buffers to keep in the recent list.
Large numbers slow down switching."
:type 'integer
:group 'eyebrowse)
(defvar eyebrowse-mode-prefix-map (defvar eyebrowse-mode-prefix-map
(let ((prefix-map (make-sparse-keymap))) (let ((prefix-map (make-sparse-keymap)))
(define-key prefix-map (kbd "<") 'eyebrowse-prev-window-config) (define-key prefix-map (kbd "<") 'eyebrowse-prev-window-config)
@ -327,20 +333,10 @@ If a buffer name equal to OLD is found, it is replaced with NEW."
(defun update-buffer-list (new-list) (defun update-buffer-list (new-list)
"Set buffers in NEW-LIST to be the most recently used, in order." "Set buffers in NEW-LIST to be the most recently used, in order."
(when new-list (when new-list
(let (firstbuf buf) (dolist (b (reverse new-list))
(while new-list (when (and (buffer-live-p b)
(setq buf (car new-list)) (not (minibufferp b)))
(when (stringp buf) (switch-to-buffer b)))))
(setq buf (get-buffer buf)))
(when (buffer-live-p buf)
(bury-buffer buf)
(unless firstbuf
(setq firstbuf buf)))
(setq new-list (cdr new-list)))
(setq new-list (buffer-list))
(while (not (eq (car new-list) firstbuf))
(bury-buffer (car new-list))
(setq new-list (cdr new-list))))))
(defun eyebrowse--load-window-config (slot) (defun eyebrowse--load-window-config (slot)
"Restore the window config from SLOT." "Restore the window config from SLOT."
@ -358,7 +354,7 @@ If a buffer name equal to OLD is found, it is replaced with NEW."
(eyebrowse--fixup-window-config window-config) (eyebrowse--fixup-window-config window-config)
(window-state-put window-config (frame-root-window) 'safe) (window-state-put window-config (frame-root-window) 'safe)
(when buffer-list (when buffer-list
(update-buffer-list buffer-list))))) (update-buffer-list (take eyebrowse-buffer-list-count buffer-list))))))
(defun eyebrowse--string-to-number (x) (defun eyebrowse--string-to-number (x)
"Version of `string-to-number' that returns nil if not a number." "Version of `string-to-number' that returns nil if not a number."