GNU bug report logs - #3634
emacsclient: unwind-protect prevents printing final form

Previous Next

Package: emacs;

Reported by: Jonas Bernoulli <jonas <at> bernoul.li>

Date: Sun, 21 Jun 2009 01:45:04 UTC

Severity: normal

Tags: moreinfo, notabug

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 3634 in the body.
You can then email your comments to 3634 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#3634; Package emacs. (Sun, 21 Jun 2009 01:45:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonas Bernoulli <jonas <at> bernoul.li>:
New bug report received and forwarded. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sun, 21 Jun 2009 01:45:04 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Jonas Bernoulli <jonas <at> bernoul.li>
To: bug-gnu-emacs <at> gnu.org
Subject: emacsclient: unwind-protect prevents printing final form
Date: Sun, 21 Jun 2009 03:43:12 +0200
Hi

I am trying to write a wrapper around emacsclient that would allow
emacs to be used by external applications to complete some string.

However it does not seem to be possible to
1. return the last form and
2. ensure that emacsclient always returns
at the same time.

(The following examples assumes default-minibuffer-frame exists. Just
remove the respective line if it doesn't.)

This works as long as the user does not abort:

#!/bin/bash
STRING=$(emacsclient -e "\
(select-frame-set-input-focus default-minibuffer-frame)
(read-string \"> \")"
echo ${STRING:1:$((${#STRING}-2))

But when he does, emacsclient never returns. So I tried using
unwind-protect to make sure that emacsclient always returns:

#!/bin/bash
STRING=$(emacsclient -e "\
(let ((emonad-client (car server-clients)))
  (select-frame-set-input-focus default-minibuffer-frame)
  (unwind-protect (read-string \"> \")
    (when (memq emonad-client server-clients)
      (server-delete-client emonad-client t))))")
echo ${STRING:1:$((${#STRING}-2))

Now my script always returns but fails to print the final form to
standard output even when input was NOT aborted.

I tried several things to work around this:

1. Store the return value of read-string in some variable, and using
the variable as last form of let. When I use (message "veni vedi %s"
tmp) as last form I can see that forms after unwind-protect are
actually evaluated, the last form's value is just never printed to
stout.
2. condition-case
3. catch

However in all cases nothing was printed to standard output. It seems
that as soon as some non-local exit is used emacsclient refuses to
print anything to stout. And since exit-minibuffer does (throw 'exit
nil) to abort minibuffer output there is now way to prevent such an
non-local exit.

As a workaround it might be possible to explicitly print to stout, but
I could not find any information on how to do that.

thx

Jonas




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#3634; Package emacs. (Sat, 07 Nov 2009 12:35:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonas Bernoulli <jonas <at> bernoul.li>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sat, 07 Nov 2009 12:35:04 GMT) Full text and rfc822 format available.

Message #10 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Jonas Bernoulli <jonas <at> bernoul.li>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#3634: emacsclient: unwind-protect prevents printing final 
	form
Date: Sat, 7 Nov 2009 13:28:44 +0100
ping

On Sun, Jun 21, 2009 at 02:43, Jonas Bernoulli <jonas <at> bernoul.li> wrote:
> Hi
>
> I am trying to write a wrapper around emacsclient that would allow
> emacs to be used by external applications to complete some string.
>
> However it does not seem to be possible to
> 1. return the last form and
> 2. ensure that emacsclient always returns
> at the same time.
>
> (The following examples assumes default-minibuffer-frame exists. Just
> remove the respective line if it doesn't.)
>
> This works as long as the user does not abort:
>
> #!/bin/bash
> STRING=$(emacsclient -e "\
> (select-frame-set-input-focus default-minibuffer-frame)
> (read-string \"> \")"
> echo ${STRING:1:$((${#STRING}-2))
>
> But when he does, emacsclient never returns. So I tried using
> unwind-protect to make sure that emacsclient always returns:
>
> #!/bin/bash
> STRING=$(emacsclient -e "\
> (let ((emonad-client (car server-clients)))
>  (select-frame-set-input-focus default-minibuffer-frame)
>  (unwind-protect (read-string \"> \")
>    (when (memq emonad-client server-clients)
>      (server-delete-client emonad-client t))))")
> echo ${STRING:1:$((${#STRING}-2))
>
> Now my script always returns but fails to print the final form to
> standard output even when input was NOT aborted.
>
> I tried several things to work around this:
>
> 1. Store the return value of read-string in some variable, and using
> the variable as last form of let. When I use (message "veni vedi %s"
> tmp) as last form I can see that forms after unwind-protect are
> actually evaluated, the last form's value is just never printed to
> stout.
> 2. condition-case
> 3. catch
>
> However in all cases nothing was printed to standard output. It seems
> that as soon as some non-local exit is used emacsclient refuses to
> print anything to stout. And since exit-minibuffer does (throw 'exit
> nil) to abort minibuffer output there is now way to prevent such an
> non-local exit.
>
> As a workaround it might be possible to explicitly print to stout, but
> I could not find any information on how to do that.
>
> thx
>
> Jonas
>
>
>
>
>




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#3634; Package emacs. (Sun, 08 Nov 2009 03:55:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> IRO.UMontreal.CA>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sun, 08 Nov 2009 03:55:05 GMT) Full text and rfc822 format available.

Message #15 received at 3634 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Jonas Bernoulli <jonas <at> bernoul.li>
Cc: 3634 <at> debbugs.gnu.org
Subject: Re: bug#3634: emacsclient: unwind-protect prevents printing final form
Date: Sat, 07 Nov 2009 22:50:15 -0500
>> But when he does, emacsclient never returns. So I tried using
>> unwind-protect to make sure that emacsclient always returns:

I'd expect that using condition-case to catch `quit' would work.
Have you tried it?


        Stefan



Added tag(s) moreinfo. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Tue, 26 Jan 2010 23:00:04 GMT) Full text and rfc822 format available.

Reply sent to Glenn Morris <rgm <at> gnu.org>:
You have taken responsibility. (Tue, 12 Jul 2011 23:08:02 GMT) Full text and rfc822 format available.

Notification sent to Jonas Bernoulli <jonas <at> bernoul.li>:
bug acknowledged by developer. (Tue, 12 Jul 2011 23:08:02 GMT) Full text and rfc822 format available.

Message #22 received at 3634-done <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: 3634-done <at> debbugs.gnu.org
Subject: Re: bug#3634: emacsclient: unwind-protect prevents printing final form
Date: Tue, 12 Jul 2011 19:07:08 -0400
Stefan Monnier wrote:

> I'd expect that using condition-case to catch `quit' would work.
> Have you tried it?

Works for me.

STRING=$(emacsclient -e "(condition-case nil (read-string \"> \") (quit nil))")




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 10 Aug 2011 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 316 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.