emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] inline src block results can be removed
@ 2014-11-12  0:49 Charles C. Berry
  2014-11-12  1:10 ` Andreas Leha
  2014-11-12 19:34 ` Aaron Ecay
  0 siblings, 2 replies; 35+ messages in thread
From: Charles C. Berry @ 2014-11-12  0:49 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: mcg, Andreas Leha, Ista Zahn, Nicolas Goaziou

[-- Attachment #1: Type: TEXT/PLAIN, Size: 902 bytes --]


Inline src blocks cannot update their results --- causing some of us 
heaadaches [1].

These patches fix that by placing the result of an inline src block in an 
export snippet with a faux :back-end called 'babel'.

So C-c C-c with point on src_R{1+2} will insert `@@babel:3@@'. Updating 
the contents of the inline src block and retyping C-c C-c will update the 
snippet. On export, these snippets are rendered using the verbatim 
transcoder, e.g. \texttt{3} for latex backends.

Support for most backends is provided.

org-babel-execute-buffer will also update such snippets.

Please try these patches out.

Remember to recompile the files that these patches modify or you will get 
wrong results when you restart emacs.

HTH,

Chuck

Footnote: [1] http://thread.gmane.org/gmane.emacs.orgmode/92481

p.s. If these patchesa are (eventually) acceptable, FSF has a copyright 
assignment for me on file.

[-- Attachment #2: ob-exp.el patch --]
[-- Type: TEXT/PLAIN, Size: 1260 bytes --]

From 78a365d223a969f407efa524b0c45e701b4ae908 Mon Sep 17 00:00:00 2001
From: chasberry <ccberry@ucsd.edu>
Date: Tue, 11 Nov 2014 12:53:01 -0800
Subject: [PATCH 1/5] lisp/ob-exp.el: Enable removable inline src results

* lisp/ob-exp.el (org-babel-exp-do-export): Clean `@@babel:result@@'
  after inline src block.
---
 lisp/ob-exp.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index edb889c..83359e5 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -315,7 +315,9 @@ The function respects the value of the :exports header argument."
   (let ((silently (lambda () (let ((session (cdr (assoc :session (nth 2 info)))))
 			       (when (not (and session (equal "none" session)))
 				 (org-babel-exp-results info type 'silent)))))
-	(clean (lambda () (unless (eq type 'inline) (org-babel-remove-result info)))))
+	(clean (lambda () (if (eq type 'inline)
+			      (org-babel-delete-babel-snippet info)
+			    (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 type))
-- 
1.9.3 (Apple Git-50)


[-- Attachment #3: export-snippet patch --]
[-- Type: TEXT/PLAIN, Size: 6534 bytes --]

From 5e84279ff5dbbcb3e9c8f89c88afc15441286aec Mon Sep 17 00:00:00 2001
From: chasberry <ccberry@ucsd.edu>
Date: Tue, 11 Nov 2014 13:01:22 -0800
Subject: [PATCH 2/5] Inline src blocks are export-snippets

   * lisp/ox-latex.el (org-latex-export-snippet): Treat the babel
   `:back-end' export-snippet value as verbatim.

   * lisp/ox-beamer.el (org-beamer-export-snippet): Treat the babel
   `:back-end' export-snippet value as verbatim.

   * lisp/ox-html.el (org-html-export-snippet): Treat the babel
   `:back-end' export-snippet value as verbatim.

   * lisp/ox-ascii.el (org-ascii-export-snippet): Treat the babel
   `:back-end' export-snippet value as verbatim.

   * lisp/ox-texinfo.el (org-texinfo-export-snippet): Treat the babel
   `:back-end' export-snippet value as verbatim.

   * lisp/ox-odt.el (org-odt-export-snippet): Treat the babel
   `:back-end' export-snippet value as verbatim.

   * lisp/ox-man.el (org-man-export-snippet): Treat the babel
   `:back-end' export-snippet value as verbatim.
---
 lisp/ox-ascii.el   | 8 ++++++--
 lisp/ox-beamer.el  | 2 ++
 lisp/ox-html.el    | 7 +++++--
 lisp/ox-latex.el   | 8 +++++---
 lisp/ox-man.el     | 8 ++++++--
 lisp/ox-odt.el     | 8 +++++---
 lisp/ox-texinfo.el | 7 +++++--
 7 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/lisp/ox-ascii.el b/lisp/ox-ascii.el
index daad00f..695277c 100644
--- a/lisp/ox-ascii.el
+++ b/lisp/ox-ascii.el
@@ -1213,8 +1213,12 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 (defun org-ascii-export-snippet (export-snippet contents info)
   "Transcode a EXPORT-SNIPPET object from Org to ASCII.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  (when (eq (org-export-snippet-backend export-snippet) 'ascii)
-    (org-element-property :value export-snippet)))
+  (let ((backend (org-export-snippet-backend export-snippet)))
+    (cond ((eq  backend 'ascii)
+	   (org-element-property :value export-snippet))
+	  ((eq backend 'babel)
+	   (org-ascii-verbatim export-snippet contents info)))))
+
 
 
 ;;;; Export Block
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 15bbce2..9f71cbb 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -291,6 +291,8 @@ channel."
 	(value (org-element-property :value export-snippet)))
     ;; Only "latex" and "beamer" snippets are retained.
     (cond ((eq backend 'latex) value)
+	  ((eq backend 'babel)
+	   (org-latex-verbatim export-snippet contents info))
 	  ;; Ignore "beamer" snippets specifying overlays.
 	  ((and (eq backend 'beamer)
 		(or (org-export-get-previous-element export-snippet info)
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 20d09eb..e377687 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2268,8 +2268,11 @@ information."
   "Transcode a EXPORT-SNIPPET object from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual
 information."
-  (when (eq (org-export-snippet-backend export-snippet) 'html)
-    (org-element-property :value export-snippet)))
+  (let ((backend (org-export-snippet-backend export-snippet)))
+    (cond ((eq  backend 'html)
+	   (org-element-property :value export-snippet))
+	  ((eq backend 'babel)
+	   (org-html-verbatim export-snippet contents info))))) 
 
 ;;;; Export Block
 
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 8b38f96..232de73 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1392,9 +1392,11 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 (defun org-latex-export-snippet (export-snippet contents info)
   "Transcode a EXPORT-SNIPPET object from Org to LaTeX.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  (when (eq (org-export-snippet-backend export-snippet) 'latex)
-    (org-element-property :value export-snippet)))
-
+  (let ((backend (org-export-snippet-backend export-snippet)))
+    (cond ((eq  backend 'latex)
+	   (org-element-property :value export-snippet))
+	  ((eq backend 'babel)
+	   (org-latex-verbatim export-snippet contents info))))) 
 
 ;;;; Fixed Width
 
diff --git a/lisp/ox-man.el b/lisp/ox-man.el
index 9bbc52d..76fa99d 100644
--- a/lisp/ox-man.el
+++ b/lisp/ox-man.el
@@ -446,8 +446,12 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 (defun org-man-export-snippet (export-snippet contents info)
   "Transcode a EXPORT-SNIPPET object from Org to Man.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  (when (eq (org-export-snippet-backend export-snippet) 'man)
-    (org-element-property :value export-snippet)))
+  (let ((backend (org-export-snippet-backend export-snippet)))
+    (cond ((eq  backend 'man)
+	   (org-element-property :value export-snippet))
+	  ((eq backend 'babel)
+	   (org-man-verbatim export-snippet contents info)))))
+
 
 
 ;;; Fixed Width
diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index 3b2596f..19db439 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -1673,9 +1673,11 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 (defun org-odt-export-snippet (export-snippet contents info)
   "Transcode a EXPORT-SNIPPET object from Org to ODT.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  (when (eq (org-export-snippet-backend export-snippet) 'odt)
-    (org-element-property :value export-snippet)))
-
+  (let ((backend (org-export-snippet-backend export-snippet)))
+    (cond ((eq  backend 'odt)
+	   (org-element-property :value export-snippet))
+	  ((eq backend 'babel)
+	   (org-odt-verbatim export-snippet contents info)))))
 
 ;;;; Export Block
 
diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el
index 20508a1..6004c65 100644
--- a/lisp/ox-texinfo.el
+++ b/lisp/ox-texinfo.el
@@ -708,8 +708,11 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 (defun org-texinfo-export-snippet (export-snippet contents info)
   "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  (when (eq (org-export-snippet-backend export-snippet) 'texinfo)
-    (org-element-property :value export-snippet)))
+  (let ((backend (org-export-snippet-backend export-snippet)))
+    (cond ((eq  backend 'texinfo)
+	   (org-element-property :value export-snippet))
+	  ((eq backend 'babel)
+	   (org-texinfo-verbatim export-snippet contents info))))) 
 
 ;;;; Fixed Width
 
-- 
1.9.3 (Apple Git-50)


[-- Attachment #4: ox-md.el export snippets --]
[-- Type: TEXT/PLAIN, Size: 1968 bytes --]

From 54a94ea382eab1138bacbb38c0064f6feedea50f Mon Sep 17 00:00:00 2001
From: chasberry <ccberry@ucsd.edu>
Date: Tue, 11 Nov 2014 13:05:00 -0800
Subject: [PATCH 3/5] Inline src blocks are export-snippets

* lisp/ox-md.el (org-md-export-snippet): For babel; snippet use
  verbatim, otherwise use the html transcoder.
---
 lisp/ox-md.el | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index f3fdedc..27da308 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -72,6 +72,7 @@ This variable can be set to either `atx' or `setext'."
 		     (comment-block . (lambda (&rest args) ""))
 		     (example-block . org-md-example-block)
 		     (export-block . org-md-export-block)
+		     (export-snippet . org-md-export-snippet)
 		     (fixed-width . org-md-example-block)
 		     (footnote-definition . ignore)
 		     (footnote-reference . ignore)
@@ -156,7 +157,7 @@ channel."
 	    value)))
 
 
-;;;; Example Block, Src Block and export Block
+;;;; Example Block, Src Block, export Block, export snippet
 
 (defun org-md-example-block (example-block contents info)
   "Transcode EXAMPLE-BLOCK element into Markdown format.
@@ -175,7 +176,17 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
     ;; Also include HTML export blocks.
     (org-export-with-backend 'html export-block contents info)))
 
-
+(defun org-md-export-snippet (export-snippet contents info)
+  "Transcode a EXPORT-SNIPPET object from Org to HTML.
+CONTENTS is nil.  INFO is a plist holding contextual
+information."
+  (let ((backend (org-export-snippet-backend export-snippet)))
+    (cond ((eq  backend 'html)
+	   (org-export-with-backend 'html export-snippet contents
+	   info))
+	  ((eq backend 'babel)
+	   (org-md-verbatim export-snippet contents info))))) 
+  
 ;;;; Headline
 
 (defun org-md-headline (headline contents info)
-- 
1.9.3 (Apple Git-50)


[-- Attachment #5: ox-man.el export snippet --]
[-- Type: TEXT/PLAIN, Size: 934 bytes --]

From 576ecdbbafcc95fcf1760fd4274b155512e09b60 Mon Sep 17 00:00:00 2001
From: chasberry <ccberry@ucsd.edu>
Date: Tue, 11 Nov 2014 13:49:18 -0800
Subject: [PATCH 4/5] Inline src blocks are export-snippets

* lisp/ox-man.org (org-man-export-snippet): Treat the babel
   `:back-end' export-snippet value as verbatim.
---
 lisp/ox-man.el | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lisp/ox-man.el b/lisp/ox-man.el
index 76fa99d..4cd6cdf 100644
--- a/lisp/ox-man.el
+++ b/lisp/ox-man.el
@@ -450,7 +450,10 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
     (cond ((eq  backend 'man)
 	   (org-element-property :value export-snippet))
 	  ((eq backend 'babel)
-	   (org-man-verbatim export-snippet contents info)))))
+	   (org-man-verbatim
+	    export-snippet
+	    (org-element-property :value export-snippet)
+	    info)))))
 
 
 
-- 
1.9.3 (Apple Git-50)


[-- Attachment #6: ob-core.el export snippet patch --]
[-- Type: TEXT/PLAIN, Size: 3103 bytes --]

From fdf7e79ed152c652c5666ce9e5ab3f1270bf72c5 Mon Sep 17 00:00:00 2001
From: chasberry <ccberry@ucsd.edu>
Date: Tue, 11 Nov 2014 15:32:41 -0800
Subject: [PATCH 5/5] lisp/ob-core.el: Enable removable inline src results

* lisp/ob-core.al (org-babel-inline-result-wrap,
  org-babel-insert-result, org-babel-delete-babel-snippet): Inline src
  blocks results are export-snippets with a faux `:back-end' of `babel'.

  (org-babel-inline-result-wrap): Now `@@babel:%s@@'.
  (org-babel-delete-babel-snippet): Remove a babel export-snippet.
  (org-babel-insert-result): Remove a babel export snippet.

  The treatment of inline src block results as verbatim,
  e.g. `=result=', makes finding and removing them programatically
  tricky and risky.  By wrapping them as `@@babel:result@@' they can
  be found and removed.
---
 lisp/ob-core.el | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 6c38677..471ff25 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -156,7 +156,7 @@ See also `org-babel-noweb-wrap-start'."
   :group 'org-babel
   :type 'string)
 
-(defcustom org-babel-inline-result-wrap "=%s="
+(defcustom org-babel-inline-result-wrap "@@babel:%s@@"
   "Format string used to wrap inline results.
 This string must include a \"%s\" which will be replaced by the results."
   :group 'org-babel
@@ -2136,8 +2136,9 @@ code ---- the results are extracted in the syntax of the source
 		  (goto-char (match-end 0))
 		  (insert (if (listp result) "\n" " "))
 		  (point))))
-	     (existing-result (unless inlinep
-				(org-babel-where-is-src-block-result
+	     (existing-result (if inlinep
+				(org-babel-delete-babel-snippet)
+                                (org-babel-where-is-src-block-result
 				 t info hash indent)))
 	     (results-switches
 	      (cdr (assoc :results_switches (nth 2 info))))
@@ -2279,6 +2280,22 @@ code ---- the results are extracted in the syntax of the source
 	   (if keep-keyword (1+ (match-end 0)) (1- (match-beginning 0)))
 	   (progn (forward-line 1) (org-babel-result-end))))))))
 
+(defun org-babel-delete-babel-snippet (&optional info)
+  "When point is before a babel export-snippet, delete it."
+  (let ((location  (org-babel-where-is-src-block-result nil info)))
+    (when location 
+      (save-excursion
+	(goto-char location)
+	(when
+	    (looking-at "\\([[:space:]]*\\)\\([@]\\)")
+          (goto-char (match-end 1))
+          (let ((export-snippet (org-element-export-snippet-parser)))
+            (if export-snippet
+                (let ((start (org-element-property :begin export-snippet))
+                      (end (org-element-property :end export-snippet)))
+                  (and (eq (org-export-snippet-backend export-snippet) 'babel)
+                       (delete-region start end))))))))))
+
 (defun org-babel-remove-result-one-or-many (x)
   "Remove the result of the current source block.
 If called with a prefix argument, remove all result blocks
-- 
1.9.3 (Apple Git-50)


^ permalink raw reply related	[flat|nested] 35+ messages in thread
* Re: [PATCH] inline src block results can be removed
@ 2014-11-24 11:12 Daniele Pizzolli
  2014-11-25  8:04 ` Daniele Pizzolli
  0 siblings, 1 reply; 35+ messages in thread
From: Daniele Pizzolli @ 2014-11-24 11:12 UTC (permalink / raw)
  To: emacs-orgmode

On 2014-11-24 11:18, Andreas Leha wrote:
> Hi Daniele,
> 
> I think your wishlist is somewhere further down the road.  I usually
> implement some of your points in the src_language.  I see that it would
> be nice if org supported these use cases, but I would see them as part
> of the LOB or maybe in some package in contrib rather than in core
> org/babel.
> 
> For that, I'd argue removable inline results that can be exported
> without special formatting would be all that is needed to support your
> wishlist.

Hi Andreas,

sure, I think I will start getting the string I needed from
src_language.  But in some language is really hard to get facilities
for text manipulation while the output as table generally supported.
And I also think that the fine grained control of the layout of the
inline sentence pertains to the org layer.

> A few inline comments below.

Thanks again, they are really a nice help to start with!

Best,
Daniele

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

end of thread, other threads:[~2015-01-29 20:31 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-12  0:49 [PATCH] inline src block results can be removed Charles C. Berry
2014-11-12  1:10 ` Andreas Leha
2014-11-12  6:58   ` Charles C. Berry
2014-11-12 19:34 ` Aaron Ecay
2014-11-12 23:47   ` Charles C. Berry
2014-11-13 17:48     ` Nicolas Goaziou
2014-11-13 19:06       ` Andreas Leha
2014-11-14 17:43       ` Charles C. Berry
2014-11-14 20:39         ` Nicolas Goaziou
2014-11-14 23:04           ` Aaron Ecay
2014-11-16  0:10             ` Nicolas Goaziou
2014-11-15 20:22           ` Charles C. Berry
2014-11-16 23:23             ` Nicolas Goaziou
2014-11-24  9:48               ` Daniele Pizzolli
2014-11-24 10:18                 ` Andreas Leha
2015-01-13  0:48               ` New patches WAS " Charles C. Berry
2015-01-16 22:41                 ` Nicolas Goaziou
2015-01-19  3:22                   ` Charles C. Berry
2015-01-19 17:53                     ` Nicolas Goaziou
2015-01-19 19:31                       ` Charles C. Berry
2015-01-20 23:30                         ` Nicolas Goaziou
2015-01-22  3:07                           ` Charles C. Berry
2015-01-22 23:08                             ` Nicolas Goaziou
2015-01-24 22:47                               ` Charles C. Berry
2015-01-25  1:14                                 ` Aaron Ecay
2015-01-25  5:01                                   ` Charles C. Berry
2015-01-29 20:31                               ` Charles C. Berry
2015-01-17  3:22                 ` Aaron Ecay
2015-01-17 22:20                   ` Nicolas Goaziou
2015-01-18 19:13                     ` Aaron Ecay
2015-01-18 22:34                       ` Nicolas Goaziou
2015-01-18 22:55                         ` Aaron Ecay
  -- strict thread matches above, loose matches on Subject: below --
2014-11-24 11:12 Daniele Pizzolli
2014-11-25  8:04 ` Daniele Pizzolli
2014-11-25  9:52   ` Andreas Leha

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