Tip: Understand Context menu in EMACS, Visual Studio and Vi

| | Comments (4) | TrackBacks (0)

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>

0 TrackBacks

Listed below are links to blogs that reference this entry: Tip: Understand Context menu in EMACS, Visual Studio and Vi.

TrackBack URL for this entry: http://scitools.com/blog/mt/mt-tb.cgi/94

4 Comments

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 :)

Leave a comment

About this Entry

This page contains a single entry by KevinG published on August 13, 2008 3:14 PM.

Understand 2.0 Build Notes (b458) was the previous entry in this blog.

Understand 2.0 Build Notes (b459) is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.