0

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.

7
  • Try (require 'cl-seq) instead: that is where cl-remove-if is defined. Commented Jan 8, 2023 at 13:02
  • Tried it -- no change, still does not work. Thanks for suggestion, though...
    – sgmoye
    Commented Jan 8, 2023 at 13:26
  • If you already required cl-lib then cl-remove-if should work. Have you tried evaluating the cl-remove-if expression separately (put your cursor after the closing parenthesis of that expression and press C-x C-e)? Commented Jan 8, 2023 at 14:24
  • Odd. Debugger entered--Lisp error: (void-variable cl-remove-if)
    – sgmoye
    Commented Jan 8, 2023 at 16:49
  • OP: @dalanicolai means evaluate the whole cl-remove-if expression, not just the symbol cl-remove-if.
    – Drew
    Commented Jan 8, 2023 at 17:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.