From 9dfdc57e74569a0d54f73006a0fb02fd64324a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBuk?= Date: Fri, 24 Mar 2017 21:54:54 +0100 Subject: [PATCH] Issue 6 fix and other minor fixes and improvements https://github.com/taigh/sublime-tagify/issues/6 --- Readme.md | 3 ++- Tagify.sublime-settings | 5 ++++- tagify.py | 31 ++++++++++++++++++++----------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/Readme.md b/Readme.md index 2f2abed..294a817 100644 --- a/Readme.md +++ b/Readme.md @@ -26,4 +26,5 @@ Using Ctrl+t you can bring menu with common and recently u ## Installation Clone this repo into packages or search in package control. - +## News +- 24 march 2017 - you can custimize tag re, also plaintext files support added diff --git a/Tagify.sublime-settings b/Tagify.sublime-settings index 500cf1a..97bcbfd 100644 --- a/Tagify.sublime-settings +++ b/Tagify.sublime-settings @@ -7,9 +7,12 @@ "common_tags": ["todo", "bug", "workaround"], // Extensions of files which will be processed by tagify + // add "none" (without " marks) to process files without extensions "extensions": ["py", "html", "htm", "js"], // In some cases we dont want particular #@string to be considered as tag // put those "bad" tags here - "blacklisted_tags": ["property"] + "blacklisted_tags": ["property"], + + "tag_re": "#@((?:[_a-zA-Z0-9]+))" } diff --git a/tagify.py b/tagify.py index e3f2f7b..e30f370 100644 --- a/tagify.py +++ b/tagify.py @@ -8,9 +8,10 @@ class Prefs: def read(): settings = sublime.load_settings('Tagify.sublime-settings') Prefs.common_tags = settings.get('common_tags', ["todo", "bug", "workaround"]) - Prefs.blacklisted_tags = set(settings.get('blacklisted_tags', ["property"])) + Prefs.blacklisted_tags = set(settings.get('blacklisted_tags', ["property"]) or []) Prefs.analyse_on_start = settings.get('analyse_on_start', True) Prefs.extensions = settings.get('extensions', ["py", "html", "htm", "js"]) + Prefs.tag_re = settings.get('tag_re', "@((?:[_a-zA-Z0-9]+))") @staticmethod def load(): @@ -19,6 +20,7 @@ def load(): settings.add_on_change('blacklisted_tags', Prefs.read) settings.add_on_change('analyse_on_start', Prefs.read) settings.add_on_change('extensions', Prefs.read) + settings.add_on_change('tag_re', Prefs.read) Prefs.read() class TagifyCommon: @@ -31,12 +33,13 @@ class Tagifier(sublime_plugin.EventListener): def __init__(self, *args, **kw): super(Tagifier, self).__init__(*args, **kw) + Prefs.load() self.last_sel = None def analyse_regions(self, view, regions): for region in regions: region = view.line(region) - tag_region = view.find("@(?:[_a-zA-Z0-9]+)", region.a) + tag_region = view.find(Prefs.tag_re, region.a) if tag_region.a >= 0: self.tags_regions.append(tag_region) view.add_regions("tagify", self.tags_regions, "markup.inserted", @@ -44,7 +47,7 @@ def analyse_regions(self, view, regions): def reanalyse_all(self, view): self.tags_regions = [] - regions = view.find_all("#@(?:[_a-zA-Z0-9]+)") + regions = view.find_all(Prefs.tag_re) self.analyse_regions(view, regions) def on_post_save_async(self, view): @@ -64,12 +67,13 @@ def on_selection_modified(self, view): for region in view.get_regions('tagify-link'): if region.contains(sel) and sel.size() > 0: name = view.substr(region) - real_name = TagifyCommon.data[name]["file"] - line_no = TagifyCommon.data[name]["line"] - view.window().open_file( - "%s:%i" % (real_name, line_no), sublime.ENCODED_POSITION) - view.sel().clear() - return + if name in TagifyCommon.data: + real_name = TagifyCommon.data[name]["file"] + line_no = TagifyCommon.data[name]["line"] + view.window().open_file( + "%s:%i" % (real_name, line_no), sublime.ENCODED_POSITION) + view.sel().clear() + return class ShowTagsMenuCommand(sublime_plugin.TextCommand): @@ -114,7 +118,6 @@ class TagifyCommand(sublime_plugin.WindowCommand): def __init__(self, arg): super(TagifyCommand, self).__init__(arg) - self.tag_re = re.compile("#@((?:[_a-zA-Z0-9]+))(.*?)$") Prefs.load() if Prefs.analyse_on_start and not TagifyCommon.ready: TagifyCommon.ready = True @@ -164,13 +167,19 @@ def process_file_list(self, paths, ctags, dir_prefix=None, root_prefix=None): folder = root_prefix else: folder = dirname - ext = filename.split('.')[-1] + split_filename = filename.split('.') + ext = split_filename[-1] processed_extensions = Prefs.extensions if ext in processed_extensions: self.tagify_file(dirname, filename, ctags, folder) + if None in processed_extensions and len(split_filename) == 1: + self.tagify_file(dirname, filename, ctags, folder) def run(self, quiet=False): + Prefs.read() + self.tag_re = re.compile("%s(.*?)$" % Prefs.tag_re) + ctags = {} #process opened folders