diff --git a/basis/tools/scaffold/scaffold-docs.factor b/basis/tools/scaffold/scaffold-docs.factor index d2989d3cac..9074c80986 100644 --- a/basis/tools/scaffold/scaffold-docs.factor +++ b/basis/tools/scaffold/scaffold-docs.factor @@ -26,7 +26,7 @@ HELP: scaffold-undocumented HELP: scaffold-vocab { $values { "vocab-root" "a vocabulary root string" } { "string" string } } -{ $description "Creates a direcory in the given root for a new vocabulary and adds a main .factor file, a tests file, and an authors.txt file." } ; +{ $description "Creates a directory in the given root for a new vocabulary and adds a main .factor file, a tests file, and an authors.txt file." } ; HELP: using { $description "Stores the vocabularies that are pulled into the documentation file from looking up the stack effect types." } ; diff --git a/extra/fuel/fuel.factor b/extra/fuel/fuel.factor index 50f02f1a1a..587537adcf 100644 --- a/extra/fuel/fuel.factor +++ b/extra/fuel/fuel.factor @@ -4,9 +4,10 @@ USING: accessors arrays assocs classes.tuple combinators compiler.units continuations debugger definitions help help.crossref help.markup help.topics io io.pathnames io.streams.string kernel lexer -make math math.order memoize namespaces parser quotations prettyprint +make math math.order memoize namespaces parser prettyprint quotations sequences sets sorting source-files strings summary tools.crossref -tools.vocabs tools.vocabs.browser vectors vocabs vocabs.parser words ; +tools.scaffold tools.vocabs tools.vocabs.browser vectors vocabs +vocabs.loader vocabs.parser words ; IN: fuel @@ -69,13 +70,15 @@ M: integer fuel-pprint pprint ; inline M: string fuel-pprint pprint ; inline -M: sequence fuel-pprint - "(" write [ " " write ] [ fuel-pprint ] interleave ")" write ; inline +: fuel-pprint-sequence ( seq open close -- ) + [ write ] dip swap [ " " write ] [ fuel-pprint ] interleave write ; inline + +M: sequence fuel-pprint "(" ")" fuel-pprint-sequence ; inline + +M: quotation fuel-pprint "[" "]" fuel-pprint-sequence ; inline M: tuple fuel-pprint tuple>array fuel-pprint ; inline -M: quotation fuel-pprint pprint ; inline - M: continuation fuel-pprint drop ":continuation" write ; inline M: restart fuel-pprint name>> fuel-pprint ; inline @@ -328,7 +331,7 @@ SYMBOL: vocab-list [ describe-words ] with-string-writer \ describe-words swap 2array ; inline : (fuel-vocab-help) ( name -- element ) - \ article swap dup >vocab-link + dup require \ article swap dup >vocab-link [ { [ vocab-authors [ \ $authors prefix , ] when* ] @@ -358,13 +361,24 @@ MEMO: (fuel-get-vocabs/author) ( author -- element ) : fuel-get-vocabs/author ( author -- ) (fuel-get-vocabs/author) fuel-eval-set-result ; -MEMO: (fuel-get-vocabs/tag ( tag -- element ) +MEMO: (fuel-get-vocabs/tag) ( tag -- element ) [ "Vocabularies tagged " prepend \ $heading swap 2array ] [ tagged fuel-vocab-list ] bi 2array ; : fuel-get-vocabs/tag ( tag -- ) - (fuel-get-vocabs/tag fuel-eval-set-result ; + (fuel-get-vocabs/tag) fuel-eval-set-result ; +! Scaffold support + +: fuel-scaffold-vocab ( root name devname -- ) + developer-name set + [ scaffold-vocab ] 2keep [ (normalize-path) ] dip dup + append-path append-path ".factor" append fuel-eval-set-result ; + +: fuel-scaffold-help ( name devname -- ) + developer-name set + dup require dup scaffold-help vocab-docs-path + (normalize-path) fuel-eval-set-result ; ! -run=fuel support diff --git a/misc/fuel/README b/misc/fuel/README index f722b18598..2f3417a6b5 100644 --- a/misc/fuel/README +++ b/misc/fuel/README @@ -43,6 +43,26 @@ beast. Many aspects of the environment can be customized: M-x customize-group fuel will show you how many. +*** Faster listener startup + + On startup, run-factor loads the fuel vocabulary, which can take a + while. If you want to speedup the load process, type 'save' in the + listener prompt just after invoking run-factor. This will save a + factor image (overwriting the current one) with all the needed + vocabs. + +*** Vocabulary creation + + FUEL offers a basic interface with Factor's scaffolding utilities. + To create a new vocabulary directory and associated files: + + M-x fuel-scaffold-vocab + + and when in a vocab file, to create a docs file with boilerplate + for each word: + + M-x fuel-scaffold-help + * Quick key reference (Triple chords ending in a single letter accept also C- (e.g. diff --git a/misc/fuel/factor-mode.el b/misc/fuel/factor-mode.el index d3a633910c..4164e14c5e 100644 --- a/misc/fuel/factor-mode.el +++ b/misc/fuel/factor-mode.el @@ -111,7 +111,7 @@ code in the buffer." (= (- be (point)) (current-indentation)) (= ln (line-number-at-pos be))) (fuel-syntax--indentation-at bs)) - ((or (fuel-syntax--is-eol bs) + ((or (fuel-syntax--is-last-char bs) (not (eq ?\ (char-after (1+ bs))))) (fuel-syntax--increased-indentation (fuel-syntax--indentation-at bs))) @@ -238,15 +238,17 @@ code in the buffer." ;;; Keymap: -(defun factor-mode-insert-and-indent (n) - (interactive "p") - (self-insert-command n) +(defun factor-mode--insert-and-indent (n) + (interactive "*p") + (let ((start (point))) + (self-insert-command n) + (save-excursion (font-lock-fontify-region start (point)))) (indent-according-to-mode)) (defvar factor-mode-map (let ((map (make-sparse-keymap))) - (define-key map [?\]] 'factor-mode-insert-and-indent) - (define-key map [?}] 'factor-mode-insert-and-indent) + (define-key map [?\]] 'factor-mode--insert-and-indent) + (define-key map [?}] 'factor-mode--insert-and-indent) (define-key map "\C-m" 'newline-and-indent) (define-key map "\C-co" 'factor-mode-visit-other-file) (define-key map "\C-c\C-o" 'factor-mode-visit-other-file) diff --git a/misc/fuel/fu.el b/misc/fuel/fu.el index ffd88bf144..e78502a6ee 100644 --- a/misc/fuel/fu.el +++ b/misc/fuel/fu.el @@ -1,6 +1,6 @@ ;;; fu.el --- Startup file for FUEL -;; Copyright (C) 2008 Jose Antonio Ortega Ruiz +;; Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz ;; See http://factorcode.org/license.txt for BSD license. ;; Author: Jose Antonio Ortega Ruiz @@ -24,6 +24,11 @@ "Minor mode showing in the minibuffer a synopsis of Factor word at point." t) +(autoload 'fuel-scaffold-vocab "fuel-scaffold.el" + "Create a new Factor vocabulary." t) + +(autoload 'fuel-scaffold-help "fuel-scaffold.el" + "Create a Factor vocabulary help file." t) ;;; fu.el ends here diff --git a/misc/fuel/fuel-eval.el b/misc/fuel/fuel-eval.el index 149e608964..543d23bd3f 100644 --- a/misc/fuel/fuel-eval.el +++ b/misc/fuel/fuel-eval.el @@ -42,7 +42,7 @@ (factor (case sexp (:rs 'fuel-eval-restartable) (:nrs 'fuel-eval-non-restartable) - (:in (fuel-syntax--current-vocab)) + (:in (or (fuel-syntax--current-vocab) "fuel")) (:usings `(:array ,@(fuel-syntax--usings))) (:get 'fuel-eval-set-result) (:end '\;) @@ -70,7 +70,7 @@ (defsubst factor--fuel-in (in) (cond ((or (eq in :in) (null in)) :in) ((eq in 'f) 'f) - ((eq in 't) "fuel-scratchpad") + ((eq in 't) "fuel") ((stringp in) in) (t (error "Invalid 'in' (%s)" in)))) diff --git a/misc/fuel/fuel-font-lock.el b/misc/fuel/fuel-font-lock.el index 45fd0758d5..b12be1eac7 100644 --- a/misc/fuel/fuel-font-lock.el +++ b/misc/fuel/fuel-font-lock.el @@ -55,6 +55,8 @@ ((comment comment "comments") (constructor type "constructors ()") (constant constant "constants and literal values") + (number constant "integers and floats") + (ratio constant "ratios") (declaration keyword "declaration words") (parsing-word keyword "parsing words") (setter-word function-name "setter words (>>foo)") @@ -80,7 +82,9 @@ (,fuel-syntax--alias-definition-regex (1 'factor-font-lock-word) (2 'factor-font-lock-word)) (,fuel-syntax--int-constant-def-regex 2 'factor-font-lock-constant) - (,fuel-syntax--number-regex . 'factor-font-lock-constant) + (,fuel-syntax--integer-regex . 'factor-font-lock-number) + (,fuel-syntax--float-regex . 'factor-font-lock-number) + (,fuel-syntax--ratio-regex . 'factor-font-lock-ratio) (,fuel-syntax--type-definition-regex 2 'factor-font-lock-type-name) (,fuel-syntax--method-definition-regex (1 'factor-font-lock-type-name) (2 'factor-font-lock-word)) @@ -103,7 +107,6 @@ (list (cons 'font-lock-syntactic-keywords fuel-syntax--syntactic-keywords)))))) - ;;; Fontify strings as Factor code: diff --git a/misc/fuel/fuel-listener.el b/misc/fuel/fuel-listener.el index d4fa5aed1f..c6835ede6b 100644 --- a/misc/fuel/fuel-listener.el +++ b/misc/fuel/fuel-listener.el @@ -102,6 +102,8 @@ buffer." (defun fuel-listener-nuke () (interactive) + (goto-char (point-max)) + (comint-kill-region comint-last-input-start (point)) (comint-redirect-cleanup) (fuel-con--setup-connection fuel-listener--buffer)) diff --git a/misc/fuel/fuel-markup.el b/misc/fuel/fuel-markup.el index 69d1de8814..9e5e1c8af2 100644 --- a/misc/fuel/fuel-markup.el +++ b/misc/fuel/fuel-markup.el @@ -373,10 +373,10 @@ (let ((heading `($heading ,(match-string-no-properties 0))) (rows)) (forward-line) - (when (looking-at "Word *Stack effect$") - (push '("Word" "Stack effect") rows) + (when (looking-at "Word *\\(Stack effect\\|Syntax\\)$") + (push (list "Word" (match-string-no-properties 1)) rows) (forward-line)) - (while (looking-at "\\(.+?\\)\\( +\\(( .*\\)\\)?$") + (while (looking-at "\\(.+?\\)\\( +\\(.+\\)\\)?$") (let ((word `($link ,(match-string-no-properties 1) ,(match-string-no-properties 1) word)) diff --git a/misc/fuel/fuel-scaffold.el b/misc/fuel/fuel-scaffold.el new file mode 100644 index 0000000000..8026371def --- /dev/null +++ b/misc/fuel/fuel-scaffold.el @@ -0,0 +1,84 @@ +;;; fuel-scaffold.el -- interaction with tools.scaffold + +;; Copyright (C) 2009 Jose Antonio Ortega Ruiz +;; See http://factorcode.org/license.txt for BSD license. + +;; Author: Jose Antonio Ortega Ruiz +;; Keywords: languages, fuel, factor +;; Start date: Sun Jan 11, 2009 18:40 + +;;; Comentary: + +;; Utilities for creating new vocabulary files and other boilerplate. +;; Mainly, an interface to Factor's tools.scaffold. + +;;; Code: + +(require 'fuel-eval) +(require 'fuel-edit) +(require 'fuel-syntax) +(require 'fuel-base) + + +;;; Customisation: + +(defgroup fuel-scaffold nil + "Options for FUEL's scaffolding." + :group 'fuel) + +(defcustom fuel-scaffold-developer-name user-full-name + "The name to be inserted as yours in scaffold templates." + :type 'string + :group 'fuel-scaffold) + + +;;; Auxiliary functions: + +(defun fuel-scaffold--vocab-roots () + (let ((cmd '(:fuel* (vocab-roots get :get) "fuel"))) + (fuel-eval--retort-result (fuel-eval--send/wait cmd)))) + + +;;; User interface: + +(defun fuel-scaffold-vocab () + "Creates a directory in the given root for a new vocabulary and +adds source, tests and authors.txt files. + +You can configure `fuel-scaffold-developer-name' (set by default to +`user-full-name') for the name to be inserted in the generated files." + (interactive) + (let* ((name (read-string "Vocab name: ")) + (root (completing-read "Vocab root: " + (fuel-scaffold--vocab-roots) + nil t "resource:")) + (cmd `(:fuel* ((,root ,name ,fuel-scaffold-developer-name) + (fuel-scaffold-vocab)) "fuel")) + (ret (fuel-eval--send/wait cmd)) + (file (fuel-eval--retort-result ret))) + (unless file + (error "Error creating vocab (%s)" (car (fuel-eval--retort-error ret)))) + (find-file file) + (goto-char (point-max)))) + +(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." + (interactive "P") + (let* ((vocab (or (and (not arg) (fuel-syntax--current-vocab)) + (fuel-edit--read-vocabulary-name nil))) + (cmd `(:fuel* (,vocab ,fuel-scaffold-developer-name fuel-scaffold-help) + "fuel")) + (ret (fuel-eval--send/wait cmd)) + (file (fuel-eval--retort-result ret))) + (unless file + (error "Error creating help file" (car (fuel-eval--retort-error ret)))) + (find-file file))) + + +(provide 'fuel-scaffold) +;;; fuel-scaffold.el ends here diff --git a/misc/fuel/fuel-syntax.el b/misc/fuel/fuel-syntax.el index 49e7788b2f..6b93787a50 100644 --- a/misc/fuel/fuel-syntax.el +++ b/misc/fuel/fuel-syntax.el @@ -44,14 +44,14 @@ (defconst fuel-syntax--parsing-words '(":" "::" ";" "<<" ">" - "ALIAS:" + "ABOUT:" "ALIAS:" "ARTICLE:" "B" "BIN:" "C:" "C-STRUCT:" "C-UNION:" "CHAR:" "CONSTANT:" "call-next-method" "DEFER:" "ERROR:" "EXCLUDE:" "f" "FORGET:" "FROM:" "GENERIC#" "GENERIC:" - "HEX:" "HOOK:" + "HELP:" "HEX:" "HOOK:" "IN:" "initial:" "INSTANCE:" "INTERSECTION:" "M:" "MACRO:" "MACRO::" "MAIN:" "MATH:" "MEMO:" "MEMO:" "METHOD:" "MIXIN:" "OCT:" @@ -63,12 +63,12 @@ "UNION:" "USE:" "USING:" "VARS:")) -(defconst fuel-syntax--bracers - '("B" "BV" "C" "CS" "H" "T" "V" "W")) - (defconst fuel-syntax--parsing-words-regex (regexp-opt fuel-syntax--parsing-words 'words)) +(defconst fuel-syntax--bracers + '("B" "BV" "C" "CS" "H" "T" "V" "W")) + (defconst fuel-syntax--brace-words-regex (format "%s{" (regexp-opt fuel-syntax--bracers t))) @@ -84,8 +84,14 @@ (defconst fuel-syntax--method-definition-regex "^M: +\\([^ ]+\\) +\\([^ ]+\\)") -(defconst fuel-syntax--number-regex - "\\(\\+\\|-\\)?\\([0-9]+\\.?[0-9]*\\|\\.[0-9]+\\)\\([eE]\\(\\+\\|-\\)?[0-9]+\\)?") +(defconst fuel-syntax--integer-regex + "\\_<-?[0-9]+\\_>") + +(defconst fuel-syntax--ratio-regex + "\\_<-?\\([0-9]+\\+\\)?[0-9]+/-?[0-9]+\\_>") + +(defconst fuel-syntax--float-regex + "\\_<-?[0-9]+\\.[0-9]*\\([eE][+-]?[0-9]+\\)?\\_>") (defconst fuel-syntax--word-definition-regex (fuel-syntax--second-word-regex @@ -142,12 +148,14 @@ fuel-syntax--declaration-words-regex)) (defconst fuel-syntax--single-liner-regex - (format "^%s" (regexp-opt '("ALIAS:" + (format "^%s" (regexp-opt '("ABOUT:" + "ARTICLE:" + "ALIAS:" "CONSTANT:" "C:" "DEFER:" "FORGET:" "GENERIC:" "GENERIC#" - "HEX:" "HOOK:" + "HELP:" "HEX:" "HOOK:" "IN:" "INSTANCE:" "MAIN:" "MATH:" "MIXIN:" "OCT:" @@ -210,8 +218,7 @@ (" \\(|\\) " (1 "(|")) (" \\(|\\)$" (1 ")")) ;; Opening brace words: - (,(format "\\_<%s\\({\\)\\_>" (regexp-opt fuel-syntax--bracers)) (1 "(}")) - ("\\_<\\({\\)\\_>" (1 "(}")) + ("\\_<\\w*\\({\\)\\_>" (1 "(}")) ("\\_<\\(}\\)\\_>" (1 "){")) ;; Parenthesis: ("\\_<\\((\\)\\_>" (1 "()")) @@ -255,7 +262,7 @@ (defsubst fuel-syntax--looking-at-emptiness () (looking-at "^[ ]*$\\|$")) -(defsubst fuel-syntax--is-eol (pos) +(defsubst fuel-syntax--is-last-char (pos) (save-excursion (goto-char (1+ pos)) (fuel-syntax--looking-at-emptiness)))