]> gitweb.factorcode.org Git - factor.git/blob - misc/fuel/fuel-scaffold.el
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / misc / fuel / fuel-scaffold.el
1 ;;; fuel-scaffold.el -- interaction with tools.scaffold
2
3 ;; Copyright (C) 2009 Jose Antonio Ortega Ruiz
4 ;; See http://factorcode.org/license.txt for BSD license.
5
6 ;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
7 ;; Keywords: languages, fuel, factor
8 ;; Start date: Sun Jan 11, 2009 18:40
9
10 ;;; Comentary:
11
12 ;; Utilities for creating new vocabulary files and other boilerplate.
13 ;; Mainly, an interface to Factor's tools.scaffold.
14
15 ;;; Code:
16
17 (require 'fuel-eval)
18 (require 'fuel-edit)
19 (require 'fuel-syntax)
20 (require 'fuel-base)
21
22 \f
23 ;;; Customisation:
24
25 (defgroup fuel-scaffold nil
26   "Options for FUEL's scaffolding."
27   :group 'fuel)
28
29 (defcustom fuel-scaffold-developer-name nil
30   "The name to be inserted as yours in scaffold templates."
31   :type '(choice string
32                  (const :tag "Factor's value for developer-name" nil))
33   :group 'fuel-scaffold)
34
35 \f
36 ;;; Auxiliary functions:
37
38 (defun fuel-scaffold--vocab-roots ()
39   (let ((cmd '(:fuel* (vocab-roots get :get) "fuel")))
40     (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
41
42 \f
43 ;;; User interface:
44
45 (defun fuel-scaffold-vocab (&optional other-window name-hint root-hint)
46   "Creates a directory in the given root for a new vocabulary and
47 adds source, tests and authors.txt files.
48
49 You can configure `fuel-scaffold-developer-name' (set by default to
50 `user-full-name') for the name to be inserted in the generated files."
51   (interactive)
52   (let* ((name (read-string "Vocab name: " name-hint))
53          (root (completing-read "Vocab root: "
54                                 (fuel-scaffold--vocab-roots)
55                                 nil t (or root-hint "resource:")))
56          (cmd `(:fuel* ((,root ,name ,fuel-scaffold-developer-name)
57                         (fuel-scaffold-vocab)) "fuel"))
58          (ret (fuel-eval--send/wait cmd))
59          (file (fuel-eval--retort-result ret)))
60     (unless file
61       (error "Error creating vocab (%s)" (car (fuel-eval--retort-error ret))))
62     (if other-window (find-file-other-window file) (find-file file))
63     (goto-char (point-max))
64     name))
65
66 (defun fuel-scaffold-help (&optional arg)
67   "Creates, if it does not already exist, a help file with
68 scaffolded help for each word in the current vocabulary.
69
70 With prefix argument, ask for the vocabulary name.
71 You can configure `fuel-scaffold-developer-name' (set by default to
72 `user-full-name') for the name to be inserted in the generated file."
73   (interactive "P")
74   (let* ((vocab (or (and (not arg) (fuel-syntax--current-vocab))
75                     (fuel-completion--read-vocab nil)))
76          (cmd `(:fuel* (,vocab ,fuel-scaffold-developer-name fuel-scaffold-help)
77                        "fuel"))
78          (ret (fuel-eval--send/wait cmd))
79          (file (fuel-eval--retort-result ret)))
80         (unless file
81           (error "Error creating help file" (car (fuel-eval--retort-error ret))))
82         (find-file file)))
83
84 \f
85 (provide 'fuel-scaffold)
86 ;;; fuel-scaffold.el ends here