emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel][PATCHES] exporting inline source code
@ 2014-06-13 17:37 Nicolas Berthier
  2014-06-22  4:02 ` Aaron Ecay
  0 siblings, 1 reply; 12+ messages in thread
From: Nicolas Berthier @ 2014-06-13 17:37 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi,

Please find attached two patches for review, related to the handling
of inline source code.

The first one enables babel to export pieces of inline source code as
inline instead of as standard code blocks as it currently does.  This
is done by adding a new template
(`org-babel-exp-inline-code-template', very similar to
`org-babel-exp-code-template' for standard code blocks), and modifying
`org-babel-exp-code' to either generate a code block or an inline one.

Also, as the generated code may not define any switches nor flags, we
might end up with org elements such as "src_emacs-lisp[]{(message
"foo!")}" during the babel pass.  I think the small modification I
made to `org-babel-inline-src-block-regexp' to allow such constructs
is much simpler than handling this particular case in
`org-babel-exp-code'.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-Support-for-exporting-inline-source-code.patch --]
[-- Type: text/x-patch, Size: 3796 bytes --]

From d6b99e92546a752419ff8b8bf919c7001e8e1ec2 Mon Sep 17 00:00:00 2001
From: Nicolas Berthier <nberth@member.fsf.org>
Date: Fri, 13 Jun 2014 15:32:54 +0200
Subject: [PATCH 1/2] ob: Support for exporting inline source code

