Go Help

Go Doc V2


The Go Documentation Chapter showed a basic External Tool for displaying documentation.   This is a much more complete script that does the following.

  1. Handles file and directory names with spaces (not a recommended practice).
  2. Can Display Documentation in a Pop up Window, a Popup Terminal or in Gedit New Tab or Bottom Pane.


  1. Make sure that you have Zenity installed.  See the end of the Plugins Chapter.
  2. If you have a general ‘temp’ directory, set it as described in the introductory chapter.
  3. Open Gedit and Go to Tools>Manage External Tools.
  4. Choose Go Pkg Doc, or create a new tool.
  5. Copy and Paste the script below into the code panel, overwriting the existing code.
  6. Make the other settings as documented in ‘Tool Settings’ in the script below.
  7. Set the OUTPUT switch below ‘Tool Settings’ in the script below.


# Go Package Doc - Takes highlighted text and displays its documentation
#                  NOTE: if no text is selected this script is never called!
#         Manual - www.gohelp.wordpress.com - 'Gedit - An IDE for Go'
#   *Tool Settings: Save = Nothing, Input = Current Word, OutPut = see below
#           Set Tool Output to:
#OUTPUT=1   Bottom Pane or Create New Document - real time,    Display
#OUTPUT=2   Bottom Pane or Create New Document - save to file, Display
#OUTPUT=3   Bottom Pane - for error display    - save to file, Popup Terminal
#OUTPUT=4   Bottom Pane - for error display    - save to file, Popup Window
OUTPUT=4   # Set OUTPUT Switch


if   ! ( test -z "$MyTemp" ) # if MyTemp exists in environment
    TMPDIR="${DIR}"  # else set TMPDIR to current document directory

WORD=$(xargs) # Get Word at cursor from document

godoc "${WORD}" > "${TMPDIR}"/GoDocFile.tmp # run 'godoc' with current word

case $OUTPUT in
    1) godoc "${WORD}"
    2) godoc "${WORD}" > "${TMPDIR}"/GoDocFile.tmp
       cat "${TMPDIR}"/GoDocFile.tmp
    3) godoc "${WORD}" > "${TMPDIR}"/GoDocFile.tmp
       TermCmd="less \"${TMPDIR}\""/"GoDocFile.tmp"
       gnome-terminal --command "${TermCmd}" -t "Go Documentation ${TermCmd}" &
    4) nLines=`wc -l "${TMPDIR}"/GoDocFile.tmp|awk '{print $1}'`
       if [ "${nLines}" -gt 28 ]
       zHeight=$(( nLines * 25 ))

       longLine=`wc -L "${TMPDIR}"/GoDocFile.tmp|awk '{print $1}'`
       if [ "${longLine}" -gt 80 ]
       zWidth=$(( longLine * 9 ))

       zenity --text-info \
           --height=${zHeight} \
           --width=${zWidth} \
           --title="Go Documents" \
           --filename="${TMPDIR}"/GoDocFile.tmp \ &

    *) echo "Please Set Package Documentation OUTPUT option"

sleep 2		# Make sure new shell has displayed before deleting tmp file
rm "${TMPDIR}"/GoDocFile.tmp

Create a free website or blog at WordPress.com.

%d bloggers like this: