Skip to content

Commit

Permalink
Merge pull request #23 from ice9js/1.4
Browse files Browse the repository at this point in the history
AceJump 1.4
  • Loading branch information
ice9js committed Sep 20, 2015
2 parents cac76b7 + 6369034 commit be155d8
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Sublime Text files
ace-jump.sublime-project
ace-jump.sublime-workspace

# To do
*.TODO
37 changes: 36 additions & 1 deletion AceJump.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,40 @@
"labels": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",

// Syntax highlighting scope for the labels
"labels_scope": "invalid"
"labels_scope": "invalid",

// View settings that should be respected when switching the syntax
// highlighting mode. In case s plugin you use adds a new
// setting to a view, you probably want to add it to this list.
"view_settings": [
"auto_indent",
"tab_size",
"translate_tabs_to_spaces",
"use_tab_stops",
"trim_automatic_white_space",
"detect_indentation",
"draw_white_space",
"trim_trailing_white_space_on_save",
"always_show_minimap_viewport",
"color_scheme",
"font_face",
"font_options",
"gutter",
"rulers",
"draw_minimap_border",
"highlight_line",
"line_padding_top",
"line_padding_bottom",
"scroll_past_end",
"line_numbers",
"word_wrap",
"wrap_width",
"indent_subsequent_lines",
"draw_centered",
"match_brackets",
"match_brackets_content",
"match_brackets_square",
"match_brackets_braces",
"match_brackets_angle",
]
}
4 changes: 4 additions & 0 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@
{
"keys": ["alt+'"],
"command": "ace_jump_add_cursor"
},
{
"keys": ["alt+."],
"command": "ace_jump_after"
}
]
4 changes: 4 additions & 0 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@
{
"keys": ["ctrl+'"],
"command": "ace_jump_add_cursor"
},
{
"keys": ["ctrl+."],
"command": "ace_jump_after"
}
]
4 changes: 4 additions & 0 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@
{
"keys": ["alt+'"],
"command": "ace_jump_add_cursor"
},
{
"keys": ["alt+."],
"command": "ace_jump_after"
}
]
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ Again, when this mode is triggered, only jumps in the same file are available.

- ```Alt+'``` (```Ctrl+'``` for OS X)

### Jump-after mode

In this mode, the cursor will jump behind the targeted instance. Unfortunetely,
this mode cannot be paired with select or multiple cursor mode yet.

- ```Alt+.``` (```Ctrl+.``` for OS X)

### Batching

In case there are more places to jump to than labels available, labels will be batched and you can cycle through them by simply pressing enter.
Expand Down
85 changes: 75 additions & 10 deletions ace_jump.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,39 @@ def get_active_views(window):
views.append(window.active_view_in_group(group))
return views

def set_views_syntax(views, syntax):
"""Sets the syntax highlighting for all given views"""
def set_views_setting(views, setting, values):
"""Sets the values for the setting in all given views"""

for i in range(len(views)):
views[i].set_syntax_file(syntax[i])
views[i].settings().set(setting, values[i])

def set_views_settings(views, settings, values):
"""Sets the values for all settings in all given views"""

def get_views_syntax(views):
"""Returns a list with syntax for each from the given views"""
for i in range(len(settings)):
set_views_setting(views, settings[i], values[i])

syntax = []
def get_views_setting(views, setting):
"""Returns the setting value for all given views"""

settings = []
for view in views:
syntax.append(view.settings().get('syntax'))
return syntax
settings.append(view.settings().get(setting))
return settings

def get_views_settings(views, settings):
"""Gets the settings for every given view"""

values = []
for setting in settings:
values.append(get_views_setting(views, setting))
return values

def set_views_syntax(views, syntax):
"""Sets the syntax highlighting for all given views"""

for i in range(len(views)):
views[i].set_syntax_file(syntax[i])

def set_views_sel(views, selections):
"""Sets the selections for all given views"""
Expand Down Expand Up @@ -63,7 +83,7 @@ def run(self):
self.breakpoints = []

self.all_views = get_active_views(self.window)
self.syntax = get_views_syntax(self.all_views)
self.syntax = get_views_setting(self.all_views, "syntax")
self.sel = get_views_sel(self.all_views)

settings = sublime.load_settings("AceJump.sublime-settings")
Expand All @@ -73,6 +93,12 @@ def run(self):
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
)

self.view_settings = settings.get("view_settings", [])
self.view_values = get_views_settings(
self.all_views,
self.view_settings
)

self.show_prompt(self.prompt(), self.init_value())

def show_prompt(self, title, value):
Expand Down Expand Up @@ -147,11 +173,18 @@ def add_labels(self, regex):
self.views.remove(view)

clear_views_sel(self.all_views)

set_views_syntax(self.all_views, list(itertools.repeat(
"Packages/AceJump/AceJump.tmLanguage",
len(self.all_views)
)))

set_views_settings(
self.all_views,
self.view_settings,
self.view_values
)

def remove_labels(self):
"""Removes all previously added labels"""

Expand All @@ -173,6 +206,7 @@ def jump(self, index):

self.window.focus_view(view)
view.run_command("perform_ace_jump", {"target": region})
self.after_jump(view)

def views_to_label(self):
"""Returns the views that still have to be labeled"""
Expand Down Expand Up @@ -201,6 +235,13 @@ def init_value(self):
def regex(self):
return r'\b{}'

def after_jump(self, view):
global mode

if mode == 3:
view.run_command("move", {"by": "word_ends", "forward": True})
mode = 0

class AceJumpCharCommand(AceJumpCommand):
"""Specialized command for char-mode"""

Expand All @@ -213,6 +254,13 @@ def init_value(self):
def regex(self):
return r'{}'

def after_jump(self, view):
global mode

if mode == 3:
view.run_command("move", {"by": "characters", "forward": True})
mode = 0

class AceJumpLineCommand(AceJumpCommand):
"""Specialized command for line-mode"""

Expand All @@ -225,6 +273,14 @@ def init_value(self):
def regex(self):
return r'(.*)[^\s](.*)\n'

def after_jump(self, view):
global mode

if mode == 3:
view.run_command("move", {"by": "lines", "forward": True})
view.run_command("move", {"by": "characters", "forward": False})
mode = 0

class AceJumpSelectCommand(sublime_plugin.WindowCommand):
"""Command for turning on select mode"""

Expand All @@ -241,6 +297,15 @@ def run(self):

mode = 0 if mode == 2 else 2

class AceJumpAfterCommand(sublime_plugin.WindowCommand):
"""Modifier-command which lets you jump behind a character, word or line"""

def run(self):
global mode

mode = 0 if mode == 3 else 3
print(mode)

class AddAceJumpLabelsCommand(sublime_plugin.TextCommand):
"""Command for adding labels to the views"""

Expand Down Expand Up @@ -299,7 +364,7 @@ class PerformAceJumpCommand(sublime_plugin.TextCommand):
"""Command performing the jump"""

def run(self, edit, target):
if mode == 0:
if mode == 0 or mode == 3:
self.view.sel().clear()

self.view.sel().add(self.target_region(target))
Expand Down

0 comments on commit be155d8

Please sign in to comment.