* How to inspect a document and check for the presence of source block language names and support
@ 2014-11-29 2:08 Grant Rettke
2014-11-29 2:22 ` Andreas Leha
0 siblings, 1 reply; 6+ messages in thread
From: Grant Rettke @ 2014-11-29 2:08 UTC (permalink / raw)
To: emacs-orgmode@gnu.org
Good evening,
My goal is to obtain the following behavior in org mode for a document:
1) Report an error if there is a source block without a language
specified
2) Report an error if there is a source block with a language specified
that is *not* present in `org-babel-load-languages'
I've thought about ways to do this and come up with:
1) Visually inspect the document
2) Use `org-element' to parse and process the document
What are some other ways and what do you think about these two options?
Emacs version: `24.4.1'
Org version: `8.2.10'
Kind regards,
--
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] 6+ messages in thread
* Re: How to inspect a document and check for the presence of source block language names and support
2014-11-29 2:08 How to inspect a document and check for the presence of source block language names and support Grant Rettke
@ 2014-11-29 2:22 ` Andreas Leha
2014-11-29 10:38 ` Nicolas Goaziou
0 siblings, 1 reply; 6+ messages in thread
From: Andreas Leha @ 2014-11-29 2:22 UTC (permalink / raw)
To: emacs-orgmode
Hi Grant,
Grant Rettke <gcr@wisdomandwonder.com> writes:
> Good evening,
>
> My goal is to obtain the following behavior in org mode for a document:
> 1) Report an error if there is a source block without a language
> specified
> 2) Report an error if there is a source block with a language specified
> that is *not* present in `org-babel-load-languages'
>
> I've thought about ways to do this and come up with:
> 1) Visually inspect the document
> 2) Use `org-element' to parse and process the document
I'd be interested in 2) if you come up with something here :-)
Regards,
Andreas
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to inspect a document and check for the presence of source block language names and support
2014-11-29 2:22 ` Andreas Leha
@ 2014-11-29 10:38 ` Nicolas Goaziou
2014-11-29 14:42 ` Grant Rettke
2015-02-03 9:55 ` Sebastien Vauban
0 siblings, 2 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2014-11-29 10:38 UTC (permalink / raw)
To: Andreas Leha; +Cc: emacs-orgmode
Hello,
Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
> Grant Rettke <gcr@wisdomandwonder.com> writes:
>> Good evening,
>>
>> My goal is to obtain the following behavior in org mode for a document:
>> 1) Report an error if there is a source block without a language
>> specified
>> 2) Report an error if there is a source block with a language specified
>> that is *not* present in `org-babel-load-languages'
>>
>> I've thought about ways to do this and come up with:
>> 1) Visually inspect the document
>> 2) Use `org-element' to parse and process the document
>
> I'd be interested in 2) if you come up with something here :-)
(defun my-src-block-check ()
(interactive)
(org-element-map (org-element-parse-buffer 'element) 'src-block
(lambda (src-block)
(let ((language (org-element-property :language src-block)))
(cond ((null language)
(error "Missing language at position %d"
(org-element-property :post-affiliated src-block)))
((not (assoc-string language org-babel-load-languages))
(error "Unknown language at position %d"
(org-element-property :post-affiliated src-block)))))))
(message "Source blocks checked in %s." (buffer-name (buffer-base-buffer))))
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to inspect a document and check for the presence of source block language names and support
2014-11-29 10:38 ` Nicolas Goaziou
@ 2014-11-29 14:42 ` Grant Rettke
2014-11-29 20:40 ` Andreas Leha
2015-02-03 9:55 ` Sebastien Vauban
1 sibling, 1 reply; 6+ messages in thread
From: Grant Rettke @ 2014-11-29 14:42 UTC (permalink / raw)
To: Andreas Leha, emacs-orgmode@gnu.org
What a treat, sir, thank you for sharing that as if by some delightful
magic, which surely it indeed is.
On Sat, Nov 29, 2014 at 4:38 AM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
> Hello,
>
> Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>
>> Grant Rettke <gcr@wisdomandwonder.com> writes:
>>> Good evening,
>>>
>>> My goal is to obtain the following behavior in org mode for a document:
>>> 1) Report an error if there is a source block without a language
>>> specified
>>> 2) Report an error if there is a source block with a language specified
>>> that is *not* present in `org-babel-load-languages'
>>>
>>> I've thought about ways to do this and come up with:
>>> 1) Visually inspect the document
>>> 2) Use `org-element' to parse and process the document
>>
>> I'd be interested in 2) if you come up with something here :-)
>
> (defun my-src-block-check ()
> (interactive)
> (org-element-map (org-element-parse-buffer 'element) 'src-block
> (lambda (src-block)
> (let ((language (org-element-property :language src-block)))
> (cond ((null language)
> (error "Missing language at position %d"
> (org-element-property :post-affiliated src-block)))
> ((not (assoc-string language org-babel-load-languages))
> (error "Unknown language at position %d"
> (org-element-property :post-affiliated src-block)))))))
> (message "Source blocks checked in %s." (buffer-name (buffer-base-buffer))))
>
>
> Regards,
>
> --
> Nicolas Goaziou
>
--
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] 6+ messages in thread
* Re: How to inspect a document and check for the presence of source block language names and support
2014-11-29 14:42 ` Grant Rettke
@ 2014-11-29 20:40 ` Andreas Leha
0 siblings, 0 replies; 6+ messages in thread
From: Andreas Leha @ 2014-11-29 20:40 UTC (permalink / raw)
To: emacs-orgmode
Grant Rettke <gcr@wisdomandwonder.com> writes:
> What a treat, sir, thank you for sharing that as if by some delightful
> magic, which surely it indeed is.
Many thanks also from my side!
>
> On Sat, Nov 29, 2014 at 4:38 AM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
>> Hello,
>>
>> Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>>
>>> Grant Rettke <gcr@wisdomandwonder.com> writes:
>>>> Good evening,
>>>>
>>>> My goal is to obtain the following behavior in org mode for a document:
>>>> 1) Report an error if there is a source block without a language
>>>> specified
>>>> 2) Report an error if there is a source block with a language specified
>>>> that is *not* present in `org-babel-load-languages'
>>>>
>>>> I've thought about ways to do this and come up with:
>>>> 1) Visually inspect the document
>>>> 2) Use `org-element' to parse and process the document
>>>
>>> I'd be interested in 2) if you come up with something here :-)
>>
>> (defun my-src-block-check ()
>> (interactive)
>> (org-element-map (org-element-parse-buffer 'element) 'src-block
>> (lambda (src-block)
>> (let ((language (org-element-property :language src-block)))
>> (cond ((null language)
>> (error "Missing language at position %d"
>> (org-element-property :post-affiliated src-block)))
>> ((not (assoc-string language org-babel-load-languages))
>> (error "Unknown language at position %d"
>> (org-element-property :post-affiliated src-block)))))))
>> (message "Source blocks checked in %s." (buffer-name (buffer-base-buffer))))
>>
>>
>> Regards,
>>
>> --
>> Nicolas Goaziou
>>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to inspect a document and check for the presence of source block language names and support
2014-11-29 10:38 ` Nicolas Goaziou
2014-11-29 14:42 ` Grant Rettke
@ 2015-02-03 9:55 ` Sebastien Vauban
1 sibling, 0 replies; 6+ messages in thread
From: Sebastien Vauban @ 2015-02-03 9:55 UTC (permalink / raw)
To: Nicolas Goaziou, Andreas Leha; +Cc: emacs-orgmode-mXXj517/zsQ
Hello,
Nicolas Goaziou wrote:
> Andreas Leha <andreas.leha-A1rZ2h3LdSKGMSlLMZIubhS11BummzK+@public.gmane.org> writes:
>> Grant Rettke <gcr-8CdBUMNg/Lm6M07oP3eFjEEOCMrvLtNR@public.gmane.org> writes:
>>>
>>> My goal is to obtain the following behavior in org mode for
>>> a document:
>>> 1) Report an error if there is a source block without a language
>>> specified
>>> 2) Report an error if there is a source block with a language
>>> specified that is *not* present in `org-babel-load-languages'
>>>
>>> I've thought about ways to do this and come up with:
>>> 1) Visually inspect the document
>>> 2) Use `org-element' to parse and process the document
>>
>> I'd be interested in 2) if you come up with something here :-)
>
> (defun my-src-block-check ()
> (interactive)
> (org-element-map (org-element-parse-buffer 'element) 'src-block
> (lambda (src-block)
> (let ((language (org-element-property :language src-block)))
> (cond ((null language)
> (error "Missing language at position %d"
> (org-element-property :post-affiliated src-block)))
> ((not (assoc-string language org-babel-load-languages))
> (error "Unknown language at position %d"
> (org-element-property :post-affiliated src-block)))))))
> (message "Source blocks checked in %s." (buffer-name (buffer-base-buffer))))
I've improved it in order to:
- Check as well for the language of inline code blocks,
- Report the line number instead of the char position.
--8<---------------cut here---------------start------------->8---
(defun org-src-block-check ()
(interactive)
(org-element-map (org-element-parse-buffer)
'(src-block inline-src-block)
(lambda (sb)
(let ((language (org-element-property :language sb)))
(cond ((null language)
(error "Missing language at line %d in %s"
(org-current-line
(org-element-property :post-affiliated sb))
(buffer-name)))
((not (assoc-string language org-babel-load-languages))
(error "Unknown language `%s' at line %d in `%s'"
language
(org-current-line
(org-element-property :post-affiliated sb))
(buffer-name)))))))
(message "Source blocks checked in %s." (buffer-name (buffer-base-buffer))))
--8<---------------cut here---------------end--------------->8---
Though, while the line number is often correct, it is not always!? Is
`org-current-line' the right function to call?
Besides that, I think we should check for such unknown languages if (and
only if) the code block is supposed to be executed.
For example, while I don't have a python interpreter on my machine
(hence, I want to be sure I never have executable python blocks in my
documents), I can have Org documentation that includes python blocks (as
examples, of just for tangling -- to be run on another machine). As
long as the code blocks don't have ":eval yes" somehow, this is OK, and
shouldn't be caught as an error. WDYT?
Best regards,
Seb
--
Sebastien Vauban
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-02-03 9:55 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-29 2:08 How to inspect a document and check for the presence of source block language names and support Grant Rettke
2014-11-29 2:22 ` Andreas Leha
2014-11-29 10:38 ` Nicolas Goaziou
2014-11-29 14:42 ` Grant Rettke
2014-11-29 20:40 ` Andreas Leha
2015-02-03 9:55 ` Sebastien Vauban
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.