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

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

[nongnu] elpa/arduino-mode 0150970 050/107: support org-mode babel Ardui


From: ELPA Syncer
Subject: [nongnu] elpa/arduino-mode 0150970 050/107: support org-mode babel Arduino src block
Date: Sun, 29 Aug 2021 10:58:15 -0400 (EDT)

branch: elpa/arduino-mode
commit 0150970da7b31a97aeec30aa0ae19cc6d298d012
Author: stardiviner <numbchild@gmail.com>
Commit: stardiviner <numbchild@gmail.com>

    support org-mode babel Arduino src block
---
 ob-arduino.el | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/ob-arduino.el b/ob-arduino.el
new file mode 100644
index 0000000..f15b6f4
--- /dev/null
+++ b/ob-arduino.el
@@ -0,0 +1,67 @@
+;;; ob-arduino.el --- Org-mode Babel support for Arduino.
+
+;;; Commentary:
+
+
+
+;;; Code:
+
+(require 'org)
+(require 'ob)
+
+(defgroup ob-arduino nil
+  "org-mode blocks for Arduino."
+  :group 'org)
+
+(defcustom ob-arduino:program "arduino"
+  "Default Arduino program name."
+  :group 'ob-arduino
+  :type 'string)
+
+(defcustom ob-arduino:port "/dev/ttyACM0"
+  "Default Arduino port."
+  :group 'ob-arduino
+  :type 'string)
+
+;;;###autoload
+(defun org-babel-execute:arduino (body params)
+  "org-babel arduino hook."
+  (let* ((port (cdr (assoc :port params)))
+         (cmd (mapconcat 'identity (list
+                                    ob-arduino:program "--upload"
+                                    (if port (concat "--port " port))) " "))
+         (code (org-babel-expand-body:generic body params))
+         (src-file (org-babel-temp-file "ob-arduino-" ".ino")))
+    ;; delete all `ob-arduino' temp files, otherwise arduino will compile all
+    ;; ob-arduino temp files, and report error.
+    (mapc
+     (lambda (f)
+       (unless (file-directory-p f)
+         (delete-file (expand-file-name f org-babel-temporary-directory))))
+     (directory-files
+      (file-name-directory (org-babel-temp-file "ob-arduino-" ".ino"))
+      nil ".ino"))
+    ;; specify file for arduino command.
+    (with-temp-file src-file
+      (insert code))
+    (org-babel-eval
+     (concat ob-arduino:program
+             " " "--upload"
+             " " (if port (concat "--port " port))
+             " " src-file)
+     "" ; pass empty string "" as `BODY' to 
`org-babel--shell-command-on-region'
+     ;; to fix command `arduino' don't accept string issue.
+     )
+    ))
+
+
+;;;###autoload
+(eval-after-load "org"
+  '(add-to-list 'org-src-lang-modes '("arduino" . arduino)))
+
+
+
+
+(provide 'ob-arduino)
+
+;;; ob-arduino.el ends here



reply via email to

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