Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New AHK Files From VS Code use the wrong template. #93

Closed
PristineWolf opened this issue May 10, 2021 · 4 comments · Fixed by #284
Closed

New AHK Files From VS Code use the wrong template. #93

PristineWolf opened this issue May 10, 2021 · 4 comments · Fixed by #284
Assignees
Labels
bug something isn't working good first issue good for new contributors template template for a new AHK script

Comments

@PristineWolf
Copy link

PristineWolf commented May 10, 2021

Description

So basically when creating a new ahk file from the winows explorer by right clicking > New AHK File. It all works fine and uses the template for ahk files in "C:\Windows\ShellNew\Template.ahk". However, when I create an ahk file in VS Code it uses this extension's template and not the above mentioned directory. After some digging I found out it's in a json file "C:\Users\This-PC.vscode\extensions\mark-wiemer.vscode-autohotkey-plus-plus-2.8.1\snippets\ahk.json"
I tried changing the code there but I'm really bad at html and json. It worked, then the extension updated and all work was wasted. So I guess I'll have to ask you if you can make the template use "C:\Windows\ShellNew\Template.ahk". Thanks

Reproduction steps

Steps to reproduce the behavior:

  1. Open a folder in VS Code (Control K then Control O and select a folder)
  2. In the explorer window (Control B to toggle it) make a new file and name it anything.ahk
    image
  3. Check the template used which is not what is in "C:\Windows\ShellNew\Template.ahk"
    image

Expected behavior

The extension should use the template in "C:\Windows\ShellNew\Template.ahk"

Additional context

At the start of the json file mentioned above there's a tag or whatever they call it in json which ahktemplate. I think it should be easy to make it use the template.ahk in "C:\Windows\ShellNew\Template.ahk".
image

Thank You!

@PristineWolf PristineWolf added the bug something isn't working label May 10, 2021
@mark-wiemer
Copy link
Member

I will likely change the default to

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

Don't want to bother people with redundant comments in their templates :) Thank you for teaching me about Template.ahk, I had no idea that was a thing!

@mark-wiemer mark-wiemer added this to the Backlog milestone May 12, 2021
@PristineWolf
Copy link
Author

PristineWolf commented May 12, 2021

Can you please make it so that it uses template.ahk? It's what I always use (and I have also tweaked it a bit as well to my liking), and what creating an ahk file outside vs code uses. It will make my life easier and not have to go and create a file in windows explorer. Thanks

@fade2gray
Copy link

fade2gray commented May 12, 2021

@PristineWolf I've just discovered this.

Go to File > Preferences > User Snippets and select ahk (AutoHotkey) from the palette list.

You'll be presented with an ahk.json snippets template file which you can edit till your heart's content and should, I assume, persist after extension updates.

Using the example below, open a new file, select the AHK language, start typing MyTemplate and you should be presented with your quick-suggestions/autocomplete list.

{
    // Place your snippets for ahk here. Each snippet is defined under a snippet name and has a prefix, body and 
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
    // same ids are connected.
    // Example:
    // "Print to console": {
    // 	"prefix": "log",
    // 	"body": [
    // 		"console.log('$1');",
    // 		"$2"
    // 	],
    // 	"description": "Log output to console"
    // }
    "MyTemplate": {
        "prefix": "#MyTemplate",
        "body": [
            "#SingleInstance, Force ; Allow only one running instance of script",
            "#Persistent ; Keep script permanently running until terminated",
            "#NoEnv ; Avoid checking empty variables to see if they are environment variables",
            ";#Warn ; Enable warnings to assist with detecting common errors",
            ";#NoTrayIcon ; Disable the tray icon of the script",
            "SendMode, Input ; Recommended for new scripts due to its superior speed and reliability",
            "SetWorkingDir, %A_ScriptDir% ; Change the working directory of the script",
            "SetBatchLines, -1 ; Run script at maximum speed",
            "",
            "",
        ]
    },
    "MyFunction": {
        "prefix": "#MyFunction",
        "body": [
            "Function(){",
            "\t$0",
            "}",
        ]
    }
}

@PristineWolf
Copy link
Author

PristineWolf commented May 12, 2021

@PristineWolf I've just discovered this.

Go to File > Preferences > User Snippets and select ahk (AutoHotkey) from the palette list.

You'll be presented with an ahk.json snippets template file which you can edit till your heart's content and should, I assume, persist after extension updates.

Using the example below, open a new file, select the AHK language, start typing MyTemplate and you should be presented with your quick-suggestions/autocomplete list.

{
    // Place your snippets for ahk here. Each snippet is defined under a snippet name and has a prefix, body and 
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
    // same ids are connected.
    // Example:
    // "Print to console": {
    // 	"prefix": "log",
    // 	"body": [
    // 		"console.log('$1');",
    // 		"$2"
    // 	],
    // 	"description": "Log output to console"
    // }
    "MyTemplate": {
        "prefix": "#MyTemplate",
        "body": [
            "#SingleInstance, Force ; Allow only one running instance of script",
            "#Persistent ; Keep script permanently running until terminated",
            "#NoEnv ; Avoid checking empty variables to see if they are environment variables",
            ";#Warn ; Enable warnings to assist with detecting common errors",
            ";#NoTrayIcon ; Disable the tray icon of the script",
            "SendMode, Input ; Recommended for new scripts due to its superior speed and reliability",
            "SetWorkingDir, %A_ScriptDir% ; Change the working directory of the script",
            "SetBatchLines, -1 ; Run script at maximum speed",
            "",
            "",
        ]
    },
    "MyFunction": {
        "prefix": "#MyFunction",
        "body": [
            "Function(){",
            "\t$0",
            "}",
        ]
    }
}

Hey,
Nice approach actually. I remember being there though too lol. The thing with this is that I still have to type #template or whatever to trigger it. In that ahk.json file even though it has a prefix I don’t know exactly how but it is also triggered alone when you create a new file in vs code. and that's exactly what I need, make a new ahk file in vs code and have it all ready. I did find a workaround though. Since mark's approach doesn't include reading that Template.ahk (I did some research and I didn't find an easy way to do this in json), I disabled extension updates then went and modified it to my liking in his ahk.json. So I guess I'm fine until he drops a new version where if I need the features I'll update and fork it again.
Thanks anyway
Edit: also if I need some boilerplate code to be filled I might as well make a hotstring for it (AHK)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something isn't working good first issue good for new contributors template template for a new AHK script
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants