AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Intellitype (+ Rajat's Intellisense II: a winning team!)

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
jordis



Joined: 30 Jul 2004
Posts: 81

PostPosted: Sat Jun 11, 2005 2:02 am    Post subject: Intellitype (+ Rajat's Intellisense II: a winning team!) Reply with quote

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

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 Smile
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 Wink

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! Wink

-jordi (wow!)
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10716

PostPosted: Sun Jun 12, 2005 11:44 am    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message Send e-mail
Rajat



Joined: 28 Mar 2004
Posts: 1687

PostPosted: Tue Jun 14, 2005 9:27 pm    Post subject: Reply with quote

i tried it but it didn't work for me!
_________________
Back to top
View user's profile Send private message
jordis



Joined: 30 Jul 2004
Posts: 81

PostPosted: Wed Jun 15, 2005 10:24 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
Rajat



Joined: 28 Mar 2004
Posts: 1687

PostPosted: Wed Jun 15, 2005 12:20 pm    Post subject: Reply with quote

the menu shows ok, but pressing a no. just puts that no. there instead of the cmd name.
_________________
Back to top
View user's profile Send private message
cmkw



Joined: 10 Jun 2005
Posts: 5

PostPosted: Wed Jun 15, 2005 1:28 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
cmkw



Joined: 10 Jun 2005
Posts: 5

PostPosted: Wed Jun 15, 2005 1:50 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Rajat



Joined: 28 Mar 2004
Posts: 1687

PostPosted: Wed Jun 15, 2005 3:33 pm    Post subject: Reply with quote

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. Sad
_________________
Back to top
View user's profile Send private message
jordis



Joined: 30 Jul 2004
Posts: 81

PostPosted: Thu Jun 16, 2005 11:58 am    Post subject: Reply with quote

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. Sad

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...
Back to top
View user's profile Send private message
Rajat



Joined: 28 Mar 2004
Posts: 1687

PostPosted: Thu Jun 16, 2005 2:14 pm    Post subject: Reply with quote

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! Rolling Eyes
_________________
Back to top
View user's profile Send private message
webber



Joined: 25 Aug 2005
Posts: 129

PostPosted: Fri Aug 26, 2005 7:33 pm    Post subject: Reply with quote

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 Fri Feb 11, 2011 4:49 am; edited 1 time in total
Back to top
View user's profile Send private message
maniac



Joined: 28 Aug 2009
Posts: 267

PostPosted: Fri Aug 28, 2009 2:42 pm    Post subject: Reply with quote

I made some fixes/modifications to this script, you can view them here:

http://www.autohotkey.com/forum/viewtopic.php?p=292220#292220

Thanks!
Back to top
View user's profile Send private message
Asaptrad



Joined: 29 Apr 2009
Posts: 4
Location: Paris, France

PostPosted: Wed Sep 02, 2009 5:26 pm    Post subject: Script to add selection to wordlist.txt Reply with quote

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
Back to top
View user's profile Send private message
Asaptrad



Joined: 29 Apr 2009
Posts: 4
Location: Paris, France

PostPosted: Thu Sep 03, 2009 8:05 am    Post subject: Script to add selected snippets to wordlist.txt Reply with quote

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
Back to top
View user's profile Send private message
maniac



Joined: 28 Aug 2009
Posts: 267

PostPosted: Mon Sep 14, 2009 12:00 pm    Post subject: Reply with quote

I made some more modifications, can be found here:
http://www.autohotkey.com/forum/viewtopic.php?p=296072#296072
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group