Re: [O] [PATCH] Respect buffer-local value of `org-edit-src-content-indentation'

2019-10-16 Thread Sebastian Miele
Hello Adam,

Adam Porter  writes:
> You might consider using the function buffer-local-value instead of the
> macro with-current-buffer.  Not that it matters so much here, but
> benchmarking shows that it is much faster when simply accessing the
> buffer-local value of a variable.

Thank you. Such information is always very welcome.

An updated patch is attached to this mail. I also added an ORG-NEWS
entry.

Best wishes
Sebastian

>From 34eb8882e09701aa12da40510a24c688f4a5ac20 Mon Sep 17 00:00:00 2001
From: Sebastian Miele 
Date: Wed, 9 Oct 2019 01:00:50 +
Subject: [PATCH] Respect buffer-local value of
 `org-edit-src-content-indentation'

* lisp/org-src.el (org-src--contents-for-write-back): Use the
potentially buffer-local value of `org-edit-src-content-indentation'
from the source buffer instead of that from the editing buffer.
---
 etc/ORG-NEWS| 4 
 lisp/org-src.el | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 0e07326cb..b562a0935 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -428,6 +428,10 @@ leave unfolded subtrees unfolded.
 I.e. treat the whole file as if it was a subtree.
 
 *** Respect narrowing when agenda command is restricted to buffer
+*** Respect buffer-local value of ~org-edit-src-content-indentation~
+
+Use the potentially buffer-local value of `org-edit-src-content-indentation'
+from the source buffer instead of that from the editing buffer.
 
 * Version 9.2
 ** Incompatible changes
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 9134d5b5d..99841c211 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -422,7 +422,8 @@ Assume point is in the corresponding edit buffer."
 (if org-src--preserve-indentation 0
   (+ (or org-src--block-indentation 0)
  (if (memq org-src--source-type '(example-block src-block))
- org-edit-src-content-indentation
+ (buffer-local-value 'org-edit-src-content-indentation
+ (marker-buffer org-src--beg-marker))
0
(use-tabs? (and (> org-src--tab-width 0) t))
(source-tab-width org-src--tab-width)
-- 
2.23.0



Re: [O] [PATCH] Add :eval only-manual to babel blocks

2019-10-16 Thread Ken Mankoff


On 2019-10-16 at 12:38 +02, Nicolas Goaziou  wrote...
> Of course, meawhile, do not rely on undefined behaviour :)

Would you accept a documentation patch that defines the current behavior?

Then I get what I want, and it is on future developers to not mess it up :).

  -k.




Re: [O] [PATCH] ox-html: add option to restore old src block behaviour?

2019-10-16 Thread Nicolas Goaziou
Hello,

Jens Lechtenboerger  writes:

> Thanks!  A patch is attached.

Applied. Thank you.

Regards,

-- 
Nicolas Goaziou



Re: [O] [PATCH] Add :eval only-manual to babel blocks

2019-10-16 Thread Nicolas Goaziou
Hello,

Ken Mankoff  writes:

> Can you provide a more obvious hint? :)

I don't have enough time to help you more on that, sorry. I didn't even
look closely to the issue you're encountering. Hopefully, someone else
on the ML can provide guidance on it.

> I've read the documentation on called-interactively-p but have not had
> success yet with that function. The bottom of that doc string suggests
> this is not an appropriate use for it.

Indeed.

> I've read the manual part on "Distinguish Interactive Calls"[1] but
> working through those examples I can't get deeper called functions to
> know if the nth-parent was called interactively or not.

IMO, this is what you shouldn't try to do: mess with the call stack.
This sounds like a wrong approach to the problem.

Regards,

-- 
Nicolas Goaziou



Re: [O] ipython integration fails

2019-10-16 Thread John Kitchin
I guess you are having a problem with the version of jupyter, and maybe
jupyter_client. Maybe upgrading thises will fix the ipython problem.

See notes below for python sessions.
Prof. Dr. Johanna May  writes:

> Hi everybody,
>
> I am creating lecture notes including some python snippets. Now, in
> order to teach jupyter notebook use I would like to include just the
> same code as in a python snippet in an ipython snippet.

If you get ipython working, then you can write your lectures in
org-mode, and use ox-ipynb from scimax to export a jupyter notebook from
the org-file.
>
> However ipython blocks don't work in my set up and I could not figure
> out which dependency or config line I might need to add in order to do
> this properly (and scimax also creates errors, but since I have my own
> config running I thought ipython might  already do the job).
>
> The ipython snippet I used is:
> #+BEGIN_SRC ipython :session :results raw drawer
>   %matplotlib inline
>   import matplotlib.pyplot as plt
>   import numpy as np
> #+END_SRC
>
> The error message is:
> Traceback (most recent call last):
>   File "/home/username/.emacs.d/elpa/ob-ipython-20180224.953/client.py", line 
> 60, in 
> c = create_client(args.conn_file)
>   File "/home/username/.emacs.d/elpa/ob-ipython-20180224.953/client.py", line 
> 43, in create_client
> cf = find_connection_file('emacs-' + name)
>   File "/usr/lib/python3.6/site-packages/jupyter_client/connect.py", line 
> 218, in find_connection_file
> raise IOError("Could not find %r in %r" % (filename, path))
> OSError: Could not find 'emacs-default' in ['.', '/run/user/1000/jupyter']
>
> Maybe I do not need ipython anyway. What works are python code snippets
> like the following one. Minted exports both, code and results and they
> are both displayed in the pdf slides/manuscript (using lualatex,
> beamerarticle etc.)
>
> #+begin_src python :results output :session :exports both
> import time
> time.sleep(3)
> #+end_src
>
> However, then, what does not work properly is several code blocks in one
> session, e.g.
>
> (1)
> #+begin_src python :results output :session :exports both
> import pandas as pd
> import numpy as np
> import matplotlib.pyplot as plt
> import datetime as dt
> import seaborn as sns
> sns.set(style="darkgrid")
> #+end_src
>
> (2)
> #+begin_src python :results output :session :exports both
> df = pd.read_csv('./household_data_1min_singleindex.csv')
> #+end_src
>
> (3)
> #+begin_src python :results output :session :exports both
> zeit=df.utc_timestamp.apply(lambda x: dt.datetime.strptime(x, 
> "%Y-%m-%dT%H:%M:%SZ"))
> #+end_src
>
> (4)
> #+begin_src python :results file :session :var 
> matplot_lib_filename=(org-babel-temp-file "figu" ".png"),fontsize=fs :exports 
> both
> plt.rcParams.update({'font.size':fontsize})
> rcParams.update({'figure.autolayout': True})
> plt.plot(zeit,df.DE_KN_residential2_washing_machine)
> plt.savefig(matplot_lib_filename)
> matplot_lib_filename
> #+end_src

To get this to work, I used

#+begin_src python :results output :session :exports both
import time
time.sleep(3)
#+end_src

#+RESULTS:
: Python 3.6.0 |Anaconda custom (x86_64)| (default, Dec 23 2016, 13:19:00)
: [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
: Type "help", "copyright", "credits" or "license" for more information.
: >>> python.el: native completion setup loaded

However, then, what does not work properly is several code blocks in one
session, e.g.

(1)
#+begin_src python :results output :session :exports both
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime as dt
import seaborn as sns
sns.set(style="darkgrid")
#+end_src

#+RESULTS:

(2)
#+begin_src python :results output :session :exports both
x = np.linspace(0, 1)
y = x**2
#+end_src

#+RESULTS:

(3)
#+begin_src python :results output :session :exports both
fontsize=12
#+end_src


(4)
#+begin_src python :results file :session :var 
matplot_lib_filename=(org-babel-temp-file "figu" ".png") :exports both
plt.rcParams.update({'font.size':fontsize})
plt.rcParams.update({'figure.autolayout': True})
plt.plot(x, y)
plt.savefig(matplot_lib_filename)
print(matplot_lib_filename)
#+end_src

5)

#+begin_src python :results file :session :var 
matplot_lib_filename=(org-babel-temp-file "figu" ".png") :exports both
plt.figure()
plt.rcParams.update({'font.size':fontsize})
plt.rcParams.update({'figure.autolayout': True})
plt.plot(x, 2 * x)
plt.savefig(matplot_lib_filename)
print(matplot_lib_filename)
#+end_src

which for me worked like I think you expect, which is your run each
block sequentially. There were some errors in your last block related to
the fontsize and rcParams that are different in my block. Probably I
have different defaults for the results (I always use output) so I
printed the results instead of using the returned value.
>
> I do not like the fact that plt.rcParams.update and other lines that
> jupyter does not need get exported - is there a simple way to 

Re: [O] [PATCH] Add :eval only-manual to babel blocks

2019-10-16 Thread Ken Mankoff
Hi Nicolas,

On 2019-10-16 at 12:38 +02, Nicolas Goaziou  wrote...
> Note that what you want, i.e., to distinguish behaviour depending on
> the location of the call stack is cheesy, at best. Think about macros,
> user-defined functions, etc.

Yes, it felt a bit hackish. But I'm new to this level of Org coding.

> The Emacs' answer to this is usually to check if call to a function is
> interactive, or not.

Can you provide a more obvious hint? :) I've read the documentation on 
called-interactively-p but have not had success yet with that function. The 
bottom of that doc string suggests this is not an appropriate use for it.

