开发者

Emacs - emacsclient or new frame?

开发者 https://www.devze.com 2022-12-08 05:54 出处:网络
this is a rather rudimentary question, but what is the practical difference between opening a new file in a separate frame (make-new-frame) from emacs or opening the file in an instance of emacsclient

this is a rather rudimentary question, but what is the practical difference between opening a new file in a separate frame (make-new-frame) from emacs or opening the file in an instance of emacsclient? I can see that if you ar开发者_如何学Goe working through a terminal, the difference is clear... but can emacsclient additionally restrict the list of buffers accessed by (buffer-menu) or ido-mode to buffers opened in that particular emacsclient instance?


There's really no difference between the two situations, other than the fact that the server sets up some buffer-local state to enable C-x # (aka server-edit).

You can limit M-x list-buffers behavior like you're asking with the following advice:

(defadvice list-buffers-noselect (before list-buffers-noselect-limit-to-those-for-emacsclient activate)
  "When the current buffer is a being viewed by an emacclient, restrict the buffers to those associated with the emacsclient"
  (when (and (null (ad-get-arg 1)) server-buffer-clients)
    (let ((blist (delete-dups (reduce 'append
                                       (mapcar (lambda (proc) (process-get proc 'buffers))
                                               server-buffer-clients)))))
      (ad-set-arg 1 blist))))

Now when you do M-x buffer-menu in a buffer visited by emacsclient, you only see other buffers visited by the same client(s). It works as normal when the buffer is not visited by an emacsclient.

I don't use ido, but I imagine the customization would be similar (if this advice doesn't work as is).

The details are that when you run emacsclient, the buffers that get opened up are associated with the server process (it can be more than one because you can open up the same file via multiple invocations of emacsclient). A buffer's server clients are stored in the buffer local variable server-buffer-clients.

To find out which buffers are associated with a particular invocation of emacsclient, find the process for that emacsclient, and do: (process-get proc 'buffers) (where proc is the particular emacsclient process - one of the elements of the list found in server-buffer-clients).

That's all the advice does.


There is no difference in emacs 23, as long as emacsserver is running. The buffer list will be the same in each.

0

精彩评论

暂无评论...
验证码 换一张
取 消