7

At times, especially when taking notes, a literate org file can contain one-line source blocks, as follows:

* Taking notes
:PROPERTIES:
:tangle: whatever.pl
:comments: org
:END:

Perl set command
#+BEGIN_SRC perl
set $random_var=1;
#+END_SRC

Perl unset command (just making it up... :P)
#+BEGIN_SRC perl
unset $random_var;
#+END_SRC

For such applications, the #+BEGIN_SRC...#+END_SRC pragma looks to be an overkill. Easy templates reduce the typing, but the org doc still looks a bit overflowing.

Is there an easy way to do this? I know that a line starting with a : gets to verbatim text automatically. Is there a way to do something similar with org-tangle?

I am looking for a solution something like this, or at least close to these lines, while still retaining the source highlighting and tangling facilities for parent mode:

* Taking notes
:PROPERTIES:
:tangle: whatever.pl
:comments: org
:mode: perl
:END:

Perl set command
: set $random_var=1;

Perl unset command (just making it up... :P)
: unset $random_var;

It's cleaner, easy to look at and, IMHO, a bit less noisy.

Any suggestions would be appreciated. Thanks in advance!

deejay
  • 193
  • 7
  • How about a hide/unhide command for the entire file as to beginning and ending source code blocks, leaving whatever is sandwiched in between? The beginning and ending would have `...` instead, or you can use whatever shorthand you like to indicate hidden text (e.g., a smiley face `☺`), or you can have no indicator whatsoever for the hidden lines – lawlist Aug 09 '16 at 15:36
  • @lawlist Am not able to understand your example... can you show a demo? – deejay Aug 09 '16 at 15:42
  • 1
    In a buffer containing your first example, evaluate the following snippet to hide text : `(save-excursion (goto-char (point-max)) (while (re-search-backward "#\\+BEGIN_SRC\\|#\\+END_SRC" nil t) (let ((ov (make-overlay (line-beginning-position) (1+ (line-end-position))))) (overlay-put ov 'invisible t))))` When you are done with your test, evaluate `(remove-overlays)`. This is just a simple example of how to hide text. You can create place-holders for the hidden text that look `...` or whatever you want -- e.g., `hidden text lies here`. Evaluate code with `M-x eval-expression` – lawlist Aug 09 '16 at 16:07
  • @lawlist thanks. that cleans up the buffer significantly. I would have been more eager for the org mode solution proposed above, though. One question: I tried to wrap your code in a function: `(defun clean-org-buffer() (save-excursion (goto-char (point-max)) (while (re-search-backward "#\\+BEGIN_SRC\\|#\\+END_SRC" nil t) (let ((ov (make-overlay (line-beginning-position) (1+ (line-end-position))))) (overlay-put ov 'invisible t)))))` However, evaluating this function results in error as follows: `Wrong type argument: commandp, clean-org-buffer`. Can you please suggest how to help this? – deejay Sep 27 '16 at 10:29
  • 1
    You can use either `M-x eval-expression RET (clean-org-buffer) RET` (without any modifications to the snippet) and/or you can add `(interactive)` just before the snippet in my previous comment (2 paragraphs above) so that it is usable interactively with `M-x clean-org-buffer`. – lawlist Sep 27 '16 at 15:11
  • 1
    @lawlist Yup - that helps. Thanks. If you can make your comment as an answer, I would upvote it. However, I am still looking for the core org capability, rather than patching my own way through it. – deejay Sep 28 '16 at 07:07

1 Answers1

4

From (org) Structure of code blocks:

Live code blocks can also be specified inline using

src_<language>{<body>}

or

src_<language>[<header arguments>]{<body>}

So you should be able to use src_perl{set $random_var=1;} instead of the full block.

Tyler
  • 21,719
  • 1
  • 52
  • 92
  • 1
    This does not seem to work. 1) The syntax highlighting is gone, 2) The tangled code comes as a comment - not a statement in the output file (whatever.pl, in this case). Am I doing it wrong? – deejay Aug 10 '16 at 05:53