Re: [O] strange behavior with org-babel python

2015-05-11 Thread Puneeth Chaganti
On Tue, May 12, 2015 at 6:37 AM, Doyley, Marvin M.
 wrote:
> Hi there,
>
> If run the follow codes I get the following, could someone explain to me what 
> is going wrong
[snip]
> PS in .emacs, I have (setq org-babel-python-command "ipython --no-banner 
> --classic --no-confirm-exit")

To reliably paste code blocks into IPython, you will have to use
%cpaste magic command.  See any of these links[1][2][3] for code you
can reuse.

[1] - 
https://github.com/punchagan/dot-emacs/blob/master/punchagan.org#python-customizations
[2] - https://lists.gnu.org/archive/html/emacs-orgmode/2014-03/msg00405.html
[3] - 
http://emacs.stackexchange.com/questions/3859/working-setup-for-ipython-in-babel

Hope that helps,
Puneeth



[O] strange behavior with org-babel python

2015-05-11 Thread Doyley, Marvin M.
Hi there,

If run the follow codes I get the following, could someone explain to me what 
is going wrong

(1) The desired results
#+BEGIN_SRC python :results output :exports both :session
x=5
def foo(x):
if x>0:
return x+1
else:
return x-1

print(foo(x))
#+END_SRC

#+RESULTS:
: 6

(2) No results
#+BEGIN_SRC python :results output raw :exports both 

x=5
if x>0:
x= x+1
else:
x= x-1
print(x)
#+END_SRC

#+RESULTS:


(3) Not sure, why I get this error
#+BEGIN_SRC python :results output raw :exports both :session

x=5
if x>0:
x= x+1
else:
x= x-1
print(x)
#+END_SRC

#+RESULTS:

>>> >>> >>> >>> ... ...   File "", line 3
else:
 ^
IndentationError: unindent does not match any outer indentation level

If you want to paste code into IPython, try the %paste and %cpaste magic 
functions.

Thanks,
M

PS in .emacs, I have (setq org-babel-python-command "ipython --no-banner 
--classic --no-confirm-exit")




[O] Capturing file name from python session when using matplotlib

2015-05-11 Thread Dror Atariah
* Capturing filename

I would like to use (babel) orgmode as an interactive python
notebook. Therefore, in order to allow the various code blocks to
"know" each other, it is important to use the ~:session~
option. However, once ~:session~ is used, together with ~matplotlib~
the desired behavior is no longer in place.

* Clean testing, no Matplotlib
For the sake of testing, the following merely suppose to return the filename

#+BEGIN_SRC python :session no_matplotlib :results file :exports both
x = 'hello '
y = 'world'
z = x + y
'foo.bar'
#+END_SRC

#+RESULTS:
[[file:foo.bar]]

*Passed* Indeed, the ~RESULTS~ block contains a link to the filename
indicated by the last string.

* Importing Matplotlib

The following minimal example should generate a simple figure,
~myfig.png~, and orgmode should capture it and interpret it as a
filename to be used by the following ~RESULTS~ block.

#+BEGIN_SRC python :session with_matplotlib :results file
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(3,2))
plt.plot([1,3,2])
plt.savefig('myfig.png')
'myfig.png'
#+END_SRC

#+RESULTS:
[[file:]]

*Failed!* This time, it doesn't work anymore. The file ~myfig.png~ is
 properly generated, but the last string is not captured by
 ~matplotlib~. Following is the content of the corresponding
 interactive python session:

#+BEGIN_SRC
Python 3.4.3 (default, Feb 27 2015, 00:22:26)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> >>> >>> ,
'''/var/folders/kz/1c2cxn1x60n_t5p2j1p02b18gn/T/py27084Z6S''', 'exec'));
import matplotlib
import matplotlib
matplotlib.use('Agg')
>>> matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(3,2))
fig=plt.figure(figsize=(3,2))
plt.plot([1,3,2])
plt.plot([1,3,2])
plt.savefig('myfig.png')
plt.savefig('myfig.png')
'myfig.png'
'myfig.png'


open('/var/folders/kz/1c2cxn1x60n_t5p2j1p02b18gn/T/babel-2708423D/python-27084mEZ',
'w').write(str(_))
open('/var/folders/kz/1c2cxn1x60n_t5p2j1p02b18gn/T/babel-2708423D/python-27084mEZ',
'w').write(str(_))




'org_babel_python_eoe'
'org_babel_python_eoe'
>>> >>> >>> >>> []
>>> 'myfig.png'
>>> >>> 9
>>> >>> >>> 'org_babel_python_eoe'
>>>
#+END_SRC

* Some background

