终止名称以特定字符串开头的缓冲区 [英] Killing buffers whose names start with a particular string
问题描述
这是我的问题:我使用 Emacs 并获得了很多一直没用的缓冲区,例如 *Messages* 或 *Completions*.
Here's my problem: I use Emacs and get lots of buffers that are pretty useless all the time, like *Messages* or *Completions*.
我想绑定 C-y 以关闭所有以 * 开头的缓冲区,除了 *shell*(和 *shell*
I want to bind C-y to close all buffers that start with * except for *shell* (and *shell* < k >) buffers.
为此,我想在我的 .emacs 文件中添加一些 Emacs-Lisp:
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)
我已经使用 Scheme 和 filter
测试了 string-prefix
和 curry2
看起来非常简单.遗憾的是,我无法让 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.
上面写着filter: Invalid function: (curry2 string-prefix)
.
现在,问题是我在 Emacs-Lisp 上有点烂,除了 Scheme,我真的不使用任何 Lisp,而在 Scheme (MIT) 中,这是有效的:
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*")
我愿意:
- 一种修复我的代码的方法
- 有关如何以不同方式执行此操作的建议
谢谢!
推荐答案
另一种方法:
(require 'cl)
(defun is-useless-buffer (buffer)
(let ((name (buffer-name buffer)))
(and (= ?* (aref name 0))
(not (string-match "^\*shell\*" name)))))
(defun kill-useless-buffers ()
(interactive)
(loop for buffer being the buffers
do (and (is-useless-buffer buffer) (kill-buffer buffer))))
这篇关于终止名称以特定字符串开头的缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!