[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)
- [nongnu] elpa/scad-mode ace55270fd 40/47: Add flymake support, (continued)
- [nongnu] elpa/scad-mode ace55270fd 40/47: Add flymake support, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 900ca6fc25 41/47: Update README, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode efc5f1cf14 46/47: Update status if original buffer is dead, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode aa2e76a29b 23/47: Rename mode back, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 1cdc9f304f 26/47: README: Update badges, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 28879e735c 33/47: Update status if preview is stale, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode b0d138e9ec 43/47: Print warning if the scad-preview package is installed, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode e5ed92217e 10/47: Cleanup mode map, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 311797dc44 15/47: Commentary: Remove old todos, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 2c9124f718 16/47: Remove some publicly exposed variables, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 9bfaed13bc 25/47: Add support for Org babel,
ELPA Syncer <=
- [nongnu] elpa/scad-mode 970982b253 31/47: Fix ob-scad, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 7cb7ee82a4 32/47: Enable scad-preview-mode immediately, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 1a2e992a5b 34/47: Fix custom types, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 4c23eae9c2 35/47: Support both ortho/perspective projection, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode a1638354e1 39/47: Log openscad output to separate buffer, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 3c5fe2c615 28/47: Improve preview mode settings, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode be02b626ce 42/47: Fix flymake configuration, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 29a4f8a848 44/47: scad-export: Add file argument, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 3076e240bf 47/47: Version 93.1, ELPA Syncer, 2022/11/12