emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/scad-mode 9bfaed13bc 25/47: Add support for Org babel


From: ELPA Syncer
Subject: [nongnu] elpa/scad-mode 9bfaed13bc 25/47: Add support for Org babel
Date: Sat, 12 Nov 2022 13:59:35 -0500 (EST)

branch: elpa/scad-mode
commit 9bfaed13bc0aebaaad0316b22e76069c4e1c5cd5
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Add support for Org babel
---
 README.org   |  9 +++++++++
 ob-scad.el   | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 scad-mode.el | 14 +++++++++-----
 3 files changed, 80 insertions(+), 5 deletions(-)

diff --git a/README.org b/README.org
index c4eaef9f87..f347f31ebd 100644
--- a/README.org
+++ b/README.org
@@ -17,6 +17,15 @@
 - Open buffer in OpenSCAD (press =C-c C-o=)
 - Export buffer with OpenSCAD (press =C-c C-e=)
 
+* Org Babel support
+
+#+begin_src scad :file example.png :colorscheme Tomorrow :imgsize 200,200
+  for (y=[0:2:20]) {
+      translate([0,0,y+1])
+          cube([30-2*y,30-2*y,2], true);
+  }
+#+end_src
+
 * Installation
 
 Install via =M-x package-install RET scad-mode RET= from MELPA.
diff --git a/ob-scad.el b/ob-scad.el
new file mode 100644
index 0000000000..f0f3f57c1e
--- /dev/null
+++ b/ob-scad.el
@@ -0,0 +1,62 @@
+;;; ob-scad.el --- Babel Functions for OpenSCAD -*- lexical-binding: t -*-
+
+;; This file is not part of GNU Emacs.
+
+;; 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 2 of the License, 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 this program; see the file COPYING.  If not, write to
+;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+;; Org Babel support for OpenSCAD
+
+;;; Code:
+
+(require 'ob)
+(require 'scad-mode)
+
+(defvar org-babel-default-header-args:scad
+  '((:results . "file")
+    (:exports . "results"))
+  "Default arguments for evaluating a scad source block.")
+
+(defvar org-babel-header-args:scad
+  '((colorscheme . :any)
+    (imgsize . :any)
+    (camera . :any))
+  "Scad specific header args.")
+
+(defun org-babel-execute:scad (body params)
+  "Evaluate BODY with `scad-command' given PARAMS."
+  (let* ((outfile (or (alist-get :file params)
+                      (error "Scad code block requires :file header 
argument")))
+         (infile (org-babel-temp-file "scad-")))
+    (message "%S" params)
+    (with-temp-file infile (insert body))
+    (apply #'call-process scad-command nil 0 nil
+           (delq nil
+                 (list "-o" outfile
+                       "--preview"
+                       "--viewall"
+                       (format "--colorscheme=%s"
+                               (alist-get :colorscheme params 
scad-preview-colorscheme))
+                       (when-let (camera (alist-get :camera params))
+                         (format "--camera=%s" camera))
+                       (when-let (imgsize (alist-get :imgsize params))
+                         (format "--imgsize=%s" imgsize))
+                       infile)))
+    nil))
+
+(provide 'ob-scad)
+;;; ob-scad.el ends here
diff --git a/scad-mode.el b/scad-mode.el
index 54e2e1d5be..7f1cf560a4 100644
--- a/scad-mode.el
+++ b/scad-mode.el
@@ -8,6 +8,8 @@
 ;; Package-Requires: ((emacs "26.1"))
 ;; Version:          92.0
 
+;; This file is not part of GNU Emacs.
+
 ;; 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 2 of the License, or
@@ -231,11 +233,13 @@ Key bindings:
   (interactive)
   (save-buffer)
   (compile (concat scad-command
-                   " -o " (expand-file-name (read-file-name
-                                             "Export to: "
-                                             nil nil nil
-                                             (concat (file-name-base 
buffer-file-name) ".stl")))
-                   " " buffer-file-name)))
+                   " -o " (shell-quote-argument
+                           (expand-file-name
+                            (read-file-name
+                             "Export to: "
+                             nil nil nil
+                             (concat (file-name-base buffer-file-name) 
".stl"))))
+                   " " (shell-quote-argument buffer-file-name))))
 
 (defvar-local scad--preview-buffer  nil)
 (defvar-local scad--preview-camera  nil)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]