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

Allow specification of arbitrary brackets #12

Closed
ryanlecompte opened this issue Jan 2, 2012 · 24 comments
Closed

Allow specification of arbitrary brackets #12

ryanlecompte opened this issue Jan 2, 2012 · 24 comments

Comments

@ryanlecompte
Copy link

I'm a Ruby developer and would love to be able to have "def" and "end" tags highlighted for method definitions to help see them aligned properly. Things like this:

if ...
end

def foo
end

while ...
end

until ..
end

Would this be possible with this plugin or is it out of scope?

Thanks!

@facelessuser
Copy link
Owner

They are related in a way, but probably not enough algorithmically to fit in with the current implementation.

There would be special considerations to take into account if this were implemented. I would need to allow for lists for each kind of syntax: ruby, c/c++, etc. to allow searching only for related blocks only in that language. We would want to limit the searching to the current syntax to limit the strain on the algorithm; the more searching that is allowed, the longer it would take.

It is surely possible, but I fear that trying to squeeze it into the current BracketHighlighter frame work might be difficult to do well without bloating it. With that said, there is nothing saying I couldn't just write a specific plugin to do exactly this; I have often wanted such functionality in languages.

Though I feel this is probably out of scope for this plugin, I will leave the issue open until I have some time to evaluate if I would like to try and squeeze this into this plugin, write a separate plugin, or pass altogether (this would be most likely if someone gets to it before me; I don't yet know when I would undertake this).

@ryanlecompte
Copy link
Author

Thanks for explaining your thoughts regarding this issue. After thinking about it a bit more, I also agree that it's most likely out of scope for the current plugin. Thanks again!

@charlesroper
Copy link

I came to the repo looking for something similar. I use Markdown a lot and would like a way of including asterisks and underscores. Trouble with this is that the opening and closing tokens are the same, so I'm guessing that makes it harder to implement.

@facelessuser
Copy link
Owner

Meh. Not necessarily more difficult to implement. I am highlighting quotes which are identical. In cases like this, using the underlying scope of the syntax highlighter can help. I am still on the fence about this though because the algorithm is streamlined to find very specific things fairly quickly.

Implementing a bunch of different matches could bog things down if they are not restricted to certain file types. If I were to do something like this, I would also need to come up with a more generalized way to handle such things or the code could become a huge mess in a hurry.

As mentioned earlier, this request is more than likely out of scope of bracket highlighter which really is mainly geared towards brackets and bracket related things (HTML tags leverage the angle bracket matching). Strings were also added so I could search for brackets within strings/regex.

I haven't really sat down yet to fully think about this yet; I have been pretty busy with other stuff. I will update this issue when I have made a decision.

@askeeve
Copy link

askeeve commented Jul 9, 2012

I wonder, would it be easy enough for somebody to modify the package locally for something like this? I have a strange syntax to work with where lists start with a ` and end with a ' . Would I be able to replace something like angle-brackets, which I don't use, with these for my own use? Also, would this matching be likely to interfere with a single-quoted string match?

Thanks so much!

@facelessuser
Copy link
Owner

@askeeve you wouldn't need to replace angle. Since the starting character and ending character are different, you could probably easily add just another rule. Also, angle is needed for tag matching.

in BracketHighlighter.py you could add a bracket type called special. Just follow the two examples below. These are the only two places you need to add them.

    def init_brackets(self):
        quote_open = "r ' \""
        quote_close = "' \""
        return {
            'bh_curly':  self.get_bracket_settings('curly', '{', '}'),
            'bh_round':  self.get_bracket_settings('round', '(', ')'),
            'bh_square': self.get_bracket_settings('square', '[', ']'),
            'bh_special': self.get_bracket_settings('special', '`', '\''),
            'bh_angle':  self.get_bracket_settings('angle', '<', '>'),
            'bh_tag':    self.get_bracket_settings('tag', '<', '>'),
            'bh_quote':  self.get_bracket_settings('quote', quote_open, quote_close)
        }
    def init_match(self):
        # Current language
        syntax = self.view.settings().get('syntax')
        language = basename(syntax).replace('.tmLanguage', '').lower() if syntax != None else "plain text"
        # Reset objects
        self.sels = []
        self.targets = []
        self.highlight_us = {}
        self.lines = 0

        # Standard Brackets
        if self.exclude_bracket('bh_curly', language) == False:
            self.add_bracket('bh_curly')
        if self.exclude_bracket('bh_round', language) == False:
            self.add_bracket('bh_round')
        if self.exclude_bracket('bh_square', language) == False:
            self.add_bracket('bh_square')
        if self.exclude_bracket('bh_angle', language) == False:
            self.add_bracket('bh_angle')
        if self.exclude_bracket('bh_special', language) == False:
            self.add_bracket('bh_special')

After that, you would just need to add all the settings in the settings file.

So if there was a setting called round_language_list, you would create one called special_language_list. Also special_scope, special_style, etc. Obviously for the icon, you would have to use something generic like dot.

