FUEL: fuel.xref subvocabulary factored out.

db4
Jose A. Ortega Ruiz 2009-01-22 16:11:44 +01:00
parent 4a5d8f5344
commit d3cbb62851
5 changed files with 93 additions and 83 deletions

View File

@ -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
<PRIVATE
: fuel-normalize-loc ( seq -- path line )
[ dup length 0 > [ 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
<PRIVATE
: fuel-callers-xref ( word -- ) callers-xref fuel-eval-set-result ;
: fuel-word>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
<PRIVATE
: fuel-filter-prefix ( seq prefix -- seq )
[ drop-prefix nip length 0 = ] curry filter prune ; inline
: (fuel-get-vocabs) ( -- seq )
all-vocabs-seq [ vocab-name ] map ; inline
MEMO: (fuel-vocab-words) ( name -- seq )
>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 ;

View File

@ -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 ;

View File

@ -0,0 +1 @@
Jose Antonio Ortega Ruiz

View File

@ -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
<PRIVATE
: normalize-loc ( seq -- path line )
[ dup length 0 > [ 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 ;

View File

@ -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)