emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: edgar@openmail.cc
To: emacs-orgmode@gnu.org
Subject: Re: :noweb from external file
Date: Sat, 01 Jul 2017 06:53:58 +0000	[thread overview]
Message-ID: <e4880e3e5575d7a1c70a32c461c28faa@openmail.cc> (raw)
In-Reply-To: <cbc2a57f31922f8435a96c836c39137b@openmail.cc>

[-- 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

  reply	other threads:[~2017-07-01 14:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 [this message]
2017-07-01  7:36       ` edgar

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=e4880e3e5575d7a1c70a32c461c28faa@openmail.cc \
    --to=edgar@openmail.cc \
    --cc=emacs-orgmode@gnu.org \
    /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).