emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <schulte.eric@gmail.com>
To: Nick Daly <nick.m.daly@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Feature Request: Allow Tangling Named INCLUDEs
Date: Mon, 20 Jan 2014 09:20:04 -0700	[thread overview]
Message-ID: <8761pey69y.fsf@gmail.com> (raw)
In-Reply-To: <87ob3ifcx4.fsf@gmail.com> (Nick Daly's message of "Sat, 11 Jan 2014 15:04:23 -0600")

Nick Daly <nick.m.daly@gmail.com> writes:

> Hi folks, I have a situation where I have many named code snippets
> currently available in external files, and would like to tangle them
> into an Org mode file.  Is it currently possible to tangle included
> files?  If not, could that feature be added to a new version of Org
> mode?  I've looked through the mailing list history a bit and couldn't
> find this specific request.
>
> - What exactly did you do? :: I created the three files shown below.
>      I then tangled the searches.org file (~C-c C-v C-t~).
>
>      For convenience, all three files can be created by tangling this
>      email.
>
> - What did you expect to happen? :: I expected the contents of the files
>      searchItems(8|12).m to appear in lines [[search-08][(search-08)]]
>      and [[search-12][(search-12)]].
>
> - What happened instead? :: The templates on lines
>      [[search-08][(search-08)]] and [[search-12][(search-12)]] were
>      empty.
>

The following function works for me on a simple example file.

    ;; -*- emacs-lisp -*-
    (defun trial-expand-and-tangle ()
      (interactive)
      (save-window-excursion
        (let ((text (buffer-string))
              (org-babel-pre-tangle-hook nil))
          (unwind-protect
              (progn
                (org-export-expand-include-keyword)
                (org-babel-tangle))
            (delete-region (point-min) (point-max))
            (goto-char (point-min))
            (insert text)))))

I'm not sure if this is common enough to have functionality added to the
core.  Maybe adding a `with-expanded-includes' macro would be useful
though.

Best,

>
> Thanks for your time,
> Nick
>
> ----
>
> If you don't understand the code below, that's because it's MUMPS.  Be
> happy that you don't understand.
>
> #+begin_src org :noweb tangle :tangle searches.org -s -n :padline no
>   ,# -*- mode: org -*-
>   ,* Searches
>
>   ,#+name: search-main
>   ,#+begin_src text :noweb tangle :tangle searchAllItems.m
>   ,  searches(pId)
>   ,    n pDate,i08,i12
>   ,    f  pDate=$$idForwardDate(pId,pDate) q:pDate=""  d
>   ,    . <<searchItem08>>          ; (ref:search-08)
>   ,    . <<searchItem12>>          ; (ref:search-12)
>   ,    . ; and about 30 more of these named searches.
>   ,#+end_src
>
>   ,#+name: searchItem08
>   ,#+INCLUDE: "searchItem08.m" src text
>
>   ,#+name: searchItem12
>   ,#+INCLUDE: "searchItem12.m" src text
>
> #+end_src
> #+begin_src text :tangle searchItem08.m :padline no
>   s i08=$$zgetnp(pId,pDate,08) i i08="" d LogIcErr("i08",i08)
> #+end_src
> #+begin_src text :tangle searchItem12.m :padline no
>   s i12=$$zgetnp(pId,pDate,12) i $$zgetnp(pId,pDate,$$zgetnp(pId,pDate,i12))'=i12 d LogIcErr("i12",i12)
> #+end_src

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

      parent reply	other threads:[~2014-01-20 16:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-11 21:04 Feature Request: Allow Tangling Named INCLUDEs Nick Daly
2014-01-19 16:01 ` Bastien
2014-01-27  0:44   ` Nick Daly
2014-01-27  9:26     ` Rainer M Krug
2014-01-27 14:37       ` Eric Schulte
2014-01-28  8:12         ` Rainer M Krug
2014-01-27 14:40     ` Eric Schulte
2014-01-20 16:19 ` Eric Schulte
2014-01-27  0:36   ` Nick Daly
2014-01-20 16:20 ` Eric Schulte [this message]

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=8761pey69y.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=nick.m.daly@gmail.com \
    /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).