all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Tangling include files
@ 2016-11-23  8:24 Harry Butterworth
  2016-11-23  9:47 ` Marco Wahl
  0 siblings, 1 reply; 6+ messages in thread
From: Harry Butterworth @ 2016-11-23  8:24 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1201 bytes --]

Hi Folks,

    I am attempting to switch from FunnelWeb to Org for literate
programming.  I'm stuck because I can't work out how to include .org files
and then tangle everything.  A tangle in the top level file only seems to
tangle the contents of that file and not the contents of the included files.

    I did find something on this topic in a mailing list from several years
back but the workaround posted there seems to be out of date.

    I don't want to put all my source code into one big .org file.  With
FunnelWeb, I would organize source code for public classes into an
interface file and an implementation file and private classes into a single
file so the resulting document could have a section documenting the public
API followed by the implementation.

So the top level document would end up something like this:

include X_int
include Y_int
include Z_int
include X
include Y
include Z
include P
include Q
include R

It looks to me like there have been some changes around the implementation
of INCLUDE in Org, I'm wondering if tangling include files is now supported
and if so, how to do it.

My installed Org version is 8.2.4 but obviously I'll upgrade if necessary.

Thanks

Harry

[-- Attachment #2: Type: text/html, Size: 1546 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Tangling include files
  2016-11-23  8:24 Tangling include files Harry Butterworth
@ 2016-11-23  9:47 ` Marco Wahl
  2016-11-24  4:00   ` Harry Butterworth
  0 siblings, 1 reply; 6+ messages in thread
From: Marco Wahl @ 2016-11-23  9:47 UTC (permalink / raw)
  To: emacs-orgmode

Hi!

>     I am attempting to switch from FunnelWeb to Org for literate
> programming.  I'm stuck because I can't work out how to include .org files
> and then tangle everything.  A tangle in the top level file only seems to
> tangle the contents of that file and not the contents of the included files.
>
>     I did find something on this topic in a mailing list from several years
> back but the workaround posted there seems to be out of date.
>
>     I don't want to put all my source code into one big .org file.  With
> FunnelWeb, I would organize source code for public classes into an
> interface file and an implementation file and private classes into a single
> file so the resulting document could have a section documenting the public
> API followed by the implementation.
>
> So the top level document would end up something like this:
>
> include X_int
> include Y_int
> include Z_int
> include X
> include Y
> include Z
> include P
> include Q
> include R
>
> It looks to me like there have been some changes around the implementation
> of INCLUDE in Org, I'm wondering if tangling include files is now supported
> and if so, how to do it.
>
> My installed Org version is 8.2.4 but obviously I'll upgrade if necessary.

Quick thought: what about exporting the top level document as Org and
then tangle the resulting (one big) .org file?


HTH

        Morco

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Tangling include files
  2016-11-23  9:47 ` Marco Wahl
@ 2016-11-24  4:00   ` Harry Butterworth
  2016-11-24  5:22     ` Charles C. Berry
  0 siblings, 1 reply; 6+ messages in thread
From: Harry Butterworth @ 2016-11-24  4:00 UTC (permalink / raw)
  To: Marco Wahl; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1723 bytes --]

I tried org-org-export-to-org which puts everything into a single document
but it strips the :tangle parameters out so a subsequent tangle doesn't
generate any source code.

On 23 November 2016 at 17:47, Marco Wahl <marcowahlsoft@gmail.com> wrote:

> Hi!
>
> >     I am attempting to switch from FunnelWeb to Org for literate
> > programming.  I'm stuck because I can't work out how to include .org
> files
> > and then tangle everything.  A tangle in the top level file only seems to
> > tangle the contents of that file and not the contents of the included
> files.
> >
> >     I did find something on this topic in a mailing list from several
> years
> > back but the workaround posted there seems to be out of date.
> >
> >     I don't want to put all my source code into one big .org file.  With
> > FunnelWeb, I would organize source code for public classes into an
> > interface file and an implementation file and private classes into a
> single
> > file so the resulting document could have a section documenting the
> public
> > API followed by the implementation.
> >
> > So the top level document would end up something like this:
> >
> > include X_int
> > include Y_int
> > include Z_int
> > include X
> > include Y
> > include Z
> > include P
> > include Q
> > include R
> >
> > It looks to me like there have been some changes around the
> implementation
> > of INCLUDE in Org, I'm wondering if tangling include files is now
> supported
> > and if so, how to do it.
> >
> > My installed Org version is 8.2.4 but obviously I'll upgrade if
> necessary.
>
> Quick thought: what about exporting the top level document as Org and
> then tangle the resulting (one big) .org file?
>
>
> HTH
>
>         Morco
>
>
>

[-- Attachment #2: Type: text/html, Size: 2309 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Tangling include files
  2016-11-24  4:00   ` Harry Butterworth
@ 2016-11-24  5:22     ` Charles C. Berry
  2016-11-24  9:00       ` Robert Klein
  0 siblings, 1 reply; 6+ messages in thread
From: Charles C. Berry @ 2016-11-24  5:22 UTC (permalink / raw)
  To: Harry Butterworth; +Cc: Marco Wahl, emacs-orgmode

On Thu, 24 Nov 2016, Harry Butterworth wrote:

> I tried org-org-export-to-org which puts everything into a single document
> but it strips the :tangle parameters out so a subsequent tangle doesn't
> generate any source code.
>

You might try this. Put this at the *top* of your file:

--8<---------------cut here---------------start------------->8---

#+PROPERTY: header-args :eval never-export

#+NAME: tangle file
#+BEGIN_SRC emacs-lisp :eval yes :exports results
(org-babel-tangle)
#+END_SRC

--8<---------------cut here---------------start------------->8---

Type C-c C-c on the property line to refresh it.

Now export. Type 'y' in reply to the query to eval the `tangle file' src 
block and again to the `discard edits' query.

Even exporting to a buffer should be fine. You do not really want the 
exported document, you just want to force the inclusions to take place and 
then run that src block.

This should work, because `org-export-as' will expand all the include's 
before running babel. If the above block runs before any others, then the 
:tangle headers will still be in place.

In fact you could create a separate file, place all the above in it and 
add one line at the bottom to include the top level org file you want to 
tangle from. Then export that.

HTH,

Chuck

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Tangling include files
  2016-11-24  5:22     ` Charles C. Berry
@ 2016-11-24  9:00       ` Robert Klein
  2016-11-24 17:56         ` Charles C. Berry
  0 siblings, 1 reply; 6+ messages in thread
From: Robert Klein @ 2016-11-24  9:00 UTC (permalink / raw)
  To: Charles C. Berry; +Cc: Marco Wahl, emacs-orgmode, Harry Butterworth

[-- Attachment #1: Type: text/plain, Size: 1755 bytes --]

On Wed, 23 Nov 2016 21:22:08 -0800
"Charles C. Berry" <ccberry@ucsd.edu> wrote:

> On Thu, 24 Nov 2016, Harry Butterworth wrote:
> 
> > I tried org-org-export-to-org which puts everything into a single
> > document but it strips the :tangle parameters out so a subsequent
> > tangle doesn't generate any source code.
> >
> 
> You might try this. Put this at the *top* of your file:
> 
> --8<---------------cut here---------------start------------->8---
> 
> #+PROPERTY: header-args :eval never-export
> 
> #+NAME: tangle file
> #+BEGIN_SRC emacs-lisp :eval yes :exports results
> (org-babel-tangle)
> #+END_SRC
> 
> --8<---------------cut here---------------start------------->8---
> 
> Type C-c C-c on the property line to refresh it.
> 
> Now export. Type 'y' in reply to the query to eval the `tangle file'
> src block and again to the `discard edits' query.
> 
> Even exporting to a buffer should be fine. You do not really want the 
> exported document, you just want to force the inclusions to take
> place and then run that src block.
> 
> This should work, because `org-export-as' will expand all the
> include's before running babel. If the above block runs before any
> others, then the :tangle headers will still be in place.
> 
> In fact you could create a separate file, place all the above in it
> and add one line at the bottom to include the top level org file you
> want to tangle from. Then export that.
> 
> HTH,
> 
> Chuck
> 

A line

#+Property: tangle yes

in your org document is sufficient to get it tangled (in org 8.3.6).

I'm currently using the attached script for tangling configuration
files and scripts from the command line.  Please note, it expects
the Emacs initialization file to be ~/.emacs ....


Best regards
Robert


[-- Attachment #2: tangle.el --]
[-- Type: text/x-emacs-lisp, Size: 3304 bytes --]

#!/usr/bin/emacs --script
;;  -*- coding: utf-8-unix; -*-

;; modified from ob-tanbgle.el:org-babel-tangle-publish
(defun roklein/tangle-publish (filename pub-dir)
  "Tangle FILENAME and place the results in PUB-DIR."
  (unless (file-exists-p pub-dir)
    (make-directory pub-dir t))
  (mapc (lambda (el)
          (rename-file el
                       (concat (directory-file-name pub-dir)
                               "/"
                               (file-name-nondirectory el))
                       t))
        (org-babel-tangle-file filename)))

(defun roklein/tangle-with-include (filename
                                    &optional
                                    output-filename
                                    output-directory)
  "Extract the body of source blocks in FILENAME.
Optional argument OUTPUT-FILE can be used to have a more original
file name for the tangled files (instead of FILENAME.lang, where
filename retains its 'org' ending).  Optional argument
OUTPUT-DIRECTORY can be used to have the tangles files moved to
it.  Note, as the original file is exported to org first, a file
FILENAME.org, or -- if given as argument -- OUTPUT-FILE will
remain in the directory of the original FILENAME file."
  (cond
   ;; filename without extension must not be outfile, or the original
   ;; org file would be overwritten.
   ((equal filename output-filename)
    (message
     "%s\n"
     "'output-filename' must not be the same as 'filename' minus extension.")
    (usage))
   ;; does the original orgfile exist and is readable?
   ((or (not (file-exists-p filename))
        (not (file-readable-p filename)))
    (message "%s\n" "Org file 'filename' does not exist or is not readable.")
    (usage))
   ;; does the output-directory exist?
   ((and output-directory
         (or (not (file-exists-p output-directory))
             (not (file-accessible-directory-p output-directory)))
         (message "%s\n" "output directory does not exist")))
   (t
    (load "~/.emacs")
    (find-file filename)
    (setq org-confirm-babel-evaluate nil)
    (let ((new-org-file (org-org-export-to-org))
          (overwrite-existing
           (when output-filename
             (if (file-exists-p output-filename)
                 (y-or-n-p
                  (concat "Output file "
                          output-filename
                          " already exists. Overwrite? "))
               t))))
      (when (and output-filename overwrite-existing)
        (rename-file new-org-file output-filename overwrite-existing))
      (when (not output-filename)
        (setq output-filename new-org-file))
      (message "output filename: %s" output-filename)
      (roklein/tangle-publish output-filename
                              (or output-directory "."))))))
     
(defun usage()
  (message "\n%s\n"
           "Usage: tangle.el filename [output-filename output-directory]"))

(defun main ()
  (let ((argc (length command-line-args-left)))
        (cond ((< argc 1)
               (message "%s\n" "Too few arguments.")
               (usage))
              ((> argc 3)
               (message "%s\n" "Too many arguments.")
               (usage))
              (t
               (apply 'roklein/tangle-with-include
                      command-line-args-left)))))

(main)



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Tangling include files
  2016-11-24  9:00       ` Robert Klein
@ 2016-11-24 17:56         ` Charles C. Berry
  0 siblings, 0 replies; 6+ messages in thread
From: Charles C. Berry @ 2016-11-24 17:56 UTC (permalink / raw)
  To: Robert Klein; +Cc: Marco Wahl, emacs-orgmode, Harry Butterworth

On Thu, 24 Nov 2016, Robert Klein wrote:

> On Wed, 23 Nov 2016 21:22:08 -0800
> "Charles C. Berry" <ccberry@ucsd.edu> wrote:
>
>> On Thu, 24 Nov 2016, Harry Butterworth wrote:
>>
>>> I tried org-org-export-to-org which puts everything into a single
>>> document but it strips the :tangle parameters out so a subsequent
>>> tangle doesn't generate any source code.
>>>
>>
>> You might try this. Put this at the *top* of your file:
>>
>> --8<---------------cut here---------------start------------->8---
>>
>> #+PROPERTY: header-args :eval never-export
>>

[deleted]

>
> A line
>
> #+Property: tangle yes

That idiom is *obsolete* and *deprecated* for a long time and 
*incompatible* as of org 9.0.

>
> in your org document is sufficient to get it tangled (in org 8.3.6).
>

The point of that line was to prevent unwanted evaluation. Presumably, OP 
had :tangle headers in the desired locations in the original org file.

Chuck

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-11-24 17:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-23  8:24 Tangling include files Harry Butterworth
2016-11-23  9:47 ` Marco Wahl
2016-11-24  4:00   ` Harry Butterworth
2016-11-24  5:22     ` Charles C. Berry
2016-11-24  9:00       ` Robert Klein
2016-11-24 17:56         ` Charles C. Berry

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.