I've read the manual part on "Distinguish Interactive Calls"[1] but working 
through those examples I can't get deeper called functions to know if the 
nth-parent was called interactively or not.

Would you solve this issue somewhere completely different? Like an advice 
around the org-ctrl-c-ctrl-c function or something?

Thanks,

  -k.

[1] 
https://www.gnu.org/software/emacs/manual/html_node/elisp/Distinguish-Interactive.html



[O] ipython integration fails

2019-10-16 Thread Prof. Dr. Johanna May


Hi everybody,

I am creating lecture notes including some python snippets. Now, in
order to teach jupyter notebook use I would like to include just the
same code as in a python snippet in an ipython snippet.

However ipython blocks don't work in my set up and I could not figure
out which dependency or config line I might need to add in order to do
this properly (and scimax also creates errors, but since I have my own
config running I thought ipython might  already do the job).

The ipython snippet I used is:
#+BEGIN_SRC ipython :session :results raw drawer
  %matplotlib inline
  import matplotlib.pyplot as plt
  import numpy as np
#+END_SRC

The error message is:
Traceback (most recent call last):
  File "/home/username/.emacs.d/elpa/ob-ipython-20180224.953/client.py", line 
60, in 
c = create_client(args.conn_file)
  File "/home/username/.emacs.d/elpa/ob-ipython-20180224.953/client.py", line 
