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
Support for a Vintage-style "Jump to Matching Bracket" Command #412
Comments
Add BH always defers to the bracket on the left when given two choices. That allows for consistency. Maybe some matchers defer to the right. Left is what I chose though when I wrote this. I get the impression that you expect it to defer right. Changing the whole match engine's preference (or providing a configurable preference) would be kind of a pain. Not sure if I'm willing to do that. So, as an example, if you are allowing the cursor to match a bracket when it is on adjacent on the outside ( |
As for controlling where the cursor is placed for a given match, you write your own bh_plugin using the current when to get you started: https://github.com/facelessuser/BracketHighlighter/blob/master/bh_modules/bracketselect.py. You can drop your personal one in a subdirectory in your user directory and load it instead of the provided one. But preference will still be left unless I overhaul things in the future. |
Thanks for the quick reply. Setting It just occurred to me that I may have over complicated my original description. I believe the behavior I'm looking for boils down to getting the "Find Matching Offscreen Bracket" "jump to bracket" link behavior as its own command. That is: How feasible is it to get the behavior of the link separated out into its own command? I took a look at bh_popup.py, and it wasn't clear to me how the jumping happens. |
Try block cursor mode as well. Turn off "outside adjacent" and turn on block cursor mode. I forgot that I added this for a vintage user: #275. // Experimental outside adjancent bracket matching
"bracket_outside_adjacent": false,
// EXPERIMENTAL: Special matching mode for block cursor.
// Essentially, this provides a matching mode that makes a little more
// sense to some in regards to the visual representation of block cursors.
// This will override "match_only_adjacet" and "bracket_outside_adjacent".
"block_cursor_mode": true, Anyways, I think this "block mode" is more what you are looking for. |
But to position cursor "on" the character when matching, you would need to modify the bh_plugin I pointed you at. |
Great, that's exactly it. Thanks for the help! I'll fiddle with a custom plugin and post here if I can get it working. |
As for how the popup works, it just get fed the bracket location and selects it. It's a little different than the bh_plugin |
Thanks for all the help. Basically, I removed the parts of
import BracketHighlighter.bh_plugin as bh_plugin
import sublime
class ViMoveToBracket(bh_plugin.BracketPluginCommand):
"""
Move to Bracket plugin for Vintage.
Based on [Select Bracket plugin](https://github.com/facelessuser/BracketHighlighter/blob/master/bh_modules/bracketselect.py).
"""
def run(self, edit, name):
"""
Jump to matching bracket
"""
self.current_left, self.current_right = self.selection[0].begin(), self.selection[0].end()
first, last = self.left.end, self.right.begin
first, last = self.select_match(name, first, last)
self.selection = [sublime.Region(first, last)]
def select_match(self, name, first, last):
"""Select the matching bracket."""
if self.left.end != self.right.end:
first, last = self.right.begin, self.right.begin
if first == self.current_left and last == self.current_right:
self.refresh_match = True
first, last = self.left.end - 1, self.left.end - 1
else:
first, last = self.right.end, self.right.end
if first == self.current_left and last == self.current_right:
self.refresh_match = True
return first, last
def plugin():
"""Make plugin available."""
return ViMoveToBracket
{
"keys": ["ctrl+m"],
"command": "bh_key",
"args": {
"lines" : true,
"plugin": {
"type": ["__all__"],
"command": "User.bh_modules.vimovetobracket"
}
}
}, |
Maybe in the future I will add a vim like bracket select module by default that people can use if they want to. Anyways, glad you solved your problem. I'll go ahead and close this for now. |
I've added a gist. Any updates I make will go there. |
Description
I am trying to implement a Vintage-style move to brackets command. The command jumps between matching brackets. BH has "jump to left" and "jump to right", but not "jump to matching". Essentially, I want "Find Matching Offscreen Bracket", but without the requirement for the match to be offscreen.
After some experimentation, this is what I ended up with:
In the following descriptions, an underscore before a character indicates that the cursor is on that character. For each pair of lines, the first line indicates the state before running the command, and the second line indicates the state after.
It meets the following requirements.
When the cursor is on a left bracket, it jumps to the right bracket:
When the cursor is in between a pair of brackets, it jumps to the innermost right bracket.
It does not meet the following requirements.
When the cursor is on a right bracket, it should jump to the left bracket. Instead, it jumps to the character after the left bracket.
It also has the following unexpected behaviors in specific cases.
I'm guessing the root cause of all of these is that the command was not designed to work when the cursor is on characters as opposed to in between characters.
Is it possible to get the behavior I want, and, if so, how?
Of course, thanks for all the hard work on an incredibly helpful plugin.
Support Info
The text was updated successfully, but these errors were encountered: