feat(SublimeText2.EditorPackages): cache packages

This commit is contained in:
Iristyle
2013-04-04 08:55:15 -04:00
parent d65666cdfc
commit c3efdad2c2
274 changed files with 26863 additions and 0 deletions

View File

@@ -0,0 +1 @@
*.pyc

View File

@@ -0,0 +1,22 @@
[
{
"keys": ["ctrl+;", "<character>"],
"command": "easy_motion",
"args": {"select_text": false}
},
{
"keys": ["ctrl+;", "enter"],
"command": "easy_motion",
"args": {"select_text": false, "character": "enter"}
},
{
"keys": ["ctrl+shift+;", "<character>"],
"command": "easy_motion",
"args": {"select_text": true}
},
{
"keys": ["ctrl+shift+;", "enter"],
"command": "easy_motion",
"args": {"select_text": true, "character": "enter"}
}
]

View File

@@ -0,0 +1,22 @@
[
{
"keys": ["super+;", "<character>"],
"command": "easy_motion",
"args": {"select_text": false}
},
{
"keys": ["super+;", "enter"],
"command": "easy_motion",
"args": {"select_text": false, "character": "enter"}
},
{
"keys": ["super+shift+;", "<character>"],
"command": "easy_motion",
"args": {"select_text": true}
},
{
"keys": ["super+shift+;", "enter"],
"command": "easy_motion",
"args": {"select_text": true, "character": "enter"}
}
]

View File

@@ -0,0 +1,22 @@
[
{
"keys": ["ctrl+;", "<character>"],
"command": "easy_motion",
"args": {"select_text": false}
},
{
"keys": ["ctrl+;", "enter"],
"command": "easy_motion",
"args": {"select_text": false, "character": "enter"}
},
{
"keys": ["ctrl+shift+;", "<character>"],
"command": "easy_motion",
"args": {"select_text": true}
},
{
"keys": ["ctrl+shift+;", "enter"],
"command": "easy_motion",
"args": {"select_text": true, "character": "enter"}
}
]

View File

@@ -0,0 +1,23 @@
[
/* haven't figured out why yet, but for some reason you need to hit ctrl+c or escape twice to get it to deactivate jump targets */
{
"keys": ["ctrl+c"],
"command": "deactivate_jump_targets", "context": [{"key": "setting.easy_motion_mode"}]
},
{
"keys": ["escape"],
"command": "deactivate_jump_targets", "context": [{"key": "setting.easy_motion_mode"}]
},
{
"keys": ["<character>"],
"command": "jump_to", "context": [{"key": "setting.easy_motion_mode"}]
},
{
"keys": ["enter"],
"command": "show_jump_group", "context": [{"key": "setting.easy_motion_mode"}]
},
{
"keys": ["shift+enter"],
"command": "show_jump_group", "context": [{"key": "setting.easy_motion_mode"}], "args": {"next": false}
}
]

View File

@@ -0,0 +1,11 @@
{
// defines syntax highlighting scope that will be used to highlight matched jump targets
// other examples include: keyword, string, number
"jump_target_scope" : "entity.name.class",
// define the characters that we can jump to, in the order that they'll appear, they should be unique
"placeholder_chars" : "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ",
// searches are case sensitive by default
"case_sensitive" : true
}

View File

