| 
									
										
										
										
											2010-02-09 04:21:05 -05:00
										 |  |  | ! Copyright (C) 2008, 2010 Slava Pestov. | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							|  |  |  | USING: accessors arrays assocs fry help.markup help.topics io | 
					
						
							|  |  |  | kernel make math math.parser namespaces sequences sorting | 
					
						
							| 
									
										
										
										
											2009-05-04 07:44:17 -04:00
										 |  |  | summary tools.completion vocabs.hierarchy help.vocabs | 
					
						
							| 
									
										
										
										
											2011-09-08 21:18:47 -04:00
										 |  |  | vocabs words unicode.case help unicode.categories | 
					
						
							|  |  |  | combinators locals ;
 | 
					
						
							| 
									
										
										
										
											2009-03-24 05:11:08 -04:00
										 |  |  | IN: help.apropos | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $completions ( seq -- )
 | 
					
						
							|  |  |  |     dup [ word? ] all? [ words-table ] [ | 
					
						
							|  |  |  |         dup [ vocab-spec? ] all? [ | 
					
						
							|  |  |  |             $vocabs | 
					
						
							|  |  |  |         ] [ | 
					
						
							| 
									
										
										
										
											2009-02-17 15:26:01 -05:00
										 |  |  |             [ <$pretty-link> 1array ] map $table | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  |         ] if
 | 
					
						
							|  |  |  |     ] if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-08 21:18:47 -04:00
										 |  |  | SYMBOLS: word-result vocabulary-result article-result ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : category>title ( category -- name )
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         { word-result [ "Words" ] } | 
					
						
							|  |  |  |         { vocabulary-result [ "Vocabularies" ] } | 
					
						
							|  |  |  |         { article-result [ "Help articles" ] } | 
					
						
							|  |  |  |     } case ;
 | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  | : category>name ( category -- name )
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         { word-result [ "word" ] } | 
					
						
							|  |  |  |         { vocabulary-result [ "vocabulary" ] } | 
					
						
							|  |  |  |         { article-result [ "help article" ] } | 
					
						
							|  |  |  |     } case ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TUPLE: more-completions seq search category ;
 | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-08 01:02:47 -05:00
										 |  |  | CONSTANT: max-completions 5
 | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-09 04:21:05 -05:00
										 |  |  | M: more-completions valid-article? drop t ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-08 01:02:47 -05:00
										 |  |  | M: more-completions article-title | 
					
						
							| 
									
										
										
										
											2011-09-08 21:18:47 -04:00
										 |  |  |     [ | 
					
						
							|  |  |  |         "All " % | 
					
						
							|  |  |  |         [ seq>> length # " " % ] | 
					
						
							|  |  |  |         [ category>> category>name % ] | 
					
						
							|  |  |  |         [ " results for “" % search>> % "”" % ] tri     | 
					
						
							|  |  |  |     ] "" make ;
 | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  | M: more-completions article-content | 
					
						
							| 
									
										
										
										
											2010-08-13 22:32:49 -04:00
										 |  |  |     seq>> [ second >lower ] sort-with keys \ $completions prefix ;
 | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-08 21:18:47 -04:00
										 |  |  | :: (apropos) ( search completions category -- element )
 | 
					
						
							|  |  |  |     completions [ | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             { $heading search } , | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  |             [ max-completions short head keys \ $completions prefix , ] | 
					
						
							| 
									
										
										
										
											2011-09-08 21:18:47 -04:00
										 |  |  |             [ | 
					
						
							|  |  |  |                 length max-completions >
 | 
					
						
							|  |  |  |                 [ { $link T{ more-completions f completions search category } } , ] when
 | 
					
						
							|  |  |  |             ] bi
 | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  |         ] unless-empty
 | 
					
						
							|  |  |  |     ] { } make ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-13 22:32:49 -04:00
										 |  |  | : articles-matching ( str -- seq )
 | 
					
						
							|  |  |  |     articles get
 | 
					
						
							|  |  |  |     [ [ >link ] [ title>> ] bi* ] { } assoc-map-as
 | 
					
						
							|  |  |  |     completions ;
 | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $apropos ( str -- )
 | 
					
						
							|  |  |  |     first
 | 
					
						
							| 
									
										
										
										
											2011-09-08 21:18:47 -04:00
										 |  |  |     [ dup words-matching word-result (apropos) ] | 
					
						
							|  |  |  |     [ dup vocabs-matching vocabulary-result (apropos) ] | 
					
						
							|  |  |  |     [ dup articles-matching article-result (apropos) ] | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  |     tri 3array print-element ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-21 01:38:41 -04:00
										 |  |  | TUPLE: apropos-search text ;
 | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-21 01:38:41 -04:00
										 |  |  | C: <apropos-search> apropos-search | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-21 01:38:41 -04:00
										 |  |  | M: apropos-search valid-article? drop t ;
 | 
					
						
							| 
									
										
										
										
											2010-02-09 04:21:05 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-21 01:38:41 -04:00
										 |  |  | M: apropos-search article-title | 
					
						
							|  |  |  |     text>> "Search results for “" "”" surround ;
 | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-21 01:38:41 -04:00
										 |  |  | M: apropos-search article-content | 
					
						
							|  |  |  |     text>> 1array \ $apropos prefix ;
 | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-21 01:38:41 -04:00
										 |  |  | M: apropos-search >link ;
 | 
					
						
							| 
									
										
										
										
											2009-03-24 05:11:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-21 01:38:41 -04:00
										 |  |  | INSTANCE: apropos-search topic | 
					
						
							| 
									
										
										
										
											2009-03-24 05:11:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  | : apropos ( str -- )
 | 
					
						
							| 
									
										
										
										
											2012-06-21 01:38:41 -04:00
										 |  |  |     [ blank? ] trim <apropos-search> print-topic ;
 |