test and rework org-babel configuration
This commit is contained in:
parent
734fb54387
commit
b5e63c121e
1 changed files with 125 additions and 15 deletions
140
init.org
140
init.org
|
@ -1,5 +1,5 @@
|
|||
#+TITLE: My Emacs Configuration
|
||||
#+PROPERTY: header-args :tangle yes
|
||||
#+PROPERTY: header-args:emacs-lisp :tangle yes :lexical yes
|
||||
|
||||
* Literate Configuration for Emacs
|
||||
** Goals
|
||||
|
@ -101,6 +101,36 @@ then load it.
|
|||
(load custom-file nil :nomessage))
|
||||
#+END_SRC
|
||||
|
||||
** Utility Functions
|
||||
|
||||
** Get latest version of a github released project
|
||||
|
||||
Many projects nowadays use github to release their software. However
|
||||
there is no easy way to get the latest version of a project
|
||||
provided. This functions uses the releases API to get the latest
|
||||
metadata and get the version number from the JSON.
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(defun pti-with-latest-github-version (repo f)
|
||||
"Return the latest version of the releases for REPO.
|
||||
|
||||
The repo should be in the form of 'owner/repo'. The function F
|
||||
will be called with the version in format 'vX.Y.Z' as the only argument."
|
||||
(url-retrieve
|
||||
(format "https://api.github.com/repos/%s/releases/latest" repo)
|
||||
(lambda (events)
|
||||
(message "Events: %s" events)
|
||||
(goto-char url-http-end-of-headers)
|
||||
(let ((json-object-type 'plist)
|
||||
(json-key-type 'symbol)
|
||||
(json-array-type 'vector))
|
||||
(let ((result (json-read)))
|
||||
(message "Latest version: %s" (plist-get result 'name))
|
||||
(funcall f (plist-get result 'name))
|
||||
)))))
|
||||
#+END_SRC
|
||||
|
||||
|
||||
* Crafted Emacs
|
||||
|
||||
When I could not solve the persistent slowness I experienced on
|
||||
|
@ -722,6 +752,12 @@ This enables direnv globally.
|
|||
#+RESULTS:
|
||||
|
||||
*** Org Babel Support
|
||||
|
||||
I have a test file which has samples of babel features for easy
|
||||
testing in my [[file:~/org/snamellit/testfile.org::*User Journey Graph][org babel test file.]]
|
||||
|
||||
**** Support REST calls in Babel Blocks
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
;; enable verb package to do REST calls
|
||||
(use-package verb
|
||||
|
@ -734,22 +770,90 @@ This enables direnv globally.
|
|||
(use-package ob-verb
|
||||
:after verb
|
||||
:defer 3)
|
||||
;; configure babel languages
|
||||
#+END_SRC
|
||||
**** Support Mermaid Diagrams in Babel Blocks
|
||||
|
||||
(use-package org-babel
|
||||
:no-require
|
||||
:after '(ob-verb)
|
||||
:config
|
||||
(org-babel-do-load-languages
|
||||
'org-babel-load-languages
|
||||
'((emacs-lisp . t)
|
||||
(shell . t)
|
||||
(python . t)
|
||||
(latex . t)
|
||||
(verb . t)
|
||||
(scheme . t)
|
||||
(plantuml . t))))
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
;; enable mermaid for org-babel
|
||||
(use-package ob-mermaid
|
||||
:ensure t
|
||||
:defer 3)
|
||||
#+END_SRC
|
||||
|
||||
Mermaid needs support of the mermaid-cli which is a node package. It
|
||||
can be installed with
|
||||
|
||||
#+BEGIN_SRC shell :tangle no
|
||||
npm install -g @mermaid-js/mermaid-cli
|
||||
#+END_SRC
|
||||
|
||||
#+RESULTS:
|
||||
| | | | | | |
|
||||
| changed | 194 | packages | in | 6s | |
|
||||
| | | | | | |
|
||||
| 39 | packages | are | looking | for | funding |
|
||||
| run | `npm | fund` | for | details | |
|
||||
|
||||
**** Support PlantUML Diagrams in Babel Blocks
|
||||
|
||||
Requires nothing special, other than *plantuml.jar* archive installed.
|
||||
|
||||
#+BEGIN_SRC emacs-lisp :lexical t
|
||||
(defun pti-download-latest-plantuml ()
|
||||
"Download the latest version of PlantUML.
|
||||
|
||||
This function is interactive to make it easy to upgrade to
|
||||
the latest, current version with `M-x pti-download-latest-plantuml'."
|
||||
(interactive)
|
||||
(pti-with-latest-github-version
|
||||
"plantuml/plantuml"
|
||||
|
||||
|
||||
(lambda (version)
|
||||
(let ((url (format
|
||||
"https://github.com/plantuml/plantuml/releases/download/%s/plantuml-%s.jar"
|
||||
version (substring version 1))))
|
||||
(message "Downloading PlantUML version %s from %s" version url)
|
||||
(url-copy-file
|
||||
url
|
||||
(concat user-emacs-directory "plantuml.jar")
|
||||
))))
|
||||
)
|
||||
|
||||
(let ((plantuml-jar (concat user-emacs-directory "plantuml.jar")))
|
||||
(if (not (file-exists-p plantuml-jar))
|
||||
(pti-download-latest-plantuml))
|
||||
|
||||
(setq org-plantuml-jar-path plantuml-jar))
|
||||
#+END_SRC
|
||||
|
||||
#+RESULTS:
|
||||
: /home/pti/.config/emacs/plantuml.jar
|
||||
|
||||
**** Configure Babel Languages
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
;; configure babel languages
|
||||
(use-package org-babel
|
||||
:no-require
|
||||
:after '(ob-verb ob-mermaid)
|
||||
:config
|
||||
(org-babel-do-load-languages
|
||||
'org-babel-load-languages
|
||||
'((emacs-lisp . t)
|
||||
(shell . t)
|
||||
(python . t)
|
||||
(latex . t)
|
||||
(verb . t)
|
||||
(scheme . t)
|
||||
(plantuml . t)
|
||||
(mermaid . t)
|
||||
(dot . t))))
|
||||
#+END_SRC
|
||||
|
||||
**** Temporary Patches for Org Babel
|
||||
|
||||
***** Fix Scheme Babel Bug
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
;; fix a bug in ob-scheme which causes an error to be thrown when evaluating
|
||||
;; a cons cell or improper list
|
||||
;; see https://list.orgmode.org/87bkk3x1bu.fsf@gajsin.name/T/
|
||||
|
@ -770,6 +874,12 @@ This enables direnv globally.
|
|||
#+RESULTS:
|
||||
: org-babel-scheme--table-or-string
|
||||
|
||||
**** TODO Move babel test file to emacs config folder
|
||||
|
||||
Alternatively I might add a sample after each configured block to keep
|
||||
it in the same context. Hmmm.... sounds even better.
|
||||
|
||||
|
||||
*** Org Export
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(use-package ox
|
||||
|
|
Loading…
Reference in a new issue