Automatically close emacs shell mode tab-completion buffer?

Quick Google search yielded two possibilities:

Emacs Icicles

ComintMode with this extension.


I think this is exactly what you want.
The delete-completion-window-buffer function will be executed every time you enter a command. 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.
At last, it passes the output string to your next hook comint-preoutput-filter-functions.
Why there is an output argument? See the comint-preoutput-filter-functions's document; 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.
But I got an solution to my problem 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.
Nice code. Hope you like it!

Tags:

Emacs

Elisp