Skip to content

Commit

Permalink
Restore buffer-list after counsel-switch-buffers
Browse files Browse the repository at this point in the history
Previewing the buffers calls `switch-to-buffer` without the NORECORD
flag, so the buffer-list is modified (previewed buffers are bumped up
the list).  This change keeps a backup of buffer-list and restores it
during unwind.

Fixes #1954
  • Loading branch information
flatwhatson authored and abo-abo committed Mar 8, 2019
1 parent 84b5ece commit 15e2c88
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions counsel.el
Expand Up @@ -5052,14 +5052,20 @@ When ARG is non-nil, ignore NoDisplay property in *.desktop files."
(defvar counsel--switch-buffer-temporary-buffers nil
"Internal.")

(defvar counsel--switch-buffer-previous-buffers nil
"Internal.")

(defun counsel--switch-buffer-unwind ()
"Clear temporary file buffers.
"Clear temporary file buffers and restore `buffer-list'.
The buffers are those opened during a session of `counsel-switch-buffer'."
(while counsel--switch-buffer-temporary-buffers
(let ((buf (pop counsel--switch-buffer-temporary-buffers)))
(kill-buffer buf))))
(mapc 'kill-buffer counsel--switch-buffer-temporary-buffers)
(mapc 'bury-buffer counsel--switch-buffer-previous-buffers)
(setq counsel--switch-buffer-temporary-buffers nil
counsel--switch-buffer-previous-buffers nil))

(defun counsel--switch-buffer-update-fn ()
(unless counsel--switch-buffer-previous-buffers
(setq counsel--switch-buffer-previous-buffers (buffer-list)))
(let ((current (ivy-state-current ivy-last)))
;; This check is necessary, otherwise typing into the completion
;; would create empty buffers.
Expand Down

0 comments on commit 15e2c88

Please sign in to comment.