You can replace the special with whatever name you want. This works well for simple single character brackets that are different.

Brackets that have the opening the same as the closing are much different and require special handling. If one day I generalize the quote matching enough, I may be able to allow for simple addition of single character same brackets. Then I could just expose a setting allowing for defining bracket rules. Multi-character opening and closing brackets is much more difficult in the current algorithm and would require me shuffling a lot around.

@askeeve
Copy link

askeeve commented Jul 9, 2012

That seems to work fantastically! Thank you so much. One small issue (and
I probably should have mentioned this before) inside the ' syntax, items are separated by ,'s. It looks like if the cursor is on or just to the right of a comma the highlight turns off for the and '. Is there
something simple I'm overlooking for this? Thanks!

On Mon, Jul 9, 2012 at 12:35 PM, Isaac Muse <
reply@reply.github.com

wrote:

@askeeve you wouldn't need to replace angle. Since the starting character
and ending character are different, you could probably easily add just
another rule.

in BracketHighlighter.py you could add a bracket type called
special. Just follow the two examples below. These are the only two
places you need to add them.

    def init_brackets(self):
        quote_open = "r ' \""
        quote_close = "' \""
        return {
            'bh_curly':  self.get_bracket_settings('curly', '{', '}'),
            'bh_round':  self.get_bracket_settings('round', '(', ')'),
            'bh_square': self.get_bracket_settings('square', '[', ']'),
            'bh_special': self.get_bracket_settings('special', '`', '\''),
            'bh_angle':  self.get_bracket_settings('angle', '<', '>'),
            'bh_tag':    self.get_bracket_settings('tag', '<', '>'),
            'bh_quote':  self.get_bracket_settings('quote', quote_open,
quote_close)
        }
    def init_match(self):
        # Current language
        syntax = self.view.settings().get('syntax')
        language = basename(syntax).replace('.tmLanguage', '').lower() if
syntax != None else "plain text"
        # Reset objects
        self.sels = []
        self.targets = []
        self.highlight_us = {}
        self.lines = 0

        # Standard Brackets
        if self.exclude_bracket('bh_curly', language) == False:
            self.add_bracket('bh_curly')
        if self.exclude_bracket('bh_round', language) == False:
            self.add_bracket('bh_round')
        if self.exclude_bracket('bh_square', language) == False:
            self.add_bracket('bh_square')
        if self.exclude_bracket('bh_angle', language) == False:
            self.add_bracket('bh_angle')
        if self.exclude_bracket('bh_special', language) == False:
            self.add_bracket('bh_special')

After that, you would just need to add all the settings in the settings
file.

So if there was a setting called round_language_list, you would
create one called special_language_list. Also special_scope,
special_style, etc. Obviously for the icon, you would have to use
something generic like dot.

You can replace the special with whatever name you want. This works
well for simple single character brackets that are different.

Brackets that have the opening the same as the closing are much different
and require special handling. If one day I a generalize the quote matching
enough, I may be able to allow for simple addition of single character same
brackets. Then I could just expose a setting allowing for defining bracket
rules. Multi-character opening and closing brackets is much more difficult
in the current algorithm and would require me shuffling a lot around.


Reply to this email directly or view it on GitHub:

#12 (comment)

-Adam

@facelessuser
Copy link
Owner

Tough to say without me playing with it. If you can fork BracketHighlighter and add your changes and maybe post an example file with your special syntax, I can play with it when I have time and maybe give you an answer/possible fix. Nothing comes to mind off the top of my head that would cause this; so I would have to play with it.

@askeeve
Copy link

askeeve commented Jul 9, 2012

Fair enough, I'll play around with it a little more and see about doing that if I can't figure it out. Thanks!

@facelessuser
Copy link
Owner

@ryanlecompte
I am doing a possible re-write. Performance will determine if it sees the light of day, but so far I am optimistic.

This is in very, very early stages. I have been tinkering with it only for a little, and it has quite a bit until it can catch up feature wise. But if it goes well, something like this may appear in BH2.

As originally requested...highlighting of ruby if|while|do etc.

The method of detecting brackets is much different allowing me to grab multi char brackets (obviously using brackets loosely here). I haven't worked out how I will expose this functionality to the user, but I am hoping to abstract it enough to essentially allow for modules to be dropped in for whatever language quirks a user would like to add...we shall see though.

@charlesroper
I don't see a problem with BH2 also supporting your markdown interests either. It appears that the markdown tmLanguage in ST2 scopes the entire underline or bold etc. with a consistant identifiable scope.

I imagine there would be two kinds of bracket styles a user could define. One where end caps are specified, and one where the scope is the base...like strings is done, and how markdown bold, underline would be done.