43, in create_client
cf = find_connection_file('emacs-' + name)
  File "/usr/lib/python3.6/site-packages/jupyter_client/connect.py", line 218, 
in find_connection_file
raise IOError("Could not find %r in %r" % (filename, path))
OSError: Could not find 'emacs-default' in ['.', '/run/user/1000/jupyter']

Maybe I do not need ipython anyway. What works are python code snippets
like the following one. Minted exports both, code and results and they
are both displayed in the pdf slides/manuscript (using lualatex,
beamerarticle etc.)

#+begin_src python :results output :session :exports both
import time
time.sleep(3)
#+end_src

However, then, what does not work properly is several code blocks in one
session, e.g.

(1)
#+begin_src python :results output :session :exports both
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime as dt
import seaborn as sns
sns.set(style="darkgrid")
#+end_src

(2)
#+begin_src python :results output :session :exports both
df = pd.read_csv('./household_data_1min_singleindex.csv')
#+end_src

(3)
#+begin_src python :results output :session :exports both
zeit=df.utc_timestamp.apply(lambda x: dt.datetime.strptime(x, 
"%Y-%m-%dT%H:%M:%SZ"))
#+end_src

(4)
#+begin_src python :results file :session :var 
matplot_lib_filename=(org-babel-temp-file "figu" ".png"),fontsize=fs :exports 
both
plt.rcParams.update({'font.size':fontsize})
rcParams.update({'figure.autolayout': True})
plt.plot(zeit,df.DE_KN_residential2_washing_machine)
plt.savefig(matplot_lib_filename)
matplot_lib_filename
#+end_src

I do not like the fact that plt.rcParams.update and other lines that
jupyter does not need get exported - is there a simple way to exclude
certain lines from export?

