Skip to content

Instantly share code, notes, and snippets.

@hh
Created February 22, 2011 08:27
Show Gist options
  • Save hh/838370 to your computer and use it in GitHub Desktop.
Save hh/838370 to your computer and use it in GitHub Desktop.
call graphviz compile on a file, and display the image when the compile is complete
;(load-file "~/.elisp/graphviz-dot-mode.el")
; http://users.skynet.be/ppareit/projects/graphviz-dot-mode/graphviz-dot-mode.html
; graphviz-dot-mode.el
;;;;
;;;; dot-compile in background
;;;;
(defun my-graphviz-dot-compile-sentinel (process change)
"Sentinel to display dot file.
PROCESS is the dot compile process
CHANGE is ignored."
(when (eq (process-status process) 'exit)
(let* (
(buf (process-buffer process))
(name (process-name process))
)
(message (concat name "FINISHED"))
(with-current-buffer (buffer-local-value 'original-buffer buf) (graphviz-dot-preview))
)
)
)
(defun my-graphviz-dot-compile ()
(interactive)
(let* (
(my-shortname (file-name-sans-extension buffer-file-name))
(my-imagefilename (concat my-shortname "." graphviz-dot-preview-extension))
(my-process-name (concat "*dot-compile*" my-shortname "*"))
(original-buffer (current-buffer))
)
(if (buffer-modified-p)
(save-buffer))
(message (concat my-process-name " Started"))
;; launch dot compile process
(setq my-process
(start-process my-process-name my-process-name
graphviz-dot-dot-program
(concat "-T" graphviz-dot-preview-extension)
buffer-file-name
(concat "-o" my-imagefilename)
))
;; make sure the process-buffer knows who launched it
(with-current-buffer (process-buffer my-process)
(set (make-local-variable 'original-buffer) original-buffer)
)
;; when there is a change in the processes status, run my sentinel
(set-process-sentinel my-process 'my-graphviz-dot-compile-sentinel)
)
)
;graphviz-dot-mode-hook
(defun my-graphviz-mode-hook ()
;(add-hook 'after-save-hook 'my-graphviz-dot-compile t t)
(define-key graphviz-dot-mode-map
[(control c)(control p)] 'my-graphviz-dot-compile)
)
(setq graphviz-dot-mode-hook 'my-graphviz-mode-hook)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment