#!/usr/bin/env wish-f # # usage: vxref file # # view an xref compiled with mxref # # (additionally, see mxref-tags, and mkid-compatibility mode in help text) if $tk_version>=4.0 { option add *Menubutton*padX 1 option add *Menubutton*padY 1 option add *Button*padX 1 option add *Button*padY 1 } set idxf [lindex $argv 0] frame .panel button .panel.quit -text quit -command {destroy .} button .panel.help -text help -command { .display.reftext delete 1.0 end .display.reftext insert 1.0 { To start out, X-select a token on any X window, and click the "idx" button. Index lines for that token will be inserted in the left window pane. Move the text cursor to any of the index lines in the left pane, and click on the "ref" button, and the text where reference occurs will be displayed in the right window pane. Simply right-click on an index line is an abbreviation for moving the cursor and clicking on "ref". Right-clicking in the right pane is an appreviation for double-clicking to select the current token, and then clicking the "idx" button. The "clr" button empties the index pane. The "tcl" button executes the current X selection as a tcl script. You can launch your favorite editor, positioned to the file and line displayed in the "ref" pane, by defining the "launch-edit" and "launch-view" procedures in your $HOME/.env-vxrefrc file. For example, to launch vi: proc launch-edit {file line} { exec xterm -e vi -c $line $file & } proc launch-view {file line} { exec xterm -e view -c $line $file & } or emacs (via the emacs client): proc launch-edit {file line} { exec emacsclient +$line $file & } You can also plug in your favorite indexing scheme. For example, the mkid/lid/gid/aid family of indexers can be plugged in via proc lookup-xref {word idxfile} { set p [format {{gsub(":"," ",$1);print "%s ",$1;}} $word] return [exec gid -f$idxfile $word | nawk $p]\n\n } Just have the lookup produce what vxref expects, which is (token, filename, line number) tupples, one tupple per line, separated by blanks. Produce the index file via (eg) "mkid -fidx *.c". In general, any customization can be added to the .vxrefrc file. For example, to select a small, 10-point font for the two primary text display windows: .display.idxtext configure -font *courier*medium*r*normal*100* .display.reftext configure -font *courier*medium*r*normal*100* In general, any wish tcl commands can be used in the rc file. The widget names initially available for customization are widget name widget type ----------- ----------- .panel frame .panel.quit button .panel.help button .panel.tcl button .panel.clr button .panel.idxshrink button .panel.idx button .panel.idxgrow button .panel.ref button .panel.le button .panel.lv button .panel.fname text .display frame .display.idxscroll scrollbar .display.idxtext text .display.refscroll scrollbar .display.reftext text }} button .panel.tcl -text tcl -command {eval [selection get]} button .panel.clr -text clr -command {.display.idxtext delete 1.0 end} button .panel.all -text all -command { .display.idxtext delete 1.0 end .display.idxtext insert 1.0 [exec cat $idxf]\n } button .panel.idx -text idx -command { set w [selection get] .display.idxtext insert 1.0 [lookup-xref $w $idxf] .display.idxtext yview 0 } button .panel.ref -text ref -command { set r [.display.idxtext get "insert linestart" "insert lineend"] set f [lindex $r 1] set l [expr [lindex $r 2]-1] .display.reftext delete 1.0 end .display.reftext insert 1.0 [exec grep -n {^} $f]\n .display.reftext yview $l .panel.fname delete 1.0 end .panel.fname insert 1.0 $f } button .panel.le -text edit -command { launch-edit [.panel.fname get 1.0 end] \ [expr int([.display.reftext index @1,1])] } button .panel.lv -text view -command { launch-view [.panel.fname get 1.0 end] \ [expr int([.display.reftext index @1,1])] } proc lookup-xref {word idxfile} { return [exec look $word $idxfile]\n\n } proc launch-view {file line} { error "view command not defined" } proc launch-edit {file line} { error "edit command not defined" } text .panel.fname -height 1 -width 60 -borderwidth 4 -relief ridge button .panel.idxshrink -text < -command { .display.idxtext configure -width \ [expr [lindex [.display.idxtext configure -width] 4]-10] } button .panel.idxgrow -text > -command { .display.idxtext configure -width \ [expr [lindex [.display.idxtext configure -width] 4]+10] } pack .panel.quit -side left pack .panel.help -side left pack .panel.tcl -side left pack .panel.clr -side left pack .panel.idxshrink -side left pack .panel.idx -side left pack .panel.idxgrow -side left pack .panel.ref -side left pack .panel.le -side left pack .panel.lv -side left pack .panel.fname -side left frame .display scrollbar .display.idxscroll -command {.display.idxtext yview} text .display.idxtext -width 40 -height 40 \ -yscroll {.display.idxscroll set} bind .display.idxtext { .display.idxtext mark set insert @%x,%y .panel.ref invoke } scrollbar .display.refscroll -command {.display.reftext yview} text .display.reftext -width 80 -height 40 \ -yscroll {.display.refscroll set} pack .display.idxscroll -side left -fill y pack .display.idxtext -side left pack .display.refscroll -side left -fill y pack .display.reftext -side left bind .display.reftext { .display.reftext tag remove sel 1.0 end .display.reftext tag add sel {@%x,%y wordstart} {@%x,%y wordend} .panel.idx invoke } pack .panel -side top -anchor w pack .display -side top wm minsize . 100 100 catch {source $env(HOME)/.vxrefrc}