@@ -0,0 +1,203 @@
/*
* Apache License
* Version 2.0, January 2004
* http://www.apache.org/licenses/
*
* TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
*
* 1. Definitions.
*
* "License" shall mean the terms and conditions for use, reproduction,
* and distribution as defined by Sections 1 through 9 of this document.
*
* "Licensor" shall mean the copyright owner or entity authorized by
* the copyright owner that is granting the License.
*
* "Legal Entity" shall mean the union of the acting entity and all
* other entities that control, are controlled by, or are under common
* control with that entity. For the purposes of this definition,
* "control" means (i) the power, direct or indirect, to cause the
* direction or management of such entity, whether by contract or
* otherwise, or (ii) ownership of fifty percent (50%) or more of the
* outstanding shares, or (iii) beneficial ownership of such entity.
*
* "You" (or "Your") shall mean an individual or Legal Entity
* exercising permissions granted by this License.
*
* "Source" form shall mean the preferred form for making modifications,
* including but not limited to software source code, documentation
* source, and configuration files.
*
* "Object" form shall mean any form resulting from mechanical
* transformation or translation of a Source form, including but
* not limited to compiled object code, generated documentation,
* and conversions to other media types.
*
* "Work" shall mean the work of authorship, whether in Source or
* Object form, made available under the License, as indicated by a
* copyright notice that is included in or attached to the work
* (an example is provided in the Appendix below).
*
* "Derivative Works" shall mean any work, whether in Source or Object
* form, that is based on (or derived from) the Work and for which the
* editorial revisions, annotations, elaborations, or other modifications
* represent, as a whole, an original work of authorship. For the purposes
* of this License, Derivative Works shall not include works that remain
* separable from, or merely link (or bind by name) to the interfaces of,
* the Work and Derivative Works thereof.
*
* "Contribution" shall mean any work of authorship, including
* the original version of the Work and any modifications or additions
* to that Work or Derivative Works thereof, that is intentionally
* submitted to Licensor for inclusion in the Work by the copyright owner
* or by an individual or Legal Entity authorized to submit on behalf of
* the copyright owner. For the purposes of this definition, "submitted"
* means any form of electronic, verbal, or written communication sent
* to the Licensor or its representatives, including but not limited to
* communication on electronic mailing lists, source code control systems,
* and issue tracking systems that are managed by, or on behalf of, the
* Licensor for the purpose of discussing and improving the Work, but
* excluding communication that is conspicuously marked or otherwise
* designated in writing by the copyright owner as "Not a Contribution."
*
* "Contributor" shall mean Licensor and any individual or Legal Entity
* on behalf of whom a Contribution has been received by Licensor and
* subsequently incorporated within the Work.
*
* 2. Grant of Copyright License. Subject to the terms and conditions of
* this License, each Contributor hereby grants to You a perpetual,
* worldwide, non-exclusive, no-charge, royalty-free, irrevocable
* copyright license to reproduce, prepare Derivative Works of,
* publicly display, publicly perform, sublicense, and distribute the
* Work and such Derivative Works in Source or Object form.
*
* 3. Grant of Patent License. Subject to the terms and conditions of
* this License, each Contributor hereby grants to You a perpetual,
* worldwide, non-exclusive, no-charge, royalty-free, irrevocable
* (except as stated in this section) patent license to make, have made,
* use, offer to sell, sell, import, and otherwise transfer the Work,
* where such license applies only to those patent claims licensable
* by such Contributor that are necessarily infringed by their
* Contribution(s) alone or by combination of their Contribution(s)
* with the Work to which such Contribution(s) was submitted. If You
* institute patent litigation against any entity (including a
* cross-claim or counterclaim in a lawsuit) alleging that the Work
* or a Contribution incorporated within the Work constitutes direct
* or contributory patent infringement, then any patent licenses
* granted to You under this License for that Work shall terminate
* as of the date such litigation is filed.
*
* 4. Redistribution. You may reproduce and distribute copies of the
* Work or Derivative Works thereof in any medium, with or without
* modifications, and in Source or Object form, provided that You
* meet the following conditions:
*
* (a) You must give any other recipients of the Work or
* Derivative Works a copy of this License; and
*
* (b) You must cause any modified files to carry prominent notices
* stating that You changed the files; and
*
* (c) You must retain, in the Source form of any Derivative Works
* that You distribute, all copyright, patent, trademark, and
* attribution notices from the Source form of the Work,
* excluding those notices that do not pertain to any part of
* the Derivative Works; and
*
* (d) If the Work includes a "NOTICE" text file as part of its
* distribution, then any Derivative Works that You distribute must
* include a readable copy of the attribution notices contained
* within such NOTICE file, excluding those notices that do not
* pertain to any part of the Derivative Works, in at least one
* of the following places: within a NOTICE text file distributed
* as part of the Derivative Works; within the Source form or
* documentation, if provided along with the Derivative Works; or,
* within a display generated by the Derivative Works, if and
* wherever such third-party notices normally appear. The contents
* of the NOTICE file are for informational purposes only and
* do not modify the License. You may add Your own attribution
* notices within Derivative Works that You distribute, alongside
* or as an addendum to the NOTICE text from the Work, provided
* that such additional attribution notices cannot be construed
* as modifying the License.
*
* You may add Your own copyright statement to Your modifications and
* may provide additional or different license terms and conditions
* for use, reproduction, or distribution of Your modifications, or
* for any such Derivative Works as a whole, provided Your use,
* reproduction, and distribution of the Work otherwise complies with
* the conditions stated in this License.
*
* 5. Submission of Contributions. Unless You explicitly state otherwise,
* any Contribution intentionally submitted for inclusion in the Work
* by You to the Licensor shall be under the terms and conditions of
* this License, without any additional terms or conditions.
* Notwithstanding the above, nothing herein shall supersede or modify
* the terms of any separate license agreement you may have executed
* with Licensor regarding such Contributions.
*
* 6. Trademarks. This License does not grant permission to use the trade
* names, trademarks, service marks, or product names of the Licensor,
* except as required for reasonable and customary use in describing the
* origin of the Work and reproducing the content of the NOTICE file.
*
* 7. Disclaimer of Warranty. Unless required by applicable law or
* agreed to in writing, Licensor provides the Work (and each
* Contributor provides its Contributions) on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied, including, without limitation, any warranties or conditions
* of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
* PARTICULAR PURPOSE. You are solely responsible for determining the
* appropriateness of using or redistributing the Work and assume any
* risks associated with Your exercise of permissions under this License.
*
* 8. Limitation of Liability. In no event and under no legal theory,
* whether in tort (including negligence), contract, or otherwise,
* unless required by applicable law (such as deliberate and grossly
* negligent acts) or agreed to in writing, shall any Contributor be
* liable to You for damages, including any direct, indirect, special,
* incidental, or consequential damages of any character arising as a
* result of this License or out of the use or inability to use the
* Work (including but not limited to damages for loss of goodwill,
* work stoppage, computer failure or malfunction, or any and all
* other commercial damages or losses), even if such Contributor
* has been advised of the possibility of such damages.
*
* 9. Accepting Warranty or Additional Liability. While redistributing
* the Work or Derivative Works thereof, You may choose to offer,
* and charge a fee for, acceptance of support, warranty, indemnity,
* or other liability obligations and/or rights consistent with this
* License. However, in accepting such obligations, You may act only
* on Your own behalf and on Your sole responsibility, not on behalf
* of any other Contributor, and only if You agree to indemnify,
* defend, and hold each Contributor harmless for any liability
* incurred by, or claims asserted against, such Contributor by reason
* of your accepting any such warranty or additional liability.
*
* END OF TERMS AND CONDITIONS
*
* APPENDIX: How to apply the Apache License to your work.
*
* To apply the Apache License to your work, attach the following
* boilerplate notice, with the fields enclosed by brackets "[]"
* replaced with your own identifying information. (Don't include
* the brackets!) The text should be enclosed in the appropriate
* comment syntax for the file format. We also recommend that a
* file or class name and description of purpose be included on the
* same "printed page" as the copyright notice for easier
* identification within third-party archives.
*
* Copyright [yyyy] [name of copyright owner]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

View File

@@ -0,0 +1,90 @@
[
{
"id": "preferences",
"children":
[
{
"id": "package-settings",
"children":
[
{
"caption": "EasyMotion",
"children":
[
// README
{
"caption": "View README",
"command": "open_file", "args": {"file": "${packages}/EasyMotion/README.md"}
},
{ "caption": "-" },
// Settings
{
"caption": "Settings Default",
"command": "open_file", "args": {"file": "${packages}/EasyMotion/EasyMotion.sublime-settings"}
},
{
"caption": "Settings User",
"command": "open_file", "args": {"file": "${packages}/User/EasyMotion.sublime-settings"}
},
{ "caption": "-" },
// Keybindings - Default
{
"caption": "Key Bindings Default",
"command": "open_file",
"args": {
"file": "${packages}/EasyMotion/Default (OSX).sublime-keymap",
"platform": "OSX"
}
},
{
"caption": "Key Bindings Default",
"command": "open_file",
"args": {
"file": "${packages}/EasyMotion/Default (Linux).sublime-keymap",
"platform": "Linux"
}
},
{
"caption": "Key Bindings Default",
"command": "open_file",
"args": {
"file": "${packages}/EasyMotion/Default (Windows).sublime-keymap",
"platform": "Windows"
}
},
// Keybindings - User
{
"caption": "Key Bindings User",
"command": "open_file",
"args": {
"file": "${packages}/User/Default (OSX).sublime-keymap",
"platform": "OSX"
}
},
{
"caption": "Key Bindings User",
"command": "open_file",
"args": {
"file": "${packages}/User/Default (Linux).sublime-keymap",
"platform": "Linux"
}
},
{
"caption": "Key Bindings User",
"command": "open_file",
"args": {
"file": "${packages}/User/Default (Windows).sublime-keymap",
"platform": "Windows"
}
},
{ "caption": "-" }
]
}
]
}
]
}
]

View File

@@ -0,0 +1,134 @@
# Sublime EasyMotion
EasyMotion is a [Sublime Text 2](http://www.sublimetext.com/2) plugin that allows you to move the cursor to any character in your current view.
It's heavily inspired by [Vim's EasyMotion](http://www.vim.org/scripts/script.php?script_id=3526), and [Emacs' AceJump](http://www.emacswiki.org/emacs/AceJump) plugins.
After pressing the EasyMotion shortcut (default `cmd-;`/`ctrl-;`), you then press the character that you'd like to jump to. EasyMotion will then replace all currently visible instances of that character with one of `a-zA-Z0-9`. Press the key for the one you want and your cursor will be moved right to it.
![Animated Gif](https://raw.github.com/tednaleid/sublime-EasyMotion/add_images/images/easymotion.gif)
## Installation
### Install via PackageControl
If you have the [PackageControl](http://wbond.net/sublime_packages/package_control) plugin installed, you can use that to install `EasyMotion`.
Just type `cmd-shift-p` (`ctrl-shift-p` on win/linux) to bring up the command pallate then type `install` and pick `Package Control: Install Package` from the dropdown.
Then type `EasyMotion` and choose the EasyMotion plugin from the dropdown. Hit `enter` and it will install.
### Manual Installation
Manual installation should be as easy as cloning this git repository into your Sublime `Packages` directory. On OSX:
cd ~/Application\ Support/Sublime\ Text\ 2/Packages
git clone git://github.com/tednaleid/sublime-EasyMotion.git EasyMotion
(The directory name underneath packages __must__ be `EasyMotion` and not `sublime-EasyMotion` for some preferences to get picked up)
If you're interested in trying the next release of the plugin, you can switch your branch to the development branch:
cd EasyMotion
git checkout development
This branch will have features that are marked as fixed in the issue, but haven't yet been merged to `master`.
## Usage
### Jump to any visible character
cmd-; <character> // OSX
ctrl-; <character> // Linux/Windows
it will label all instances of that character with a unique value in `a-zA-Z0-9`, type the label you want and it will jump you to it.
#### Example
The cursor is at the end of the file and we want to jump to the beginning of the `realpart` variable on line 3
![EasyMotion Begin](https://raw.github.com/tednaleid/sublime-EasyMotion/add_images/images/sublimejump_begin.png)
Instead of hitting the up arrow twice and scrolling over to the r (or grabbing your mouse), you could press `cmd-;` followed by `r`. That will transform your file into this (notice that each instance of `r` has been turned into one of `a-zA-Z0-9`):
![EasyMotion Middle](https://raw.github.com/tednaleid/sublime-EasyMotion/add_images/images/sublimejump_middle.png)
Press `e` and your cursor will jump right there:
![EasyMotion Middle](https://raw.github.com/tednaleid/sublime-EasyMotion/add_images/images/sublimejump_end.png)
If your target character occurs more than 62 times in the visible area, it will decorate them in batches.
So if we search this for the letter `l` using `cmd-;`+`l`
![Many Matches Start](https://raw.github.com/tednaleid/sublime-EasyMotion/add_images/images/many_matches_start.png)
The first batch of 62 targets will look like this:
![Many Matches First](https://raw.github.com/tednaleid/sublime-EasyMotion/add_images/images/many_matches_first.png)
**Just hit `enter` and it will highlight the next group of matches.**
![Many Matches Second](https://raw.github.com/tednaleid/sublime-EasyMotion/add_images/images/many_matches_second.png)
Keep hitting `enter` and it will continue to cycle through them in groups of 62. You can also hit `shift-enter` to cycle backwards through the target groups. Hitting the `spacebar` will exit, and so will `ctrl-c` and `escape` (but for some reason there's currently a bug that makes you hit those twice to exit).
### Select all text between cursor and any visible character
cmd-shift-; <character> // OSX
ctrl-shift-; <character> // Linux/Windows
it will label all instances of that character with a unique value in `a-zA-Z0-9`, type it and it will select all text between your current cursor position and the chosen jump target.
#### Example
So in the same situation as above, if we had hit `cmd-shift-;` followed by `r` and picked the `e` target that occurs at the start of the `imagpart` variable on line 3, we would end up with this:
![EasyMotion Select](https://raw.github.com/tednaleid/sublime-EasyMotion/add_images/images/sublimejump_select.png)
## User Modifiable Preferences
### Remapping the Sublime EasyMotion keyboard shortcut
You can remap your keys to be something other than the defaults by entering an override value into your "User - KeyBindings" (under Sublime Text 2 -> Preferences -> Package Settings -> Easy Motion on OSX), just make sure to copy the existing key bindings exactly and change only the first item in the `keys` stanza, otherwise it won't work. So if you wanted the jump command to be `ctrl-,`, you'd use:
[
{
"keys": ["ctrl+,", "<character>"],
"command": "easy_motion",
"args": {"select_text": false}
},
{
"keys": ["ctrl+shift+,", "<character>"],
"command": "easy_motion",
"args": {"select_text": true}
}
]
### Overriding the placeholder characters used for jumping
Add this to your "User Settings" file (found at "Sublime Text 2 -> Preferences -> Package Settings -> Easy Motion -> Settings - User" on OSX) and change the string to contain whatever characters you'd like to use:
// define the characters that we can jump to, in the order that they'll appear, they should be unique
"placeholder_chars" : "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
example using only QWERTY home-row replacements:
"placeholder_chars" : "jkl;asdfHGJKL:ASDFHG"
### Override the highlight color for jump targets
If the highlight color used for jump targets isn't bold enough if your color scheme, you can override it by changing this "User Setting":
// defines syntax highlighting scope that will be used to highlight matched jump targets
// other examples include: keyword, string, number
"jump_target_scope" : "entity.name.class"
# Versions
- 0.8 - released 2/3/13 - updates location of preferences to EasyMotion specific file and includes plugin specific preferences file. You'll need to migrate preferences over into this file for them to stick.
- 0.9 - released 2/14/13 - removes need for input panel and implements an easy_motion_mode to accept keystrokes, also lets `shift-enter` cycle backwards

View File

@@ -0,0 +1,293 @@
import sublime
import sublime_plugin
import re
from itertools import izip_longest
from pprint import pprint
REGEX_ESCAPE_CHARS = '\\+*()[]{}^$?|:].,'
# not a fan of using globals like this, but not sure if there's a better way with the plugin
# API that ST2 provides. Tried attaching as fields to active_view, but didn't persiste, I'm guessing
# it's just a representation of something that gets regenerated on demand so dynamic fields are transient
JUMP_GROUP_GENERATOR = None
CURRENT_JUMP_GROUP = None
EASY_MOTION_EDIT = None
SELECT_TEXT = False
COMMAND_MODE_WAS = False
JUMP_TARGET_SCOPE = 'string'
class JumpGroupGenerator:
'''
given a list of region jump targets matching the given character, can emit a series of
JumpGroup dictionaries going forwards with next and backwards with previous
'''
def __init__(self, view, character, placeholder_chars, case_sensitive):
self.view = view
self.case_sensitive = case_sensitive
self.placeholder_chars = placeholder_chars
self.all_jump_targets = self.find_all_jump_targets_in_visible_region(character)
self.interleaved_jump_targets = self.interleave_jump_targets_from_cursor()
self.jump_target_index = 0
self.jump_target_groups = self.create_jump_target_groups()
self.jump_target_group_index = -1
def determine_re_flags(self, character):
if character == 'enter':
return '(?m)'
elif self.case_sensitive:
return '(?i)'
else:
return ''
def interleave_jump_targets_from_cursor(self):
sel = self.view.sel()[0] # multi select not supported, doesn't really make sense
sel_begin = sel.begin()
sel_end = sel.end()
before = []
after = []
# split them into two lists radiating out from the cursor position
for target in self.all_jump_targets:
if target.begin() < sel_begin:
# add to beginning of list so closest targets to cursor are first
before.insert(0, target)
elif target.begin() > sel_end:
after.append(target)
# now interleave the two lists together into one list
return [target for targets in izip_longest(before, after) for target in targets if target is not None]
def create_jump_target_groups(self):
jump_target_groups = []
while self.has_next_jump_target():
jump_group = dict()
for placeholder_char in self.placeholder_chars:
if self.has_next_jump_target():
jump_group[placeholder_char] = self.interleaved_jump_targets[self.jump_target_index]
self.jump_target_index += 1
else:
break
jump_target_groups.append(jump_group)
return jump_target_groups
def has_next_jump_target(self):
return self.jump_target_index < len(self.interleaved_jump_targets)
def __len__(self):
return len(self.jump_target_groups)
def next(self):
self.jump_target_group_index += 1
if self.jump_target_group_index >= len(self.jump_target_groups) or self.jump_target_group_index < 0:
self.jump_target_group_index = 0
return self.jump_target_groups[self.jump_target_group_index]
def previous(self):
self.jump_target_group_index -= 1
if self.jump_target_group_index < 0 or self.jump_target_group_index >= len(self.jump_target_groups):
self.jump_target_group_index = len(self.jump_target_groups) - 1
return self.jump_target_groups[self.jump_target_group_index]
def find_all_jump_targets_in_visible_region(self, character):
visible_region_begin = self.visible_region_begin()
visible_text = self.visible_text()
folded_regions = self.get_folded_regions(self.view)
matching_regions = []
target_regexp = self.target_regexp(character)
for char_at in (match.start() for match in re.finditer(target_regexp, visible_text)):
char_point = char_at + visible_region_begin
char_region = sublime.Region(char_point, char_point + 1)
if not self.region_list_contains_region(folded_regions, char_region):
matching_regions.append(char_region)
return matching_regions
def region_list_contains_region(self, region_list, region):
for element_region in region_list:
if element_region.contains(region):
return True
return False
def visible_region_begin(self):
return self.view.visible_region().begin()
def visible_text(self):
visible_region = self.view.visible_region()
return self.view.substr(visible_region)
def target_regexp(self, character):
re_flags = self.determine_re_flags(character)
if (REGEX_ESCAPE_CHARS.find(character) >= 0):
return re_flags + '\\' + character
elif character == "enter":
return re_flags + "(?=^).|.(?=$)"
else:
return re_flags + character
def get_folded_regions(self, view):
'''
No way in the API to get the folded regions without unfolding them first
seems to be quick enough that you can't actually see them fold/unfold
'''
folded_regions = view.unfold(view.visible_region())
view.fold(folded_regions)
return folded_regions
class EasyMotionCommand(sublime_plugin.WindowCommand):
winning_selection = None
def run(self, character=None, select_text=False):
global JUMP_GROUP_GENERATOR, SELECT_TEXT, JUMP_TARGET_SCOPE
sublime.status_message("EasyMotion: Jump to " + character)
SELECT_TEXT = select_text
active_view = self.window.active_view()
settings = sublime.load_settings("EasyMotion.sublime-settings")
placeholder_chars = settings.get('placeholder_chars', 'abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ')
JUMP_TARGET_SCOPE = settings.get('jump_target_scope', 'string')
case_sensitive = settings.get('case_sensitive', True)
JUMP_GROUP_GENERATOR = JumpGroupGenerator(active_view, character, placeholder_chars, case_sensitive)
if len(JUMP_GROUP_GENERATOR) > 0:
self.activate_mode(active_view)
self.window.run_command("show_jump_group")
else:
sublime.status_message("EasyMotion: unable to find any instances of " + character + " in visible region")
def activate_mode(self, active_view):
global COMMAND_MODE_WAS
active_view.settings().set('easy_motion_mode', True)
# yes, this feels a little dirty to mess with the Vintage plugin, but there
# doesn't appear to be any other way to tell it to not intercept keys, so turn it
# off (if it's on) while we're running EasyMotion
COMMAND_MODE_WAS = active_view.settings().get('command_mode')
if (COMMAND_MODE_WAS):
active_view.settings().set('command_mode', False)
class ShowJumpGroup(sublime_plugin.WindowCommand):
active_view = None
def run(self, next=True):
self.active_view = self.window.active_view()
self.show_jump_group(next)
def show_jump_group(self, next=True):
global JUMP_GROUP_GENERATOR, CURRENT_JUMP_GROUP
if next:
CURRENT_JUMP_GROUP = JUMP_GROUP_GENERATOR.next()
else:
CURRENT_JUMP_GROUP = JUMP_GROUP_GENERATOR.previous()
self.activate_current_jump_group()
def activate_current_jump_group(self):
global CURRENT_JUMP_GROUP, EASY_MOTION_EDIT, JUMP_TARGET_SCOPE
'''
Start up an edit object if we don't have one already, then create all of the jump targets
'''
if (EASY_MOTION_EDIT is not None):
# normally would call deactivate_current_jump_group here, but apparent ST2 bug prevents it from calling undo correctly
# instead just decorate the new character and keep the same edit object so all changes get undone properly
self.active_view.erase_regions("jump_match_regions")
else:
EASY_MOTION_EDIT = self.active_view.begin_edit()
for placeholder_char in CURRENT_JUMP_GROUP.keys():
self.active_view.replace(EASY_MOTION_EDIT, CURRENT_JUMP_GROUP[placeholder_char], placeholder_char)
self.active_view.add_regions("jump_match_regions", CURRENT_JUMP_GROUP.values(), JUMP_TARGET_SCOPE, "dot")
class JumpTo(sublime_plugin.WindowCommand):
def run(self, character=None):
global COMMAND_MODE_WAS
self.active_view = self.window.active_view()
self.winning_selection = self.winning_selection_from(character)
self.finish_easy_motion()
self.active_view.settings().set('easy_motion_mode', False)
if (COMMAND_MODE_WAS):
self.active_view.settings().set('command_mode', True)
def winning_selection_from(self, selection):
global CURRENT_JUMP_GROUP, SELECT_TEXT
winning_region = None
if selection in CURRENT_JUMP_GROUP:
winning_region = CURRENT_JUMP_GROUP[selection]
if winning_region is not None:
if SELECT_TEXT:
for current_selection in self.active_view.sel():
if winning_region.begin() < current_selection.begin():
return sublime.Region(current_selection.end(), winning_region.begin())
else:
return sublime.Region(current_selection.begin(), winning_region.end())
else:
return sublime.Region(winning_region.begin(), winning_region.begin())
def finish_easy_motion(self):
'''
We need to clean up after ourselves by restoring the view to it's original state, if the user did
press a jump target that we've got saved, jump to it as the last action
'''
self.deactivate_current_jump_group()
self.jump_to_winning_selection()
def deactivate_current_jump_group(self):
'''
Close out the edit that we've been messing with and then undo it right away to return the buffer to
the pristine state that we found it in. Other methods ended up leaving the window in a dirty save state
and this seems to be the cleanest way to get back to the original state
'''
global EASY_MOTION_EDIT
if (EASY_MOTION_EDIT is not None):
self.active_view.end_edit(EASY_MOTION_EDIT)
self.window.run_command("undo")
EASY_MOTION_EDIT = None
self.active_view.erase_regions("jump_match_regions")
def jump_to_winning_selection(self):
if self.winning_selection is not None:
self.active_view.run_command("jump_to_winning_selection", {"begin": self.winning_selection.begin(), "end": self.winning_selection.end()})
class DeactivateJumpTargets(sublime_plugin.WindowCommand):
def run(self):
pprint("DeactivateJumpTargets called")
global EASY_MOTION_EDIT
active_view = self.window.active_view()
if (EASY_MOTION_EDIT is not None):
active_view.end_edit(EASY_MOTION_EDIT)
self.window.run_command("undo")
EASY_MOTION_EDIT = None
active_view.erase_regions("jump_match_regions")
class JumpToWinningSelection(sublime_plugin.TextCommand):
def run(self, edit, begin, end):
winning_region = sublime.Region(long(begin), long(end))
sel = self.view.sel()
sel.clear()
sel.add(winning_region)
self.view.show(winning_region)

View File

@@ -0,0 +1 @@
{"url": "https://github.com/tednaleid/sublime-EasyMotion", "version": "2013.03.26.20.46.50", "description": "Sublime Text 2 plugin to quickly jump to any character in the visible area of the active view."}