* :noweb from external file
[not found] <mailman.109.1498147218.16109.emacs-orgmode@gnu.org>
@ 2017-06-22 22:08 ` edgar
2017-06-24 6:03 ` edgar
0 siblings, 1 reply; 4+ messages in thread
From: edgar @ 2017-06-22 22:08 UTC (permalink / raw)
To: emacs-orgmode
Hello,
I would like to know if someone knows how I can achieve something
like this (importing a block of code from another file):
Definition of the original code:
../dir1/file1.org
==============================
#+NAME: py-numpy
#+CAPTION: Loading Numpy and Matplotlib onto Python.
#+BEGIN_SRC python :results none
import numpy as np
from matplotlib import pyplot as pl
#+END_SRC
==============================
I would like something like this:
../dir2/file2.org
==============================
#+NAME: py-noweb
#+CAPTION: Loading Numpy and Matplotlib onto Python.
#+BEGIN_SRC python :results none :noweb yes
<<../dir1/file1.org::py-numpy>>
#+END_SRC
==============================
Right now, I can only do it like this:
../dir2/file3.org
==============================
#+INCLUDE: ../dir1/file1.org::py-numpy
#+NAME: py-noweb
#+CAPTION: Loading Numpy and Matplotlib onto Python.
#+BEGIN_SRC python :results none :noweb yes
<<py-numpy>>
#+END_SRC
==============================
I know that there is Library of Babel, but I don't know
how to use it (I installed it through ELPA). The documentation
mentions a ~doc~ directory, but I don't have such a directory in
~/.emacs.d/elpa/org-*/. Besides, it may be that I don't always
want to store my functions in the library.
Thanks!
-------------------------------------------------
ONLY AT VFEmail! - Use our Metadata Mitigator to keep your email out of the NSA's hands!
$24.95 ONETIME Lifetime accounts with Privacy Features!
15GB disk! No bandwidth quotas!
Commercial and Bulk Mail Options!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: :noweb from external file
2017-06-22 22:08 ` :noweb from external file edgar
@ 2017-06-24 6:03 ` edgar
2017-07-01 6:53 ` edgar
0 siblings, 1 reply; 4+ messages in thread
From: edgar @ 2017-06-24 6:03 UTC (permalink / raw)
To: emacs-orgmode
On 2017-06-22 22:08, edgar@openmail.cc wrote:
> Right now, I can only do it like this:
>
> ../dir2/file3.org
> ==============================
> #+INCLUDE: ../dir1/file1.org::py-numpy
> #+NAME: py-noweb
> #+CAPTION: Loading Numpy and Matplotlib onto Python.
> #+BEGIN_SRC python :results none :noweb yes
> <<py-numpy>>
> #+END_SRC
> ==============================
>
I'm sorry. This is not working either. I am not trying to waste your
time, I promise: it was working at some point.
Thanks again.
-------------------------------------------------
ONLY AT VFEmail! - Use our Metadata Mitigator to keep your email out of the NSA's hands!
$24.95 ONETIME Lifetime accounts with Privacy Features!
15GB disk! No bandwidth quotas!
Commercial and Bulk Mail Options!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: :noweb from external file
2017-06-24 6:03 ` edgar
@ 2017-07-01 6:53 ` edgar
2017-07-01 7:36 ` edgar
0 siblings, 1 reply; 4+ messages in thread
From: edgar @ 2017-07-01 6:53 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1829 bytes --]
On 2017-06-24 06:03, edgar@openmail.cc wrote:
> On 2017-06-22 22:08, edgar@openmail.cc wrote:
>
>> Right now, I can only do it like this:
>>
>> ../dir2/file3.org
>> ==============================
>> #+INCLUDE: ../dir1/file1.org::py-numpy
>> #+NAME: py-noweb
>> #+CAPTION: Loading Numpy and Matplotlib onto Python.
>> #+BEGIN_SRC python :results none :noweb yes
>> <<py-numpy>>
>> #+END_SRC
>> ==============================
>>
>
> I'm sorry. This is not working either. I am not trying to waste your
> time, I promise: it was working at some point.
>
> Thanks again.
* Contribution: Script to convert directory with source to an org-file
So, by now, everybody knows that I don't understand squat about lisp.
Yet, I created a little bash script (for which there may be an
alternative already) to convert a directory with source files (in
Python) to source blocks within an Org file. It should be easily
adaptable to other languages. I hope that it is useful to someone. See
attachment.
* Question
The reason for which I reply to this thread is that it can serve in the
case that one wishes to use (org-babel-lob-ingest "path/to/file.org"). I
would like to know if loading such a file every time I start Emacs (with
my init file) will slow the startup. Thanks, and sorry if it is a stupid
question.
* Request (or how to, if exists)
Does anybody know how to achieve this?:
- inherit fill-column When C-c ' to edit source
it would be nice if the new temporary buffer
had the same fill-column as the one that
spawns it
Thanks for this too.
-------------------------------------------------
ONLY AT VFEmail! - Use our Metadata Mitigator to keep your email out of the NSA's hands!
$24.95 ONETIME Lifetime accounts with Privacy Features!
15GB disk! No bandwidth quotas!
Commercial and Bulk Mail Options!
[-- Attachment #2: dir-to-org-babel.org --]
[-- Type: text/plain, Size: 3428 bytes --]
This code helps to convert a directory with Python
files into an org-mode file with code
blocks. Change the value of :dir if you want
another path. Do ~C-c C-c~ or ~C-c C-v C-e~
(~org-babel-execute-maybe~) on the next block. It
will (hopefully) generate a file named
*code-blocks.org* which you could (possibly) use to
load into the Library of Babel by doing
~M-:(org-babel-lob-ingest "path/to/file.org")~
#+HEADER: :results none
#+BEGIN_SRC bash :dir ./
#!/bin/bash
# * Set a general configuration
cat << EOF > code-blocks.org;
All my functions are in this file. If you want
to create individual files, run
~M-x org-babel-tangle~.
Make sure that there is a directory for each heading.
,* License
EOF
cat LICENSE.txt >> code-blocks.org
cat <<EOF >> code-blocks.org
,* Configuration :noexport:ARCHIVE:
When exporting, print table of contents,
author and date
,#+OPTIONS: toc:t author:t date:t
When opening this file, visually indent lines
according to headers
,#+STARTUP: indent hidestars
By default, set Python blocks to run with Python 3,
do not evaluate when exporting (quick) and work
in a dedicated session.
,#+PROPERTY: header-args:python ":python python3 :eval no-export :session
EOF
printf "* Code to generate this file\n" >> code-blocks.org;
cat dir-to-org-babel.org >> code-blocks.org;
printf "\n" >> code-blocks.org;
# * Loop over the contents of the current
# directory (having two nested while IFS... seemed
# too much, but may be a more efficient way)
for dir in *; do
# ** Make sure that we will look into directories
if [[ -d "$dir" ]] && [[ ! "$dir" =~ "Moose" ]]; then
# *** Make the name of the sub-dir a heading
printf "* $dir\n";
# ** Loop over the files of the current sub-dir
# https://stackoverflow.com/a/301059 this
# is safe (requires that ~find~ can use
# ~-print0~)
while IFS= read -r -d '' file; do
# *** Print file only if it has code
# **** Get number of lines with awk
numl=$(awk 'END{print NR}')
if [[ "$numl" -gt 0 ]]; then
# *** Print the file names (in quotation
# format; with spaces like \ )
printf '** %q\n' "${file##./}" |
sed "s-$dir/--";
# *** Print a name for the block,
# substitute slashes with dashes,
# remove ./
# **** Create prototype for name
a=py-$(printf "$file" |
sed 's_\./__g; s_/_-_g')
# **** Print name header
printf "#+NAME: $a\n"
# *** Print a caption for the block
# (use same prototype as the name)
printf "#+CAPTION: $a\n";
# *** Print start of the block
printf "#+BEGIN_SRC python :tangle $file\n";
cat "$file";
# *** Print end of block
printf "#+END_SRC\n\n";
else
printf "\n";
fi;
done < <(# **** List all files that end with .py
find ./"$dir" -mindepth 1\
-type f -iname '*.py' -print0)
fi;
# ** Export everything that is printed to a file
done >> code-blocks.org
#+END_SRC
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: :noweb from external file
2017-07-01 6:53 ` edgar
@ 2017-07-01 7:36 ` edgar
0 siblings, 0 replies; 4+ messages in thread
From: edgar @ 2017-07-01 7:36 UTC (permalink / raw)
To: emacs-orgmode
On 2017-07-01 06:53, edgar@openmail.cc wrote:
> * Contribution: Script to convert directory with source to an org-file
> So, by now, everybody knows that I don't understand squat about lisp.
> Yet, I created a little bash script (for which there may be an
> alternative already) to convert a directory with source files (in
> Python) to source blocks within an Org file. It should be easily
> adaptable to other languages. I hope that it is useful to someone. See
> attachment.
>
Oops, missed the name file in the awk line
modified dir-to-org-babel.org
@@ -58,7 +58,7 @@ load into the Library of Babel by doing
while IFS= read -r -d '' file; do
# *** Print file only if it has code
# **** Get number of lines with awk
- numl=$(awk 'END{print NR}')
+ numl=$(awk 'END{print NR}' "$file")
if [[ "$numl" -gt 0 ]]; then
# *** Print the file names (in quotation
# format; with spaces like \ )
-------------------------------------------------
ONLY AT VFEmail! - Use our Metadata Mitigator to keep your email out of the NSA's hands!
$24.95 ONETIME Lifetime accounts with Privacy Features!
15GB disk! No bandwidth quotas!
Commercial and Bulk Mail Options!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-07-01 14:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.109.1498147218.16109.emacs-orgmode@gnu.org>
2017-06-22 22:08 ` :noweb from external file edgar
2017-06-24 6:03 ` edgar
2017-07-01 6:53 ` edgar
2017-07-01 7:36 ` edgar
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).