杀死名称以特定字符串开头的缓冲区 [英] Killing buffers whose names start with a particular string
问题描述
这是我的问题:
我使用Emacs并得到很多缓冲区,一直都是无用的,像*消息*或*达成*。
我想绑定\Cy以关闭所有以* shell *(和* shell * k)缓冲区除外的*开头的缓冲区。
要做我想在我的.emacs文件中添加一些Emacs-Lisp:
(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)
(fxy)))))
(def()()($($($)$($($($)$ f(car l))(cons(car l)rest)
rest))))
(defun kill-withouteless(arg)
p)
(map'kill-buffer
(filter
(not((curry2 string-prefix)* shell *))
(list-buffer s)
)))
(全局设置键\Cy'杀死无用)
我已经使用Scheme来测试了 string-prefix
和 curry2
和过滤器
似乎很简单。
不幸的是,我根本无法获得 kill-withouteless
正常工作。
它说 filter:无效的函数:(curry2 string-prefix)
。
现在,我在Emacs- Lisp,我没有真正使用任何Lisp,除了Scheme,而在Scheme(MIT)中,这样做是有效的:
(filter (curry2 string-prefix)* shell)'(* shell ** sh22eel))
;值5:(* shell *)
我想:
- a解决我的代码的方法
- 关于如何以其他方式执行此操作的建议
谢谢
另一种方法:
$ b(defun is-useless-buffer(buffer)
(let((name(buffer-name buffer)))
(=?*(aref name 0))
(not(string-match^ \\ * shell\\\ *name)))))
(defun kill-useless-buffers()
(i nteractive)
(缓冲区的循环为缓冲区
do(和(is-useless-buffer buffer)(kill-buffer buffer)))
pre>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
andcurry2
using Scheme andfilter
seems pretty straightforward. Sadly I just can't getkill-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!
解决方案An alternate approach:
(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屋!