tags:

views:

82

answers:

3

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?

A: 

Just start a new 'frame', i.e. a new standalone window under X11, using

emacsclient -c somefile.txt

It will have access to all your other buffers as you would expect using the client / server model. When you are done, just press C-x 5 0, and your new frame stop.

Likewise, you can start session without X11 support when working remotely, or in screen, or ... I find this rather indispensable and use it all the time and essentially never close my main emacs session.

Dirk Eddelbuettel
A: 

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)))))
scottfrazer
thank you so much for your solution and advice :) This is exactly what I want.
ybyygu
A: 

Do something like the following:

(defun my-kill-buffer-and-frame ()
  "kill the current buffer and the current frame"
  (interactive)
  (when (y-or-n-p "Are you sure you wish to delete the current frame?")
    (kill-buffer)
    (delete-frame)))

If you're sure you always wnt to do it, you can get rid of the prompt:

(defun my-kill-buffer-and-frame ()
  "kill the current buffer and the current frame"
  (interactive)
  (kill-buffer)
  (delete-frame))

Then bind it to a key of your choice, like so:

(global-set-key [(f5)] 'my-kill-buffer-and-frame)

Enjoy!

Joe Casadonte
Cool! this is another possible solution :)
ybyygu