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
.DS_Store

View File

@@ -0,0 +1,581 @@
import os
import sublime
import sublime_plugin
import re
import logging
import errno
SETTINGS = [
"alias",
"default_initial",
"use_cursor_text",
"show_files",
"show_path",
"default_root",
"default_path",
"default_folder_index",
"os_specific_alias",
"ignore_case",
"alias_root",
"alias_path",
"alias_folder_index",
"debug",
"auto_refresh_sidebar"
]
VIEW_NAME = "AdvancedNewFileCreation"
WIN_ROOT_REGEX = r"[a-zA-Z]:(/|\\)"
NIX_ROOT_REGEX = r"^/"
HOME_REGEX = r"^~"
# Set up logger
logging.basicConfig(format='[AdvancedNewFile] %(levelname)s %(message)s')
logger = logging.getLogger()
class AdvancedNewFileCommand(sublime_plugin.WindowCommand):
def run(self, is_python=False):
self.PLATFORM = sublime.platform().lower()
self.root = None
self.alias_root = None
self.top_level_split_char = ":"
self.is_python = is_python
self.view = self.window.active_view()
# Settings will be based on the view
settings = get_settings(self.view)
self.aliases = self.get_aliases(settings)
self.show_path = settings.get("show_path")
self.auto_refresh_sidebar = settings.get("auto_refresh_sidebar")
self.default_folder_index = settings.get("default_folder_index")
self.alias_folder_index = settings.get("alias_folder_index")
default_root = self.get_default_root(settings.get("default_root"))
if default_root == "path":
self.root = os.path.expanduser(settings.get("default_path"))
default_root = ""
self.root, path = self.split_path(default_root)
# Set some default values for the auto complete
PathAutocomplete.set_show_files(settings.get("show_files"))
PathAutocomplete.set_aliases(self.aliases)
PathAutocomplete.set_ignore_case(settings.get("ignore_case"))
# Search for initial string
path = settings.get("default_initial", "")
if settings.get("use_cursor_text", False):
tmp = self.get_cursor_path()
if tmp != "":
path = tmp
alias_root = self.get_default_root(settings.get("alias_root"), True)
if alias_root == "path":
self.alias_root = os.path.expanduser(settings.get("alias_path"))
alias_root = ""
self.alias_root, tmp = self.split_path(alias_root, True)
debug = settings.get("debug") or False
if debug:
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.ERROR)
# Get user input
self.show_filename_input(path)
def get_aliases(self, settings):
aliases = settings.get("alias")
all_os_aliases = settings.get("os_specific_alias")
for key in all_os_aliases:
if self.PLATFORM in all_os_aliases.get(key):
aliases[key] = all_os_aliases.get(key).get(self.PLATFORM)
return aliases
def get_default_root(self, string, is_alias=False):
root = ""
if string == "home":
root = "~/"
elif string == "current":
root = self.top_level_split_char
elif string == "project_folder":
if is_alias:
folder_index = self.alias_folder_index
else:
folder_index = self.default_folder_index
if len(self.window.folders()) <= folder_index:
if is_alias:
self.alias_folder_index = 0
else:
self.default_folder_index = 0
elif string == "top_folder":
if is_alias:
self.alias_folder_index = 0
else:
self.default_folder_index = 0
elif string == "path":
root = "path"
else:
logger.error("Invalid specifier for \"default_root\"")
return root
def split_path(self, path="", is_alias=False):
HOME_REGEX = r"^~[/\\]"
root = None
try:
# Parse windows root
if self.PLATFORM == "windows":
if re.match(WIN_ROOT_REGEX, path):
root = path[0:3]
path = path[3:]
# Parse if alias
if self.top_level_split_char in path and root == None:
parts = path.rsplit(self.top_level_split_char, 1)
root, path = self.translate_alias(parts[0])
path_list = []
if path != "":
path_list.append(path)
if parts[1] != "":
path_list.append(parts[1])
path = self.top_level_split_char.join(path_list)
# Parse if tilde used
elif re.match(HOME_REGEX, path) and root == None:
root = os.path.expanduser("~")
path = path[2:]
# Default
if root == None:
if is_alias:
root = self.alias_root
folder_index = self.alias_folder_index
else:
root = self.root
folder_index = self.default_folder_index
root = root or self.window.folders()[folder_index]
except IndexError:
root = os.path.expanduser("~")
return root, path
def translate_alias(self, path):
root = None
split_path = None
if path == "" and self.view is not None:
filename = self.view.file_name()
if filename is not None:
root = os.path.dirname(filename)
else:
split_path = path.split(self.top_level_split_char)
join_index = len(split_path) - 1
target = path
root_found = False
while join_index >= 0 and not root_found:
# Folder aliases
for folder in self.window.folders():
basename = os.path.basename(folder)
if basename == target:
root = folder
root_found = True
break
# Aliases from settings.
for alias in self.aliases.keys():
if alias == target:
alias_path = self.aliases.get(alias)
if re.search(HOME_REGEX, alias_path) is None:
if self.PLATFORM == "windows":
if re.search(WIN_ROOT_REGEX, alias_path) is None:
root = os.path.join(self.alias_root, alias_path)
break
else:
if re.search(NIX_ROOT_REGEX, alias_path) is None:
root = os.path.join(self.alias_root, alias_path)
break
root = os.path.expanduser(alias_path)
root_found = True
break
remove = re.escape(split_path[join_index])
target = re.sub(r":%s$" % remove, "", target)
join_index -= 1
if root is None:
return None, path
elif split_path is None:
return os.path.abspath(root), ""
else:
# Add to index so we re
join_index += 2
return os.path.abspath(root), self.top_level_split_char.join(split_path[join_index:])
def show_filename_input(self, initial=''):
caption = 'Enter a path for a new file'
if self.is_python:
caption = '%s (creates __init__.py in new dirs)' % caption
view = self.window.show_input_panel(
caption, initial,
self.entered_filename, self.update_filename_input, self.clear
)
view.set_name(VIEW_NAME)
temp = view.settings().get("word_separators")
temp = temp.replace(".", "")
view.settings().set("word_separators", temp)
view.settings().set("auto_complete_commit_on_tab", True)
view.settings().set("tab_completion", True)
PathAutocomplete.set_view_id(view.id())
PathAutocomplete.set_root(self.root, True)
def update_filename_input(self, path_in):
base, path = self.split_path(path_in)
if self.top_level_split_char in path_in or re.match(r"^~[/\\]", path_in):
PathAutocomplete.set_root(base, False)
else:
PathAutocomplete.set_root(base, True)
creation_path = self.generate_creation_path(base, path)
if self.show_path:
if self.view != None:
self.view.set_status("AdvancedNewFile", "Creating file at %s " % \
creation_path)
else:
sublime.status_message("Creating file at %s " % creation_path)
logger.debug("Creation path is '%s'" % creation_path)
PathAutocomplete.set_path(path)
def generate_creation_path(self, base, path):
if self.PLATFORM == "windows":
if not re.match(WIN_ROOT_REGEX, base):
return base + self.top_level_split_char + path
else:
if not re.match(NIX_ROOT_REGEX, base):
return base + self.top_level_split_char + path
return os.path.abspath(os.path.join(base, path))
def entered_filename(self, filename):
# Check if valid root specified for windows.
if self.PLATFORM == "windows":
if re.match(WIN_ROOT_REGEX, filename):
root = filename[0:3]
if not os.path.isdir(root):
sublime.error_message(root + " is not a valid root.")
self.clear()
return
base, path = self.split_path(filename)
file_path = os.path.join(base, path)
# Check for invalid alias specified.
if self.top_level_split_char in filename and \
not (self.PLATFORM == "windows" and re.match(WIN_ROOT_REGEX, base)) and \
not (self.PLATFORM != "windows" and re.match(NIX_ROOT_REGEX, base)):
if base == "":
error_message = "Current file cannot be resolved."
else:
error_message = "'" + base + "' is an invalid alias."
sublime.error_message(error_message)
else:
attempt_open = True
logger.debug("Creating file at %s", file_path)
if not os.path.exists(file_path):
try:
self.create(file_path)
except OSError as e:
attempt_open = False
sublime.error_message("Cannot create '" + file_path + "'. See console for details")
logger.error("Exception: %s '%s'" % (e.strerror, e.filename))
if attempt_open:
if os.path.isdir(file_path):
if not re.search(r"(/|\\)$", file_path):
sublime.error_message("Cannot open view for '" + file_path + "'. It is a directory. ")
else:
self.window.open_file(file_path)
self.clear()
self.refresh_sidebar()
def refresh_sidebar(self):
if self.auto_refresh_sidebar:
try:
self.window.run_command("refresh_folder_list")
except:
pass
def clear(self):
if self.view != None:
self.view.erase_status("AdvancedNewFile")
PathAutocomplete.clear()
def create(self, filename):
base, filename = os.path.split(filename)
self.create_folder(base)
if filename != "":
open(os.path.join(base, filename), "a").close()
def create_folder(self, path):
try:
os.makedirs(path)
except OSError as ex:
if ex.errno != errno.EEXIST:
raise
if self.is_python:
open(os.path.join(base, '__init__.py'), 'a').close()
def get_cursor_path(self):
if self.view == None:
return ""
view = self.view
path = ""
for region in view.sel():
syntax = view.syntax_name(region.begin())
if region.begin() != region.end():
path = view.substr(region)
break
if re.match(".*string.quoted.double", syntax) or re.match(".*string.quoted.single", syntax):
path = view.substr(view.extract_scope(region.begin()))
path = re.sub('^"|\'', '', re.sub('"|\'$', '', path.strip()))
break
return path
class PathAutocomplete(sublime_plugin.EventListener):
aliases = {}
show_files = False
ignore_case = False
path = ""
root = ""
default_root = True
view_id = None
prev_suggestions = []
prev_base = ""
prev_directory = ""
path_empty = True
prev_root = ""
prev_prefix = ""
prev_locations = []
def on_query_context(self, view, key, operator, operand, match_all):
if key == "advanced_new_file_completion" and PathAutocomplete.view_id != None and view.id() == PathAutocomplete.view_id:
return True
return None
def continue_previous_autocomplete(self):
pac = PathAutocomplete
sep = os.sep
root_path = pac.root + sep
prev_base = pac.prev_base
prev_directory = pac.prev_directory
prev_root = pac.prev_root
base = os.path.basename(pac.path)
directory = os.path.dirname(pac.path)
# If base is empty, we may be cycling through directory options
if base == "":
return True
# Ensures the correct directory is used if the default root is specified
# using an alias.
if base == prev_base and \
directory == prev_directory and \
prev_root == root_path and \
pac.default_root:
return True
# Continue completions if file names are completed.
if os.path.isfile(os.path.join(root_path, pac.path)):
return True
return False
def on_query_completions(self, view, prefix, locations):
self.suggestion_entries = []
pac = PathAutocomplete
if pac.view_id == None or view.id() != pac.view_id:
return []
auto_complete_prefix = ""
if self.continue_previous_autocomplete() and prefix != "":
logger.debug("(Prev) Suggestions")
logger.debug(pac.prev_suggestions)
if len(pac.prev_suggestions) > 1:
return (pac.prev_suggestions, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
elif len(pac.prev_suggestions) == 1:
auto_complete_prefix = pac.prev_suggestions[0][1]
suggestions = []
suggestions_w_spaces = []
root_path = pac.root + os.sep
directory, base = os.path.split(pac.path)
if directory == "" and pac.default_root:
# Project folders
sugg, sugg_w_spaces = self.generate_project_auto_complete(base)
suggestions += sugg
suggestions_w_spaces += sugg_w_spaces
# Aliases
sugg, sugg_w_spaces = self.generate_alias_auto_complete(base)
suggestions += sugg
suggestions_w_spaces += sugg_w_spaces
# Directories
path = os.path.join(root_path, directory)
if os.path.exists(path):
sugg, sugg_w_spaces = self.generate_relative_auto_complete(path, base, auto_complete_prefix)
suggestions += sugg
suggestions_w_spaces += sugg_w_spaces
# If suggestions exist, use complete name
# else remove base prefix
if len(suggestions) > 0:
for name in suggestions_w_spaces:
suggestions.append((" " + name, name))
else:
for name in suggestions_w_spaces:
temp = name
name = name[len(base) - 1:]
suggestions.append((" " + temp, name))
if len(suggestions) == 0 and locations == pac.prev_locations:
return (pac.prev_suggestions, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
# Previous used to determine cycling through entries.
pac.prev_directory = directory
pac.prev_base = base
pac.prev_suggestions = suggestions
pac.prev_root = root_path
pac.prev_prefix = prefix
pac.prev_locations = locations
logger.debug("Suggestions:")
logger.debug(suggestions)
return (suggestions, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
def generate_project_auto_complete(self, base):
folders = sublime.active_window().folders()
if len(folders) > 1:
folders = map(lambda f: os.path.basename(f), folders)
return self.generate_auto_complete(base, folders)
return [], []
def generate_alias_auto_complete(self, base):
return self.generate_auto_complete(base, PathAutocomplete.aliases)
def generate_auto_complete(self, base, iterable_var):
sugg = []
sugg_w_spaces = []
for entry in iterable_var:
if entry in self.suggestion_entries:
continue
self.suggestion_entries.append(entry)
compare_entry = entry
compare_base = base
if PathAutocomplete.ignore_case:
compare_entry = compare_entry.lower()
compare_base = compare_base.lower()
if compare_entry.find(compare_base) == 0:
if " " in base:
sugg_w_spaces.append(entry + ":")
else:
sugg.append((entry + ":", entry + ":"))
return sugg, sugg_w_spaces
def generate_relative_auto_complete(self, path, base, auto_complete_prefix):
sep = os.sep
sugg = []
sugg_w_spaces = []
# Attempt to prevent searching the same path when a path has been specified
# Problems occur when using tab to complete entry with single completion
# followed by ctrl + space
if ":" in auto_complete_prefix:
compare_prefix = auto_complete_prefix.split(":", 1)[1]
else:
compare_prefix = auto_complete_prefix
if re.search(r"[/\\]$", auto_complete_prefix) and not path.endswith(compare_prefix[0:-1]):
path = os.path.join(path, compare_prefix)
for filename in os.listdir(path):
if PathAutocomplete.show_files or os.path.isdir(os.path.join(path, filename)):
compare_base = base
compare_filename = filename
if PathAutocomplete.ignore_case:
compare_base = compare_base.lower()
compare_filename = filename.lower()
if compare_filename.find(compare_base) == 0:
# Need to find a better way to do the auto complete.
if " " in compare_base:
if os.path.isdir(os.path.join(path, filename)):
sugg_w_spaces.append(auto_complete_prefix + filename + sep)
else:
sugg_w_spaces.append(auto_complete_prefix + filename)
else:
if os.path.isdir(os.path.join(path, filename)):
sugg.append((" " + auto_complete_prefix + filename + sep, auto_complete_prefix + filename + sep))
else:
sugg.append((" " + auto_complete_prefix + filename, auto_complete_prefix + filename))
return sugg, sugg_w_spaces
@staticmethod
def set_path(path_input):
PathAutocomplete.path = path_input
@staticmethod
def set_root(root_input, default_root):
PathAutocomplete.root = root_input
PathAutocomplete.default_root = default_root
@staticmethod
def clear():
PathAutocomplete.path = ""
PathAutocomplete.root = ""
PathAutocomplete.prev_suggestions = []
PathAutocomplete.prev_base = ""
PathAutocomplete.prev_directory = ""
PathAutocomplete.aliases = {}
PathAutocomplete.path_empty = True
PathAutocomplete.prev_root = ""
PathAutocomplete.default_root = True
PathAutocomplete.show_files = False
PathAutocomplete.prev_prefix = ""
PathAutocomplete.prev_locations = []
PathAutocomplete.view_id = None
@staticmethod
def set_aliases(aliases):
PathAutocomplete.aliases = aliases
@staticmethod
def set_show_files(show_files):
PathAutocomplete.show_files = show_files
@staticmethod
def set_ignore_case(ignore_case):
PathAutocomplete.ignore_case = ignore_case
@staticmethod
def set_view_id(view_id):
PathAutocomplete.view_id = view_id
def get_settings(view):
settings = sublime.load_settings("AdvancedNewFile.sublime-settings")
project_settings = {}
local_settings = {}
if view != None:
project_settings = view.settings().get('AdvancedNewFile', {})
for setting in SETTINGS:
local_settings[setting] = settings.get(setting)
for key in project_settings:
if key in SETTINGS:
if key == "alias":
local_settings[key] = dict(local_settings[key].items() + project_settings.get(key).items())
else:
local_settings[key] = project_settings[key]
else:
logger.error("AdvancedNewFile[Warning]: Invalid key '%s' in project settings.", key)
return local_settings

View File

@@ -0,0 +1,80 @@
{
// This setting contains a dictionary of aliases. The keys represent the
// alias names, the values represent the paths.
// NOTE: These should be absolute paths. Also, these paths should
// match your systems convention. For example, Windows machines should
// have paths similar to "C:\\Users\\username\\Desktop". *nix systems should
// have paths similar to "/home/username/desktop".
"alias": {},
// This is a secondary field for aliases. These aliases will be platform specific.
// The key for the entry will still represent the name to be used for the alias.
// Rather than being just a string path, the value will be a nested dictionary.
// The dictionary may have one of three keys, "windows", "linux", or "osx".
// The path used for this alias will be based on the operating system being used.
"os_specific_alias": {},
// A default initial value to fill the create new file input path with.
"default_initial": "",
// A boolean defining if cursor text should be used. Text bound by single or
// double quotes or within a region will be used. If multiple cursors
// are used, the earliest selection containing a region or existing
// within quotes will be used.
// NOTE: A value read from cursor will override the default
// initial string setting.
"use_cursor_text": false,
// A boolean value specifying if regular files should be included in the auto
// complete options.
"show_files": false,
// A boolean specifying if the file path being created should be displayed in
// the status bar.
"show_path": true,
// This value specifies the default directory when using AdvancedNewFile.
// Note it must be one of these values:
// project_folder - Default will be the folder index specified by the "default_folder_index" setting.
// current - Default will be the directory of the current view.
// home - Default will be the home folder (~/)
// path - Default will be defined by the setting "default_path"
// If the current view or top folder cannot be resolved, the home directory
// will be used.
"default_root": "project_folder",
// A string specifying the default root to use. For this to be utilized,
// "default_root" must be set to "path"
"default_path": "~",
// An integer value representing a folder index to be used when "folder" is specified
// for "default_root". If an index outside of the range of existing folders is used,
// it will default to 0 (the top level folder).
"default_folder_index": 0,
// This value specifies the root that will be used when resolving relative paths
// defined in aliases. For more information about valid values, see "default_root".
// Note that if "default_path" or "default_folder_index" is used,
// "alias_path" and "alias_folder_index" must be used for the respective entries.
"alias_root": "current",
// A string specifying the path to use for the alias root. For this to be
// utilized, "alias_root" must be set to "path"
"alias_path": "~",
// An integer value representing the folder index to use when "folder" is specified
// for "alias_root". If an index outside of the range of the existing folders is used,
// it will default to 0.
"alias_folder_index": 0,
// A boolean specifying if case should be ignored when building
// auto complete list.
"ignore_case": false,
// A boolean specifying if folders should automatically refresh and update the sidebar.
// In some builds, the sidebar does not refresh when contents of project folder are updated.
// This setting is required to refresh the sidebar in these circumstances.
// false by default
"auto_refresh_sidebar": false
}

View File

@@ -0,0 +1,51 @@
# Changelog for AdvancedNewFile
- 2 February 2013
- Update to be compatible with Sublime Text 3.
- 14 January 2013
- Add `alias_root` setting, used with aliases with relative paths.
- Add setting to allow user to specify which folder from the project should be used.
- Bug fixes
- Do not require relative alias paths to begin with `./`
- Prevent duplicate entries from appearing in auto complete list.
- 17 December 2012
- Allow selected text to fill entry window.
- Basic work for continued autocompletion (Only applies if there is a single completion option)
- Bug fixes
- Properly display completions when using "ctrl+space" to manually display auto complete options.
- Prevent error pop up from occuring when explicitly creating a directory structure.
- Fix bug where using cursor text causes an error.
- Prevent spaces from being inserted when tab is without a possible completion.
- 26 November 2012
- Add setting to display path for file to be created in status bar.
- Add setting to set default base path (home, current, top_folder, path).
- Add setting to ignore case for auto completion.
- Add support for relative paths in alias.
- Add OS Specific Aliases to settings.
- Display an error when attempting to use an invalid alias.
- Display an error when attempting to open a directory in a view.
- Display an error if path creation fails.
- Bug Fixes
- Auto complete bug for files with spaces in their name
- Status bar update causing errors when no view is present.
- Specifying absolute paths for Windows produced unexpected behavior.
- 30 October 2012
- Initial work for tab autocompletion
- Files created when path entered
- Add setting to fill with a default value.
- Setting to prefill entry box with text in quotes.
- Add setting to display non directory files
- Add user defined aliases.
- Bug fixes.
- Prevent buffer from being opened when a directory is specified.
- 20 April 2012
- Add ability to specify top level folders
- Bug fixes
- Fix Windows keybindings
- Fix save issue on Windows
- 29 October 2011
- Initial release of AdvancedNewFile plugin

View File

@@ -0,0 +1,15 @@
[
{ "keys": ["super+alt+n"], "command": "advanced_new_file"},
{ "keys": ["shift+super+alt+n"], "command": "advanced_new_file", "args": {"is_python": true}},
{
"keys": ["tab"],
"command": "insert_best_completion",
"args": {"default": "", "exact": false},
"context": [
{ "key": "advanced_new_file_completion"},
{ "key": "setting.tab_completion", "operator": "equal", "operand": true },
{ "key": "last_command", "operator": "not_equal", "operand": "insert_best_completion" },
{ "key": "auto_complete_visible" , "operator": "equal", "operand": false}
]
}
]

View File

@@ -0,0 +1,15 @@
[
{ "keys": ["super+alt+n"], "command": "advanced_new_file"},
{ "keys": ["shift+super+alt+n"], "command": "advanced_new_file", "args": {"is_python": true}},
{
"keys": ["tab"],
"command": "insert_best_completion",
"args": {"default": "", "exact": false},
"context": [
{ "key": "advanced_new_file_completion"},
{ "key": "setting.tab_completion", "operator": "equal", "operand": true },
{ "key": "last_command", "operator": "not_equal", "operand": "insert_best_completion" },
{ "key": "auto_complete_visible" , "operator": "equal", "operand": false}
]
}
]

View File

@@ -0,0 +1,16 @@
[
{ "keys": ["ctrl+alt+n"], "command": "advanced_new_file"},
{ "keys": ["shift+ctrl+alt+n"], "command": "advanced_new_file", "args": {"is_python": true}},
// Forces insert best autocomplete to run for advanced new file
{
"keys": ["tab"],
"command": "insert_best_completion",
"args": {"default": "", "exact": false},
"context": [
{ "key": "advanced_new_file_completion"},
{ "key": "setting.tab_completion", "operator": "equal", "operand": true },
{ "key": "last_command", "operator": "not_equal", "operand": "insert_best_completion" },
{ "key": "auto_complete_visible" , "operator": "equal", "operand": false}
]
}
]

View File

@@ -0,0 +1,18 @@
The MIT License (MIT)
Copyright (c) 2012 AdvancedNewFile authors
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,
sOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,90 @@
[
{
"caption": "Preferences",
"mnemonic": "n",
"id": "preferences",
"children":
[
{
"caption": "Package Settings",
"mnemonic": "P",
"id": "package-settings",
"children":
[
{
"caption": "AdvancedNewFile",
"children":
[
{
"command": "open_file",
"args": {"file": "${packages}/AdvancedNewFile/README.md"},
"caption": "README"
},
{ "caption": "-" },
{
"command": "open_file",
"args": {"file": "${packages}/AdvancedNewFile/AdvancedNewFile.sublime-settings"},
"caption": "Settings Default"
},
{
"command": "open_file",
"args": {"file": "${packages}/User/AdvancedNewFile.sublime-settings"},
"caption": "Settings User"
},
{ "caption": "-" },
{
"command": "open_file",
"args": {
"file": "${packages}/AdvancedNewFile/Default (OSX).sublime-keymap",
"platform": "OSX"
},
"caption": "Key Bindings Default"
},
{
"command": "open_file",
"args": {
"file": "${packages}/AdvancedNewFile/Default (Linux).sublime-keymap",
"platform": "Linux"
},
"caption": "Key Bindings Default"
},
{
"command": "open_file",
"args": {
"file": "${packages}/AdvancedNewFile/Default (Windows).sublime-keymap",
"platform": "Windows"
},
"caption": "Key Bindings Default"
},
{
"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": "Key Bindings User"
},
{ "caption": "-" }
]
}
]
}
]
}
]

View File

@@ -0,0 +1,181 @@
# AdvancedNewFile
Advanced file creation for Sublime Text 2 and Sublime Text 3.
## Overview
This plugin allows for faster file creation within a project. Please see the [Features](https://github.com/skuroda/Sublime-AdvancedNewFile#features) section for more detailed information about advanced features.
## Installation
Note with either method, you may need to restart Sublime Text 2 for the plugin to load.
### Package Control
Installation through [package control](http://wbond.net/sublime_packages/package_control) is recommended. It will handle updating your packages as they become available. To install, do the following.
* In the Command Palette, enter `Package Control: Install Package`
* Search for `AdvancedNewFile`
* In the Command Palette, enter `Package Control :Enable Package` -> select AdvancedNewFile
### Manual
Clone or copy this repository into the packages directory. By default, they are located at:
* OS X: ~/Library/Application Support/Sublime Text 2/Packages/
* Windows: %APPDATA%/Roaming/Sublime Text 2/Packages/
* Linux: ~/.config/sublime-text-2/Packages/
## Usage
Simply bring up the AdvancedNewFile input through the appropriate [key binding](https://github.com/skuroda/Sublime-AdvancedNewFile). Then, enter the path, along with the file name into the input field. Upon pressing enter, the file will be created. In addition, if the directories specified do not yet exists, they will also be created. For more advanced usage of this plugin, be sure to look at [Advanced Path Usage](https://github.com/skuroda/Sublime-AdvancedNewFile#advanced-path-usage). By default, the path to the file being created will be filled shown in the status bar as you enter the path information.
**Default directory:**
The default directory is specified by the `default_root` setting. By default, it will be the top directory of the folders listed in the window. If this cannot be resolved, the home directory will be used. See [Settings](https://github.com/skuroda/Sublime-AdvancedNewFile#settings) (`default_root`) for more information.
## Keymaps
If you have issues with keymaps, consider running [FindKeyConflicts](https://github.com/skuroda/FindKeyConflicts), also available through the package manager. Alternatively, set command logging to true by entering `sublime.log_commands(True)` in the Sublime Text console.
### Windows
`ctrl+alt+n`: General keymap to create new files.
`ctrl+shift+alt+n`: In addition to creating the folders specified, new folders will also contain an `__init__.py` file.
### OS X and Linux
The super keys for Linux and OS X are the Windows and command key respectively.
`super+alt+n`: General keymap to create new files.
`shift+super+alt+n`: In addition to creating the folders specified, new folders will also contain an `__init__.py` file.
## Settings
`alias`:
A dictionary that contains a set of aliases tied to a directory. For more information, see [Aliases](https://github.com/skuroda/Sublime-AdvancedNewFile#aliases)
`os_specific_alias`:
A dictionary containing a set of aliases tied to a directory. These aliases will be platform specific. For more information, see [Platform Specific Aliases](https://github.com/skuroda/Sublime-AdvancedNewFile#platform-specific-aliases)
`default_initial`:
A string that will be automatically inserted into the new file creation input.
`use_cursor_text`:
A boolean value determining if text from a buffer, bound by quotes or a selected region, will be auto inserted into the new file generation input field. If multiple cursors are used, the first entry either contained in quotes, are a selected region, will be used.
`show_files`:
A boolean value determining if regular files should be included in the autocompletion list.
`show_path`:
A boolean value used to determine if the path of the file to be created should be displayed in the status bar.
`default_root`:
This value is used to determine the default root when using AdvancedNewFile. It must be one of the following values:
* `project_folder`- The default path will be the folder specified by the 'default_folder_index' setting.
* `current` - The default path will be the directory of the current active view.
* `home` - The default path will be your home directory.
* `path` - The default path will be defined by the setting `default_path`
If the current view's directory cannot be resolved, the top level folder in the window will be used. If the top level folder in the window cannot be resolved either, the home directory will be used.
`default_path`:
This path is used as the default if `path` has been specified for the setting `default_root`. This path should be absolute. If a relative path is specified, it will be relative to the AdvancedNewFile package directory.
`default_folder_index`:
An integer value representing a folder index to be used when "folder" is specified for "default_root". If an index outside of the range of existing folders is used, it will default to 0 (the top level folder).
`alias_root`:
This entry defines the root that will be used when resolving aliases defined as relative paths. For more information about valid entries, see `default_root`. Note that for path, `alias_path` will be specified.
`alias_path`:
This path is used as the default if `path` has been specified for the setting `alias_root`.
`alias_folder_index`:
An integer value representing the folder index to use when "folder" is specified for "alias_root". If an index outside of the range of the existing folders is used, it will default to 0.
`ignore_case`:
A boolean specifying if case should be ignored when building auto complete list.
`auto_refresh_sidebar`:
A boolean specifying if folders should automatically refresh and update the sidebar. In some builds, the sidebar does not refresh when contents of project folder are updated. This setting is required to refresh the sidebar in these circumstances. False by default.
### Project Specific Settings
All of the above settings can also be specified as part of the project specific settings. These values override any previous values set by higher level settings, with aliases being an exception. Alias settings will be merged with higher level configurations for alias. In addition, if the same alias exist for both default/user settings and project settings, the project setting will take precedence.
"settings":
{
"AdvancedNewFile":
{
"default_initial": "/project/specific/path"
}
}
## Features
#### __init__.py creation:
This plugin may optionally create `__init__` in the created directories. Please reference [Key Maps](https://github.com/skuroda/Sublime-AdvancedNewFile#keymaps) to see the default key bindings to do this.
#### Tab Autocompletion:
After typing in a partial path, simply press tab to autocomplete it. Continue to press tab to cycle through the options.
### Advanced Path Usage
#### Home directory:
To begin at the home directory simply start with `~/` like you would in the shell.
#### Aliases:
You can create an alias to quickly navigate to a directory. Simply type in the alias followed by a colon. Then specify the path as you would normally. Note, in an event a specified alias conflicts with a [predefined alias](https://github.com/skuroda/Sublime-AdvancedNewFile#predefined-aliases), the specified alias will take precedence.
Alias paths may be relative or absolute. If a relative path is specified, the `alias_root` setting will be used as the base. When specifying absolute paths, be sure to use the system specific style (e.g. Windows `C:\\Users\\username\\Desktop`, OS X and Linix `/home/username/desktop/`). In addition, you may specify an alias from the home directory by using `~/`.
If an invalid alias is specified, an error pop up will be displayed when trying to create the file.
Sample aliases:
{
"alias": {
"Desktop": "~/Desktop/"
}
}
To use the above alias, when specifying a new file enter `Desktop:testDir/testFile`, which would then create a file at `<home_directory>/Desktop/testDir/testFile`.
##### Platform Specific Aliases
You can also create aliases that are platform specific. These follow a similar set of rules as aliases. However, rather than specifying a string path to use, a dictionary is specified. This dictionary may contain the following keys: `windows`, `linux`, and `osx`. The path for this particular alias will be used based on the operating system in use. If the same alias is specified in both `alias` and `os_specific_alias`, the path in `os_specific_alias` will be used.
Sample OS Specific Aliases:
{
"os_specific_alias": {
"subl_packages" {
"windows": "~\\AppData\\Roaming\\Sublime Text 2\\Packages",
"linux": "~/.config/sublime-text-2/Packages",
"osx": "~/Library/Application Support/Sublime Text 2/Packages"
}
}
}
##### Predefined Aliases
###### Top level folders in window
Top level folders can be specified by typing in the name of the folder followed by a colon. Then specify the path as you would normally.
###### Current Working Directory
To specify the current working directory, simply type a colon, without any preceding text.
## Notes
Thanks to Dima Kukushkin ([xobb1t](https://github.com/xobb1t)) for the original work on this plugin. Also, thank you to [facelessuser](https://github.com/facelessuser), and by extension biermeester and matthjes for the idea of platform specific settings.
### Contributors
* [xobb1t](https://github.com/xobb1t)
* [edmundask](https://github.com/edmundask)
* [alirezadot](https://github.com/alirezadot)
* [aventurella](https://github.com/aventurella)
* [skuroda](https://github.com/skuroda)

View File

@@ -0,0 +1,7 @@
{
"install": "messages/install.txt",
"2012.11.08.20.00.00": "messages/1.txt",
"2012.11.12.11.00.00": "messages/2.txt",
"2012.11.26.11.00.00": "messages/3.txt",
"2012.12.17.11.00.00": "messages/4.txt"
}

View File

@@ -0,0 +1 @@
The repository has now been transferred to the proper URL. If you experienced any issues while this transition was occuring, my apologies. Please take a look at the README for new enhancments if you have not done so already.

View File

@@ -0,0 +1,10 @@
New Features/Enhancements:
- Add setting to display path for file to be created in status bar. - Default true
- Add setting to set default base path (home, current, top_folder, path). - Default "top_folder"
- Add support for relative paths in alias.
Please see the README for more information about the new settings.
Bug Fixes:
- Auto complete bug for files with spaces in their name

View File

@@ -0,0 +1,12 @@
New Features/Enhancements:
- Add OS Specific Aliases to settings.
- Display an error when attempting to use an invalid alias.
- Display an error when attempting to open a directory in a view.
- Display an error if path creation fails.
Please see the README for more information about the new settings.
Bug Fixes:
- Status bar update causing errors when no view is present.
- Specifying absolute paths for Windows produced unexpected behavior.

View File

@@ -0,0 +1,12 @@
New Features/Enhancements:
- Enabling "use_cursor_text" will fill with selected regions. The first cursor/region to match the conditions (region or quoted section) will be used.
- Autocompleting with tab where there is only a single completion option will continue completion on subsequent directories.
Please see the README for more information about the new settings.
Bug Fixes:
- Properly display completions when using "ctrl+space" to manually display auto complete options.
- Prevent error pop up from occuring when explicitly creating a directory structure.
- Fix bug where using cursor text causes an error.
- Prevent spaces from being inserted when tab is without a possible completion.

View File

@@ -0,0 +1,9 @@
Thank you for installing the AdvancedNewFile plugin.
For more information please visit https://github.com/skuroda/Sublime-AdvancedNewFile.
Note you may need to restart Sublime Text 2 after installing this plugin.
If you have any questions, comments, or run into issues, please let me know! Hope you enjoy the plugin.
Thank you!

View File

@@ -0,0 +1 @@
{"url": "https://github.com/skuroda/Sublime-AdvancedNewFile", "version": "2013.04.02.21.22.36", "description": "File creation plugin for Sublime Text 2 and Sublime Text 3."}