Permalink
Browse files

- Lint fixes

- Plugin loading fix
  • Loading branch information...
1 parent b9d3bc5 commit c866b30b57c13eef8d5a3d311c5a4aca89aaca68 @facelessuser committed May 17, 2014
Showing with 52 additions and 49 deletions.
  1. +7 −8 rr_manual_sequencer.py
  2. +4 −3 rr_plugin.py
  3. +26 −26 rr_replacer.py
  4. +15 −12 rr_sequencer.py
@@ -1,4 +1,3 @@
-import sublime
import sublime_plugin
import re
@@ -16,7 +15,7 @@ def run_sequence(self, value):
# Parse Input
matches = re.match(r"(\?)?\s*([^\+][\w\W]*|\+?)\s*:\s*([\w\W]*)\s*", value)
- if matches != None:
+ if matches is not None:
# Sequence
value = matches.group(3)
@@ -29,20 +28,20 @@ def run_sequence(self, value):
multi_pass = True
# Action?
- elif matches.group(2) != '' and matches.group(2) != None:
+ elif matches.group(2) != '' and matches.group(2) is not None:
# Mark or unmark: parse options?
params = re.match(
r"^(unmark|mark)\s*=\s*([\w\s\.\-]*)\s*(?:,\s*([\w\s\.\-]*)\s*)?(?:,\s*([\w\s\.\-]*))?\s*",
matches.group(2)
)
- if params != None:
- if params.group(2) != '' and params.group(2) != None:
+ if params is not None:
+ if params.group(2) != '' and params.group(2) is not None:
# Mark options
if params.group(1) == 'mark':
options['key'] = params.group(2).strip()
- if params.group(3) != '' and params.group(3) != None:
+ if params.group(3) != '' and params.group(3) is not None:
options['scope'] = params.group(3).strip()
- if params.group(4) != '' and params.group(4) != None:
+ if params.group(4) != '' and params.group(4) is not None:
options['style'] = params.group(4).strip()
action = params.group(1)
# Unmark options
@@ -58,7 +57,7 @@ def run_sequence(self, value):
view = self.window.active_view()
# Execute sequence
- if view != None:
+ if view is not None:
view.run_command(
'reg_replace',
{
View
@@ -1,14 +1,14 @@
import sublime
import imp
import sys
-import traceback
+# import traceback
from os.path import join, normpath
import re
def sublime_format_path(pth):
m = re.match(r"^([A-Za-z]{1}):(?:/|\\)(.*)", pth)
- if sublime.platform() == "windows" and m != None:
+ if sublime.platform() == "windows" and m is not None:
pth = m.group(1) + "/" + m.group(2)
return pth.replace("\\", "/")
@@ -18,7 +18,7 @@ class Plugin(object):
@classmethod
def purge(cls):
- loaded = []
+ cls.loaded = []
@classmethod
def get_module(cls, module_name, path_name):
@@ -27,6 +27,7 @@ def get_module(cls, module_name, path_name):
module = sys.modules[module_name]
except:
module = cls.load_module(module_name, path_name)
+ return module
@classmethod
def load_module(cls, module_name, path_name):
View
@@ -33,7 +33,7 @@ def run_plugin(self, text):
Run the associated plugin on text
"""
- if self.plugin != None:
+ if self.plugin is not None:
module = None
try:
module = Plugin.load(self.plugin)
@@ -56,11 +56,11 @@ def filter_by_selection(self, regions, extractions=None):
for sel in sels:
if region.begin() >= sel.begin() and region.end() <= sel.end():
new_regions.append(region)
- if extractions != None:
+ if extractions is not None:
new_extractions.append(extractions[idx])
break
idx += 1
- if extractions == None:
+ if extractions is None:
return new_regions
else:
return new_regions, new_extractions
@@ -121,7 +121,7 @@ def qualify_by_scope(self, region, pattern):
break
pt += 1
# If qualificatin of one fails, bail
- if qualify == False:
+ if qualify is False:
return qualify
# Qualification completed successfully
return True
@@ -138,10 +138,10 @@ def greedy_replace(self, find, replace, regions, scope_filter):
# Step through all targets and qualify them for replacement
for region in reversed(regions):
# Does the scope qualify?
- qualify = self.qualify_by_scope(region, scope_filter) if scope_filter != None else True
+ qualify = self.qualify_by_scope(region, scope_filter) if scope_filter is not None else True
if qualify:
replaced += 1
- if self.find_only or self.action != None:
+ if self.find_only or self.action is not None:
# If "find only" or replace action is overridden, just track regions
self.target_regions.append(region)
else:
@@ -168,7 +168,7 @@ def non_greedy_replace(self, find, replace, regions, scope_filter):
count = 0
for region in regions:
# Does the scope qualify?
- qualify = self.qualify_by_scope(region, scope_filter) if scope_filter != None else True
+ qualify = self.qualify_by_scope(region, scope_filter) if scope_filter is not None else True
if qualify:
# Update as new replacement candidate
selected_region = region
@@ -178,15 +178,15 @@ def non_greedy_replace(self, find, replace, regions, scope_filter):
count += 1
# If regions were already swept till the end, skip calculation relative to cursor
- if selected_region != None and count < last_region and pt != None:
+ if selected_region is not None and count < last_region and pt is not None:
# Try and find the first qualifying match contained withing the first selection or after
reverse_count = last_region
for region in reversed(regions):
# Make sure we are not checking previously checked regions
# And check if region contained after start of selection?
if reverse_count >= count and region.end() - 1 >= pt:
# Does the scope qualify?
- qualify = self.qualify_by_scope(region, scope_filter) if scope_filter != None else True
+ qualify = self.qualify_by_scope(region, scope_filter) if scope_filter is not None else True
if qualify:
# Update as new replacement candidate
selected_region = region
@@ -197,11 +197,11 @@ def non_greedy_replace(self, find, replace, regions, scope_filter):
break
# Did we find a suitable region?
- if selected_region != None:
+ if selected_region is not None:
# Show Instance
replaced += 1
self.view.show(selected_region.begin())
- if self.find_only or self.action != None:
+ if self.find_only or self.action is not None:
# If "find only" or replace action is overridden, just track regions
self.target_regions.append(selected_region)
else:
@@ -309,7 +309,7 @@ def apply_scope_regex(self, string, re_find, replace, greedy_replace, multi):
replaced = 0
extraction = string
- if multi and not self.find_only and self.action == None:
+ if multi and not self.find_only and self.action is None:
extraction, replaced = self.apply_multi_pass_scope_regex(string, extraction, re_find, replace, greedy_replace)
else:
if greedy_replace:
@@ -357,7 +357,7 @@ def greedy_scope_literal_replace(self, regions, find, replace, greedy_replace):
pass
if replaced > 0:
total_replaced += 1
- if self.find_only or self.action != None:
+ if self.find_only or self.action is not None:
self.target_regions.append(region)
else:
self.view.replace(self.edit, region, self.run_plugin(extraction))
@@ -400,7 +400,7 @@ def non_greedy_scope_literal_replace(self, regions, find, replace, greedy_replac
count += 1
# If regions were already swept till the end, skip calculation relative to cursor
- if selected_region != None and count < last_region and pt != None:
+ if selected_region is not None and count < last_region and pt is not None:
# Try and find the first qualifying match contained withing the first selection or after
reverse_count = last_region
for region in reversed(regions):
@@ -426,11 +426,11 @@ def non_greedy_scope_literal_replace(self, regions, find, replace, greedy_replac
break
# Did we find a suitable region?
- if selected_region != None:
+ if selected_region is not None:
# Show Instance
total_replaced += 1
self.view.show(selected_region.begin())
- if self.find_only or self.action != None:
+ if self.find_only or self.action is not None:
# If "find only" or replace action is overridden, just track regions
self.target_regions.append(selected_region)
else:
@@ -451,7 +451,7 @@ def greedy_scope_replace(self, regions, re_find, replace, greedy_replace, multi)
extraction, replaced = self.apply_scope_regex(string, re_find, replace, greedy_replace, multi)
if replaced > 0:
total_replaced += 1
- if self.find_only or self.action != None:
+ if self.find_only or self.action is not None:
self.target_regions.append(region)
else:
self.view.replace(self.edit, region, self.run_plugin(extraction))
@@ -494,7 +494,7 @@ def non_greedy_scope_replace(self, regions, re_find, replace, greedy_replace, mu
try:
# If regions were already swept till the end, skip calculation relative to cursor
- if selected_region != None and count < last_region and pt != None:
+ if selected_region is not None and count < last_region and pt is not None:
# Try and find the first qualifying match contained withing the first selection or after
reverse_count = last_region
for region in reversed(regions):
@@ -514,11 +514,11 @@ def non_greedy_scope_replace(self, regions, re_find, replace, greedy_replace, mu
return total_replaced
# Did we find a suitable region?
- if selected_region != None:
+ if selected_region is not None:
# Show Instance
total_replaced += 1
self.view.show(selected_region.begin())
- if self.find_only or self.action != None:
+ if self.find_only or self.action is not None:
# If "find only" or replace action is overridden, just track regions
self.target_regions.append(selected_region)
else:
@@ -550,7 +550,7 @@ def select_scope_regions(self, regions, greedy_scope):
# Walk backwards seeing which scope is valid
# Quit if you reach the already selected first scope
- if selected_region != None and last_region > first_region and pt != None:
+ if selected_region is not None and last_region > first_region and pt is not None:
reverse_count = last_region
for region in reversed(regions):
if reverse_count >= first_region and region.end() - 1 >= pt:
@@ -560,7 +560,7 @@ def select_scope_regions(self, regions, greedy_scope):
break
# Store the scope if we found one
- if selected_region != None:
+ if selected_region is not None:
replaced += 1
self.view.show(selected_region.begin())
self.target_regions += [selected_region]
@@ -586,10 +586,10 @@ def scope_apply(self, pattern):
multi = bool(pattern['multi_pass_regex']) if 'multi_pass_regex' in pattern else False
literal = bool(pattern['literal']) if 'literal' in pattern else False
dotall = bool(pattern['dotall']) if 'dotall' in pattern else False
- self.plugin = pattern.get("plugin", None)
+ self.plugin = pattern.get("plugin", None)
self.plugin_args = pattern.get("args", {})
- if scope == None or scope == '':
+ if scope is None or scope == '':
return replace
if self.selection_only:
@@ -606,7 +606,7 @@ def scope_apply(self, pattern):
regions = self.filter_by_selection(regions)
# Find supplied?
- if find != None:
+ if find is not None:
# Compile regex: Ignore case flag?
if not literal:
try:
@@ -620,7 +620,7 @@ def scope_apply(self, pattern):
sublime.error_message('REGEX ERROR: %s' % str(err))
return replaced
- #Greedy Scope?
+ # Greedy Scope?
if greedy_scope:
replaced = self.greedy_scope_replace(regions, re_find, replace, greedy_replace, multi)
else:
View
@@ -16,6 +16,8 @@
DEFAULT_MULTI_PASS_MAX_SWEEP = 100
MODULE_NAME = 'RegReplace'
+rrsettings = {}
+
def underline(regions):
"""
@@ -63,14 +65,14 @@ def find_replacements(self, view):
match = False
file_name = view.file_name()
- if file_name != None and rrsettings.get('on_save', False):
+ if file_name is not None and rrsettings.get('on_save', False):
replacements = rrsettings.get('on_save_sequences', [])
scope = rrsettings.get('on_save_highlight_scope', None)
style = rrsettings.get('on_save_highlight_style', None)
self.options["key"] = MODULE_NAME
- if scope != None:
+ if scope is not None:
self.options["scope"] = scope
- if style != None:
+ if style is not None:
self.options["style"] = style
for item in replacements:
found = False
@@ -84,12 +86,12 @@ def find_replacements(self, view):
for regex in item['file_regex']:
try:
flags = 0
- if not 'case' in item or not bool(item['case']):
+ if 'case' not in item or not bool(item['case']):
flags |= re.IGNORECASE
if 'dotall' in item and bool(item['dotall']):
flags |= re.DOTALL
r = re.compile(regex, flags)
- if r.match(file_name) != None:
+ if r.match(file_name) is not None:
found = True
self.select(item)
break
@@ -202,9 +204,9 @@ def run_replace(self, answer):
# See if we know this view
window = sublime.active_window()
- view = window.active_view() if window != None else None
- if view != None:
- if self.handshake != None and self.handshake == view.id():
+ view = window.active_view() if window is not None else None
+ if view is not None:
+ if self.handshake is not None and self.handshake == view.id():
self.forget_handshake()
# re-run command to actually replace targets
view.run_command(
@@ -313,7 +315,7 @@ def print_results_panel(self, text):
window = self.view.window()
view = window.get_output_panel('reg_replace_results')
- #Turn off stylings in panel
+ # Turn off stylings in panel
view.settings().set('draw_white_space', 'none')
view.settings().set('draw_indent_guides', False)
view.settings().set('gutter', 'none')
@@ -372,7 +374,7 @@ def find_and_replace(self):
# Walk the sequence
# Multi-pass only if requested and will be occuring
- if self.multi_pass and not self.find_only and self.action == None:
+ if self.multi_pass and not self.find_only and self.action is None:
# Multi-pass initialization
current_replacements = 0
total_replacements = 0
@@ -421,7 +423,7 @@ def start_sequence(self):
else:
self.clear_highlights(MODULE_NAME)
# Perform action
- if self.action != None:
+ if self.action is not None:
if not self.perform_action():
results = 'Error: Bad Action!'
@@ -443,7 +445,7 @@ def run(
"""
self.find_only = bool(find_only)
- self.action = action.strip() if action != None else action
+ self.action = action.strip() if action is not None else action
self.full_file = bool(regex_full_file_with_selections)
self.selection_only = True if not no_selection and rrsettings.get('selection_only', False) and self.is_selection_available() else False
self.max_sweeps = rrsettings.get('multi_pass_max_sweeps', DEFAULT_MULTI_PASS_MAX_SWEEP)
@@ -474,6 +476,7 @@ def run(
else:
self.replace_obj.close()
+
def plugin_loaded():
global rrsettings
rrsettings = sublime.load_settings('reg_replace.sublime-settings')

0 comments on commit c866b30

Please sign in to comment.