* [ANN] Convert Org-mode file to Source-code file
@ 2013-06-20 0:19 Thorsten Jolitz
2013-06-20 18:17 ` Charles Berry
2013-06-20 18:37 ` Eric Schulte
0 siblings, 2 replies; 7+ messages in thread
From: Thorsten Jolitz @ 2013-06-20 0:19 UTC (permalink / raw)
To: emacs-orgmode
Hi List,
it is now possible to convert existing Org-mode files with source-blocks into
machine-executable source-code files, using the following function from
`outorg.el':
#+begin_src emacs-lisp
(defun outorg-convert-org-file-to-source-code
(&optional mode infile outfile BATCH)
"Convert an existing Org-mode file into an Outshine buffer.
If MODE is non-nil, the Outshine buffer will be put in this
major-mode, otherwise the major-mode of the language of the first
source-code block in the Org-mode buffer will be used.
If INFILE is non-nil, the specified Org-mode file will be visited
and its buffer converted, otherwise the current buffer will be
converted.
If OUTFILE is non-nil, the converted Outshine buffer will be saved in this
file. Its the user's responsability to make sure that OUTFILE's
file-extension is suited for the major-mode of the Outshine buffer to be
saved. When in doubt, consult variable `auto-mode-alist' for associations
between file-extensions and major-modes.
If BATCH is non-nil (and OUTFILE is non-nil, otherwise it makes
no sense), the new Outshine file is saved and its buffer
deleted."...)
#+end_src
Usage example:
,----------------------------------------------------------------
| (outorg-convert-org-file-to-source-code
| "emacs-lisp-mode" "~/junk/test.org" "~/junk/test.el" 'BATCH)
`----------------------------------------------------------------
I'm not sure about the general use case for this, but I do have my uses for
it, so I announce it here because it might serve others too.
PS
This is *not* about tangling, try it out to see the (big) difference.
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [ANN] Convert Org-mode file to Source-code file
2013-06-20 0:19 [ANN] Convert Org-mode file to Source-code file Thorsten Jolitz
@ 2013-06-20 18:17 ` Charles Berry
2013-06-21 9:00 ` Thorsten Jolitz
2013-06-20 18:37 ` Eric Schulte
1 sibling, 1 reply; 7+ messages in thread
From: Charles Berry @ 2013-06-20 18:17 UTC (permalink / raw)
To: emacs-orgmode
Thorsten Jolitz <tjolitz <at> gmail.com> writes:
>
> Hi List,
>
> it is now possible to convert existing Org-mode files with source-blocks into
> machine-executable source-code files, using the following function from
> `outorg.el':
>
> #+begin_src emacs-lisp
> (defun outorg-convert-org-file-to-source-code
> (&optional mode infile outfile BATCH)
With this buffer
,----
|
|
| * head1
|
| abc
|
|
| #+NAME: test-src
| #+BEGIN_SRC R
| ls()
| #+END_SRC
`----
it fails with
Debugger entered--Lisp error: (void-variable
outorg-code-buffer-beg-of-subtree-marker)
(set-marker outorg-code-buffer-beg-of-subtree-marker nil)
outorg-reset-global-vars()
outorg-copy-edits-and-exit()
...
in the backtrace.
The tmp buffer looks right, though
,----
|
|
| ## * head1
|
| ## abc
|
|
| ## #+NAME: test-src
| ls()
`----
HTH,
Chuck
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [ANN] Convert Org-mode file to Source-code file
2013-06-20 0:19 [ANN] Convert Org-mode file to Source-code file Thorsten Jolitz
2013-06-20 18:17 ` Charles Berry
@ 2013-06-20 18:37 ` Eric Schulte
2013-06-21 9:58 ` Thorsten Jolitz
1 sibling, 1 reply; 7+ messages in thread
From: Eric Schulte @ 2013-06-20 18:37 UTC (permalink / raw)
To: Thorsten Jolitz; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 63 bytes --]
How does this differ from ":tangle yes :comments org"?
e.g.,
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: foo.org --]
[-- Type: text/x-org, Size: 672 bytes --]
#+Property: tangle yes
#+Property: comments org
* This is the top
#+begin_src sh :shebang #!/bin/bash
echo "##this file will cat itself"
echo ""
#+end_src
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
hendrerit tempor tellus. Donec pretium posuere tellus. Proin quam
nisl, tincidunt et, mattis eget, convallis nec, purus. Cum sociis
natoque penatibus et magnis dis parturient montes, nascetur ridiculus
mus. Nulla posuere. Donec vitae dolor. Nullam tristique diam non
turpis. Cras placerat accumsan nulla. Nullam rutrum. Nam vestibulum
accumsan nisl.
| a | table |
| in | the |
| tangled | file |
#+begin_src sh
cat $0
#+end_src
[-- Attachment #3: Type: text/plain, Size: 13 bytes --]
tangles to
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: foo.sh --]
[-- Type: text/x-sh, Size: 579 bytes --]
#!/bin/bash
# This is the top
echo "##this file will cat itself"
echo ""
# Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
# hendrerit tempor tellus. Donec pretium posuere tellus. Proin quam
# nisl, tincidunt et, mattis eget, convallis nec, purus. Cum sociis
# natoque penatibus et magnis dis parturient montes, nascetur ridiculus
# mus. Nulla posuere. Donec vitae dolor. Nullam tristique diam non
# turpis. Cras placerat accumsan nulla. Nullam rutrum. Nam vestibulum
# accumsan nisl.
# | a | table |
# | in | the |
# | tangled | file |
cat $0
[-- Attachment #5: Type: text/plain, Size: 1780 bytes --]
Thorsten Jolitz <tjolitz@gmail.com> writes:
> Hi List,
>
> it is now possible to convert existing Org-mode files with source-blocks into
> machine-executable source-code files, using the following function from
> `outorg.el':
>
> #+begin_src emacs-lisp
> (defun outorg-convert-org-file-to-source-code
> (&optional mode infile outfile BATCH)
> "Convert an existing Org-mode file into an Outshine buffer.
>
> If MODE is non-nil, the Outshine buffer will be put in this
> major-mode, otherwise the major-mode of the language of the first
> source-code block in the Org-mode buffer will be used.
>
> If INFILE is non-nil, the specified Org-mode file will be visited
> and its buffer converted, otherwise the current buffer will be
> converted.
>
> If OUTFILE is non-nil, the converted Outshine buffer will be saved in this
> file. Its the user's responsability to make sure that OUTFILE's
> file-extension is suited for the major-mode of the Outshine buffer to be
> saved. When in doubt, consult variable `auto-mode-alist' for associations
> between file-extensions and major-modes.
>
> If BATCH is non-nil (and OUTFILE is non-nil, otherwise it makes
> no sense), the new Outshine file is saved and its buffer
> deleted."...)
> #+end_src
>
> Usage example:
>
> ,----------------------------------------------------------------
> | (outorg-convert-org-file-to-source-code
> | "emacs-lisp-mode" "~/junk/test.org" "~/junk/test.el" 'BATCH)
> `----------------------------------------------------------------
>
> I'm not sure about the general use case for this, but I do have my uses for
> it, so I announce it here because it might serve others too.
>
> PS
> This is *not* about tangling, try it out to see the (big) difference.
--
Eric Schulte
http://cs.unm.edu/~eschulte
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [ANN] Convert Org-mode file to Source-code file
2013-06-20 18:17 ` Charles Berry
@ 2013-06-21 9:00 ` Thorsten Jolitz
2013-06-21 16:11 ` Charles Berry
0 siblings, 1 reply; 7+ messages in thread
From: Thorsten Jolitz @ 2013-06-21 9:00 UTC (permalink / raw)
To: emacs-orgmode
Charles Berry <ccberry@ucsd.edu> writes:
> Thorsten Jolitz <tjolitz <at> gmail.com> writes:
>
>>
>> Hi List,
>>
>> it is now possible to convert existing Org-mode files with
>> source-blocks into machine-executable source-code files, using the
>> following function from `outorg.el':
>>
>> #+begin_src emacs-lisp
>> (defun outorg-convert-org-file-to-source-code
>> (&optional mode infile outfile BATCH)
>
>
> With this buffer
>
> ,----
> |
> |
> | * head1
> |
> | abc
> |
> |
> | #+NAME: test-src
> | #+BEGIN_SRC R
> | ls()
> | #+END_SRC
> `----
>
> it fails with
>
> Debugger entered--Lisp error: (void-variable
> outorg-code-buffer-beg-of-subtree-marker)
> (set-marker outorg-code-buffer-beg-of-subtree-marker nil)
> outorg-reset-global-vars()
> outorg-copy-edits-and-exit()
> ...
>
> in the backtrace.
This should be fixed now, thanks for reporting.
> The tmp buffer looks right, though
>
> ,----
> |
> |
> | ## * head1
> |
> | ## abc
> |
> |
> | ## #+NAME: test-src
> | ls()
> `----
Please note that I renamed
,---------------------------------------
| outorg-convert-org-file-to-source-code
`---------------------------------------
to
,-------------------------------
| outorg-convert-org-to-outshine
`-------------------------------
because that better reflects its purpose.
This
,--------------
| ## * head1
`--------------
is actually the decisive part of the output, since the converted
source-code file will have (if outshine is activated) the look&feel of
the original Org-mode file, only that now the text parts are 'caged'
behind comments while in the Org file the source code was 'caged' in
special blocks.
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [ANN] Convert Org-mode file to Source-code file
2013-06-20 18:37 ` Eric Schulte
@ 2013-06-21 9:58 ` Thorsten Jolitz
0 siblings, 0 replies; 7+ messages in thread
From: Thorsten Jolitz @ 2013-06-21 9:58 UTC (permalink / raw)
To: emacs-orgmode
Eric Schulte <schulte.eric@gmail.com> writes:
> How does this differ from ":tangle yes :comments org"?
I wasn't actually aware (or forgot about) the :comments argument in
Babel when I wrote the conversion function (that is renamed to
'outorg-convert-org-to-outshine' now to better reflect its purpose).
> e.g.,
>
> #+Property: tangle yes
> #+Property: comments org
>
> * This is the top
>
> #+begin_src sh :shebang #!/bin/bash
> echo "##this file will cat itself"
> echo ""
> #+end_src
>
> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
> hendrerit tempor tellus. Donec pretium posuere tellus. Proin quam
> nisl, tincidunt et, mattis eget, convallis nec, purus. Cum sociis
> natoque penatibus et magnis dis parturient montes, nascetur ridiculus
> mus. Nulla posuere. Donec vitae dolor. Nullam tristique diam non
> turpis. Cras placerat accumsan nulla. Nullam rutrum. Nam vestibulum
> accumsan nisl.
>
> | a | table |
> | in | the |
> | tangled | file |
>
> #+begin_src sh
> cat $0
> #+end_src
>
> tangles to
>
>
> #!/bin/bash
>
> # This is the top
>
> echo "##this file will cat itself"
> echo ""
>
> # Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
> # hendrerit tempor tellus. Donec pretium posuere tellus. Proin quam
> # nisl, tincidunt et, mattis eget, convallis nec, purus. Cum sociis
> # natoque penatibus et magnis dis parturient montes, nascetur ridiculus
> # mus. Nulla posuere. Donec vitae dolor. Nullam tristique diam non
> # turpis. Cras placerat accumsan nulla. Nullam rutrum. Nam vestibulum
> # accumsan nisl.
>
> # | a | table |
> # | in | the |
> # | tangled | file |
>
> cat $0
in your example file the main difference is that
,--------------------
| > * This is the top
`--------------------
becomes
,--------------------
| > # This is the top
`--------------------
which is not an outshine header, thus the outline structure is lost in
the tangled file.
But it would really be nice if the conversion from Org to Outshine could
be done with the existing 'Babel Toolkit'. On the other hand, since my
conversion function seems to work alright now (bugreports welcome!), it
would not make much sense to invest time into make Babel do the same
thing.
I see the following problems with Babel:
1. (from your example I deduce that) outline structure is not conserved
in the comment sections, thus the tangles files won't work with outshine.
2. the overriding of header args cause problems with files that set
(e.g. code block specific) :tangle or :comment args themnselves, that
then override buffer wide args.
3. an outshine file is a file in a certain programming language
major-mode. 'outorg-convert-org-to-outshine' outcomments everything
else, including property-drawers, org comments, or souce-blocks from
other languages, so that the whole Org-file is preserved. I'm not sure
how this works when tangling with :comments org?
Maybe just check if it works with a real world .org file? The best one I
can think of is
,----------------------------------
| http://doc.norang.ca/org-mode.org
`----------------------------------
since it covers so many aspects of Org-mode.
So I downloaded it and added this at the front
,-----------------------------------------------------------------------
| [...]
| #+EXPORT_EXCLUDE_TAGS: noexport
|
| #+PROPERTY: tangle yes
| #+PROPERTY: comments org
|
| Org-mode is a fabulous organizational tool originally built by Carsten
| Dominik that operates on plain text files. Org-mode is part of Emacs.
| [...]
`-----------------------------------------------------------------------
and then did
1.
,----------
| C-c C-v t
`----------
The tangled file org-mode.el does not at all look as expected, it rather
seems the added properties have been completely ignored. Is it possible
to squeeze Org-Babel such that the tangled file looks like the result of
2.
,----------------------------------------------------------
| M-: (outorg-convert-org-to-outshine "emacs-lisp-mode"
| "~/junk/org-mode.org" "~/junk/org-mode-outorg.el")
`----------------------------------------------------------
This seems to convert the full Org file to Outshine, and when I do M-#
M-# then on the Outshine file, I see the same Org-file as before in the
*outorg-edit-buffer*, as intended. (almost, see the PS).
PS
One thing on my list for outorg is better handling of src-block header
args for the code-sections. Until now, I viewed it from the perspective
of a source-code file (e.g. emacs-lisp), and it was no problem to
surround the code parts simply with
#+begin_src emacs-lisp
<<code>>
#+end_src
and assume that the users use Org-mode properties for persistantly specifying
export options. So when going back from Org to Outshine, I simply deleted the
,-------------------------
|#+begin_src emacs-lisp
|#+end_src
`-------------------------
lines.
But now, from the perspective of converting existing Org-files to Outshine,
this does not look like such a good idea anymore, since I delete important
header info from the original file (although I want to conserve all info that
exists in the file, just transform it to a different state).
So here is a RFC:
What would be best way to conserve the header info from source-blocks of the
major-mode language of the outshine buffer (all the other blocks are
conserved anyway)?
1. simply outcomment and uncomment the header lines instead of deleting them?
Very easy, but looks a bit ugly ... but leaves the original file untouched.
2. transform them into #+HEADER or #+HEADERS lines (whats the difference?)?
This would be my favorite, but changes the original file a bit (visible,
when transforming back from Outshine to Org).
3. transform them into properties inside property drawers. Nice, but not able
to reflect code-block-specific headers.
> Thorsten Jolitz <tjolitz@gmail.com> writes:
>
>> Hi List,
>>
>> it is now possible to convert existing Org-mode files with
>> source-blocks into machine-executable source-code files, using the
>> following function from `outorg.el':
>>
>> #+begin_src emacs-lisp
>> (defun outorg-convert-org-file-to-source-code
>> (&optional mode infile outfile BATCH)
>> "Convert an existing Org-mode file into an Outshine buffer.
>>
>> If MODE is non-nil, the Outshine buffer will be put in this
>> major-mode, otherwise the major-mode of the language of the first
>> source-code block in the Org-mode buffer will be used.
>>
>> If INFILE is non-nil, the specified Org-mode file will be visited
>> and its buffer converted, otherwise the current buffer will be
>> converted.
>>
>> If OUTFILE is non-nil, the converted Outshine buffer will be saved in this
>> file. Its the user's responsability to make sure that OUTFILE's
>> file-extension is suited for the major-mode of the Outshine buffer to be
>> saved. When in doubt, consult variable `auto-mode-alist' for associations
>> between file-extensions and major-modes.
>>
>> If BATCH is non-nil (and OUTFILE is non-nil, otherwise it makes
>> no sense), the new Outshine file is saved and its buffer
>> deleted."...)
>> #+end_src
>>
>> Usage example:
>>
>> ,----------------------------------------------------------------
>> | (outorg-convert-org-file-to-source-code
>> | "emacs-lisp-mode" "~/junk/test.org" "~/junk/test.el" 'BATCH)
>> `----------------------------------------------------------------
>>
>> I'm not sure about the general use case for this, but I do have my
>> uses for it, so I announce it here because it might serve others too.
>>
>> PS
>> This is *not* about tangling, try it out to see the (big) difference.
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [ANN] Convert Org-mode file to Source-code file
2013-06-21 9:00 ` Thorsten Jolitz
@ 2013-06-21 16:11 ` Charles Berry
2013-06-21 17:16 ` Thorsten Jolitz
0 siblings, 1 reply; 7+ messages in thread
From: Charles Berry @ 2013-06-21 16:11 UTC (permalink / raw)
To: emacs-orgmode
Thorsten Jolitz <tjolitz <at> gmail.com> writes:
>
> Charles Berry <ccberry <at> ucsd.edu> writes:
>
> > Thorsten Jolitz <tjolitz <at> gmail.com> writes:
> >
> >>
> >> Hi List,
> >>
> >> it is now possible to convert existing Org-mode files with
> >> source-blocks into machine-executable source-code files, using the
> >> following function from `outorg.el':
> >>
[bug description deleted]
>
> This should be fixed now, thanks for reporting.
>
Now I get
Debugger entered--Lisp error: (void-function region-or-buffer-limits)
[...]
outorg-convert-org-to-outshine()
eval((outorg-convert-org-to-outshine) nil)
eval-expression((outorg-convert-org-to-outshine) nil)
call-interactively(eval-expression nil nil)
and nothing visible in the tmp buffer.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [ANN] Convert Org-mode file to Source-code file
2013-06-21 16:11 ` Charles Berry
@ 2013-06-21 17:16 ` Thorsten Jolitz
0 siblings, 0 replies; 7+ messages in thread
From: Thorsten Jolitz @ 2013-06-21 17:16 UTC (permalink / raw)
To: emacs-orgmode
Charles Berry <ccberry@ucsd.edu> writes:
> Thorsten Jolitz <tjolitz <at> gmail.com> writes:
>
>>
>> Charles Berry <ccberry <at> ucsd.edu> writes:
>>
>> > Thorsten Jolitz <tjolitz <at> gmail.com> writes:
>> >
>> >>
>> >> Hi List,
>> >>
>> >> it is now possible to convert existing Org-mode files with
>> >> source-blocks into machine-executable source-code files, using the
>> >> following function from `outorg.el':
>> >>
>
> [bug description deleted]
>
>>
>> This should be fixed now, thanks for reporting.
>>
>
> Now I get
>
> Debugger entered--Lisp error: (void-function region-or-buffer-limits)
> [...]
>
> outorg-convert-org-to-outshine()
> eval((outorg-convert-org-to-outshine) nil)
> eval-expression((outorg-convert-org-to-outshine) nil)
> call-interactively(eval-expression nil nil)
>
> and nothing visible in the tmp buffer.
ups, sorry, another function from the 'basic-edit-toolkit' I have
installed and take for granted (i.e. think its part of core Emacs).
I just pushed a fix, should work now.
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-06-21 17:16 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-20 0:19 [ANN] Convert Org-mode file to Source-code file Thorsten Jolitz
2013-06-20 18:17 ` Charles Berry
2013-06-21 9:00 ` Thorsten Jolitz
2013-06-21 16:11 ` Charles Berry
2013-06-21 17:16 ` Thorsten Jolitz
2013-06-20 18:37 ` Eric Schulte
2013-06-21 9:58 ` Thorsten Jolitz
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).