Tip: Understand Context menu in EMACS, Visual Studio and Vi
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
Step 2: Add a keyboard shortcut to Visual Studio
- 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>
August 29th, 2008 at 9:30 am
Should the last line include a key to be bound such as <C-U>?
August 29th, 2008 at 9:54 am
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
August 29th, 2008 at 10:27 am
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.
August 29th, 2008 at 10:55 am
Your right – I’ve updated my example to reflect yours instead. Thanks for keeping me honest
July 16th, 2010 at 4:53 pm
Ultraedit (http://www.ultraedit.com/) is in heavy use here. Adding the Understand RightClick menus would get wide useage. Anybody working that connection??
July 20th, 2010 at 12:22 am
I haven’t used ultraedit, but it looks like a powerful tool. I looked around on their website and found these instructions for generating a user tool:
http://www.ultraedit.com/support/tutorials_power_tips/ultraedit/user_and_project_tools.html
Other variables for the custom tool were available in the manual so the full command would be something like:
understand -existing -contextmenu "%P" -line %line% -col %col%I hope this helps.
KevinG
November 19th, 2010 at 11:38 am
I found that for Visual Studio 2005 I had to enter the following:
In the Arguments text box in the External Tools dialog window:
-existing -contextmenu $(ItemPath) -line $(CurLine) -col $(CurCol) -text $(CurText)