* lisp/ob-exp.el (org-babel-exp-inline-code-template): New
customizable variable to export inline source code (similar to
`org-babel-exp-code-template').
(org-babel-exp-code): New `type' argument to differentiate between
inline and standard code blocks.

* lisp/ob-core.el (org-babel-inline-src-block-regexp): Allow empty set
of switches and header arguments as in "src_sh[]{echo foo;}".

Until now pieces of inline source code were handled as standard code
blocks during export.  These changes enable them to be exported.
---
 lisp/ob-core.el |  2 +-
 lisp/ob-exp.el  | 30 ++++++++++++++++++++++++++----
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index e1d4f39..062d4e1 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -203,7 +203,7 @@ This string must include a \"%s\" which will be replaced by the results."
 (defvar org-babel-inline-src-block-regexp
   (concat
    ;; (1) replacement target (2) lang
-   "\\(?:^\\|[^-[:alnum:]]\\)\\(src_\\([^ \f\t\n\r\v]+\\)"
+   "\\(?:^\\|[^-[:alnum:]]\\)\\(src_\\([^ \f\t\n\r\v\\[]+\\)"
    ;; (3,4) (unused, headers)
    "\\(\\|\\[\\(.*?\\)\\]\\)"
    ;; (5) body
diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index 3a47661..37625ab 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -318,10 +318,10 @@ The function respects the value of the :exports header argument."
 	(clean (lambda () (unless (eq type 'inline) (org-babel-remove-result info)))))
     (case (intern (or (cdr (assoc :exports (nth 2 info))) "code"))
       ('none (funcall silently) (funcall clean) "")
-      ('code (funcall silently) (funcall clean) (org-babel-exp-code info))
+      ('code (funcall silently) (funcall clean) (org-babel-exp-code info type))
       ('results (org-babel-exp-results info type nil hash) "")
       ('both (org-babel-exp-results info type nil hash)
-	     (org-babel-exp-code info)))))
+	     (org-babel-exp-code info type)))))
 
 (defcustom org-babel-exp-code-template
   "#+BEGIN_SRC %lang%switches%flags\n%body\n#+END_SRC"
@@ -343,7 +343,27 @@ replaced with its value."
   :group 'org-babel
   :type 'string)
 
-(defun org-babel-exp-code (info)
+(defcustom org-babel-exp-inline-code-template
+  "src_%lang[%switches%flags]{%body}"
+  "Template used to export the body of inline code blocks.
+This template may be customized to include additional information
+such as the code block name, or the values of particular header
+arguments.  The template is filled out using `org-fill-template',
+and the following %keys may be used.
+
+ lang ------ the language of the code block
+ name ------ the name of the code block
+ body ------ the body of the code block
+ switches -- the switches associated to the code block
+ flags ----- the flags passed to the code block
+
+In addition to the keys mentioned above, every header argument
+defined for the code block may be used as a key and will be
+replaced with its value."
+  :group 'org-babel
+  :type 'string)
+
+(defun org-babel-exp-code (info type)
   "Return the original code block formatted for export."
   (setf (nth 1 info)
 	(if (string= "strip-export" (cdr (assoc :noweb (nth 2 info))))
@@ -354,7 +374,9 @@ replaced with its value."
 	       info org-babel-exp-reference-buffer)
 	    (nth 1 info))))
   (org-fill-template
-   org-babel-exp-code-template
+   (if (eq type 'inline)
+       org-babel-exp-inline-code-template 
+       org-babel-exp-code-template)
    `(("lang"  . ,(nth 0 info))
      ("body"  . ,(org-escape-code-in-string (nth 1 info)))
      ("switches" . ,(let ((f (nth 3 info)))
-- 
2.0.0.rc4


[-- Attachment #3: Type: text/plain, Size: 81 bytes --]


The second patch implements the transcoding of inline source blocks
into HTML.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0002-ox-html.el-Support-for-exporting-inline-source-code-.patch --]
[-- Type: text/x-patch, Size: 1388 bytes --]

From 2ce230d0dda6869b4d91a4a27d40d62fdb0593d2 Mon Sep 17 00:00:00 2001
From: Nicolas Berthier <nberth@member.fsf.org>
Date: Fri, 13 Jun 2014 16:39:18 +0200
Subject: [PATCH 2/2] ox-html.el: Support for exporting inline source code to
 HTML

* lisp/ox-html.el (org-html-inline-src-block): support for exporting
inline source code to HTML.
---
 lisp/ox-html.el | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 762e1dc..7ece2a9 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2482,7 +2482,17 @@ CONTENTS holds the contents of the item.  INFO is a plist holding
 contextual information."
   (let* ((org-lang (org-element-property :language inline-src-block))
 	 (code (org-element-property :value inline-src-block)))
-    (error "Cannot export inline src block")))
+    (let ((lang (org-element-property :language inline-src-block))
+	  (code (org-html-format-code inline-src-block info))
+	  (label (let ((lbl (org-element-property :name inline-src-block)))
+		   (if (not lbl) ""
+		     (format " id=\"%s\""
+			     (org-export-solidify-link-text lbl))))))
+      (if lang
+	  (format "<code style=\"display: inline\" class=\"src src-%s\"%s>%s</code>" 
+		  lang label code)
+	  (format "<code style=\"display: inline\" class=\"example\"%s>\n%s</code>"
+		  label code)))))
 
 ;;;; Inlinetask
 
-- 
2.0.0.rc4


[-- Attachment #5: Type: text/plain, Size: 1063 bytes --]


These patches allow to handle the following piece of Org code, and
then to export it in both LaTeX (both with and without evaluating the
`setup' code block) and HTML.

#+BEGIN_SRC org
  ,#+TITLE: Testing inline code blocks

  The following code and its result
  src_emacs-lisp[:exports both]{(message "foo!")}
  should be inline.

  The following src_sh[:exports code]{eval `cat ~/.emacs`;} should also
  be inline.

  Ibid for src_emacs-lisp[:exports code]{(let ((x 10)) (< (* x 3) 2))}
  and src_emacs-lisp[:exports both]{(message "foo!\nbar!")} (as
  expected?).

  ,* COMMENT setup
  ,#+NAME: setup
  ,#+BEGIN_SRC emacs-lisp :exports code :results silent
    (eval-after-load "ox-latex"
      '(progn
        (set (make-local-variable 'org-latex-listings) t)
        (add-to-list (make-local-variable 'org-latex-packages-alist)
         '("" "listings"))))
  ,#+END_SRC

#+END_SRC

I have started the FSF copyright assignment process, in case these
patches are accepted.

Nicolas

-- 
Nicolas Berthier                                        FSF Member #7975

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

* Re: [babel][PATCHES] exporting inline source code
  2014-06-13 17:37 [babel][PATCHES] exporting inline source code Nicolas Berthier
@ 2014-06-22  4:02 ` Aaron Ecay
  2014-07-27 17:23   ` Bastien
  0 siblings, 1 reply; 12+ messages in thread
From: Aaron Ecay @ 2014-06-22  4:02 UTC (permalink / raw)
  To: Nicolas Berthier, emacs-orgmode

Hi Nicolas,

These both seem like good patches to me.  Did you run the test suite to
make sure that no tests are broken by them?  It would also be good if
you added some tests for this functionality – the example included at
the bottom of your email is a good starting point.  The other babel
export tests live in the file testing/lisp/test-ob-exp.el, so that’s the
spot to look for examples.

Have you heard back from the FSF about your copyright assignment?

Thanks for the patches,

-- 
Aaron Ecay

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

* Re: [babel][PATCHES] exporting inline source code
  2014-06-22  4:02 ` Aaron Ecay
@ 2014-07-27 17:23   ` Bastien
  2014-07-29  7:40     ` Nicolas Berthier
  0 siblings, 1 reply; 12+ messages in thread
From: Bastien @ 2014-07-27 17:23 UTC (permalink / raw)
  To: Aaron Ecay; +Cc: emacs-orgmode, Nicolas Berthier

Hi,

Aaron Ecay <aaronecay@gmail.com> writes:

> Have you heard back from the FSF about your copyright assignment?

This is more than 5 weeks since the patches were sent, so I hope the
FSF sent the papers.

Nicolas, let us know so that we can move forward on this.

Thanks,

-- 
 Bastien

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

* Re: [babel][PATCHES] exporting inline source code
  2014-07-27 17:23   ` Bastien
@ 2014-07-29  7:40     ` Nicolas Berthier
  2014-07-29 13:19       ` Bastien
  0 siblings, 1 reply; 12+ messages in thread
From: Nicolas Berthier @ 2014-07-29  7:40 UTC (permalink / raw)
  To: Bastien; +Cc: Aaron Ecay, emacs-orgmode, Nicolas Berthier

You wrote:

> Hi,
>
> Aaron Ecay <aaronecay@gmail.com> writes:
>
>> Have you heard back from the FSF about your copyright assignment?
>
> This is more than 5 weeks since the patches were sent, so I hope the
> FSF sent the papers.
>
> Nicolas, let us know so that we can move forward on this.
>
> Thanks,

Hi,

I have signed the paper, and sent it back to the FSF's assignment
administrator one or two weeks ago, but did not hear anything about that
since.  I will investigate on this ASAP, and notice you when I receive
a confirmation that the FSF signed it.

Regards,

-- 
Nicolas Berthier                                        FSF Member #7975

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

* Re: [babel][PATCHES] exporting inline source code
  2014-07-29  7:40     ` Nicolas Berthier
@ 2014-07-29 13:19       ` Bastien
  2014-07-30 16:06         ` Nicolas Berthier
  0 siblings, 1 reply; 12+ messages in thread
From: Bastien @ 2014-07-29 13:19 UTC (permalink / raw)
  To: Nicolas Berthier; +Cc: Aaron Ecay, emacs-orgmode

Hi Nicolas,

Nicolas Berthier <nberth@member.fsf.org> writes:

> I will investigate on this ASAP, and notice you when I receive
> a confirmation that the FSF signed it.

Thanks, we should expect longer delays during the summer I guess.

-- 
 Bastien

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

* Re: [babel][PATCHES] exporting inline source code
  2014-07-29 13:19       ` Bastien
@ 2014-07-30 16:06         ` Nicolas Berthier
  2014-07-30 19:26           ` Nicolas Goaziou
  0 siblings, 1 reply; 12+ messages in thread
From: Nicolas Berthier @ 2014-07-30 16:06 UTC (permalink / raw)
  To: Bastien; +Cc: Aaron Ecay, emacs-orgmode, Nicolas Berthier

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

You wrote:

> Hi Nicolas,
>
> Nicolas Berthier <nberth@member.fsf.org> writes:
>
>> I will investigate on this ASAP, and notice you when I receive
>> a confirmation that the FSF signed it.
>
> Thanks, we should expect longer delays during the summer I guess.

Hi,

I received the confirmation form the FSF today (should I forward it to
some of you?).

In any case, as advised earlier in the discussion, I updated one patch
to integrate new tests for the new feature. I also slightly simplified
the HTML export patch to avoid useless display attributes.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-Support-for-exporting-inline-source-code.patch --]
[-- Type: text/x-patch, Size: 11114 bytes --]

From 00fc0209ba50587075e4cf271d1b9a3612574562 Mon Sep 17 00:00:00 2001
From: Nicolas Berthier <nberth@member.fsf.org>
Date: Fri, 13 Jun 2014 15:32:54 +0200
Subject: [PATCH 1/2] ob: Support for exporting inline source code

* lisp/ob-exp.el (org-babel-exp-inline-code-template): New
customizable variable to export inline source code (similar to
`org-babel-exp-code-template').
(org-babel-exp-code): New `type' argument to differentiate between
inline and standard code blocks.

* lisp/ob-core.el (org-babel-inline-src-block-regexp): Allow empty set
of switches and header arguments as in "src_sh[]{echo foo;}".

* testing/lisp/test-ob-exp.el (ob-exp/exports-inline-code): New
function for testing inline source code handling.

* testing/lisp/test-ob.el
(test-org-babel/org-babel-get-inline-src-block-matches): Test for
inline source blocks with empty header arguments.

* testing/examples/babel.org: New sections for testing (i) exported
inline source code (used by `ob-exp/exports-inline-code'); (ii)
parsing inline source blocks with empty header arguments (used by
`test-org-babel/org-babel-get-inline-src-block-matches').

Until now pieces of inline source code were handled as standard code
blocks during export.  These changes enable them to be exported.
---
 lisp/ob-core.el             |  2 +-
 lisp/ob-exp.el              | 30 ++++++++++++++++---
 testing/examples/babel.org  | 22 ++++++++++++++
 testing/lisp/test-ob-exp.el | 14 +++++++++
 testing/lisp/test-ob.el     | 71 ++++++++++++++++++++++++++-------------------
 5 files changed, 104 insertions(+), 35 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index ccc0878..08d4c65 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -203,7 +203,7 @@ This string must include a \"%s\" which will be replaced by the results."
 (defvar org-babel-inline-src-block-regexp
   (concat
    ;; (1) replacement target (2) lang
-   "\\(?:^\\|[^-[:alnum:]]\\)\\(src_\\([^ \f\t\n\r\v]+\\)"
+   "\\(?:^\\|[^-[:alnum:]]\\)\\(src_\\([^ \f\t\n\r\v\\[]+\\)"
    ;; (3,4) (unused, headers)
    "\\(\\|\\[\\(.*?\\)\\]\\)"
    ;; (5) body
diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index 3a47661..37625ab 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -318,10 +318,10 @@ The function respects the value of the :exports header argument."
 	(clean (lambda () (unless (eq type 'inline) (org-babel-remove-result info)))))
     (case (intern (or (cdr (assoc :exports (nth 2 info))) "code"))
       ('none (funcall silently) (funcall clean) "")
-      ('code (funcall silently) (funcall clean) (org-babel-exp-code info))
+      ('code (funcall silently) (funcall clean) (org-babel-exp-code info type))
       ('results (org-babel-exp-results info type nil hash) "")
       ('both (org-babel-exp-results info type nil hash)
-	     (org-babel-exp-code info)))))
+	     (org-babel-exp-code info type)))))
 
 (defcustom org-babel-exp-code-template
   "#+BEGIN_SRC %lang%switches%flags\n%body\n#+END_SRC"
@@ -343,7 +343,27 @@ replaced with its value."
   :group 'org-babel
   :type 'string)
 
-(defun org-babel-exp-code (info)
+(defcustom org-babel-exp-inline-code-template
+  "src_%lang[%switches%flags]{%body}"
+  "Template used to export the body of inline code blocks.
+This template may be customized to include additional information
+such as the code block name, or the values of particular header
+arguments.  The template is filled out using `org-fill-template',
+and the following %keys may be used.
+
+ lang ------ the language of the code block
+ name ------ the name of the code block
+ body ------ the body of the code block
+ switches -- the switches associated to the code block
+ flags ----- the flags passed to the code block
+
+In addition to the keys mentioned above, every header argument
+defined for the code block may be used as a key and will be
+replaced with its value."
+  :group 'org-babel
+  :type 'string)
+
+(defun org-babel-exp-code (info type)
   "Return the original code block formatted for export."
   (setf (nth 1 info)
 	(if (string= "strip-export" (cdr (assoc :noweb (nth 2 info))))
@@ -354,7 +374,9 @@ replaced with its value."
 	       info org-babel-exp-reference-buffer)
 	    (nth 1 info))))
   (org-fill-template
-   org-babel-exp-code-template
+   (if (eq type 'inline)
+       org-babel-exp-inline-code-template 
+       org-babel-exp-code-template)
    `(("lang"  . ,(nth 0 info))
      ("body"  . ,(org-escape-code-in-string (nth 1 info)))
      ("switches" . ,(let ((f (nth 3 info)))
diff --git a/testing/examples/babel.org b/testing/examples/babel.org
index a8015d1..8bae65b 100644
--- a/testing/examples/babel.org
+++ b/testing/examples/babel.org
@@ -200,6 +200,17 @@ Here is one in the middle src_sh{echo 1} of a line.
 Here is one at the end of a line. src_sh{echo 2}
 src_sh{echo 3} Here is one at the beginning of a line.
 
+* exported inline source block
+:PROPERTIES:
+:ID:       cd54fc88-1b6b-45b6-8511-4d8fa7fc8076
+:results:  silent
+:exports:  code
+:END:
+Here is one in the middle src_sh{echo 1} of a line.
+Here is one at the end of a line. src_sh{echo 2}
+src_sh{echo 3} Here is one at the beginning of a line.
+Here is one that is also evaluated: src_sh[:exports both]{echo 4}
+
 * mixed blocks with exports both
   :PROPERTIES:
   :ID:       5daa4d03-e3ea-46b7-b093-62c1b7632df3
@@ -283,6 +294,17 @@ src_sh{echo "One"} block at start of line
  One spaced block in  src_sh{ echo "middle" } of line
 src_sh{echo 2} blocks on the src_emacs-lisp{"same"} line
  Inline block with src_sh[:results silent]{ echo "parameters" }.
+
+* org-babel-get-inline-src-block-matches (with empty args)
+  :PROPERTIES:
+  :results:  silent
+  :ID:       d55dada7-de0e-4340-8061-787cccbedee5
+  :END:
+src_sh[]{echo "One"} block at start of line
+ One spaced block in  src_sh[]{ echo "middle" } of line
+src_sh[]{echo 2} blocks on the src_emacs-lisp[]{"same"} line
+ Inline block with src_sh[:results silent]{ echo "parameters" }.
+
 * exporting a code block with a name
   :PROPERTIES:
   :ID:       b02ddd8a-eeb8-42ab-8664-8a759e6f43d9
diff --git a/testing/lisp/test-ob-exp.el b/testing/lisp/test-ob-exp.el
index 1fe810b..b2d4958 100644
--- a/testing/lisp/test-ob-exp.el
+++ b/testing/lisp/test-ob-exp.el
@@ -197,6 +197,20 @@ Here is one at the end of a line. =2=
       (org-narrow-to-subtree)
       (org-test-with-expanded-babel-code (buffer-string))))))
 
+(ert-deftest ob-exp/exports-inline-code ()
+  (should
+   (string-match
+    (replace-regexp-in-string
+     "\\\\\\[]{" "\\(?:\\[]\\)?{" ;accept both src_sh[]{...} or src_sh{...}
+     (regexp-quote "Here is one in the middle src_sh[]{echo 1} of a line.
+Here is one at the end of a line. src_sh[]{echo 2}
+src_sh[]{echo 3} Here is one at the beginning of a line.
+Here is one that is also evaluated: src_sh[]{echo 4} =4=")
+     nil t)
+    (org-test-at-id "cd54fc88-1b6b-45b6-8511-4d8fa7fc8076"
+      (org-narrow-to-subtree)
+      (org-test-with-expanded-babel-code (buffer-string))))))
+
 (ert-deftest ob-exp/export-call-line-information ()
   (org-test-at-id "bec63a04-491e-4caa-97f5-108f3020365c"
     (org-narrow-to-subtree)
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index 1162162..fdb5a3e 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -249,38 +249,49 @@ this is simple"
     (should (= 14 (org-babel-execute-src-block)))))
 
 (ert-deftest test-org-babel/inline-src-blocks ()
-  (org-test-at-id "54cb8dc3-298c-4883-a933-029b3c9d4b18"
-    (macrolet ((at-next (&rest body)
-			`(progn
-			   (move-end-of-line 1)
-			   (re-search-forward org-babel-inline-src-block-regexp nil t)
-			   (goto-char (match-beginning 1))
-			   (save-match-data ,@body))))
-      (at-next (should (equal 1 (org-babel-execute-src-block))))
-      (at-next (should (equal 2 (org-babel-execute-src-block))))
-      (at-next (should (equal 3 (org-babel-execute-src-block)))))))
+  (macrolet ((at-next (&rest body)
+	       `(progn
+		  (move-end-of-line 1)
+		  (re-search-forward org-babel-inline-src-block-regexp nil t)
+		  (goto-char (match-beginning 1))
+		  (save-match-data ,@body))))
+    (org-test-at-id
+     "54cb8dc3-298c-4883-a933-029b3c9d4b18"
+     (at-next (should (equal 1 (org-babel-execute-src-block))))
+     (at-next (should (equal 2 (org-babel-execute-src-block))))
+     (at-next (should (equal 3 (org-babel-execute-src-block)))))
+    (org-test-at-id
+     "cd54fc88-1b6b-45b6-8511-4d8fa7fc8076"
+     (at-next (should (equal 1 (org-babel-execute-src-block))))
+     (at-next (should (equal 2 (org-babel-execute-src-block))))
+     (at-next (should (equal 3 (org-babel-execute-src-block))))
+     (at-next (should (equal 4 (org-babel-execute-src-block)))))))
 
 (ert-deftest test-org-babel/org-babel-get-inline-src-block-matches ()
-  (org-test-at-id "0D0983D4-DE33-400A-8A05-A225A567BC74"
-    (let ((test-point (point)))
-      (should (fboundp 'org-babel-get-inline-src-block-matches))
-      (should (re-search-forward "src_" nil t)) ;; 1
-      (should (org-babel-get-inline-src-block-matches))
-      (should (re-search-forward "}" nil (point-at-bol))) ;; 1
-      (should-not (org-babel-get-inline-src-block-matches))
-      (should (re-search-forward "in" nil t)) ;; 2
-      (should-not (org-babel-get-inline-src-block-matches))
-      (should (re-search-forward "echo" nil t)) ;; 2
-      (should (org-babel-get-inline-src-block-matches))
-      (should (re-search-forward "blocks" nil t)) ;; 3
-      (backward-char 8) ;; 3
-      (should (org-babel-get-inline-src-block-matches))
-      (forward-char 1) ;;3
-      (should-not (org-babel-get-inline-src-block-matches))
-      (should (re-search-forward ":results" nil t)) ;; 4
-      (should (org-babel-get-inline-src-block-matches))
-      (end-of-line)
-      (should-not (org-babel-get-inline-src-block-matches)))))
+  (flet ((test-at-id (id)
+	   (org-test-at-id 
+	    id
+	    (let ((test-point (point)))
+	      (should (fboundp 'org-babel-get-inline-src-block-matches))
+	      (should (re-search-forward "src_" nil t)) ;; 1
+	      (should (org-babel-get-inline-src-block-matches))
+	      (should (re-search-forward "}" nil (point-at-bol))) ;; 1
+	      (should-not (org-babel-get-inline-src-block-matches))
+	      (should (re-search-forward "in" nil t)) ;; 2
+	      (should-not (org-babel-get-inline-src-block-matches))
+	      (should (re-search-forward "echo" nil t)) ;; 2
+	      (should (org-babel-get-inline-src-block-matches))
+	      (should (re-search-forward "blocks" nil t)) ;; 3
+	      (backward-char 8) ;; 3
+	      (should (org-babel-get-inline-src-block-matches))
+	      (forward-char 1) ;;3
+	      (should-not (org-babel-get-inline-src-block-matches))
+	      (should (re-search-forward ":results" nil t)) ;; 4
+	      (should (org-babel-get-inline-src-block-matches))
+	      (end-of-line)
+	      (should-not (org-babel-get-inline-src-block-matches))))))
+    (test-at-id "0D0983D4-DE33-400A-8A05-A225A567BC74")
+    (test-at-id "d55dada7-de0e-4340-8061-787cccbedee5")))
 
 (ert-deftest test-org-babel/inline-src_blk-default-results-replace-line-1 ()
   (let ((test-line "src_sh{echo 1}"))
-- 
2.0.0.rc4


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-ox-html-Support-for-exporting-inline-source-code-to-.patch --]
[-- Type: text/x-patch, Size: 1318 bytes --]

From 41841fa8c318302884f201c9c0d39c8ebd31d0df Mon Sep 17 00:00:00 2001
From: Nicolas Berthier <nberth@member.fsf.org>
Date: Fri, 13 Jun 2014 16:39:18 +0200
Subject: [PATCH 2/2] ox-html: Support for exporting inline source code to HTML

* lisp/ox-html.el (org-html-inline-src-block): support for exporting
inline source code to HTML.
---
 lisp/ox-html.el | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index af4232c..6cc030c 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2411,7 +2411,15 @@ CONTENTS holds the contents of the item.  INFO is a plist holding
 contextual information."
   (let* ((org-lang (org-element-property :language inline-src-block))
 	 (code (org-element-property :value inline-src-block)))
-    (error "Cannot export inline src block")))
+    (let ((lang (org-element-property :language inline-src-block))
+	  (code (org-html-format-code inline-src-block info))
+	  (label (let ((lbl (org-element-property :name inline-src-block)))
+		   (if (not lbl) ""
+		     (format " id=\"%s\""
+			     (org-export-solidify-link-text lbl))))))
+      (if lang
+	  (format "<code class=\"src src-%s\"%s>%s</code>" lang label code)
+	  (format "<code class=\"example\"%s>\n%s</code>" label code)))))
 
 ;;;; Inlinetask
 
-- 
2.0.0.rc4


[-- Attachment #4: Type: text/plain, Size: 88 bytes --]


Regards,

-- 
Nicolas Berthier                                        FSF Member #7975

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

* Re: [babel][PATCHES] exporting inline source code
  2014-07-30 16:06         ` Nicolas Berthier
@ 2014-07-30 19:26           ` Nicolas Goaziou
  2014-07-30 20:01             ` Achim Gratz
  2014-08-01 12:23             ` Nicolas Berthier
  0 siblings, 2 replies; 12+ messages in thread
From: Nicolas Goaziou @ 2014-07-30 19:26 UTC (permalink / raw)
  To: Nicolas Berthier; +Cc: Bastien, Aaron Ecay, emacs-orgmode

Hello,

Nicolas Berthier <nberth@member.fsf.org> writes:

> In any case, as advised earlier in the discussion, I updated one patch
> to integrate new tests for the new feature. I also slightly simplified
> the HTML export patch to avoid useless display attributes.

Thank you for this nice patch. Some comments follow.

> +   "\\(?:^\\|[^-[:alnum:]]\\)\\(src_\\([^ \f\t\n\r\v\\[]+\\)"

I think "[^ \f\t\n\r\v[]" is enough.

> +(defcustom org-babel-exp-inline-code-template
> +  "src_%lang[%switches%flags]{%body}"
> +  "Template used to export the body of inline code blocks.
> +This template may be customized to include additional information
> +such as the code block name, or the values of particular header
> +arguments.  The template is filled out using `org-fill-template',
> +and the following %keys may be used.
> +
> + lang ------ the language of the code block
> + name ------ the name of the code block
> + body ------ the body of the code block
> + switches -- the switches associated to the code block
> + flags ----- the flags passed to the code block
> +
> +In addition to the keys mentioned above, every header argument
> +defined for the code block may be used as a key and will be
> +replaced with its value."
> +  :group 'org-babel
> +  :type 'string)

You need to add :version and :package-version values for new defcustoms.

> +(ert-deftest ob-exp/exports-inline-code ()
> +  (should
> +   (string-match
> +    (replace-regexp-in-string
> +     "\\\\\\[]{" "\\(?:\\[]\\)?{" ;accept both src_sh[]{...} or src_sh{...}
> +     (regexp-quote "Here is one in the middle src_sh[]{echo 1} of a line.
> +Here is one at the end of a line. src_sh[]{echo 2}
> +src_sh[]{echo 3} Here is one at the beginning of a line.
> +Here is one that is also evaluated: src_sh[]{echo 4} =4=")
> +     nil t)
> +    (org-test-at-id "cd54fc88-1b6b-45b6-8511-4d8fa7fc8076"
> +      (org-narrow-to-subtree)
> +      (org-test-with-expanded-babel-code (buffer-string))))))

It is a matter of taste, but I think tests should be self-contained. In
particular, it isn't fun debugging `org-test-at-id'. The same goes for
other tests.

> +      (if lang
> +	  (format "<code class=\"src src-%s\"%s>%s</code>" lang label code)
> +	  (format "<code class=\"example\"%s>\n%s</code>" label code)))))

LANG cannot be nil. So,

  (format "<code class=\"src src-%s\"%s>%s</code>" lang label code)

is sufficient.


Regards,

-- 
Nicolas Goaziou

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

* Re: [babel][PATCHES] exporting inline source code
  2014-07-30 19:26           ` Nicolas Goaziou
@ 2014-07-30 20:01             ` Achim Gratz
  2014-07-30 20:23               ` Nicolas Goaziou
  2014-08-01 12:23             ` Nicolas Berthier
  1 sibling, 1 reply; 12+ messages in thread
From: Achim Gratz @ 2014-07-30 20:01 UTC (permalink / raw)
  To: emacs-orgmode

Nicolas Goaziou writes:
>> +   "\\(?:^\\|[^-[:alnum:]]\\)\\(src_\\([^ \f\t\n\r\v\\[]+\\)"
>
> I think "[^ \f\t\n\r\v[]" is enough.

Yes.  But looking at the original regex has me wondering if the need for
the extra '[' isn't an indication of something more fundamentally wrong
with it.  Where does that need to have unused groups and groups that
match the empty string come from?


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

SD adaptations for KORG EX-800 and Poly-800MkII V0.9:
http://Synth.Stromeko.net/Downloads.html#KorgSDada

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

* Re: [babel][PATCHES] exporting inline source code
  2014-07-30 20:01             ` Achim Gratz
@ 2014-07-30 20:23               ` Nicolas Goaziou
  0 siblings, 0 replies; 12+ messages in thread
From: Nicolas Goaziou @ 2014-07-30 20:23 UTC (permalink / raw)
  To: Achim Gratz; +Cc: emacs-orgmode

Hello,

Achim Gratz <Stromeko@nexgo.de> writes:

> Yes.  But looking at the original regex has me wondering if the need for
> the extra '[' isn't an indication of something more fundamentally wrong
> with it.

[^ \f\t\n\r\v] is wrong as character set allowed for languages should be
much more limited than that. I discussed it with Eric some months ago.

> Where does that need to have unused groups and groups that match the
> empty string come from?

This is probably to prevent matching

  thisisasrc_emacs-list{}


Regards,

-- 
Nicolas Goaziou

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

* Re: [babel][PATCHES] exporting inline source code
  2014-07-30 19:26           ` Nicolas Goaziou
  2014-07-30 20:01             ` Achim Gratz
@ 2014-08-01 12:23             ` Nicolas Berthier
  2014-08-22 12:47               ` Nicolas Goaziou
  1 sibling, 1 reply; 12+ messages in thread
From: Nicolas Berthier @ 2014-08-01 12:23 UTC (permalink / raw)
  To: emacs-orgmode

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

Nicolas Goaziou wrote:

> Hello,
>
> Nicolas Berthier <nberth@member.fsf.org> writes:
>
>> In any case, as advised earlier in the discussion, I updated one patch
>> to integrate new tests for the new feature. I also slightly simplified
>> the HTML export patch to avoid useless display attributes.
>
> Thank you for this nice patch. Some comments follow.
>
>> +   "\\(?:^\\|[^-[:alnum:]]\\)\\(src_\\([^ \f\t\n\r\v\\[]+\\)"
>
> I think "[^ \f\t\n\r\v[]" is enough.

Indeed.  I fixed it in the new attached patch.  Thanks.

As for the definition of what enters into a language name, I suggest
leaving it for a subsequent modification as it's not the intended goal
of this patch.

>> +(defcustom org-babel-exp-inline-code-template
>> +  "src_%lang[%switches%flags]{%body}"
>> +  "Template used to export the body of inline code blocks.
>> +This template may be customized to include additional information
>> +such as the code block name, or the values of particular header
>> +arguments.  The template is filled out using `org-fill-template',
>> +and the following %keys may be used.
>> +
>> + lang ------ the language of the code block
>> + name ------ the name of the code block
>> + body ------ the body of the code block
>> + switches -- the switches associated to the code block
>> + flags ----- the flags passed to the code block
>> +
>> +In addition to the keys mentioned above, every header argument
>> +defined for the code block may be used as a key and will be
>> +replaced with its value."
>> +  :group 'org-babel
>> +  :type 'string)
>
> You need to add :version and :package-version values for new defcustoms.

Fixed with what I assume are the correct version numbers.  Correct me if
they are wrong.

>> +(ert-deftest ob-exp/exports-inline-code ()
>> +  (should
>> +   (string-match
>> +    (replace-regexp-in-string
>> +     "\\\\\\[]{" "\\(?:\\[]\\)?{" ;accept both src_sh[]{...} or src_sh{...}
>> +     (regexp-quote "Here is one in the middle src_sh[]{echo 1} of a line.
>> +Here is one at the end of a line. src_sh[]{echo 2}
>> +src_sh[]{echo 3} Here is one at the beginning of a line.
>> +Here is one that is also evaluated: src_sh[]{echo 4} =4=")
>> +     nil t)
>> +    (org-test-at-id "cd54fc88-1b6b-45b6-8511-4d8fa7fc8076"
>> +      (org-narrow-to-subtree)
>> +      (org-test-with-expanded-babel-code (buffer-string))))))
>
> It is a matter of taste, but I think tests should be self-contained. In
> particular, it isn't fun debugging `org-test-at-id'. The same goes for
> other tests.

New tests in "testing/lisp/test-ob.el" are akin already existing tests
in this file that were easy to adapt.  Considering that the patch adds
mostly export-related plus minor syntactic stuff, I think testing babel
evaluation itself is not as critical as testing the babel export
functionality w.r.t the inline code export, and the org-element parser
w.r.t the new syntax.  So, I did not add self-contained tests in
"test-ob.el" itself, and concentrated on "test-ob-exp.el" and
"test-org-element.el".  Then, the new patch adds some more
self-contained tests to ease debugging simple cases, as well as basic
tests for the inline source block parser in
`test-org-element/inline-src-block-parser'.

Besides, adding new tests made me encounter two unexpected results
during export:

- First, I discovered that the data resulting from calls to
  `org-babel-parse-header-arguments' were malformed when it was called
  with strings starting with a single space (e.g., " :foo bar") as it
  led to `(intern "")' calls in this function (leading to errors in some
  other place).

  For now, I fixed it in the first patch by further extending
  `org-babel-inline-src-block-regexp' to wipe out all spaces before the
  headers matching group (as `org-babel-src-block-regexp' does), even
  though handling cases where `arg' equals "" in
  `org-babel-parse-header-arguments' may be a cleaner solution;

- Secondly, wrapping of results when exporting code with ":results code"
  switches (as in "src_emacs-lisp[:exports results :results code]{(+
  1 1)}") led to unexpected results.  I doubt writing such kind of thing
  is actually useful, but it does not seem to cost too much to handle
  simple cases anyway.  I added two new failing tests to exhibit such
  cases in the first patch, and attached a third patch fixing this
  problem.  However, I am not even sure about the results that ought to
  be expected from the export of such code blocks, and it is still easy
  to find code blocks that break it (if only by writing code printing
  newlines).

All tests pass after each patch.

>> +      (if lang
>> +	  (format "<code class=\"src src-%s\"%s>%s</code>" lang label code)
>> +	  (format "<code class=\"example\"%s>\n%s</code>" label code)))))
>
> LANG cannot be nil. So,
>
>   (format "<code class=\"src src-%s\"%s>%s</code>" lang label code)
>
> is sufficient.

Done. Thanks.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-Support-for-exporting-inline-source-code.patch --]
[-- Type: text/x-patch, Size: 16009 bytes --]

From 66f602987e6479e73e13e78235c9a7f6316e1a7d Mon Sep 17 00:00:00 2001
From: Nicolas Berthier <nberth@member.fsf.org>
Date: Fri, 13 Jun 2014 15:32:54 +0200
Subject: [PATCH 1/3] ob: Support for exporting inline source code

* lisp/ob-exp.el (org-babel-exp-inline-code-template): New
customizable variable to export inline source code (similar to
`org-babel-exp-code-template').
(org-babel-exp-code): New `type' argument to differentiate between
inline and standard code blocks.

* lisp/ob-core.el (org-babel-inline-src-block-regexp): Allow empty set
of switches and header arguments as in "src_sh[]{echo foo;}".  Also
permit spaces before them.

* testint/lisp/test-org-element.el
(test-org-element/inline-src-block-parser): Test extended syntax for
inline source code.

* testing/lisp/test-ob-exp.el (ob-exp/exports-inline-code): New
function for testing inline source code handling.  Also add three new
failing tests exhibiting unexpected results with ":results code"
switches.

* testing/lisp/test-ob.el
(test-org-babel/org-babel-get-inline-src-block-matches): Test for
inline source blocks with empty header arguments.

* testing/examples/babel.org: New sections for testing (i) exported
inline source code (used by `ob-exp/exports-inline-code'); (ii)
parsing inline source blocks with empty header arguments (used by
`test-org-babel/org-babel-get-inline-src-block-matches').

Until now pieces of inline source code were handled as standard code
blocks during export.  These changes enable them to be exported.
---
 lisp/ob-core.el                  |  4 +-
 lisp/ob-exp.el                   | 32 ++++++++++++--
 testing/examples/babel.org       | 22 ++++++++++
 testing/lisp/test-ob-exp.el      | 93 ++++++++++++++++++++++++++++++++++++++++
 testing/lisp/test-ob.el          | 71 +++++++++++++++++-------------
 testing/lisp/test-org-element.el | 22 ++++++++++
 6 files changed, 208 insertions(+), 36 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index ccc0878..c5beb60 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -203,9 +203,9 @@ This string must include a \"%s\" which will be replaced by the results."
 (defvar org-babel-inline-src-block-regexp
   (concat
    ;; (1) replacement target (2) lang
-   "\\(?:^\\|[^-[:alnum:]]\\)\\(src_\\([^ \f\t\n\r\v]+\\)"
+   "\\(?:^\\|[^-[:alnum:]]\\)\\(src_\\([^ \f\t\n\r\v[]+\\)"
    ;; (3,4) (unused, headers)
-   "\\(\\|\\[\\(.*?\\)\\]\\)"
+   "\\(\\|\\[[ \t]*\\(.*?\\)\\]\\)"
    ;; (5) body
    "{\\([^\f\n\r\v]+?\\)}\\)")
   "Regexp used to identify inline src-blocks.")
diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index 3a47661..492bc35 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -318,10 +318,10 @@ The function respects the value of the :exports header argument."
 	(clean (lambda () (unless (eq type 'inline) (org-babel-remove-result info)))))
     (case (intern (or (cdr (assoc :exports (nth 2 info))) "code"))
       ('none (funcall silently) (funcall clean) "")
-      ('code (funcall silently) (funcall clean) (org-babel-exp-code info))
+      ('code (funcall silently) (funcall clean) (org-babel-exp-code info type))
       ('results (org-babel-exp-results info type nil hash) "")
       ('both (org-babel-exp-results info type nil hash)
-	     (org-babel-exp-code info)))))
+	     (org-babel-exp-code info type)))))
 
 (defcustom org-babel-exp-code-template
   "#+BEGIN_SRC %lang%switches%flags\n%body\n#+END_SRC"
@@ -343,7 +343,29 @@ replaced with its value."
   :group 'org-babel
   :type 'string)
 
-(defun org-babel-exp-code (info)
+(defcustom org-babel-exp-inline-code-template
+  "src_%lang[%switches%flags]{%body}"
+  "Template used to export the body of inline code blocks.
+This template may be customized to include additional information
+such as the code block name, or the values of particular header
+arguments.  The template is filled out using `org-fill-template',
+and the following %keys may be used.
+
+ lang ------ the language of the code block
+ name ------ the name of the code block
+ body ------ the body of the code block
+ switches -- the switches associated to the code block
+ flags ----- the flags passed to the code block
+
+In addition to the keys mentioned above, every header argument
+defined for the code block may be used as a key and will be
+replaced with its value."
+  :group 'org-babel
+  :type 'string
+  :version "24.5"
+  :package-version '(Org . "8.3"))
+
+(defun org-babel-exp-code (info type)
   "Return the original code block formatted for export."
   (setf (nth 1 info)
 	(if (string= "strip-export" (cdr (assoc :noweb (nth 2 info))))
@@ -354,7 +376,9 @@ replaced with its value."
 	       info org-babel-exp-reference-buffer)
 	    (nth 1 info))))
   (org-fill-template
-   org-babel-exp-code-template
+   (if (eq type 'inline)
+       org-babel-exp-inline-code-template 
+       org-babel-exp-code-template)
    `(("lang"  . ,(nth 0 info))
      ("body"  . ,(org-escape-code-in-string (nth 1 info)))
      ("switches" . ,(let ((f (nth 3 info)))
diff --git a/testing/examples/babel.org b/testing/examples/babel.org
index a8015d1..8bae65b 100644
--- a/testing/examples/babel.org
+++ b/testing/examples/babel.org
@@ -200,6 +200,17 @@ Here is one in the middle src_sh{echo 1} of a line.
 Here is one at the end of a line. src_sh{echo 2}
 src_sh{echo 3} Here is one at the beginning of a line.
 
+* exported inline source block
+:PROPERTIES:
+:ID:       cd54fc88-1b6b-45b6-8511-4d8fa7fc8076
+:results:  silent
+:exports:  code
+:END:
+Here is one in the middle src_sh{echo 1} of a line.
+Here is one at the end of a line. src_sh{echo 2}
+src_sh{echo 3} Here is one at the beginning of a line.
+Here is one that is also evaluated: src_sh[:exports both]{echo 4}
+
 * mixed blocks with exports both
   :PROPERTIES:
   :ID:       5daa4d03-e3ea-46b7-b093-62c1b7632df3
@@ -283,6 +294,17 @@ src_sh{echo "One"} block at start of line
  One spaced block in  src_sh{ echo "middle" } of line
 src_sh{echo 2} blocks on the src_emacs-lisp{"same"} line
  Inline block with src_sh[:results silent]{ echo "parameters" }.
+
+* org-babel-get-inline-src-block-matches (with empty args)
+  :PROPERTIES:
+  :results:  silent
+  :ID:       d55dada7-de0e-4340-8061-787cccbedee5
+  :END:
+src_sh[]{echo "One"} block at start of line
+ One spaced block in  src_sh[]{ echo "middle" } of line
+src_sh[]{echo 2} blocks on the src_emacs-lisp[]{"same"} line
+ Inline block with src_sh[:results silent]{ echo "parameters" }.
+
 * exporting a code block with a name
   :PROPERTIES:
   :ID:       b02ddd8a-eeb8-42ab-8664-8a759e6f43d9
diff --git a/testing/lisp/test-ob-exp.el b/testing/lisp/test-ob-exp.el
index 1fe810b..e319bd2 100644
--- a/testing/lisp/test-ob-exp.el
+++ b/testing/lisp/test-ob-exp.el
@@ -197,6 +197,99 @@ Here is one at the end of a line. =2=
       (org-narrow-to-subtree)
       (org-test-with-expanded-babel-code (buffer-string))))))
 
+(ert-deftest ob-exp/exports-inline-code ()
+  (should
+   (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)}$"
+		 (org-test-with-temp-text
+		  "src_emacs-lisp[:exports code]{(+ 1 1)}"
+		  (org-export-execute-babel-code)
+		  (buffer-string))))
+  (should
+   (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)}$"
+		 (org-test-with-temp-text
+		  "src_emacs-lisp[ :exports code ]{(+ 1 1)}"
+		  (org-export-execute-babel-code)
+		  (buffer-string))))
+  (should
+   (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)} =2=$"
+		 (org-test-with-temp-text
+		  "src_emacs-lisp[:exports both]{(+ 1 1)}"
+		  (org-export-execute-babel-code)
+		  (buffer-string))))
+  (should
+   (string-match "\\`=2=$"
+		 (org-test-with-temp-text
+		  "src_emacs-lisp[:exports results :results scalar]{(+ 1 1)}"
+		  (org-export-execute-babel-code)
+		  (buffer-string))))
+  (should
+   (let ((text "foosrc_emacs-lisp[:exports code]{(+ 1 1)}"))
+     (string-match (regexp-quote text)
+		   (org-test-with-temp-text
+		    text
+		    (org-export-execute-babel-code)
+		    (buffer-string)))))
+  (should
+   (let ((text "src_emacs lisp{(+ 1 1)}"))
+     (string-match (regexp-quote text)
+		   (org-test-with-temp-text
+		    text
+		    (org-export-execute-babel-code)
+		    (buffer-string)))))
+  (should
+   (string-match
+    (replace-regexp-in-string
+     "\\\\\\[]{" "\\(?:\\[]\\)?{" ;accept both src_sh[]{...} or src_sh{...}
+     (regexp-quote "Here is one in the middle src_sh[]{echo 1} of a line.
+Here is one at the end of a line. src_sh[]{echo 2}
+src_sh[]{echo 3} Here is one at the beginning of a line.
+Here is one that is also evaluated: src_sh[]{echo 4} =4=")
+     nil t)
+    (org-test-at-id "cd54fc88-1b6b-45b6-8511-4d8fa7fc8076"
+      (org-narrow-to-subtree)
+      (org-test-with-expanded-babel-code (buffer-string))))))
+
+(ert-deftest ob-exp/exports-inline-code-double-eval-bug ()
+  "Failing for now as the result actually is
+`#+BEGIN_SRC emacs-lisp\n2#+END_SRC\n'.
+
+Based on default header arguments for inline code blocks (:exports
+results), the resulting code block `src_emacs-lisp{2}' should also be
+evaluated."
+  :expected-result :failed
+  (should
+   (string-match "\\`=2=$"
+  		 (org-test-with-temp-text
+  		  "src_emacs-lisp[:exports results :results code]{(+ 1 1)}"
+  		  (org-export-execute-babel-code)
+  		  (buffer-string)))))
+
+(ert-deftest ob-exp/exports-inline-code-eval-code-once-bug ()
+  "Ibid above, except that the resulting inline code block should not
+be evaluated. Result for now is
+`#+BEGIN_SRC emacs-lisp :exports code\n2#+END_SRC\n'"
+  :expected-result :failed
+  (should
+   (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{2}$"
+  		 (org-test-with-temp-text
+  		  (concat "src_emacs-lisp[:exports results :results code "
+			  ":results_switches \":exports code\"]{(+ 1 1)}")
+  		  (org-export-execute-babel-code)
+  		  (buffer-string)))))
+
+(ert-deftest ob-exp/exports-inline-code-double-eval-exports-both-bug ()
+  "Failing for now as the result actually is 
+`src_emacs-lisp[]{(+ 1 1)} #+BEGIN_SRC emacs-lisp\n2#+END_SRC\n'."
+  :expected-result :failed
+  (should
+   (string-match (concat "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)} "
+  			 "src_emacs-lisp\\(?:\\[]\\)?{2}$")
+  		 (org-test-with-temp-text
+  		  (concat "src_emacs-lisp[:exports both :results code "
+			  ":results_switches \":exports code\"]{(+ 1 1)}")
+  		  (org-export-execute-babel-code)
+  		  (buffer-string)))))
+
 (ert-deftest ob-exp/export-call-line-information ()
   (org-test-at-id "bec63a04-491e-4caa-97f5-108f3020365c"
     (org-narrow-to-subtree)
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index 1162162..fdb5a3e 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -249,38 +249,49 @@ this is simple"
     (should (= 14 (org-babel-execute-src-block)))))
 
 (ert-deftest test-org-babel/inline-src-blocks ()
-  (org-test-at-id "54cb8dc3-298c-4883-a933-029b3c9d4b18"
-    (macrolet ((at-next (&rest body)
-			`(progn
-			   (move-end-of-line 1)
-			   (re-search-forward org-babel-inline-src-block-regexp nil t)
-			   (goto-char (match-beginning 1))
-			   (save-match-data ,@body))))
-      (at-next (should (equal 1 (org-babel-execute-src-block))))
-      (at-next (should (equal 2 (org-babel-execute-src-block))))
-      (at-next (should (equal 3 (org-babel-execute-src-block)))))))
+  (macrolet ((at-next (&rest body)
+	       `(progn
+		  (move-end-of-line 1)
+		  (re-search-forward org-babel-inline-src-block-regexp nil t)
+		  (goto-char (match-beginning 1))
+		  (save-match-data ,@body))))
+    (org-test-at-id
+     "54cb8dc3-298c-4883-a933-029b3c9d4b18"
+     (at-next (should (equal 1 (org-babel-execute-src-block))))
+     (at-next (should (equal 2 (org-babel-execute-src-block))))
+     (at-next (should (equal 3 (org-babel-execute-src-block)))))
+    (org-test-at-id
+     "cd54fc88-1b6b-45b6-8511-4d8fa7fc8076"
+     (at-next (should (equal 1 (org-babel-execute-src-block))))
+     (at-next (should (equal 2 (org-babel-execute-src-block))))
+     (at-next (should (equal 3 (org-babel-execute-src-block))))
+     (at-next (should (equal 4 (org-babel-execute-src-block)))))))
 
 (ert-deftest test-org-babel/org-babel-get-inline-src-block-matches ()
-  (org-test-at-id "0D0983D4-DE33-400A-8A05-A225A567BC74"
-    (let ((test-point (point)))
-      (should (fboundp 'org-babel-get-inline-src-block-matches))
-      (should (re-search-forward "src_" nil t)) ;; 1
-      (should (org-babel-get-inline-src-block-matches))
-      (should (re-search-forward "}" nil (point-at-bol))) ;; 1
-      (should-not (org-babel-get-inline-src-block-matches))
-      (should (re-search-forward "in" nil t)) ;; 2
-      (should-not (org-babel-get-inline-src-block-matches))
-      (should (re-search-forward "echo" nil t)) ;; 2
-      (should (org-babel-get-inline-src-block-matches))
-      (should (re-search-forward "blocks" nil t)) ;; 3
-      (backward-char 8) ;; 3
-      (should (org-babel-get-inline-src-block-matches))
-      (forward-char 1) ;;3
-      (should-not (org-babel-get-inline-src-block-matches))
-      (should (re-search-forward ":results" nil t)) ;; 4
-      (should (org-babel-get-inline-src-block-matches))
-      (end-of-line)
-      (should-not (org-babel-get-inline-src-block-matches)))))
+  (flet ((test-at-id (id)
+	   (org-test-at-id 
+	    id
+	    (let ((test-point (point)))
+	      (should (fboundp 'org-babel-get-inline-src-block-matches))
+	      (should (re-search-forward "src_" nil t)) ;; 1
+	      (should (org-babel-get-inline-src-block-matches))
+	      (should (re-search-forward "}" nil (point-at-bol))) ;; 1
+	      (should-not (org-babel-get-inline-src-block-matches))
+	      (should (re-search-forward "in" nil t)) ;; 2
+	      (should-not (org-babel-get-inline-src-block-matches))
+	      (should (re-search-forward "echo" nil t)) ;; 2
+	      (should (org-babel-get-inline-src-block-matches))
+	      (should (re-search-forward "blocks" nil t)) ;; 3
+	      (backward-char 8) ;; 3
+	      (should (org-babel-get-inline-src-block-matches))
+	      (forward-char 1) ;;3
+	      (should-not (org-babel-get-inline-src-block-matches))
+	      (should (re-search-forward ":results" nil t)) ;; 4
+	      (should (org-babel-get-inline-src-block-matches))
+	      (end-of-line)
+	      (should-not (org-babel-get-inline-src-block-matches))))))
+    (test-at-id "0D0983D4-DE33-400A-8A05-A225A567BC74")
+    (test-at-id "d55dada7-de0e-4340-8061-787cccbedee5")))
 
 (ert-deftest test-org-babel/inline-src_blk-default-results-replace-line-1 ()
   (let ((test-line "src_sh{echo 1}"))
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 1705a4d..0bd8501 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -1051,6 +1051,28 @@ Some other text
   (should
    (org-test-with-temp-text "src_emacs-lisp{(+ 1 1)}"
      (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
+  ;; With switches.
+  (should
+   (org-test-with-temp-text "src_emacs-lisp[:foo bar]{(+ 1 1)}"
+     (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
+  (should
+   (org-test-with-temp-text "src_emacs-lisp[ :foo bar]{(+ 1 1)}"
+     (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
+  ;; Empty switches.
+  (should
+   (org-test-with-temp-text "src_emacs-lisp[]{(+ 1 1)}"
+     (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
+  ;; Invalid syntax.
+  (should-not
+   (org-test-with-temp-text "foosrc_emacs-lisp[]{(+ 1 1)}"
+     (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
+  (should-not
+   (org-test-with-temp-text "src_emacs-lisp[]foo{(+ 1 1)}"
+     (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
+  ;; Invalid language name
+  (should-not
+   (org-test-with-temp-text "src_emacs-\tlisp{(+ 1 1)}"
+     (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
   ;; Test parsing at the beginning of an item.
   (should
    (org-test-with-temp-text "- src_emacs-lisp{(+ 1 1)}"
-- 
2.0.0.rc4


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-ox-html-Support-for-exporting-inline-source-code-to-.patch --]
[-- Type: text/x-patch, Size: 1241 bytes --]

From 7596530cb0b59aee5060d333c9ecd0ece6dc6374 Mon Sep 17 00:00:00 2001
From: Nicolas Berthier <nberth@member.fsf.org>
Date: Fri, 13 Jun 2014 16:39:18 +0200
Subject: [PATCH 2/3] ox-html: Support for exporting inline source code to HTML

* lisp/ox-html.el (org-html-inline-src-block): support for exporting
inline source code to HTML.
---
 lisp/ox-html.el | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 22d0b04..a730984 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2411,7 +2411,13 @@ CONTENTS holds the contents of the item.  INFO is a plist holding
 contextual information."
   (let* ((org-lang (org-element-property :language inline-src-block))
 	 (code (org-element-property :value inline-src-block)))
-    (error "Cannot export inline src block")))
+    (let ((lang (org-element-property :language inline-src-block))
+	  (code (org-html-format-code inline-src-block info))
+	  (label (let ((lbl (org-element-property :name inline-src-block)))
+		   (if (not lbl) ""
+		       (format " id=\"%s\""
+			       (org-export-solidify-link-text lbl))))))
+      (format "<code class=\"src src-%s\"%s>%s</code>" lang label code))))
 
 ;;;; Inlinetask
 
-- 
2.0.0.rc4


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-ob-core-Preserve-inline-ness-of-source-blocks-when-i.patch --]
[-- Type: text/x-patch, Size: 5986 bytes --]

From 326d51913a0d69fa42c67814f11f2c844acc0076 Mon Sep 17 00:00:00 2001
From: Nicolas Berthier <nberth@member.fsf.org>
Date: Fri, 1 Aug 2014 11:28:05 +0200
Subject: [PATCH 3/3] ob-core: Preserve inline-ness of source blocks when
 inserting results

* lisp/ob-core.el (org-babel-insert-result): Preserve inline-ness of
source blocks.

* testing/lisp/test-ob-exp.el: Update newly passing tests.
---
 lisp/ob-core.el             | 36 ++++++++++++++++++++++++------------
 testing/lisp/test-ob-exp.el | 19 +++++--------------
 2 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index c5beb60..50a13c2 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2094,9 +2094,11 @@ drawer -- results are added directly to the Org-mode file as with
           \"raw\", but are wrapped in a RESULTS drawer, allowing
           them to later be replaced or removed automatically.
 
-org ----- results are added inside of a \"#+BEGIN_SRC org\" block.
-          They are not comma-escaped when inserted, but Org syntax
-          here will be discarded when exporting the file.
+org ----- results are added inside of a \"src_org{}\" or \"#+BEGIN_SRC
+          org\" block depending on whether the current source block is
+          inline or not.  They are not comma-escaped when inserted,
+          but Org syntax here will be discarded when exporting the
+          file.
 
 html ---- results are added inside of a #+BEGIN_HTML block.  This
           is a good option if you code block will output html
@@ -2108,8 +2110,9 @@ latex --- results are added inside of a #+BEGIN_LATEX block.
 
 code ---- the results are extracted in the syntax of the source
           code of the language being evaluated and are added
-          inside of a #+BEGIN_SRC block with the source-code
-          language set appropriately.  Note this relies on the
+          inside of a source block with the source-code language
+          set appropriately.  Also, source block inlining is
+          preserved in this case.  Note this relies on the
           optional LANG argument."
   (if (stringp result)
       (progn
@@ -2171,12 +2174,15 @@ code ---- the results are extracted in the syntax of the source
 		 ((member "prepend" result-params)))) ; already there
 	      (setq results-switches
 		    (if results-switches (concat " " results-switches) ""))
-	      (let ((wrap (lambda (start finish &optional no-escape)
-			    (goto-char end) (insert (concat finish "\n"))
-			    (goto-char beg) (insert (concat start "\n"))
+	      (let ((wrap (lambda (start finish &optional no-escape no-newlines)
+			    (goto-char end)
+			    (insert (concat finish (unless no-newlines "\n")))
+			    (goto-char beg)
+			    (insert (concat start (unless no-newlines "\n")))
 			    (unless no-escape
 			      (org-escape-code-in-region (min (point) end) end))
-			    (goto-char end) (goto-char (point-at-eol))
+			    (goto-char end)
+			    (unless no-newlines (goto-char (point-at-eol)))
 			    (setq end (point-marker))))
 		    (proper-list-p (lambda (it) (and (listp it) (null (cdr (last it)))))))
 		;; insert results based on type
@@ -2224,10 +2230,16 @@ code ---- the results are extracted in the syntax of the source
 		  (funcall wrap "#+BEGIN_LaTeX" "#+END_LaTeX"))
 		 ((member "org" result-params)
 		  (goto-char beg) (if (org-at-table-p) (org-cycle))
-		  (funcall wrap "#+BEGIN_SRC org" "#+END_SRC"))
+		  (if inlinep
+		      (funcall wrap "src_org{" "}" nil t)
+		      (funcall wrap "#+BEGIN_SRC org" "#+END_SRC")))
 		 ((member "code" result-params)
-		  (funcall wrap (format "#+BEGIN_SRC %s%s" (or lang "none") results-switches)
-			   "#+END_SRC"))
+		  (let ((lang (or lang "none")))
+		    (if inlinep
+			(funcall wrap (format "src_%s[%s]{" lang results-switches)
+				 "}" nil t)
+			(funcall wrap (format "#+BEGIN_SRC %s%s" lang results-switches)
+				 "#+END_SRC"))))
 		 ((member "raw" result-params)
 		  (goto-char beg) (if (org-at-table-p) (org-cycle)))
 		 ((or (member "drawer" result-params)
diff --git a/testing/lisp/test-ob-exp.el b/testing/lisp/test-ob-exp.el
index e319bd2..456f794 100644
--- a/testing/lisp/test-ob-exp.el
+++ b/testing/lisp/test-ob-exp.el
@@ -249,14 +249,10 @@ Here is one that is also evaluated: src_sh[]{echo 4} =4=")
       (org-narrow-to-subtree)
       (org-test-with-expanded-babel-code (buffer-string))))))
 
-(ert-deftest ob-exp/exports-inline-code-double-eval-bug ()
-  "Failing for now as the result actually is
-`#+BEGIN_SRC emacs-lisp\n2#+END_SRC\n'.
-
-Based on default header arguments for inline code blocks (:exports
+(ert-deftest ob-exp/exports-inline-code-double-eval ()
+  "Based on default header arguments for inline code blocks (:exports
 results), the resulting code block `src_emacs-lisp{2}' should also be
 evaluated."
-  :expected-result :failed
   (should
    (string-match "\\`=2=$"
   		 (org-test-with-temp-text
@@ -264,11 +260,9 @@ evaluated."
   		  (org-export-execute-babel-code)
   		  (buffer-string)))))
 
-(ert-deftest ob-exp/exports-inline-code-eval-code-once-bug ()
+(ert-deftest ob-exp/exports-inline-code-eval-code-once ()
   "Ibid above, except that the resulting inline code block should not
-be evaluated. Result for now is
-`#+BEGIN_SRC emacs-lisp :exports code\n2#+END_SRC\n'"
-  :expected-result :failed
+be evaluated."
   (should
    (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{2}$"
   		 (org-test-with-temp-text
@@ -277,10 +271,7 @@ be evaluated. Result for now is
   		  (org-export-execute-babel-code)
   		  (buffer-string)))))
 
-(ert-deftest ob-exp/exports-inline-code-double-eval-exports-both-bug ()
-  "Failing for now as the result actually is 
-`src_emacs-lisp[]{(+ 1 1)} #+BEGIN_SRC emacs-lisp\n2#+END_SRC\n'."
-  :expected-result :failed
+(ert-deftest ob-exp/exports-inline-code-double-eval-exports-both ()
   (should
    (string-match (concat "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)} "
   			 "src_emacs-lisp\\(?:\\[]\\)?{2}$")
-- 
2.0.0.rc4


[-- Attachment #5: Type: text/plain, Size: 88 bytes --]


Regards,

-- 
Nicolas Berthier                                        FSF Member #7975

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

* Re: [babel][PATCHES] exporting inline source code
  2014-08-01 12:23             ` Nicolas Berthier
@ 2014-08-22 12:47               ` Nicolas Goaziou
  2014-08-22 13:32                 ` Bastien
  0 siblings, 1 reply; 12+ messages in thread
From: Nicolas Goaziou @ 2014-08-22 12:47 UTC (permalink / raw)
  To: Nicolas Berthier; +Cc: emacs-orgmode

Hello,

Nicolas Berthier <nberth@member.fsf.org> writes:

> Indeed.  I fixed it in the new attached patch.  Thanks.

Applied. Thank you.


Regards,

-- 
Nicolas Goaziou

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

* Re: [babel][PATCHES] exporting inline source code
  2014-08-22 12:47               ` Nicolas Goaziou
@ 2014-08-22 13:32                 ` Bastien
  0 siblings, 0 replies; 12+ messages in thread
From: Bastien @ 2014-08-22 13:32 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode, Nicolas Berthier

Hi Nicolas,

thanks for implementing this.

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Nicolas Berthier <nberth@member.fsf.org> writes:
>
>> Indeed.  I fixed it in the new attached patch.  Thanks.
>
> Applied. Thank you.

Since the patch has been applied, I get a "Not at a block" error
when finding some org-mode files -- I'll investigate later if it
is needed, just dropping this here now in case the bug is obvious.

-- 
 Bastien

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

end of thread, other threads:[~2014-08-22 13:39 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-13 17:37 [babel][PATCHES] exporting inline source code Nicolas Berthier
2014-06-22  4:02 ` Aaron Ecay
2014-07-27 17:23   ` Bastien
2014-07-29  7:40     ` Nicolas Berthier
2014-07-29 13:19       ` Bastien
2014-07-30 16:06         ` Nicolas Berthier
2014-07-30 19:26           ` Nicolas Goaziou
2014-07-30 20:01             ` Achim Gratz
2014-07-30 20:23               ` Nicolas Goaziou
2014-08-01 12:23             ` Nicolas Berthier
2014-08-22 12:47               ` Nicolas Goaziou
2014-08-22 13:32                 ` Bastien

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).