User:Joe Bogner/InlineDictionary

From J Wiki
Jump to navigation Jump to search

Purpose: Shows the J dictionary entry summary for the supplied word in the J session without opening a web browser. Can be useful to not lose the flow during the repl session.

Prequisites: This script requires the qt version of J as that's where the help lookup function comes from.

To invoke:

dict ';'

or remote_dict ';' or local_dict ';'

You can change it to use a remote dictionary by changing the binding to be remote_dict

┌───────────────┐
│; Raze  -  Link│
└───────────────┘
monad

;y assembles along a leading axis the opened elements
of the ravel of y . The fit
conjunction (;!.f) provides fill
specified by the atom f .


dyad

x;y is (<x),y if y is boxed,
and (<x),<y if y is open.


load 'regex'
require '~addons/ide/qt/help.ijs'
require '~addons/web/gethttp/gethttp.ijs'

remote_dict=: 3 : 0
url=.'http://www.jsoftware.com/help/','.htm',~ helpsel_jqtide_
doc=.gethttp_wgethttp_ url y

showdoc doc
)


local_dict=: 3 : 0
path=:(jpath '~addons/docs/help/'),'.htm',~ helpsel_jqtide_
doc=.1!:1 <path y

showdoc doc
)


showdoc=: 3 : 0
addbreaks=. ('|';LF;' ';'';'>';'>';'<';'<';'"';'"';'&';'') stringreplace ]
striphtml=.('<(.|\n)+?>';'') rxrplc ]

html=.y

NB. need text/css as a hack to workaround the title from a 302 redirect
title=.< addbreaks > (1}"1 ('type="text/css"><title>(.+)</title>' rxmatches html) rxfrom html)
htmlnolf=.(CR;'';LF;'|') stringreplace html
cases=.('bgcolor="?#eeeeee"?>(.*?)</td>' rxmatches htmlnolf) rxfrom htmlnolf


html=.striphtml each (1{"1 cases)
smoutput title

smoutput > ('monad';'dyad'),.(2 {. (addbreaks each html))

)

dict=:local_dict