Compare commits
5 Commits
a82da456bd
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| cce76e2f8f | |||
| 14a495e7b6 | |||
| f18bcfd3aa | |||
| 4313ddd4e8 | |||
| e0d77de442 |
182
lisp/ob-manim.el
Normal file
182
lisp/ob-manim.el
Normal file
@@ -0,0 +1,182 @@
|
||||
;;; ob-manim.el --- org-babel functions for manim evaluation
|
||||
|
||||
;; Copyright (C) David Crompton
|
||||
|
||||
;; Author: David Crompton
|
||||
;; Keywords: manim, python, literate programming, reproducible research
|
||||
;; Homepage: https://orgmode.org
|
||||
;; Version: 0.01
|
||||
|
||||
;;; 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.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; This file is not intended to ever be loaded by org-babel, rather it is a
|
||||
;; manim for use in adding new language support to Org-babel. Good first
|
||||
;; steps are to copy this file to a file named by the language you are adding,
|
||||
;; and then use `query-replace' to replace all strings of "manim" in this
|
||||
;; file with the name of your new language.
|
||||
|
||||
;; After the `query-replace' step, it is recommended to load the file and
|
||||
;; register it to org-babel either via the customize menu, or by evaluating the
|
||||
;; line: (add-to-list 'org-babel-load-languages '(manim . t)) where
|
||||
;; `manim' should have been replaced by the name of the language you are
|
||||
;; implementing (note that this applies to all occurrences of 'manim' in this
|
||||
;; file).
|
||||
|
||||
;; After that continue by creating a simple code block that looks like e.g.
|
||||
;;
|
||||
;; #+begin_src manim
|
||||
|
||||
;; test
|
||||
|
||||
;; #+end_src
|
||||
|
||||
;; Finally you can use `edebug' to instrumentalize
|
||||
;; `org-babel-expand-body:manim' and continue to evaluate the code block. You
|
||||
;; try to add header keywords and change the body of the code block and
|
||||
;; reevaluate the code block to observe how things get handled.
|
||||
|
||||
;;
|
||||
;; If you have questions as to any of the portions of the file defined
|
||||
;; below please look to existing language support for guidance.
|
||||
;;
|
||||
;; If you are planning on adding a language to org-babel we would ask
|
||||
;; that if possible you fill out the FSF copyright assignment form
|
||||
;; available at https://orgmode.org/request-assign-future.txt as this
|
||||
;; will make it possible to include your language support in the core
|
||||
;; of Org-mode, otherwise unassigned language support files can still
|
||||
;; be included in the contrib/ directory of the Org-mode repository.
|
||||
|
||||
|
||||
;;; Requirements:
|
||||
|
||||
;; Use this section to list the requirements of this language. Most
|
||||
;; languages will require that at least the language be installed on
|
||||
;; the user's system, and the Emacs major mode relevant to the
|
||||
;; language be installed as well.
|
||||
|
||||
;;; Code:
|
||||
(require 'ob)
|
||||
(require 'ob-ref)
|
||||
(require 'ob-comint)
|
||||
(require 'ob-eval)
|
||||
(require 'python)
|
||||
;; possibly require modes required for your language
|
||||
|
||||
;; optionally define a file extension for this language
|
||||
(add-to-list 'org-babel-tangle-lang-exts '("manim" . "py"))
|
||||
|
||||
(add-to-list 'org-src-lang-modes '("manim" . python))
|
||||
|
||||
;; optionally declare default header arguments for this language
|
||||
(defvar org-babel-default-header-args:manim '())
|
||||
|
||||
;; This function expands the body of a source code block by doing things like
|
||||
;; prepending argument definitions to the body, it should be called by the
|
||||
;; `org-babel-execute:manim' function below. Variables get concatenated in
|
||||
;; the `mapconcat' form, therefore to change the formatting you can edit the
|
||||
;; `format' form.
|
||||
(defun org-babel-expand-body:manim (body params &optional processed-params)
|
||||
"Expand BODY according to PARAMS, return the expanded body."
|
||||
(require 'inf-manim nil t)
|
||||
(let ((vars (org-babel--get-vars (or processed-params (org-babel-process-params params)))))
|
||||
(concat
|
||||
(mapconcat ;; define any variables
|
||||
(lambda (pair)
|
||||
(format "%s=%S"
|
||||
(car pair) (org-babel-manim-var-to-manim (cdr pair))))
|
||||
vars "\n")
|
||||
"\n" body "\n")))
|
||||
|
||||
;; This is the main function which is called to evaluate a code
|
||||
;; block.
|
||||
;;
|
||||
;; This function will evaluate the body of the source code and
|
||||
;; return the results as emacs-lisp depending on the value of the
|
||||
;; :results header argument
|
||||
;; - output means that the output to STDOUT will be captured and
|
||||
;; returned
|
||||
;; - value means that the value of the last statement in the
|
||||
;; source code block will be returned
|
||||
;;
|
||||
;; The most common first step in this function is the expansion of the
|
||||
;; PARAMS argument using `org-babel-process-params'.
|
||||
;;
|
||||
;; Please feel free to not implement options which aren't appropriate
|
||||
;; for your language (e.g. not all languages support interactive
|
||||
;; "session" evaluation). Also you are free to define any new header
|
||||
;; arguments which you feel may be useful -- all header arguments
|
||||
;; specified by the user will be available in the PARAMS variable.
|
||||
(defun org-babel-execute:manim (body params)
|
||||
"Execute a block of Manim code with org-babel.
|
||||
This function is called by `org-babel-execute-src-block'"
|
||||
(message "executing Manim source code block")
|
||||
(let* ((processed-params (org-babel-process-params params))
|
||||
;; variables assigned for use in the block
|
||||
(vars (org-babel--get-vars processed-params))
|
||||
(result-params (assq :result-params processed-params))
|
||||
;; either OUTPUT or VALUE which should behave as described above
|
||||
(result-type (assq :result-type processed-params))
|
||||
;; expand the body with `org-babel-expand-body:manim'
|
||||
(full-body (org-babel-expand-body:manim
|
||||
body params processed-params))
|
||||
(result (let ((script-file (org-babel-temp-file "org-babel-manim-" ".py")))
|
||||
(with-temp-file script-file
|
||||
(insert full-body))
|
||||
(org-babel-eval (format "manim --progress_bar none %s" (org-babel-process-file-name script-file)) "")))))
|
||||
;; actually execute the source-code block either in a session or
|
||||
;; possibly by dropping it to a temporary file and evaluating the
|
||||
;; file.
|
||||
;;
|
||||
;; for session based evaluation the functions defined in
|
||||
;; `org-babel-comint' will probably be helpful.
|
||||
;;
|
||||
;; for external evaluation the functions defined in
|
||||
;; `org-babel-eval' will probably be helpful.
|
||||
;;
|
||||
;; when forming a shell command, or a fragment of code in some
|
||||
;; other language, please preprocess any file names involved with
|
||||
;; the function `org-babel-process-file-name'. (See the way that
|
||||
;; function is used in the language files)
|
||||
(format "./media/%s/%s/%s/%s" ("image" "video") (filename) ("1080p60" or ".") ("OutputFile")))
|
||||
|
||||
;; This function should be used to assign any variables in params in
|
||||
;; the context of the session environment.
|
||||
(defun org-babel-prep-session:manim (session params)
|
||||
"Prepare SESSION according to the header arguments specified in PARAMS."
|
||||
)
|
||||
|
||||
(defun org-babel-manim-var-to-manim (var)
|
||||
"Convert an elisp var into a string of manim source code
|
||||
specifying a var of the same value."
|
||||
(format "%S" var))
|
||||
|
||||
(defun org-babel-manim-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."
|
||||
)
|
||||
|
||||
(defun org-babel-manim-initiate-session (&optional session)
|
||||
"If there is not a current inferior-process-buffer in SESSION then create.
|
||||
Return the initialized session."
|
||||
(unless (string= session "none")
|
||||
))
|
||||
|
||||
(provide 'ob-manim)
|
||||
;;; ob-manim.el ends here
|
||||
41
main.org
41
main.org
@@ -94,6 +94,12 @@ Disabled for now. (May add flags to enable on specific systems)
|
||||
|
||||
** Emacs Paths
|
||||
|
||||
*** Custom loads
|
||||
|
||||
#+begin_src elisp :tangle yes :exports code
|
||||
(add-to-list 'load-path "~/.emacs.d/lisp")
|
||||
#+end_src
|
||||
|
||||
*** Custom.el
|
||||
|
||||
Ensure that the =custom.el= resides in the users' emacs directory.
|
||||
@@ -346,7 +352,7 @@ highlighting) compared to builtin python-mode.
|
||||
(leaf python-mode
|
||||
:ensure t
|
||||
:mode "\\.py\\'"
|
||||
:config
|
||||
:init
|
||||
(setq python-shell-interpreter "ipython"
|
||||
python-shell-interpreter-args "-i --simple-prompt --InteractiveShell.display_page=True"))
|
||||
#+end_src
|
||||
@@ -363,16 +369,12 @@ For when we aren't nix'ing things, and want some nice poetry.
|
||||
|
||||
Who even needs C++, not me, no way, no how.
|
||||
|
||||
#+begin_src elisp :tangle no :exports code
|
||||
#+begin_src elisp :tangle yes :exports code
|
||||
(leaf c-config
|
||||
:config
|
||||
; (leaf company-ctags :ensure t
|
||||
; :hook c-mode-hook c++-mode-hook)
|
||||
; (leaf company-c-headers :ensure t
|
||||
; :hook c-mode-hook c++-mode-hook)
|
||||
; (leaf meson-mode :ensure t
|
||||
; :hook c-mode-hook c++-mode-hook)
|
||||
)
|
||||
(leaf company-ctags :ensure t)
|
||||
(leaf company-c-headers :ensure t)
|
||||
(leaf meson-mode :ensure t))
|
||||
#+end_src
|
||||
|
||||
* Haskell
|
||||
@@ -472,11 +474,12 @@ We use org-ref because it provides some niceties, like doi-utils for
|
||||
updating our bibliography.
|
||||
|
||||
#+begin_src elisp :tangle yes :exports code
|
||||
(leaf org-ref :ensure t helm-bibtex pdf-tools
|
||||
(leaf org-ref :ensure t helm-bibtex
|
||||
:after org
|
||||
:bind*
|
||||
("C-c ]" . org-ref-insert-link)
|
||||
:config
|
||||
(custom-set-faces '(org-ref-ref-face ((t (:inherit org-link :foreground "linkColor")))))
|
||||
(setq org-bib-dir (concat document-dir "/Bibliography"))
|
||||
(setq org-bib-file (concat org-bib-dir "/references.bib"))
|
||||
;; Where should PDFs be stored
|
||||
@@ -506,8 +509,10 @@ updating our bibliography.
|
||||
bibtex-autokey-titlewords 2
|
||||
bibtex-autokey-titlewords-stretch 1
|
||||
bibtex-autokey-titleword-length 5)
|
||||
;; (add-to-list 'org-export-before-parsing-functions 'org-ref-csl-preprocess-buffer)
|
||||
;; (add-to-list 'org-export-before-parsing-functions 'org-ref-refproc)
|
||||
;; Otherwise PDFs cannot be embedded as figures with autoref :o
|
||||
(add-to-list 'image-file-name-extensions "pdf")
|
||||
(add-to-list 'org-export-before-parsing-functions 'org-ref-csl-preprocess-buffer)
|
||||
(add-to-list 'org-export-before-parsing-functions 'org-ref-refproc)
|
||||
:require org-ref org-ref-helm oc-bibtex oc-bibtex oc-csl oc-natbib org-ref-refproc)
|
||||
#+end_src
|
||||
|
||||
@@ -518,11 +523,12 @@ updating our bibliography.
|
||||
We really do require latex
|
||||
|
||||
#+begin_src elisp :tangle yes :exports code
|
||||
(leaf ox-latex :require t
|
||||
(leaf ox-latex :require t ox-beamer
|
||||
:after org
|
||||
:config
|
||||
(add-to-list 'org-latex-packages-alist '("" "minted"))
|
||||
(setq org-latex-listings 'minted)
|
||||
;; This adds compatability for org-ref cross-references etc.
|
||||
(setq org-latex-prefer-user-labels t)
|
||||
(add-to-list 'org-latex-classes
|
||||
'("labtemplate" "\\documentclass{labtemplate}"
|
||||
@@ -709,8 +715,8 @@ taking package.
|
||||
|
||||
#+begin_src elisp :tangle yes :exports code
|
||||
(leaf org-roam-bibtex :ensure t
|
||||
:after org-roam org-ref
|
||||
:require t
|
||||
:after org-roam
|
||||
:require t org-ref
|
||||
:hook (after-init-hook . org-roam-bibtex-mode))
|
||||
#+end_src
|
||||
|
||||
@@ -719,12 +725,15 @@ taking package.
|
||||
#+begin_src elisp :tangle yes :exports code
|
||||
(leaf org-babel
|
||||
:after org
|
||||
:require ob-manim
|
||||
:config
|
||||
(org-babel-do-load-languages
|
||||
'org-babel-load-languages
|
||||
'((emacs-lisp . t)
|
||||
(python . t)
|
||||
(shell . t))))
|
||||
(shell . t)
|
||||
(manim . t)
|
||||
)))
|
||||
#+end_src
|
||||
|
||||
* Flutter
|
||||
|
||||
Reference in New Issue
Block a user