diff --git a/chatu-babashka.el b/chatu-babashka.el index 57e8321..5384efd 100644 --- a/chatu-babashka.el +++ b/chatu-babashka.el @@ -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) diff --git a/chatu-clojure.el b/chatu-clojure.el index 6fd7108..4d31c3d 100644 --- a/chatu-clojure.el +++ b/chatu-clojure.el @@ -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) diff --git a/chatu-common.el b/chatu-common.el index 9a49d69..c7f55f8 100644 --- a/chatu-common.el +++ b/chatu-common.el @@ -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) diff --git a/chatu-drawio.el b/chatu-drawio.el index e29d6c9..209671e 100644 --- a/chatu-drawio.el +++ b/chatu-drawio.el @@ -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 + "" + "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) diff --git a/chatu-lilypond.el b/chatu-lilypond.el index c137b02..3708cd6 100644 --- a/chatu-lilypond.el +++ b/chatu-lilypond.el @@ -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) diff --git a/chatu-plantuml.el b/chatu-plantuml.el index 4297e35..900110e 100644 --- a/chatu-plantuml.el +++ b/chatu-plantuml.el @@ -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) diff --git a/chatu-r.el b/chatu-r.el index 9480140..9e07a24 100644 --- a/chatu-r.el +++ b/chatu-r.el @@ -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)