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:
- a way to fix my code
- suggestions on how to do this in a different way
Thanks!