** Python Version
#+BEGIN_SRC python :session background :results output
import sys
sys.version
#+END_SRC

#+RESULTS:
: import sys
: >>> sys.version
: '3.4.3 (default, Feb 27 2015, 00:22:26) \n[GCC 4.2.1 Compatible Apple
LLVM 6.0 (clang-600.0.56)]'
: sys.executable
: '/Users/drorata/py-envs/generic3.4/bin/python'
:
:

** System
I am running Emacs version ~GNU Emacs 24.4.51.1 (x86_64-apple-darwin14.1.0,
NS apple-appkit-1344.72) of 2015-02-02 on boxname.local~

The orgmode version is: ~Org-mode version 8.2.10
(8.2.10-40-gc763fa-elpaplus @
/Users/username/.emacs.d/elpa/org-plus-contrib-20150504/)~

** Stackoverflow reference
I also posted a question in the SE network:
[[
http://emacs.stackexchange.com/questions/11075/org-mode-python-session-does-not-return-a-file-name
]]

* Question
So, my question is how to tackle/debug this issue? Can someone give me
a hand here? That would be really great! Thanks!

-- 
Dror Atariah, Ph.D.
de.linkedin.com/in/atariah


[O] Inaccurate documentation for org-metaleft?

2015-05-11 Thread Alain . Cochard

Sorry if I am totally confused, I am an org beginner. 

If I do 'C-h f org-metaleft', I see

   org-metaleft is an interactive compiled Lisp function in `org.el'.
   (org-metaleft &optional ARG)
   Promote heading or move table column to left.
   Calls `org-do-promote' or `org-table-move-column', depending on context.
   With no specific context, calls the Emacs default `backward-word'.
   See the individual commands for more information.

However, if I look at the code, it seems to me that it does other
things, at least org-outdent-item.  Experimenting a bit with
org-metaleft and org-outdent-item seems to confirm this feeling.

The doc for org-metaright

   org-metaright is an interactive compiled Lisp function in `org.el'.
   (org-metaright &optional ARG)
   Demote a subtree, a list item or move table column to right.
   In front of a drawer or a block keyword, indent it correctly.
   With no specific context, calls the Emacs default `forward-word'.
   See the individual commands for more information.

is more accurate with respect to list items, but one would expect it
to say "Calls `org-do-demote' etc."



-- 
EOST (École et Observatoire des Sciences de la Terre) 
IPG (Institut de Physique du Globe) | alain.coch...@unistra.fr
5 rue René Descartes   [bureau 106] | Phone: +33 (0)3 68 85 50 44 
F-67084 Strasbourg Cedex, France| Fax:   +33 (0)3 68 85 01 25 


Re: [O] bug:? org babel updating images (C-c C-c) triggers "show as text" (C-c C-c) in imagemagick buffer.

2015-05-11 Thread Leo Ufimtsev


- Original Message -
> From: "Sebastien Vauban" 
> To: emacs-orgmode@gnu.org
> Sent: Sunday, May 10, 2015 4:37:39 PM
> Subject: Re: [O] bug:? org babel updating images (C-c C-c) triggers "show as  
> text" (C-c C-c) in imagemagick buffer.
> 
> Eric S Fraga wrote:
> > On Friday,  8 May 2015 at 15:22, Leo Ufimtsev wrote:
> >> I use org-babel to make graphviz diagrams in my notes.
> >>
> >> I open resulting images in the side panel via C-u C-c C-o (or right-click
> >> image).
> >> (See 20 screen shot)
> >>
> >> Now it shows the image fine at first.
> >>
> >> Then I run org-babel in the text buffer (on the left) to update the image
> >> on disk (C-c C-c).
> >> But for some reason, this also calls 'show as text' 'C-c C-c'
> >> (image-toggle-display) in the side panel and causes the image to look
> >> like bits of text.
> >>
> >> I then have to constantly go to the side panel to return it back to image.
> >> (C-c C-c).
> >>
> >> Sometimes I it happens after the 2nd update of the image. But eventually
> >> I'll see text.
> >
> > this happens to me all the time so it's nothing unique in your
> > configuration.  I also find it very annoying and would love to see a
> > solution.
> 
> IIUC, you should retrain yourselves to use other key bindings than the
> "do-it-all" C-c C-c.
> 
> For executing code, that's C-c C-v C-e (or e on the beginning of the
> code block -- speed key).

Thank you for the suggestion.

Unfortunately the C-c C-v C-e produces the same effect. 

It seems there's something else going on there :-/

Hmmm.

