module: add :lang graphviz

Close: #7546
Co-authored-by: nbfalcon <nbfalcon@users.noreply.github.com>
Co-authored-by: peterhoeg <peterhoeg@users.noreply.github.com>
This commit is contained in:
Henrik Lissner 2024-09-11 05:27:14 -04:00
parent fc35b3cf37
commit f6b7e8ae48
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
6 changed files with 132 additions and 0 deletions

View file

@ -0,0 +1,64 @@
:PROPERTIES:
:ID: 3efe8402-e4a1-41c3-ad1a-9aaa3783f68f
:END:
#+title: :lang graphviz
#+subtitle: Diagrams to confuse yourself even more
#+created: Nov 14, 2023
#+since: 23.09.0-pre
* Description :unfold:
This module adds graphviz support to Emacs, allowing you to generate diagrams
from plain text. Flycheck is supported.
** Maintainers
/This module has no dedicated maintainers./ [[doom-contrib-maintainer:][Become a maintainer?]]
** Module flags
/This module has no flags./
** Packages
- [[doom-package:graphviz-dot-mode]]
** Hacks
/No hacks documented for this module./
** TODO Changelog
# This section will be machine generated. Don't edit it by hand.
/This module does not have a changelog yet./
* Installation
[[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]]
This module requires that the =graphviz= package be installed on your system to
build diagrams with. You can install it using:
#+begin_src shell
sudo dnf install graphviz # For fedora
sudo apt install graphviz # For debian/ubuntu
#+end_src
* Usage
This module should configure "out-of-the-box" if you have installed graphviz on
your system.
With org-babel LaTeX/PDF-export, use a file naming ending with ".pdf", otherwise
LaTeX might complain about a non-existant ~\\includesvg~ command.
#+begin_src dot :file graph-1.pdf
digraph {
A -> B;
B -> D;
}
#+end_src
* Configuration
There is nothing to configure. Just install dot and it should work.
* Troubleshooting
/There are no known problems with this module./ [[doom-report:][Report one?]]
* Frequently asked questions
/This module has no FAQs yet./ [[doom-suggest-faq:][Ask one?]]
* TODO Appendix
#+begin_quote
󱌣 This module has no appendix yet. [[doom-contrib-module:][Write one?]]
#+end_quote

View file

@ -0,0 +1,19 @@
;;; lang/graphviz/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(cl-defun +graphviz-formatter (&key _buffer scratch callback &allow-other-keys)
"Format graphviz graphs."
(with-current-buffer scratch
(let ((inhibit-message t)
(message-log-max nil))
(goto-char (point-min))
(graphviz-dot-indent-graph))
(funcall callback)))
;;;###autoload
(defun +graphviz/toggle-preview ()
"Toggle `graphviz-dot-auto-preview-on-save'."
(interactive nil 'graphviz-dot-mode)
(if graphviz-dot-auto-preview-on-save
(graphviz-turn-off-live-preview)
(graphviz-turn-on-live-preview)))

View file

@ -0,0 +1,38 @@
;;; lang/graphviz/config.el -*- lexical-binding: t; -*-
(use-package! graphviz-dot-mode
:mode "\\.\\(?:nw\\|rack\\)diag\\'"
:init
(after! org-src
(add-to-list '+org-babel-mode-alist '(dot . graphviz-dot-mode))
(add-to-list 'org-src-lang-modes '("dot" . graphviz-dot-mode)))
:config
(set-company-backend! 'graphviz-dot-mode 'company-graphviz-dot-backend)
(set-formatter! 'graphviz-dot #'+graphviz-formatter :modes '(graphviz-dot-mode))
(set-tree-sitter-lang! 'graphviz-dot-mode 'dot)
(when (modulep! +tree-sitter)
(add-hook 'graphiz-dot-mode-hook #'tree-sitter!))
(after! dtrt-indent
(add-to-list 'dtrt-indent-hook-mapping-list '(graphviz-mode graphviz-dot-indent-width)))
(when (and (modulep! :checker syntax)
(not (modulep! :checker syntax +flymake)))
(after! flycheck
(flycheck-define-checker graphviz-dot
"A checker using graphviz dot."
:command ("dot")
:standard-input t
:error-patterns ((error line-start "Error: <stdin>: " (message "syntax error in line " line (* nonl)))
;; I have no idea if this can actually be printed
(error line-start "Error: <stdin>: " (message)))
:modes graphviz-dot-mode)
(add-to-list 'flycheck-checkers 'graphviz-dot)))
(map! :map graphviz-dot-mode-map
:localleader
:desc "External view" :nv "e" #'graphviz-dot-view
:desc "Preview" :nv "p" #'graphviz-dot-preview
:prefix ("t" . "toggle")
:desc "Preview" :nv "p" #'+graphviz/toggle-preview))

View file

@ -0,0 +1,6 @@
;; -*- lexical-binding: t; no-byte-compile: t; -*-
;;; lang/graphviz/doctor.el
(when (require 'graphviz-dot-mode nil t)
(unless (executable-find graphviz-dot-dot-program)
(warn! "Couldn't find dot. Previewing and exporting will not work")))

View file

@ -0,0 +1,4 @@
;; -*- no-byte-compile: t; -*-
;;; lang/graphviz/packages.el
(package! graphviz-dot-mode :pin "8ff793b13707cb511875f56e167ff7f980a31136")

View file

@ -154,6 +154,7 @@
org ; organize your plain life in plain text
;;php ; perl's insecure younger brother
;;plantuml ; diagrams for confusing people more
;;graphviz ; diagrams for confusing yourself even more
;;purescript ; javascript, but functional
;;python ; beautiful is better than ugly
;;qt ; the 'cutest' gui framework ever