Skip to main content
1 of 6
Simon Woods
  • 85.9k
  • 8
  • 183
  • 332

I have been using this. It's mostly Leonid's code from the stackoverflow question you linked to, but it uses FullDefinition instead of DownValues. Symbol names are printed without any context, but the full symbol name is put into a Tooltip so you can always find out what context a symbol is in.

Spelunk[symbol_Symbol] := With[{sym = symbol}, Internal`InheritedBlock[{sym}, Unprotect[sym]; ClearAttributes[sym, ReadProtected]; Module[{boxes = ToBoxes@FullDefinition@sym}, boxes = boxes /. InterpretationBox[a_, b___] :> a; boxes = boxes /. s_String?(StringMatchQ[#, __ ~~ "`" ~~ __] &) :> First@StringCases[s, a : (__ ~~ "`" ~~ b__) :> TooltipBox[b, a]]; boxes = boxes /. {" "} -> {"\n-----------\n"}; CellPrint[ Cell[BoxData[#], "Input", Background -> RGBColor[1, 0.95, 0.9]]] &[ boxes /. f_[left___, "\[RuleDelayed]", right___] :> f[left, "\[RuleDelayed]", "\n", right] //. {RowBox[{left___, ";", next : Except["\n"], right___}] :> RowBox[{left, ";", "\n", "\t", next, right}], RowBox[{sc : ("Block" | "Module" | "With"), "[", RowBox[{vars_, ",", body_}], "]"}] :> RowBox[{sc, "[", RowBox[{vars, ",", "\n\t", body}], "]"}]}]]]] 
Simon Woods
  • 85.9k
  • 8
  • 183
  • 332