From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: [Announcement] Org-babel initial release Date: Tue, 15 Sep 2009 14:03:16 -0600 Message-ID: References: <87pr9sazlr.fsf@gmx.de> <87ab0waukq.fsf@gmx.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MneFf-00014u-U3 for emacs-orgmode@gnu.org; Tue, 15 Sep 2009 16:03:47 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MneFb-000141-3C for emacs-orgmode@gnu.org; Tue, 15 Sep 2009 16:03:47 -0400 Received: from [199.232.76.173] (port=42815 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MneFa-00013y-Vf for emacs-orgmode@gnu.org; Tue, 15 Sep 2009 16:03:43 -0400 Received: from mail-pz0-f201.google.com ([209.85.222.201]:35338) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MneFa-0000To-8m for emacs-orgmode@gnu.org; Tue, 15 Sep 2009 16:03:42 -0400 Received: by pzk39 with SMTP id 39so3671774pzk.15 for ; Tue, 15 Sep 2009 13:03:41 -0700 (PDT) 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: Sebastian Rose Cc: Org Mode --=-=-= Sebastian Rose writes: > "Eric Schulte" writes: >> >> Yes, currently the best way to get a feel for how to add languages would >> be to start with an existing language file (I'd suggest >> org-babel-python.el or org-babel-ruby.el, or for simpler less >> comprehensive language support look at org-babel-ditaa or >> org-babel-haskell) and make changes from there. I agree that a brief >> tutorial for adding language support would be helpful. > > > A skeleton maybe? > And just a few comments describing the I/O of the basic functions > (and/or the global vars/containers that take the results). > > Good idea, I'm attaching an org-babel-template.el file which tries to be just that. I'd be interested to hear how it works for you, or if you want to make any changes. Once there is a good version maybe it would be a good thing to either add to the babel/lisp/langs directory, or at least to post on Worg. --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=org-babel-template.el Content-Transfer-Encoding: quoted-printable ;;; org-babel-template.el --- org-babel functions for template evaluation ;; Copyright (C) your name here ;; Author: your name here ;; Keywords: literate programming, reproducible research ;; Homepage: http://orgmode.org ;; Version: 0.01 ;;; License: ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; This file is not intended to ever be loaded by org-babel, rather it ;; is a template for use in adding new language support to Org-babel. ;; Good first steps are to copy this file to a file named by the ;; language you are adding, and then use `query-replace' to replace ;; all strings of "template" in this file with the name of your new ;; language. ;; ;; If you have questions as to any of the portions of the file defined ;; below please look to existing language support for guidance. ;;; Requirements: ;; Use this section to list the requirements of this language. Most ;; languages will require that at least the language be installed on ;; the user's system, and the Emacs major mode relevant to the ;; language be installed as well. ;;; Code: (require 'org-babel) ;; possibly require modes required for your language ;; Add this language to the list of supported languages. Org-babel ;; will match the string below against the declared language of the ;; source-code block. (org-babel-add-interpreter "template") ;; specify the name, file extension, and shebang line for this language (add-to-list 'org-babel-tangle-langs '("template" "template-extension" "#!/= usr/bin/env template")) ;; This is the main function which is called to evaluate a code ;; block. It should setup the source code block according to all of ;; the header arguments packaged into params, including... ;; - defining variables ;; - optionally starting up a session (depending on the value of the ;; :session) header argument ;; ;; This function will then evaluate the body of the source code and ;; return the results as emacs-lisp depending on the value of the ;; :results header argument ;; - output means that the output to STDOUT will be captured and ;; returned ;; - value means that the value of the last statement in the ;; source code block will be returned ;; ;; Existing variables. The following variables are already defined ;; for use in this function. ;;=20 ;; - session :: name of the session to be used for evaluation or nil ;; for non-session based evaluation ;;=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ;; - vars :: list of cons cells s.t. the car of each element is the ;; name of a variable and the cdr is the emacs-lisp value to ;; associate with the element ;;=20=20=20=20=20=20=20=20=20=20=20 ;; - result-params :: list of the values of the :results header ;; argument, for more information on possible values of the ;; :results header argument see ;; http://orgmode.org/worg/org-contrib/babel/org-babel.php#header= -arguments ;; ;; - result-type :: either 'output or 'value as mentioned above (defun org-babel-execute:template (body params) "Execute a block of Template code with org-babel. This function is called by `org-babel-execute-src-block' via multiple-value-bind." (message "executing Template source code block") (let ((full-body (concat ;; prepend code to define all arguments passed to the c= ode block (mapconcat (lambda (pair) (format "%s=3D%s" (car pair) (org-babel-template-var-to-template (cdr pair)))) vars "\n") "\n" body "\n")) ;; set the session if the session variable is non-nil (session (org-babel-template-initiate-session session))) ;; actually execute the source-code block either in a session or ;; possibly by dropping it to a temporary file and evaluating the ;; file. ;;=20 ;; for session based evaluation the helpers defined in ;; `org-babel-comint' will probably be helpful. )) ;; This function should be used to assign any variables in params in ;; the context of the session environment. (defun org-babel-prep-session:template (session params) "Prepare SESSION according to the header arguments specified in PARAMS." ) (defun org-babel-template-var-to-template (var) "Convert an elisp var into a string of template source code specifying a var of the same value." ) (defun org-babel-template-table-or-string (results) "If the results look like a table, then convert them into an Emacs-lisp table, otherwise return the results as a string." ) (defun org-babel-template-initiate-session (&optional session) "If there is not a current inferior-process-buffer in SESSION then create. Return the initialized session." (unless (string=3D session "none") )) (provide 'org-babel-template) ;;; org-babel-template.el ends here --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable >> There are two key language specific features which keep us from treating >> all interpreted languages identically. >> 1) Org-babel collects the last value of a source-code block to be >> returned (see [1]) and this value needs to be collected and >> potentially converted into elisp in a language specific manner >> 2) Org-babel has support for evaluation in a session allowing >> persistence of state between different blocks which use the same >> session. I now notice that the :session header argument is not >> currently documented on the Worg page. I'll try to add this >> documentation soon. The sessions are handled through Emacs comint >> buffers which are very language specific. > > > Ahhh, I now comprehend. You're library makes all kinds of source blocks > work together as a whole. Great! I now understand your intention! Make > that old joke become true: "Emacs is a great OS, it's just missing a > good editor" :-D > ..... Nachtigall ick h=C3=B6r dir trappsen ... > :) heh, I hadn't thought of it that way, but yea, the idea is to allow different languages to interact all using emacs-lisp as the lower-common-denominator. Best -- Eric --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-=--