I have a very useful bit of code in my .emacs file which closes all buffers except the current one, and scratch and TeX_snippets.org buffers:
(defun my/kill-all-buffers-except-toolbox ()
"Kill all buffers except current one and toolkit (*Messages*, *scratch*).
Close other windows."
(interactive)
(mapc 'kill-buffer (remove-if
(lambda (x)
(or (eq x (current-buffer))
(member (buffer-name x)
'("*scratch*" "TeX_snippets.org"))))
(buffer-list)))
(delete-other-windows))
(define-key global-map (kbd "C-c m") 'my/kill-all-buffers-except-toolbox)
On upgrading to emacs 28.2 (9) on Mac OS X, it appears that cl
(from which remove-if
comes) is deprecated. Apparently the functions have been renamed to, in this case, cl-remove-if
and is in cl-lib
. I made this change in the .emacs file:
(defun my/kill-all-buffers-except-toolbox ()
"Kill all buffers except current one and toolkit (*Messages*, *scratch*).
Close other windows."
(interactive)
(mapc 'kill-buffer (cl-remove-if
(lambda (x)
(or (eq x (current-buffer))
(member (buffer-name x)
'("*scratch*" "TeX_snippets.org"))))
(buffer-list)))
(delete-other-windows))
(define-key global-map (kbd "C-c m") 'my/kill-all-buffers-except-toolbox)
but nothing happens when I hit C-c m
. I have seen it suggested the (require 'cl-lib)
is required -- adding that to .emacs makes no change. What am I missing/doing wrong? This is an extremely useful function for me.
(require 'cl-seq)
instead: that is wherecl-remove-if
is defined.cl-lib
thencl-remove-if
should work. Have you tried evaluating thecl-remove-if
expression separately (put your cursor after the closing parenthesis of that expression and pressC-x C-e
)?Debugger entered--Lisp error: (void-variable cl-remove-if)
cl-remove-if
expression, not just the symbolcl-remove-if
.