emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Eric Schulte" <schulte.eric@gmail.com>
To: Carsten Dominik <carsten.dominik@gmail.com>
Cc: Emacs-orgmode mailing list <emacs-orgmode@gnu.org>
Subject: Re: [BUG] #+begin_src wo. language blocks XHTML export
Date: Mon, 12 Jul 2010 12:33:52 -0700	[thread overview]
Message-ID: <87fwzobii2.fsf@gmail.com> (raw)
In-Reply-To: 602AF50D-9053-4D34-A6CB-6CD0879376BA@gmail.com

Done -- Eric

Carsten Dominik <carsten.dominik@gmail.com> writes:

> Hi Eric,
>
> Please go ahead and apply it, Eric, and mark the first as
> superseded, the second as applied on the patchwork server.
>
> Thanks!
>
> - Carsten
>
> On Jul 12, 2010, at 7:44 PM, Eric Schulte wrote:
>
>> Carsten Dominik <carsten.dominik@gmail.com> writes:
>>
>>> On Jul 12, 2010, at 10:13 AM, David Maus wrote:
>>>
>>>> SEric Schulte wrote:
>>>>> "Thomas S. Dye" <tsd@tsdye.com> writes:
>>>>
>>>>>> On Jul 8, 2010, at 9:09 AM, Eric Schulte wrote:
>>>>>>
>>>>>>> Sebastian Rose <sebastian_rose@gmx.de> writes:
>>>>>>>
>>>>>>> [...]
>>>>>>>>
>>>>>>>> It can be considered an error, since the docs say:
>>>>>>>>
>>>>>>>> "...This is done with the ‘src’ block, where you also need to
>>>>>>>> specify the name of the major mode that should be used to
>>>>>>>> fontify
>>>>>>>> the example..."
>>>>>>>>
>>>>>>>
>>>>>>> I would vote that this be considered an error as a source block
>>>>>>> doesn't make sense w/o a source language.  If others agree with
>>>>>>> this
>>>>>>> interpretation, I would be happy to submit a patch which actively
>>>>>>> raises an errors when this cases is encountered.
>>>>>>>
>>>>>>> Cheers -- Eric
>>>>>>
>>>>>> This seems like the right approach to me.
>>>>>>
>>>>>> Tom
>>>>
>>>>> As promised here's a patch which raises errors when source blocks
>>>>> don't
>>>>> have a specified language.  I would prefer if the error could
>>>>> indicate
>>>>> which block caused the problem, but I don't know how to accomplish
>>>>> this.
>>>>
>>>> Maybe we could store a marker in a text property of (source) blocks
>>>> right before they are processed in the input file?
>>>
>>> The problem here is that during export, the source code is taken
>>> from a temporary buffer containing an already modifed copy of the
>>> original buffer.
>>>
>>> Another solution would be to include into the message is short
>>> part of the code itself (maybe the first line...) - this should
>>> make it possible to identify the problematic block reasonably easily.
>>>
>>> - Carsten
>>
>> The following updated patch includes the first line (up to 35
>> characters) of the code block in the error message.
>>
>> -- Eric
>>
>> From a76629a565920c3506f7046cc15d27ad01b8bd47 Mon Sep 17 00:00:00 2001
>> From: Eric Schulte <schulte.eric@gmail.com>
>> Date: Mon, 12 Jul 2010 10:42:59 -0700
>> Subject: [PATCH] org-exp: raise an error when trying to export code
>> blocks w/o languages
>>
>> * lisp/ob.el (org-babel-get-src-block-info): ensure that we don't
>>  match (and return info for) source blocks without a language
>>
>> * lisp/org-exp.el (org-export-replace-src-segments-and-examples):
>>  updated source code block regexp so that the presence of a language
>>  can be explicitly checked.  Also now raising an error when a source
>>  block does not have a language.
>> ---
>> lisp/ob.el      |    3 ++-
>> lisp/org-exp.el |   30 ++++++++++++++++++++----------
>> 2 files changed, 22 insertions(+), 11 deletions(-)
>>
>> diff --git a/lisp/ob.el b/lisp/ob.el
>> index 7b7be3d..d94cc06 100644
>> --- a/lisp/ob.el
>> +++ b/lisp/ob.el
>> @@ -143,7 +143,8 @@ added to the header-arguments-alist."
>> 	  (setq indent (car (last info)))
>> 	  (setq info (butlast info))
>> 	  (forward-line -1)
>> -	  (if (looking-at org-babel-src-name-w-name-regexp)
>> +	  (if (and (looking-at org-babel-src-name-w-name-regexp)
>> +		   (match-string 2))
>> 	      (progn
>> 		(setq info (append info (list (org-babel-clean-text-properties
>> 					       (match-string 2)))))
>> diff --git a/lisp/org-exp.el b/lisp/org-exp.el
>> index f1cea62..55b8812 100644
>> --- a/lisp/org-exp.el
>> +++ b/lisp/org-exp.el
>> @@ -2107,19 +2107,29 @@ in the list) and remove property and value
>> from the list in LISTVAR."
>> 	lang code trans opts indent caption)
>>     (goto-char (point-min))
>>     (while (re-search-forward
>> -	    "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^
>> \t\n]+\\)\\(.*\\)\n
>> \\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\
>> +BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\
>> +END_EXAMPLE.*\n?\\)"
>> +	    "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?\\([ \t]+\\([^
>> \t\n]+\\)\\)?\\
>> (.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\
>> \)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)
>> [ \t]*#\\+END_EXAMPLE.*\n?\\)"
>> 	    nil t)
>>       (if (match-end 1)
>> -	  ;; src segments
>> -	  (setq lang (match-string 3)
>> -		opts (match-string 4)
>> -		code (match-string 5)
>> -		indent (length (match-string 2))
>> -                caption (get-text-property 0 'org-caption (match-
>> string 0)))
>> +	  (if (not (match-string 4))
>> +	      (error "source block missing language specification: %s"
>> +		     (let* ((body (match-string 6))
>> +			    (nothing (message "body:%s" body))
>> +			    (preview (or (and (string-match
>> +					       "^[ \t]*\\([^\n\r]*\\)" body)
>> +					      (match-string 1 body)) body)))
>> +		       (if (> (length preview) 35)
>> +			   (concat (substring preview 0 32) "...")
>> +			 preview)))
>> +	    ;; src segments
>> +	    (setq lang (match-string 4)
>> +		  opts (match-string 5)
>> +		  code (match-string 6)
>> +		  indent (length (match-string 2))
>> +		  caption (get-text-property 0 'org-caption (match-string 0))))
>> 	(setq lang nil
>> -	      opts (match-string 8)
>> -	      code (match-string 9)
>> -	      indent (length (match-string 7))
>> +	      opts (match-string 9)
>> +	      code (match-string 10)
>> +	      indent (length (match-string 8))
>>               caption (get-text-property 0 'org-caption (match-
>> string 0))))
>>
>>       (setq trans (org-export-format-source-code-or-example
>> --
>> 1.7.0.4
>>
>
> - Carsten

      reply	other threads:[~2010-07-12 19:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-25 23:02 [BUG] #+begin_src wo. language blocks XHTML export Sebastian Rose
2010-07-04 14:11 ` David Maus
2010-07-04 22:10   ` Sebastian Rose
2010-07-05 14:56     ` David Maus
2010-07-08 19:09     ` Eric Schulte
2010-07-08 19:37       ` Thomas S. Dye
2010-07-10  4:32         ` Eric Schulte
2010-07-12  8:13           ` David Maus
2010-07-12  9:11             ` Carsten Dominik
2010-07-12 17:44               ` Eric Schulte
2010-07-12 18:12                 ` Carsten Dominik
2010-07-12 19:33                   ` Eric Schulte [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fwzobii2.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=carsten.dominik@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).