1. Universal Context Sensitive Help utility program for Geany and other editors
- Posted by K_D_R Jan 26, 2013
- 1512 views
-- -- EuHelp.ex -- -- EUDIR must be set. -- make this file executable! - or not, see below: -- install it in Geany's Preferences/Tools/Commands/Context action box: -- [ eui /home/ken/edx-1.0/EuHelp.ex %s] -- Geany makes it easy to select the file -- Now all you have to do is assign your favorite key/key combination to the action -- There is NOTHING TO IT! include EuHelp.e integer online = 0 -- default, use local *.html files, "1" selects openeuphoria.orgs online files sequence word object cl = command_line() if length(cl)<3 then puts(1,"EuHELP: Enter search word: ") word=gets(0) puts(1,"\n") if atom(word) then word="" else word=word[1..length(word)-1] end if if equal(word,"") then puts(1, "No word given, aborting...") end if else word=cl[3] end if EuHelp(word, online) <eucode> <eucode> -- -- EuHelp.e -- 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 online = 0 -- "0" for local std*.html files, "1" for openeuphoria.org files. public procedure EuHelp( sequence word, integer online) sequence pattern sequence HelpFile = EUDIR & SLASH -- HelpFile starts as: & "docs" & SLASH & "html" & SLASH & "key_index.html" -- key_index.html object line integer start_slice, end_slice, underscore, wcmatch, hfn integer cont = 1, files = 0, maxfiles = 4 -- maximum number of *.html help pages to display. hfn = open(HelpFile, "r") 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) 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 ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
2. Re: Universal Context Sensitive Help utility program for Geany and other editors
- Posted by SDPringle Jan 28, 2013
- 1383 views
Now, I plan to make a ticket to distribute a 'search.dat' with the next release of EUPHORIA. WIth this file, a EUPHORIA program will be able to determine exactly where a documented constant or routine definition is *in the standard library* only. The search.dat wont help you with say euGrid routines. However, this can compliment your approach you are using here.
3. Re: Universal Context Sensitive Help utility program for Geany and other editors
- Posted by K_D_R Jan 28, 2013
- 1388 views
Now, I plan to make a ticket to distribute a 'search.dat' with the next release of EUPHORIA. WIth this file, a EUPHORIA program will be able to determine exactly where a documented constant or routine definition is *in the standard library* only. The search.dat wont help you with say euGrid routines. However, this can compliment your approach you are using here.
Wonderful! I look forward to seeing that program/file.
I have decided to post a snapshot of my heavily modified version of ed.ex which includes slightly improved versions of EuHelp.ex and EuHelp.edx as well as a keyword file with 1400 words extracted from key_index.html. I'll say more about it in a new topic.
Ken
4. Re: Universal Context Sensitive Help utility program for Geany and other editors
- Posted by K_D_R Jan 28, 2013
- 1370 views
Here are the upgraded EuHelp files. I added an option to "install" a *.html help file for a 3rd party library which can be opened, if no match for the search word is found in key_index.html. The 3rd party *.html file should be placed in /EUDIR/docs/html/
-- -- EuHelp.e -- -- usage: EuHelp(sequence word, integer online) -- if "word" is found in one of Euphoria's Standard Libraries, -- a specific article from a /EUDIR/doc/html/std*.hml file will -- be loaded into your browser. Multiple articles can be loaded, -- and the number to be loaded can be designated by the user for -- disambiguation. -- /* If you are using a 3rd party Euphoria Library for which you -- have a *.html help file you can configure EuHelp to load that -- help file into your browser, if your search word is not found -- in one of Euphoria's Standard Libraries. See comments below */ include std/filesys.e include std/text.e include std/console.e include std/wildcard.e -- Linux users must specify a browser: -- constant BROWSER = "midori --log-file=midori.log " -- constant BROWSER = "dillo " -- constant BROWSER = "google-chrome " -- constant BROWSER = "firefox " 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 --------------------------------------------------------------------------- -----------< install an alternate *.html file if desired >----------------- integer AltHelpFile = 0 -- set to one if you have installed/copied an -- alternate *.html help file in /EUDIR/docs/html/ sequence ALT_HELPFILE = "index.html" --< name your helpfile ALT_HELPFILE = EUDIR & SLASH & "docs" & SLASH & "html" & SLASH & ALT_HELPFILE ifdef LINUX then ALT_HELPFILE = BROWSER & "file://" & ALT_HELPFILE end ifdef ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ -- integer online = 0 -- "0" for local std*.html files, "1" for openeuphoria.org files. public procedure EuHelp( sequence word, integer online) sequence pattern sequence HelpFile = EUDIR & SLASH -- HelpFile starts as: & "docs" & SLASH & "html" & SLASH & "key_index.html" -- key_index.html object line integer start_slice, end_slice, underscore, wcmatch, hfn integer cont = 1, files = 0, maxfiles = 4 -- maximum number of *.html help pages to display. hfn = open(HelpFile, "r") 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 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) 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 -- Openeuphoria.org 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 -- edit:---------------------------------------------------------------------------------------- if files = 1 then system(HelpFile, 0) elsif files > 1 then cont = prompt_number("\nEnter \"1\" to read next article, or \"0\" to quit. 0/1 :: ", {0,1}) if cont then system(HelpFile, 0) else -- quit exit end if end if -- end edit ----------------------------------------------------------------------------------- end if end if if files = maxfiles then cont = 0 close(hfn) end if end while if files = 0 then close(hfn) if AltHelpFile then system(ALT_HELPFILE, 0) else printf(1, "\n\n\tNo match for <%s> in Euphoria's Standard Libraries\n\t", {word}) puts(1, "Press any key to return...") end if end if close(hfn) abort(1) end procedure ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
-- -- EuHelp.ex -- -- EUDIR must be set. -- Make this file executable! - or not, see below: -- install it in Geany's Preferences/Tools/Commands/Context action box: -- [ eui /home/ken/edx-1.0/EuHelp.ex %s] -- Geany makes it easy to select the file -- Now all you have to do is assign your favorite key/key combination to the action -- There is NOTHING TO IT! -- If you translate_to_c-code/compile EuHelp.ex, you can place EuHelp -- in /EUDIR/bin/ and then Geany installation is simply: -- Context action [EuHelp %s] include EuHelp.e integer online = 0 -- default, use local *.html files, -- "1" selects openeuphoria.orgs online files sequence word object cl = command_line() if length(cl)<3 then puts(1,"\n\tEuHELP: Enter search word: ") word=gets(0) puts(1,"\n") if atom(word) then word="" else word=word[1..length(word)-1] end if if equal(word,"") then puts(1, "\n\t Usage: eui EuHelp.ex <search_word>\n") puts(1, "\n\t Press any key...\n") abort(1) end if else word=cl[3] end if EuHelp(word, online)
5. Re: Universal Context Sensitive Help utility program for Geany and other editors
- Posted by SDPringle Jan 31, 2013
- 1280 views
On Linux there is a way of specifying a preferred browser. Failing that, you can use locate_file, to find out which browsers are installed on the system.
object BROWSER = 0 browsers = { "midori", "dillo", "google-chrome", "firefox", "opera" } for browser_i = length(browsers) to 1 by -1 do sequence temp = locate_file(browsers[browser_i], getenv("PATH")) if not equal(temp, browsers[browser_i]) then BROWSER = temp & " " exit end if end for
Some bad news : As of 4.0, EUDIR does not get set. But you can find eui on Windows via: locate_file( "eui.exe", getenv("PATH") ) and then go up one directory to get where EUDIR is.
On debian the documents go to /usr/share/doc/euphoria/html.
[ Edited to remove stray creole code ]
6. Re: Universal Context Sensitive Help utility program for Geany and other editors
- Posted by K_D_R Feb 01, 2013
- 1238 views
Thanks for the tricks and tips. I'll update EuHelp.
I think it is a mistake to abandon EUDIR. Perhaps a cross platform eudir function should be added utilizing the "locate_file( "eui.exe", getenv("PATH") ) and then go up one directory to get where EUDIR is" method - this would take some of the pain out of updating old code which utilizes EUDIR.
On Linux there is a way of specifying a preferred browser. Failing that, you can use locate_file, to find out which browsers are installed on the system.
object BROWSER = 0 browsers = { "midori", "dillo", "google-chrome", "firefox", "opera" } for browser_i = length(browsers) to 1 by -1 do sequence temp = locate_file(browsers[browser_i], getenv("PATH")) if not equal(temp, browsers[browser_i]) then BROWSER = temp & " " exit end if end for
Some bad news : As of 4.0, EUDIR does not get set. But you can find eui on Windows via: locate_file( "eui.exe", getenv("PATH") ) and then go up one directory to get where EUDIR is.
On debian the documents go to /usr/share/doc/euphoria/html.
[ Edited to remove stray creole code ]
7. Re: Universal Context Sensitive Help utility program for Geany and other editors
- Posted by K_D_R Feb 01, 2013
- 1260 views
Edited - eudir() corrected. Now the HelpFile is opened correctly.
-- -- EuHelp.e edited February 1, 2013 to include two routines -- suggested by SDPRINGLE -- -- usage: EuHelp(sequence word, integer online) -- if "word" is found in one of Euphoria's Standard Libraries, -- a specific article from a /EUDIR/doc/html/std*.hml file will -- be loaded into your browser. Multiple articles can be loaded, -- and the number to be loaded can be designated by the user for -- disambiguation. -- If you are using a 3rd party library for which you -- have a *.html help file you can configure EuHelp to load that -- help file into your browser, if your search word is not found -- in one of Euphoria's Standard Libraries. See comments below: include std/filesys.e include std/text.e include std/console.e include std/wildcard.e -- Linux users can specify a browser -- constant BROWSER = "google-chrome " -- constant BROWSER = "firefox " -- constant BROWSER = "netsurf " -- constant BROWSER = "midori --log-file=midori.log " -- constant BROWSER = "dillo " -- or use this routine provided by SDPRINGLE to select a browser from "PATH": object BROWSER = 0 browsers = { "midori", "dillo", "google-chrome", "firefox", "opera", "netsurf" } for browser_i = length(browsers) to 1 by -1 do sequence temp = locate_file(browsers[browser_i], getenv("PATH")) if not equal(temp, browsers[browser_i]) then BROWSER = temp & " " exit end if end for -- get EUDIR from path to "eui/eui.ex", thanks to SDPRINGLE: sequence eui ifdef WINDOWS then eui = "eui.exe" elsedef eui = "eui" end ifdef function eudir() sequence eudirectory eudirectory = locate_file( eui, getenv("PATH") ) eudirectory = eudirectory[1..length(eudirectory)-length(eui)-4] return eudirectory end function constant EUDIR = eudir() --------------------------------------------------------------------------- --------------------------------------------------------------------------- -----------< install an alternate *.html file if desired >----------------- integer AltHelpFile = 0 -- set to one if you have installed/coclose(hfn) pied an -- alternate *.html help file in /EUDIR/docs/html/ sequence ALT_HELPFILE = "index.html" --< name your helpfile ALT_HELPFILE = EUDIR & SLASH & "docs" & SLASH & "html" & SLASH & ALT_HELPFILE ifdef LINUX then ALT_HELPFILE = BROWSER & "file://" & ALT_HELPFILE end ifdef constant ONLINE_INDEX_MATCHES_LOCAL = 0 -- FALSE -- set to 1, if you have verified that your -- local *.html index numbers match those online ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ -- integer online = 0 -- "0" for local std*.html files, "1" for openeuphoria.org files. public procedure EuHelp( sequence word, integer online) sequence pattern sequence HelpFile = EUDIR & SLASH -- HelpFile starts as: & "docs" & SLASH & "html" & SLASH & "key_index.html" -- key_index.html close(hfn) object line integer start_slice, end_slice, underscore, wcmatch, hfn integer cont = 1, files = 0, maxfiles = 4 -- maximum number of *.html help pages to display. hfn = open(HelpFile, "r") 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 close(hfn) exit end if 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) 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 -- Openeuphoria.org 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 if files = 0 then if AltHelpFile then system(ALT_HELPFILE, 0) else printf(1, "\n\n\tNo match for <%s> in Euphoria's Standard Libraries\n\t", {word}) puts(1, "Press any key to return...") end if end if close(hfn) abort(1) end procedure ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------