cl ref: referencing documentation for symbols in Common Lisp
the script⌗
#!/bin/sh
directory="/home/zest/setup/readables/cl-doc"
allSym="$directory/Front/X_AllSym.htm"
browser="netsurf-gtk3"
data="$(awk '/<LI>/ {
ok=$0;
gsub(/<[^>]*>/, "", ok);
match($0, /HREF="[^"]*"/);
httrAttr=substr($0, RSTART, RLENGTH);
gsub(/HREF=|"/, "", httrAttr);
printf "%s %s\n",ok,httrAttr;
}' "$allSym")"
answer="$(echo "$data" | awk '{ print $1 }' | dmenu)"
if [ ! -z "$answer" ]; then
href="$(echo "$data" | grep -m 1 "$answer")"
if [ ! -z "$href" ]; then
html="file://$directory/Front/$(echo "$href" | awk '{ print $2 }')"
echo "$html"
"$browser" "$html"
fi
fi
what the script does⌗
If you setup the directory
and browser
to your respective values and you have dmenu
installed, you should have a menu that shows you all symbols in Common Lisp. Be it global variable, function keys, macros, functions or other symbols.
After selecting a value, it should open that value in your browser.
how does it work?⌗
It reads the X_AllSym.htm
, sees the list items in that page and does some regular expressions to turn something like:
<LI><A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&allow-other-keys</B></A>
<LI><A REL=DEFINITION HREF="../Body/03_da.htm#AMaux"><B>&aux</B></A>
<LI><A REL=DEFINITION HREF="../Body/03_dd.htm#AMbody"><B>&body</B></A>
into
&allow-other-keys ../Body/03_da.htm#AMallow-other-keys
&aux ../Body/03_da.htm#AMaux
&body ../Body/03_dd.htm#AMbody
After that data is transformed, awk
prints the first column in each line. Columns are seperated by spaces. Essentially, awk
just takes the first value in each line seperated by a space. dmenu
shows the menu to the user and returns the selected symbol or an empty value.
Afterwards, the script uses grep to find the first line that contains the symbol. When it is found, awk
prints the second-column which is the href value that points to the documentation page. Lastly, the script opens the browser pointing at that file and voila, you have your page.
why?⌗
I thought it was fun. It turned out to be fun. It took about 20 minutes. I usually just open cl-doc
and that’s it.