]> gitweb.factorcode.org Git - factor.git/blobdiff - misc/fuel/fuel-scaffold.el
FUEL: fix cmd syntax of call to fuel-scaffold-vocab
[factor.git] / misc / fuel / fuel-scaffold.el
index 9e8e56475d39fbe7d814cc048cc0cd2f349111ea..ae0091b9333dac69a4705bae4ed37e57321aa1eb 100644 (file)
 
 (require 'fuel-eval)
 (require 'fuel-edit)
-(require 'fuel-syntax)
 (require 'fuel-base)
+(require 'factor-mode)
 
 \f
 ;;; Customisation:
 
+;;;###autoload
 (defgroup fuel-scaffold nil
   "Options for FUEL's scaffolding."
   :group 'fuel)
 
-(defcustom fuel-scaffold-developer-name nil
-  "The name to be inserted as yours in scaffold templates."
-  :type '(choice string
-                 (const :tag "Factor's value for developer-name" nil))
-  :group 'fuel-scaffold)
-
-\f
 ;;; Auxiliary functions:
 
+(defun fuel-mode--code-file (kind &optional file)
+  (let* ((file (or file (buffer-file-name)))
+         (bn (file-name-nondirectory file)))
+    (and (string-match (format "\\(.+\\)-%s\\.factor$" kind) bn)
+         (expand-file-name (concat (match-string 1 bn) ".factor")
+                           (file-name-directory file)))))
+
+(defun fuel-mode--in-docs (&optional file)
+  (fuel-mode--code-file "docs"))
+
+(defun fuel-mode--in-tests (&optional file)
+  (fuel-mode--code-file "tests"))
+
 (defun fuel-scaffold--vocab-roots ()
-  (let ((cmd '(:fuel* (vocab-roots get :get) "fuel")))
-    (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
+  (let ((cmd '(:fuel* (vocab-roots get)
+                      "fuel" ("namespaces" "vocabs.loader"))))
+    (nth 1 (fuel-eval--send/wait cmd))))
 
 (defun fuel-scaffold--dev-name ()
-  (or fuel-scaffold-developer-name
-      (let ((cmd '(:fuel* (developer-name get :get) "fuel")))
+  (or (let ((cmd '(:fuel* (developer-name get)
+                          "fuel"
+                          ("namespaces" "tools.scaffold"))))
         (fuel-eval--retort-result (fuel-eval--send/wait cmd)))
+      user-full-name
       "Your name"))
 
 (defun fuel-scaffold--first-vocab ()
   (goto-char (point-min))
-  (re-search-forward fuel-syntax--current-vocab-regex nil t))
+  (re-search-forward factor-current-vocab-regex nil t))
 
 (defsubst fuel-scaffold--vocab (file)
-  (save-excursion
-    (set-buffer (find-file-noselect file))
+  (with-current-buffer (find-file-noselect file)
     (fuel-scaffold--first-vocab)
-    (fuel-syntax--current-vocab)))
+    (factor-current-vocab)))
 
 (defconst fuel-scaffold--tests-header-format
   "! Copyright (C) %s %s
@@ -62,6 +71,10 @@ USING: %s tools.test ;
 IN: %s
 ")
 
+(defvar fuel-scaffold-test-autoinsert-p nil)
+(defvar fuel-scaffold-help-autoinsert-p nil)
+(defvar fuel-scaffold-help-header-only-p nil)
+
 (defsubst fuel-scaffold--check-auto (var)
   (and var (or (eq var 'always) (y-or-n-p "Insert template? "))))
 
@@ -75,17 +88,18 @@ IN: %s
       t)))
 
 (defsubst fuel-scaffold--create-docs (vocab)
-  (let ((cmd `(:fuel* (,vocab ,fuel-scaffold-developer-name fuel-scaffold-help)
+  (let ((cmd `(:fuel* (,vocab ,(fuel-scaffold--dev-name) fuel-scaffold-help)
                       "fuel")))
     (fuel-eval--send/wait cmd)))
 
 (defsubst fuel-scaffold--create-tests (vocab)
-  (let ((cmd `(:fuel* (,vocab ,fuel-scaffold-developer-name fuel-scaffold-tests)
+  (let ((cmd `(:fuel* (,vocab ,(fuel-scaffold--dev-name) fuel-scaffold-tests)
                       "fuel")))
     (fuel-eval--send/wait cmd)))
 
 (defsubst fuel-scaffold--create-authors (vocab)
-  (let ((cmd `(:fuel* (,vocab ,fuel-scaffold-developer-name fuel-scaffold-authors) "fuel")))
+  (let ((cmd `(:fuel* (,vocab ,(fuel-scaffold--dev-name)
+                              fuel-scaffold-authors) "fuel")))
     (fuel-eval--send/wait cmd)))
 
 (defsubst fuel-scaffold--create-tags (vocab tags)
@@ -96,7 +110,9 @@ IN: %s
   (let ((cmd `(:fuel* (,vocab ,summary fuel-scaffold-summary) "fuel")))
     (fuel-eval--send/wait cmd)))
 
-(defsubst fuel-scaffold--creaet-
+(defsubst fuel-scaffold--create-platforms (vocab platforms)
+  (let ((cmd `(:fuel* (,vocab ,platforms fuel-scaffold-platforms) "fuel")))
+    (fuel-eval--send/wait cmd)))
 
 (defun fuel-scaffold--help (parent)
   (when (and parent (fuel-scaffold--check-auto fuel-scaffold-help-autoinsert-p))
@@ -113,19 +129,20 @@ IN: %s
 
 (defun fuel-scaffold--maybe-insert ()
   (ignore-errors
-    (or (fuel-scaffold--tests (factor-mode--in-tests))
-        (fuel-scaffold--help (factor-mode--in-docs)))))
+    (or (fuel-scaffold--tests (fuel-mode--in-tests))
+        (fuel-scaffold--help (fuel-mode--in-docs)))))
 
 \f
 ;;; User interface:
 
+;;;###autoload
 (defun fuel-scaffold-vocab (&optional other-window name-hint root-hint)
   "Creates a directory in the given root for a new vocabulary and
 adds source and authors.txt files. Prompts the user for optional summary,
 tags, help, and test file creation.
 
-You can configure `fuel-scaffold-developer-name' (set by default to
-`user-full-name') for the name to be inserted in the generated files."
+You can configure `user-full-name' for the name to be inserted in
+the generated files."
   (interactive)
   (let* ((name (read-string "Vocab name: " name-hint))
          (root (completing-read "Vocab root: "
@@ -133,10 +150,11 @@ You can configure `fuel-scaffold-developer-name' (set by default to
                                 nil t (or root-hint "resource:")))
          (summary (read-string "Vocab summary (empty for none): "))
          (tags (read-string "Vocab tags (empty for none): "))
+         (platforms (read-string "Vocab platforms (empty for all): "))
          (help (y-or-n-p "Scaffold help? "))
          (tests (y-or-n-p "Scaffold tests? "))
-         (cmd `(:fuel* ((,root ,name ,fuel-scaffold-developer-name)
-                        (fuel-scaffold-vocab)) "fuel"))
+         (cmd `(:fuel* (,root ,name ,(fuel-scaffold--dev-name)
+                              fuel-scaffold-vocab) "fuel"))
          (ret (fuel-eval--send/wait cmd))
          (file (fuel-eval--retort-result ret)))
     (unless file
@@ -145,6 +163,8 @@ You can configure `fuel-scaffold-developer-name' (set by default to
       (fuel-scaffold--create-summary name summary))
     (when (not (equal "" tags))
       (fuel-scaffold--create-tags name tags))
+    (when (not (equal "" platforms))
+      (fuel-scaffold--create-platforms name platforms))
     (when help
          (fuel-scaffold--create-docs name))
     (when tests
@@ -153,76 +173,102 @@ You can configure `fuel-scaffold-developer-name' (set by default to
     (goto-char (point-max))
     name))
 
+;;;###autoload
 (defun fuel-scaffold-help (&optional arg)
   "Creates, if it does not already exist, a help file with
 scaffolded help for each word in the current vocabulary.
 
-With prefix argument, ask for the vocabulary name.
-You can configure `fuel-scaffold-developer-name' (set by default to
-`user-full-name') for the name to be inserted in the generated file."
+With prefix argument, ask for the vocabulary name. You can
+configure `user-full-name' for the name to be
+inserted in the generated file."
   (interactive "P")
-  (let* ((vocab (or (and (not arg) (fuel-syntax--current-vocab))
+  (let* ((vocab (or (and (not arg) (factor-current-vocab))
                     (fuel-completion--read-vocab nil)))
          (ret (fuel-scaffold--create-docs vocab))
          (file (fuel-eval--retort-result ret)))
         (unless file
-          (error "Error creating help file" (car (fuel-eval--retort-error ret))))
+          (error "Error creating help file: %s"
+                 (car (fuel-eval--retort-error ret))))
         (find-file file)))
 
+;;;###autoload
 (defun fuel-scaffold-tests (&optional arg)
-  "Creates, if it does not already exist, a tests file for the current vocabulary.
+  "Creates, if it does not already exist, a tests file for the current
+vocabulary.
 
-With prefix argument, ask for the vocabulary name.
-You can configure `fuel-scaffold-developer-name' (set by default to
-`user-full-name') for the name to be inserted in the generated file."
+With prefix argument, ask for the vocabulary name. You can
+configure `user-full-name' for the name to be inserted in the
+generated file."
   (interactive "P")
-  (let* ((vocab (or (and (not arg) (fuel-syntax--current-vocab))
+  (let* ((vocab (or (and (not arg) (factor-current-vocab))
                     (fuel-completion--read-vocab nil)))
          (ret (fuel-scaffold--create-tests vocab))
          (file (fuel-eval--retort-result ret)))
         (unless file
-          (error "Error creating tests file" (car (fuel-eval--retort-error ret))))
+          (error "Error creating tests file: %s"
+                 (car (fuel-eval--retort-error ret))))
         (find-file file)))
 
 (defun fuel-scaffold-authors (&optional arg)
-  "Creates, if it does not already exist, an authors file for the current vocabulary.
+  "Creates, if it does not already exist, an authors file for the current
+vocabulary.
 
-With prefix argument, ask for the vocabulary name.
-You can configure `fuel-scaffold-developer-name' (set by default to
-`user-full-name') for the name to be inserted in the generated file."
+With prefix argument, ask for the vocabulary name. You can
+configure `user-full-name' for the name to be
+inserted in the generated file."
   (interactive "P")
-  (let* ((vocab (or (and (not arg) (fuel-syntax--current-vocab))
+  (let* ((vocab (or (and (not arg) (factor-current-vocab))
                     (fuel-completion--read-vocab nil)))
          (ret (fuel-scaffold--create-authors vocab))
          (file (fuel-eval--retort-result ret)))
         (unless file
-          (error "Error creating authors file" (car (fuel-eval--retort-error ret))))
+          (error "Error creating authors file: %s"
+                 (car (fuel-eval--retort-error ret))))
         (find-file file)))
 
 (defun fuel-scaffold-tags (&optional arg)
-  "Creates, if it does not already exist, a tags file for the current vocabulary."
+  "Creates, if it does not already exist, a tags file for the current
+vocabulary."
   (interactive "P")
-  (let* ((vocab (or (and (not arg) (fuel-syntax--current-vocab))
+  (let* ((vocab (or (and (not arg) (factor-current-vocab))
                     (fuel-completion--read-vocab nil)))
          (tags (read-string "Tags: "))
          (ret (fuel-scaffold--create-tags vocab tags))
          (file (fuel-eval--retort-result ret)))
         (unless file
-          (error "Error creating tags file" (car (fuel-eval--retort-error ret))))
+          (error "Error creating tags file: %s"
+                 (car (fuel-eval--retort-error ret))))
         (find-file file)))
 
 (defun fuel-scaffold-summary (&optional arg)
-  "Creates, if it does not already exist, a summary file for the current vocabulary."
+  "Creates, if it does not already exist, a summary file for the current
+vocabulary."
   (interactive "P")
-  (let* ((vocab (or (and (not arg ) (fuel-syntax--current-vocab))
+  (let* ((vocab (or (and (not arg ) (factor-current-vocab))
                     (fuel-completion--read-vocab nil)))
          (summary (read-string "Summary: "))
          (ret (fuel-scaffold--create-summary vocab summary))
          (file (fuel-eval--retort-result ret)))
         (unless file
-          (error "Error creating summary file" (car (fuel-eval--retort-error ret))))
+          (error "Error creating summary file: %s"
+                 (car (fuel-eval--retort-error ret))))
+        (find-file file)))
+
+(defun fuel-scaffold-platforms (&optional arg)
+  "Creates, if it does not already exist, a platforms file for the current
+vocabulary."
+  (interactive "P")
+  (let* ((vocab (or (and (not arg ) (factor-current-vocab))
+                    (fuel-completion--read-vocab nil)))
+         (platforms (read-string "Platforms: "))
+         (ret (fuel-scaffold--create-platforms vocab platforms))
+         (file (fuel-eval--retort-result ret)))
+        (unless file
+          (error "Error creating platforms file: %s"
+                 (car (fuel-eval--retort-error ret))))
         (find-file file)))
 
 \f
 (provide 'fuel-scaffold)
+
 ;;; fuel-scaffold.el ends here