]> gitweb.factorcode.org Git - factor.git/blob - misc/fuel/fuel-scaffold.el
Merge branch 'master' of git://repo.or.cz/factor/jcg
[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 user-full-name
30   "The name to be inserted as yours in scaffold templates."
31   :type 'string
32   :group 'fuel-scaffold)
33
34 \f
35 ;;; Auxiliary functions:
36
37 (defun fuel-scaffold--vocab-roots ()
38   (let ((cmd '(:fuel* (vocab-roots get :get) "fuel")))
39     (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
40
41 \f
42 ;;; User interface:
43
44 (defun fuel-scaffold-vocab (&optional other-window name-hint root-hint)
45   "Creates a directory in the given root for a new vocabulary and
46 adds source, tests and authors.txt files.
47
48 You can configure `fuel-scaffold-developer-name' (set by default to
49 `user-full-name') for the name to be inserted in the generated files."
50   (interactive)
51   (let* ((name (read-string "Vocab name: " name-hint))
52          (root (completing-read "Vocab root: "
53                                 (fuel-scaffold--vocab-roots)
54                                 nil t (or root-hint "resource:")))
55          (cmd `(:fuel* ((,root ,name ,fuel-scaffold-developer-name)
56                         (fuel-scaffold-vocab)) "fuel"))
57          (ret (fuel-eval--send/wait cmd))
58          (file (fuel-eval--retort-result ret)))
59     (unless file
60       (error "Error creating vocab (%s)" (car (fuel-eval--retort-error ret))))
61     (if other-window (find-file-other-window file) (find-file file))
62     (goto-char (point-max))
63     name))
64
65 (defun fuel-scaffold-help (&optional arg)
66   "Creates, if it does not already exist, a help file with
67 scaffolded help for each word in the current vocabulary.
68
69 With prefix argument, ask for the vocabulary name.
70 You can configure `fuel-scaffold-developer-name' (set by default to
71 `user-full-name') for the name to be inserted in the generated file."
72   (interactive "P")
73   (let* ((vocab (or (and (not arg) (fuel-syntax--current-vocab))
74                    (fuel-edit--read-vocabulary-name nil)))
75          (cmd `(:fuel* (,vocab ,fuel-scaffold-developer-name fuel-scaffold-help)
76                        "fuel"))
77          (ret (fuel-eval--send/wait cmd))
78          (file (fuel-eval--retort-result ret)))
79         (unless file
80           (error "Error creating help file" (car (fuel-eval--retort-error ret))))
81         (find-file file)))
82
83 \f
84 (provide 'fuel-scaffold)
85 ;;; fuel-scaffold.el ends here