用C-d杀死*终端*缓冲区 [英] Kill the *terminal* buffer with C-d

查看:215
本文介绍了用C-d杀死*终端*缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现一个好帖子几个
天前详细说明如何使用 Cd 键杀死shell缓冲区。基本上,
在使用 Cd 杀死进程后,现在可以再次点击 Cd ,还可以杀死
缓冲区。

I found a nice post a few days ago detailing how to kill the shell buffer with the C-d key. Basically, after killing the process with C-d you can now tap C-d again to also kill the buffer.

我正在尝试实现类似于术语模式的类似操作,但是我碰到了
的问题。杀死术语过程(通常使用 Cd )似乎
缓冲区使用的键映射更改,但是我找不到这是什么!

I was trying to implement something similar for term-mode, but I ran into a problem. After you kill the term process (with the usual C-d) it seems that the key-map being used by the buffer changes, but I can't find out what it is!

例如,启动术语命令( Mx术语RET RET ),然后只需
immediatelly命中 Cd 。一旦进程死机,缓冲区仍然报告为
在术语模式,但它们使用的键映射既不是 term-mode-map 也不是
term-raw-map

For example, launch the term command (M-x term RET RET) and then just immediatelly hit C-d. Once the process is dead, the buffer still reports being in term-mode, but they key-map it's using is neither term-mode-map nor term-raw-map.

所以

我需要找出它使用的地图,所以我可以绑定 Cd kill-buffer 。 >
或者我需要另一种方法来杀死缓冲区,使用 Cd 在术语模式。

So
I either need to find out what map it is using so I can bind C-d to kill-buffer.
Or I need another way to kill the buffer with C-d in term-mode.

推荐答案

虽然Trey Jackson的版本是绝对正确的,下面是不需要知道缓冲区名称的另一个版本。然后更容易管理多个终端缓冲区。

While Trey Jackson's version is absolutely correct, below is another version which doesn't require knowing the buffer name. It is then easier to manage multiple terminal buffers.

(defun term-handle-exit--close-buffer (&rest args)
  (when (null (get-buffer-process (current-buffer)))
    (insert "Press <C-d> to kill the buffer.")
    (use-local-map (let ((map (make-sparse-keymap)))
                     (define-key map (kbd "C-d")
                       (lambda ()
                         (interactive)
                         (kill-buffer (current-buffer))))
                     map))))
(advice-add 'term-handle-exit :after #'term-handle-exit--close-buffer)

这篇关于用C-d杀死*终端*缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