From d5e155998d9c0dcd54d69491162f96c5bf188198 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Tue, 21 Feb 2023 16:23:23 +0800 Subject: eshell: graphviz files management Handle compilation and removal of graphviz files easily. * .gitignore: Ignore elpa files that appear out of thin air. * eshell-conf.el (eshell/gv): Entry point for handling graphviz files. (vc): Use vc to find the project root. (eshell-gv): The internal function to handle graphviz files. --- .gitignore | 1 + eshell-conf.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/.gitignore b/.gitignore index 648dea0..f99fcfd 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ projects tramp calc.el multisession/* +elpa/* \ No newline at end of file diff --git a/eshell-conf.el b/eshell-conf.el index 42b727d..ba14746 100644 --- a/eshell-conf.el +++ b/eshell-conf.el @@ -560,5 +560,67 @@ For example, \"...\" expands into \"../..\"." :override #'durand-eshell-bookmark-jump) +;;; Handle graphviz commands + +;; It is convenient to be able to compile multiple GraphViz files or +;; delete multiple image files simultaneously. + +(defun eshell/gv (&rest args) + "Compile GraphViz files into images, or delete images, depending \ +on `args'." + (eshell-eval-using-options + "gv" args + '((?h "help" nil nil "Print this help message") + (?f "format" t image-format "Which image format to output") + (?r "remove" nil removep "Whether to remove images or not") + (?R "remove-all" nil remove-allp "Whether to remove images and sources or not") + :usage "[-f format] [-r|-R] [graphviz file names...] +This little command can perform two tasks: + +- Compile multiple GraphViz files. +- Remove output image files. + +The file names should not include any extension." + :preserve-args + :parse-leading-options-only + :show-usage) + (let ((removep (cond (remove-allp 'all) (removep)))) + (eshell-gv image-format removep args)))) + +(require 'vc) + +(defun eshell-gv (image-format removep &rest args) + "Internal function for `eshell/gv'." + (let ((args (car args)) + (image-format (cond (image-format) ("png"))) + (root-dir (expand-file-name "output" (vc-root-dir)))) + (cond + (removep + (mapc + (lambda (arg) + (let* ((file-name (expand-file-name + (format "%s.%s" arg image-format))) + (source-file-name (format "%s.gv" arg)) + (source-file-name + (expand-file-name source-file-name root-dir))) + (delete-file file-name) + (cond + ((eq removep 'all) (delete-file source-file-name))))) + args)) + ((mapc + (lambda (arg) + (let* ((out-file-name (format "%s.%s" arg image-format)) + (source-file-name (format "%s.gv" arg)) + (source-file-name + (expand-file-name source-file-name root-dir))) + (eshell-command-result + (format + "dot -T%s \"%s\" -o \"%s\"" + image-format + source-file-name + out-file-name)))) + args)))) + nil) + (provide 'eshell-conf) ;;; eshell-conf.el ends here -- cgit v1.2.3-18-g5258