From d07262c63af9aa56114648092d0a9d047bcd98d2 Mon Sep 17 00:00:00 2001 From: Vova Kolobok Date: Mon, 8 Apr 2013 17:36:42 +0700 Subject: [PATCH 1/4] modifies smart_lists adds non-lists patterns: block quotes (>); line block (|); title block (%); marker of ordered list may be enclosed in parentheses or followed by a single right-parentheses; list item may contain multiple paragraphs (i.e. empty list bullet is converted to whitespaces) --- Default.sublime-keymap | 2 +- smart_list.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Default.sublime-keymap b/Default.sublime-keymap index 28a78b4..8d1301b 100644 --- a/Default.sublime-keymap +++ b/Default.sublime-keymap @@ -12,7 +12,7 @@ { "keys": ["enter"], "command": "smart_list", "context": [ { "key": "selector", "operator": "equal", "operand": "text.html.markdown" }, - { "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*([-+\\**]|\\d+\\.+)\\s+" } + { "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*([-+\\**\\>\\|%]+|[(]?\\d+[.)]+)\\s+" } ] }, { "keys": ["enter"], "command": "smart_list", "context": diff --git a/smart_list.py b/smart_list.py index c1e229f..0edcc61 100644 --- a/smart_list.py +++ b/smart_list.py @@ -7,9 +7,10 @@ import sublime_plugin -ORDER_LIST_PATTERN = re.compile(r"(\s*)(\d+)(\.\s+)\S+") +ORDER_LIST_PATTERN = re.compile(r"(\s*[(]?)(\d+)([.)]\s+)\S+") UNORDER_LIST_PATTERN = re.compile(r"(\s*[-+\**]+)(\s+)\S+") -EMPTY_LIST_PATTERN = re.compile(r"(\s*([-+\**]|\d+\.+))\s+$") +EMPTY_LIST_PATTERN = re.compile(r"(\s*)([-+\**]|[(]?\d+[.)])(\s+)$") +NONLIST_PATTERN = re.compile(r"(\s*[>|%]+)(\s+)\S?") class SmartListCommand(sublime_plugin.TextCommand): @@ -32,7 +33,11 @@ def run(self, edit): match = EMPTY_LIST_PATTERN.match(before_point_content) if match: + insert_text = match.group(1) + \ + re.sub(r'\S', ' ', str(match.group(2))) + \ + match.group(3) self.view.erase(edit, before_point_region) + self.view.insert(edit, line_region.a, insert_text) break match = ORDER_LIST_PATTERN.match(before_point_content) @@ -49,6 +54,12 @@ def run(self, edit): self.view.insert(edit, region.a, "\n" + insert_text) break + match = NONLIST_PATTERN.match(before_point_content) + if match: + insert_text = match.group(1) + match.group(2) + self.view.insert(edit, region.a, "\n" + insert_text) + break + self.view.insert(edit, region.a, '\n') self.adjust_view() From bb1bb76179771212c1f21883d9b64d0a299fc98c Mon Sep 17 00:00:00 2001 From: Vova Kolobok Date: Mon, 8 Apr 2013 19:45:13 +0700 Subject: [PATCH 2/4] new line should have the same indent as prev ST does it by default, so SM should too --- smart_list.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/smart_list.py b/smart_list.py index 0edcc61..aebd927 100644 --- a/smart_list.py +++ b/smart_list.py @@ -60,7 +60,8 @@ def run(self, edit): self.view.insert(edit, region.a, "\n" + insert_text) break - self.view.insert(edit, region.a, '\n') + self.view.insert(edit, region.a, '\n' + \ + re.sub(r'\S+\s*', '', before_point_content)) self.adjust_view() def adjust_view(self): From 2ff258d9d3c4a7e89d74aee62a991b5b8e411408 Mon Sep 17 00:00:00 2001 From: Vova Kolobok Date: Mon, 22 Apr 2013 19:40:45 +0700 Subject: [PATCH 3/4] reverts prev commit; adds option for empty bullet --- SmartMarkdown.sublime-settings | 6 +++++- smart_list.py | 17 ++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/SmartMarkdown.sublime-settings b/SmartMarkdown.sublime-settings index 69d1fb2..2ab86e8 100644 --- a/SmartMarkdown.sublime-settings +++ b/SmartMarkdown.sublime-settings @@ -7,5 +7,9 @@ "pandoc_args": [], "pandoc_args_pdf": [], "pandoc_args_html": [], - "pandoc_args_docx": [] + "pandoc_args_docx": [], + + /* If true empty bullet will be converted into whitespaces when pressing enter, + if false empty bullet will be erased completely */ + "empty_list_bullet": false } \ No newline at end of file diff --git a/smart_list.py b/smart_list.py index aebd927..9273d7b 100644 --- a/smart_list.py +++ b/smart_list.py @@ -33,11 +33,15 @@ def run(self, edit): match = EMPTY_LIST_PATTERN.match(before_point_content) if match: - insert_text = match.group(1) + \ - re.sub(r'\S', ' ', str(match.group(2))) + \ - match.group(3) - self.view.erase(edit, before_point_region) - self.view.insert(edit, line_region.a, insert_text) + settings = sublime.load_settings("SmartMarkdown.sublime-settings") + if settings.get("empty_list_bullet"): + insert_text = match.group(1) + \ + re.sub(r'\S', ' ', str(match.group(2))) + \ + match.group(3) + self.view.erase(edit, before_point_region) + self.view.insert(edit, line_region.a, insert_text) + else: + self.view.erase(edit, before_point_region) break match = ORDER_LIST_PATTERN.match(before_point_content) @@ -60,8 +64,7 @@ def run(self, edit): self.view.insert(edit, region.a, "\n" + insert_text) break - self.view.insert(edit, region.a, '\n' + \ - re.sub(r'\S+\s*', '', before_point_content)) + self.view.insert(edit, region.a, '\n') self.adjust_view() def adjust_view(self): From a4ae20043ed983ad7109b24d1e331551f7b7298e Mon Sep 17 00:00:00 2001 From: Vova Kolobok Date: Sun, 16 Jun 2013 20:03:54 +0700 Subject: [PATCH 4/4] adds break for non-lists patterns if current line and previous one are empty (viz. [%>|]\s), enter erases content of those lines; cursor remains on the same line --- smart_list.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/smart_list.py b/smart_list.py index 9273d7b..ec82424 100644 --- a/smart_list.py +++ b/smart_list.py @@ -60,8 +60,15 @@ def run(self, edit): match = NONLIST_PATTERN.match(before_point_content) if match: - insert_text = match.group(1) + match.group(2) - self.view.insert(edit, region.a, "\n" + insert_text) + current_line = self.view.line(region.a) + prev_line = self.view.line(current_line.a - 1) + empty_nonlist = match.group(1) + match.group(2) + if (self.view.substr(prev_line) == empty_nonlist) and (self.view.substr(current_line) == empty_nonlist): + self.view.replace(edit, current_line, '') + self.view.replace(edit, prev_line, '') + else: + insert_text = match.group(1) + match.group(2) + self.view.insert(edit, region.a, "\n" + insert_text) break self.view.insert(edit, region.a, '\n')