Jump to content

Recommended Posts

Posted (edited)

Hi all,

I am trying to make simple function to help coding in SciTE editor. This function will automatically add an "EndIf / EndFunc / WEnd / Next / EndSwitch / EndSelect / Until " after we press the enter key. It checks for first word of that line. And if the first word is " If / Func / While / For / Switch / Select / Do" , then it will work. Otherwise a normal enter key will work. Please look at my code. Unfortunately, this is not working. Please help me to find the error.

 
 
#include <StringConstants.au3>
#include <Array.au3>

HotKeySet("{ENTER}", "AutoFiller")
HotKeySet("!{ESC}", "Exiter")
While 1
    Sleep(10)
WEnd




Func AutoFiller()

    Local $title = WinGetTitle("[CLASS:SciTEWindow]")             ; getting title of SciTE window
    Local $text = ControlGetText($title, "S", 350)            ; getting text from code editor
    Local $col = ControlGetText($title, "", 353)              ; getting text from status bar

    Local $Get_Digit_from_col = StringRegExp($col, "\d{1,4}", 3)  ; an array and put line number and col number
    Local $Line_number = $Get_Digit_from_col[0]           ; this is line number where cursor residing 
    Local $Col_number = $Get_Digit_from_col[1]            ; this is col number where cursor residing 
    Local $CodeLines_Array = StringSplit($text, @CR)          ; splitting code window text as lines 

    Local $Last_lineText = $CodeLines_Array[$Line_number]         ; this is text where cursor residing
    Local $TempArray = StringSplit($Last_lineText, " ")       ; splitting the text into words 
    Local $Start_text = $TempArray[1]                     ; this is the first word in that line
    Local $End_text = $TempArray[$TempArray[0]]           ; this is the last word in that line


    If $Start_text = "If" And $End_text = "Then" Then                                           
        ControlSend($title, "S", 350, "{ENTER}{BACKSPACE}{ENTER}EndIf{ESC}{UP}{TAB}")           

    ElseIf $Start_text = "If" And $End_text <> "Then" Then                                      
        ControlSend($title, "S", 350, " Then {ENTER}{BACKSPACE}{ENTER}EndIf{ESC}{UP}{TAB}")     

    ElseIf $Start_text = "Func" Then                                                            
        ControlSend($title, "S", 350, "{ENTER}{BACKSPACE}{ENTER}EndFunc{ESC}{UP}{TAB}")

    ElseIf $Start_text = "While" Then                                                           
        ControlSend($title, "S", 350, "{ENTER}{BACKSPACE}{ENTER}WEnd{ESC}{UP}{TAB}")

    ElseIf $Start_text = "For" Then                                                             
        ControlSend($title, "S", 350, "{ENTER}{BACKSPACE}{ENTER}Next{ESC}{UP}{TAB}")

    ElseIf $Start_text = "Do" Then                                                              
        ControlSend($title, "S", 350, "{ENTER}{BACKSPACE}{ENTER}Untill{ESC}{UP}{TAB}")

    ElseIf $Start_text = "Switch" Then                                                          
        ControlSend($title, "S", 350, "{ENTER}Case {ENTER} {BACKSPACE}EndSwitch{ESC}{UP}{END}")

    ElseIf $Start_text = "Select" Then                                                          
        ControlSend($title, "S", 350, "{ENTER}Case {ENTER} {BACKSPACE}EndSelect{ESC}{UP}{END}")

    Else                                                                                        
        ControlSend($title, "S", 350, "{ENTER}")
    EndIf

EndFunc   ;==>AutoFiller

Func Exiter()
    Exit
EndFunc   ;==>Exiter
Edited by kcvinu
  Reveal hidden contents

 

  • Developers
Posted

Are you trying to re-create the build-in Abbreviations functionality?

I would never approach it in this way but rather write a LUA or AutoIt3Script using the DIrector interface in the Background.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

@Jos, there is an abbreviation file but it contains only some short form text like "au3.keywords.abbrev= a3w a3w2 ". I don't know how to deal with them. So i planned to make a script. And you mean this method is a slower one ?. Or an impossible one ?. 

  Reveal hidden contents

 

  • Developers
Posted
  On 3/10/2015 at 6:25 PM, kcvinu said:

@Jos, there is an abbreviation file but it contains only some short form text like "au3.keywords.abbrev= a3w a3w2 ". I don't know how to deal with them. So i planned to make a script. And you mean this method is a slower one ?. Or an impossible one ?. 

Not knowing "how it works" shouldn't be an excuse for not using it.

This method will always have the risk to conflict with something and requires this extra script to run always, were Abbrevs or Lua/Director interface work in the background.

My 2 cents ;)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

@Jos, Then where i can learn about thease " Abbrevs or Lua/Director interface". I have never seen any tutorials or examples.

  Reveal hidden contents

 

  • Developers
Posted
  On 3/10/2015 at 6:32 PM, kcvinu said:

@Jos, Then where i can learn about thease " Abbrevs or Lua/Director interface". I have never seen any tutorials or examples.

Information is out there, but will take time to read/learn and understand.

Abbreviations is pretty well documented in the Helpfile and is even an script written by Melba23, included in SciTEConfig, to maintain them.

I am not going to spoon feed any of this but will help in case there are questions after I see some investment. ;)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

@Jos, Ok Thanks. If it is possible, then why we don't have this feature in SciTE ?. Is it a giant task ?

  Reveal hidden contents

 

Posted (edited)

Pressing enter after an if statement without "Then" will display a "Then" and a new line and "EndIf" and the cursor rests in the newline. 

Edit : The same feature in visual studio

Edited by kcvinu
  Reveal hidden contents

 

Posted

What i am talking about is that, after we type an "If " statement and the expression like this

If x = y

And i need a "Then" automatically right after i hit Enter. And an "EndIf" in the next line

  Reveal hidden contents

 

Posted

@Jos, The feature you said above (ifthen & space) will work but it needs two up arrow key press to type the expression.

  Reveal hidden contents

 

Posted

@jos, This is not a fun project. This is a must have feature for a coding IDE. Why visual studio has this feature ?. This feature increases productivity. 

  Reveal hidden contents

 

  • Developers
Posted
  On 3/10/2015 at 7:07 PM, kcvinu said:

@jos, This is not a fun project. This is a must have feature for a coding IDE. Why visual studio has this feature ?. This feature increases productivity. 

seems you are serious about it, well let me know when you are done so it can be implemented in SciTE.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted (edited)

  On 3/10/2015 at 7:06 PM, kcvinu said:

@Jos, The feature you said above (ifthen & space) will work but it needs two up arrow key press to type the expression.

 

??

 

in au3abbrev.properties

there is

  Quote
ifthen=If | ThennEndIf

when you use this like you say (ifthen & space)

then:

If "HERE IS CURSOR" Then
EndIf

so I do not understand why you say:

  Quote

 it needs two up arrow key press to type the expression

 

mLipok

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Hi 

mLipok, I can't see such a file named  au3abbrev.properties in my pc.  And my arrow key rests after "Endif" .I am sure

And what i am talking about is not the abbreviation. Abbreviation only works after space key. I am talking about the Enter key. If we type "If " and the expression (say x = 15) then if we hit enter, there would be a "Then" and a new line and an "EndIf". Is this possible with an abbreviation ?

  Reveal hidden contents

 

Posted
  On 3/10/2015 at 9:38 PM, kcvinu said:

mLipok, I can't see such a file named  au3abbrev.properties in my pc.  And my arrow key rests after "Endif" 

C:Users{UserName}AppDataLocalAutoIt v3SciTEau3abbrev.properties

 

  On 3/10/2015 at 9:38 PM, kcvinu said:

I am sure And what i am talking about is not the abbreviation. Abbreviation only works after space key.

 

I know, you know what you want :)

 

  On 3/10/2015 at 9:38 PM, kcvinu said:

I am talking about the Enter key. If we type "If " and the expression (say x = 15) then if we hit enter, there would be a "Then" and a new line and an "EndIf". Is this possible with an abbreviation ?

 

No.

Maybe Lua.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Hi all,

I have got a working code. But don't know how limit it for SciTE window only.

Here is the code.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=D:\AotoIt Works\EXEs\AutoFiller32.Exe
#AutoIt3Wrapper_Outfile_x64=D:\AotoIt Works\EXEs\AutoFiller64.Exe
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.12.0
    Author:         kcvinu

    Script Function: This program will paste EndIf / EndFunc / WEnd / Next / EndSwitch / Until / EndSelect automaticlly right after you hit enter

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here


#include <Array.au3>
#include <String.au3>
#include <StringConstants.au3>
#include <WinAPISys.au3>

HotKeySet("{ENTER}", "AutoFiller")
HotKeySet("{ESC}", "Exiter")

While 1
    Sleep(5)

WEnd


Func AutoFiller()
    Global $Words_array
    Global $FW_array
    Global $LW_array
    Global $First_word
    Global $Index
    Global $Last_word
    Global $Parenthesis


    Global $title = WinGetTitle("[CLASS:SciTEWindow]")

    If WinGetState($title) = 47 Or WinGetState($title) = 15 Then

        Global $Current_line = ControlCommand($title, "S", 350, "GetCurrentLine", "")
        Global $Text = ControlGetText($title, "S", 350)
        Global $Text_Array = StringSplit($Text, @LF)
        Global $Current_lineRaw = $Text_Array[$Current_line]
        Global $Current_lineText = StringStripWS($Current_lineRaw, 2)
        $Current_lineText = StringStripWS($Current_lineText, 1)
        $Last_word = StringRight($Current_lineText, 4)

        $Parenthesis = StringRight($Current_lineText, 2)

        If StringInStr($Current_lineText, " ") Then

            $FW_array = StringRegExp($Current_lineText, "(^\w+)", 1)
            $First_word = $FW_array[0]
            If @error Then
                ControlSend($title, "S", 350, "{ENTER}")

            EndIf


            If $First_word == "If" And Not ($Last_word == "Then") Then
                ControlSend($title, "S", 350, " Then {ENTER}{HOME}{ENTER}EndIf {UP}{TAB}", 0)

            ElseIf $First_word == "If" And $Last_word == "Then" Then
                ControlSend($title, "S", 350, "{ENTER}{HOME}{ENTER}EndIf {UP}{TAB}", 0)

            ElseIf $First_word == "Func" And Not ($Parenthesis = "()") Then
                ControlSend($title, "S", 350, "(){ENTER}{HOME}{ENTER}EndFunc {UP}{TAB}", 0)

            ElseIf $First_word == "Func" And $Parenthesis = "()" Then
                ControlSend($title, "S", 350, "{ENTER}{HOME}{ENTER}EndFunc {UP}{TAB}", 0)

            ElseIf $First_word == "For" Then
                ControlSend($title, "S", 350, "{ENTER}{HOME}{ENTER}Next {UP}{TAB}", 0)

            ElseIf $First_word == "While" Then
                ControlSend($title, "S", 350, "{ENTER}{HOME}{ENTER}WEnd {UP}{TAB}", 0)

            ElseIf $First_word == "Do" Then
                ControlSend($title, "S", 350, "{ENTER}{HOME}{ENTER}Until {UP}{TAB}", 0)

            ElseIf $First_word == "Switch" Then
                ControlSend($title, "S", 350, "{ENTER}Case {ENTER} {HOME}EndSwitch {UP}{SPACE}", 0)

            ElseIf $First_word == "Select" Then
                ControlSend($title, "S", 350, "{ENTER}{HOME}{ENTER}EndSelect {UP}{TAB}", 0)

            Else
                ControlSend($title, "S", 350, "{ENTER}")

            EndIf
        Else
            ControlSend($title, "S", 350, "{ENTER}")

        EndIf
    Else
        Local $hnd = _WinAPI_GetActiveWindow()
        WinActivate($hnd)
        Send("{ENTER}")

    EndIf

EndFunc   ;==>AutoFiller



Func Exiter()
    Exit
EndFunc   ;==>Exiter
;~ AF()
;~ _ArrayDisplay($Words_array)
  Reveal hidden contents

 

Posted

Lines from 103 to 105 are not tested yet. This function is working properly.

  Reveal hidden contents

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...