1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-24 07:20:29 +00:00
org-mode/lisp/ob-haskell.el

390 lines
16 KiB
EmacsLisp
Raw Normal View History

Activate lexical binding in some libraries * lisp/ob-C.el (org-babel-prep-session:C): (org-babel-load-session:C): * lisp/ob-J.el: (org-babel-expand-body:J): (org-babel-execute:J): * lisp/ob-R.el: (org-babel-expand-body:R): * lisp/ob-abc.el: (org-babel-execute:abc): (org-babel-prep-session:abc): * lisp/ob-asymptote.el: (org-babel-execute:asymptote): (org-babel-prep-session:asymptote): * lisp/ob-awk.el: (org-babel-expand-body:awk): * lisp/ob-calc.el: (org-babel-expand-body:calc): * lisp/ob-clojure.el: * lisp/ob-comint.el: (org-babel-comint-in-buffer): (org-babel-comint-with-output): (org-babel-comint-eval-invisibly-and-wait-for-file): * lisp/ob-coq.el: * lisp/ob-css.el: (org-babel-execute:css): (org-babel-prep-session:css): * lisp/ob-ditaa.el: (org-babel-execute:ditaa): (org-babel-prep-session:ditaa): * lisp/ob-dot.el: (org-babel-execute:dot): (org-babel-prep-session:dot): * lisp/ob-ebnf.el: * lisp/ob-emacs-lisp.el: * lisp/ob-eval.el: * lisp/ob-forth.el: * lisp/ob-fortran.el: (org-babel-execute:fortran): (org-babel-prep-session:fortran): (org-babel-load-session:fortran): * lisp/ob-gnuplot.el: (org-babel-expand-body:gnuplot): (org-babel-prep-session:gnuplot): (org-babel-gnuplot-initiate-session): * lisp/ob-groovy.el: (org-babel-prep-session:groovy): (org-babel-groovy-initiate-session): * lisp/ob-haskell.el: (org-babel-haskell-initiate-session): * lisp/ob-io.el: (org-babel-prep-session:io): (org-babel-io-initiate-session): * lisp/ob-java.el: (org-babel-execute:java): * lisp/ob-js.el: * lisp/ob-keys.el: * lisp/ob-latex.el: (org-babel-prep-session:latex): * lisp/ob-ledger.el: (org-babel-execute:ledger): (org-babel-prep-session:ledger): * lisp/ob-lilypond.el: (org-babel-lilypond-commands): (org-babel-lilypond-process-basic): (org-babel-prep-session:lilypond): (org-babel-lilypond-parse-line-num): * lisp/ob-lisp.el: * lisp/ob-makefile.el: (org-babel-execute:makefile): (org-babel-prep-session:makefile): * lisp/ob-matlab.el: * lisp/ob-maxima.el: (org-babel-prep-session:maxima): * lisp/ob-mscgen.el: (org-babel-prep-session:mscgen): * lisp/ob-ocaml.el: (org-babel-execute:ocaml): (org-babel-prep-session:ocaml): * lisp/ob-octave.el: (org-babel-execute:octave): (org-babel-octave-initiate-session): * lisp/ob-org.el: (org-babel-prep-session:org): * lisp/ob-perl.el: (org-babel-prep-session:perl): (org-babel-perl--var-to-perl): (org-babel-perl-initiate-session): * lisp/ob-picolisp.el: (org-babel-expand-body:picolisp): (org-babel-execute:picolisp): * lisp/ob-plantuml.el: (org-babel-execute:plantuml): (org-babel-prep-session:plantuml): * lisp/ob-processing.el: (org-babel-prep-session:processing): * lisp/ob-python.el: (org-babel-python-initiate-session): * lisp/ob-ref.el: (org-babel-ref-resolve): * lisp/ob-ruby.el: (org-babel-ruby-initiate-session): * lisp/ob-sass.el: (org-babel-execute:sass): (org-babel-prep-session:sass): * lisp/ob-scala.el: (org-babel-execute:scala): (org-babel-prep-session:scala): (org-babel-scala-initiate-session): * lisp/ob-scheme.el: * lisp/ob-screen.el: (org-babel-prep-session:screen): (org-babel-screen-session-write-temp-file): (org-babel-screen-test): * lisp/ob.el: * lisp/org-colview.el: (org-columns-todo): (org-columns-set-tags-or-toggle): (org-columns-new): (org-columns-uncompile-format): (org-agenda-colview-summarize): * lisp/org-footnote.el: (electric-indent-mode): * lisp/org-indent.el: (org-indent-refresh-maybe): * lisp/org-list.el: * lisp/org-macro.el: (org-macro--collect-macros): * lisp/org-src.el: * lisp/org-table.el: (sort-fold-case): (org-table-create): (org-table-field-info): (org-table-transpose-table-at-point): (org-table-remove-rectangle-highlight): (orgtbl-create-or-convert-from-region): (org-define-lookup-function): * lisp/ox-ascii.el: (org-ascii-format-drawer-function): (org-ascii--has-caption-p): (org-ascii-bold): (org-ascii-center-block): (org-ascii-clock): (org-ascii-code): (org-ascii-dynamic-block): (org-ascii-entity): (org-ascii-example-block): (org-ascii-export-snippet): (org-ascii-export-block): (org-ascii-fixed-width): (org-ascii-footnote-reference): (org-ascii-horizontal-rule): (org-ascii-inline-src-block): (org-ascii-format-inlinetask-default): (org-ascii-italic): (org-ascii-keyword): (org-ascii-latex-environment): (org-ascii-latex-fragment): (org-ascii-line-break): (org-ascii-node-property): (org-ascii-planning): (org-ascii-quote-block): (org-ascii-radio-target): (org-ascii-special-block): (org-ascii-src-block): (org-ascii-statistics-cookie): (org-ascii-subscript): (org-ascii-superscript): (org-ascii-strike-through): (org-ascii-timestamp): (org-ascii-underline): (org-ascii-verbatim): (org-ascii-verse-block): (org-ascii-filter-headline-blank-lines): (org-ascii-filter-paragraph-spacing): (org-ascii-filter-comment-spacing): Use lexical binding.
2015-10-26 00:56:00 +00:00
;;; ob-haskell.el --- Babel Functions for Haskell -*- lexical-binding: t; -*-
2009-08-27 14:03:02 +00:00
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
2009-08-27 14:03:02 +00:00
;; Author: Eric Schulte
;; Maintainer: Lawrence Bottorff <borgauf@gmail.com>
2009-08-27 14:03:02 +00:00
;; Keywords: literate programming, reproducible research
;; URL: https://orgmode.org
2009-08-27 14:03:02 +00:00
;; This file is part of GNU Emacs.
2009-08-27 14:03:02 +00:00
;; GNU Emacs is free software: you can redistribute it and/or modify
2009-08-27 14:03:02 +00:00
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
2009-08-27 14:03:02 +00:00
;; 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.
2009-08-27 14:03:02 +00:00
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
2009-08-27 14:03:02 +00:00
;;; Commentary:
;; Org Babel support for evaluating Haskell source code.
;; Haskell programs must be compiled before
2009-08-27 14:03:02 +00:00
;; they can be run, but haskell code can also be run through an
;; interactive interpreter.
;;
;; By default we evaluate using the Haskell interpreter.
;; To use the compiler, specify :compile yes in the header.
2009-08-27 14:03:02 +00:00
;;; Requirements:
2021-03-21 18:55:14 +00:00
;; - haskell-mode: https://www.iro.umontreal.ca/~monnier/elisp/#haskell-mode
;; - inf-haskell: https://www.iro.umontreal.ca/~monnier/elisp/#haskell-mode
;; - (optionally) lhs2tex: https://people.cs.uu.nl/andres/lhs2tex/
2009-08-27 14:03:02 +00:00
;;; Code:
(require 'org-macs)
(org-assert-version)
(require 'ob)
(require 'org-macs)
(require 'comint)
(declare-function haskell-mode "ext:haskell-mode" ())
(declare-function run-haskell "ext:inf-haskell" (&optional arg))
(declare-function inferior-haskell-load-file
"ext:inf-haskell" (&optional reload))
(declare-function org-entry-get "org" (pom property &optional inherit literal-nil))
2009-08-27 14:03:02 +00:00
(defvar org-babel-tangle-lang-exts)
(add-to-list 'org-babel-tangle-lang-exts '("haskell" . "hs"))
(defvar org-babel-default-header-args:haskell
'((:padlines . "no")))
(defvar org-babel-haskell-lhs2tex-command "lhs2tex")
(defvar org-babel-haskell-eoe "org-babel-haskell-eoe")
2009-08-27 14:03:02 +00:00
(defvar haskell-prompt-regexp)
(defcustom org-babel-haskell-compiler "ghc"
"Command used to compile a Haskell source code file into an executable.
May be either a command in the path, like \"ghc\" or an absolute
path name, like \"/usr/local/bin/ghc\". The command can include
a parameter, such as \"ghc -v\"."
:group 'org-babel
:package-version '(Org "9.4")
:type 'string)
(defconst org-babel-header-args:haskell '((compile . :any))
"Haskell-specific header arguments.")
(defun org-babel-haskell-with-session--worker (params todo)
"See `org-babel-haskell-with-session'."
(let* ((sn (cdr (assq :session params)))
(session (org-babel-haskell-initiate-session sn params))
(one-shot (equal sn "none")))
(unwind-protect
(funcall todo session)
(when (and one-shot (buffer-live-p session))
;; As we don't control how the session temporary buffer is
;; created, we need to explicitly work around the hooks and
;; query functions.
(with-current-buffer session
(let ((kill-buffer-query-functions nil)
(kill-buffer-hook nil))
(kill-buffer session)))))))
(defmacro org-babel-haskell-with-session (session-symbol params &rest body)
"Get the session identified by PARAMS and run BODY with it.
Get or create a session, as needed to match PARAMS. Assign the session to
SESSION-SYMBOL. Execute BODY. Destroy the session if needed.
Return the value of the last form of BODY."
(declare (indent 2) (debug (symbolp form body)))
`(org-babel-haskell-with-session--worker ,params (lambda (,session-symbol) ,@body)))
(defun org-babel-haskell-execute (body params)
"Execute Haskell BODY according to PARAMS.
This function should only be called by `org-babel-execute:haskell'."
(let* ((tmp-src-file (org-babel-temp-file "Haskell-src-" ".hs"))
(tmp-bin-file
(org-babel-process-file-name
(org-babel-temp-file "Haskell-bin-" org-babel-exeext)))
(cmdline (cdr (assq :cmdline params)))
(cmdline (if cmdline (concat " " cmdline) ""))
(flags (cdr (assq :flags params)))
(flags (mapconcat #'identity
(if (listp flags)
flags
(list flags))
" "))
(libs (org-babel-read
(or (cdr (assq :libs params))
(org-entry-get nil "libs" t))
nil))
(libs (mapconcat #'identity
(if (listp libs) libs (list libs))
" ")))
(with-temp-file tmp-src-file (insert body))
(org-babel-eval
(format "%s -o %s %s %s %s"
org-babel-haskell-compiler
tmp-bin-file
flags
(org-babel-process-file-name tmp-src-file)
libs)
"")
(let ((results (org-babel-eval (concat tmp-bin-file cmdline) "")))
(when results
(setq results (org-trim (org-remove-indentation results)))
(org-babel-reassemble-table
(org-babel-result-cond (cdr (assq :result-params params))
(org-babel-read results t)
(let ((tmp-file (org-babel-temp-file "Haskell-")))
(with-temp-file tmp-file (insert results))
(org-babel-import-elisp-from-file tmp-file)))
(org-babel-pick-name
(cdr (assq :colname-names params)) (cdr (assq :colnames params)))
(org-babel-pick-name
(cdr (assq :rowname-names params)) (cdr (assq :rownames params))))))))
(defun org-babel-interpret-haskell (body params)
Provide a uniform way to inform users about missing third-party packages * lisp/org-macs.el (org-require-package): New macro trying to load a library and displaying custom error message or warning on failure. The actual package (not library) name can be provided as optional argument. * lisp/ob-R.el (org-babel-R-initiate-session): * lisp/ob-clojure.el (ob-clojure-eval-with-inf-clojure): (ob-clojure-eval-with-cider): (ob-clojure-eval-with-slime): * lisp/ob-forth.el (org-babel-forth-session-execute): * lisp/ob-gnuplot.el (org-babel-execute:gnuplot): (org-babel-gnuplot-initiate-session): * lisp/ob-haskell.el (org-babel-interpret-haskell): (org-babel-haskell-initiate-session): * lisp/ob-js.el (org-babel-execute:js): (org-babel-js-initiate-session): * lisp/ob-julia.el (org-babel-julia-initiate-session): * lisp/ob-lisp.el (org-babel-execute:lisp): * lisp/ob-ocaml.el (org-babel-prep-session:ocaml): * lisp/ob-octave.el (org-babel-octave-initiate-session): * lisp/ob-processing.el (org-babel-processing-view-sketch): * lisp/ob-ruby.el (org-babel-execute:ruby): (org-babel-ruby-initiate-session): * lisp/ol-bbdb.el (org-bbdb-open): (org-bbdb-complete-link): (org-bbdb-anniv-export-ical): * lisp/org-agenda.el: * lisp/org-plot.el (org-plot/gnuplot): * lisp/org.el: * lisp/ox-ascii.el (org-ascii-table): * lisp/ox-html.el (org-html-htmlize-generate-css): * lisp/ox-org.el: Use the new macro. * lisp/oc-csl.el: Add FIXME. oc-csl uses a custom function doing similar job. * lisp/ob-js.el (org-babel-js-initiate-session): Add FIXME noting that the third-party package is outdated.
2023-01-23 15:06:46 +00:00
(org-require-package 'inf-haskell "haskell-mode")
(add-hook 'inferior-haskell-hook
(lambda ()
(setq-local
org-babel-comint-prompt-regexp-fallback comint-prompt-regexp
comint-prompt-regexp
(concat haskell-prompt-regexp "\\|^λ?> "))))
(org-babel-haskell-with-session session params
(cl-labels
((send-txt-to-ghci (txt)
(insert txt) (comint-send-input nil t))
(send-eoe ()
(send-txt-to-ghci (concat "putStrLn \"" org-babel-haskell-eoe "\"\n")))
(comint-with-output (todo)
(let ((comint-preoutput-filter-functions
(cons 'ansi-color-filter-apply
comint-preoutput-filter-functions)))
(org-babel-comint-with-output
(session org-babel-haskell-eoe nil nil)
(funcall todo)))))
(let* ((result-type (cdr (assq :result-type params)))
(full-body (org-babel-expand-body:generic
body params
(org-babel-variable-assignments:haskell params)))
(raw (pcase result-type
(`output
(comint-with-output
(lambda () (send-txt-to-ghci (org-trim full-body)) (send-eoe))))
(`value
;; We first compute the value and store it,
;; ignoring any output.
(comint-with-output
(lambda ()
(send-txt-to-ghci "__LAST_VALUE_IMPROBABLE_NAME__=()::()\n")
(send-txt-to-ghci (org-trim full-body))
(send-txt-to-ghci "__LAST_VALUE_IMPROBABLE_NAME__=it\n")
(send-eoe)))
;; We now display and capture the value.
(comint-with-output
(lambda()
(send-txt-to-ghci "__LAST_VALUE_IMPROBABLE_NAME__\n")
(send-eoe))))))
(results (mapcar #'org-strip-quotes
(cdr (member org-babel-haskell-eoe
(reverse (mapcar #'org-trim raw)))))))
(org-babel-reassemble-table
(let ((result
(pcase result-type
(`output (mapconcat #'identity (reverse results) "\n"))
(`value (car results)))))
(org-babel-result-cond (cdr (assq :result-params params))
result (when result (org-babel-script-escape result))))
(org-babel-pick-name (cdr (assq :colname-names params))
(cdr (assq :colname-names params)))
(org-babel-pick-name (cdr (assq :rowname-names params))
(cdr (assq :rowname-names params))))))))
2009-08-27 14:03:02 +00:00
(defun org-babel-execute:haskell (body params)
"Execute a block of Haskell code."
(let ((compile (string= "yes" (cdr (assq :compile params)))))
(if (not compile)
(org-babel-interpret-haskell body params)
(org-babel-haskell-execute body params))))
;; Variable defined in inf-haskell (haskell-mode package).
(defvar inferior-haskell-buffer)
(defvar inferior-haskell-root-dir)
(defun org-babel-haskell-initiate-session (&optional session-name _params)
2010-07-13 23:20:08 +00:00
"Initiate a haskell session.
Return the initialized session, i.e. the buffer for this session.
When SESSION-NAME is nil, use a global session named
\"*ob-haskell*\". When SESSION-NAME is the string \"none\", use
a temporary buffer. Else, (re)use the session named
SESSION-NAME. The buffer name is the session name. See also
`org-babel-haskell-with-session'."
Provide a uniform way to inform users about missing third-party packages * lisp/org-macs.el (org-require-package): New macro trying to load a library and displaying custom error message or warning on failure. The actual package (not library) name can be provided as optional argument. * lisp/ob-R.el (org-babel-R-initiate-session): * lisp/ob-clojure.el (ob-clojure-eval-with-inf-clojure): (ob-clojure-eval-with-cider): (ob-clojure-eval-with-slime): * lisp/ob-forth.el (org-babel-forth-session-execute): * lisp/ob-gnuplot.el (org-babel-execute:gnuplot): (org-babel-gnuplot-initiate-session): * lisp/ob-haskell.el (org-babel-interpret-haskell): (org-babel-haskell-initiate-session): * lisp/ob-js.el (org-babel-execute:js): (org-babel-js-initiate-session): * lisp/ob-julia.el (org-babel-julia-initiate-session): * lisp/ob-lisp.el (org-babel-execute:lisp): * lisp/ob-ocaml.el (org-babel-prep-session:ocaml): * lisp/ob-octave.el (org-babel-octave-initiate-session): * lisp/ob-processing.el (org-babel-processing-view-sketch): * lisp/ob-ruby.el (org-babel-execute:ruby): (org-babel-ruby-initiate-session): * lisp/ol-bbdb.el (org-bbdb-open): (org-bbdb-complete-link): (org-bbdb-anniv-export-ical): * lisp/org-agenda.el: * lisp/org-plot.el (org-plot/gnuplot): * lisp/org.el: * lisp/ox-ascii.el (org-ascii-table): * lisp/ox-html.el (org-html-htmlize-generate-css): * lisp/ox-org.el: Use the new macro. * lisp/oc-csl.el: Add FIXME. oc-csl uses a custom function doing similar job. * lisp/ob-js.el (org-babel-js-initiate-session): Add FIXME noting that the third-party package is outdated.
2023-01-23 15:06:46 +00:00
(org-require-package 'inf-haskell "haskell-mode")
(cond
((equal "none" session-name)
;; Temporary buffer name.
(setq session-name (generate-new-buffer-name " *ob-haskell-tmp*")))
((eq nil session-name)
;; The global default session. As haskell-mode is using the buffer
;; named "*haskell*", we stay away from it.
(setq session-name "*ob-haskell*"))
((not (stringp session-name))
(error "session-name must be a string")))
(let ((session (get-buffer session-name)))
;; NOTE: By construction, as SESSION-NAME is a string, session is
;; either nil or a live buffer.
(save-window-excursion
(or (org-babel-comint-buffer-livep session)
(let ((inferior-haskell-buffer session))
;; As inferior-haskell expects the buffer to be named
;; "*haskell*", we temporarily rename it while executing
;; `run-haskell' (unless the user explicitly requested to
;; use the name "*haskell*").
(when (not (equal "*haskell*" session-name))
(when (bufferp session)
(when (bufferp "*haskell*")
(user-error "Conflicting buffer '*haskell*', rename it or kill it"))
(with-current-buffer session (rename-buffer "*haskell*"))))
(unwind-protect
(let ((inferior-haskell-root-dir default-directory))
(run-haskell)
(sleep-for 0.25)
(setq session inferior-haskell-buffer))
(when (and (not (equal "*haskell*" session-name))
(bufferp session))
(with-current-buffer session (rename-buffer session-name))))
;; Disable secondary prompt: If we do not do this,
;; org-comint may treat secondary prompts as a part of
;; output.
(org-babel-comint-input-command
session
":set prompt-cont \"\"")
session)
))
session))
removing obsoleted optional third argument from org-babel-expand-body:LANG * lisp/ob-C.el (org-babel-expand-body:c++): removing obsoleted optional third argument (org-babel-expand-body:c++): removing obsoleted optional third argument (org-babel-C-expand): removing obsoleted optional third argument * lisp/ob-R.el: (org-babel-expand-body:R): removing obsoleted optional third argument (org-babel-execute:R): removing obsoleted optional third argument (org-babel-R-variable-assignments): removing obsoleted optional third argument * lisp/ob-asymptote.el: (org-babel-expand-body:asymptote): removing obsoleted optional third argument (org-babel-execute:asymptote): removing obsoleted optional third argument * lisp/ob-clojure.el: (org-babel-expand-body:clojure): removing obsoleted optional third argument (org-babel-execute:clojure): removing obsoleted optional third argument * lisp/ob-css.el: (org-babel-expand-body:css): removing obsoleted optional third argument * lisp/ob-ditaa.el: (org-babel-expand-body:ditaa): removing obsoleted optional third argument * lisp/ob-dot.el: (org-babel-expand-body:dot): removing obsoleted optional third argument (org-babel-execute:dot): removing obsoleted optional third argument * lisp/ob-emacs-lisp.el: (org-babel-expand-body:emacs-lisp): removing obsoleted optional third argument (org-babel-execute:emacs-lisp): removing obsoleted optional third argument * lisp/ob-gnuplot.el: (org-babel-expand-body:gnuplot): removing obsoleted optional third argument * lisp/ob-haskell.el: (org-babel-expand-body:haskell): removing obsoleted optional third argument (org-babel-execute:haskell): removing obsoleted optional third argument (org-babel-load-session:haskell): removing obsoleted optional third (org-babel-prep-session:haskell): removing obsoleted optional third * lisp/ob-js.el: (org-babel-expand-body:js): removing obsoleted optional third argument (org-babel-execute:js): removing obsoleted optional third argument * lisp/ob-latex.el: (org-babel-expand-body:latex): removing obsoleted optional third argument * lisp/ob-lisp.el: (org-babel-expand-body:lisp): removing obsoleted optional third argument (org-babel-execute:lisp): removing obsoleted optional third argument * lisp/ob-mscgen.el: (org-babel-expand-body:mscgen): removing obsoleted optional third argument * lisp/ob-ocaml.el: (org-babel-expand-body:ocaml): removing obsoleted optional third argument (org-babel-execute:ocaml): removing obsoleted optional third argument * lisp/ob-octave.el: (org-babel-expand-body:matlab): removing obsoleted optional third argument (org-babel-expand-body:octave): removing obsoleted optional third argument (org-babel-execute:octave): removing obsoleted optional third argument (org-babel-octave-variable-assignments): removing obsoleted optional third * lisp/ob-org.el: (org-babel-expand-body:org): removing obsoleted optional third argument * lisp/ob-perl.el: (org-babel-expand-body:perl): removing obsoleted optional third argument (org-babel-execute:perl): removing obsoleted optional third argument * lisp/ob-plantuml.el: (org-babel-expand-body:plantuml): removing obsoleted optional third argument * lisp/ob-python.el: (org-babel-expand-body:python): removing obsoleted optional third argument (org-babel-execute:python): removing obsoleted optional third argument (org-babel-python-variable-assignments): removing obsoleted optional third * lisp/ob-ruby.el: (org-babel-expand-body:ruby): removing obsoleted optional third argument (org-babel-execute:ruby): removing obsoleted optional third argument * lisp/ob-sass.el: (org-babel-expand-body:sass): removing obsoleted optional third argument * lisp/ob-scheme.el: (org-babel-expand-body:scheme): removing obsoleted optional third argument (org-babel-execute:scheme): removing obsoleted optional third argument * lisp/ob-screen.el: (org-babel-expand-body:screen): removing obsoleted optional third argument * lisp/ob-sh.el: (org-babel-expand-body:sh): removing obsoleted optional third argument (org-babel-execute:sh): removing obsoleted optional third argument (org-babel-sh-variable-assignments): removing obsoleted optional third * lisp/ob-sql.el: (org-babel-expand-body:sql): removing obsoleted optional third argument * lisp/ob-sqlite.el: (org-babel-expand-body:sqlite): removing obsoleted optional third argument (org-babel-execute:sqlite): removing obsoleted optional third argument * lisp/ob.el: (org-babel-expand-body:generic): removing obsoleted optional third argument
2010-10-16 03:35:45 +00:00
(defun org-babel-load-session:haskell (session body params)
"Load BODY into SESSION."
(save-window-excursion
removing obsoleted optional third argument from org-babel-expand-body:LANG * lisp/ob-C.el (org-babel-expand-body:c++): removing obsoleted optional third argument (org-babel-expand-body:c++): removing obsoleted optional third argument (org-babel-C-expand): removing obsoleted optional third argument * lisp/ob-R.el: (org-babel-expand-body:R): removing obsoleted optional third argument (org-babel-execute:R): removing obsoleted optional third argument (org-babel-R-variable-assignments): removing obsoleted optional third argument * lisp/ob-asymptote.el: (org-babel-expand-body:asymptote): removing obsoleted optional third argument (org-babel-execute:asymptote): removing obsoleted optional third argument * lisp/ob-clojure.el: (org-babel-expand-body:clojure): removing obsoleted optional third argument (org-babel-execute:clojure): removing obsoleted optional third argument * lisp/ob-css.el: (org-babel-expand-body:css): removing obsoleted optional third argument * lisp/ob-ditaa.el: (org-babel-expand-body:ditaa): removing obsoleted optional third argument * lisp/ob-dot.el: (org-babel-expand-body:dot): removing obsoleted optional third argument (org-babel-execute:dot): removing obsoleted optional third argument * lisp/ob-emacs-lisp.el: (org-babel-expand-body:emacs-lisp): removing obsoleted optional third argument (org-babel-execute:emacs-lisp): removing obsoleted optional third argument * lisp/ob-gnuplot.el: (org-babel-expand-body:gnuplot): removing obsoleted optional third argument * lisp/ob-haskell.el: (org-babel-expand-body:haskell): removing obsoleted optional third argument (org-babel-execute:haskell): removing obsoleted optional third argument (org-babel-load-session:haskell): removing obsoleted optional third (org-babel-prep-session:haskell): removing obsoleted optional third * lisp/ob-js.el: (org-babel-expand-body:js): removing obsoleted optional third argument (org-babel-execute:js): removing obsoleted optional third argument * lisp/ob-latex.el: (org-babel-expand-body:latex): removing obsoleted optional third argument * lisp/ob-lisp.el: (org-babel-expand-body:lisp): removing obsoleted optional third argument (org-babel-execute:lisp): removing obsoleted optional third argument * lisp/ob-mscgen.el: (org-babel-expand-body:mscgen): removing obsoleted optional third argument * lisp/ob-ocaml.el: (org-babel-expand-body:ocaml): removing obsoleted optional third argument (org-babel-execute:ocaml): removing obsoleted optional third argument * lisp/ob-octave.el: (org-babel-expand-body:matlab): removing obsoleted optional third argument (org-babel-expand-body:octave): removing obsoleted optional third argument (org-babel-execute:octave): removing obsoleted optional third argument (org-babel-octave-variable-assignments): removing obsoleted optional third * lisp/ob-org.el: (org-babel-expand-body:org): removing obsoleted optional third argument * lisp/ob-perl.el: (org-babel-expand-body:perl): removing obsoleted optional third argument (org-babel-execute:perl): removing obsoleted optional third argument * lisp/ob-plantuml.el: (org-babel-expand-body:plantuml): removing obsoleted optional third argument * lisp/ob-python.el: (org-babel-expand-body:python): removing obsoleted optional third argument (org-babel-execute:python): removing obsoleted optional third argument (org-babel-python-variable-assignments): removing obsoleted optional third * lisp/ob-ruby.el: (org-babel-expand-body:ruby): removing obsoleted optional third argument (org-babel-execute:ruby): removing obsoleted optional third argument * lisp/ob-sass.el: (org-babel-expand-body:sass): removing obsoleted optional third argument * lisp/ob-scheme.el: (org-babel-expand-body:scheme): removing obsoleted optional third argument (org-babel-execute:scheme): removing obsoleted optional third argument * lisp/ob-screen.el: (org-babel-expand-body:screen): removing obsoleted optional third argument * lisp/ob-sh.el: (org-babel-expand-body:sh): removing obsoleted optional third argument (org-babel-execute:sh): removing obsoleted optional third argument (org-babel-sh-variable-assignments): removing obsoleted optional third * lisp/ob-sql.el: (org-babel-expand-body:sql): removing obsoleted optional third argument * lisp/ob-sqlite.el: (org-babel-expand-body:sqlite): removing obsoleted optional third argument (org-babel-execute:sqlite): removing obsoleted optional third argument * lisp/ob.el: (org-babel-expand-body:generic): removing obsoleted optional third argument
2010-10-16 03:35:45 +00:00
(let* ((buffer (org-babel-prep-session:haskell session params))
Babel now cleans up any temporary files created using org-babel-temp-file * lisp/ob.el (org-babel-temporary-directory): variable to hold the value of the Babel temporary directory (org-babel-temp-file): replacement for make-temp-file with cleanup on exit of Emacs (org-babel-remove-temporary-directory): cleanup function run on exit of Emacs (kill-emacs-hook): now includes babel cleanup function * lisp/ob-C.el (org-babel-C-execute): using org-babel-temp-file instead of make-temp-file * lisp/ob-R.el (org-babel-R-assign-elisp): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-R-evaluate-external-process): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-R-evaluate-session): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-asymptote.el (org-babel-execute:asymptote): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-clojure.el (org-babel-clojure-evaluate-external-process): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-ditaa.el (org-babel-execute:ditaa): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-dot.el (org-babel-execute:dot): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-gnuplot.el (org-babel-gnuplot-process-vars): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-execute:gnuplot): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-haskell.el (org-babel-load-session:haskell): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-haskell-export-to-lhs): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-latex.el (org-babel-execute:latex): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-ledger.el (org-babel-execute:ledger): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-lisp.el (org-babel-execute:lisp): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-octave.el (org-babel-octave-evaluate-external-process): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-octave-evaluate-session): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-octave-import-elisp-from-file): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-perl.el (org-babel-perl-evaluate): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-python.el (org-babel-python-evaluate): using `org-babel-temp-file' instead of `make-temp-file' using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-ruby.el (org-babel-ruby-evaluate): using `org-babel-temp-file' instead of `make-temp-file' using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-sass.el (org-babel-execute:sass): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-sh.el (org-babel-sh-evaluate): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-sql.el (org-babel-execute:sql): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-sqlite.el (org-babel-execute:sqlite): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-sqlite-expand-vars): using `org-babel-temp-file' instead of `make-temp-file'
2010-08-25 20:43:07 +00:00
(load-file (concat (org-babel-temp-file "haskell-load-") ".hs")))
(with-temp-buffer
(insert body) (write-file load-file)
(haskell-mode) (inferior-haskell-load-file))
buffer)))
removing obsoleted optional third argument from org-babel-expand-body:LANG * lisp/ob-C.el (org-babel-expand-body:c++): removing obsoleted optional third argument (org-babel-expand-body:c++): removing obsoleted optional third argument (org-babel-C-expand): removing obsoleted optional third argument * lisp/ob-R.el: (org-babel-expand-body:R): removing obsoleted optional third argument (org-babel-execute:R): removing obsoleted optional third argument (org-babel-R-variable-assignments): removing obsoleted optional third argument * lisp/ob-asymptote.el: (org-babel-expand-body:asymptote): removing obsoleted optional third argument (org-babel-execute:asymptote): removing obsoleted optional third argument * lisp/ob-clojure.el: (org-babel-expand-body:clojure): removing obsoleted optional third argument (org-babel-execute:clojure): removing obsoleted optional third argument * lisp/ob-css.el: (org-babel-expand-body:css): removing obsoleted optional third argument * lisp/ob-ditaa.el: (org-babel-expand-body:ditaa): removing obsoleted optional third argument * lisp/ob-dot.el: (org-babel-expand-body:dot): removing obsoleted optional third argument (org-babel-execute:dot): removing obsoleted optional third argument * lisp/ob-emacs-lisp.el: (org-babel-expand-body:emacs-lisp): removing obsoleted optional third argument (org-babel-execute:emacs-lisp): removing obsoleted optional third argument * lisp/ob-gnuplot.el: (org-babel-expand-body:gnuplot): removing obsoleted optional third argument * lisp/ob-haskell.el: (org-babel-expand-body:haskell): removing obsoleted optional third argument (org-babel-execute:haskell): removing obsoleted optional third argument (org-babel-load-session:haskell): removing obsoleted optional third (org-babel-prep-session:haskell): removing obsoleted optional third * lisp/ob-js.el: (org-babel-expand-body:js): removing obsoleted optional third argument (org-babel-execute:js): removing obsoleted optional third argument * lisp/ob-latex.el: (org-babel-expand-body:latex): removing obsoleted optional third argument * lisp/ob-lisp.el: (org-babel-expand-body:lisp): removing obsoleted optional third argument (org-babel-execute:lisp): removing obsoleted optional third argument * lisp/ob-mscgen.el: (org-babel-expand-body:mscgen): removing obsoleted optional third argument * lisp/ob-ocaml.el: (org-babel-expand-body:ocaml): removing obsoleted optional third argument (org-babel-execute:ocaml): removing obsoleted optional third argument * lisp/ob-octave.el: (org-babel-expand-body:matlab): removing obsoleted optional third argument (org-babel-expand-body:octave): removing obsoleted optional third argument (org-babel-execute:octave): removing obsoleted optional third argument (org-babel-octave-variable-assignments): removing obsoleted optional third * lisp/ob-org.el: (org-babel-expand-body:org): removing obsoleted optional third argument * lisp/ob-perl.el: (org-babel-expand-body:perl): removing obsoleted optional third argument (org-babel-execute:perl): removing obsoleted optional third argument * lisp/ob-plantuml.el: (org-babel-expand-body:plantuml): removing obsoleted optional third argument * lisp/ob-python.el: (org-babel-expand-body:python): removing obsoleted optional third argument (org-babel-execute:python): removing obsoleted optional third argument (org-babel-python-variable-assignments): removing obsoleted optional third * lisp/ob-ruby.el: (org-babel-expand-body:ruby): removing obsoleted optional third argument (org-babel-execute:ruby): removing obsoleted optional third argument * lisp/ob-sass.el: (org-babel-expand-body:sass): removing obsoleted optional third argument * lisp/ob-scheme.el: (org-babel-expand-body:scheme): removing obsoleted optional third argument (org-babel-execute:scheme): removing obsoleted optional third argument * lisp/ob-screen.el: (org-babel-expand-body:screen): removing obsoleted optional third argument * lisp/ob-sh.el: (org-babel-expand-body:sh): removing obsoleted optional third argument (org-babel-execute:sh): removing obsoleted optional third argument (org-babel-sh-variable-assignments): removing obsoleted optional third * lisp/ob-sql.el: (org-babel-expand-body:sql): removing obsoleted optional third argument * lisp/ob-sqlite.el: (org-babel-expand-body:sqlite): removing obsoleted optional third argument (org-babel-execute:sqlite): removing obsoleted optional third argument * lisp/ob.el: (org-babel-expand-body:generic): removing obsoleted optional third argument
2010-10-16 03:35:45 +00:00
(defun org-babel-prep-session:haskell (session params)
2010-07-13 23:20:08 +00:00
"Prepare SESSION according to the header arguments in PARAMS."
(save-window-excursion
(let ((buffer (org-babel-haskell-initiate-session session)))
(org-babel-comint-in-buffer buffer
(mapc (lambda (line)
(insert line)
(comint-send-input nil t))
(org-babel-variable-assignments:haskell params)))
(current-buffer))))
2009-08-27 14:03:02 +00:00
(defun org-babel-variable-assignments:haskell (params)
"Return list of haskell statements assigning the block's variables."
(mapcar (lambda (pair)
(format "let %s = %s"
(car pair)
(org-babel-haskell-var-to-haskell (cdr pair))))
babel: small change in API. * lisp/ob-core.el (org-babel--get-vars): New function. (org-babel-get-header): Delete. * lisp/ob-C.el (org-babel-C-expand-C): (org-babel-C-expand-D): * lisp/ob-R.el (org-babel-variable-assignments:R): * lisp/ob-abc.el (org-babel-expand-body:abc): * lisp/ob-asymptote.el (org-babel-variable-assignments:asymptote): * lisp/ob-awk.el (org-babel-execute:awk): * lisp/ob-calc.el (org-babel-execute:calc): * lisp/ob-clojure.el (org-babel-expand-body:clojure): * lisp/ob-dot.el (org-babel-expand-body:dot): * lisp/ob-emacs-lisp.el (org-babel-expand-body:emacs-lisp): * lisp/ob-fortran.el (org-babel-expand-body:fortran): (org-babel-fortran-ensure-main-wrap): * lisp/ob-gnuplot.el (org-babel-gnuplot-process-vars): * lisp/ob-haskell.el (org-babel-variable-assignments:haskell): * lisp/ob-js.el (org-babel-variable-assignments:js): * lisp/ob-latex.el (org-babel-expand-body:latex): * lisp/ob-lilypond.el (org-babel-expand-body:lilypond): * lisp/ob-lisp.el (org-babel-expand-body:lisp): * lisp/ob-maxima.el (org-babel-maxima-expand): * lisp/ob-ocaml.el (org-babel-variable-assignments:ocaml): * lisp/ob-octave.el (org-babel-variable-assignments:octave): * lisp/ob-org.el (org-babel-expand-body:org): * lisp/ob-perl.el (org-babel-variable-assignments:perl): * lisp/ob-picolisp.el (org-babel-expand-body:picolisp): * lisp/ob-processing.el (org-babel-variable-assignments:processing): * lisp/ob-python.el (org-babel-variable-assignments:python): * lisp/ob-ruby.el (org-babel-variable-assignments:ruby): * lisp/ob-scheme.el (org-babel-expand-body:scheme): * lisp/ob-shell.el (org-babel-variable-assignments:shell): * lisp/ob-shen.el (org-babel-expand-body:shen): * lisp/ob-sql.el (org-babel-expand-body:sql): * lisp/ob-sqlite.el (org-babel-expand-body:sqlite): Adapt to change. * etc/ORG-NEWS: Document change.
2015-10-29 19:26:11 +00:00
(org-babel--get-vars params)))
(defun org-babel-haskell-var-to-haskell (var)
2010-07-13 23:20:08 +00:00
"Convert an elisp value VAR into a haskell variable.
The elisp VAR is converted to a string of haskell source code
specifying a variable of the same value."
(if (listp var)
(concat "[" (mapconcat #'org-babel-haskell-var-to-haskell var ", ") "]")
(format "%S" var)))
Backport changes from Emacs revs 115081 and 115082 2013-11-12 Stefan Monnier <monnier@iro.umontreal.ca> Address some byte-compiler warnings. * ob-abc.el (org-babel-expand-body:abc): Use dolist. (org-babel-execute:abc): Fix regexp quoting. * ob-calc.el (org--var-syms): Rename from `var-syms'. * ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding. * ob-table.el (sbe): Move debug declaration. * org-clock.el (org--msg-extra): Rename from `msg-extra'. * org.el (org-version): Avoid var name starting with _. (org-inhibit-startup, org-called-with-limited-levels) (org-link-search-inhibit-query, org-time-was-given) (org-end-time-was-given, org-def, org-defdecode, org-with-time): * org-colview.el (org-agenda-overriding-columns-format): * org-agenda.el (org-agenda-multi, org-depend-tag-blocked) (org-agenda-show-log-scoped): * ob-python.el (py-which-bufname, python-shell-buffer-name): * ob-haskell.el (org-export-copy-to-kill-ring): * ob-exp.el (org-link-search-inhibit-query): * ob-R.el (ess-eval-visibly-p): * ob-core.el (org-src-window-setup): Declare before use. (org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'. * ox-odt.el (org-odt-hfy-face-to-css): * org-src.el (org-src-associate-babel-session, org-src-get-lang-mode): * org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex) (org-bibtex-check): * ob-tangle.el (org-babel-tangle, org-babel-spec-to-string) (org-babel-tangle-single-block, org-babel-tangle-comment-links): * ob-table.el (sbe): * ob-sqlite.el (org-babel-sqlite-expand-vars): * ob-sql.el (org-babel-sql-expand-vars): * ob-shen.el (org-babel-execute:shen): * ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate): * ob-scala.el (org-babel-scala-evaluate): * ob-ruby.el (org-babel-ruby-table-or-string) (org-babel-ruby-evaluate): * ob-python.el (org-babel-python-table-or-string) (org-babel-python-evaluate-external-process) (org-babel-python-evaluate-session): * ob-picolisp.el (org-babel-execute:picolisp): * ob-perl.el (org-babel-perl-evaluate): * ob-maxima.el (org-babel-execute:maxima): * ob-lisp.el (org-babel-execute:lisp): * ob-java.el (org-babel-execute:java): * ob-io.el (org-babel-io-evaluate): * ob-haskell.el (org-babel-execute:haskell): * ob-fortran.el (org-babel-execute:fortran): * ob-exp.el (org-babel-exp-code): * ob-emacs-lisp.el (org-babel-execute:emacs-lisp): * ob-ditaa.el (org-babel-execute:ditaa): * ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash) (org-babel-parse-header-arguments, org-babel-reassemble-table) (org-babel-goto-src-block-head, org-babel-mark-block) (org-babel-expand-noweb-references, org-babel-script-escape) (org-babel-process-file-name): * ob-clojure.el (org-babel-execute:clojure): * ob-calc.el (org-babel-execute:calc): * ob-awk.el (org-babel-execute:awk): * ob-abc.el (org-babel-execute:abc): * ob-R.el (org-babel-expand-body:R): * ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...). 2013-11-12 Glenn Morris <rgm@gnu.org> * ox-html.el (org-html-scripts): Add 2013 to copyright years. (org-html-infojs-template): Copyright holder to FSF.
2013-11-12 19:57:31 +00:00
(defvar org-export-copy-to-kill-ring)
(declare-function org-export-to-file "ox"
(backend file
Backport commit 65c8c7c from Emacs * lisp/ob-awk.el (orgtbl-to-generic): * lisp/ob-core.el (orgtbl-to-generic): * lisp/ob-exp.el (org-element-context): * lisp/ob-gnuplot.el (org-time-string-to-time) (orgtbl-to-generic): * lisp/ob-haskell.el (org-export-to-file): * lisp/ob-latex.el (org-create-formula-image) (org-latex-compile): * lisp/ob-python.el (run-python): * lisp/ob-tangle.el (org-link-escape, org-back-to-heading): * lisp/org-colview.el (org-agenda-redo): * lisp/org-feed.el (url-retrieve-synchronously): * lisp/org-info.el (Info-find-node): * lisp/org-list.el (org-previous-line-empty-p): * lisp/org-macs.el (org-string-match-p): * lisp/org.el (org-beamer-mode): Fix prototype to match current definition. * lisp/ob-comint.el (tramp-flush-directory-property): * lisp/ob-tangle.el (org-babel-update-block-body): * lisp/org-bibtex.el (org-babel-trim): * lisp/org-pcomplete.el (org-export-backend-options): * lisp/org-protocol.el (org-publish-get-project-from-filename): Fix file name in declare-function. * lisp/ob-comint.el (with-parsed-tramp-file-name) * lisp/ob-core.el (with-parsed-tramp-file-name): * lisp/org.el (org-beamer-mode): Append ‘t’ to declare-function, since the declaration isn’t a defun. * lisp/ob-core.el (org-save-outline-visibility): Remove; not needed. * lisp/ob-scheme.el (run-geiser, geiser-mode) (geiser-eval-region, geiser-repl-exit): * lisp/ox-org.el (htmlize-buffer): Prepend "ext:" to file name, since it is not part of Emacs. * lisp/org-gnus.el (nnimap-group-overview-filename): Remove decl, since function was removed. * lisp/org-macro.el (org-with-wide-buffer): Omit unnecessary (and mismatching) decl. * lisp/org-clock.el (calendar-iso-to-absolute): Declare calendar-iso-to-absolute instead, since it is the non-obsolete version of this function. * lisp/org-compat.el (w32-focus-frame): Remove decl, since function is now obsolete. Pacify ‘make check-declare’ 65c8c7cb96c14f9c6accd03cc8851b5a3459049e Paul Eggert Sat May 14 19:57:44 2016 -0700
2016-05-15 02:56:53 +00:00
&optional async subtreep visible-only body-only
ext-plist post-process))
(defun org-babel-haskell-export-to-lhs (&optional arg)
2010-07-13 23:20:08 +00:00
"Export to a .lhs file with all haskell code blocks escaped.
When called with a prefix argument the resulting
.lhs file will be exported to a .tex file. This function will
create two new files, base-name.lhs and base-name.tex where
base-name is the name of the current Org file.
2010-07-13 23:20:08 +00:00
Note that all standard Babel literate programming
constructs (header arguments, no-web syntax etc...) are ignored."
(interactive "P")
(let* ((contents (buffer-string))
(haskell-regexp
(concat "^\\([ \t]*\\)#\\+begin_src[ \t]haskell*\\(.*\\)[\r\n]"
"\\(\\(?:.\\|\n\\)*?\\)[\r\n][ \t]*#\\+end_src.*"))
(base-name (file-name-sans-extension (buffer-file-name)))
Babel now cleans up any temporary files created using org-babel-temp-file * lisp/ob.el (org-babel-temporary-directory): variable to hold the value of the Babel temporary directory (org-babel-temp-file): replacement for make-temp-file with cleanup on exit of Emacs (org-babel-remove-temporary-directory): cleanup function run on exit of Emacs (kill-emacs-hook): now includes babel cleanup function * lisp/ob-C.el (org-babel-C-execute): using org-babel-temp-file instead of make-temp-file * lisp/ob-R.el (org-babel-R-assign-elisp): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-R-evaluate-external-process): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-R-evaluate-session): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-asymptote.el (org-babel-execute:asymptote): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-clojure.el (org-babel-clojure-evaluate-external-process): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-ditaa.el (org-babel-execute:ditaa): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-dot.el (org-babel-execute:dot): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-gnuplot.el (org-babel-gnuplot-process-vars): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-execute:gnuplot): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-haskell.el (org-babel-load-session:haskell): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-haskell-export-to-lhs): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-latex.el (org-babel-execute:latex): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-ledger.el (org-babel-execute:ledger): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-lisp.el (org-babel-execute:lisp): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-octave.el (org-babel-octave-evaluate-external-process): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-octave-evaluate-session): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-octave-import-elisp-from-file): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-perl.el (org-babel-perl-evaluate): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-python.el (org-babel-python-evaluate): using `org-babel-temp-file' instead of `make-temp-file' using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-ruby.el (org-babel-ruby-evaluate): using `org-babel-temp-file' instead of `make-temp-file' using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-sass.el (org-babel-execute:sass): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-sh.el (org-babel-sh-evaluate): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-sql.el (org-babel-execute:sql): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-sqlite.el (org-babel-execute:sqlite): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-sqlite-expand-vars): using `org-babel-temp-file' instead of `make-temp-file'
2010-08-25 20:43:07 +00:00
(tmp-file (org-babel-temp-file "haskell-"))
(tmp-org-file (concat tmp-file ".org"))
(tmp-tex-file (concat tmp-file ".tex"))
(lhs-file (concat base-name ".lhs"))
(tex-file (concat base-name ".tex"))
babel: New function to process file names for use in external processes * ob.el (org-babel-process-file-name): New function (org-babel-maybe-remote-file): Delete function * ob-sql.el (org-babel-execute:sql): Use org-babel-process-file-name * ob-scheme.el (org-babel-execute:scheme): Use org-babel-process-file-name * ob-sass.el (org-babel-execute:sass): Use org-babel-process-file-name * ob-ruby.el (org-babel-ruby-evaluate): Use org-babel-process-file-name * ob-python.el (org-babel-python-evaluate-external-process): Use org-babel-process-file-name (org-babel-python-evaluate-session): Use org-babel-process-file-name * ob-plantuml.el (org-babel-execute:plantuml): Use org-babel-process-file-name * ob-perl.el (org-babel-perl-evaluate): Use org-babel-process-file-name * ob-octave.el (org-babel-octave-evaluate-external-process): Use org-babel-process-file-name (org-babel-octave-evaluate-session): Use org-babel-process-file-name, don't use org-babel-maybe-remote-file * ob-lisp.el (org-babel-execute:lisp): Use org-babel-process-file-name * ob-ledger.el (org-babel-execute:ledger): Use org-babel-process-file-name * ob-js.el (org-babel-execute:js): Use org-babel-process-file-name * ob-haskell.el (org-babel-haskell-export-to-lhs): Use org-babel-process-file-name * ob-gnuplot.el (org-babel-execute:gnuplot): Use org-babel-process-file-name * ob-eval.el (org-babel-eval-read-file): Don't use org-babel-maybe-remote-file * ob-dot.el (org-babel-execute:dot): Use org-babel-process-file-name * ob-ditaa.el (org-babel-execute:ditaa): Use org-babel-process-file-name * ob-clojure.el (org-babel-clojure-evaluate-external-process): Use org-babel-process-file-name * ob-asymptote.el (org-babel-execute:asymptote): Use org-babel-process-file-name * ob-R.el (org-babel-R-assign-elisp): Don't use org-babel-maybe-remote-file, use org-babel-process-file-name (org-babel-R-evaluate-external-process): Use org-babel-process-file-name (org-babel-R-evaluate-session): Use org-babel-process-file-name * ob-C.el (org-babel-C-execute): Use org-babel-process-file-name In addition to passing the file path through `expand-file-name', tramp-style remote file names are converted to conventional (local) file paths. The reason is that, if a tramp file name was in use in emacs, then the shell command will be executing on the remote machine in question. Further, by default the file name is passed through `shell-quote-argument'.
2010-09-22 20:40:14 +00:00
(command (concat org-babel-haskell-lhs2tex-command
" " (org-babel-process-file-name lhs-file)
" > " (org-babel-process-file-name tex-file)))
(preserve-indentp org-src-preserve-indentation)
indentation)
;; escape haskell source-code blocks
(with-temp-file tmp-org-file
(insert contents)
(goto-char (point-min))
(while (re-search-forward haskell-regexp nil t)
(save-match-data (setq indentation (length (match-string 1))))
(replace-match (save-match-data
(concat
Change export block syntax * lisp/org-element.el (org-element-export-block-parser): (org-element--current-element): Use new syntax for export blocks. (org-element-block-name-alist): Remove. * lisp/ox.el (org-export-register-backend): (org-export-define-derived-backend): Remove :export-block keyword from back-end's definition. (org-export-expand-include-keyword): Use new syntax for include keywords. * lisp/ox-ascii.el (ascii): * lisp/ox-beamer.el (beamer): * lisp/ox-html.el (html): * lisp/ox-latex.el (latex): (org-latex-prefer-user-labels): * lisp/ox-man.el (man): * lisp/ox-md.el (md): * lisp/ox-odt.el (odt): * lisp/ox-texinfo.el (texinfo): Propagate changes to "ox.el". * lisp/ob-core.el (org-babel-insert-result): * lisp/ob-haskell.el (org-babel-haskell-export-to-lhs): Use new syntax. * lisp/org.el (org-structure-template-alist): Use new syntax. (org-protecting-blocks): Add "export" to protected blocks. Remove back-ends blocks, which are now special blocks. (org-fontify-meta-lines-and-blocks-1): Fontify correctly new blocks. * lisp/org-footnote.el (org-footnote-forbidden-blocks): * lisp/org-list.el (org-list-forbidden-blocks): Add "export" to forbidden blocks. Remove back-ends blocks, which are now special blocks. * contrib/lisp/ox-extra.el: Update comments. * testing/lisp/test-org-element.el (test-org-element/export-block-parser): (test-org-element/export-block-interpreter): * testing/lisp/test-ob.el (test-ob/org-babel-remove-result--results-html): (test-ob/org-babel-remove-result--results-latex): * testing/lisp/test-ox.el (test-org-export/expand-include): Update tests. Export blocks are explicitly marked as such at the syntax level to disambiguate their parsing from special blocks. The new syntax is #+BEGIN_EXPORT backend ... #+END_EXPORT instead of #+BEGIN_backend ... #+END_backend As a consequence, =INCLUDE= keywords syntax is modified, e.g., #+INCLUDE: "file.org" HTML becomes #+INCLUDE: "file.org" export html
2015-02-03 15:16:54 +00:00
"#+begin_export latex\n\\begin{code}\n"
(if (or preserve-indentp
(string-match "-i" (match-string 2)))
(match-string 3)
(org-remove-indentation (match-string 3)))
Change export block syntax * lisp/org-element.el (org-element-export-block-parser): (org-element--current-element): Use new syntax for export blocks. (org-element-block-name-alist): Remove. * lisp/ox.el (org-export-register-backend): (org-export-define-derived-backend): Remove :export-block keyword from back-end's definition. (org-export-expand-include-keyword): Use new syntax for include keywords. * lisp/ox-ascii.el (ascii): * lisp/ox-beamer.el (beamer): * lisp/ox-html.el (html): * lisp/ox-latex.el (latex): (org-latex-prefer-user-labels): * lisp/ox-man.el (man): * lisp/ox-md.el (md): * lisp/ox-odt.el (odt): * lisp/ox-texinfo.el (texinfo): Propagate changes to "ox.el". * lisp/ob-core.el (org-babel-insert-result): * lisp/ob-haskell.el (org-babel-haskell-export-to-lhs): Use new syntax. * lisp/org.el (org-structure-template-alist): Use new syntax. (org-protecting-blocks): Add "export" to protected blocks. Remove back-ends blocks, which are now special blocks. (org-fontify-meta-lines-and-blocks-1): Fontify correctly new blocks. * lisp/org-footnote.el (org-footnote-forbidden-blocks): * lisp/org-list.el (org-list-forbidden-blocks): Add "export" to forbidden blocks. Remove back-ends blocks, which are now special blocks. * contrib/lisp/ox-extra.el: Update comments. * testing/lisp/test-org-element.el (test-org-element/export-block-parser): (test-org-element/export-block-interpreter): * testing/lisp/test-ob.el (test-ob/org-babel-remove-result--results-html): (test-ob/org-babel-remove-result--results-latex): * testing/lisp/test-ox.el (test-org-export/expand-include): Update tests. Export blocks are explicitly marked as such at the syntax level to disambiguate their parsing from special blocks. The new syntax is #+BEGIN_EXPORT backend ... #+END_EXPORT instead of #+BEGIN_backend ... #+END_backend As a consequence, =INCLUDE= keywords syntax is modified, e.g., #+INCLUDE: "file.org" HTML becomes #+INCLUDE: "file.org" export html
2015-02-03 15:16:54 +00:00
"\n\\end{code}\n#+end_export\n"))
t t)
(indent-code-rigidly (match-beginning 0) (match-end 0) indentation)))
(save-excursion
(unwind-protect
(with-temp-buffer
;; Export to latex w/org and save as .lhs
(require 'ox-latex)
(insert-file-contents tmp-org-file)
;; Ensure we do not clutter kill ring with incomplete results.
(let (org-export-copy-to-kill-ring)
(org-export-to-file 'latex tmp-tex-file)))
(delete-file tmp-org-file))
(unwind-protect
(with-temp-buffer
(insert-file-contents tmp-tex-file)
(goto-char (point-min)) (forward-line 2)
(insert "%include polycode.fmt\n")
;; ensure all \begin/end{code} statements start at the first column
(while (re-search-forward "^[ \t]+\\\\begin{code}\\(?:.\\|\n\\)+\\\\end{code}" nil t)
(replace-match (save-match-data (org-remove-indentation (match-string 0)))
t t))
;; save org exported latex to a .lhs file
(write-region nil nil lhs-file))
(delete-file tmp-tex-file)))
(if (not arg)
(find-file lhs-file)
;; process .lhs file with lhs2tex
(message "running %s" command) (shell-command command) (find-file tex-file))))
(provide 'ob-haskell)
;;; ob-haskell.el ends here