unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#11358: 24.1.50; Feature request: A way to abort emacs-client
@ 2012-04-27  7:44 Harald Hanche-Olsen
  2016-07-07  1:07 ` npostavs
  0 siblings, 1 reply; 8+ messages in thread
From: Harald Hanche-Olsen @ 2012-04-27  7:44 UTC (permalink / raw)
  To: 11358

There should be a way, from within a server editing buffer, to cause
the corresponding emacs-client process to exit with a nonzero exit
status. This can then be used by the calling process as an indication
that the user has abandoned the edit.

If there is already a way to achieve this, consider this a
documentation bug: I am certainly unable to find this feature.

In GNU Emacs 24.1.50.2 (x86_64-unknown-linux-gnu, GTK+ Version 2.20.1)
 of 2012-04-10 on fia.math.ntnu.no
Bzr revision: 107840 larsi@gnus.org-20120410112744-slbrfdrrjb0x1mfy

- Harald





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

* bug#11358: 24.1.50; Feature request: A way to abort emacs-client
  2012-04-27  7:44 bug#11358: 24.1.50; Feature request: A way to abort emacs-client Harald Hanche-Olsen
@ 2016-07-07  1:07 ` npostavs
  2021-06-02  6:38   ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: npostavs @ 2016-07-07  1:07 UTC (permalink / raw)
  To: Harald Hanche-Olsen; +Cc: 11358

Harald Hanche-Olsen <hanche@math.ntnu.no> writes:

> There should be a way, from within a server editing buffer, to cause
> the corresponding emacs-client process to exit with a nonzero exit
> status. This can then be used by the calling process as an indication
> that the user has abandoned the edit.
>
> If there is already a way to achieve this, consider this a
> documentation bug: I am certainly unable to find this feature.

There is a way to do this, I know because it's used by magit to tell git
to cancel the commit message editing (with-editor is a library that was
spun off from magit):

