From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martyn Jago Subject: [babel] [PATCH] Date: Fri, 25 Feb 2011 13:50:18 +0000 Message-ID: <87y6548bqd.fsf@btinternet.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from [140.186.70.92] (port=36615 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Psy48-00083U-TV for emacs-orgmode@gnu.org; Fri, 25 Feb 2011 08:50:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Psy47-000641-Gq for emacs-orgmode@gnu.org; Fri, 25 Feb 2011 08:50:40 -0500 Received: from lo.gmane.org ([80.91.229.12]:36974) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Psy47-00063a-5d for emacs-orgmode@gnu.org; Fri, 25 Feb 2011 08:50:39 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Psy43-0006Gl-Hj for emacs-orgmode@gnu.org; Fri, 25 Feb 2011 14:50:35 +0100 Received: from 88-96-171-142.dsl.zen.co.uk ([88.96.171.142]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 25 Feb 2011 14:50:35 +0100 Received: from martyn.jago by 88-96-171-142.dsl.zen.co.uk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 25 Feb 2011 14:50:35 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hi Babel I've been working on an exporter and have come across some strange behaviour regarding 'empty' source blocks with regard to tangling. If an attempt is made to tangle a block containing two blank (no white-space) lines, the block is exported as carriage returns (as I would expect). If a block contains one or no blank lines, the #+end_src tag appears to be consumed by the block (along with subsequent text upto the next #+end_src tag). I tracked this down to the org-babel-src-block-regexp variable in ob.el and have modified it to give what appears to be consistent behaviour. I also found the following unresolved bug report which may be related... http://www.mail-archive.com/emacs-orgmode@gnu.org/msg29992.html I've included a simple test file, and resultant tangled files before and after the patch to attempt to convey the problem. NOTE: Since the patch itself modifies a defvar, and since I'm not clear on how a patched defvar should be updated downstream, the patch includes a setq statement to update the defvar org-babel-src-block-regexp for test purposes. The patch cannot therefore be applied as is. --=-=-= Content-Type: text/x-org Content-Disposition: attachment; filename=empty-block-tangle-test.org Content-Description: empty-block-tangle-test.org * Empty Block Tangle Test ** Typical Execution #+BEGIN_SRC emacs-lisp :tangle no (org-babel-tangle) ; or org-babel-tangle-file "empty-block.org" #+END_SRC #+results: | test-out | ** Tests *** Block 1 (Exports OK) #+BEGIN_SRC sh :tangle test-out Block 1 #+END_SRC *** Block 2 (Exports OK - double blank line no white-space in Block) #+BEGIN_SRC sh :tangle test-out #+END_SRC *** Block 3 (Fails - single blank line no white-space in Block) #+BEGIN_SRC sh :tangle test-out #+END_SRC *** Block 4 (Gets consumed by previous Block) #+BEGIN_SRC sh :tangle test-out Block 4 #+END_SRC *** Block 5 (Fails - no lines in Block) #+BEGIN_SRC sh :tangle test-out #+END_SRC *** Block 6 (Gets consumed by previous Block #+BEGIN_SRC sh :tangle test-out Block 6 #+END_SRC *** Block 7 (Exports OK) #+BEGIN_SRC sh :tangle test-out Block 7 #+END_SRC ** List params #+begin_src emacs-lisp (sort* (mapcar (lambda (x) (list (car x) (cdr x))) params) 'string-lessp :key 'car) #+end_src #+results: | :cache | no | | :colname-names | nil | | :colnames | no | | :comments | | | :exports | results | | :hlines | yes | | :noweb | no | | :result-params | (replace) | | :result-type | value | | :results | replace | | :rowname-names | nil | | :session | none | | :shebang | | | :tangle | test-out | --=-=-= Content-Type: application/octet-stream Content-Disposition: attachment; filename=test-out-pre-patch Content-Transfer-Encoding: base64 Content-Description: test-out-pre-patch CkJsb2NrIDEKCgoKIytFTkRfU1JDCgoqKiogQmxvY2sgNCAoR2V0cyBjb25zdW1lZCBieSBwcmV2 aW91cyBCbG9jaykKCiMrQkVHSU5fU1JDIHNoIDp0YW5nbGUgdGVzdC1vdXQKQmxvY2sgNAoKIytF TkRfU1JDCgoqKiogQmxvY2sgNiAoR2V0cyBjb25zdW1lZCBieSBwcmV2aW91cyBCbG9jawoKIytC RUdJTl9TUkMgc2ggOnRhbmdsZSB0ZXN0LW91dApCbG9jayA2CgpCbG9jayA3Cg== --=-=-= Content-Type: application/octet-stream Content-Disposition: attachment; filename=test-out-post-patch Content-Transfer-Encoding: base64 Content-Description: test-out-post-patch CkJsb2NrIDEKCgoKCgpCbG9jayA0CgoKCkJsb2NrIDYKCkJsb2NrIDcK --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=org-babel-src-block-regexp.patch Content-Description: org-babel-src-block-regexp diff --git a/lisp/ob.el b/lisp/ob.el index 6e98263..6d2f0d0 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -138,9 +138,20 @@ remove code block execution from the C-c C-c keybinding." ;; (4) header arguments "\\([^\n]*\\)\n" ;; (5) body - "\\([^\000]+?\n\\)[ \t]*#\\+end_src") + "\\([^\000]*?\n*\\)[ \t]*#\\+end_src") "Regexp used to identify code blocks.") +(setq org-babel-src-block-regexp + (concat + ;; (1) indentation (2) lang + "^\\([ \t]*\\)#\\+begin_src[ \t]+\\([^ \f\t\n\r\v]+\\)[ \t]*" + ;; (3) switches + "\\([^\":\n]*\"[^\"\n*]*\"[^\":\n]*\\|[^\":\n]*\\)" + ;; (4) header arguments + "\\([^\n]*\\)\n" + ;; (5) body + "\\([^\000]*?\n*\\)[ \t]*#\\+end_src")) + (defvar org-babel-inline-src-block-regexp (concat ;; (1) replacement target (2) lang --=-=-= Content-Type: text/plain Regards Martyn --- Org-mode version 7.4 (release_7.4.529.gb23d) GNU Emacs 24.0.50.1 (i686-pc-linux-gnu, GTK+ Version 2.24.0) of 2011-02-25 --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-=--