Sublime Forum

AStyleFormatter plugin gets run on Markdown files

#1

I use the AStyleFormatter plugin and set it to automatically format my file when I save. This is really good when I’m writing C++ and so on.

However, its save-hook gets activated by the Markdown syntax if my cursor happens to be inside a fenced code block when I save.

Is there any way to have Markdown not activate a fenced code block’s save hook when I save the file, or have it only apply to the code block in some way? It’s pretty annoying when this happens.

0 Likes

#2

It looks like the plugin author had switched to VSCode. You may have to modify the source code by yourself.


change

into

def get_syntax_for_view(view):
    first_selection = view.sel()[0]
    if first_selection.empty():
        caret = 0
    else:
        caret = first_selection.a
    syntax = SYNTAX_RE.search(view.scope_name(caret))
    if syntax is None:
        return ''
    return syntax.group(0).lower()
1 Like

#3

Thanks. I use PackageControl to keep my packages in sync and I’ve never done anything with writing my own packages - is there a quick guide for how to make a package local? I assume it’s just a matter of moving it into my synchronized User/Packages/ (or whatever) folder and doing the edits there?

0 Likes

#4

The simplest way would be to install PackageResourceViewer. Open Command Palette, type PVR, then Open Resource. Select AStyleFormat.py, find get_syntax_for_view, make the necessary changes, (or copy and paste), save the file, and restart Sublime Text.

2 Likes