(defun with-editor-return (cancel)
  (let ...
        (clients server-buffer-clients)
...
               (dolist (client clients)
                 (ignore-errors
                   (server-send-string client "-error Canceled by user"))
...


The only documentation I could find on it was in server-process-filter
docstring:

(cl-defun server-process-filter (proc string)
  "Process a request from the server to edit some files.
PROC is the server process. [...]
The following commands are accepted by the client:
[...]
`-error DESCRIPTION'
  Signal an error and delete process PROC.

Probably it should be mentioned in the elisp manual somewhere, not sure
where, there doesn't seem to be an appropriate existing chapter.





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

* bug#11358: 24.1.50; Feature request: A way to abort emacs-client
  2016-07-07  1:07 ` npostavs
@ 2021-06-02  6:38   ` Lars Ingebrigtsen
  2021-06-02  7:05     ` Harald Hanche-Olsen
  0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-06-02  6:38 UTC (permalink / raw)
  To: npostavs; +Cc: 11358, Harald Hanche-Olsen

npostavs@users.sourceforge.net writes:

> Harald Hanche-Olsen <hanche@math.ntnu.no> writes:
>
>> There should be a way, from within a server editing buffer, to cause
>> the corresponding emacs-client process to exit with a nonzero exit
>> status. This can then be used by the calling process as an indication
>> that the user has abandoned the edit.
>>
>> If there is already a way to achieve this, consider this a
>> documentation bug: I am certainly unable to find this feature.
>
> There is a way to do this, I know because it's used by magit to tell git
> to cancel the commit message editing (with-editor is a library that was
> spun off from magit):

[...]

>                    (server-send-string client "-error Canceled by user"))

[...]

> Probably it should be mentioned in the elisp manual somewhere, not sure
> where, there doesn't seem to be an appropriate existing chapter.

Yes, the server isn't discussed in the elisp manual at all.

Anyway -- was the request here to add a new command to work like
`C-x #', but instead send "-error Canceled by user"?  

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#11358: 24.1.50; Feature request: A way to abort emacs-client
  2021-06-02  6:38   ` Lars Ingebrigtsen
@ 2021-06-02  7:05     ` Harald Hanche-Olsen
  2021-06-03  7:07       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Harald Hanche-Olsen @ 2021-06-02  7:05 UTC (permalink / raw)
  To: Lars Ingebrigtsen, npostavs@users.sourceforge.net; +Cc: 11358@debbugs.gnu.org

From: Lars Ingebrigtsen <larsi@gnus.org>

> Anyway -- was the request here to add a new command to work like
> `C-x #', but instead send "-error Canceled by user"?  

That was my thought, yes. It would not need to be bound to any key by default.
Perhaps ‘server-edit-abort’ is a good name?

– Harald (new email address, formerly hanche@math.ntnu.no)


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

* bug#11358: 24.1.50; Feature request: A way to abort emacs-client
  2021-06-02  7:05     ` Harald Hanche-Olsen
@ 2021-06-03  7:07       ` Lars Ingebrigtsen
  2021-06-03  7:54         ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-06-03  7:07 UTC (permalink / raw)
  To: Harald Hanche-Olsen; +Cc: 11358@debbugs.gnu.org, npostavs@users.sourceforge.net

Harald Hanche-Olsen <harald.hanche-olsen@ntnu.no> writes:

> From: Lars Ingebrigtsen <larsi@gnus.org>
>
>> Anyway -- was the request here to add a new command to work like
>> `C-x #', but instead send "-error Canceled by user"?  
>
> That was my thought, yes. It would not need to be bound to any key by default.
> Perhaps ‘server-edit-abort’ is a good name?

Sure.  I'm not that familiar with how server.el/emacsclient works,
though -- can somebody else propose a patch to implement this command?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#11358: 24.1.50; Feature request: A way to abort emacs-client
  2021-06-03  7:07       ` Lars Ingebrigtsen
@ 2021-06-03  7:54         ` Eli Zaretskii
  2021-06-03 14:46           ` Harald Hanche-Olsen
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2021-06-03  7:54 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 11358, harald.hanche-olsen, npostavs

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Date: Thu, 03 Jun 2021 09:07:52 +0200
> Cc: "11358@debbugs.gnu.org" <11358@debbugs.gnu.org>,
>  "npostavs@users.sourceforge.net" <npostavs@users.sourceforge.net>
> 
> Harald Hanche-Olsen <harald.hanche-olsen@ntnu.no> writes:
> 
> > From: Lars Ingebrigtsen <larsi@gnus.org>
> >
> >> Anyway -- was the request here to add a new command to work like
> >> `C-x #', but instead send "-error Canceled by user"?  
> >
> > That was my thought, yes. It would not need to be bound to any key by default.
> > Perhaps ‘server-edit-abort’ is a good name?
> 
> Sure.  I'm not that familiar with how server.el/emacsclient works,
> though -- can somebody else propose a patch to implement this command?

The commands accepted by the client are documented in the doc string
of server-process-filter.  There's already a command that causes the
client to exit with a non-zero exit status: "-error MESSAGE".  Maybe
just reusing it would do.





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

* bug#11358: 24.1.50; Feature request: A way to abort emacs-client
  2021-06-03  7:54         ` Eli Zaretskii
@ 2021-06-03 14:46           ` Harald Hanche-Olsen
  2021-06-04  9:13             ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Harald Hanche-Olsen @ 2021-06-03 14:46 UTC (permalink / raw)
  To: Eli Zaretskii, Lars Ingebrigtsen
  Cc: 11358@debbugs.gnu.org, npostavs@users.sourceforge.net

Here is a very naive first stab:

(defun server-abort ()
  (interactive)
  (if server-clients
      (mapc (lambda (proc)
              (server-send-string
               proc (concat "-error "
                            (server-quote-arg "Aborted by the user"))))
            server-clients)
    (message "This buffer has no clients")))

That is good enough for me, but ‘server-edit’ (or ‘server-done’, really)
does a bit of housekeeping that this one does not.
Most importantly, what this code does not is decide what to do
with the buffer. It appears that, if it is unmodified, a process sentinel
will delete it, but if it is modified, it remains. Perhaps that is okay.
Perhaps aborting a server is such an exceptional event, one should
leave the cleanup to the user anyhow.
Further ‘server-edit’ will try to switch to a different server buffer,
if one exists. This code does not. Again, perhaps that is as it should be.

– Harald



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

* bug#11358: 24.1.50; Feature request: A way to abort emacs-client
  2021-06-03 14:46           ` Harald Hanche-Olsen
@ 2021-06-04  9:13             ` Lars Ingebrigtsen
  0 siblings, 0 replies; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-06-04  9:13 UTC (permalink / raw)
  To: Harald Hanche-Olsen; +Cc: 11358@debbugs.gnu.org, npostavs@users.sourceforge.net

Harald Hanche-Olsen <harald.hanche-olsen@ntnu.no> writes:

> Here is a very naive first stab:
>
> (defun server-abort ()
>   (interactive)
>   (if server-clients
>       (mapc (lambda (proc)
>               (server-send-string
>                proc (concat "-error "
>                             (server-quote-arg "Aborted by the user"))))
>             server-clients)
>     (message "This buffer has no clients")))
>
> That is good enough for me, but ‘server-edit’ (or ‘server-done’, really)
> does a bit of housekeeping that this one does not.

Thanks, I installed this in Emacs 28 (under the name
server-edit-abort).  This, along with your previous patch, reaches the
limit of the number of lines we can accept into Emacs without a
copyright assignment.  Would you be willing to sign such paperwork?

> Most importantly, what this code does not is decide what to do
> with the buffer. It appears that, if it is unmodified, a process sentinel
> will delete it, but if it is modified, it remains. Perhaps that is okay.
> Perhaps aborting a server is such an exceptional event, one should
> leave the cleanup to the user anyhow.

Yes, I think that makes sense.  If somebody wants to add more logic
here (to query the user for something), that might also be nice.  But it
may not be necessary.

> Further ‘server-edit’ will try to switch to a different server buffer,
> if one exists. This code does not. Again, perhaps that is as it should be.

Yeah, I think aborting just the current buffer makes sense, but I can
see somebody wanting this to behave more like `server-edit' -- I guess
we'll see.  But I think this is fine for now, at least, so I'm closing
this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

end of thread, other threads:[~2021-06-04  9:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-27  7:44 bug#11358: 24.1.50; Feature request: A way to abort emacs-client Harald Hanche-Olsen
2016-07-07  1:07 ` npostavs
2021-06-02  6:38   ` Lars Ingebrigtsen
2021-06-02  7:05     ` Harald Hanche-Olsen
2021-06-03  7:07       ` Lars Ingebrigtsen
2021-06-03  7:54         ` Eli Zaretskii
2021-06-03 14:46           ` Harald Hanche-Olsen
2021-06-04  9:13             ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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