Sublime Forum

Auto Align (Symbolic)

#1

It would be great, if I can have auto align feature for my codes based on symbols.
Is it possible?

I understand, its hard to get, if I desire it for many symbols:

But, can I have it at least for “:”?
:slight_smile:

1 Like

#2

I am working on a tool to do this and more for any language, in a correct way. It should take at least a year before I finish it. Until there you can experiment using the same thing you did on this other question:

import sublime_plugin

class AlwaysAutoAlignByFirstColon(sublime_plugin.EventListener):

    def on_modified_async(self, view):
        base_scopes = self.view.scope_name(0)
        target_scopes = \
        [ 
            "source.css",
        ]

        if is_on_valid_scope( base_scopes, target_scopes ):
            view.run_command( "align_tab", {"user_input" : ":/f"} )

    def is_on_valid_scope(self, base_scopes, target_scopes):

        for target_scope in target_scopes:

            if target_scope in base_scopes:
                return True

        return False
0 Likes

#3

I actually have an align on regexp method in my package if it’s useful. It might be a skosh language specific, but maybe that can be worked around. I do alignment on various symbols. Hardest problem is knowing when to stop aligning.

0 Likes

#5

Can you please share the method you are trying for skosh? I think it should go fine if we can target specific files, like for example, “:” symbol should be all we want in CSS

0 Likes

#6

Maybe https://packagecontrol.io/packages/Align%20Arguments ? Can be configured by alignment characters etc.

0 Likes

#7

I apologize for the misunderstanding there. “Skosh” is an idiom, usually meaning “small”. And I took a look at my method and it’s got a lot of language specific things inside, though if it were parameterized, maybe that would be okay. In any event, if someone wants to take a look at it, or adopt it to something this is the method align_block_on_re: https://github.com/Remillard/VHDL-Mode/blob/b52457eed82f130fb61a5def6ece52a0bad4e950/vhdl_lang.py#L207

0 Likes

#8

I have installed the plugin and also added this is settings:

"align_arguments": {
  "line_length": 120,
  "one_per_line": true,
}

It’s not working and I dont have the deep knowledge to configure it my-self… :sweat:

0 Likes

#9

Hi Remi,
Please pardon me for not having deep knowledge. Can you please tell me how can I make it working?

0 Likes

#10

I’m afraid it’s not going to be a simple matter of binding this to a key. It requires some preparation work. A Sublime API method would be used to extract the text. It would be broken up into discrete lines, run this method against it, and then replace the original text, just for starters. Working it into a full fledged package is unfortunately something I do not currently have time for.

0 Likes