Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to automatically close filename completetion buffers in Emacs?

Tags:

emacs

elisp

For example, when you open a file via C-x-C-f, you can TAB complete file names, and if there are more than one possible completions, it will pop open a completion buffer with a list of possible completions. The problem is, after you've opened the file, the window the buffer was in switches back to normal, but it doesn't close. Is there any way I can make those buffers close automatically after the file has been opened?

like image 865
Rayne Avatar asked Jan 03 '10 20:01

Rayne


People also ask

Can you have only one buffer open in Emacs at a time?

Each Emacs window displays one Emacs buffer at any time. A single buffer may appear in more than one window; if it does, any changes in its text are displayed in all the windows where it appears.

Can you have more than one buffer open in Emacs?

Much better to use the multiple buffer feature of emacs. If you are editing the first file and want to start editing the second file, simply use the hot key C-x C-f or the menu selection File->Open File to start the second file. The second file is loaded into its own buffer.

What is buffer in Emacs?

Buffers in Emacs editing are objects that have distinct names and hold text that can be edited. Buffers appear to Lisp programs as a special data type. You can think of the contents of a buffer as a string that you can extend; insertions and deletions may occur in any part of the buffer.

How to open buffers in Emacs?

Hold down Ctrl and click the left mouse button. Emacs displays a pop-up menu of current buffers by mode (Mac OS X). To cycle through all the buffers you have, type C-x → to go to the next buffer (in the buffer list) or C-x to go to the previous buffer.


2 Answers

Sorry to enter really late on this but this is how I do:

;; Remove completion buffer when done
(add-hook 'minibuffer-exit-hook 
      '(lambda ()
         (let ((buffer "*Completions*"))
           (and (get-buffer buffer)
            (kill-buffer buffer)))))

Tested on GNU Emacs 22.x and 23.x

like image 110
Xavier Maillard Avatar answered Sep 28 '22 09:09

Xavier Maillard


Although it does not directly solve your problem have you considered ido-mode as a mechanism for opening files?

ido-mode will bind C-x C-f to ido-find-file this allows you to interactively opening files (selecting between name collisions from within the minibuffer C-s and various other nifty features) I find it a much easier method of finding files and it will get rid of the *Completions* buffer altogether.

like image 42
kjfletch Avatar answered Sep 28 '22 10:09

kjfletch