In Using Understand with an external editor - SlickEdit I explained how to hook up Understand to run with SlickEdit. As a follow up, here are the commands to setup the same Understand menu inside of EMACS, Visual Studio, and Vi. Do let me know if I made any mistakes here since I'm not an expert on these editors.
EMACS
Add the following lisp to your .emacs file to open the Understand right click menu when C-c u is pressed (thanks for the correction Guillaume):
Note: this assumes the understand executable is in your path
(defun understand-word-at-point ()
"Run understand menu for the word at point."
(interactive)
(setq understand-command
(concat
"understand -existing -contextmenu " (buffer-file-name)
"-text "(current-word)" -line "
(number-to-string (count-lines (point-min) (point)))" -col " (number-to-string (current-column))
) )
(shell-command understand-command)
)
(global-set-key "\C-cu" 'understand-word-at-point)
Visual Studio
Step 1: Add Understand to Visual Studio's External Tools
- On the Tools menu, click External Tools
- Click Add
- Type "&Understand Menu" in the Title box
- Type "C:\Program Files\STI\bin\pc-win32\understand.exe" in the Command box
- Type "-existing -contextmenu $(TargetPath) -line $(CurLine) -col $(CurCol) -name $(CurText) in the Arguments box
- Click OK
- On the Tools menu, Click Options
- Expand the Environment Folder and select Keyboard
- Type "Tools.ExternalCommand" in the box labeled "Show commands containing"
- Select the ExternalCommand associated with the "&Understand Menu" External Tool. If "&Understand Menu" was 8th on the list (default) then select Tools.ExternalCommand8
- Click the box labeled "Press shortcut key(s)". Type in a keyboard combination such as Ctrl+U or Ctrl+`
- Click Assign
- Click Ok
Vi
Add the following to your vi startup file -.vimrc, _vimrc, etc. Note: this assumes the understand executable is in your path:
Linux/Unix:(courtesy of Devin)
:command! UMenu silent: exe "!understand -existing -contextmenu %:p -line " line('.') " -col " col('.') " -text <cword> &" | redraw!
map <C-u> :UMenu<CR>
Windows: (thanks for the help Ilguiz):
command UMenu silent: exe join(['!understand -existing -contextmenu "$(cygpath -w "%:p")" -line ', line('.'), ' -col ', col('.'), ' -text ', '<cword>', ' &']) | redraw!
map <C-u> :UMenu<CR>
Should the last line include a key to be bound such as <C-U>?
Probably a good idea. I've not done much .vimrc modification but I've modified it so I think it's correct. Let me know if it's not, and thanks for pointing it out.
KG
Perhaps, it makes sense to add -col and -text parameters as well. I could get to the "View Information" item of the context menu.
I ran understand against the proper UDB file, then launched vi manually from command line rather than from Understand.
I had to add this to my vimrc:
command UMenu silent: exe join(['!understand -existing -contextmenu "$(cygpath -w "%:p")" -line ', line('.'), ' -col ', col('.'), ' -text ', '<cword>', ' &']) | redraw!
map <C-u> :UMenu<CR>
Thanks for the tip.
Your right - I've updated my example to reflect yours instead. Thanks for keeping me honest :)