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
: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
(let ((prefix-map (make-sparse-keymap)))
(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)
"Set buffers in NEW-LIST to be the most recently used, in order."
(when new-list
(let (firstbuf buf)
(while new-list
(setq buf (car new-list))
(when (stringp buf)
(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))))))
(dolist (b (reverse new-list))
(when (and (buffer-live-p b)
(not (minibufferp b)))
(switch-to-buffer b)))))
(defun eyebrowse--load-window-config (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)
(window-state-put window-config (frame-root-window) 'safe)
(when buffer-list
(update-buffer-list buffer-list)))))
(update-buffer-list (take eyebrowse-buffer-list-count buffer-list))))))
(defun eyebrowse--string-to-number (x)
"Version of `string-to-number' that returns nil if not a number."