Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

IntelliSense+simple INPLACE autoComplete for PARTIAL words


  • Please log in to reply
10 replies to this topic
wOxxOm
  • Members
  • 371 posts
  • Last active: Feb 20 2015 12:10 PM
  • Joined: 09 Feb 2006
This IntelliSense autoComplete behaves similar to visualBasic/Delphi autocomplete wherever in string you press your assigned key (Ctrl-Space by default) there you will have tooltip help concerning CURRENT word BEGINNING
NB. 1.0.42+ - due to use #ifWinActive hotkey assignment

1. you don't even have to type whole word to look-up autocomplete!!!!!
2. In case there'll be no info on beginning of current word, then info will be shown for the first word on line - typically command name
3. if more than one match found then first 20 matches will be displayed
4. info is shown from all syntax files, not only commands.txt, so you will see autocompletes for keywords,keys,functions,variables
5. if only one match found then word under cursor will be completed inplace to full name regardless of position in string
6. also Ctrl-Shift-Space to show info about first word ("command" usually)
7. You may choose what command to autoComplete from a drop-down menu. First word of command will be autocomplete inplace. if you hold SHIFT and choose (by mouse/Enter key) drop-down auto-suggestion item even with multiline example then this block will be pasted in editor preserving current indent. Text caret is moved on next line after command, not after end of block as in other version of intellisense
8. ahkHelpLookup is provided. Modded version from forum - recognises command inline with open block "{"

;specify Editor window
#ifWinActive ahk_class EmEditorMainFrame3
ToolTipActive:=0
auEditorWin="ahk_class EmEditorMainFrame3"
^Space::AutoComplete()
^+Space::AutoComplete(1) ; first word help (command)
; uncomment next line to enable AutoHotKey help file lookup on Win-Space
;#Space::ahkHelpLookup()
#ifWinActive


