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.

phils
  • 48,657
  • 3
  • 76
  • 115
sgmoye
  • 179
  • 1
  • 8
  • Try `(require 'cl-seq)` instead: that is where `cl-remove-if` is defined. – Fran Burstall Jan 08 '23 at 13:02
  • Tried it -- no change, still does not work. Thanks for suggestion, though... – sgmoye Jan 08 '23 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`)? – dalanicolai Jan 08 '23 at 14:24
  • Odd. `Debugger entered--Lisp error: (void-variable cl-remove-if)` – sgmoye Jan 08 '23 at 16:49
  • OP: @dalanicolai means evaluate the whole `cl-remove-if` *expression*, not just the symbol `cl-remove-if`. – Drew Jan 08 '23 at 17:10
  • Please reindent your code better. Thx. – Drew Jan 08 '23 at 17:11
  • You need to require the library that provides the definition of `cl-remove-if` *before* any code that uses it. Did you do that? You say only that you tried adding the `require` to your init file - it needs to come before any code that uses that function. – Drew Jan 08 '23 at 17:13

0 Answers0