emacs - 自动关闭emacs shell模式选项卡完成缓冲区?

标签 emacs elisp

这让我发疯了很长时间;我想知道有没有办法解决它?希望我能很好地描述情况。

为简单起见,假设我有以下目录结构:~jer/dirA 和 ~jer/dirB

在 emacs 的一个 shell 中,我从我的顶级目录 (~jer) 开始,输入“cd dir”,然后点击选项卡。

我的窗口一分为二,我有一个 *Completions* 缓冲区。这很酷;我看到我的选择是 'dirA' 和 'dirB',我输入了一个 'A'(所以我的完整命令是 'cd dirA')并按回车键,但 *Completions* 缓冲区保持打开状态,我必须手动关闭它(通常使用 'C-x 1',因为我在要保存的 shell 缓冲区中,但如果我已经有一个拆分窗口,那就更烦人了,因为 *Completions* 缓冲区取代了另一个已经在那里,我必须切换到那个并按 C-x k 手动杀死它)。

所以我的问题是:有没有办法让 *Completions* 在我完成命令后自动消失?在上面的示例中,只要我在输入“cd DirA”后按 Enter,我就会希望缓冲区被终止。

谢谢,我希望这是有道理的。请注意,我不认为这是 Is there any way to automatically close filename completetion buffers in Emacs? 的副本,因为那是关于使用 find-file (在这种情况下, *Completions* 缓冲区确实会关闭。

最佳答案

我认为这正是你想要的。
删除完成窗口缓冲区 每次输入命令时都会执行函数。它找到所有当前窗口并从中获取缓冲区。然后它会检查缓冲区的名称是否是“*Completions*”,是让你发疯的缓冲区,如果是,则杀死缓冲区并删除相应的窗口。
最后,它将输出字符串传递给您的下一个钩子(Hook) comint-preoutput-filter-functions。
为什么有输出参数? 请参阅 comint-preoutput-filter-functions 的文档;在那里更好地解释。

(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)

但实际上,完成缓冲区并没有给我带来太多困扰。麻烦的是命令“clear”没有
运作良好。为了解决你的问题,我google shell-mode,什么都没有。
但我找到了解决问题的方法 EmacsWiki .

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

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

我将它绑定(bind)到 Ctrl-L,即普通的终端绑定(bind)。
不错的代码。希望你喜欢!

关于emacs - 自动关闭emacs shell模式选项卡完成缓冲区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6458220/

相关文章:

emacs - 如何在 Lisp In A Box 中更改 emacs 配置

emacs - 保存时自动字节编译

regex - Emacs Lisp : can the same regexp match two different patterns with same number of groupings?

emacs - 如何将超链接复制到 emacs?

emacs - 如何在 Emacs 中保存框架位置?

git - 点文件存储库 : Switching from per-package Git submodules to ELPA while maintaining portability

emacs - 想要在 Emacs 的正常状态下使用空格键后接一个键而不是 C 键

emacs - 如何在 Emacs 中进行缓冲区本地键绑定(bind)?

emacs - 是否可以告诉 Windows 上的 emacs 使用 IE http 代理设置?

search - Emacs:如何删除以特定文本开头的行