home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 May / maximum-cd-2010-05.iso / DiscContents / AutoHotkey104805_Install.exe / Extras / Scripts / IntelliSense.ahk
Encoding:
Text File  |  2007-03-27  |  5.3 KB  |  189 lines

  1. ; IntelliSense -- by Rajat (requires XP/2k/NT)
  2. ; http://www.autohotkey.com
  3. ; This script watches while you edit an AutoHotkey script.  When it sees you
  4. ; type a command followed by a comma or space, it displays that command's
  5. ; parameter list to guide you.  In addition, you can press Ctrl+F1 (or
  6. ; another hotkey of your choice) to display that command's page in the help
  7. ; file. To dismiss the parameter list, press Escape or Enter.
  8.  
  9. ; Requires v1.0.41+
  10.  
  11. ; CONFIGURATION SECTION: Customize the script with the following variables.
  12.  
  13. ; The hotkey below is pressed to display the current command's page in the
  14. ; help file:
  15. I_HelpHotkey = ^F1
  16.  
  17. ; The string below must exist somewhere in the active window's title for
  18. ; IntelliSense to be in effect while you're typing.  Make it blank to have
  19. ; IntelliSense operate in all windows.  Make it Pad to have it operate in
  20. ; editors such as Metapad, Notepad, and Textpad.  Make it .ahk to have it
  21. ; operate only when a .ahk file is open in Notepad, Metapad, etc.
  22. I_Editor = pad
  23.  
  24. ; If you wish to have a different icon for this script to distinguish it from
  25. ; other scripts in the tray, provide the filename below (leave blank to have
  26. ; no icon). For example: E:\stuff\Pics\icons\GeoIcons\Information.ico
  27. I_Icon = 
  28.  
  29. ; END OF CONFIGURATION SECTION (do not make changes below this point unless
  30. ; you want to change the basic functionality of the script).
  31.  
  32. SetKeyDelay, 0
  33. #SingleInstance
  34.  
  35. if I_HelpHotkey <>
  36.     Hotkey, %I_HelpHotkey%, I_HelpHotkey
  37.  
  38. ; Change tray icon (if one was specified in the configuration section above):
  39. if I_Icon <>
  40.     IfExist, %I_Icon%
  41.         Menu, Tray, Icon, %I_Icon%
  42.  
  43. ; Determine AutoHotkey's location:
  44. RegRead, ahk_dir, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotkey, InstallDir
  45. if ErrorLevel  ; Not found, so look for it in some other common locations.
  46. {
  47.     if A_AhkPath
  48.         SplitPath, A_AhkPath,, ahk_dir
  49.     else IfExist ..\..\AutoHotkey.chm
  50.         ahk_dir = ..\..
  51.     else IfExist %A_ProgramFiles%\AutoHotkey\AutoHotkey.chm
  52.         ahk_dir = %A_ProgramFiles%\AutoHotkey
  53.     else
  54.     {
  55.         MsgBox Could not find the AutoHotkey folder.
  56.         ExitApp
  57.     }
  58. }
  59.  
  60. ahk_help_file = %ahk_dir%\AutoHotkey.chm
  61.  
  62. ; Read command syntaxes:
  63. Loop, Read, %ahk_dir%\Extras\Editors\Syntax\Commands.txt
  64. {
  65.     I_FullCmd = %A_LoopReadLine%
  66.  
  67.     ; Directives have a first space instead of a first comma.
  68.     ; So use whichever comes first as the end of the command name:
  69.     StringGetPos, I_cPos, I_FullCmd, `,
  70.     StringGetPos, I_sPos, I_FullCmd, %A_Space%
  71.     if (I_cPos = -1 or (I_cPos > I_sPos and I_sPos <> -1))
  72.         I_EndPos := I_sPos
  73.     else
  74.         I_EndPos := I_cPos
  75.  
  76.     if I_EndPos <> -1
  77.         StringLeft, I_CurrCmd, I_FullCmd, %I_EndPos%
  78.     else  ; This is a directive/command with no parameters.
  79.         I_CurrCmd = %A_LoopReadLine%
  80.     
  81.     StringReplace, I_CurrCmd, I_CurrCmd, [,, All
  82.     StringReplace, I_CurrCmd, I_CurrCmd, %A_Space%,, All
  83.     StringReplace, I_FullCmd, I_FullCmd, ``n, `n, All
  84.     StringReplace, I_FullCmd, I_FullCmd, ``t, `t, All
  85.     
  86.     ; Make arrays of command names and full cmd syntaxes:
  87.     I_Cmd%A_Index% = %I_CurrCmd%
  88.     I_FullCmd%A_Index% = %I_FullCmd%
  89. }
  90.  
  91. ; Use the Input command to watch for commands that the user types:
  92. Loop
  93. {
  94.     ; Editor window check:
  95.     WinGetTitle, ActiveTitle, A
  96.     IfNotInString, ActiveTitle, %I_Editor%
  97.     {
  98.         ToolTip
  99.         Sleep, 500
  100.         Continue
  101.     }
  102.     
  103.     ; Get all keys till endkey:
  104.     Input, I_Word, V, {enter}{escape}{space}`,
  105.     I_EndKey = %ErrorLevel%
  106.     
  107.     ; Tooltip is hidden in these cases:
  108.     if I_EndKey in EndKey:Enter,EndKey:Escape
  109.     {
  110.         ToolTip
  111.         Continue
  112.     }
  113.  
  114.     ; Editor window check again!
  115.     WinGetActiveTitle, ActiveTitle
  116.     IfNotInString, ActiveTitle, %I_Editor%
  117.     {
  118.         ToolTip
  119.         Continue
  120.     }
  121.  
  122.     ; Compensate for any indentation that is present:
  123.     StringReplace, I_Word, I_Word, %A_Space%,, All
  124.     StringReplace, I_Word, I_Word, %A_Tab%,, All
  125.     if I_Word =
  126.         Continue
  127.     
  128.     ; Check for commented line:
  129.     StringLeft, I_Check, I_Word, 1
  130.     if (I_Check = ";" or I_Word = "If")  ; "If" seems a little too annoying to show tooltip for.
  131.         Continue
  132.  
  133.     ; Match word with command:
  134.     I_Index =
  135.     Loop
  136.     {
  137.         ; It helps performance to resolve dynamic variables only once.
  138.         ; In addition, the value put into I_ThisCmd is also used by the
  139.         ; I_HelpHotkey subroutine:
  140.         I_ThisCmd := I_Cmd%A_Index%
  141.         if I_ThisCmd =
  142.             break
  143.         if (I_Word = I_ThisCmd)
  144.         {
  145.             I_Index := A_Index
  146.             I_HelpOn = %I_ThisCmd%
  147.             break
  148.         }
  149.     }
  150.     
  151.     ; If no match then resume watching user input:
  152.     if I_Index =
  153.         Continue
  154.     
  155.     ; Show matched command to guide the user:
  156.     I_ThisFullCmd := I_FullCmd%I_Index%
  157.     ToolTip, %I_ThisFullCmd%, A_CaretX, A_CaretY + 20
  158. }
  159.  
  160.  
  161.  
  162. I_HelpHotkey:
  163. WinGetTitle, ActiveTitle, A
  164. IfNotInString, ActiveTitle, %I_Editor%, Return
  165.  
  166. ToolTip  ; Turn off syntax helper since there is no need for it now.
  167.  
  168. SetTitleMatchMode, 1  ; In case it's 3. This setting is in effect only for this thread.
  169. IfWinNotExist, AutoHotkey Help
  170. {
  171.     IfNotExist, %ahk_help_file%
  172.     {
  173.         MsgBox, Could not find the help file: %ahk_help_file%.
  174.         return
  175.     }
  176.     Run, %ahk_help_file%
  177.     WinWait, AutoHotkey Help
  178. }
  179.  
  180. if I_ThisCmd =  ; Instead, use what was most recently typed.
  181.     I_ThisCmd := I_Word
  182.  
  183. ; The above has set the "last found" window which we use below:
  184. WinActivate
  185. WinWaitActive
  186. StringReplace, I_ThisCmd, I_ThisCmd, #, {#}  ; Replace leading #, if any.
  187. Send, !n{home}+{end}%I_HelpOn%{enter}
  188. return
  189.