If you guys still have interest in this feature, when I get it more fleshed out (and if it doesn't to turn to crap on me), I may need some testers.

@ryanlecompte
Copy link
Author

Awesome work!!!!!

On Oct 1, 2012, at 8:34 PM, Isaac Muse notifications@github.com wrote:

@ryanlecompte
I am doing a possible re-write. Performance will determine if it sees the light of day, but so far I am optimistic.

This is in very, very early stages. I have been tinkering with it only for a little, and it has quite a bit until it can catch up feature wise. But if it goes well, something like this may appear in BH2.

As originally requested...highlighting of ruby if|while|do etc.

The method of detecting brackets is much different allowing me to grab multi char brackets (obviously using brackets loosely here). I haven't worked out how I will expose this functionality to the user, but I am hoping to abstract it enough to essentially allow for modules to be dropped in for whatever language quirks a user would like to add...we shall see though.

@charlesroper
I don't see a problem with BH2 also supporting your markdown interests either. It appears that the markdown tmLanguage in ST2 scopes the entire underline or bold etc. with a consistant identifiable scope.

I imagine there would be two kinds of bracket styles a user could define. One where end caps are specified, and one where the scope is the base...like strings is done, and how markdown bold, underline would be done.

If you guys still have interest in this feature, when I get it more fleshed out (and if it doesn't to turn to crap on me), I may need some testers.


Reply to this email directly or view it on GitHub.

@charlesroper
Copy link

Sweet. Definitely interested in this. Also been doing some rst lately so it
would be useful there too.

Thanks for doing into this - very much appreciated.

@facelessuser
Copy link
Owner

@charlesroper
Thought you might like this.

Completely generalized. This is done simply by an entry in the settings file:

        {
            "open": "(\\*|_)",
            "close": "(\\*|_)",
            "highlight_subgroup": [1, 1],
            "name": "mditalic",
            "color": "bracket.curly",
            "language_filter": "whitelist",
            "language_list": ["Markdown"],
            "scopes": ["markup.italic"],
            "style": "underline",
            "icon": "dot",
            "enabled": true
        },
        {
            "open": "(\\*\\*|__)",
            "close": "(\\*\\*|__)",
            "highlight_subgroup": [1, 1],
            "name": "mdbold",
            "color": "keyword",
            "language_filter": "whitelist",
            "language_list": ["Markdown"],
            "scopes": ["markup.bold"],
            "style": "underline",
            "icon": "dot",
            "enabled": true
        }

Things are still subject to change, but right now I am thinking it might look something like that for people to create their own scope based brackets. Traditional brackets will be slightly different. Still working towards a testable alpha, but I am very pleased in the progress made so far.

@charlesroper
Copy link

That, frankly, is music to my eyes. Nice one indeed, and sincere thanks.

@facelessuser
Copy link
Owner

New algorithm seems to be faster as well. In retrospect this makes sense, but initially I though the inverse would be true. So this is looking like a win win re-write. This means thresholds can be extended further without slowing things down.

@facelessuser
Copy link
Owner

I am thinking sometime next week I will have a testable branch.

@facelessuser
Copy link
Owner

An early Alpha branch is up at https://github.com/facelessuser/BracketHighlighter/tree/BH2

I still need to add the bracket swapping and bracket removing plugin. There is no documentation right now so...you are on your own right now :).

Feel free to ask questions, make suggestions, report bugs, and do let me know how it is performing for you.

@facelessuser
Copy link
Owner

A couple of fixes since the initial Alpha post.

  • Icons path was incorrect in the settings file
  • Included bracket remove plugin
  • A number of other small tweaks

Make sure to restart ST2 after updating to this branch.

@charlesroper
Copy link

Just wanted to let you know I'm chronically busy at the moment and won't have a chance to have a look-see for another week or so. Didn't want you to think I was unappreciative - on the contrary, I'm really looking forward to digging in. 😃

@facelessuser
Copy link
Owner

No worries, I've had a couple people over on the forums trying it out and giving some feedback. It helped getting feedback about ruby; I think ruby support is much better now.

Also got some feedback on styling brackets and I am going to play around with that in the next number of days.

Just let me know what you think whenever you get a chance.

@facelessuser
Copy link
Owner

If you were using the alpha before now, I changed some important stuff in the settings file during the last commit that will require reconfiguring your personal settings again, but that should be last non-backwards compatible change hopefully. Also, shortcuts related to tags probably need to be reconfigured if you used those as well. See Example.sublime-keymap for examples.

@facelessuser
Copy link
Owner

The official release of BracketHighlighter 2 is coming very soon. All planned features are in. I simply need to write up the documentation, and if there are no critical bugs, I will release it. Hopefully it will have a positive reception. I believe it should be capable of handling most everyone's bracket desires now.

Now would probably be the time for anyone to file last minute issues or suggestions.

@facelessuser
Copy link
Owner

BracketHighlighter 2 is now on the master branch. This issue is now solved.

@charlesroper
Copy link

Thank you for your work on this Isaac, it's very much appreciated. Kudos.
On 23 Mar 2013 23:26, "Isaac Muse" notifications@github.com wrote:

BracketHighlighter 2 is now on the master branch. This issue is now solved.


Reply to this email directly or view it on GitHubhttps://github.com//issues/12#issuecomment-15348038
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants