When you say User
folder here, do you mean the configuration area of Sublime in general or your User
package in particular (Preferences: Browse Packages
, and it’s a folder that appears in the list).
sublime-package
files aren’t loaded from that location, only from inside of Installed Packages
or a subdirectory inside of it; perhaps that was your problem initially?
In any case, indeed the override alters the package entirely; if your goal is to do both then you need a different solution. Combining that with your desire to not have it be automatically updated (which, given the last update date was 7 years ago, is probably not forthcoming anyway) then the most expedient solution would probably be to just use the plugin directly and avoid using it as a package.
The package mentality is more for a “I want this piece of functionality and I don’t want to have to install it and keep it updated myself” kind of workflow, which is not really what you’re after here. You want a version of this particular functionality custom tuned to your own liking, for which you’re willing to install it manually and perform updates manually.
In that case:
import sublime_plugin
class AppendCharacterCommand(sublime_plugin.TextCommand):
"""
Append the provided character to the end of the current line if it's not
already there, possibly also entering a newline as well.
"""
def run(self, edit, character=';', enter_new_line=False):
def insert_character(point):
self.view.insert(edit, point, character)
def is_character(point):
return self.view.substr(point) == character
for region in self.view.sel():
line = self.view.line(region)
line_begin = line.begin()
line_end = line.end()
# go to the first character from the end that isn't whitespace
while(self.view.substr(line_end - 1).isspace() and line_end != line_begin):
line_end -= 1
if line_end == line_begin:
continue
if self.view.match_selector(line_end - 1, 'comment'):
point = self.view.extract_scope(line_end - 1).a - 1
if point < line_begin:
continue
# go to the first character before the comment that isn't whitespace
while(self.view.substr(point).isspace() and point != line_begin):
point -= 1
if not self.view.substr(point).isspace() and not is_character(point):
insert_character(point + 1)
elif not is_character(line_end - 1):
insert_character(line_end)
if enter_new_line == True:
self.view.run_command("run_macro_file", {"file": "Packages/Default/Add Line.sublime-macro"})
Store that in your User
package (how you get there outlined above) as any .py
file you like, then add some custom key bindings:
{ "keys": ["ctrl+;"], "command": "append_character", "args": {"character": ";"} },
{ "keys": ["ctrl+shift+;"], "command": "append_character", "args": {"character": ";", "enter_new_line": true} },
{ "keys": ["ctrl+,"], "command": "append_character", "args": {"character": ","} },
{ "keys": ["ctrl+shift+,"], "command": "append_character", "args": {"character": ",", "enter_new_line": true} },
This is based on the version from the package, but cleaned up a bit (hence the name is also changed to make sure that older key bindings won’t trigger it). It takes as an argument the character to be added, so you can use it with any characters you like.