Search code examples
notepad++autohotkey

Automatic Notepad++ formatting for writing scripts


I'm wondering if anyone had techniques/tips for using Notepad++ for writing scripts. I know real IDE programs I've used for say, python, have a lot of built-in autoformatting. When I write an IF statement or LOOP it will create some of the bracketing needed. I use Notepad++ for writing AutoHotKey and it works really really well, but would love if it had some auto-formatting capability.

Something like; I type if and gets turned into...

if ()
  {

  }

or typing functions such as RegExMatch into... RegExMatch(,,,)

If Notepad++ is not the best editor for AHK then what is?


Solution

  • For typing AHK commands and functions in Editors I use context-sensitive Hotstrings with a special ending char in my main script:

            ; === auto-execute section ===  (top of the script)
    
    ; create a group of those editors:  
    GroupAdd, myEditors, ahk_class Notepad
    GroupAdd, myEditors, ahk_class Notepad++
    ; ...
    
                RETURN   ; === end of auto-execute section ===
    
    ; Hotstring-Options:    
    ; C0: Case-insensitive
    ; O: Omit the ending character
    ; T: Send the replacement text raw
    ; EndChar: < 
    #Hotstring T O C0
    #Hotstring EndChars <    
    
    #IfWinActive ahk_group myEditors
    
    ::if:: ; type if< to send 
    Send {Text}
    (
    if ()
      {
    
      }
    )
    return
    
    ; type rexm< or RegExMatch< to send RegExMatch(,,,)
    ::rexm::RegExMatch(,,,)
    ::RegExMatch::RegExMatch(,,,)
    
    ; ...
    
    
    
     #IfWinActive ; turn off context-sensitivity