Skip to content

Commit

Permalink
let chatu help you create empty draw
Browse files Browse the repository at this point in the history
  • Loading branch information
kimim committed Feb 14, 2024
1 parent 32a3b4f commit 674ef15
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 23 deletions.
2 changes: 1 addition & 1 deletion chatu-babashka.el
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ KEYWORD-PLIST contains parameters from the chatu line."
(interactive)
(let* ((path (plist-get keyword-plist :input-path))
(path (chatu-common-with-extension path "bb")))
(find-file-other-window path)))
(chatu-common-open-other-window path "")))

(provide 'chatu-babashka)

Expand Down
2 changes: 1 addition & 1 deletion chatu-clojure.el
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ KEYWORD-PLIST contains parameters from the chatu line."
(interactive)
(let* ((path (plist-get keyword-plist :input-path))
(path (chatu-common-with-extension path "clj")))
(find-file-other-window path)))
(chatu-common-open-other-window path "")))

(provide 'chatu-clojure)

Expand Down
50 changes: 33 additions & 17 deletions chatu-common.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,38 @@
path
(file-name-with-extension path file-ext)))

(defun chatu-common-open-external (executable path)
"Open chatu PATH with EXECUTABLE program."
(cond
;; ensure that draw.io.exe is in execute PATH
((string-equal system-type "windows-nt")
(if (fboundp 'w32-shell-execute)
(w32-shell-execute "open" path)))
;; TODO: need some test for other systems
((string-equal system-type "darwin")
(start-process "" nil "open" "-a" executable
path))
((string-equal system-type "gnu/linux")
(start-process "" nil "xdg-open"
executable path))
((string-equal system-type "cygwin")
(start-process "" nil "xdg-open"
executable path))))
(defun chatu-common-open-other-window (path empty)
"Open chatu PATH in other window.
Fill PATH with EMPTY string if nonexist."
(let ((parent (file-name-parent-directory path)))
(when (not (file-exists-p parent))
(make-directory parent-dir t))
(when (not (file-exists-p path))
(write-region empty nil path))
(find-file-other-window path)))

(defun chatu-common-open-external (executable path empty)
"Open chatu PATH with EXECUTABLE program.
Fill PATH with EMPTY string, if nonexist."
(let ((parent (file-name-parent-directory path)))
(when (not (file-exists-p parent))
(make-directory parent t))
(when (not (file-exists-p path))
(write-region empty nil path))
(cond
;; ensure that draw.io.exe is in execute PATH
((string-equal system-type "windows-nt")
(if (fboundp 'w32-shell-execute)
(w32-shell-execute "open" path)))
;; TODO: need some test for other systems
((string-equal system-type "darwin")
(start-process "" nil "open" "-a" executable
path))
((string-equal system-type "gnu/linux")
(start-process "" nil "xdg-open"
executable path))
((string-equal system-type "cygwin")
(start-process "" nil "xdg-open"
executable path)))))

(provide 'chatu-common)
6 changes: 5 additions & 1 deletion chatu-drawio.el
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ KEYWORD-PLIST contains parameters from the chatu line."
(shell-quote-argument output-path)
(shell-quote-argument output-path-pdf)))))

(defconst chatu-drawio-empty
"<mxfile><diagram><mxGraphModel></mxGraphModel></diagram></mxfile>"
"Content of empty drawio file.")

(defun chatu-drawio-open (keyword-plist)
"Open .drawio file.
KEYWORD-PLIST contains parameters from the chatu line."
(interactive)
(let* ((path (plist-get keyword-plist :input-path))
(path (chatu-common-with-extension path "drawio")))
(chatu-common-open-external "draw.io" path)))
(chatu-common-open-external "draw.io" path chatu-drawio-empty)))

(provide 'chatu-drawio)

Expand Down
10 changes: 9 additions & 1 deletion chatu-lilypond.el
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,21 @@ KEYWORD-PLIST contains parameters from the chatu line."
(shell-quote-argument cropped)
(shell-quote-argument with-svg))))

(defconst chatu-lilypond-empty
"\\header {
title = ""
}
\relative c' {
}"
"Content of empty LilyPond file.")

(defun chatu-lilypond-open (keyword-plist)
"Open input file.
KEYWORD-PLIST contains parameters from the chatu line."
(interactive)
(let* ((path (plist-get keyword-plist :input-path))
(path (chatu-common-with-extension path "ly")))
(find-file-other-window path)))
(chatu-common-open-other-window path chatu-lilypond-empty)))

(provide 'chatu-lilypond)

Expand Down
2 changes: 1 addition & 1 deletion chatu-plantuml.el
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ KEYWORD-PLIST contains parameters from the chatu line."
(interactive)
(let* ((path (plist-get keyword-plist :input-path))
(path (chatu-common-with-extension path "puml")))
(find-file-other-window path)))
(chatu-common-open-other-window path "")))

(provide 'chatu-plantuml)

Expand Down
2 changes: 1 addition & 1 deletion chatu-r.el
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ KEYWORD-PLIST contains parameters from the chatu line."
(interactive)
(let* ((path (plist-get keyword-plist :input-path))
(path (chatu-common-with-extension path "R")))
(find-file-other-window path)))
(chatu-common-open-other-window path "")))

(provide 'chatu-r)

Expand Down

0 comments on commit 674ef15

Please sign in to comment.