all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to set a default language for source blocks?
@ 2015-02-17 19:44 Grant Rettke
  2015-02-17 19:51 ` Rasmus
  2015-02-17 20:09 ` Jorge A. Alfaro-Murillo
  0 siblings, 2 replies; 4+ messages in thread
From: Grant Rettke @ 2015-02-17 19:44 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

Good afternoon,

Just read [this] question. It is interesting. We always want to optimize
our documents. Re-use reduces errors. Defining `:header-args:foo:
:session *bar*' is a great example. Rather than having to type it 100
times all over, just do it once. It never occurred to be that we might
want to default the language for a source block. It should have. It
would be simpler to say "this whole document will be R source blocks,
unless I specify other wise". I looked at [the spec]. I wanted to obtain
this behavior. I couldn't figure out how. Is it possible?  I didn't look
at the parser, is that the right place to look to answer questions like
this?

[this]
https://emacs.stackexchange.com/questions/8314/set-default-language-for-code-blocks-in-orgmode/9316#9316

[the spec]
http://orgmode.org/manual/Structure-of-code-blocks.html#Structure-of-code-blocks

-- 
Grant Rettke
gcr@wisdomandwonder.com | http://www.wisdomandwonder.com/
“Wisdom begins in wonder.” --Socrates
((λ (x) (x x)) (λ (x) (x x)))
“Life has become immeasurably better since I have been forced to stop
taking it seriously.” --Thompson

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

* Re: How to set a default language for source blocks?
  2015-02-17 19:44 How to set a default language for source blocks? Grant Rettke
@ 2015-02-17 19:51 ` Rasmus
  2015-02-17 20:09 ` Jorge A. Alfaro-Murillo
  1 sibling, 0 replies; 4+ messages in thread
From: Rasmus @ 2015-02-17 19:51 UTC (permalink / raw)
  To: emacs-orgmode

Grant Rettke <gcr@wisdomandwonder.com> writes:

> Just read [this] question. It is interesting. We always want to optimize
> our documents. Re-use reduces errors. Defining `:header-args:foo:
> :session *bar*' is a great example. Rather than having to type it 100
> times all over, just do it once. It never occurred to be that we might
> want to default the language for a source block. It should have. It
> would be simpler to say "this whole document will be R source blocks,
> unless I specify other wise". I looked at [the spec]. I wanted to obtain
> this behavior. I couldn't figure out how. Is it possible?  I didn't look
> at the parser, is that the right place to look to answer questions like
> this?

You don't have to check the implementation, you can simply check the Org
syntax¹.

    Blocks

    Like greater blocks, pattern for blocks is:

    #+BEGIN_NAME DATA
    CONTENTS
    #+END_NAME

    NAME cannot contain any whitespace character.

    [...] If it is “SRC”, it will be a “source block” [...]

    DATA can contain any character but a new line. It can be ommitted,
    unless the block is a “source block”. In this case, it must follow the
    pattern “LANGUAGE SWITCHES ARGUMENTS”, where SWITCHES and ARGUMENTS
    are optional.

—Rasmus

Footnotes: 
¹   http://orgmode.org/worg/dev/org-syntax.html

-- 
The right to be left alone is a human right

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

* Re: How to set a default language for source blocks?
  2015-02-17 19:44 How to set a default language for source blocks? Grant Rettke
  2015-02-17 19:51 ` Rasmus
@ 2015-02-17 20:09 ` Jorge A. Alfaro-Murillo
  2015-02-18  2:26   ` Grant Rettke
  1 sibling, 1 reply; 4+ messages in thread
From: Jorge A. Alfaro-Murillo @ 2015-02-17 20:09 UTC (permalink / raw)
  To: emacs-orgmode

Hi, Grant.

Grant Rettke writes:

> It would be simpler to say "this whole document will be R source 
> blocks, unless I specify other wise". I looked at [the spec]. I 
> wanted to obtain this behavior. I couldn't figure out how. Is it 
> possible?

The problem is that if there is nothing after #+BEGIN_SRC, then 
org-babel-get-src-block-info returns nil. Probably you would have 
to modify org-babel-get-src-block-info so that it returns a 
default when there is nothing after #+BEGIN_SRC. But isn't it 
easier to set org-structure-template-alist as a local buffer 
variable, say in the first line of your file something like:

#+BEGIN_EXAMPLE
  # -*- org-structure-template-alist: '(("s" "#+BEGIN_SRC 
  python\n?\n#+END_SRC")) -*-
#+END_EXAMPLE

Then <s followed by TAB, would always get you python for that 
file, for example.

Best,

-- 
Jorge.

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

* Re: How to set a default language for source blocks?
  2015-02-17 20:09 ` Jorge A. Alfaro-Murillo
@ 2015-02-18  2:26   ` Grant Rettke
  0 siblings, 0 replies; 4+ messages in thread
From: Grant Rettke @ 2015-02-18  2:26 UTC (permalink / raw)
  To: Jorge A. Alfaro-Murillo; +Cc: emacs-orgmode@gnu.org

Rasmus: Thanks

Jorge: Yes probably

On Tue, Feb 17, 2015 at 2:09 PM, Jorge A. Alfaro-Murillo
<jorge.alfaro-murillo@yale.edu> wrote:
> Hi, Grant.
>
> Grant Rettke writes:
>
>> It would be simpler to say "this whole document will be R source blocks,
>> unless I specify other wise". I looked at [the spec]. I wanted to obtain
>> this behavior. I couldn't figure out how. Is it possible?
>
>
> The problem is that if there is nothing after #+BEGIN_SRC, then
> org-babel-get-src-block-info returns nil. Probably you would have to modify
> org-babel-get-src-block-info so that it returns a default when there is
> nothing after #+BEGIN_SRC. But isn't it easier to set
> org-structure-template-alist as a local buffer variable, say in the first
> line of your file something like:
>
> #+BEGIN_EXAMPLE
>  # -*- org-structure-template-alist: '(("s" "#+BEGIN_SRC
> python\n?\n#+END_SRC")) -*-
> #+END_EXAMPLE
>
> Then <s followed by TAB, would always get you python for that file, for
> example.
>
> Best,
>
> --
> Jorge.
>
>



-- 
Grant Rettke
gcr@wisdomandwonder.com | http://www.wisdomandwonder.com/
“Wisdom begins in wonder.” --Socrates
((λ (x) (x x)) (λ (x) (x x)))
“Life has become immeasurably better since I have been forced to stop
taking it seriously.” --Thompson

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

end of thread, other threads:[~2015-02-18  2:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-17 19:44 How to set a default language for source blocks? Grant Rettke
2015-02-17 19:51 ` Rasmus
2015-02-17 20:09 ` Jorge A. Alfaro-Murillo
2015-02-18  2:26   ` Grant Rettke

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.