Sublime Text Resources - [plugins, lang files, etc.]

Discuss features, issues, about Editors for AHK
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Sublime Text Resources - [plugins, lang files, etc.]

Post by Coco » 02 Oct 2013, 08:17

This thread is for users of Sublime Text (2|3) who wants to share their AutoHotkey configuration/setup for the said text editor. To start with, below is a link to my custom sublime plugin that enables the user to run/build AHK scripts (saved or unsaved). By passing some special parameter(s) to the command, the user can:
  1. open AutoHotkey CHM Documentation
  2. run Window Spy
  3. run dynamic code
  4. run a script
The command can be used for custom sublime menus, bound to hotkey, added to the command palette, called from the Sublime Text console, etc.
USAGE/EXAMPLE:
First save the Python script as ahk.py and put it in your AutoHotkey package folder.

Calling it from the Sublime Text Console: (type the following in the console):

Code: Select all

view.run_command("ahk", {"cmd":"$help"}) # opens documentation
OR
view.run_command("ahk", {"cmd":"$win_spy"}) # runs Window Spy
OR
view.run_command("ahk", {"cmd":None}) # runs code from active Sublime Text view
OR
view.run_command("ahk", {"cmd":"C:\\Users\\MyUser\\Documents\\AutoHotkey\\some_ahk_script.ahk"}) # run script in HD
OR
view.run_command("ahk", {"cmd":"MsgBox, Hello World\nreturn"}) # run dynamic AHK code
As key binding: (pressing F5 will run code in active Sublime Text view)

Code: Select all

[
	{
		"keys": ["f5"],
		"command": "ahk",
		"context": [
			{ "key": "selector", "operator": "equal", "operand": "source.ahk" },
		]
	},
	{
		"keys": ["f5"],
		"command": "ahk",
		"context": [
			{ "key": "selector", "operator": "equal", "operand": "text.plain" },
		]
	}
]
**Tip/trick: Bind the command to a hotkey, type any AHK code in the Sublime Text console(use "\n" to indicate new lines = e.g.[do not include quotes]: "MsgBox, Hello Word\nreturn") , press the hotkey - the code is ran dynamically.

Here is the link to the Python script: ahk.py

UPDATE:

Code: Select all

CHANGELOG(topmost-recent):
10/20/13 - Added ability to pass arguments to script via 'args' parameter - 'args' should be a sequence/list/array of script arguments. For temp/unsaved script(s): if 'include_print' parameter is set to 'True'(default is True), a 'print(str)' function will be appended to the code. Calling this function from AHK will write 'str' to stdout, in this case, captured by Sublime Text's console - useful for debugging. Renamed 'param' parameter to 'cmd'.

10/09/13 - AHK scripts (whether from file or string) is now launched with the "/ErrorStdOut" switch. Runtime error(s) and #Warn warnings(if 'WarningMode' parameter is set to 'StdOut') are now displayed in Sublime Text's console.
NOTE: For now, the provided script is for Sublime Text 3 [beta] which uses Python 3.x. I will be posting a Sublime Text 2 compatible script.
Last edited by Coco on 19 Oct 2013, 14:57, edited 3 times in total.

User avatar
budRich
Posts: 82
Joined: 29 Sep 2013, 16:52
Location: Wermland
Contact:

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by budRich » 02 Oct 2013, 18:13

Great!
Here's my contribution, GoToTilla . It's a ahk script so i posted it in scripts & functions. Maybe someday, I'll make a python version of it, but not today.

User avatar
budRich
Posts: 82
Joined: 29 Sep 2013, 16:52
Location: Wermland
Contact:

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by budRich » 02 Oct 2013, 18:31

I've also made a color theme called HatOfGod, (also included in SciTE4AutoHotkey).

User avatar
Avi
Posts: 193
Joined: 30 Sep 2013, 09:51
Location: India
Contact:

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by Avi » 03 Oct 2013, 02:50

AutoHotkey Patch for Sublime Text (Sublime 4 AutoHotkey)
Github - https://github.com/avi-aryan/Sublime4Autohotkey
Old ahk Topic - http://www.autohotkey.com/board/topic/9 ... autohotkey

AutoHotkey Language Files for Sublime Text
Github - https://github.com/avi-aryan/AutoHotkey
Writes at Dev Letters

Clipjump Clipboard Manager : More Scripts (updated 2019)

Image

Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by Coco » 09 Oct 2013, 14:51

Update on AHK Python plugin - see OP:
AHK scripts (whether from file or string) is now launched with the "/ErrorStdOut" switch. Runtime error(s) and #Warn warnings(if 'WarningMode' parameter is set to 'StdOut') are now displayed in Sublime Text's console.

tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by tmplinshi » 12 Oct 2013, 04:53

Plugins:

1. Alignment
Dead-simple alignment of multi-line selections and multiple selections for Sublime Text 2.

Screenshot:
Spoiler
2. HighlightWords
A Sublime Text 2 & 3 plugin for highlighting mutiple words in different colors

Screenshot:
Spoiler
3. JumpTo
Sublime Text 2 plugin to move the cursor

4. MultiFill
A sublime text plugin for multi-fill text.

Screenshot:
Spoiler
5. ColorPicker

Screenshot:
Spoiler
Last edited by tmplinshi on 30 Jun 2014, 05:23, edited 1 time in total.

tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by tmplinshi » 28 Jan 2014, 09:20

Lookup keywords in chm file

ahk_help.py:
Spoiler
Install
  • Save above code to \Data\Packages\User\ahk_help.py
  • Open ahk_help.py, and modify D:\\Program Files\\AutoHotkey\\AutoHotkey.chm to your chm file path.
  • Add a hotkey to Preferences > Key Bindings - User

    Code: Select all

    { "keys": ["alt+f1"], "command": "customhelp" }
Usage
Select a word or just place the cursor at the word , then press Alt+F1

Screenshot ( CustomHelp and StrokeIt )
Spoiler
Last edited by tmplinshi on 19 Mar 2014, 09:35, edited 2 times in total.

User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by jNizM » 19 Mar 2014, 01:57

GutterColor
Gutter Color is a Sublime Text plugin which displays a colored icon for all lines which contain a color.
Image
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

ryunp
Posts: 6
Joined: 14 Jan 2014, 02:01

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by ryunp » 30 Jul 2015, 17:49

While modifying the color theme for the github ST3 package I ended up customizing the tmLanguage syntax rules a bit.
Among a few changes, I wanted the text after Msgbox to appear the same as String color, but only when no % symbol was present. I nearly got it, but there is some overriding happening :/.

Image

If anyone is interested, here is the additions I made:
Inside AutoHotkey.tmLanguage

Code: Select all

<key>patterns</key>
	<array>
	
		...
		
		<dict>
			<key>match</key>
			<string>(?<=[Mm]sg[Bb]ox[, ])[\s\t]*[^%].*</string>
			<key>name</key>
			<string>support.function.msgbox.text.ahk</string>
		</dict>
		
		...
Inside YourThemeFile.tmTheme

Code: Select all

<string>YOUR THEME NAME HERE</string>
	<key>settings</key>
	<array>
		<dict>
			<key>settings</key>
			
			...
			
			<dict>
			<key>name</key>
			<string>Library class&#x2f;type</string>
			<key>scope</key>
			<string>support.function.msgbox.text</string>
			<key>settings</key>
			<dict>
				<key>fontStyle</key>
				<string>italic</string>
				<key>foreground</key>
				<string>#DDDD33</string>
			</dict>
		</dict>
		
		...

ryunp
Posts: 6
Joined: 14 Jan 2014, 02:01

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by ryunp » 30 Jul 2015, 19:14

Also, CHM Lookup is awesome.

For anyone looking to implement tmplinshi's CHM Lookup on ST3 with Python3 for Windows there are a few adjustments. For those less inclined to mess with the updating...
ST3 Path Change:
Pathing doesn't contain 'Data'; 'C:\Users\<user>\AppData\Roaming\Data\Sublime Text 3\Packages\User'

Update Python code to v3:
Unicode changes. You can remove my commented lines, but for brevity's sake I'll just outline the changes in-place.
tmplinshi wrote:

Code: Select all

# http://www.sublimetext.com/forum/viewtopic.php?f=3&t=689
 
# -*- coding: utf-8 -*-
# Some code based on http://d.hatena.ne.jp/pipehead/20071121/1195597559
import ctypes
from ctypes.wintypes import BOOL
 
import os
import sublime, sublime_plugin
 
# PYTHONv3: No need for ASCII to Unicode conversion (may as well keep for < Pv3 use)
def _T(string):
    if isinstance(string, str):
        string = unicode(string, 'utf-8')
    return string
 
HH_KEYWORD_LOOKUP = 0x000D
 
class c_tchar_p(ctypes._SimpleCData):
    _type_ = 'Z' # c_wchar_p
 
class HH_AKLINK(ctypes.Structure):
    _fields_ = (
        ('cbStruct',     ctypes.c_int), # sizeof this structure
        ('fReserved',    BOOL),         # must be FALSE (really!)
        ('pszKeywords',  c_tchar_p),    # semi-colon separated keywords
        ('pszUrl',       c_tchar_p),    # URL to jump to if no keywords found (may be NULL)
        ('pszMsgText',   c_tchar_p),    # Message text to display in MessageBox if pszUrl is NULL and no keyword match
        ('pszMsgTitle',  c_tchar_p),    # Message text to display in MessageBox if pszUrl is NULL and no keyword match
        ('pszWindow',    c_tchar_p),    # Window to display URL in
        ('fIndexOnFail', BOOL)          # Displays index if keyword lookup fails.
  )
 
class CustomhelpCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        selected = []
        for region in self.view.sel():
            selected.append(self.view.substr(self.view.word(region)) if region.empty() else self.view.substr(region))
        selected = ';'.join(selected)
        # PYTHONv3: Print now a function
        #print 'Displaying help topics for:', selected
        print('Displaying help topics for:', selected)
 
        # PYTHONv3: Implicit unicode strings (no need for '_T()')
        #ak = HH_AKLINK(ctypes.sizeof(HH_AKLINK), False, _T(selected), None, None, None, None, True)
        ak = HH_AKLINK(ctypes.sizeof(HH_AKLINK), False, selected, None, None, None, None, True)
        HtmlHelp = ctypes.windll.LoadLibrary('hhctrl.ocx').HtmlHelpW
        #HtmlHelp(ctypes.windll.user32.GetDesktopWindow(), _T('C:\\Program Files\\AutoHotkey\\AutoHotkey.chm'), HH_KEYWORD_LOOKUP, ctypes.byref(ak))
        HtmlHelp(ctypes.windll.user32.GetDesktopWindow(), 'C:\\Program Files\\AutoHotkey\\AutoHotkey.chm', HH_KEYWORD_LOOKUP, ctypes.byref(ak))
 
    def isEnabled(self, view, args):
      return True

20170201225639
Posts: 144
Joined: 01 Feb 2017, 22:57

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by 20170201225639 » 22 Apr 2017, 07:11

very minor thing:

there's a small bug in the Sublime4Autohotkey autuhotkey syntax file that's never been fixed, i.e. it wouldn't recognize variable names with #, @, and $ in them as legit.
as a result these names wouldn't get properly highlighted and indexed (for e.g. showing up in autocomplete)
if you use these symbols, here's how to fix this:

Image

after doing this you may also want to edit the config file to make these symbols not "word separators" (so you can doubleclick on a variable containing $ and select the whole name)


another problem with the syntax file is that function declarations with opening brace on a new line ('cuddled' brace style) doesn't get recognized as legit. still trying to figure out how to fix this ...

User avatar
Cerberus
Posts: 172
Joined: 12 Jan 2016, 15:46

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by Cerberus » 28 Jan 2018, 13:26

Thank you, everyone, for these great tips! I've added a couple to my Sublime Text.

As to properly highlighting function definitions where the curly brace comes on the next line, it cannot be done in Sublime Text, it's hardcoded that way. The problem is that a regex cannot look beyond the end of the current line, for reasons of performance. This will not change.

The only thing you could do is add a comment after the function definition, on the same line:

Code: Select all

MyFunction()          ;{
{
That the regex can recognise (though it's hardly a solution: I myself will just put the real brace on the same line as the function name, which works fine in Autohotkey). Then you can edit the regex in the tmlanguage file for the 'functionline.ahk' class such that it looks for this:

Code: Select all

^\s*(\w+)(\()(.*)(\))\s*({|\s(?=;{))\s*(;?.*)$
Does anyone have any new tips or ideas? Or are people not using Sublime Text any more?

Kryu
Posts: 7
Joined: 26 Sep 2016, 13:25

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by Kryu » 14 May 2018, 15:55

Cerberus wrote:Thank you, everyone, for these great tips! I've added a couple to my Sublime Text.

As to properly highlighting function definitions where the curly brace comes on the next line, it cannot be done in Sublime Text, it's hardcoded that way. The problem is that a regex cannot look beyond the end of the current line, for reasons of performance. This will not change.

The only thing you could do is add a comment after the function definition, on the same line:

Code: Select all

MyFunction()          ;{
{
That the regex can recognise (though it's hardly a solution: I myself will just put the real brace on the same line as the function name, which works fine in Autohotkey). Then you can edit the regex in the tmlanguage file for the 'functionline.ahk' class such that it looks for this:

Code: Select all

^\s*(\w+)(\()(.*)(\))\s*({|\s(?=;{))\s*(;?.*)$
Does anyone have any new tips or ideas? Or are people not using Sublime Text any more?
I tried to fix this, but I failed.
If anyone know how to fix this, please, help.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by swagfag » 14 May 2018, 17:42

You can't fix this. Not whilst using .tmLang files for doing the syntax highlighting, as they can only ever parse a single line at a time. There is virtually no way for the lexer to know an opening brace is coming up on the line below belonging to a function declaration.

Kryu
Posts: 7
Joined: 26 Sep 2016, 13:25

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by Kryu » 15 May 2018, 13:11

swagfag wrote:You can't fix this. Not whilst using .tmLang files for doing the syntax highlighting, as they can only ever parse a single line at a time. There is virtually no way for the lexer to know an opening brace is coming up on the line below belonging to a function declaration.
This is sad.
I'm really addicted to multiple edit possibilities that Sublime has, but this syntax issue breaks 'go to definition'.
:/

User avatar
Cerberus
Posts: 172
Joined: 12 Jan 2016, 15:46

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by Cerberus » 22 Jun 2018, 21:13

Kryu wrote:
swagfag wrote:You can't fix this. Not whilst using .tmLang files for doing the syntax highlighting, as they can only ever parse a single line at a time. There is virtually no way for the lexer to know an opening brace is coming up on the line below belonging to a function declaration.
This is sad.
I'm really addicted to multiple edit possibilities that Sublime has, but this syntax issue breaks 'go to definition'.
:/
I apologize for replying so late. So what I suggested is not really a solution, but it is a good work-around. You need to change function lines in every Autohotkey script where you want this highlighting to appear, or it won't work. The change goes as follows. Old line:

Code: Select all

MyFunction(Parameter)
{
...
}
New Line:

Code: Select all

MyFunction(Parameter)        ;{
{
...
}
So the only change is adding that little comment in each function definition where you want this highlighting. The advantage is that you don't need to change the code itself, only add that comment. The line numbers won't change.

Then you need to make a change in the syntax file, but you only need to do that once (see my earlier message).

If you can't make it work, I'll try to help. Or maybe you'll decide that it isn't worth it and you'll just change your scripts to use the one-true-brace style, which already has the proper highlighting:

Code: Select all

MyFunction(Parameter) {
...
}

Inserio
Posts: 5
Joined: 29 Jul 2018, 14:49

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by Inserio » 29 Jul 2018, 14:54

ryunp wrote:Also, CHM Lookup is awesome.

For anyone looking to implement tmplinshi's CHM Lookup on ST3 with Python3 for Windows there are a few adjustments. For those less inclined to mess with the updating...
ST3 Path Change:
Pathing doesn't contain 'Data'; 'C:\Users\<user>\AppData\Roaming\Data\Sublime Text 3\Packages\User'

Update Python code to v3:
Unicode changes. You can remove my commented lines, but for brevity's sake I'll just outline the changes in-place.
tmplinshi wrote:

Code: Select all

# http://www.sublimetext.com/forum/viewtopic.php?f=3&t=689
 
# -*- coding: utf-8 -*-
# Some code based on http://d.hatena.ne.jp/pipehead/20071121/1195597559
import ctypes
from ctypes.wintypes import BOOL
 
import os
import sublime, sublime_plugin
 
# PYTHONv3: No need for ASCII to Unicode conversion (may as well keep for < Pv3 use)
def _T(string):
    if isinstance(string, str):
        string = unicode(string, 'utf-8')
    return string
 
HH_KEYWORD_LOOKUP = 0x000D
 
class c_tchar_p(ctypes._SimpleCData):
    _type_ = 'Z' # c_wchar_p
 
class HH_AKLINK(ctypes.Structure):
    _fields_ = (
        ('cbStruct',     ctypes.c_int), # sizeof this structure
        ('fReserved',    BOOL),         # must be FALSE (really!)
        ('pszKeywords',  c_tchar_p),    # semi-colon separated keywords
        ('pszUrl',       c_tchar_p),    # URL to jump to if no keywords found (may be NULL)
        ('pszMsgText',   c_tchar_p),    # Message text to display in MessageBox if pszUrl is NULL and no keyword match
        ('pszMsgTitle',  c_tchar_p),    # Message text to display in MessageBox if pszUrl is NULL and no keyword match
        ('pszWindow',    c_tchar_p),    # Window to display URL in
        ('fIndexOnFail', BOOL)          # Displays index if keyword lookup fails.
  )
 
class CustomhelpCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        selected = []
        for region in self.view.sel():
            selected.append(self.view.substr(self.view.word(region)) if region.empty() else self.view.substr(region))
        selected = ';'.join(selected)
        # PYTHONv3: Print now a function
        #print 'Displaying help topics for:', selected
        print('Displaying help topics for:', selected)
 
        # PYTHONv3: Implicit unicode strings (no need for '_T()')
        #ak = HH_AKLINK(ctypes.sizeof(HH_AKLINK), False, _T(selected), None, None, None, None, True)
        ak = HH_AKLINK(ctypes.sizeof(HH_AKLINK), False, selected, None, None, None, None, True)
        HtmlHelp = ctypes.windll.LoadLibrary('hhctrl.ocx').HtmlHelpW
        #HtmlHelp(ctypes.windll.user32.GetDesktopWindow(), _T('C:\\Program Files\\AutoHotkey\\AutoHotkey.chm'), HH_KEYWORD_LOOKUP, ctypes.byref(ak))
        HtmlHelp(ctypes.windll.user32.GetDesktopWindow(), 'C:\\Program Files\\AutoHotkey\\AutoHotkey.chm', HH_KEYWORD_LOOKUP, ctypes.byref(ak))
 
    def isEnabled(self, view, args):
      return True
I had to edit this to include

Code: Select all

         HtmlHelp(ctypes.windll.user32.ShowWindow(), 'C:\\Program Files\\AutoHotkey\\AutoHotkey.chm', 1)
after the

Code: Select all

         HtmlHelp(ctypes.windll.user32.GetDesktopWindow(), 'C:\\Program Files\\AutoHotkey\\AutoHotkey.chm', HH_KEYWORD_LOOKUP, ctypes.byref(ak))
line in order to get the help window to pop up in front when Sublime Text was maximized.
I imagine that could be written better but I know nothing about python coding and just adapted stuff from elsewhere until something worked.

User avatar
Cerberus
Posts: 172
Joined: 12 Jan 2016, 15:46

Re: Sublime Text Resources - [plugins, lang files, etc.]

Post by Cerberus » 07 Apr 2019, 20:11

Inserio wrote:
29 Jul 2018, 14:54
...
I imagine that could be written better but I know nothing about python coding and just adapted stuff from elsewhere until something worked.
Thanks for the tip! Added.

Post Reply

Return to “Editors”