Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch mode #16

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,19 @@ By default `d2-tmp-dir` points to `\tmp\`. Feel free to set it to a more appropr
To customize the key bindings but this into your `init.el` ...

```elisp
(setq d2-mode-map
(let ((map d2-mode-map))
(define-key map (kbd "C-c C-c") nil)
(define-key map (kbd "C-c C-f") nil)
(define-key map (kbd "C-c C-b") nil)
(define-key map (kbd "C-c C-r") nil)
(define-key map (kbd "C-c C-o") nil)
(define-key map (kbd "C-c C-d") nil)
(define-key map (kbd "C-c C-d c") 'd2-compile)
(define-key map (kbd "C-c C-d c") 'd2-compile)
(define-key map (kbd "C-c C-d f") 'd2-compile-file)
(define-key map (kbd "C-c C-d b") 'd2-compile-buffer)
(define-key map (kbd "C-c C-d r") 'd2-compile-region)
(define-key map (kbd "C-c C-d o") 'd2-open-browser)
(define-key map (kbd "C-c C-d d") 'd2-open-doc)
(defvar d2-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-c") 'd2-compile)
(define-key map (kbd "C-c C-f") 'd2-compile-file)
(define-key map (kbd "C-c C-b") 'd2-compile-buffer)
(define-key map (kbd "C-c C-r") 'd2-compile-region)
(define-key map (kbd "C-c C-o") 'd2-open-browser)
(define-key map (kbd "C-c C-d") 'd2-open-doc)
(define-key map (kbd "C-c C-w") 'd2-compile-and-watch-file)
(define-key map (kbd "C-c C-K") 'd2-kill-all-processes)
(define-key map (kbd "C-c C-s") 'd2-show-processes)
(define-key map (kbd "C-c C-k") 'd2-kill-process)
map))

```

## Bugs & Issues
Expand Down
32 changes: 31 additions & 1 deletion d2-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,36 @@ STR is the declaration."
(interactive "fFilename: ")
(let* ((input file-name)
(output (concat (file-name-sans-extension input) d2-output-format)))
(message output)
(apply #'call-process d2-location nil "*d2*" nil (list input output))
(display-buffer (find-file-noselect output t))))

(defun process-signal (process signal)
(when (memq (process-status process) '(exit signal))
(message "Do something!")
(shell-command-sentinel process signal)))

(defun d2-compile-and-watch-file ()
;; async watching of file
(interactive)
(let* ((output-buffer (generate-new-buffer "*d2 Watch Mode*"))
(proc (progn
(async-shell-command "/opt/homebrew/bin/d2 -w /Users/akmb2/Downloads/input.d2 /tmp/output2.svg" output-buffer)
(get-buffer-process output-buffer))))
(if (process-live-p proc)
(set-process-sentinel proc #'process-signal)
(message "No process running."))))

(defun d2-kill-all-processes ()
((interactive))
(message "not implemented"))

(defun d2-kill-processes ()
((interactive))
(message "not implemented"))

(defun d2-show-proccesses ()
(interactive)
(message "not implemented"))

(defun d2-open-doc ()
"Open the d2 home page and doc."
Expand All @@ -193,6 +219,10 @@ STR is the declaration."
(define-key map (kbd "C-c C-r") 'd2-compile-region)
(define-key map (kbd "C-c C-o") 'd2-open-browser)
(define-key map (kbd "C-c C-d") 'd2-open-doc)
(define-key map (kbd "C-c C-w") 'd2-compile-and-watch-file)
(define-key map (kbd "C-c C-K") 'd2-kill-all-processes)
(define-key map (kbd "C-c C-s") 'd2-show-processes)
(define-key map (kbd "C-c C-k") 'd2-kill-process)
map))

;;;###autoload
Expand Down