Domanda

If I am running emacs --daemon with a bunch of buffers already in it, is there a way to start emacsclient so it just opens whatever was the top buffer when I last worked in it? If I use emacsclient -t or emacsclient -c it creates a new frame and places it on top, how can I avoid this behavior and just resume whatever I was doing?

È stato utile?

Soluzione

Seems like I found an answer, although it is somewhat inelegant. In my .bash_profile, I put

alias emacs='emacsclient -a "" -t -e \(kill-buffer\)'

so, that a daemon process is started if it doesn't exist, emacs client connects to it, creates a new buffer and immediately kills it, thus leaving whatever buffer was on top before (I use emacs desktop saving) is now displayed on top.

Altri suggerimenti

You could try something like:

emacsclient -e '(raise-frame)'

or

emacsclient -e '(other-frame 0)'

If none of these solutions work (depending on your window manager), you can also try the following solution (from this SO answer):

emacsclient -e  "(select-frame-set-input-focus (selected-frame))"

You seem to be a bit confused with emacs concepts. A frame is in emacs what others call window and an emacs window is where a buffer (the text you are editing) is displayed.

The options -c and -t are supposed to create a new frame (either graphically or on a tty) and if you don't want that, than just leave them out.

If there still is an open (graphical) frame, the last active one will be focused (may be depending on your window manager) and shows a buffer visiting the given file in the last active window. If there is no graphical frame, a new frame on the current tty is opened.

emacsclient cannot be called without a file or directory and either -t or -c. So use your window manager then to show the desired frame.

But if what you really want is, to open a new frame with the buffer at the top of the list (list-buffers) then you are out of luck, since a new frame always shows the scratch-buffer (if not configured). You can change manually with C-x b or tinker with the variable initial-buffer-choice.

None of

emacsclient -e '(raise-frame)'

or

emacsclient -e '(other-frame 0)'

or

emacsclient -e  "(select-frame-set-input-focus (selected-frame))"

worked for me. They did cause emacs to initially show a buffer other than *scratch* , but it was not the last buffer I was working on. I had to write my own mechanism for getting this to work - it assumes you use C-x C-c to disconnect emacsclient from the server :

(defun save-last-buffer-name-and-kill()                                                                                                                                    
  (interactive)                                                                                                                                                            
  (setq jeeves/last-buffer-name (current-buffer))                                                                                                                          
  (save-buffers-kill-terminal)                                                                                                                                             
  )                                                                                                                                                                        
(defun get-last-buffer-name()                                                                                                                                              
  jeeves/last-buffer-name                                                                                                                                                  
  )                                                                                                                                                                        
(global-set-key (kbd "C-x C-c") 'save-last-buffer-name-and-kill)                                                                                                           
(setq initial-buffer-choice 'get-last-buffer-name)                                                                                                                      
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top