On 2017-06-24 06:03, ed...@openmail.cc wrote:
On 2017-06-22 22:08, ed...@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!
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