English 中文(简体)
2. 杀害名字始于特别扼杀的缓冲器
原标题:Killing buffers whose names start with a particular string

Here s my problem: I use Emacs and get lots of buffers that are pretty useless all the time, like *Messages* or *Completions*.

除了*shell*(和*shell* <k >)缓冲外,我想把C-y捆绑起来,关闭从*起的所有缓冲地带。

为此,我要在我的ema子档案中增加一些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)
    (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.

它说<代码>过滤器:无效功能:(curry2 string-prefix)。

现在,在Emacs-Lisp,我确实不使用任何许可证,但计划(麻省理工学院)则这样做:

(filter ((curry2 string-prefix?) "*shell")  ("*shell*" "*sh22" "eel"))
;Value 5: ("*shell*")

我这样说:

  1. a way to fix my code
  2. suggestions on how to do this in a different way

感谢!

最佳回答

另一种做法:

(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))))
问题回答

<C-h>f>>> RET

kill-matching-buffers is an interactive compiled Lisp function in `files.el .

(技能-配对-装饰器 REGEXP &optional InterNAL-TOO)

Kill buffers whose name matches the specified REGEXP. The optional second argument indicates whether to kill internal buffers too.

牢记弃置的胎盘,甚至连环。 yn和 se异。 例如,<代码>defun要求列出括号的参数清单。 而且,理赔实际上不可能。

幸运的是,你想要做的多数事情已经消失了。 www.un.org/Depts/DGACM/index_spanish.htm 您可使用<代码>string-prefix-p。 filter/code>, 或remove-if-not, 或remove-if for the inverse.

用于治疗的,可使用<代码>部分应用。 a. 具备与预设的<代码>** shell*相匹配的职能。

(apply-partially  string-prefix-p "*shell*")

你们可以这样做:

(mapcar
 (apply-partially  string-prefix-p "*shell*")
  ("*shell*" "foo" "*shell*<2>"))

; results in
(t nil t)

(require  cl) ; for remove-if
(remove-if
 (apply-partially  string-prefix-p "*shell*")
  ("*shell*" "foo" "*shell*<2>"))

; results in
("foo")

看到你在删除之前将删除的内容,从而发挥安全作用,这可以是一个好的想法。

在<>Icicles,通过违约C-x k,是一种多管齐下的做法,你可以用来杀死与你的微薄投入相匹配的任何缓冲器。 在这种情况下,请将<代码>* TAB改为“代码>*的所有缓冲名称作为完成的候选人。

然后,你可以多种方式缩小距离。 如果剩下的所有配对物都是你想要的,请上<代码>。 C-!,删除所有这些缓冲地带。

如果你提出,你不想删除标明<代码>*shell.的缓冲器。 ∗ 待印发。 页: 1 这只局限于<代码>*shell. ,你想要杀死而不是的缓冲。 页: 1 C-~ 减去这些匹配(构成部分)。 这留下了所有缓冲,但空壳缓冲除外。 页: 1

您也可通过在*Completions*上对其姓名进行公正的控制而杀死个人缓冲器:C-mouse-2

更一般地说,在Icicles every多通and中,用“密码>S-delete(Shift + 删除 key)来杀缓冲候选人。

http://www.emacswiki.org/emacs/Icicles_-_More_About_Multi-Commands

我发现,<条码>技能-配对功能促使我进行未经修改的缓冲,而这正是我所希望的。 以下职能将造成与预设物相匹配的缓冲(如问题标题)。 并非你所希望的,但也许像我这样的从谷歌来到这里的人会发现这种好处。

(require  cl)
(defun kill-buffers-with-prefix (prefix)
  "Kill buffers whose names start with the given prefix"
  (interactive "sPrefix to kill: ")
  (loop for buffer in (buffer-list)
        do (if (string-prefix-p prefix (buffer-name buffer))
               (kill-buffer buffer))))

杀害所有其他缓冲区

(defun px-kill-other-buffers ()
  "Kill all other buffers."
  (interactive)
  (mapc  kill-buffer (delq (current-buffer) (buffer-list))))

1. 寻找扼杀的开始

(defun string-starts-with-p (string prefix)
    "Return t if STRING starts with prefix."
    (and
     (string-match (rx-to-string `(: bos ,prefix) t) string)
     t))




相关问题
Lisp code called from Java

Long story: I am doing a project for my functional programing class, and I thought of writing an AI controller in Lisp, for the Mario AI competition. I was looking over frameworks/libraries/ways of ...

Emacs, Zen-Coding mode, and Putty

I use emacs via Putty and since Putty doesn t send certain key combinations to the remote console I generally need to re-bind them to other key combinations. After installing the amazing Zen-Coding ...

In Which Cases Is Better To Use Clojure? [closed]

I develop in Lisp and in Scheme, but I was reading about Clojure and then I want to know, in which cases is better to use it than using Lisp or Scheme? Thanks

lambda-gtk negative pointer

I was trying to write my own put-pixel on (Gdk) pixbuf in Lisp. When I finally realized how I can operate on C pointers in CL, new obstacle came along - (gdk:pixbuf-get-pixels pb) returns me negative ...

Is there a common lisp package naming convention?

I have created some of my own user packages and have run into a name clash. In Java, the naming convention is to use your domain name in the package name: e.g. import com.example.somepackage;. Are ...

SOAP request from within an AutoLISP/AutoCAD macro

We have built a webservice for a client that uses AutoCAD. They have a macro that runs in AutoCAD that builds a SOAP request. But they have not figured out how to actually send() the soap request to ...

热门标签