feat(SublimeText2.UtilPackages): cache packages

This commit is contained in:
Iristyle
2013-04-04 08:54:47 -04:00
parent 1e6f643a1b
commit d65666cdfc
541 changed files with 26347 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,5 @@
{
"highlight_search_icon": "bookmark",
"highlight_search_scope": "entity.name.function",
"highlight_search_results": false
}

View File

@@ -0,0 +1,5 @@
# Contributors
The following people have contributed code to the OpenSearchResult plugin.
Chris Barnett <barney.chrisj@gmail.com>

View File

@@ -0,0 +1,7 @@
[
{
"keys": ["g", "o"],
"command": "open_search_result",
"context": [{"key": "setting.command_mode"}]
}
]

View File

@@ -0,0 +1,18 @@
Copyright (c) 2012 Andrew Brookins
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,26 @@
# Open Search Result Plugin for Sublime Text 2
This plugin creates a command that allows you to open files listed in the search
results of the 'Find in Files' command.
- When run on a line in the search results that includes a line number, e.g.,
"102: print 'foo'" it opens the file at the correct line number.
- When run on a line that contains a file path like '/path/to/somewhere:'
in the search listing, it opens the file without a line number specified.
## Key Binding
- The default key binding is a Vintage command mode key: "g, o".
## Customizing
You can change various things about the plugin by adding user settings:
- 'highlight_search_results': Set to false to disable highlighting openable
paths (the open command will still work)
- 'highlight_search_scope': The scope that will be used to color the outline for
openable paths or the icon. See your theme file for examples of colors.
- 'highlight_search_icon': If you want an icon to show up in the gutter next to
openable paths, include a valid icon name as a string (e.g., 'circle', 'dot' or
'bookmark')

View File

@@ -0,0 +1,126 @@
import os
import sublime, sublime_plugin
import util
class HighlightFilePaths(sublime_plugin.EventListener):
HIGHLIGHT_REGION_NAME = 'HighlightFilePaths'
HIGHLIGHT_ENABLED_KEY = 'highlight_search_results'
SCOPE_SETTINGS_KEY = 'highlight_search_scope'
ICON_SETTINGS_KEY = 'highlight_search_icon'
DEFAULT_SCOPE = 'search_result_highlight'
DEFAULT_ICON = ''
def show_highlight(self, view):
valid_regions = []
show_highlight = view.settings().get(self.HIGHLIGHT_ENABLED_KEY, False)
scope = view.settings().get(self.SCOPE_SETTINGS_KEY, self.DEFAULT_SCOPE)
icon = view.settings().get(self.ICON_SETTINGS_KEY, self.DEFAULT_ICON)
if view.name() != 'Find Results':
return
for s in view.sel():
line = view.line(s)
line_str = view.substr(view.line(s))
line_num = util.parse_line_number(line_str)
if util.is_file_path(line_str) or line_num:
valid_regions.append(line)
if valid_regions:
if show_highlight:
options = sublime.DRAW_EMPTY | sublime.DRAW_OUTLINED
else:
options = sublime.HIDDEN
view.add_regions(
self.HIGHLIGHT_REGION_NAME, valid_regions, scope, icon, options)
else:
view.erase_regions(self.HIGHLIGHT_REGION_NAME)
def on_selection_modified(self, view):
highlight_enabled = (view.settings().get(self.HIGHLIGHT_ENABLED_KEY)
or view.settings().get(self.ICON_SETTINGS_KEY))
if view.settings().get('is_widget') \
or not view.settings().get('command_mode') \
or not highlight_enabled:
view.erase_regions(self.HIGHLIGHT_REGION_NAME)
return
self.show_highlight(view)
def on_deactivated(self, view):
view.erase_regions(self.HIGHLIGHT_REGION_NAME)
def on_activated(self, view):
if view.settings().get('highlight_file_paths'):
self.show_highlight(view)
class OpenSearchResultCommand(sublime_plugin.TextCommand):
"""
Open a file listed in the Find In File search results at the line the
cursor is on, or just open the file if the cursor is on the file path.
"""
def open_file_from_line(self, line, line_num):
"""
Attempt to parse a file path from the string `line` and open it in a
new buffer.
"""
if ':' not in line:
return
file_path = line[0:-1]
if os.path.exists(file_path):
self.view.window().open_file(
"%s:%s" % (file_path, line_num), sublime.ENCODED_POSITION)
def previous_line(self, region):
""" `region` should be a Region covering the entire hard line """
if region.begin() == 0:
return None
else:
return self.view.full_line(region.begin() - 1)
def open_file_path(self, line_str):
"""
Parse a file path from a string `line_str` of the format: "<path>:"
"""
file_path = line_str[0:-1]
if os.path.exists(file_path):
self.view.window().open_file(file_path)
def open_file_at_line_num(self, cur_line, line_num):
"""
Starting at the position `cur_line` (a `Region`), count backwards
until we find a path or the beginning of the file. If we find a file
path, open it in a new tab at `line_num`.
"""
prev = cur_line
while True:
prev = self.previous_line(prev)
if prev is None:
break
line = self.view.substr(prev).strip()
if util.is_file_path(line):
return self.open_file_from_line(line, line_num)
def run(self, edit):
for cursor in self.view.sel():
cur_line = self.view.line(cursor)
line_str = self.view.substr(cur_line).strip()
line_num = util.parse_line_number(line_str)
if self.view.name() != 'Find Results':
return
if util.is_file_path(line_str):
self.open_file_path(line_str)
elif line_num:
self.open_file_at_line_num(cur_line, line_num)

View File

@@ -0,0 +1 @@
{"url": "https://github.com/abrookins/OpenSearchResult", "version": "2012.09.11.15.18.59", "description": "a Sublime Text 2 plugin that opens files listed in the Find in File output"}

View File

@@ -0,0 +1,36 @@
"""
util.py: Utility functions for opening Sublime Text 2 search results.
"""
import re
def parse_line_number(line_str):
"""
In a line of the format "<line_num>: <text>"or "<line_num> <text>"
this grabs line_num.
>>> parse_line_number('5: def parse_line_number(line_str):')
'5'
>>> parse_line_number('43 line = view.line(s)')
'43'
>>> parse_line_number('136: line_num = parse_line_number(line_str)')
'136'
"""
parts = line_str.split()
line_num = parts[0].strip().replace(':', '')
return line_num
def is_file_path(line_str):
"""
Test if `line_str` is a file path.
>>> is_file_path('/Users/me/code/OpenSearchResult/open_search_result.py:')
True
>>> is_file_path('C:\Users\me\\test.txt:')
True
>>> is_file_path('5: def parse_line_number(line_str):')
False
"""
return re.match("^(/|\w:\\\).*:$", line_str) is not None