From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric S Fraga Subject: Re: [babel] maxima support? Date: Tue, 15 Mar 2011 16:39:32 +0000 Message-ID: <87d3lss5h7.fsf@ucl.ac.uk> References: <5rbp23p04b.fsf@kana.aer.mw.tum.de> <87bp21ohkt.fsf@pinto.chemeng.ucl.ac.uk> <8762s7ipr7.fsf@gmail.com> <87y6503zkk.fsf@ucl.ac.uk> <874o75wfzf.fsf@gmail.com> <871v28slsr.fsf@ucl.ac.uk> <87r5a834lc.fsf@gmail.com> <87fwqompb6.fsf@ucl.ac.uk> <87oc5c1js6.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from [140.186.70.92] (port=54754 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PzXHZ-0004tX-8A for emacs-orgmode@gnu.org; Tue, 15 Mar 2011 12:39:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PzXHX-0003oO-TT for emacs-orgmode@gnu.org; Tue, 15 Mar 2011 12:39:41 -0400 Received: from vscane-a2.ucl.ac.uk ([144.82.108.42]:46517) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PzXHX-0003o4-J4 for emacs-orgmode@gnu.org; Tue, 15 Mar 2011 12:39:39 -0400 In-Reply-To: <87oc5c1js6.fsf@gmail.com> (Eric Schulte's message of "Tue, 15 Mar 2011 09:32:41 -0600") 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: Eric Schulte Cc: Litvinov Sergey , emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain "Eric Schulte" writes: > Eric S Fraga writes: > >> "Eric Schulte" writes: >> >> [...] >> >>> >>> Ah, I see the problem, I used let instead of let*. Please try this >>> updated version of the patch. Sorry I would test this myself, but I >>> don't have Maxima installed. >> >> No problem at all! I'm happy to test this as many times as necessary. >> >> In any case, this works fine in that maxima is indeed evaluated and >> output is returned. However, two problems arise: >> >> 1. lines of the form "rat: replaced XXX by YYY = ZZZ" are not deleted >> (as used to be by the grep -v replaced hack I had in the original >> ob-maxima). Essentially, we need to ignore output lines that match >> the regex "^rat: replaced .*$" (I think this should do it...). >> >> 2. The output is converted to an org table: >> > > The attached should fix both of these problems. Please let me know how > this works. Eric, Well, it didn't work :(. However, I think I managed to fix it. I think you have an ulterior motive: to make me learn elisp properly once and for all... ;-). Attached is the updated ob-maxima.el file with two changes: 1. quoted =identity= in the =mapconcat= sexp. 2. asked =split-string= to split on newlines so that (a) the regex for the rat line would match *and* (b) so that the output is faithful to what maxima generates. I hope these make sense! I've gone through the code and I think I understand it. More importantly, the output is now essentially the same as I was getting before which makes me quite happy. I'll do some more testing but the various tests I have tried should cover most aspects that I ever use. Thanks, eric --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=ob-maxima.el Content-Transfer-Encoding: quoted-printable Content-Description: modified ob-maximal file ;;; org-babel-maxima.el --- org-babel functions for maxima evaluation ;; Copyright (c) 2009, 2010, 2011 Eric S Fraga, Eric Schulte ;; Author: Eric S Fraga, Eric Schulte ;; Keywords: literate programming, reproducible research, maxima ;; 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: ;; Org-Babel support for evaluating maxima entries. ;; ;; This differs from most standard languages in that ;; ;; 1) there is no such thing as a "session" in maxima ;; ;; 2) we are generally only going to return output from maxima ;; ;; 3) we are adding the "cmdline" header argument ;; ;; 4) there are no variables ;;; Code: (require 'ob) (defvar org-babel-default-header-args:maxima '()) (defun org-babel-maxima-expand (body params) "Expand a block of Maxima code according to its header arguments." body) (defun org-babel-execute:maxima (body params) "Execute a block of Maxima entries with org-babel. This function is called by `org-babel-execute-src-block'." (message "executing Maxima source code block") (let* ((result-params (split-string (or (cdr (assoc :results params)) "")= )) (cmdline (cdr (assoc :cmdline params))) (in-file (org-babel-temp-file "maxima-")) (cmd (format "maxima --very-quiet -r 'batchload(%S)$' %s" in-file cmdline))) (with-temp-file in-file (insert body)) (message cmd) ((lambda (raw) ;; " | grep -v batch | grep -v 'replaced' | sed '/^$/d' " (mapconcat 'identity (delq nil (mapcar (lambda (line) (unless (or (string-match "batch" line) (string-match "^rat: replaced .*$" line) (=3D 0 (length line))) line)) (split-string raw "\n"))) "\n")) (org-babel-eval cmd "")))) (defun org-babel-prep-session:maxima (session params) (error "Maxima does not support sessions")) (provide 'ob-maxima) ;; arch-tag: d86c97ac-7eab-4349-8d8b-302dd09779a8 ;;; org-babel-maxima.el ends here --=-=-= Content-Type: text/plain -- : Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1 : using Org-mode version 7.5 (release_7.5.38.gf8c6.dirty) --=-=-=--