And I do get in serious trouble when I add a second data set (another csv) and 
do
further analysis steps - all graphics then look the same and bad and do
not represent the actual result of the code block. It seems that all get
the same wrong name and then at each graphics location this same png
gets displayed. 

So, maybe there is a good tutorial on using sessions in ob-python or
some other hint that I could use?

Is there a way to restart the (python) kernel with some header message
in the src block?

Thank you very much,

Cheers,

J. May



Re: [O] [PATCH] Add :eval only-manual to babel blocks

2019-10-16 Thread Nicolas Goaziou
Hello,

Ken Mankoff  writes:

> Hmm. So it turns out (I think) this patch isn't necessary. The
> behavior I wanted and thought I implemented is actually the default
> behavior! I think the behavior is undefined for :eval not equal to
> "yes", "no", or "query", but the current undefined implementation does
> what I want.

Note that what you want, i.e., to distinguish behaviour depending on the
location of the call stack is cheesy, at best. Think about macros,
user-defined functions, etc.

The Emacs' answer to this is usually to check if call to a function is
interactive, or not.

So, if you want to implement it properly, you may want to look into that
direction.

Of course, meawhile, do not rely on undefined behaviour :)

Regards,

-- 
Nicolas Goaziou



Re: [O] [RFC] Document level property drawer

2019-10-16 Thread Marco Wahl
Gustav Wikström  writes:

> I'd like to take the next step with this patch. I'm hesitant to do it
> without wider support though, since only a few people have commented.
>
> @Marco Wahl; As I understand you've applied the patch and tried it
> out. Have you found any issues yet? What do you think of the patch
> after having used it for a while?

Indeed I applied your patch and have it applied still.  Please note that
I did nothing fancy and in particular I did not try to break the patch.

The patch works good for me.

Noteworthy observations AFAICT:

1. I could not translate my personal "#+TODO: . N ~ | x c g >" into a
respective :TODO: property.

2. With org-ids turned on and point before the first heading, function
org-store-link creates an org-id property at the document level.

Regarding number 1. I think a list of document-level properties which
don't behave the same when used in the document property drawer would be
nice.  Ideally this list is empty AFAICT.  Maybe I overlook something.
Is this an issue?

I think observation 2. is just a little surprise but turns out to be
natural when the document level property drawer is enabled.


Still +1 for the inclusion of the patch and HTH,
-- 
Marco





Re: [O] Inject value of macro into code using a variable

2019-10-16 Thread Fraga, Eric
On Tuesday, 15 Oct 2019 at 09:37, wlharvey4 via Emacs-orgmode wrote:
> Is it possible to inject the value of a macro into code using a variable?

I use properties for this, as in:

#+begin_src org
  ,#+property: version 2.0.5
  ,#+header: :var version=(esf/get-parameter "benzenefeed")
  [...]
  ,#+begin_src somelanguage
  [... code that uses version ...]
  ,#+end_src
#+end_src

where
#+begin_src emacs-lisp
  (defun esf/get-parameter (p)
(let ((value (org-entry-get (point) p 'inherit)))
  (message "parameter %s value obtained %s" p value)
  (if value
  (if (string-match-p "^[-+ ]*[[:digit:].]+$" value)
  (string-to-number value)
value)
(error "Property parameter \"%s\" not known." p
#+end_src 

-- 
Eric S Fraga via Emacs 27.0.50, Org release_9.2.6-552-g8c5a78



Re: [O] [PATCH] Add :eval only-manual to babel blocks

2019-10-16 Thread Ken Mankoff


On 2019-10-14 at 09:10 +02, Ken Mankoff  wrote...
> With this patch and ":eval only-manual" in a babel header,
>
> Org evaluates the source code if it is run via ~org-ctrl-c-ctrl-c~
> (e.g. =C-c C-c= in the babel block), but not if run via the
> ~org-babel-execute-buffer~ function.

Hmm. So it turns out (I think) this patch isn't necessary. The behavior I 
wanted and thought I implemented is actually the default behavior! I think the 
behavior is undefined for :eval not equal to "yes", "no", or "query", but the 
current undefined implementation does what I want.

  -k.