使用emacs shell命令清除shell [英] Command to clear shell while using emacs shell

查看:444
本文介绍了使用emacs shell命令清除shell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果没有,是否有一个elisp函数来实现相同的?

解决方案

2015年2月更新



只是注意到Emacs现在(版本25+)命令 comint-clear-buffer ,绑定到 Cc Mo ,默认情况下,我们需要这样做,可能是优先于我最初发布的答案。



要考虑的选项:




  1. Cl 将重新填充缓冲区。重复按下该循环缓冲区,以便该点出现在缓冲区的顶部,中间或底部。当它停在顶部时,缓冲区看起来像已经被清除,尽管所有的文本仍然存在,但不在视图中。


  2. Cx h 标记整个缓冲区,之后 Cw 杀死它。这也会导致最后一个提示,但是在您输入下一个命令后,您将得到提示。


  3. 您还可以使用擦除-buffer ,默认情况下不绑定键,但很容易完成(您也可以使用 Mx erase-buffer




 (defun my-shell-hook 
(本地设置键\C-cl'擦除缓冲区))

(add-hook'shell-mode-hook'my-shell-hook)

将其绑定到 Cc l ;您可以选择你想要的是什么。


  1. 可以快速修复在清除后重新创建提示:



 (defun my-clear()
(interactive)
(擦除缓冲区)
(comint-send-input))

(defun my-shell-hook()
(local-set-key\C -cl'我的清除))

(a dd-hook'shell-mode-hook'my-shell-hook)

使用emacs一段时间,标记和杀死地区变得自然,所以你可能会发现第一个选项是足够的。如果没有,最后一个选项最接近你想要的。



编辑:只是在emacs wiki上找到这个,比我的选择更好4:

 (defun my-clear()
(interactive)
(let((comint- buffer-maximum-size 0))
(comint-truncate-buffer)))


Is there a builtin command to clear shell while using shell in emacs?

If not, is there an elisp function to achieve the same?

解决方案

Update February 2015

Just noticed that Emacs now (version 25+) has the command comint-clear-buffer, bound to C-c M-o by default, that does what we need here, and probably is preferable to the answers I originally posted below.

Options to consider:

  1. C-l will recenter the buffer. Pressing it repeatedly cycles the buffer, so that point appears at the top, middle, or bottom of the buffer. When it stops at the top, the buffer looks like it's been cleared, although all the text is still there, out of view.

  2. C-x h marks the whole buffer, after which C-w kills it. This kills the last prompt as well, but after you enter the next command you get your prompt back.

  3. You can also use erase-buffer, which isn't bound to a key by default, but it's easily done (you can also use M-x erase-buffer:

    (defun my-shell-hook ()
      (local-set-key "\C-cl" 'erase-buffer))

    (add-hook 'shell-mode-hook 'my-shell-hook)

That binds it to C-c l; you can pick what you like.

  1. A quick fix to re-create your prompt after clearing is possible:

    (defun my-clear ()
      (interactive)
      (erase-buffer)
      (comint-send-input))

    (defun my-shell-hook ()
      (local-set-key "\C-cl" 'my-clear))

    (add-hook 'shell-mode-hook 'my-shell-hook)

After you've been using emacs for a while, marking and killing regions becomes natural, so you might find the first option is enough. If not, the last option is closest to what you want.

EDIT: just found this on the emacs wiki, it's better than my option 4:

(defun my-clear ()
  (interactive)
  (let ((comint-buffer-maximum-size 0))
    (comint-truncate-buffer)))

这篇关于使用emacs shell命令清除shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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