Skip to content

Instantly share code, notes, and snippets.

@larrasket
larrasket / chess-babel.el
Last active October 31, 2024 18:04
Add org babel support for Portable Game Notation
;; this is another version that doesn't require any user parameters
(defun org-babel-execute:chess (body params)
"Execute a block of Chess code with org-babel.
This function is called by `org-babel-execute-src-block'."
(let* ((output-file (concat (file-name-sans-extension (buffer-file-name)) (format "_%s_chess_output.svg" (format-time-string "%Y-%m-%d_%H-%M-%S")) ))
(notation (cdr (assq :notation params)))
(extension (if (equal notation "fen") ".fen" ".pgn"))
(notation-file (make-temp-file "chess-notation" nil extension))
(cmd (format "python ~/configs/elchess.py %s %s %s" notation-file output-file notation)))