emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Eric Schulte" <schulte.eric@gmail.com>
To: Erik Iverson <eriki@ccbr.umn.edu>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: [babel] writing my .Rprofile in orgmode, issue with emacsclient
Date: Fri, 04 Jun 2010 12:29:19 -0600	[thread overview]
Message-ID: <87iq5yy7ls.fsf@gmail.com> (raw)
In-Reply-To: <4C05E841.7070003@ccbr.umn.edu> (Erik Iverson's message of "Wed, 02 Jun 2010 00:12:33 -0500")

[-- Attachment #1: Type: text/plain, Size: 137 bytes --]

Hi Erik,

This is an interesting problem.  The simplest setup I was able to use to
reproduce the issue was the following org-mode file,


[-- Attachment #2: babel-call-test.org --]
[-- Type: text/plain, Size: 134 bytes --]

* babel call test
Test calling Emacs from within a babel code block.

#+begin_src sh :results output
  ./babel-call-test.sh
#+end_src

[-- Attachment #3: Type: text/plain, Size: 41 bytes --]


which calls the following shell script


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: babel-call-test.sh --]
[-- Type: text/x-sh, Size: 262 bytes --]

#!/bin/sh
# babel-call-test.sh -- for testing calling emacs from inside of a babel code block

EMACSCMD="/home/eschulte/src/emacs/lib-src/emacsclient"
# EMACSCMD="/home/eschulte/src/emacs/src/emacs --batch -Q"

$EMACSCMD --eval "(message \"number %d\" (+ 1 2))"

[-- Attachment #5: Type: text/plain, Size: 4892 bytes --]


When the `emacs' command is used, then everything works as expected, and
the following

  #+results:
  : number 3

is inserted into the org-mode buffer, however when `emcasclient' is used
the call hangs forever.

At first this was puzzling, but it makes perfect sense, when org-babel
executes a source block, it does so in a synchronous blocking manner,
meaning that all of Emacs waits until the command returns before doing
anything, emacs "blocks" on the external call.  When the external
command wants to talk to Emacs, the external command waits on Emacs,
which is itself waiting on the external command -- and everyone waits
forever.

The only solutions here are the one you've found (which I'm honestly
surprised even works), for org-babel to implement non-blocking calls to
external processes (which may happen in the future, but not the
immediate future), or for Emacs to become multi-threaded (also only in
some possible non-immediate futures).

Thanks for pointing out this issue.  Please let me know if any of the
above doesn't make sense.

Best -- Eric

Erik Iverson <eriki@ccbr.umn.edu> writes:

> Hello,
>
> In the spirit of the examples of writing your .emacs file in orgmode,
> I wrote my .Rprofile (R's startup file) in orgmode.  I do have one
> issue where I have no idea what is going wrong, and would appreciate
> any information!
>
> Basic setup, GNU Emacs 23.1, latest git org-mode, running on Linux.  I
> start emacs with emacs --daemon on startup, and always just use
> emacsclient to do everything.  So for my org-mode .Rprofile,
>
> 1) I create a ~/.Rprofile.org file that uses org-mode syntax and
> includes all R code in R source blocks that will be tangled into a
> .Rprofile.R file.
>
> 2) In my actual .Rprofile, I have the following, which actually works.
> The basic idea was taken from
> http://orgmode.org/worg/org-contrib/babel/reference.php#sec-6 .  I
> simply want to tangle the .Rprofile.org file from (1) above into
> .Rprofile.R and source it. I know the lisp isn't as simple as it could
> be, since I adapted it from the more complex setup referenced, but
> this actually works for me.
>
> #BEGIN .Rprofile
> invisible(system("emacsclient -t --eval \"(progn
> (add-to-list 'load-path (expand-file-name \\\"~/lisp/org-mode/lisp/\\\"))
> (add-to-list 'load-path (expand-file-name \\\"~/lisp/org-mode/contrib/lisp/\\\"))
> (require 'org)(require 'org-exp)(require 'org-babel)
> (mapc (lambda (file)
>        (find-file (expand-file-name file \\\"/home/erik\\\"))
>        (org-babel-tangle)) '(\\\".Rprofile.org\\\")))\"", intern =
> TRUE, ignore.stderr = TRUE))
>
> source("~/.Rprofile.R")
> #END .Rprofile
>
> Then I do 'M-x R' in emacs, and R tangles the org-mode file, sources
> the result, and everything works.  This even works without the '-t'
> option given above to emacsclient.
>
> The problem is when I try to C-c C-c on an R source block in an
> org-mode file. My issue is, that *without* the '-t' option to
> emacsclient, (-t says it "opens a new emacs frame on the current
> terminal"), org-babel-execute-src-block hangs when I press C-c C-c in
> an R code block using the above setup.  It definitely relates to the
> emacsclient call in my .Rprofile,  because I can simply comment that
> system call out of my .Rprofile and all is well.  If I use :session,
> everything is fine.
>
> The best lead I have is that if I change org-babel-R-evaluate in the
> following way, my setup also works without the -t option:
>
> Give the R call in the following line
>
> (point-min) (point-max) "R --no-save" nil 'replace (current-buffer)))
>
> the --vanilla option.  Obviously this just doesn't run my problematic
> .Rprofile, but the point is that this is the exact location in the
> chain of calls where it's getting 'stuck'.  Emacs just hangs with the
> busy' mouse cursor until I C-g.
>
> If I watch the system process list, the R process does get started,
> and a new (2nd) instance of emacsclient is also started, but it
> doesn't return.
>
> Like I said, I have 'fixed' this with -t, but I really want to know
> why it wasn't working in the first place, and if this is really a fix.
> Notice how I have to also ignore.stderr = TRUE in my 'system' R call,
> because if I don't, all my org-babel output contains
>
> #+results:
> : emacsclient: could not get terminal name
> ...further output...
>
> if my source block has :results output as opposed to :results value.
>
> I just don't get why my setup works with M-x R but not with
> org-babel-execute-src-block, there is some interaction between those
> two and I can't see what it is.
>
> Sorry for the long post, I hope my question makes sense!
>
> Best Regards,
> Erik Iverson
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

[-- Attachment #6: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

      reply	other threads:[~2010-06-04 18:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-02  5:12 [babel] writing my .Rprofile in orgmode, issue with emacsclient Erik Iverson
2010-06-04 18:29 ` Eric Schulte [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87iq5yy7ls.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=eriki@ccbr.umn.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).