Sublime Forum

BracketHighlighter

#150

It might be. BH is mostly optimized to find “matching” pairs. It is probably pretty reliable at finding left hanging brackets than it is at finding right hanging brackets. It is best if the brackets match though. This is mainly due to how complicated the system is for finding custom brackets and the fact that BH bails as soon has it is pretty sure it can’t find a match (less lag in searching keeps the plugin from annoying people). So it doesn’t always search both ways, but it usually starts out searching left first.

0 Likes

#151

First thank you for that great plugin! Can’t work without it.

Now i am looking at feature present in most editors, select the bracket scope content on double mouse click on bracket. This is very useful to select arrays and such.

Now i was wondering if that was possible with you plugin (maybe using command) without breaking the normal behaviour of double click (select word)
Finally it would need to select the brackets with it. i mention that because by using select scope content it doesnt actually select the brackets.

Thanks

0 Likes

#152

[quote=“farfromrefuge”]Now i am looking at feature present in most editors, select the bracket scope content on double mouse click on bracket. This is very useful to select arrays and such.

Now i was wondering if that was possible with you plugin (maybe using command) without breaking the normal behavior of double click (select word)[/quote]

Honestly, the current mouse API in Sublime sucks. I don’t think this can be done reliably.

I plan on adding a variant of the current command to select brackets as well github.com/facelessuser/Bracket … issues/132 …when I get some time and feel like working on it :smile:.

0 Likes

#153

I „fixed” the select the whole bracket scope by using this snippet (in .sublime-mousemap file, obviously)

{ "button": "button1", "count": 1, "modifiers": "button2"], "command": "expand_selection", "args": {"to": "brackets"}, "press_command": "drag_select" }

It doesn’t work on double click, but it works by holding click2 then press on click1 buttons.

0 Likes

#154

[quote=“iamntz”]I „fixed” the select the whole bracket scope by using this snippet (in .sublime-mousemap file, obviously)

{ "button": "button1", "count": 1, "modifiers": "button2"], "command": "expand_selection", "args": {"to": "brackets"}, "press_command": "drag_select" }

It doesn’t work on double click, but it works by holding click2 then press on click1 buttons.[/quote]

This doesn’t really “fix” it per se. BH selects more than common curly, round, and square brackets. BH has a number of custom brackets as well. Also the algorithm for built in ST bracket matching is different than BH, so this won’t always select what you see BH targeting (ST algorithm can be sometimes inconsistent with brackets next to each other, at least it use to be…haven’t checked recently).

The option of mouse modifier might be a nice touch though. As soon as I add the alternative bracket selection command (or command parameter), you should be able to use something like iamntz posted above for the BH variant that will target custom brackets as well.

0 Likes

#155

I know, that’s why i used quotes :wink:

Anyhow, for css(sass), php and js, this works every single time. Since the API sucks, we work with what we have :mrgreen:

0 Likes

#156

Man I completely missed those :smile:.

Anyways, thanks for sharing. I don’t use mouse maps at all, so it is nice to see things like that work…I should play around with the mouse maps a bit more.

0 Likes

#157

I added a flag for the bracket select command to always select the tags with content. So by just taking the current command and adding the always_include_brackets argument, you can select the content and tags:

[pre=#232628] // Select text including brackets
{
“keys”: “ctrl+alt+super+d”],
“command”: “bh_key”,
“args”:
{
“lines” : true,
“plugin”:
{
“type”: “all”],
“command”: “bh_modules.bracketselect”,
“args”: {“always_include_brackets”: true}
}
}
},[/pre]

Pair that with the mouse trick, and that should do it.

0 Likes

#158

no problem, thanks for answering !

0 Likes

#159

I can’t seem to get the mouse thing to work at all. The log says it’s firing, but nothing happens. Any ideas?

And thanks to the dev for adding that new always_include_brackets option. :smiley:

0 Likes

#160

@facelessuser

[quote]This is what you need:
{
“name”: “latex_floats”,
“open”: “(\\begin\{(?:table|sidewaystable|figure|sidewaysfigure|algorithm)\})”,
“close”: “(\\end\{(?:table|sidewaystable|figure|sidewaysfigure|algorithm)\})”,
// “open”: “(\begin\{sidewaystable\})”,
// “close”: “(\end\{sidewaystable\})”,
“style”: “default”,
“scope_exclude”: “string”, “comment”],
“language_filter”: “whitelist”,
“language_list”: “LaTeX”],
“enabled”: true
},
[/quote]

Am I correct in assuming that this will not work with nested constructs? E.g.:

\begin{figure}[thb]
    \begin{center}
         \includegraphics]{Fig_Geometric_Nonlinear_Examples/Roll-up_Dyn/timegeo1.eps}
    \end{center}
\end{figure}

