Skip to content
Browse files

[fixes #7] Strip whitespace inside when matching opening symbol of a …

…pair
  • Loading branch information...
1 parent 913e90d commit a8d80367a88502f95bcc29f230cb837cbbae78a7 @jcartledge committed Oct 24, 2012
Showing with 12 additions and 40 deletions.
  1. +6 −34 Surround.py
  2. +6 −6 surround.sublime-settings
View
40 Surround.py
@@ -2,30 +2,17 @@
import sublime_plugin
import re
-surround_settings = sublime.load_settings('surround.sublime-settings')
-
class SurroundCommand(sublime_plugin.TextCommand):
""" Base class for surround commands
"""
+ def __init__(self, _):
+ self.settings = sublime.load_settings('surround.sublime-settings')
+ sublime_plugin.TextCommand.__init__(self, _)
+
def pairs_for_replacement(self, surround):
- pairs = surround_settings.get('surround_pairs_for_replacement')
- if pairs is None:
- pairs = {
- "{": ["{ ", " }"],
- "}": ["{", "}"],
- "[": ["[ ", " ]"],
- "]": ["[", "]"],
- "(": ["( ", " )"],
- ")": ["(", ")"],
- "<": ["< ", " >"],
- ">": ["<", ">"],
- "<!--": ["<!-- ", " -->"],
- "-->": ["<!--", "-->"],
- "/*": ["/* ", " */"],
- "*/": ["/*", "*/"]
- }
+ pairs = self.settings.get('surround_pairs_for_replacement')
return self.pair(surround, pairs)
def pair(self, surround, pairs):
@@ -145,22 +132,7 @@ def search_patterns_for_surround(self, surround):
return surround
def pairs_for_search(self, surround):
- pairs = surround_settings.get('surround_pairs_for_search')
- if pairs is None:
- pairs = {
- "{": ["{", "}"],
- "}": ["{", "}"],
- "[": ["[", "]"],
- "]": ["[", "]"],
- "(": ["(", ")"],
- ")": ["(", ")"],
- "<": ["<", ">"],
- ">": ["<", ">"],
- "<!--": ["<!--", "-->"],
- "-->": ["<!--", "-->"],
- "/*": ["/*", "*/"],
- "*/": ["/*", "*/"],
- }
+ pairs = self.settings.get('surround_pairs_for_search')
return self.pair(surround, pairs)
def tags_for_search(self, surround):
View
12 surround.sublime-settings
@@ -14,17 +14,17 @@
"*/": ["/*", "*/"]
},
"surround_pairs_for_search": {
- "{": ["{", "}"],
+ "{": ["\\{[\\s]?", "[\\s]?s*\\}"],
"}": ["{", "}"],
- "[": ["[", "]"],
+ "[": ["\\[[\\s]?", "[\\s]?\\]"],
"]": ["[", "]"],
- "(": ["(", ")"],
+ "(": ["\\([\\s]?", "[\\s]?\\)"],
")": ["(", ")"],
- "<": ["<", ">"],
+ "<": ["<[\\s]?", "[\\s]?>"],
">": ["<", ">"],
- "<!--": ["<!--", "-->"],
+ "<!--": ["<!--[\\s]?", "[\\s]?-->"],
"-->": ["<!--", "-->"],
- "/*": ["/*", "*/"],
+ "/*": ["\\/\\*", "\\*\\/"],
"*/": ["/*", "*/"]
}
}

0 comments on commit a8d8036

Please sign in to comment.
Something went wrong with that request. Please try again.