emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Martyn Jago <martyn.jago@btinternet.com>
To: emacs-orgmode@gnu.org
Subject: [babel] [PATCH]
Date: Fri, 25 Feb 2011 13:50:18 +0000	[thread overview]
Message-ID: <87y6548bqd.fsf@btinternet.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1132 bytes --]


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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: empty-block-tangle-test.org --]
[-- Type: text/x-org, Size: 1441 bytes --]


* 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  |


[-- Attachment #3: test-out-pre-patch --]
[-- Type: application/octet-stream, Size: 217 bytes --]


Block 1



#+END_SRC

*** Block 4 (Gets consumed by previous Block)

#+BEGIN_SRC sh :tangle test-out
Block 4

#+END_SRC

*** Block 6 (Gets consumed by previous Block

#+BEGIN_SRC sh :tangle test-out
Block 6

Block 7

[-- Attachment #4: test-out-post-patch --]
[-- Type: application/octet-stream, Size: 42 bytes --]


Block 1





Block 4



Block 6

Block 7

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: org-babel-src-block-regexp --]
[-- Type: text/x-diff, Size: 818 bytes --]

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

[-- Attachment #6: Type: text/plain, Size: 144 bytes --]


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 

[-- Attachment #7: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

             reply	other threads:[~2011-02-25 13:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-25 13:50 Martyn Jago [this message]
2011-02-27 22:02 ` [babel] [PATCH] Eric Schulte
2011-02-28 21:11   ` Martyn Jago
2011-03-01 17:06     ` Eric Schulte
2011-03-02 18:37       ` Martyn Jago
2011-03-02 18:45         ` Eric Schulte
2011-03-02 19:00           ` Martyn Jago

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=87y6548bqd.fsf@btinternet.com \
    --to=martyn.jago@btinternet.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).