From c42602d646e08c3779eaf80ae0475c3a8e8a76fc Mon Sep 17 00:00:00 2001 From: nik gaffney Date: Sun, 16 Oct 2022 14:09:28 +0200 Subject: [PATCH] engine revving --- .gitignore | 1 + src/moonrat.el | 52 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 1a59348..0332b40 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .DS_Store compiled/ /doc/ +*.elc diff --git a/src/moonrat.el b/src/moonrat.el index 5e94ff2..eb53cb8 100644 --- a/src/moonrat.el +++ b/src/moonrat.el @@ -31,9 +31,43 @@ ;;; Code: +(defvar moonrat-command + "raco moonrat" + "The CLI command to generate texts with.") + +;;;###autoload (defun moonrat-generate () - "Generate something." - (message "not yet...")) + "Generate some text from a file or the current buffer." + (interactive) + (let ((src (completing-read + "Generate from: " + '(("buffer" 1) ("file" 2)) + nil t ""))) + (cond ((string= src "file") + (call-interactively #'moonrat-generate-from-file)) + ((string= src "buffer") + (call-interactively #'moonrat-generate-from-buffer))))) + +;;;###autoload +(defun moonrat-generate-from-buffer (&optional buffer) + "Generate some text from a template in the current buffer or BUFFER." + (interactive) + (shell-command + (concat moonrat-command " " + (buffer-file-name (current-buffer))) + (get-buffer-create "*moonrat-output*") + (get-buffer-create "*moonrat-errors*"))) + +;;;###autoload +(defun moonrat-generate-from-file (&optional file) + "Generate some text from a template in FILE." + (interactive + (list (read-file-name "Template file to use: "))) + (shell-command + (concat moonrat-command " " file) + (get-buffer-create "*moonrat-output*") + (get-buffer-create "*moonrat-errors*"))) + (defvar moonrat-mode-map (let ((map (make-sparse-keymap))) @@ -43,20 +77,6 @@ (defconst moonrat-keywords '(("output" . 'font-lock-function-name-face))) -;; (defconst moonrat-syntax-table -;; (let ((table (make-syntax-table))) - -;; ;; brackets -;; (modify-syntax-entry ?\{ "(}" table) -;; (modify-syntax-entry ?\} "){" table) -;; (modify-syntax-entry ?\[ "(]" table) -;; (modify-syntax-entry ?\] ")[" table) - -;; ;; / is punctuation, but // is a comment starter -;; (modify-syntax-entry ?/ ". 12" table) -;; ;; \n ends a comment -;; (modify-syntax-entry ?\n ">" table) -;; table)) ;;;###autoload (define-derived-mode moonrat-mode prog-mode "🌝"