Autohotkey Code Formatter for Piotr's PowerPack V2 Code Snippets


Here’s something that I’ve wanted for ages

Its only useful if you use @Piotr powerpack V2 with the codesnippet manager part

The problem I had is it doesn’t support [tab] based formatting at well, so I had this autohotkey made that solves the issue

clipboard := StrReplace(clipboard, A_Tab, A_Space A_Space)
position := RegExMatch(clipboard, "\S")
test := RegExReplace(clipboard, "m)^[ ]{" . position - 1 . "}")
clipboard := test

So I basically go to my favorite IDE (I only tested PHPstorm so far), Copy some code there, Press F9, Paste into dynalist

This is what it looks like without the autohotkey fix, and with it

makes reading code sooooooo much easier now. Before I had to manually format everything, literally go line by line, remove spacing, add more spaces, etc. This sometimes took like 100 steps and was really time consuming

Demonstrating the whole process in action (copy, Press F9, paste)

If you use powerPack V2 code snippet support, and want to use this script, you do the following:

  1. Download AutoHotkey
  2. Rightclick anywhere on desktop → “New AutoHotKey Script”
  3. Paste the code at the top
  4. “Compile Code”
  5. Run the Exe

Then all you have to do is

  1. Copy some code somewhere
  2. Press F9
  3. Paste using powerPack v2

I have it currently set to two spaces, per indent, but if you wanted 4 spaces instead, you just change the 2nd line . From this:

clipboard := StrReplace(clipboard, A_Tab, A_Space A_Space)
clipboard := StrReplace(clipboard, A_Tab, A_Space A_Space A_Space A_Space)

Below is a comparison between a 2 space VS 4 space indent


PHPstorm / webstorm default settings work fine

it doesn’t work with vscode standard default settings