From 1524994babb3e495bd68dcafe7a8740603baf761 Mon Sep 17 00:00:00 2001 From: Erwin Boskma Date: Mon, 16 Dec 2024 16:16:53 +0100 Subject: [PATCH] emacs: Add plantuml wrapper so org-mode can work with plantuml-server --- home-manager/modules/emacs/config.org | 42 ++++++++++++++------------ home-manager/modules/emacs/default.nix | 32 ++++++++++++++++++++ 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/home-manager/modules/emacs/config.org b/home-manager/modules/emacs/config.org index 096691e..3aaa4c4 100644 --- a/home-manager/modules/emacs/config.org +++ b/home-manager/modules/emacs/config.org @@ -1778,26 +1778,28 @@ Configuration #+name: org-config #+begin_src emacs-lisp :tangle no - (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode)) - (add-to-list - 'org-src-lang-modes '("plantuml" . plantuml)) - (dolist (face '((org-level-1 . 1.2) - (org-level-2 . 1.1) - (org-level-3 . 1.05) - (org-level-4 . 1.0) - (org-level-5 . 1.0) - (org-level-6 . 1.0) - (org-level-7 . 1.0) - (org-level-8 . 1.0))) - (set-face-attribute (car face) nil :family my/variable-width-font :weight 'medium :height (cdr face))) - (set-face-attribute 'org-document-title nil :family my/variable-width-font :weight 'bold :height 1.3) - (set-face-attribute 'org-block nil :foreground nil :inherit 'fixed-pitch) - (set-face-attribute 'org-table nil :inherit 'fixed-pitch) - (set-face-attribute 'org-formula nil :inherit 'fixed-pitch) - (set-face-attribute 'org-code nil :inherit '(shadow fixed-pitch)) - (set-face-attribute 'org-verbatim nil :inherit '(shadow fixed-pitch)) - (set-face-attribute 'org-special-keyword nil :inherit '(font-lock-comment-face fixed-pitch)) - (set-face-attribute 'org-checkbox nil :inherit 'fixed-pitch) + (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode)) + (add-to-list + 'org-src-lang-modes '("plantuml" . plantuml)) + (dolist (face '((org-level-1 . 1.2) + (org-level-2 . 1.1) + (org-level-3 . 1.05) + (org-level-4 . 1.0) + (org-level-5 . 1.0) + (org-level-6 . 1.0) + (org-level-7 . 1.0) + (org-level-8 . 1.0))) + (set-face-attribute (car face) nil :family my/variable-width-font :weight 'medium :height (cdr face))) + (set-face-attribute 'org-document-title nil :family my/variable-width-font :weight 'bold :height 1.3) + (set-face-attribute 'org-block nil :foreground nil :inherit 'fixed-pitch) + (set-face-attribute 'org-table nil :inherit 'fixed-pitch) + (set-face-attribute 'org-formula nil :inherit 'fixed-pitch) + (set-face-attribute 'org-code nil :inherit '(shadow fixed-pitch)) + (set-face-attribute 'org-verbatim nil :inherit '(shadow fixed-pitch)) + (set-face-attribute 'org-special-keyword nil :inherit '(font-lock-comment-face fixed-pitch)) + (set-face-attribute 'org-checkbox nil :inherit 'fixed-pitch) + (setq org-plantuml-exec-mode 'plantuml + org-plantuml-executable-path "plantuml-client") #+end_src =org-capture= allows creating and saving quick notes, links and TODOs diff --git a/home-manager/modules/emacs/default.nix b/home-manager/modules/emacs/default.nix index a1e4df3..a30ed74 100644 --- a/home-manager/modules/emacs/default.nix +++ b/home-manager/modules/emacs/default.nix @@ -8,6 +8,37 @@ with lib; let cfg = config.eboskma.programs.emacs; + plantuml-client = pkgs.writeShellApplication { + name = "plantuml-client"; + runtimeInputs = with pkgs; [ + coreutils + xh + ]; + + text = '' + type= + while getopts ":t:" option; do + case "''${option}" in + t) + type="''${OPTARG}";; + \?) + ;; + esac + done + + tempfile=$(mktemp --suffix plantuml) + + while IFS= read -r line; do + echo "''${line}" >> "''${tempfile}" + done + + encoded=$(xh --print=b post http://localhost:5080/plantuml/coder Content-Type:text/plain < "''${tempfile}") + rm "''${tempfile}" + + xh get "http://localhost:5080/plantuml/''${type}/''${encoded}" + ''; + }; + tangleEmacsConfig = initFile: pkgs.runCommand "tangled-emacs-${initFile}" { } '' @@ -173,6 +204,7 @@ in })) nixfmt-rfc-style python3 + plantuml-client ] ++ (with aspellDicts; [ en