> For images, that's C-c C-x C-v.
> 
> In fact, I never use C-c C-c in Org. I've even customized:
> 
>   (setq org-babel-no-eval-on-ctrl-c-ctrl-c t)
> 
> to be sure to unlearn C-c C-c.
> 
> Best regards,
>   Seb
> 
> --
> Sebastien Vauban
> 
> 
> 

-- 
Leo Ufimtsev | Intern Software Engineer @ Eclipse Team



[O] Bug: org-set-tags duplicates tags in org-tag-persistent-alist

2015-05-11 Thread Paul Rankin
When setting org-tag-alist or org-tag-persistent-alist, calling org-set-tags or 
org-agenda-set-tags will populate select with both alist tags and any tags from 
tagged subheadings.

To reproduce:

$ cat tmp.org
* TODO task:tag1:
$ emacs -Q

(setq org-tag-persistent-alist
  '(("tag1" . ?1)
("tag2" . ?2)))

M-x eval-last sexp
M-x find-file RET tmp.org
M-x org-set-tags

Inherited:
Current:tag1

  [1] tag1   [2] tag2   [t] tag1

"tag1" is duplicated.

This also occurs if tmp.org is added to agenda and org-agenda-set-tags is 
called, however this bug *compounds* with each additional agenda file 
containing tagged subheadings, e.g. if org-agenda-files contains five org 
files, each with subheadings tagged :work: then org-agenda-set-tags will 
populate with six :work: selections (org-tag-persistent-alist plus each 
additional file).

This bug appears to have been first reported back in 2012 but not investigated:
https://lists.gnu.org/archive/html/emacs-orgmode/2012-12/msg00470.html

GNU Emacs 24.5.1 (x86_64-apple-darwin14.3.0, NS apple-appkit-1347.57) of 
2015-04-21 on Pauls-MacBook-Pro.local
Org-mode version 8.2.10 (8.2.10-40-gc763fa-elpa @ 
/Users/Paul/.emacs.d/elpa/org-20150504/)




Re: [O] bug:? org babel updating images (C-c C-c) triggers "show as text" (C-c C-c) in imagemagick buffer.

2015-05-11 Thread Eric S Fraga
On Sunday, 10 May 2015 at 22:37, Sebastien Vauban wrote:

[...]

> IIUC, you should retrain yourselves to use other key bindings than the
> "do-it-all" C-c C-c.

No, this has nothing to do with C-c C-c in org.  It has to do with what
Emacs does with image buffers so is potentially a little off-topic.

If you have an image that is being viewed in a separate buffer, not an
org buffer, and if that image gets updated by, for instance, executing
an org babel src block, sometimes (in my case almost always), the update
of the image in the image buffer shows text instead of the image.

In the image buffer, C-c C-c will toggle display of image or text but
one shouldn't have to do that.
-- 
: Eric S Fraga (0xFFFCF67D), Emacs 24.4.1, Org release_8.3beta-820-gd92ef9



[O] Correct way to insert results

2015-05-11 Thread Alex Bennée
Hi,

I'm working on adding async call functionality to org-babel blocks so I
don't need to block my main Emacs for long running calculations. However
I'm having problems with the insertion of the results once handled. My
code looks like this:

(defmacro async-org-call (async-form)
  "Expands `ASYNC-FORM' as an asynchronus org-bable function.
If executed inside an org file will insert the results into the src
  blocks results.  Otherwise the result will be echoed to the Message
  buffer."

  (let ((result-buffer (buffer-name))
(result-org-name (nth 4 (org-babel-get-src-block-info

`(async-start

  ;; The result of the async-sexp is returned to the handler
  ;; as result.
  (lambda ()
,(async-inject-variables "async-form")
(eval async-form))

  ;; This code runs in the current emacs process.
  (lambda (result)
(let ((buf ,result-buffer)
  (org ,result-org-name))
  
  ;; Send the results somewhere
  (if (and buf org)
  (save-excursion
(with-current-buffer buf
  (org-babel-goto-named-result org)
  (org-babel-insert-result (format "%s" result
(message (pp (format "async-result: %s" result)

However the insert result seems to keep skipping the named result I'm
aiming for (I was calling basic-async-test, the results end up after
async-with-delay in a fresh RESULTS: drawer):

** Basic async

#+name: basic-async-test
#+begin_src emacs-lisp 
(async-org-call (format "this is in inferior"))
#+end_src

#+RESULTS: basic-async-test
: #

#+name: async-with-delay
#+begin_src emacs-lisp 
(async-org-call ((sleep-for 3) (format "woken up")))
#+end_src

#+RESULTS:
=this is in inferior
=: this is in inferior

#+RESULTS: async-with-delay
: #

Any idea how I can do this better?


-- 
Alex Bennée