diff options
author | JSDurand <mmemmew@gmail.com> | 2023-02-21 16:23:23 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2023-02-21 16:23:23 +0800 |
commit | d5e155998d9c0dcd54d69491162f96c5bf188198 (patch) | |
tree | 9ac4f71e257511d933f7358bdf62e67a3660b57d /eshell-conf.el | |
parent | 53d5d8fd235b99d20a9fade158483f4603fefc2b (diff) |
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.
Diffstat (limited to 'eshell-conf.el')
-rw-r--r-- | eshell-conf.el | 62 |
1 files changed, 62 insertions, 0 deletions
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 |