* inline source code blocks
@ 2014-03-05 21:28 Ilya Shlyakhter
2014-03-06 22:04 ` Eric Schulte
0 siblings, 1 reply; 6+ messages in thread
From: Ilya Shlyakhter @ 2014-03-05 21:28 UTC (permalink / raw)
To: emacs-orgmode
Some questions about inline source code blocks:
- They're not fontified even when org-src-fontify-natively is true
-- correct?
- They're not included in tangled code; is that intended behavior?
The manual does not seem to say they're different from normal code
blocks, except for syntax.
There are also mailing list messages that suggest they're not meant
to be exported. What is the correct understanding? I can submit a
patch to the manual once I understand this myself.
- For very short code snippets (1-2 lines), it would be good to
allow specifying (via properties) a default language for code blocks
(say C) and a prefix character (say '>'), after which one could write
> int i;
and have this be the equivalent of
+BEGIN_SRC c
int i;
+END_SRC
by analogy with short literal examples
: such as this
Would this break any Org invariants?
(Context: trying to use Org for literate programming in C++;
interested in others' experience in this area).
Thanks,
Ilya
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: inline source code blocks
2014-03-05 21:28 inline source code blocks Ilya Shlyakhter
@ 2014-03-06 22:04 ` Eric Schulte
2014-03-06 23:35 ` Ilya Shlyakhter
2014-03-07 0:02 ` Ilya Shlyakhter
0 siblings, 2 replies; 6+ messages in thread
From: Eric Schulte @ 2014-03-06 22:04 UTC (permalink / raw)
To: Ilya Shlyakhter; +Cc: emacs-orgmode
Ilya Shlyakhter <ilya_shl@alum.mit.edu> writes:
> Some questions about inline source code blocks:
>
> - They're not fontified even when org-src-fontify-natively is true
> -- correct?
Correct.
>
> - They're not included in tangled code; is that intended behavior?
> The manual does not seem to say they're different from normal code
> blocks, except for syntax.
They were originally added for the sole purpose of including results
inline in textual elements. They are not meant to export code. There
is currently no support (to my knowledge) for inline fontified code.
> There are also mailing list messages that suggest they're not meant
> to be exported. What is the correct understanding? I can submit a
> patch to the manual once I understand this myself.
>
That would be much appreciated.
>
> - For very short code snippets (1-2 lines), it would be good to
> allow specifying (via properties) a default language for code blocks
> (say C) and a prefix character (say '>'), after which one could write
>
> > int i;
>
I think code blocks work well for non-inline code. Although I think
that an inline fontification solution may be nice. I use the following
to make code block syntax less intrusive...
Pretty code blocks
#+begin_src emacs-lisp
(defun prettier-org-code-blocks ()
(interactive)
(font-lock-add-keywords nil
'(("\\(\+begin_src\\)"
(0 (progn (compose-region (match-beginning 1) (match-end 1) ?¦)
nil)))
("\\(\+end_src\\)"
(0 (progn (compose-region (match-beginning 1) (match-end 1) ?¦)
nil))))))
(add-hook 'org-mode-hook 'prettier-org-code-blocks)
#+end_src
and code blocks may easily by typed with "< s TAB". Beyond that you
could add personal customization to further reduce either the visual or
typing burden.
>
> and have this be the equivalent of
>
> +BEGIN_SRC c
> int i;
> +END_SRC
>
> by analogy with short literal examples
> : such as this
>
> Would this break any Org invariants?
>
> (Context: trying to use Org for literate programming in C++;
> interested in others' experience in this area).
>
Hope these suggestions help,
>
> Thanks,
>
> Ilya
>
--
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: inline source code blocks
2014-03-06 22:04 ` Eric Schulte
@ 2014-03-06 23:35 ` Ilya Shlyakhter
2014-03-07 2:22 ` Eric Schulte
2014-03-07 0:02 ` Ilya Shlyakhter
1 sibling, 1 reply; 6+ messages in thread
From: Ilya Shlyakhter @ 2014-03-06 23:35 UTC (permalink / raw)
To: emacs-orgmode
On 3/6/14 5:04 PM, Eric Schulte wrote:
> I think code blocks work well for non-inline code.
For a series of one-liners interspersed with comments, code block
boundaries triple the number of lines. E.g. the example in the manual
at http://orgmode.org/org.html#noweb_002dref
+BEGIN_SRC sh :tangle yes :noweb yes :shebang #!/bin/sh
<<fullest-disk>>
#+END_SRC
* the mount point of the fullest disk
:PROPERTIES:
:noweb-ref: fullest-disk
:END:
** query all mounted disks
#+BEGIN_SRC sh
df \
#+END_SRC
** strip the header row
#+BEGIN_SRC sh
|sed '1d' \
#+END_SRC
** sort by the percent full
#+BEGIN_SRC sh
|awk '{print $5 " " $6}'|sort -n |tail -1 \
#+END_SRC
** extract the mount point
#+BEGIN_SRC sh
|awk '{print $2}'
#+END_SRC
could be shortened to
#+PROPERTY: ob-default-lang sh
#+HEADER: :tangle yes :noweb yes :shebang #!/bin/sh
: <<fullest-disk>>
* the mount point of the fullest disk
:PROPERTIES:
:noweb-ref: fullest-disk
:END:
** query all mounted disks
: df \
** strip the header row
: |sed '1d' \
** sort by the percent full
: |awk '{print $5 " " $6}'|sort -n |tail -1 \
** extract the mount point
: |awk '{print $2}'
i.e. where the (inherited) property ob-default-lang exists, literal
examples become code blocks in that language.
Or in a list of C++ declarations:
#+PROPERTY: ob-default-lang c++
...
* class MyClass
Does X, Y and Z.
: class MyClass: public MyParent {
** Private fields
*** Field a: stores thing one
: int a;
*** Field b: stores thing two
: char *b;
** Public methods
: public:
*** Method getA: Returns the value of a.
: int getA() const { return a; }
** end class MyClass
:}
I'm finding that Org would work well as a literate programming system
for C++, if the code block starts and ends didn't get in the way so much
during frequent switching between code and prose.
> I use the following to make code block syntax less intrusive
Thanks, that was helpful, didn't know about compose-region.
Still, it does not reduce the number of lines used, so a short list of
declarations interspersed with comments quickly ends up taking a lot of
vertical space. When coding it helps to be able to see many things at
once, and having many extra lines (even mostly-blank ones) makes that
difficult.
ilya
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: inline source code blocks
2014-03-06 22:04 ` Eric Schulte
2014-03-06 23:35 ` Ilya Shlyakhter
@ 2014-03-07 0:02 ` Ilya Shlyakhter
1 sibling, 0 replies; 6+ messages in thread
From: Ilya Shlyakhter @ 2014-03-07 0:02 UTC (permalink / raw)
To: emacs-orgmode
> I think code blocks work well for non-inline code.
For a series of one-liners interspersed with comments, code block
boundaries triple the number of lines. E.g. the example in the manual
at http://orgmode.org/org.html#noweb_002dref
+BEGIN_SRC sh :tangle yes :noweb yes :shebang #!/bin/sh
<<fullest-disk>>
#+END_SRC
* the mount point of the fullest disk
:PROPERTIES:
:noweb-ref: fullest-disk
:END:
** query all mounted disks
#+BEGIN_SRC sh
df \
#+END_SRC
** strip the header row
#+BEGIN_SRC sh
|sed '1d' \
#+END_SRC
** sort by the percent full
#+BEGIN_SRC sh
awk '{print $5 " " $6}'|sort -n |tail -1 \
#+END_SRC
** extract the mount point
#+BEGIN_SRC sh
|awk '{print $2}'
#+END_SRC
could be shortened to
#+PROPERTY: ob-default-lang sh
#+HEADER: :tangle yes :noweb yes :shebang #!/bin/sh
: <<fullest-disk>>
* the mount point of the fullest disk
:PROPERTIES:
:noweb-ref: fullest-disk
:END:
** query all mounted disks
: df \
** strip the header row
: |sed '1d' \
** sort by the percent full
: |awk '{print $5 " " $6}'|sort -n |tail -1 \
** extract the mount point
: |awk '{print $2}'
i.e. where the (inherited) property ob-default-lang exists, literal
examples become code blocks in that language.
Or in a list of C++ declarations:
#+PROPERTY: ob-default-lang c++
...
* class MyClass
Does X, Y and Z.
: class MyClass: public MyParent {
** Private fields
*** Field a: stores thing one
: int a;
*** Field b: stores thing two
: char *b;
** Public methods
: public:
*** Method getA: Returns the value of a.
: int getA() const { return a; }
** end class MyClass
: }
I'm finding that Org would work well as a literate programming system
for C++, if the code block starts and ends didn't get in the way so much
during frequent switching between code and prose.
> I use the following to make code block syntax less intrusive
Thanks, that was helpful, didn't know about compose-region.
Still, it does not reduce the number of lines used, so a short list of
declarations interspersed with comments quickly ends up taking a lot of
vertical space. When coding it helps to be able to see many things at
once, and having many extra lines (even mostly-blank ones) makes that
difficult.
ilya
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: inline source code blocks
2014-03-06 23:35 ` Ilya Shlyakhter
@ 2014-03-07 2:22 ` Eric Schulte
2014-03-07 2:52 ` Ilya Shlyakhter
0 siblings, 1 reply; 6+ messages in thread
From: Eric Schulte @ 2014-03-07 2:22 UTC (permalink / raw)
To: Ilya Shlyakhter; +Cc: emacs-orgmode
> I'm finding that Org would work well as a literate programming system
> for C++, if the code block starts and ends didn't get in the way so much
> during frequent switching between code and prose.
>
> > I use the following to make code block syntax less intrusive
>
> Thanks, that was helpful, didn't know about compose-region.
> Still, it does not reduce the number of lines used, so a short list of
> declarations interspersed with comments quickly ends up taking a lot of
> vertical space. When coding it helps to be able to see many things at
> once, and having many extra lines (even mostly-blank ones) makes that
> difficult.
>
I agree that maximizing code per vertical space is important. However,
keeping Org-mode parseable and editable is also important. How about
the following alternative to my previous suggestion, which will
eliminate the extra lines.
(defun prettier-org-code-blocks ()
(interactive)
(font-lock-add-keywords nil
'(("\\(^[[:space:]]*#\\+begin_src .*[\r\n]\\)"
(0 (progn (compose-region (match-beginning 1) (match-end 1) "")
nil)))
("\\(^[[:space:]]*#\\+end_src[\r\n]\\)"
(0 (progn (compose-region (match-beginning 1) (match-end 1) "")
nil))))))
Best,
>
> ilya
>
>
>
--
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: inline source code blocks
2014-03-07 2:22 ` Eric Schulte
@ 2014-03-07 2:52 ` Ilya Shlyakhter
0 siblings, 0 replies; 6+ messages in thread
From: Ilya Shlyakhter @ 2014-03-07 2:52 UTC (permalink / raw)
To: emacs-orgmode
On 3/6/14 9:22 PM, Eric Schulte wrote:
> How about the following alternative to my previous suggestion, which will eliminate the extra lines.
Looks beautiful initially, but leads to some confusing behaviors due to
invisible lines. But eliminating extra lines is only important for some
sections of code; in others, the extra lines (though shortened) actually
help. I'll use begin_src/end_src for the former and BEGIN_SRC/END_SRC
for the latter, and have your prettier-org-code-blocks fontifier match
just the lowercase version.
Thanks a lot,
ilya
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-03-07 2:52 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-05 21:28 inline source code blocks Ilya Shlyakhter
2014-03-06 22:04 ` Eric Schulte
2014-03-06 23:35 ` Ilya Shlyakhter
2014-03-07 2:22 ` Eric Schulte
2014-03-07 2:52 ` Ilya Shlyakhter
2014-03-07 0:02 ` Ilya Shlyakhter
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).