* Controlling example block export?
@ 2014-04-01 9:20 Heikki Lehvaslaiho
2014-04-01 10:10 ` Thorsten Jolitz
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Heikki Lehvaslaiho @ 2014-04-01 9:20 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1080 bytes --]
I am using example blocks as inline notes where I paste snippets of
(pre-formatted) text. I'd like to be able to control the exporting of
those block individually (per document would also be useful). I do not seem
to be able to find documentation about anything along those lines.
Here is a mock-up:
#+BEGIN_EXAMPLE :exports none
private notes...
#+END_EXAMPLE
A bigger question is that while code blocks are well defined and well
documented, all other blocks are not. Is there somewhere a design document
the would give a logic of having different blocks and how they are
controlled? Maybe there is an other type of a block that does what I want?
The inline documentation in ox*.el files is too low level to be helpful.
-Heikki
Heikki Lehvaslaiho - skype:heikki_lehvaslaiho http://about.me/heikki
cell: +966 545 595 849 office: +966 12 808 2429
Saudi Arabian weekend is now Friday and Saturday.
KAUST Supercomputing Center, Building #1, Level 0, 0203-WS23
4700 King Abdullah University of Science and Technology (KAUST)
Thuwal 23955-6900, Kingdom of Saudi Arabia
[-- Attachment #2: Type: text/html, Size: 1429 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Controlling example block export?
2014-04-01 9:20 Controlling example block export? Heikki Lehvaslaiho
@ 2014-04-01 10:10 ` Thorsten Jolitz
2014-04-01 12:40 ` Heikki Lehvaslaiho
2014-04-01 15:34 ` Nicolas Goaziou
2014-04-01 16:33 ` Charles Berry
2 siblings, 1 reply; 8+ messages in thread
From: Thorsten Jolitz @ 2014-04-01 10:10 UTC (permalink / raw)
To: emacs-orgmode
Heikki Lehvaslaiho <heikki.lehvaslaiho@gmail.com> writes:
> I am using example blocks as inline notes where I paste snippets of
> (pre-formatted) text. I'd like to be able to control the exporting of
> those block individually (per document would also be useful). I do not
> seem to be able to find documentation about anything along those
> lines.
>
> Here is a mock-up:
>
> #+BEGIN_EXAMPLE :exports none
> private notes...
> #+END_EXAMPLE
I don't think example blocks take arguments. You might try
#+BEGIN_SRC org :exports none
private notes...
#+END_SRC
or collect these example blocks in subtrees with export tags/properties.
> A bigger question is that while code blocks are well defined and well
> documented, all other blocks are not. Is there somewhere a design
> document the would give a logic of having different blocks and how
> they are controlled? Maybe there is an other type of a block that does
> what I want?
> The inline documentation in ox*.el files is too low level to be
> helpful.
AFAIK export of these block types is backend specific, e.g. ox-ascii.el
might treat example block different than ox-html.el, so thats where to
look.
,---------------------------
| C-h v org-export-with- TAB
`---------------------------
gives some hints too. Using drawers instead of example blocks would
enable you to toggle export documentwise.
I asked a similar 'bigger' question before, and remember that the answer
was more or less 'the block name says it all'.
However, here is a (dense) description of the org syntax:
,--------------------------------------------
| http://orgmode.org/worg/dev/org-syntax.html
`--------------------------------------------
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Controlling example block export?
2014-04-01 10:10 ` Thorsten Jolitz
@ 2014-04-01 12:40 ` Heikki Lehvaslaiho
2014-04-01 14:52 ` Thorsten Jolitz
2014-04-01 15:38 ` Nicolas Goaziou
0 siblings, 2 replies; 8+ messages in thread
From: Heikki Lehvaslaiho @ 2014-04-01 12:40 UTC (permalink / raw)
To: Thorsten Jolitz; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 3696 bytes --]
Thanks, Torsten. Very illuminating.
The org-syntax.html says of blocks:
#+BEGIN_NAME PARAMETERS
CONTENTS
#+END_NAME
NAME can contain any non-whitespace character.
PARAMETERS can contain any character other than new line, and can be
omitted.
If NAME is "CENTER", it will be a "center block". If it is "QUOTE", it will
be a "quote block".
If the block is neither a center block, a quote block or a block
element<http://orgmode.org/worg/dev/org-syntax.html#Blocks>,
it will be a "special block".
That does not seem to be quite true as lisp/org-element.el recognises the
following blocks (perlregexp: /begin_(\w+)/i):
- CENTER
- COMMENT
- EXAMPLE
- QUOTE
- SRC
- VERSE
... in addition to any other valid block names. For these, the content is
displayed as plain text after striping the BEGIN/END lines unless the
exporter used has code for handling it differently.
Note: org-syntax.html needs updating.
So, to implement parameters for the EXAMPLE block, relevant code has to be
added to the exporter. That's a nontrivial task to do consistently.
Incidentally, the solution to my immediate problem is the COMMENT block.
Its contents are completely ignored and not passed to exporters. If I find
myself using that a lot, a macro or a a function to toggle between these
two might come handy:
#+BEGIN_COMMENT :type EXAMPLE
text in a block
#+END_COMMENT
<>
#+BEGIN_ EXAMPLE
text in a block
#+END_EXAMPLE
Unless someone beats me to it, I'll write it one day. :)
-Heikki
Heikki Lehvaslaiho - skype:heikki_lehvaslaiho http://about.me/heikki
cell: +966 545 595 849 office: +966 12 808 2429
Saudi Arabian weekend is now Friday and Saturday.
KAUST Supercomputing Center, Building #1, Level 0, 0203-WS23
4700 King Abdullah University of Science and Technology (KAUST)
Thuwal 23955-6900, Kingdom of Saudi Arabia
On 1 April 2014 13:10, Thorsten Jolitz <tjolitz@gmail.com> wrote:
> Heikki Lehvaslaiho <heikki.lehvaslaiho@gmail.com> writes:
>
> > I am using example blocks as inline notes where I paste snippets of
> > (pre-formatted) text. I'd like to be able to control the exporting of
> > those block individually (per document would also be useful). I do not
> > seem to be able to find documentation about anything along those
> > lines.
> >
> > Here is a mock-up:
> >
> > #+BEGIN_EXAMPLE :exports none
> > private notes...
> > #+END_EXAMPLE
>
> I don't think example blocks take arguments. You might try
>
> #+BEGIN_SRC org :exports none
> private notes...
> #+END_SRC
>
> or collect these example blocks in subtrees with export tags/properties.
>
> > A bigger question is that while code blocks are well defined and well
> > documented, all other blocks are not. Is there somewhere a design
> > document the would give a logic of having different blocks and how
> > they are controlled? Maybe there is an other type of a block that does
> > what I want?
> > The inline documentation in ox*.el files is too low level to be
> > helpful.
>
> AFAIK export of these block types is backend specific, e.g. ox-ascii.el
> might treat example block different than ox-html.el, so thats where to
> look.
>
> ,---------------------------
> | C-h v org-export-with- TAB
> `---------------------------
>
> gives some hints too. Using drawers instead of example blocks would
> enable you to toggle export documentwise.
>
> I asked a similar 'bigger' question before, and remember that the answer
> was more or less 'the block name says it all'.
>
> However, here is a (dense) description of the org syntax:
>
> ,--------------------------------------------
> | http://orgmode.org/worg/dev/org-syntax.html
> `--------------------------------------------
>
> --
> cheers,
> Thorsten
>
>
>
[-- Attachment #2: Type: text/html, Size: 5842 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Controlling example block export?
2014-04-01 12:40 ` Heikki Lehvaslaiho
@ 2014-04-01 14:52 ` Thorsten Jolitz
2014-04-01 15:16 ` Thorsten Jolitz
2014-04-01 15:38 ` Nicolas Goaziou
1 sibling, 1 reply; 8+ messages in thread
From: Thorsten Jolitz @ 2014-04-01 14:52 UTC (permalink / raw)
To: emacs-orgmode
Heikki Lehvaslaiho <heikki.lehvaslaiho@gmail.com> writes:
> Unless someone beats me to it, I'll write it one day. :)
What about:
#+begin_src emacs-lisp
(defun tj/toggle-example-and-comment-blocks ()
"Toggle example and comment blocks in current buffer."
(interactive)
(org-block-map
(lambda ()
(org-mark-element)
(when (use-region-p)
(let ((beg (region-beginning))
(end (region-end)))
(cond
((save-excursion
(re-search-forward "#\\+begin_comment"
(line-end-position) 'NOERROR))
(replace-string "#+begin_comment" "#+begin_example"
nil beg end)
(replace-string "#+end_comment" "#+end_example"
nil beg end))
((save-excursion
(re-search-forward "#\\+begin_example"
(line-end-position) 'NOERROR))
(replace-string "#+begin_example" "#+begin_comment"
nil beg end)
(replace-string "#+end_example" "#+end_comment"
nil beg end))
(t nil))
(deactivate-mark))))))
#+end_src
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Controlling example block export?
2014-04-01 14:52 ` Thorsten Jolitz
@ 2014-04-01 15:16 ` Thorsten Jolitz
0 siblings, 0 replies; 8+ messages in thread
From: Thorsten Jolitz @ 2014-04-01 15:16 UTC (permalink / raw)
To: emacs-orgmode
Thorsten Jolitz <tjolitz@gmail.com> writes:
> Heikki Lehvaslaiho <heikki.lehvaslaiho@gmail.com> writes:
>
>> Unless someone beats me to it, I'll write it one day. :)
>
> What about:
>
> #+begin_src emacs-lisp
> (defun tj/toggle-example-and-comment-blocks ()
> "Toggle example and comment blocks in current buffer."
> (interactive)
> (org-block-map
> (lambda ()
> (org-mark-element)
> (when (use-region-p)
> (let ((beg (region-beginning))
> (end (region-end)))
> (cond
> ((save-excursion
> (re-search-forward "#\\+begin_comment"
> (line-end-position) 'NOERROR))
> (replace-string "#+begin_comment" "#+begin_example"
> nil beg end)
> (replace-string "#+end_comment" "#+end_example"
> nil beg end))
> ((save-excursion
> (re-search-forward "#\\+begin_example"
> (line-end-position) 'NOERROR))
> (replace-string "#+begin_example" "#+begin_comment"
> nil beg end)
> (replace-string "#+end_example" "#+end_comment"
> nil beg end))
> (t nil))
> (deactivate-mark))))))
> #+end_src
I should have read the help string of `replace-string' till the end,
because
,-------------------------------------------------------------------
| This function is usually the wrong thing to use in a Lisp program.
| What you probably want is a loop like this:
| (while (search-forward FROM-STRING nil t)
| (replace-match TO-STRING nil t))
| which will run faster and will not set the mark or print anything.
`-------------------------------------------------------------------
Here is the corrected version:
#+begin_src emacs-lisp
(defun tj/toggle-example-and-comment-blocks ()
"Toggle example and comment blocks in current buffer."
(interactive)
(org-block-map
(lambda ()
(org-mark-element)
(when (use-region-p)
(let ((end (region-end)))
(cond
((save-excursion
(re-search-forward "#\\+begin_comment"
(line-end-position) 'NOERROR))
(while (search-forward "#+begin_comment"
(line-end-position) t)
(replace-match "#+begin_example" nil t))
(while (search-forward "#+end_comment" end t)
(replace-match "#+end_example" nil t)))
((save-excursion
(re-search-forward "#\\+begin_example"
(line-end-position) 'NOERROR))
(while (search-forward "#+begin_example"
(line-end-position) t)
(replace-match "#+begin_comment" nil t))
(while (search-forward "#+end_example" end t)
(replace-match "#+end_comment" nil t)))
(t nil))
(deactivate-mark))))))
#+end_src
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Controlling example block export?
2014-04-01 9:20 Controlling example block export? Heikki Lehvaslaiho
2014-04-01 10:10 ` Thorsten Jolitz
@ 2014-04-01 15:34 ` Nicolas Goaziou
2014-04-01 16:33 ` Charles Berry
2 siblings, 0 replies; 8+ messages in thread
From: Nicolas Goaziou @ 2014-04-01 15:34 UTC (permalink / raw)
To: Heikki Lehvaslaiho; +Cc: emacs-orgmode
Hello,
Heikki Lehvaslaiho <heikki.lehvaslaiho@gmail.com> writes:
> I am using example blocks as inline notes where I paste snippets of
> (pre-formatted) text. I'd like to be able to control the exporting of
> those block individually (per document would also be useful). I do not seem
> to be able to find documentation about anything along those lines.
>
> Here is a mock-up:
>
> #+BEGIN_EXAMPLE :exports none
> private notes...
> #+END_EXAMPLE
You should use drawers for that. See also `org-export-with-drawers'.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Controlling example block export?
2014-04-01 12:40 ` Heikki Lehvaslaiho
2014-04-01 14:52 ` Thorsten Jolitz
@ 2014-04-01 15:38 ` Nicolas Goaziou
1 sibling, 0 replies; 8+ messages in thread
From: Nicolas Goaziou @ 2014-04-01 15:38 UTC (permalink / raw)
To: Heikki Lehvaslaiho; +Cc: emacs-orgmode, Thorsten Jolitz
Hello,
Heikki Lehvaslaiho <heikki.lehvaslaiho@gmail.com> writes:
> The org-syntax.html says of blocks:
>
> #+BEGIN_NAME PARAMETERS
> CONTENTS
> #+END_NAME
>
> NAME can contain any non-whitespace character.
> PARAMETERS can contain any character other than new line, and can be
> omitted.
> If NAME is "CENTER", it will be a "center block". If it is "QUOTE", it will
> be a "quote block".
> If the block is neither a center block, a quote block or a block
> element<http://orgmode.org/worg/dev/org-syntax.html#Blocks>,
> it will be a "special block".
>
> That does not seem to be quite true as lisp/org-element.el recognises the
> following blocks (perlregexp: /begin_(\w+)/i):
Have you looked at:
http://orgmode.org/worg/dev/org-syntax.html#Blocks
> Note: org-syntax.html needs updating.
Possibly. Where?
> So, to implement parameters for the EXAMPLE block, relevant code has to be
> added to the exporter. That's a nontrivial task to do consistently.
For now, there is no need for that.
> Incidentally, the solution to my immediate problem is the COMMENT block.
> Its contents are completely ignored and not passed to exporters.
This is the purpose of comments.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Controlling example block export?
2014-04-01 9:20 Controlling example block export? Heikki Lehvaslaiho
2014-04-01 10:10 ` Thorsten Jolitz
2014-04-01 15:34 ` Nicolas Goaziou
@ 2014-04-01 16:33 ` Charles Berry
2 siblings, 0 replies; 8+ messages in thread
From: Charles Berry @ 2014-04-01 16:33 UTC (permalink / raw)
To: emacs-orgmode
Heikki Lehvaslaiho <heikki.lehvaslaiho <at> gmail.com> writes:
>
>
>
> I am using example blocks as inline notes where I paste snippets of
> (pre-formatted) text. I'd like to be able to control the exporting of
> those block individually (per document would also be useful). I do not
> seem to be able to find documentation about anything along those lines.
>
>
> Here is a mock-up:
>
>
> #+BEGIN_EXAMPLE :exports none
> private notes...
> #+END_EXAMPLE
>
>
Advise or redefine the org-<backend>-example-block function to use
:switches to decide whether to skip an example block.
Something like this:
#+BEGIN_SRC emacs-lisp
(defvar org-example-block-skip ":skip"
"example block :switch to skip.")
(defun org-latex-example-block (example-block contents info)
"Transcode an EXAMPLE-BLOCK element from Org to LaTeX.
CONTENTS is nil. INFO is a plist holding contextual
information."
(when (and (org-string-nw-p
(org-element-property :value example-block))
(not (string=
org-example-block-skip
(org-element-property :switches example-block))))
(org-latex--wrap-label
example-block
(format "\\begin{verbatim}\n%s\\end{verbatim}"
(org-export-format-code-default
example-block info)))))
#+END_SRC
> A bigger question is that while code blocks are well defined and well
> documented, all other blocks are not. Is there somewhere a design
> document the would give a logic of having different blocks and how they
> are controlled? Maybe there is an other type of a block that does what I
> want?
>
>
> The inline documentation in ox*.el files is too low level to be helpful.
>
See also org-element.el and
http://orgmode.org/worg/dev/org-export-reference.html
Looking at what (org-element-at-point) returns often helps.
Special blocks are another possibility, but will require some customization.
HTH,
Chuck
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-04-01 16:34 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-01 9:20 Controlling example block export? Heikki Lehvaslaiho
2014-04-01 10:10 ` Thorsten Jolitz
2014-04-01 12:40 ` Heikki Lehvaslaiho
2014-04-01 14:52 ` Thorsten Jolitz
2014-04-01 15:16 ` Thorsten Jolitz
2014-04-01 15:38 ` Nicolas Goaziou
2014-04-01 15:34 ` Nicolas Goaziou
2014-04-01 16:33 ` Charles 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.