From d3cbb6285108f8ceaea1e16660441f9793955324 Mon Sep 17 00:00:00 2001 From: "Jose A. Ortega Ruiz" Date: Thu, 22 Jan 2009 16:11:44 +0100 Subject: [PATCH] FUEL: fuel.xref subvocabulary factored out. --- extra/fuel/fuel.factor | 106 +++++++++--------------------------- extra/fuel/help/help.factor | 3 + extra/fuel/xref/authors.txt | 1 + extra/fuel/xref/xref.factor | 62 +++++++++++++++++++++ misc/fuel/fuel-edit.el | 4 +- 5 files changed, 93 insertions(+), 83 deletions(-) create mode 100644 extra/fuel/xref/authors.txt create mode 100644 extra/fuel/xref/xref.factor diff --git a/extra/fuel/fuel.factor b/extra/fuel/fuel.factor index 6efc1a9fef..d4bff7678d 100644 --- a/extra/fuel/fuel.factor +++ b/extra/fuel/fuel.factor @@ -1,11 +1,9 @@ ! Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays assocs compiler.units definitions fuel.eval -fuel.help fuel.remote help.markup help.topics io.pathnames kernel math -math.order memoize namespaces parser sequences sets sorting -tools.crossref tools.scaffold tools.vocabs vocabs vocabs.loader -vocabs.parser words ; +USING: assocs compiler.units fuel.eval fuel.help fuel.remote fuel.xref +help.topics io.pathnames kernel namespaces parser sequences +tools.scaffold vocabs.loader ; IN: fuel @@ -51,92 +49,36 @@ PRIVATE> ! Edit locations - [ first (normalize-path) ] [ drop f ] if ] - [ dup length 1 > [ second ] [ drop 1 ] if ] bi ; - -: fuel-get-loc ( object -- ) - fuel-normalize-loc 2array fuel-eval-set-result ; - -PRIVATE> - -: fuel-get-edit-location ( word -- ) where fuel-get-loc ; inline +: fuel-get-word-location ( word -- ) + word-location fuel-eval-set-result ; : fuel-get-vocab-location ( vocab -- ) - >vocab-link fuel-get-edit-location ; inline + vocab-location fuel-eval-set-result ; -: fuel-get-doc-location ( word -- ) props>> "help-loc" swap at fuel-get-loc ; +: fuel-get-doc-location ( word -- ) + doc-location fuel-eval-set-result ; -: fuel-get-article-location ( name -- ) article loc>> fuel-get-loc ; +: fuel-get-article-location ( name -- ) + article-location fuel-eval-set-result ; + +: fuel-get-vocabs ( -- ) + get-vocabs fuel-eval-set-result ; + +: fuel-get-vocabs/prefix ( prefix -- ) + get-vocabs/prefix fuel-eval-set-result ; + +: fuel-get-words ( prefix names -- ) + get-vocabs-words/prefix fuel-eval-set-result ; ! Cross-references -xref ( word -- xref ) - [ name>> ] [ vocabulary>> ] [ where fuel-normalize-loc ] tri 4array ; +: fuel-callees-xref ( word -- ) callees-xref fuel-eval-set-result ; -: fuel-sort-xrefs ( seq -- seq' ) - [ [ first ] dip first <=> ] sort ; inline +: fuel-apropos-xref ( str -- ) apropos-xref fuel-eval-set-result ; -: fuel-format-xrefs ( seq -- seq' ) - [ word? ] filter [ fuel-word>xref ] map ; inline - -: (fuel-index) ( seq -- seq ) - [ [ >link name>> ] [ article-title ] bi 2array \ $subsection prefix ] map ; - -PRIVATE> - -: fuel-callers-xref ( word -- ) - usage fuel-format-xrefs fuel-sort-xrefs fuel-eval-set-result ; inline - -: fuel-callees-xref ( word -- ) - uses fuel-format-xrefs fuel-sort-xrefs fuel-eval-set-result ; inline - -: fuel-apropos-xref ( str -- ) - words-matching fuel-format-xrefs fuel-eval-set-result ; inline - -: fuel-vocab-xref ( vocab -- ) - words fuel-format-xrefs fuel-eval-set-result ; inline - -: fuel-index ( quot: ( -- seq ) -- ) - call (fuel-index) fuel-eval-set-result ; inline - -! Completion support - -vocab-link words [ name>> ] map ; - -: fuel-current-words ( -- seq ) - use get [ keys ] map concat ; inline - -: fuel-vocabs-words ( names -- seq ) - prune [ (fuel-vocab-words) ] map concat ; inline - -: (fuel-get-words) ( prefix names/f -- seq ) - [ fuel-vocabs-words ] [ fuel-current-words ] if* natural-sort - swap fuel-filter-prefix ; - -PRIVATE> - -: fuel-get-vocabs ( -- ) - (fuel-get-vocabs) fuel-eval-set-result ; - -: fuel-get-vocabs/prefix ( prefix -- ) - (fuel-get-vocabs) swap fuel-filter-prefix fuel-eval-set-result ; - -: fuel-get-words ( prefix names -- ) - (fuel-get-words) fuel-eval-set-result ; +: fuel-vocab-xref ( vocab -- ) vocab-xref fuel-eval-set-result ; ! Help support @@ -156,6 +98,8 @@ PRIVATE> : fuel-vocab-summary ( name -- ) (fuel-vocab-summary) fuel-eval-set-result ; +: fuel-index ( quot -- ) call format-index fuel-eval-set-result ; + : fuel-get-vocabs/tag ( tag -- ) (fuel-get-vocabs/tag) fuel-eval-set-result ; diff --git a/extra/fuel/help/help.factor b/extra/fuel/help/help.factor index ff7239ac8f..e70327bd35 100644 --- a/extra/fuel/help/help.factor +++ b/extra/fuel/help/help.factor @@ -109,3 +109,6 @@ MEMO: (fuel-get-vocabs/author) ( author -- element ) MEMO: (fuel-get-vocabs/tag) ( tag -- element ) [ "Vocabularies tagged " prepend \ $heading swap 2array ] [ tagged fuel-vocab-list ] bi 2array ; + +: format-index ( seq -- seq ) + [ [ >link name>> ] [ article-title ] bi 2array \ $subsection prefix ] map ; diff --git a/extra/fuel/xref/authors.txt b/extra/fuel/xref/authors.txt new file mode 100644 index 0000000000..48f802a3cd --- /dev/null +++ b/extra/fuel/xref/authors.txt @@ -0,0 +1 @@ +Jose Antonio Ortega Ruiz \ No newline at end of file diff --git a/extra/fuel/xref/xref.factor b/extra/fuel/xref/xref.factor new file mode 100644 index 0000000000..56a2ac5803 --- /dev/null +++ b/extra/fuel/xref/xref.factor @@ -0,0 +1,62 @@ +! Copyright (C) 2009 Jose Antonio Ortega Ruiz. +! See http://factorcode.org/license.txt for BSD license. + +USING: accessors arrays assocs definitions help.topics io.pathnames +kernel math math.order memoize namespaces sequences sets sorting +tools.crossref tools.vocabs vocabs vocabs.parser words ; + +IN: fuel.xref + + [ first (normalize-path) ] [ drop f ] if ] + [ dup length 1 > [ second ] [ drop 1 ] if ] bi ; + +: get-loc ( object -- loc ) normalize-loc 2array ; + +: word>xref ( word -- xref ) + [ name>> ] [ vocabulary>> ] [ where normalize-loc ] tri 4array ; + +: sort-xrefs ( seq -- seq' ) + [ [ first ] dip first <=> ] sort ; inline + +: format-xrefs ( seq -- seq' ) + [ word? ] filter [ word>xref ] map ; inline + +: filter-prefix ( seq prefix -- seq ) + [ drop-prefix nip length 0 = ] curry filter prune ; inline + +MEMO: (vocab-words) ( name -- seq ) + >vocab-link words [ name>> ] map ; + +: current-words ( -- seq ) + use get [ keys ] map concat ; inline + +: vocabs-words ( names -- seq ) + prune [ (vocab-words) ] map concat ; inline + +PRIVATE> + +: callers-xref ( word -- seq ) usage format-xrefs sort-xrefs ; + +: callees-xref ( word -- seq ) uses format-xrefs sort-xrefs ; + +: apropos-xref ( str -- seq ) words-matching format-xrefs ; + +: vocab-xref ( vocab -- seq ) words format-xrefs ; + +: word-location ( word -- loc ) where get-loc ; + +: vocab-location ( vocab -- loc ) >vocab-link where get-loc ; + +: doc-location ( word -- loc ) props>> "help-loc" swap at get-loc ; + +: article-location ( name -- loc ) article loc>> get-loc ; + +: get-vocabs ( -- seq ) all-vocabs-seq [ vocab-name ] map ; + +: get-vocabs/prefix ( prefix -- seq ) get-vocabs swap filter-prefix ; + +: get-vocabs-words/prefix ( prefix names/f -- seq ) + [ vocabs-words ] [ current-words ] if* natural-sort swap filter-prefix ; diff --git a/misc/fuel/fuel-edit.el b/misc/fuel/fuel-edit.el index 484fed66cd..0037c6718a 100644 --- a/misc/fuel/fuel-edit.el +++ b/misc/fuel/fuel-edit.el @@ -93,7 +93,7 @@ offered." nil fuel-edit--word-history arg)) - (cmd `(:fuel* ((:quote ,word) fuel-get-edit-location)))) + (cmd `(:fuel* ((:quote ,word) fuel-get-word-location)))) (fuel-edit--try-edit (fuel-eval--send/wait cmd)))) (defun fuel-edit-word-at-point (&optional arg) @@ -102,7 +102,7 @@ With prefix, asks for the word to edit." (interactive "P") (let* ((word (or (and (not arg) (fuel-syntax-symbol-at-point)) (fuel-completion--read-word "Edit word: "))) - (cmd `(:fuel* ((:quote ,word) fuel-get-edit-location))) + (cmd `(:fuel* ((:quote ,word) fuel-get-word-location))) (marker (and (not arg) (point-marker)))) (if (and (not arg) (fuel-edit--looking-at-vocab)) (fuel-edit-vocabulary nil word)