简体   繁体   English

自动关闭emacs shell模式tab-completion buffer?

[英]Automatically close emacs shell mode tab-completion buffer?

This has driven me crazy for a long time; 这让我疯了很长时间; I wonder if there is a way to fix it? 我想知道是否有办法解决它? Hopefully I can describe the situation well. 希望我能很好地描述这种情况。

For simplicity's sake, say I've got the following directory structure: ~jer/dirA and ~jer/dirB 为简单起见,请说我有以下目录结构:~jer / dirA和~jer / dirB

Within a shell within emacs, I start off in my top-level directory (~jer), type 'cd dir', and hit tab. 在emacs的shell中,我从顶级目录(~jer)开始,输入'cd dir',然后点击tab。

My window splits in 2, and I've got a *Completions* buffer. 我的窗口分为2,我有一个* Completions *缓冲区。 This is cool; 这很酷; I see that my choices are 'dirA' and 'dirB', I type an 'A' (so my full command is 'cd dirA') and hit enter, but the *Completions* buffer stays open and I have to manually close it (generally with 'Cx 1' because I'm in the shell buffer that I want to save, but if I already have a split window this is even more annoying, because the *Completions* buffer takes the place of the other one that was already there, and I have to switch to that one and hit Cx k to manually kill it). 我看到我的选择是'dirA'和'dirB',我键入'A'(所以我的完整命令是'cd dirA')然后点击回车,但* Completions *缓冲区保持打开状态,我必须手动关闭它(通常使用'Cx 1',因为我在shell缓冲区中我要保存,但是如果我已经有一个拆分窗口,这会更烦人,因为* Completions *缓冲区代替了另一个已经存在,我必须切换到那个并点击Cx k手动杀死它)。

So my question: is there a way to make the *Completions* die automatically once I finish my command? 所以我的问题是:有没有办法让* Completions *在我完成命令后自动死亡? In the example above, as soon as I hit enter after typing 'cd DirA' I would want the buffer to be killed. 在上面的示例中,只要在输入'cd DirA'后按Enter键,我就希望缓冲区被杀死。

Thanks, and I hope this makes sense. 谢谢,我希望这是有道理的。 Note, I don't think this is a duplicate of Is there any way to automatically close filename completetion buffers in Emacs? 注意,我不认为这是重复的是否有任何方法可以自动关闭Emacs中的文件名完成缓冲区? , because that's about using find-file (and in that case the *Completions* buffer does close. ,因为那是关于使用find-file(在这种情况下,* Completions *缓冲区确实关闭。

I think this is exactly what you want. 我认为这正是你想要的。
The delete-completion-window-buffer function will be executed every time you enter a command. 每次输入命令时都会执行delete-completion-window-buffer功能。 It finds all current windows and gets the buffer out of it. 它找到所有当前窗口并从中获取缓冲区。 Then it will check whether the buffer's name is "*Completions*", the buffer that makes you mad, and if so kill the buffer and delete the corresponding window. 然后它将检查缓冲区的名称是否为“* Completions *”,缓冲区让你发疯,如果是,则杀死缓冲区并删除相应的窗口。
At last, it passes the output string to your next hook comint-preoutput-filter-functions. 最后,它将输出字符串传递给下一个钩子comint-preoutput-filter-functions。
Why there is an output argument? 为什么有输出参数? See the comint-preoutput-filter-functions's document; 请参阅comint-preoutput-filter-functions的文档; better explained there. 更好的解释。

(defun delete-completion-window-buffer (&optional output)                                                                
  (interactive)                                                                                                
  (dolist (win (window-list))                                                                                  
    (when (string= (buffer-name (window-buffer win)) "*Completions*")                                          
      (delete-window win)                                                                                      
      (kill-buffer "*Completions*")))                                                                          
  output)                                                                                                      

(add-hook 'comint-preoutput-filter-functions 'delete-completion-window-buffer)

But actually, the completion buffer doesn't bother me a lot. 但实际上,完成缓冲区并没有给我带来太多麻烦。 What bothers is that the command "clear" doesn't work well. 令人困扰的是命令“清除”效果不佳。 In order to solve your problem I google shell-mode, nothing there. 为了解决你的问题我谷歌shell模式,没有什么。
But I got an solution to my problem EmacsWiki . 但我得到了解决我的问题EmacsWiki的解决方案。

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

(define-key shell-mode-map (kbd "C-l") 'clear-shell)                                                           

I bind it to Ctrl-L, the normal terminal binding. 我将它绑定到Ctrl-L,正常的终端绑定。
Nice code. 好的代码。 Hope you like it! 希望你喜欢!

Quick Google search yielded two possibilities: 快速Google搜索产生了两种可能性:

Emacs Icicles Emacs冰柱

ComintMode with this extension . 具有此扩展名的 ComintMode

eshell-mode. ESHELL模式。 Completions buffer will be closed when you hit space or command is finished. 当您点击空格或命令完成时,将关闭完成缓冲区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM