unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Understanding the behaviour of Emacs and Emacs Client
@ 2022-02-23  3:23 Pankaj Jangid
  2022-02-23  6:56 ` Jean Louis
  2022-02-23 12:26 ` Eli Zaretskii
  0 siblings, 2 replies; 8+ messages in thread
From: Pankaj Jangid @ 2022-02-23  3:23 UTC (permalink / raw)
  To: help-gnu-emacs

I am on version 29 (Git-master). And I "make install" into $HOME/.local
on a Debian (stable) system. I am using Gnome.

Now I have two application icons - Emacs and Emacs (Client). I want to
understand the behaviour of these two links. Following is what is
happening on my system and I want to know if that is the desired
behaviour:

1. When I launch Emacs by clicking "Emacs" icon from apps. Emacs
   launches as usual and shows "Emacs (Client)" near the Activities menu
   in Gnome shell. And when I exit Emacs, C-x C-c, it is perfectly
   shutdown.

2. When I launch Emacs by clicking "Emacs (Client)" icon from
   apps. Emacs launches as expected. And shows "Emacs (Client)" near the
   Activities menu. But when I want to exit this instance of Emacs, I
   press C-x C-c and the frame is gone. But there is still an Emacs
   process running.

I want to know if this is the desired behaviour of Emacs. And if Yes
then what is the official way to terminate the residual Emacs process in
case (2) above?

~Regards Pankaj




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

* Re: Understanding the behaviour of Emacs and Emacs Client
  2022-02-23  3:23 Understanding the behaviour of Emacs and Emacs Client Pankaj Jangid
@ 2022-02-23  6:56 ` Jean Louis
  2022-02-23  8:41   ` Pankaj Jangid
  2022-02-23 12:26 ` Eli Zaretskii
  1 sibling, 1 reply; 8+ messages in thread
From: Jean Louis @ 2022-02-23  6:56 UTC (permalink / raw)
  To: Pankaj Jangid; +Cc: help-gnu-emacs

* Pankaj Jangid <pankaj@codeisgreat.org> [2022-02-23 06:25]:
> I am on version 29 (Git-master). And I "make install" into $HOME/.local
> on a Debian (stable) system. I am using Gnome.
> 
> Now I have two application icons - Emacs and Emacs (Client). I want to
> understand the behaviour of these two links. Following is what is
> happening on my system and I want to know if that is the desired
> behaviour:
> 
> 1. When I launch Emacs by clicking "Emacs" icon from apps. Emacs
>    launches as usual and shows "Emacs (Client)" near the Activities menu
>    in Gnome shell. And when I exit Emacs, C-x C-c, it is perfectly
>    shutdown.
> 
> 2. When I launch Emacs by clicking "Emacs (Client)" icon from
>    apps. Emacs launches as expected. And shows "Emacs (Client)" near the
>    Activities menu. But when I want to exit this instance of Emacs, I
>    press C-x C-c and the frame is gone. But there is still an Emacs
>    process running.
> 
> I want to know if this is the desired behaviour of Emacs. And if Yes
> then what is the official way to terminate the residual Emacs process in
> case (2) above?

Emacs Client will connect to Emacs server or daemon. 

And here it output from

$ emacs --help

use this to understand how to run Emacs daemon, there are few ways.

Usage: emacs [OPTION-OR-FILENAME]...

Run Emacs, the extensible, customizable, self-documenting real-time
display editor.  The recommended way to start Emacs for normal editing
is with no options at all.

Run M-x info RET m emacs RET m emacs invocation RET inside Emacs to
read the main documentation for these command-line arguments.

Initialization options:

--batch                     do not do interactive display; implies -q
--chdir DIR                 change to directory DIR
--daemon, --bg-daemon[=NAME] start a (named) server in the background
--fg-daemon[=NAME]          start a (named) server in the foreground
--debug-init                enable Emacs Lisp debugger for init file
--display, -d DISPLAY       use X server DISPLAY
--module-assertions         assert behavior of dynamic modules
--dump-file FILE            read dumped state from FILE
--fingerprint               output fingerprint and exit
--seccomp=FILE              read Seccomp BPF filter from FILE
--no-build-details          do not add build details such as time stamps
--no-desktop                do not load a saved desktop
--no-init-file, -q          load neither ~/.emacs nor default.el
--no-loadup, -nl            do not load loadup.el into bare Emacs
--no-site-file              do not load site-start.el
--no-x-resources            do not load X resources
--no-site-lisp, -nsl        do not add site-lisp directories to load-path
--no-splash                 do not display a splash screen on startup
--no-window-system, -nw     do not communicate with X, ignoring $DISPLAY
--quick, -Q                 equivalent to:
                              -q --no-site-file --no-site-lisp --no-splash
                              --no-x-resources
--script FILE               run FILE as an Emacs Lisp script
--terminal, -t DEVICE       use DEVICE for terminal I/O
--user, -u USER             load ~USER/.emacs instead of your own

Action options:

FILE                    visit FILE
+LINE                   go to line LINE in next FILE
+LINE:COLUMN            go to line LINE, column COLUMN, in next FILE
--directory, -L DIR     prepend DIR to load-path (with :DIR, append DIR)
--eval EXPR             evaluate Emacs Lisp expression EXPR
--execute EXPR          evaluate Emacs Lisp expression EXPR
--file FILE             visit FILE
--find-file FILE        visit FILE
--funcall, -f FUNC      call Emacs Lisp function FUNC with no arguments
--insert FILE           insert contents of FILE into current buffer
--kill                  exit without asking for confirmation
--load, -l FILE         load Emacs Lisp FILE using the load function
--visit FILE            visit FILE

Display options:

--background-color, -bg COLOR   window background color
--basic-display, -D             disable many display features;
                                  used for debugging Emacs
--border-color, -bd COLOR       main border color
--border-width, -bw WIDTH       width of main border
--color, --color=MODE           override color mode for character terminals;
                                  MODE defaults to `auto', and
                                  can also be `never', `always',
                                  or a mode name like `ansi8'
--cursor-color, -cr COLOR       color of the Emacs cursor indicating point
--font, -fn FONT                default font; must be fixed-width
--foreground-color, -fg COLOR   window foreground color
--fullheight, -fh               make the first frame high as the screen
--fullscreen, -fs               make the first frame fullscreen
--fullwidth, -fw                make the first frame wide as the screen
--maximized, -mm                make the first frame maximized
--geometry, -g GEOMETRY         window geometry
--no-bitmap-icon, -nbi          do not use picture of gnu for Emacs icon
--iconic                        start Emacs in iconified state
--internal-border, -ib WIDTH    width between text and main border
--line-spacing, -lsp PIXELS     additional space to put between lines
--mouse-color, -ms COLOR        mouse cursor color in Emacs window
--name NAME                     title for initial Emacs frame
--no-blinking-cursor, -nbc      disable blinking cursor
--reverse-video, -r, -rv        switch foreground and background
--title, -T TITLE               title for initial Emacs frame
--vertical-scroll-bars, -vb     enable vertical scroll bars
--xrm XRESOURCES                set additional X resources
--parent-id XID                 set parent window
--help                          display this help and exit
--version                       output version information and exit

You can generally also specify long option names with a single -; for
example, -batch as well as --batch.  You can use any unambiguous
abbreviation for a --option.

Various environment variables and window system resources also affect
the operation of Emacs.  See the main documentation.

Report bugs to bug-gnu-emacs@gnu.org.  First, please see the Bugs
section of the Emacs manual or the file BUGS.

I use this file to start Emacs as server, subsequently emacsclient,
and if Emacs already run as server, I start emacsclient. So I use
emacsclient all the time.

#!/bin/bash
export EMACS_SOCKET_NAME="/run/user/1001/emacs/server"
if pgrep -f "emacs --bg-daemon" > /dev/null
then
    espeak "Starting Emacs client"
    emacsclient -c
else
    espeak "Starting Emacs daemon"
    emacs --bg-daemon
    sleep 10
    emacsclient -c
fi


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

* Re: Understanding the behaviour of Emacs and Emacs Client
  2022-02-23  6:56 ` Jean Louis
@ 2022-02-23  8:41   ` Pankaj Jangid
  2022-02-23 12:02     ` Jean Louis
  0 siblings, 1 reply; 8+ messages in thread
From: Pankaj Jangid @ 2022-02-23  8:41 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis <bugs@gnu.support> writes:

> * Pankaj Jangid <pankaj@codeisgreat.org> [2022-02-23 06:25]:
>> 1. When I launch Emacs by clicking "Emacs" icon from apps. Emacs
>>    launches as usual and shows "Emacs (Client)" near the Activities menu
>>    in Gnome shell. And when I exit Emacs, C-x C-c, it is perfectly
>>    shutdown.
>> 
>> 2. When I launch Emacs by clicking "Emacs (Client)" icon from
>>    apps. Emacs launches as expected. And shows "Emacs (Client)" near the
>>    Activities menu. But when I want to exit this instance of Emacs, I
>>    press C-x C-c and the frame is gone. But there is still an Emacs
>>    process running.
>> 
>> I want to know if this is the desired behaviour of Emacs. And if Yes
>> then what is the official way to terminate the residual Emacs process in
>> case (2) above?
>
> <<cut>>
>
> I use this file to start Emacs as server, subsequently emacsclient,
> and if Emacs already run as server, I start emacsclient. So I use
> emacsclient all the time.
>
> #!/bin/bash
> export EMACS_SOCKET_NAME="/run/user/1001/emacs/server"
> if pgrep -f "emacs --bg-daemon" > /dev/null
> then
>     espeak "Starting Emacs client"
>     emacsclient -c
> else
>     espeak "Starting Emacs daemon"
>     emacs --bg-daemon
>     sleep 10
>     emacsclient -c
> fi

I understand how to launch the server and how to launch from CLI. May be
that I was not clear enough.

I just want to know how to cleanup (gracefully) the residual process
when there are no more clients connecting. i.e. case (2) above. User has
started Emacs by clicking on the "Emacs (Client)" icon in a graphical
environment.



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

* Re: Understanding the behaviour of Emacs and Emacs Client
  2022-02-23  8:41   ` Pankaj Jangid
@ 2022-02-23 12:02     ` Jean Louis
  2022-02-23 12:54       ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Jean Louis @ 2022-02-23 12:02 UTC (permalink / raw)
  To: help-gnu-emacs

* Pankaj Jangid <pankaj@codeisgreat.org> [2022-02-23 11:44]:
> I just want to know how to cleanup (gracefully) the residual process
> when there are no more clients connecting. i.e. case (2) above. User has
> started Emacs by clicking on the "Emacs (Client)" icon in a graphical
> environment.

To cleanup you kill Emacs as daemon in memory. To remove Emacs
client's frame, I use C-x 5 0

You could remove daemon process with:

pkill "emacs --daemon" or other command line you used.

I don't do that almost ever, as computer once it turns off does i.t



-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

* Re: Understanding the behaviour of Emacs and Emacs Client
  2022-02-23  3:23 Understanding the behaviour of Emacs and Emacs Client Pankaj Jangid
  2022-02-23  6:56 ` Jean Louis
@ 2022-02-23 12:26 ` Eli Zaretskii
  2022-02-28  3:29   ` Pankaj Jangid
  1 sibling, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2022-02-23 12:26 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Pankaj Jangid <pankaj@codeisgreat.org>
> Date: Wed, 23 Feb 2022 08:53:35 +0530
> 
> 1. When I launch Emacs by clicking "Emacs" icon from apps. Emacs
>    launches as usual and shows "Emacs (Client)" near the Activities menu
>    in Gnome shell. And when I exit Emacs, C-x C-c, it is perfectly
>    shutdown.
> 
> 2. When I launch Emacs by clicking "Emacs (Client)" icon from
>    apps. Emacs launches as expected. And shows "Emacs (Client)" near the
>    Activities menu. But when I want to exit this instance of Emacs, I
>    press C-x C-c and the frame is gone. But there is still an Emacs
>    process running.
> 
> I want to know if this is the desired behaviour of Emacs.

Yes.

> And if Yes then what is the official way to terminate the residual
> Emacs process in case (2) above?

The official way is to type "M-x kill-emacs RET".  (But in general, if
you use the "client" icon, the assumption is that you don't want to do
that.  rather, leave the Emacs process running and use the client icon
to open a new frame next time you want to do something in Emacs --
this way, you keep all the history and the buffers inside the
session, and the startup will be faster.)



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

* Re: Understanding the behaviour of Emacs and Emacs Client
  2022-02-23 12:02     ` Jean Louis
@ 2022-02-23 12:54       ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2022-02-23 12:54 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Wed, 23 Feb 2022 15:02:53 +0300
> From: Jean Louis <bugs@gnu.support>
> 
> pkill "emacs --daemon" or other command line you used.

No, just "M-x kill-emacs RET" from the client frame.

Killing the process will lose any unsaved work, will not call the
hooks in the likes of saveplace.el and desktop.el, etc.  Not
recommended.



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

* Re: Understanding the behaviour of Emacs and Emacs Client
  2022-02-23 12:26 ` Eli Zaretskii
@ 2022-02-28  3:29   ` Pankaj Jangid
  2022-03-01 16:54     ` Suvayu Ali
  0 siblings, 1 reply; 8+ messages in thread
From: Pankaj Jangid @ 2022-02-28  3:29 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> And if Yes then what is the official way to terminate the residual
>> Emacs process in case (2) above?
>
> The official way is to type "M-x kill-emacs RET".  (But in general, if
> you use the "client" icon, the assumption is that you don't want to do
> that.  rather, leave the Emacs process running and use the client icon
> to open a new frame next time you want to do something in Emacs --
> this way, you keep all the history and the buffers inside the
> session, and the startup will be faster.)

Thanks for the explanation, Eli. The only time I would want to do that
is when I am shutting down or rebooting the system for some reason. I
want to cleanly exit and save all work. "M-x kill-emacs RET" certainly
helps.

Customization var like "kill-emacs-with-last-frame" could be a good
idea. Or "C-x C-c" on last frame may be used to default to this
behaviour; this will prevent any lost work due to reboot or
shutdown. Because the daemon is invisible after last frame. Just an
idea. "C-x 5 0" remains the same.




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

* Re: Understanding the behaviour of Emacs and Emacs Client
  2022-02-28  3:29   ` Pankaj Jangid
@ 2022-03-01 16:54     ` Suvayu Ali
  0 siblings, 0 replies; 8+ messages in thread
From: Suvayu Ali @ 2022-03-01 16:54 UTC (permalink / raw)
  To: Emacs mailing list

On Mon, Feb 28, 2022 at 3:29 AM Pankaj Jangid <pankaj@codeisgreat.org> wrote:
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> >> And if Yes then what is the official way to terminate the residual
> >> Emacs process in case (2) above?
> >
> > The official way is to type "M-x kill-emacs RET".  (But in general, if
> > you use the "client" icon, the assumption is that you don't want to do
> > that.  rather, leave the Emacs process running and use the client icon
> > to open a new frame next time you want to do something in Emacs --
> > this way, you keep all the history and the buffers inside the
> > session, and the startup will be faster.)
>
> Thanks for the explanation, Eli. The only time I would want to do that
> is when I am shutting down or rebooting the system for some reason. I
> want to cleanly exit and save all work. "M-x kill-emacs RET" certainly
> helps.
>
> Customization var like "kill-emacs-with-last-frame" could be a good
> idea. Or "C-x C-c" on last frame may be used to default to this
> behaviour; this will prevent any lost work due to reboot or
> shutdown. Because the daemon is invisible after last frame. Just an
> idea. "C-x 5 0" remains the same.

I use the following:

  emacsclient --eval "(save-some-buffers t)" --eval "(kill-emacs)"

-- 
Suvayu

Open source is the future. It sets us free.



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

end of thread, other threads:[~2022-03-01 16:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-23  3:23 Understanding the behaviour of Emacs and Emacs Client Pankaj Jangid
2022-02-23  6:56 ` Jean Louis
2022-02-23  8:41   ` Pankaj Jangid
2022-02-23 12:02     ` Jean Louis
2022-02-23 12:54       ` Eli Zaretskii
2022-02-23 12:26 ` Eli Zaretskii
2022-02-28  3:29   ` Pankaj Jangid
2022-03-01 16:54     ` Suvayu Ali

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).