Re: Indexing Euphoria HTML Documentation for context sensitive help

new topic     » goto parent     » topic index » view thread      » older message » newer message

Well, I finally came up with the idea of searching the key_index.html file for search word "hits" and extracting the path to the related *.html file and -hopefully- the best specific article(s). Some command "key words" are re-used in different libraries, and some commands are referenced, or discussed in many different articles, so I use a "maxfile" integer setting to limit the number of *.html "articles" will be opened.

This is rough, even by my standards. Comments, suggestions for improvements will be welcomed.

 
-- 
-- EuHelp.e 
-- 
-- include this file just before the get_escape(boolean help) routine in ed.ex: 
 
 
 
 
 
include std/filesys.e 
include std/text.e 
include std/console.e 
include std/wildcard.e 
 
-- constant BROWSER = "midori --log-file=midori.log  " 
-- constant BROWSER = "dillo  " 
-- constant BROWSER = "google-chrome  " 
constant BROWSER  = "netsurf " 
constant EUDIR = getenv("EUDIR") 
 
constant ONLINE_INDEX_MATCHES_LOCAL = 0  -- FALSE 
                                         -- set to 1, if you have verified that your 
                                         -- local *.html index numbers match those online 
 
-- integer = 0 = offline, use local html files (default),  
-- integer = 1 = online, use openeuphoria.org files. 
 
 
-------------------------------------------------------------------------------- 
-------------------------------------------------------------------------------- 
public procedure EuHelp( sequence word, integer online)  
sequence pattern, HelpFile = EUDIR & SLASH   -- HelpFile starts as: 
			    & "docs" & SLASH  
				& "html" & SLASH  
				    & "key_index.html" -- key_index.html 
 
object line 
integer start_slice, end_slice, wcmatch, hfn, underscore 
integer cont = 1, files = 0,  
	maxfiles = 4  -- maximum number of *.html help pages to display. 
 
hfn = open(HelpFile, "r")  -- opens key_index.html 
while cont do 
    line = gets(hfn) 
    if hfn = -1 then 
	puts(1, "Couldn't open key_index.html\n") 
	abort(1) 
    end if 
    if atom(line) then 
	-- end of file 
	exit 
    end if 
     
    files = 0 
    word = lower(word) 
    line = lower(line) 
    pattern = "*std*"  & word & "\">*" 
    pattern = lower(pattern) 
    wcmatch =  is_match(pattern, line)  
    if wcmatch then 
	start_slice = match("std", line) 
	files += 1 
	pattern = "_" & word & "\">" 
        underscore = match(pattern, line) 
        if underscore then                                                                                     
            pattern = "\">"                                                                                    
            end_slice = match(pattern, line)                                                                   
            end_slice = end_slice -1                                                                           
            HelpFile = line[start_slice..end_slice]  -- HelpFile now = help "article"                          
            files += 1              	 
	 
	    if online then 
--                              online index's need to match local html file indexes.  
--                              Maybe when 4.1 is officially released: 
                if ONLINE_INDEX_MATCHES_LOCAL then 
                    HelpFile = "http://openeuphoria.org/docs/" & HelpFile 
		else 
                    HelpFile = "openeuphoria.org/search/results.wc?manual=1\\&s="&word 
                end if 
 
                ifdef LINUX  then 
                    HelpFile = BROWSER & HelpFile                     
                end ifdef               	        
	    else 
		-- offline, using local std*.html files 
		ifdef LINUX then 
		    HelpFile = BROWSER & "file://" & EUDIR & SLASH  
					    & "docs" & SLASH  
						    & "html" & SLASH & HelpFile 
		elsifdef WINDOWS then                
		    HelpFile = EUDIR & SLASH  
					& "docs" & SLASH  
         					& "html"  & SLASH  & HelpFile	     
		end ifdef 
           end if 
        system(HelpFile, 0) 
       end if 
    end if 
   
     
    if files = maxfiles then 
       cont = 0 
       close(hfn) 
    end if 
end while 
 
end procedure 
-------------------------------------------------------------------------------- 
-------------------------------------------------------------------------------- 
 
 
-- call EuHelp(search_word) in ed.ex's help routine:--------------- 
-- if answer[1] = 'y' then 
				 
-- instead of this line: ----> system(self_command & SLASH & "html" & SLASH & "index.html")    
                    EuHelp(search_word, 0)  -- call the EuHelp function, or: 
                    EuHelp(search_word, 1)  -- to use euphoria.org files online.			 
            else 
		normal_video() 
		end if 
	     end if 
 
	elsif command[1] = 'l' then 
------------------------------------------------------------------------ 
-- export sequence search_word should be defined in syncolor.e 
-- I placed it befor the integer color declarations: 
export sequence search_word = " "  --<-------- insert  -- edx 
integer NORMAL_COLOR, 
------------------------------------------------------------------------ 
-- then, in the function SyntaxColor, insert the following line 
 
	                else seg_flush(NORMAL_COLOR) 
			end if 
			search_word = word --<---------- insert ----- ****** 
			seg_end = last 
 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu