unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Question about Emacs client and server
@ 2023-07-12 11:34 PierGianLuca
  2023-07-12 12:34 ` Eric S Fraga
  0 siblings, 1 reply; 6+ messages in thread
From: PierGianLuca @ 2023-07-12 11:34 UTC (permalink / raw)
  To: help-gnu-emacs

I'm on a Linux machine (Ubuntu) with a desktop manager (KDE). It has always been my wish to set up Emacs so that it works as follows:

1a. If no Emacs is running, then launching "Emacs" (from program launcher or command line) should start Emacs and reopen the previous Emacs-desktop configuration.

1b. If Emacs is already running, then launching "Emacs" should open a new empty (scratch) frame.

2a. If Emacs is already running, and a (say .txt) file is double-clicked or sent to "open with Emacs", or called by some other program invoking a text editor, then it should open in a new Emacs frame.

2b. If no Emacs is running, and a file is double-clicked or called by some other program invoking a text editor, then it should open in a new Emacs frame, and the previous Emacs-desktop configuration should be restored.


Now I've managed to almost achieve this behaviour, but I notice that some Emacs frames are "emacsclient" ones (they have a "@" in the status line); others are not. I don't see why they should be different.

And sometimes launching an Emacs instance warns me that the emacs-desktop is already in use. This happens if I'm not careful and am launching "Emacs" instead of "Emacs (client)".

I wonder if anyone here has suggestions on how to achieve the behaviour that I wish – or can tell me if it isn't possible.

I've tried to understand and configure the Emacs server and the emacsclient behaviour for some years now, but in the end I've always given up. I haven't fully grasped how they work yet.

Just to avoid misunderstandings: this is absolutely *not* meant as a criticism of how Emacs works. It's just a request for customization help. And I understand that great part of the problem comes from my ignorance about Emacs's workings.

Cheers!
Luca





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about Emacs client and server
  2023-07-12 11:34 Question about Emacs client and server PierGianLuca
@ 2023-07-12 12:34 ` Eric S Fraga
  2023-07-12 13:35   ` PierGianLuca
  2023-07-12 13:56   ` PierGianLuca
  0 siblings, 2 replies; 6+ messages in thread
From: Eric S Fraga @ 2023-07-12 12:34 UTC (permalink / raw)
  To: help-gnu-emacs

I achieve pretty much what you want by *always* executing

emacsclient -a emacs -c

(with optional file to open) which will start a fresh emacs is not
already running but otherwise will create a new frame.

It is up to your emacs initialization to take care of the desktop
configuration (something I do not do).

The only thing I cannot help with is:

> I notice that some Emacs frames are "emacsclient" ones (they have a
> "@" in the status line); others are not. I don't see why they should
> be different.

but I don't find this to be an issue.  YMMV, of course.

-- 
Eric S Fraga via gnus (Emacs 30.0.50 2023-07-10) on Debian 12.0




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about Emacs client and server
  2023-07-12 12:34 ` Eric S Fraga
@ 2023-07-12 13:35   ` PierGianLuca
  2023-07-12 14:59     ` Eric S Fraga
  2023-07-12 13:56   ` PierGianLuca
  1 sibling, 1 reply; 6+ messages in thread
From: PierGianLuca @ 2023-07-12 13:35 UTC (permalink / raw)
  To: help-gnu-emacs

Thank you very much, Eric!

It work almost smoothly. But it still has some "glitches" (with respect to my workflow).

For example, if I issue a "kill-current-buffer" in a "client buffer" (no "@"), then the buffer will be killed, but the frame stays there, displaying some other buffer (which is what I want). If the frame displayed two buffers, the other buffer remains.

If I issue a "kill-current-buffer" in a "client buffer" (showing "@"), then the whole frame is also closed. This is slightly annoying because I have to check whether the "@" is there or not, in order to know whether the frame will be deleted or not.

On 230712 14:34, Eric S Fraga wrote:
> I achieve pretty much what you want by *always* executing
> 
> emacsclient -a emacs -c
> 
> (with optional file to open) which will start a fresh emacs is not
> already running but otherwise will create a new frame.
> 
> It is up to your emacs initialization to take care of the desktop
> configuration (something I do not do).
> 
> The only thing I cannot help with is:
> 
>> I notice that some Emacs frames are "emacsclient" ones (they have a
>> "@" in the status line); others are not. I don't see why they should
>> be different.
> 
> but I don't find this to be an issue.  YMMV, of course.
> 



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about Emacs client and server
  2023-07-12 12:34 ` Eric S Fraga
  2023-07-12 13:35   ` PierGianLuca
@ 2023-07-12 13:56   ` PierGianLuca
  1 sibling, 0 replies; 6+ messages in thread
From: PierGianLuca @ 2023-07-12 13:56 UTC (permalink / raw)
  To: help-gnu-emacs

Ok it seems that if I add a --no-wait

emacsclient --no-wait -a emacs -c

then "kill-current-buffer" will not delete the client frame.

I only have to check whether this interferes with programs that temporarily call Emacs to edit some text files...

Thank you again for the suggestion!

On 230712 14:34, Eric S Fraga wrote:
> I achieve pretty much what you want by *always* executing
> 
> emacsclient -a emacs -c
> 
> (with optional file to open) which will start a fresh emacs is not
> already running but otherwise will create a new frame.
> 
> It is up to your emacs initialization to take care of the desktop
> configuration (something I do not do).
> 
> The only thing I cannot help with is:
> 
>> I notice that some Emacs frames are "emacsclient" ones (they have a
>> "@" in the status line); others are not. I don't see why they should
>> be different.
> 
> but I don't find this to be an issue.  YMMV, of course.
> 



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about Emacs client and server
  2023-07-12 13:35   ` PierGianLuca
@ 2023-07-12 14:59     ` Eric S Fraga
  2023-07-12 15:43       ` PierGianLuca
  0 siblings, 1 reply; 6+ messages in thread
From: Eric S Fraga @ 2023-07-12 14:59 UTC (permalink / raw)
  To: help-gnu-emacs

On Wednesday, 12 Jul 2023 at 15:35, PierGianLuca wrote:
> It work almost smoothly. But it still has some "glitches" (with
> respect to my workflow).

Glad it works (almost)!

Regarding closing frames etc., my use case seldom involves killing a
buffer so it's not something I have encountered.  I let buffers build up
and, despite having emacs uptimes on the order of weeks, I've never had
a problem.

In your other post, adding --no-wait is likely to cause issues with some
uses, I would imagine, where the invoking program thinks you are done...

-- 
Eric S Fraga via gnus (Emacs 30.0.50 2023-07-10) on Debian 12.0




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about Emacs client and server
  2023-07-12 14:59     ` Eric S Fraga
@ 2023-07-12 15:43       ` PierGianLuca
  0 siblings, 0 replies; 6+ messages in thread
From: PierGianLuca @ 2023-07-12 15:43 UTC (permalink / raw)
  To: help-gnu-emacs


> Regarding closing frames etc., my use case seldom involves killing a
> buffer so it's not something I have encountered.  I let buffers build up

I used to do that, but realized that (in my case) it complicated the buffer-switching – often had to go through a long list of buffers or many partial-name-matches before finding the right one.

> In your other post, adding --no-wait is likely to cause issues with some
> uses, I would imagine, where the invoking program thinks you are done...

Thank you for the warning. Yes I fear that. I'll check what happens next time I invoke such a program.

Incidentally, I saw hat in the folder where Emacs (28.1 in my case) gets compiled, it creates an "emacsclient.desktop" file with the following quite complex call:

sh -c "if [ -n \\"\\$*\\" ]; then exec emacsclient --alternate-editor= --display=\\"\\$DISPLAY\\" \\"\\$@\\"; else exec emacsclient --alternate-editor= --create-frame; fi" placeholder %F

I suppose it's written this way to take care of different displays.

I'll report later on how things are going with this setup, if anyone is interested.

One last comment: I also found it useful to set "server-client-instructions" to 'nil'.

Thank you again Eric!
Luca



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-07-12 15:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-12 11:34 Question about Emacs client and server PierGianLuca
2023-07-12 12:34 ` Eric S Fraga
2023-07-12 13:35   ` PierGianLuca
2023-07-12 14:59     ` Eric S Fraga
2023-07-12 15:43       ` PierGianLuca
2023-07-12 13:56   ` PierGianLuca

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).