Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kill the associated buffer when close the emacs-client frame by pressing Alt+F4

Tags:

emacs

I get used to emacsclient for the speedy response like vim, by putting emacs into sever mode with command "emacs --daemon". But I found it quite annoying that lots of buffers kept alive when I viewed some files and then closed them by pressing Alt+F4. I have to kill the buffer explicitly before closing the frame.

I want to know, if there is a way to make emacsclient behave more like a lightweight GUI editor(e.g. vim) in this point?

like image 870
ybyygu Avatar asked Dec 06 '09 06:12

ybyygu


People also ask

How do I close a buffer window in Emacs?

C-x 4 0 ( kill-buffer-and-window ) is a stronger command than C-x 0 ; it kills the current buffer and then deletes the selected window. C-x 1 ( delete-other-windows ) deletes all the windows, except the selected one; the selected window expands to use the whole frame.

How do I close a frame in Emacs?

Typing C-x C-c closes all the frames on the current display, and ends the Emacs session if it has no frames open on any other displays (see Exiting Emacs). To close just the selected frame, type C-x 5 0 (that is zero, not o ).

How do I kill multiple buffers in Emacs?

Select all matches with M-m ( helm-toggle-all-marks ). Optionally, refine your selection with C-SPC ( helm-toggle-visible-marks ), using C-n / C-p to navigate. Press TAB , select "kill buffers" from the available options.

How do I kill a process in Emacs?

41.2. 1 Killing Emacs Killing Emacs means ending the execution of the Emacs process. If you started Emacs from a terminal, the parent process normally resumes control. The low-level primitive for killing Emacs is kill-emacs . This command calls the hook kill-emacs-hook , then exits the Emacs process and kills it.


2 Answers

I think you're asking for trouble, but you you could try this:

(add-hook 'delete-frame-functions
          (lambda (frame)
            (let* ((window (frame-selected-window frame))
                   (buffer (and window (window-buffer window))))
              (when (and buffer (buffer-file-name buffer))
                (kill-buffer buffer)))))
like image 138
scottfrazer Avatar answered Oct 23 '22 05:10

scottfrazer


I suggest that you use the command quit-window which does precisely what you want (with the prefix argument); it is already the binding for q in special-mode (i.e., not self-insert) buffers. You can bind it to, say, C-f4, and it will kill the buffer and the frame when you type C-u C-f4.

like image 30
sds Avatar answered Oct 23 '22 04:10

sds