[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/scala-mode 474a616 175/217: Merge ob-scala into scala-mode
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/scala-mode 474a616 175/217: Merge ob-scala into scala-mode (#107) |
Date: |
Sun, 29 Aug 2021 11:31:07 -0400 (EDT) |
branch: elpa/scala-mode
commit 474a6163798cad3cb190ae0869ad4fdf939d78af
Author: reactormonk <hafnersimon@gmail.com>
Commit: Sam Halliday <sam.halliday@gmail.com>
Merge ob-scala into scala-mode (#107)
* Initial commit
* initial working ugly version
* clarified readme
* updated melpa headers
* removed package information
* No need for LICENSE/README because of scala-mode
---
ob-scala.el | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 116 insertions(+)
diff --git a/ob-scala.el b/ob-scala.el
new file mode 100644
index 0000000..6389b3a
--- /dev/null
+++ b/ob-scala.el
@@ -0,0 +1,116 @@
+;;; ob-scala.el --- org-babel functions for scala evaluation
+
+;; Copyright (C) Simon Hafner
+
+;;; License:
+
+;; 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 3, 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 GNU Emacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Code:
+(require 'ob)
+(require 'ob-ref)
+(require 'ob-comint)
+(require 'ob-eval)
+(require 'ensime)
+;; possibly require modes required for your language
+
+;; optionally define a file extension for this language
+(add-to-list 'org-babel-tangle-lang-exts '("scala" . "scala"))
+
+;; optionally declare default header arguments for this language
+(defvar org-babel-default-header-args:scala '())
+
+(defun org-babel-expand-body:scala (body params &optional processed-params)
+ "Expand BODY according to PARAMS, return the expanded body."
+ (require 'ensime-inf)
+ (let ((vars (assoc-default :vars (or processed-params
(org-babel-process-params params)))))
+ (concat
+ (mapconcat ;; define any variables
+ (lambda (pair)
+ (format "val %s=%S"
+ (car pair) (org-babel-scala-var-to-scala (cdr pair)))) vars
"\n")
+ "\n" body "\nprint(\"\\nob_scala_eol\")")))
+
+
+;; This is the main function which is called to evaluate a code
+;; block.
+;;
+;; So far, only result :output is supported. The session is always
+;; interactive. Manual start of `ensime-inf-buffer-name` via
+;; `ensime-inf-run-scala` is recommended.
+(defun org-babel-execute:scala (body params)
+ "Execute a block of Scalacode with org-babel.
+This function is called by `org-babel-execute-src-block'"
+ (message "executing Scala source code block")
+ (let* ((processed-params (org-babel-process-params params))
+ ;; set the session
+ (session (org-babel-scala-initiate-session (assoc-default :session
processed-params)))
+ ;; variables assigned for use in the block
+ (vars (assoc-default :vars processed-params))
+ (result-params (assoc-default :result-params processed-params))
+ ;; either OUTPUT or VALUE which should behave as described above
+ (result-type (assoc-default :result-type processed-params))
+ ;; expand the body with `org-babel-expand-body:scala'
+ (full-body (org-babel-expand-body:scala
+ body params processed-params)))
+ (ensime-inf-assert-running)
+ (org-babel-scala-table-or-string
+ (let ((temp-file (make-temp-file "scala-eval")))
+ (message temp-file)
+ (with-temp-file temp-file
+ (insert full-body))
+ (let ((output
+ (org-babel-comint-with-output (ensime-inf-buffer-name
"ob_scala_eol")
+ (ensime-inf-send-string (concat ":load " temp-file))
+ (comint-send-input nil t )
+ (sleep-for 0 5))))
+ (delete-file temp-file)
+ output)))))
+
+;; This function should be used to assign any variables in params in
+;; the context of the session environment.
+(defun org-babel-prep-session:scala (session params)
+ "Prepare SESSION according to the header arguments specified in PARAMS."
+ )
+
+(defun org-babel-scala-var-to-scala (var)
+ "Convert an elisp var into a string of scala source code
+specifying a var of the same value."
+ (format "%S" var))
+
+(defun org-babel-scala-table-or-string (results)
+ "If the results look like a table, then convert them into an
+Emacs-lisp table, otherwise return the results as a string."
+ (message (format "%S" results))
+ (org-trim (mapconcat (lambda (element)
+ (if (or
+ (string-equal (org-trim element) "scala>")
+ (string-equal (org-trim element)
"ob_scala_eol"))
+ ""
+ element))
+ (cddr results)
+ "")))
+
+(defun org-babel-scala-initiate-session (&optional session)
+ "If there is not a current inferior-process-buffer in SESSION then create.
+Return the initialized session."
+ (unless (get-buffer ensime-inf-buffer-name)
+ (ensime-inf-run-scala))
+ ensime-inf-buffer-name
+ )
+
+(provide 'ob-scala)
+;;; ob-scala.el ends here
- [nongnu] elpa/scala-mode ad73d10 096/217: Merge pull request #49 from zbskii/master, (continued)
- [nongnu] elpa/scala-mode ad73d10 096/217: Merge pull request #49 from zbskii/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode defa2af 098/217: pkg.el cleanup, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 13b30a6 093/217: Added Hugh Giddens to contributors, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 9ab0a59 091/217: Update README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode c48b479 113/217: Update README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode af2dc30 136/217: Removed Marmelade from README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 8d4d99b 156/217: Add optional flattening to creation of imenu index (again)., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode aebed53 168/217: Mark a couple of indentation variables as safe (#105), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode ece95ca 170/217: use CI to compile PRs, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 37e7537 173/217: rename to scala-mode (#110), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 474a616 175/217: Merge ob-scala into scala-mode (#107),
ELPA Syncer <=
- [nongnu] elpa/scala-mode a0b73b2 177/217: add string interpolation (#116), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 4b492b9 179/217: Fix for fill-paragraph (#123), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 5ffaa1f 185/217: Merge pull request #129 from ensime/hvesalai-patch-94, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode f88091a 191/217: `**` at end of multiline comment cause issue #140 (#141), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 44772cb 196/217: fixed some compilation warnings, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 9e5b8af 190/217: Operator characters ids cannot be adjoint to word constituent ids (#139), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode a82f186 192/217: Removed duplicated defconst, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode cc960f3 197/217: fixed some markdown syntax mistakes, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 9d3b56e 206/217: Merge pull request #161 from Kazark/scala3-keywords, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode a4ed6b4 073/217: Merge pull request #28 from non/bug/fix-colon-operators, ELPA Syncer, 2021/08/29