Kaynağa Gözat

ob-calc: added to org-src-lang-modes, safer evaluation, better error messages

* lisp/ob-calc.el (org-babel-execute:calc): safer evaluation and
  hopefully better error messages

* lisp/org-src.el (org-src-lang-modes): mapping calc blocks to
  fundamental mode
Eric Schulte 14 yıl önce
ebeveyn
işleme
598be4a4a4
2 değiştirilmiş dosya ile 13 ekleme ve 5 silme
  1. 11 4
      lisp/ob-calc.el
  2. 2 1
      lisp/org-src.el

+ 11 - 4
lisp/ob-calc.el

@@ -45,10 +45,17 @@
      (when (> (length line) 0)
        (if (string= "'" (substring line 0 1))
 	   (funcall (lookup-key calc-mode-map (substring line 1)) nil)
-	 (calc-push-list (list ((lambda (res)
-				  (if (numberp res) res (math-read-number res)))
-				(calc-eval line)))))))
-   (split-string (org-babel-expand-body:calc body params) "[\n\r]"))
+	 (calc-push-list
+	  (list ((lambda (res)
+		   (cond
+		    ((numberp res) res)
+		    ((listp res) (error "calc error \"%s\" on input \"%s\""
+					(cadr res) line))
+		    (t res))
+		   (if (numberp res) res (math-read-number res)))
+		 (calc-eval line)))))))
+   (mapcar #'org-babel-trim
+	   (split-string (org-babel-expand-body:calc body params) "[\n\r]")))
   (save-excursion
     (set-buffer (get-buffer "*Calculator*"))
     (calc-eval (calc-top 1))))

+ 2 - 1
lisp/org-src.el

@@ -153,7 +153,8 @@ but which mess up the display of a snippet in Org exported files.")
 
 (defcustom org-src-lang-modes
   '(("ocaml" . tuareg) ("elisp" . emacs-lisp) ("ditaa" . artist)
-    ("asymptote" . asy) ("dot" . fundamental) ("sqlite" . sql))
+    ("asymptote" . asy) ("dot" . fundamental) ("sqlite" . sql)
+    ("calc" . fundamental))
   "Alist mapping languages to their major mode.
 The key is the language name, the value is the string that should
 be inserted as the name of the major mode.  For many languages this is