Here's my problem: I use Emacs and get lots of buffers that are pretty useless all the time, like *Messages* or *Completions*.
I want to bind \C-y to close all buffers that start with * except for *shell* (and *shell* < k >) buffers.
To do that, I'd like to add some Emacs-Lisp in my .emacs file:
(defun string-prefix s1 s2
(if (> (string-length s1) (string-length s2)) nil
(string=? s1 (substring s2 0 (string-length s1))) ))
(defun curry2
(lambda (f)
(lambda (x)
(lambda (y)
(f x y) ))))
(defun filter
(lambda (f l)
(if (null? l) '()
(let ((rest (cdr l)))
(if (f (car l)) (cons (car l) rest)
rest) ))))
(defun kill-useless (arg)
(interactive "p")
(map 'kill-buffer
(filter
(not ((curry2 string-prefix) "*shell*"))
(list-buffers)
) ))
(global-set-key "\C-y" 'kill-useless)
I've already tested string-prefix
and curry2
using Scheme and filter
seems pretty straightforward.
Sadly I just can't get kill-useless
to work properly.
It says filter: Invalid function: (curry2 string-prefix)
.
Now, the thing is I kind of suck at Emacs-Lisp, I don't really use any Lisp except Scheme, and in Scheme (MIT), this works:
(filter ((curry2 string-prefix?) "*shell") '("*shell*" "*sh22" "eel"))
;Value 5: ("*shell*")
I'd like:
Thanks!
C-h f kill-matching-buffers
RET
kill-matching-buffers is an interactive compiled Lisp function in `files.el'.
(kill-matching-buffers REGEXP &optional INTERNAL-TOO)
Kill buffers whose name matches the specified REGEXP. The optional second argument indicates whether to kill internal buffers too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With