From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thorsten Jolitz Subject: (Maybe) enhance `org-element-src-block-interpreter'? Date: Tue, 05 Aug 2014 18:17:27 +0200 Message-ID: <87tx5qvrl4.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49960) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEhQv-0004rM-Ib for emacs-orgmode@gnu.org; Tue, 05 Aug 2014 12:18:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XEhQl-0003rk-Pc for emacs-orgmode@gnu.org; Tue, 05 Aug 2014 12:17:53 -0400 Received: from plane.gmane.org ([80.91.229.3]:40357) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEhQl-0003qu-JK for emacs-orgmode@gnu.org; Tue, 05 Aug 2014 12:17:43 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XEhQk-0002cZ-RX for emacs-orgmode@gnu.org; Tue, 05 Aug 2014 18:17:42 +0200 Received: from e178062049.adsl.alicedsl.de ([85.178.62.49]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 05 Aug 2014 18:17:42 +0200 Received: from tjolitz by e178062049.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 05 Aug 2014 18:17:42 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Hi, a slight enhancement: #+begin_src emacs-lisp (defun tj/src-block-interpreter (src-block contents) "Interpret SRC-BLOCK element as Org syntax. CONTENTS is nil." (let ((lang (org-element-property :language src-block)) (switches (org-element-property :switches src-block)) (params (org-element-property :parameters src-block)) (headers (org-element-property :header src-block)) (value (let ((val (org-element-property :value src-block))) (cond ((or org-src-preserve-indentation (org-element-property :preserve-indent src-block)) val) ((zerop org-edit-src-content-indentation) val) (t (let ((ind (make-string org-edit-src-content-indentation ?\s))) (replace-regexp-in-string "\\(^\\)[ \t]*\\S-" ind val nil nil 1)))))) packed-headers) (concat (format "%s#+BEGIN_SRC%s\n" (progn (while headers (setq packed-headers (concat (format "#+HEADER: %s\n" (pop headers)) packed-headers))) (or packed-headers "")) (concat (and lang (concat " " lang)) (and switches (concat " " switches)) (and params (concat " " params)))) (org-escape-code-in-string value) ;; (save-match-data ;; (if (looking-at "^$") "" "\n")) "#+END_SRC"))) #+end_src #+results: : tj/src-block-interpreter Parse this src-block (with point at beg of block): ,---- | M-: (setq ptree (org-element-at-point)) `---- #+header: :results raw #+begin_src emacs-lisp (message "hello world") #+end_src #+results: hello world Then evaluate #+begin_src emacs-lisp (org-element-src-block-interpreter ptree nil) #+end_src #+results: : #+BEGIN_SRC emacs-lisp : (message "hello world") : #+END_SRC #+begin_src emacs-lisp (tj/src-block-interpreter ptree nil) #+end_src #+results: : #+HEADER: :results raw : #+BEGIN_SRC emacs-lisp : (message "hello world") : #+END_SRC -- cheers, Thorsten