AutoComplete(subCommand=0)                ;;
{  global tooltipActive
   static ahkCmds,ahkVars,ahkKeywords,ahkKeys,ahkFuncs

   timeOut=10000

   if !ahkCmds
   {  splitPath,A_AHKpath,,ahkDir
      fileRead,ahkCmds,%ahkDir%\Extras\Editors\Syntax\Commands.txt
      fileRead,ahkVars,%ahkDir%\Extras\Editors\Syntax\Variables.txt
      fileRead,ahkKeywords,%ahkDir%\Extras\Editors\Syntax\Keywords.txt
         sort,ahkKeywords
      fileRead,ahkKeys,%ahkDir%\Extras\Editors\Syntax\Keys.txt
         sort,ahkKeys
      fileRead,ahkFuncs,%ahkDir%\Extras\Editors\Syntax\Functions.txt
      ahkCmds=`r`n%ahkCmds%`r`n
      ahkVars=`r`n%ahkVars%`r`n
      ahkKeywords=`r`n%ahkKeywords%`r`n
      ahkKeys=`r`n%ahkKeys%`r`n
      ahkFuncs=`r`n%ahkFuncs%`r`n
   }

   userX:=A_CaretX
   userY:=A_CaretY
   oldClip:=Clipboard
   oldKeyDelay:=A_KeyDelay
   setKeyDelay,0
   autoTrim,on

   send,+{Home}^c
   sleep,100
   lineToLeft=%Clipboard%
   cmd:=lineToLeft

   loop,parse,cmd,%A_Space%`t()`%=:`, ,`{
      s:=A_LoopField
   cmd=%s%

   send {End}+{Home}^c
   sleep,100
   fullLine=%clipboard%
   LineIndent:=clipboard
   ifNotEqual,fullLine,,stringLeft,LineIndent,LineIndent,% inStr(LineIndent,fullLine)-1

   stringLeft,s,fullLine,1
   if (s="{")
   {  stringTrimLeft,fullLine,fullLine,1
      fullLine=%fullLine%
      stringTrimLeft,lineToLeft,lineToLeft,1
      lineToLeft=%lineToLeft%
   }

   if (subCommand=1) or !cmd
      or !inStr(ahkCmds . ahkVars . ahkKeywords . ahkKeys . ahkFuncs,"`n" cmd)
      loop,parse,fullLine,%A_Space%`t`(`=`:`, ,`{
      {  cmd:=A_LoopField
         break
      }

   setKeyDelay,%oldKeyDelay%
   Clipboard:=oldClip
   CoordMode,mouse,relative
   mousegetPos,mX,mY
   mouseClick,,%userX%,%userY%,,0
   mouseMove,%mX%,%mY%,0

   if !cmd or !inStr(ahkCmds . ahkVars . ahkKeywords . ahkKeys . ahkFuncs,"`n" cmd)
      return

   Menu, Tray, Icon, %windir%\system32\shell32.dll,24
   matchCmds:=AutoCompleteSearchArea(ahkCmds,cmd)
            . AutoCompleteSearchArea(ahkVars,cmd,":=")
            . AutoCompleteSearchArea(ahkKeywords,cmd)
            . AutoCompleteSearchArea(ahkKeys,cmd,"{","}")
            . AutoCompleteSearchArea(ahkFuncs,cmd)
   stringReplace,matchCmds,matchCmds,`r,`r,all UseErrorLevel
   matches#:=errorlevel
   if (matches#>20)
   {  i=0
      loop,parse,matchCmds,`n,`r
         if (A_Index>20)
            break
         else
            i+=strLen(A_LoopField)+1
      stringLeft,matchCmds,matchCmds,%i% ; inStr(matchCmds,"`r`n" s "`r`n")
      matchCmds=%matchCmds%`n--------------------
   }
   stringTrimRight,matchCmds,matchCmds,1

   if (matches#<=1)
      if (strLen(matchCmds)-strLen(autoCompleteRestOfCmd(matchCmds
                  ,cmd,fullLine,lineToLeft,userX,userY,timeOut))<3)
         return

   Menu ClickMenu,Add
   Menu ClickMenu,DeleteAll
   loop,parse,matchCmds,`n`r,`r
      if (a_loopField)
         Menu ClickMenu,Add, %a_LoopField%, CClick
   TooltipActive:=1
   Menu ClickMenu,Show,%userX%,% userY+16
   return

keyHelp:
   ahkHelpLookup(cmd)
CClick:
   Menu, Tray, Icon, %A_AhkPath%
   oldClip:=clipboard
   if (getKeyState("Shift","P"))
   {  stringReplace,s,A_ThisMenuItem,``t,%A_tab%,all
      stringReplace,s,s,``n,% "`n" lineIndent,all useErrorLevel
      lines#:=errorlevel
      clipboard:=s
      send ^v
      if (InStr(s,"{"))
         lines#-=1
      ifNotEqual,lines#,0,send % "{Up " lines#-1 "}"
      sleep,100
      clipboard:=oldClip
   }
   else if (matches#>1)
      autoCompleteRestOfCmd(A_ThisMenuItem,cmd,fullLine,lineToLeft,userX,userY,timeOut,1)
   Menu ClickMenu,DeleteAll
   return

TimerTooltipRemove:
   TooltipActive:=0
   tooltip,,,,20
   setTimer,TimerTooltipRemove,OFF
   Menu, Tray, Icon, %A_AhkPath%
   return
}

AutoCompleteSearchArea(byref area, cmd, prefix="",postfix="")        ;;
{
   i:=inStr(area,"`n" cmd)
   if !i
      return
   j:=inStr(area,"`n" cmd,0,0)
   j:=inStr(area,"`n",0,j+1)
   stringMid,found,area,%i%,% j-i
   stringTrimLeft,found,found,1 ; remove `r`n
   if (prefix) or (postfix)
   {  stringReplace,found,found,`r`n,%postfix%`r`n%prefix%,all
      found=%prefix%%found%
   }
   return found
}

autoCompleteRestOfCmd(syntax,cmd,fullLine,lineToLeft,x,y,timeOut,ForceReplace=0)    ;;
{  global ToolTipActive
   stringLeft,s,syntax,2
   ifEqual,s,:=,stringTrimLeft,syntax,syntax,2
   stringLeft,s,syntax,1
   ifEqual,s,{,stringTrimLeft,syntax,syntax,1
   loop,parse,syntax,%A_Space%`,(
   {  cmdFull:=A_LoopField
      break
   }

   if (cmd<>cmdFull)
   {  StringTrimLeft,s,cmdFull,% strLen(cmd)
      stringTrimLeft,fullLine,fullLine,% strLen(lineToLeft)
      stringLeft,ss,fullLine,1
      wordSymbols:="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ#_@$?[]0123456789"
      userWord=0
      if (ss)
         ifInString,wordSymbols,%ss%
            userWord=1
      if (ForceReplace)
      {  if (userWord)
         {  s:=cmdFull
            mouseClick,,% x-5,%y%,2,0
         }
         clipboard:=s
         send ^v
         sleep,100
         clipboard:=oldClip
      }
      else
         if !FullLine or dllCall("CompareString",int,0x400,int,1
                  ,str,s,int,strlen(s),str,fullLine,int,strlen(s))<>2
         {  clipboard:=s
            send ^v
            sleep,100
            clipboard:=oldClip
         }
   }
   CoordMode, ToolTip, Relative
   ToolTip, %syntax%, %x%, % y+16,20
   setTimer,TimerTooltipRemove,%timeOut%
   TooltipActive:=1
   return cmdFull
}

ahkHelpLookup(c_cmd="")               ;;
{  if !c_cmd
   {
      SetWinDelay 10
      SetKeyDelay 0
      AutoTrim, On
      C_ClipboardPrev:=clipboardAll
      clipboard=
      Send, ^c
      ClipWait, 0.1
      if ErrorLevel <> 0
      {  Send, {home}+{end}^c
         ClipWait, 0.2
         if (ErrorLevel)
         {  clipboard:=C_ClipboardPrev
            return
         }
      }
      C_Cmd=%clipboard%  ; This will trim leading and trailing tabs & spaces.
      clipboard:=C_ClipboardPrev
      stringLeft,s,c_cmd,1
      ifEqual,s,{,stringMid,c_cmd,c_cmd,2,200
      c_cmd=%c_cmd%
      Loop, parse, C_Cmd, %A_Space%`,  ; The first space or comma is the end of the command.
      {  C_Cmd=%A_LoopField%
         break ; i.e. we only need one interation.
      }
   }
   IfWinNotExist, AutoHotkey Help
   {  ; Use non-abbreviated root key to support older versions of AHK:
      RegRead, ahk_dir, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotkey, InstallDir
      if ErrorLevel <> 0
         ahk_dir=%ProgramFiles%\AutoHotkey
      ahk_help_file=%ahk_dir%\AutoHotkey.chm
      IfNotExist, %ahk_help_file%
      {  traytip,,Could not find the help file: %ahk_help_file%.
         return
      }
      Run, %ahk_help_file%
      WinWait, AutoHotkey Help
   }
   ; The above has set the "last found" window which we use below:
   WinActivate
   WinWaitActive
   StringReplace, C_Cmd, C_Cmd, #, {#}
   send, !n{home}+{end}%C_Cmd%{enter}
   return
}


Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Looks nice, but
- The icon file is missing.
- The path to the txt files miss "Editors", which is in the default location. It should be %ahkDir%\Extras\Editors\Syntax\Commands.txt, etc.
- I got the list of matches, but could not figure out how to select one and insert into the text. Could you give a bit more instructions?

wOxxOm
  • Members
  • 371 posts
  • Last active: Feb 20 2015 12:10 PM
  • Joined: 09 Feb 2006

Looks nice, but
- The icon file is missing.

I edited script and reposted it, so icon file now is taken from shell32.dll in system32 windows directory #24 (help icon).

- The path to the txt files miss "Editors", which is in the default location. It should be %ahkDir%\Extras\Editors\Syntax\Commands.txt, etc.

Done. I moved that directory accidentally

- I got the list of matches, but could not figure out how to select one and insert into the text. Could you give a bit more instructions?

I didn't implemented it, though I had an idea to do this through "gui"-window with selecting (as in mature editors is done). Maybe I will finish it today. Any other ideas how to choose line? Hot-binding {up}/{Down} keys maybe?

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
You could run a Loop with the matches, and do "Menu ClickMenu, Add, %match%, CClick" (first with "Menu ClickMenu, DeleteAll"). It builds a new pop-up menu. Instead of the ToolTip, use "Menu ClickMenu, Show" in the ^Space hotkey subroutine. It will pop up a list at the mouse position, similar to a ToolTip, but it is clickable, and the Up/Down arrows select items. If you prefer, use "Menu ClickMenu, Show, %A_CaretX%, %A_CaretY%", to pop up the menu at the text insertion point, instead.

Define the menu action in the CClick: subroutine as "Send %A_ThisMenuItem%", and "Return". A mouse-click on an item, or Up/Down arrows and Enter inserts the text, Esc closes the menu automatically, you don't have to write code.

wOxxOm
  • Members
  • 371 posts
  • Last active: Feb 20 2015 12:10 PM
  • Joined: 09 Feb 2006
Done. First post is updated with new code. Some useful capabilities added

robiandi
  • Guests
  • Last active:
  • Joined: --
I get Error: Call to nonexistent function
within the function ahkHelpLookup(c_cmd="")
on line
c_cmd:=iif(strLeft(c_cmd,1)="{",strmid(c_cmd,2),c_cmd)
??

wOxxOm
  • Members
  • 371 posts
  • Last active: Feb 20 2015 12:10 PM
  • Joined: 09 Feb 2006

I get Error: Call to nonexistent function
within the function ahkHelpLookup(c_cmd="")
on line
c_cmd:=iif(strLeft(c_cmd,1)="{",strmid(c_cmd,2),c_cmd)
??


Sorry. instead of this line, I should write
      stringLeft,s,c_cmd,1
      ifEqual,s,{,stringMid,c_cmd,c_cmd,2,200

First post is updated. thanx

robiandi
  • Guests
  • Last active:
  • Joined: --
@wOxxOm: many thanks, it works now.

AHKnow*
  • Guests
  • Last active:
  • Joined: --
Titan should really add this to his AutoHotkey Studio ( http://www.autohotke...opic.php?t=2459 ). I like using an AutoHotkey editor than you can edit the code in AutoHotkey.

Veovis
  • Members
  • 389 posts
  • Last active: Mar 17 2009 12:24 AM
  • Joined: 13 Feb 2006
:D Excellent! :D I might implement it in my AHKPad. (When i have the time of course...Doing High School and College at the same time sucks...) :cry:
Posted Image
"Power can be given overnight, but responsibility must be taught. Long years go into its making."

webber
  • Members
  • 129 posts
  • Last active: Aug 13 2011 06:45 PM
  • Joined: 25 Aug 2005
how can I activate this script to work with Textpad editor ?
________
HAWAII MEDICAL MARIJUANA