AutoHotkey Community

It is currently May 26th, 2012, 2:35 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 15 posts ] 
Author Message
PostPosted: June 11th, 2005, 3:02 am 
Offline

Joined: July 30th, 2004, 9:08 pm
Posts: 81
Hi all
This code is a slight modification of my previous Intellisense-like autoreplacement with multiple suggestions (which in turn was a heavy-duty modification of Rafat's first IntelliSense script)
I thought I would post it here, since it was in the support/help forum waiting for some refinements (which never came due to lack of time :oops:)

Just out of curiosity, I tried how Rajat's Intellisense II script would interoperate with my Intellitype script (i just named it like that) and it turned out to be a great team!
How it works? Intellitype guesses the command you're trying to type and then Intelisense shows its syntax... wow!
I though that I would probably need to change some shared variable names or something but nope... they work just great together!
My script requires a file called Wordlist.txt in the script's directory containing the AHK commands it should guess (or actually, anything you would like it to guess)... I took the contents from:
<ahk_install_dir>\Extras\Editors\Syntax\CommandNames.txt
but you can actually also add
<ahk_install_dir>\Syntax\Keywords.txt
<ahk_install_dir>\Syntax\Variables.txt
to the wordlist.txt

@Rajat
I just installed your Intellisense II script, but I had to modify the following line:
Code:
;reads command syntaxes
Loop, Read, %ahkpath%\Extras\Editors\TextPad\AHKcommands.txt
Reason is, there's no AHKcommands.txt file in that folder... Probably got deleted in some of the really frequent (wow chris!) builds?
Anyway, I found this other file which I guess contains the info that we need :)
Code:
Loop, Read, %ahkpath%\Extras\Editors\Syntax\Commands.txt


Anyway, here's the code:
Code:
;  Intellitype: typing aid
;  Press 1 to 0 keys to autocomplete the word upon suggestion
;  (0 will match suggestion 10)
;                                  - Jordi S
;___________________________________________

;    CONFIGURATIONS

; Editor Window Recognition
; (make it blank to make the script seek all windows)

ETitle =

;Minimum word length to make a guess
WLen = 3
keyagain=
key=
clearword=1
;Gosub,clearallvars   ; clean vars from start

; Press 1 to 0 keys to autocomplete the word upon suggestion
; (0 will match suggestion 10)
;_______________________________________

SetKeyDelay, 0
CoordMode, ToolTip, Relative
AutoTrim, Off

;reads list of words from file
Loop, Read,  %A_ScriptDir%\Wordlist.txt   
{
   tosend = %a_loopreadline%
   cmd%a_index% = %toSend%
}
SetTimer, Winchanged, 100

Loop
{
   ;Editor window check
    WinGetActiveTitle, ATitle
    WinGet, A_id, ID, %ATitle%
    IfNotInString, ATitle, %ETitle%
    {
      ToolTip
      Setenv, Word,
      sleep, 500
      Continue
  }
   
   ;Get one key at a time
   Input, chr, L1 V,{enter}{space}.;`,:¿?¡!'"()]{}{bs}{esc}
   EndKey = %errorlevel%
   ; If active window has different window ID from before the input, blank word
   ; (well, assign the number pressed to the word)
   WinGetActiveTitle, ATitle
   WinGet, A_id2, ID, %ATitle%
   IfNotEqual, A_id, %A_id2%
   {
      Gosub,clearallvars
      Setenv, Word, %chr%
      Continue
   }
   
   ;Blanks word reserve
   ifequal, EndKey, Endkey:Enter, Gosub,clearallvars
   ifequal, EndKey, Endkey:Escape, Gosub,clearallvars
   ifequal, EndKey, Endkey:Space, Gosub,clearallvars
   ifequal, EndKey, Endkey:`,, Gosub,clearallvars
   ifequal, EndKey, Endkey:., Gosub,clearallvars
   ifequal, EndKey, Endkey:`:, Gosub,clearallvars
   ifequal, EndKey, Endkey:`;, Gosub,clearallvars
   ifequal, EndKey, Endkey:!, Gosub,clearallvars
   ifequal, EndKey, Endkey:¡, Gosub,clearallvars
   ifequal, EndKey, Endkey:?, Gosub,clearallvars
   ifequal, EndKey, Endkey:¿, Gosub,clearallvars
   ifequal, EndKey, Endkey:", Gosub,clearallvars
   ifequal, EndKey, Endkey:', Gosub,clearallvars
   ifequal, EndKey, Endkey:(, Gosub,clearallvars
   ifequal, EndKey, Endkey:), Gosub,clearallvars
;   ifequal, EndKey, Endkey:[, Gosub,clearallvars
   ifequal, EndKey, Endkey:], Gosub,clearallvars
   ifequal, EndKey, Endkey:{, Gosub,clearallvars
   ifequal, EndKey, Endkey:}, Gosub,clearallvars
   
   ;Backspace clears last letter
   ifequal, EndKey, Endkey:BackSpace, StringTrimRight, Word, Word, 1
   ifnotequal, EndKey, Endkey:BackSpace, Setenv, Word, %word%%chr%
   
   ;Wait till minimum letters
   StringLen, len, Word
   IfLess, len, %wlen%
   {
      ToolTip
      Continue
   }
   
   ;Match part-word with command
   Num =
   Match =
   singlematch = 0
   number = 0
   Loop
   {
      IfEqual, cmd%a_index%,, Break
      StringLen, chars, Word
      StringLeft, strippedcmd, cmd%a_index%, %chars%
      StringLeft, strippedword, Word, %chars%
      ifequal, strippedcmd, %strippedword%
      {
         num = %a_index%
         number ++

         ; Create list of matches
         StringTrimLeft, singlematch, cmd%num%, 0
         match = %match%%number%. %singlematch%`n

         ; Map singlematch with corresponding cmd
         singlematch%number%=cmd%num%

         Continue
      }
   }

   ;If no match then clear Tip
   IfEqual, Num,
   {
      clearword=0
      Gosub,clearallvars
      Continue
   }
   
   ;Show matched command
   StringTrimRight, match, match, 1        ; Get rid of the last linefeed
;   IfNotEqual, Word,,ToolTip, %match%, 388, 24
   display_y = %A_CaretY%
   display_y += 20 ; Move tooltip down a little so as not to hide the caret.
   IfNotEqual, Word,,ToolTip, %match%, %A_CaretX%, %display_y%


}

; Timed function to detect change of focus (and remove tooltip when changing active window)
Winchanged:
   WinGetActiveTitle, ATitle
   WinGet, A_id3, ID, %ATitle%
   IfNotEqual, A_id, %A_id3%
   {
      ToolTip
   }
   Return
   
; Key definitions for autocomplete (0 to 9)
#MaxThreadsPerHotkey 1
$1::
key=1
Gosub, checkword
Return

$2::
key=2
Gosub, checkword
Return

$3::
key=3
Gosub, checkword
Return

$4::
key=4
Gosub, checkword
Return

$5::
key=5
Gosub, checkword
Return

$6::
key=6
Gosub, checkword
Return

$7::
key=7
Gosub, checkword
Return

$8::
key=8
Gosub, checkword
Return

$9::
key=9
Gosub, checkword
Return

$0::
key=10
Gosub, checkword
Return


; If hotkey was pressed, check wether there's a match going on and send it, otherwise send the number(s) typed
checkword:
   clearword=1
   Suspend, on    ; Suspend hotkeys so that they don't interfere with the second press

   ; If active window has different window ID from before the input, blank word
   ; (well, assign the number pressed to the word)
   WinGetActiveTitle, ATitle
   WinGet, A_id2, ID, %ATitle%
   IfNotEqual, A_id, %A_id2%
      {
         if key =10
            key = 0
         Send,%key%
         Gosub,clearallvars
         Suspend, off
         Return
      }

   if word=        ; only continue if word is not empty
      {
         if key =10
            key = 0
         Send,%key%
         Setenv, Word, %key%
         clearword=0
         Gosub,clearallvars
         Suspend, off
         Return
      }
   
   ifequal, singlematch%key%,   ; only continue singlematch is not empty
      {
         if key =10
            key = 0
         Send,%key%
         Setenv, Word, %word%%key%
         clearword=0
         Gosub,clearallvars
         Suspend, off
         Return
      }

   ; 2nd press to confirm replacement
   Input, keyagain, L1 I T0.5, 1234567890

;   msgbox, ErrorLevel=%ErrorLevel%   ; UNCOMMENT FOR TESTING 2ND PROBLEM DISCUSSED IN POST

   ; If there is a timeout, abort replacement, send key and return
   IfEqual, ErrorLevel, Timeout
   {
      if key =10
         key = 0
      Send, %key%
      Setenv, Word, %word%%key%
      clearword=0
      Gosub,clearallvars
      Suspend, off
      Return
   }
   
     
   ; Make sure it's an EndKey, otherwise abort replacement, send key and return
   IfNotInString, ErrorLevel, EndKey:
   {
      if key =10
         key = 0
      Send, %key%%keyagain%
      Setenv, Word, %word%%key%%keyagain%
      clearword=0
      Gosub,clearallvars
      Suspend, off
      Return
   }

   ; If the 2nd key is NOT the same 1st trigger key, abort replacement and send keys
   if key =10
      key = 0
   IfNotInString,ErrorLevel, %key%
   {
     StringTrimLeft, keyagain, ErrorLevel, 7
      Send, %key%%keyagain%
      Setenv, Word, %word%%key%%keyagain%
      clearword=0
      Gosub,clearallvars
      Suspend, off
      Return
   }

   ; SEND THE WORD!
   if key =0
      key = 10
   StringTrimLeft, lastone, singlematch%key%, 0 ; This is because i can't get %singlematch%%key%
   StringTrimLeft, sending, %lastone%, 0        ; to work in this line
   StringLen, len, Word
   Send, {BS %len%}    ; First do the backpaces
   SendRaw, %sending%  ; Then send word (Raw because we want the string exactly as in wordlist.txt)
   Gosub,clearallvars
   Suspend, off
   Return


; This is to blank all vars related to matches, tooltip and (optionally) word
clearallvars:
      Ifequal,clearword,1,Setenv,word,
      ToolTip
      ; Clear all singlematches
      Loop, 10
      {
         singlematch%a_index% =
      }
      sending =
      key=
      match=
      clearword=1
      Return


For more information on how Intellitype works, see Intellisense-like autoreplacement with multiple suggestions

Quoting myself from there,
jordi wrote:
The script is still in a development stage... for example I didn't event implement the new Caret recognition functions to show the tooltip near the caret... YET
Well, this is actually implemented in the above script...
And I plan to work in new features and improvements (check out the suggestion for multipleline items support in the previous post)... anyway time will tell...

One note: So far, Intellitype supports "double-clicking" the keyboards keys 0 to 9 (not extended keyboard) to trigger a replacement (0 is the 10th suggestion). Sometimes the suggestion tooltip shows more than 10 matches (try typing "file" for example). So only the 1st ten suggestions are "usable", but keep typing the next character of the command and the list will narrow ;-)

Both Intellisense II + Intelliype are quite "old" scripts (from last year). I mean that they don't take advantage of the whole bunch newer AHK features that Chris has been implementing (wow!)

Anyway, Intellitype + Intellisense II are worth trying out together...
just had to say it! ;-)

-jordi (wow!)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 12th, 2005, 12:44 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
This looks great. I've been meaning to start using Intellisense personally for a long time. I know it's hard to live without once you get used to it.

If you or others become comfortable with this as a complete package that can work in nearly any editor -- and you think that 90% or more of AutoComplete and IntelliSense users would prefer to have both in one package if only they knew about it -- perhaps this script should be packaged with the distribution and/or put into the Script Showcase.

If sent with the distribution, it would be good to include A to Z install and usage instructions for someone completely unfamiliar with it. Ideally, when the script is run the first time, a simple GUI window could be presented that allows customization of any options through checkboxes. The results could be written to an .ini file.

This is only a casual idea so feel free to ignore it :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 14th, 2005, 10:27 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
i tried it but it didn't work for me!

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 15th, 2005, 11:24 am 
Offline

Joined: July 30th, 2004, 9:08 pm
Posts: 81
mmm
Well, it sure worked for me...
Just to make sure, I meant running them separately (i.e. 2 AHK icons in the system tray), *not* both combined in a single script...
what's exactly not working in your case?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 15th, 2005, 1:20 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
the menu shows ok, but pressing a no. just puts that no. there instead of the cmd name.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 15th, 2005, 2:28 pm 
Offline

Joined: June 10th, 2005, 1:12 am
Posts: 5
I got it working after reading your previous post last year. Use the number keys not the keypad numbers and double hit the number within.5 sec.
I have it in my toolkit with a nice icon but the compiled exe doesn't work only the .ahk file. I think this is another great tool but you have to fast on the keystrokes.

cmkw


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 15th, 2005, 2:50 pm 
Offline

Joined: June 10th, 2005, 1:12 am
Posts: 5
Sorry the exe works. (must have had the wrong directory) Played around with the timer. set it to 1000 and it makes it easier.

cmkw


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 15th, 2005, 4:33 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
Quote:
Use the number keys not the keypad numbers and double hit the number within.5 sec.
ohh ok!
but my intellisense isn't grabbing the keystrokes sent by this script so the sysntax isn't shown. :(

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 16th, 2005, 12:58 pm 
Offline

Joined: July 30th, 2004, 9:08 pm
Posts: 81
cmkw wrote:
Use the number keys not the keypad numbers and double hit the number within.5 sec.

That's right, pressing a number *only once* will type that number after half a second.
Quoting myself from my preivous post:
Quote:
To trigger the replacement, I though about pressing control something, or alt something, but then I thought I would avoid such key combinations because 1) the apllication in which i want to use it, already uses these key combinations for other purposes and 2) I dont think it's fast or convenient enough having to press an extra key during normal typing. Therefore, I though to use the 0-9 number keys (regular ones, not numpad) to trigger the replacement. So, when a suggestion is presented to the user, he/she simply has to "double-press" the corresponding number (kind of double-click, but with the number key). I think this is faster than having to press a combination of another key plus the number... There is a timeout of 0.5 seconds for the second key press. That is, if the user presses 1 upon a suggestion, the script will wait for half a second to check whether the 1 key is pressed again. Otherwise, a literal 1 is send.


Rajat wrote:
but my intellisense isn't grabbing the keystrokes sent by this script so the sysntax isn't shown. :(

Are you typing a comma or a space after the command? The syntax is not shown straightaway, since your Intellisense requires you to type a space/comma...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 16th, 2005, 3:14 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
jordi wrote:
Are you typing a comma or a space after the command? The syntax is not shown straightaway, since your Intellisense requires you to type a space/comma...

yes i'd been doing that. whatever the problem was its gone now by itself! :roll:

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2005, 8:33 pm 
Offline

Joined: August 25th, 2005, 9:40 pm
Posts: 129
Quote:
Both Intellisense II + Intelliype are quite "old" scripts (from last year). I mean that they don't take advantage of the whole bunch newer AHK features that Chris has been implementing (wow!)

Anyway, Intellitype + Intellisense II are worth trying out together...


2 questions:
==================
1] is it possible to preface commands with letters after the 10th listing ?

2] is it possible to show listing in a listbox so user can select by clicking on item ?
________
Justin Bieber


Last edited by webber on February 11th, 2011, 5:49 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 3:42 pm 
Offline

Joined: August 28th, 2009, 3:00 pm
Posts: 275
I made some fixes/modifications to this script, you can view them here:

http://www.autohotkey.com/forum/viewtop ... 220#292220

Thanks!


Report this post
Top
 Profile  
Reply with quote  
PostPosted: September 2nd, 2009, 6:26 pm 
Offline

Joined: April 29th, 2009, 7:57 pm
Posts: 4
Location: Paris, France
This is a great script. Thanks!
It would also be nice to have a little script to add selected snippets to the wordlist.txt file, save the file and reload the script. There's no doubt an existing script that could be tweaked for this purpose.

Dave

_________________
David


Report this post
Top
 Profile  
Reply with quote  
PostPosted: September 3rd, 2009, 9:05 am 
Offline

Joined: April 29th, 2009, 7:57 pm
Posts: 4
Location: Paris, France
Maybe something like this?

#c::
text =
ClipBoard =
Sleep, 100
SendInput, ^c
Sleep, 200
text = %Clipboard%

found = 0

Loop, Read, wordlist.txt
{
If text = %A_LoopReadLine%
found = 1
}

If found = 0
FileAppend, %text%`n, wordlist.txt

Reload
Sleep 200

return

_________________
David


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 14th, 2009, 1:00 pm 
Offline

Joined: August 28th, 2009, 3:00 pm
Posts: 275
I made some more modifications, can be found here:
http://www.autohotkey.com/forum/viewtop ... 072#296072


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, mhe and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group