unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#3634: emacsclient: unwind-protect prevents printing final form
@ 2009-06-21  1:43 Jonas Bernoulli
  2009-11-07 12:28 ` Jonas Bernoulli
  0 siblings, 1 reply; 4+ messages in thread
From: Jonas Bernoulli @ 2009-06-21  1:43 UTC (permalink / raw)
  To: bug-gnu-emacs

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






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

* bug#3634: emacsclient: unwind-protect prevents printing final form
  2009-06-21  1:43 bug#3634: emacsclient: unwind-protect prevents printing final form Jonas Bernoulli
@ 2009-11-07 12:28 ` Jonas Bernoulli
  2009-11-08  3:50   ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Jonas Bernoulli @ 2009-11-07 12:28 UTC (permalink / raw)
  To: bug-gnu-emacs

ping

On Sun, Jun 21, 2009 at 02:43, Jonas Bernoulli <jonas@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
>
>
>
>
>






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

* bug#3634: emacsclient: unwind-protect prevents printing final form
  2009-11-07 12:28 ` Jonas Bernoulli
@ 2009-11-08  3:50   ` Stefan Monnier
  2011-07-12 23:07     ` Glenn Morris
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2009-11-08  3:50 UTC (permalink / raw)
  To: Jonas Bernoulli; +Cc: 3634

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





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

* bug#3634: emacsclient: unwind-protect prevents printing final form
  2009-11-08  3:50   ` Stefan Monnier
@ 2011-07-12 23:07     ` Glenn Morris
  0 siblings, 0 replies; 4+ messages in thread
From: Glenn Morris @ 2011-07-12 23:07 UTC (permalink / raw)
  To: 3634-done

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





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

end of thread, other threads:[~2011-07-12 23:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-21  1:43 bug#3634: emacsclient: unwind-protect prevents printing final form Jonas Bernoulli
2009-11-07 12:28 ` Jonas Bernoulli
2009-11-08  3:50   ` Stefan Monnier
2011-07-12 23:07     ` Glenn Morris

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