]> gitweb.factorcode.org Git - factor.git/commitdiff
FUEL: fallback to the all-words algorithm when search doesnt work
authorBjörn Lindqvist <bjourne@gmail.com>
Fri, 18 Apr 2014 00:37:56 +0000 (02:37 +0200)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 18 Apr 2014 15:43:11 +0000 (08:43 -0700)
It's to hard to figure out the correct "in" and "usings" values for
fuel-eval-in-context when *fuel help* is looking at articles. Instead
of trying, fallback on the less precise word lookup algorith and
accept that it sometimes will lead you wrong.

extra/fuel/help/help.factor

index c461a39b6222cf75e6a1d8a8e99ff9cf94bc61f2..0083d1e456da43d64d558ac6028c145a5168675f 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2009 Jose Antonio Ortega Ruiz.
 ! See http://factorcode.org/license.txt for BSD license.
 
-USING: accessors arrays assocs combinators fuel.eval help help.crossref
-help.markup help.topics io io.streams.string kernel make namespaces
-parser prettyprint sequences summary help.vocabs
+USING: accessors arrays assocs combinators combinators.short-circuit fry
+fuel.eval help help.crossref help.markup help.topics io io.streams.string
+kernel make namespaces parser prettyprint sequences summary help.vocabs
 vocabs vocabs.loader vocabs.hierarchy vocabs.metadata vocabs.parser words see
 listener sets ;
 FROM: vocabs.hierarchy => child-vocabs ;
@@ -11,6 +11,11 @@ IN: fuel.help
 
 <PRIVATE
 
+! Prefer to use search which takes the execution context into
+! account. If that fails, fall back on a search of all words.
+: fuel-find-word ( name -- word/f )
+    { [ search ] [ '[ name>> _ = ] all-words swap find nip ] } 1|| ;
+
 : fuel-value-str ( word -- str )
     [ pprint-short ] with-string-writer ; inline
 
@@ -88,16 +93,18 @@ SYMBOL: describe-words
 PRIVATE>
 
 : (fuel-word-help) ( name -- elem )
-    search [ [ auto-use? on (fuel-word-element) ] with-scope ] [ f ] if* ;
+    fuel-find-word [
+        [ auto-use? on (fuel-word-element) ] with-scope
+    ] [ f ] if* ;
 
 : (fuel-word-synopsis) ( word usings -- str/f )
     [
         [ lookup-vocab ] filter interactive-vocabs [ append ] change
-        search [ synopsis ] [ f ] if*
+        fuel-find-word [ synopsis ] [ f ] if*
     ] with-scope ;
 
 : (fuel-word-def) ( name -- str )
-    search [ [ def>> pprint ] with-string-writer ] [ f ] if* ; inline
+    fuel-find-word [ [ def>> pprint ] with-string-writer ] [ f ] if* ; inline
 
 : (fuel-vocab-summary) ( name -- str ) >vocab-link summary ; inline