I would think that it would be necessary to include an additional captured group in the open pattern, that was searched for in the close pattern. To try and get this to work I’ve been trying to hook up to the ht/xml tag matching. I tried adding the following (copying //HTML, and modifying the ends of the regex):

// LaTeX \begin{(...)} \end{(...)}
{
    "name": "latex",
    "open": "(\\\\begin\\{)(?=\\w\\:\\-]+(?:(?:\\s+\\w\\-:]+(?:\\s*=\\s*(?:\"^\"]*\"|'^']*'|^>\\s]+))?)*)\\s*\\/?>|\\/\\w\\:\\-]+^>]*\\})",
    "close": "(?<=\\\\end\\{)(?:\\w\\:\\-]+(?:(?:\\s+\\w\\-:]+(?:\\s*=\\s*(?:\"^\"]*\"|'^']*'|^>\\s]+))?)*)\\s*\\/?|\\/\\w\\:\\-]+^>]*)(\\})",
    "style": "tag",
    "scope_exclude": "string", "comment"],
    "language_filter": "whitelist",
    "language_list": "LaTeX"],
    "plugin_library": "bh_modules.tags",
    "find_in_sub_search": "only",
    "enabled": true
},

and then

"tag_mode": {
        "xhtml": "XML", "LaTeX"], ...

But I don’t get anything. I haven’t been able to find info on how to hook up custom tags.

0 Likes

#161

Probably will need to right a bh_plugin.

We have a proprietary language I have to use at work that is similar in this way:

for illustration

def somefunction var1 var2
        if (somecondition)
            some more code;
        eif
edef

So, I define my opening and closing brackets, and then sort out which opening matches to which closing by using a bh_plugin (do until is an exception):
[pre=#232628]def compare(name, first, second, bfr):
opening = bfrfirst.begin:first.end].lower()
closing = bfrsecond.begin:second.end].lower()
match = False
if opening == “do”:
if closing == “until”:
match = True
else:
match = “e” + opening == closing
return match[/pre]

Another example for handling case differences in PHP keywords:
github.com/facelessuser/Bracket … eywords.py

0 Likes

#162

Match when cursor is on outside edge of bracket:
Okay, everyone that has been wanting this, take some time to test the new experimental feature (ST3 only currently)

Add this setting to your “bh_core.sublime-settings”.

"bracket_outside_adjacent": true,

There is going to be some more overhead when this is turned on, but hopefully the impact won’t be too noticeable. I did this for you guys, so please do test and give feedback. If you are waiting for ST2, it may be a tomorrow or the day after.

0 Likes

#163

Few small things:

  1. It seems that this command doesn’t work anymore after the update (and boy, this command is damn useful!):
{ "keys": "ctrl+shift+space"], "command": "bh_key", "args": { "lines" : true, "plugin": { "type": "__all__"], "command": "bh_modules.bracketselect" } } }

The issue is present, with without bracket_outside_adjacent set to either true or false
2) add a different scope for adjacent, so it can have different color

0 Likes

#164
  1. This is now fixed. Funny, it had nothing to do with the new algorithm…just me with a stray mutli-cursor editing something I shouldn’t have.

  2. How come? Current algorithm doesn’t track such things. I would need to pass that info around, and it would require a bit of change to the code. Not sure I really want to spend time on that unless there was a really good reason.

FYI, I know tag outside adjacent just shows angles, I haven’t updated the tag bh_plugin with support yet.

0 Likes

#165

Tag support for experimental outside adjacent is in.

0 Likes

#166

Thanks! I had 3 hours of hell without that! :smiley:

About different highlight: my idea was only in case is an easy thing to do and it aims at certain situations like this:

There are some (probably) rare cases where highlight adjacent it may stay in your way. The idea is to highlight adjacent slightly different AND highlight regular brackets. So in the case i presented in the screenshots, outside brackets should be green, inside brackets should be dark (or light) green (or pink, or whatever i set in the colorscheme). Make sense?

0 Likes

#167

That just means you now appreciate me more :smile:.

Let me think about it. I don’t actually track whether I am catching an adjacent match currently. I inject some stuff to conditionally alter the algorithm to work in these adjacent cases, but it is rarely aware that the final matched brackets are in fact adjacent.

Right now, I am just happy I got it in. I have been putting it off for over a year because I just didn’t want to add more complexity to an already complex system. It really wasn’t as bad as I thought (once I finally spent real time analyzing what would need to be done). I know people have been wanting it though, so hopefully it works well, I figure with enough guinea pigs testing this out, we should hopefully find any overlooked problems.

0 Likes

#168

ST2 Experimental outside adjacent matching has been merged in.

Side note, I may add an additional option to have some bh_plugins ignore the “outside adjacent” setting. Things like pressing select and having it expand does not work with adjacent; instead, it just expands and shrinks over and over :smile:.

0 Likes

#169

Yay! Awesome thanks a lot, much appreciated. At first insight seems to work great, and looks mixed with inside adjacent which is handy. I’ll report back any oddities; I’ve a feature request, (that I have no idea if is complicated or not.)

When I put the cursor in
});|
It would be nice to skip the character “;” and highlight the bracket “)” this is handy for JavaScript. It would be also nice, something similar with “},|” skipping the “,”. But the comma should not be skipped for example with quotes as “aasdasd”,|

Thanks! :slight_smile:

0 Likes