Permalink
Browse files

Initial ST3 support:

* Fixed import statements;
* view.find now returns `(-1, -1)` instead of `Null` on nothing found, adjusted (prevents infinite loops mostly);
  • Loading branch information...
UNOwen committed Feb 16, 2013
1 parent 9a8f01f commit 4f4ed0e3d4c9b23e307057b7323b014aa462f538
Showing with 28 additions and 20 deletions.
  1. +6 −7 headline.py
  2. +3 −2 headline_move.py
  3. +2 −2 pandoc_render.py
  4. +8 −7 smart_folding.py
  5. +1 −1 smart_table.py
  6. +1 −1 table.py
  7. +7 −0 utilities.py
View
@@ -8,9 +8,8 @@
# Author: Muchenxuan Tong <demon386@gmail.com>
import re
-
import sublime
-
+from .utilities import is_region_void
MATCH_PARENT = 1 # Match headlines at the same or higher level
MATCH_CHILD = 2 # Match headlines at the same or lower level
@@ -36,7 +35,7 @@ def region_of_content_of_headline_at_point(view, from_point):
level, \
True, \
MATCH_PARENT)
- if next_headline != None:
+ if not is_region_void(next_headline):
end_pos = next_headline.a - 1
else:
end_pos = view.size()
@@ -62,7 +61,7 @@ def headline_and_level_at_point(view, from_point, search_above_and_down=False):
ANY_LEVEL,
False,
skip_folded=True)
- if headline_region:
+ if not is_region_void(headline_region):
line_content, level = headline_and_level_at_point(view,\
headline_region.a)
# Search down
@@ -72,7 +71,7 @@ def headline_and_level_at_point(view, from_point, search_above_and_down=False):
ANY_LEVEL,
True,
skip_folded=True)
- if headline_region:
+ if not is_region_void(headline_region):
line_content, level = headline_and_level_at_point(view, headline_region.a)
return line_content, level
@@ -168,11 +167,11 @@ def find_headline(view, from_point, level, forward=True, \
skip_folded)
if skip_folded:
- while (match_region and _is_region_folded(match_region, view)):
+ while (_is_region_folded(match_region, view)):
from_point = match_region.b
match_region = view.find(re_string, from_point)
- if match_region:
+ if not is_region_void(match_region):
if not is_scope_headline(view, match_region.a):
return find_headline(view, match_region.a, level, forward, \
match_type, True, skip_folded)
View
@@ -8,7 +8,8 @@
import sublime
import sublime_plugin
-import headline
+from . import headline
+from .utilities import is_region_void
class HeadlineMoveCommand(sublime_plugin.TextCommand):
@@ -43,7 +44,7 @@ def run(self, edit, forward=True, same_level=True):
skip_headline_at_point=True,\
skip_folded=True)
- if not match_region:
+ if is_region_void(match_region):
return
new_sel.append(sublime.Region(match_region.a, match_region.a))
View
@@ -93,7 +93,7 @@ def run_pandoc(self, infile, outfile, args):
if err:
raise Exception("Command: %s\n" % " ".join(cmd) + "\nErrors: " + err)
except Exception as e:
- sublime.error_message("Fail to generate output.\n\b{0}".format(e))
+ sublime.error_message("Fail to generate output.\n{0}".format(e))
def pandoc_args(self, target):
"""
@@ -119,6 +119,6 @@ def open_result(self, outfile, target):
os.startfile(outfile)
elif "mac" in sys.platform or "darwin" in sys.platform:
os.system("open %s" % outfile)
- print outfile
+ print(outfile)
elif "posix" in sys.platform or "linux" in sys.platform:
os.system("xdg-open %s" % outfile)
View
@@ -13,7 +13,8 @@
import sublime
import sublime_plugin
-import headline
+from . import headline
+from .utilities import is_region_void
HEADLINE_PATTERN = re.compile(r'^(#+)\s.*')
@@ -81,7 +82,7 @@ def unfold_yet_fold_subheads(self, region, level):
child_headline_region, _ = headline.find_headline(self.view, region.a, level, True, \
headline.MATCH_CHILD)
- while (child_headline_region is not None and child_headline_region.b <= region.b):
+ while (not is_region_void(child_headline_region) and child_headline_region.b <= region.b):
child_content_region = headline.region_of_content_of_headline_at_point(self.view,
child_headline_region.a)
if child_content_region is not None:
@@ -117,15 +118,15 @@ def is_global_folded(self):
headline.ANY_LEVEL, True)
# Treating no heeadline as folded, since unfolded all makes
# no harm in this situation.
- if not region:
+ if is_region_void(region):
return True
point = region.a
# point can be zero
while (point is not None and region):
region = headline.region_of_content_of_headline_at_point(self.view, \
point)
- if region:
+ if not is_region_void(region):
point = region.b
if not self.is_region_totally_folded(region):
return False
@@ -134,7 +135,7 @@ def is_global_folded(self):
headline.ANY_LEVEL, \
True,
skip_headline_at_point=True)
- if region:
+ if not is_region_void(region):
point = region.a
return True
@@ -155,14 +156,14 @@ def fold_all(self):
while (point is not None and region):
region = headline.region_of_content_of_headline_at_point(self.view, \
point)
- if region:
+ if not is_region_void(region):
point = region.b
self.view.fold(region)
region, level = headline.find_headline(self.view, point, \
headline.ANY_LEVEL,
True, \
skip_headline_at_point=True)
- if region:
+ if not is_region_void(region):
point = region.a
self.adjust_cursors_and_view()
View
@@ -10,7 +10,7 @@
import sublime
import sublime_plugin
-import table
+from . import table
class SmartTable(sublime_plugin.TextCommand):
View
@@ -14,7 +14,7 @@
import sublime
-import utilities
+from . import utilities
TABLE_PATTERN = re.compile(r"\s*\|")
SEPARATOR_PATTERN = re.compile(r"\s*(\+[=-])")
View
@@ -14,3 +14,10 @@ def text_at_line(view, line_num):
point = view.text_point(line_num, 0)
line_region = view.line(point)
return view.substr(line_region)
+
+def is_region_void(region):
+ if region == None:
+ return True
+ if region.a == -1 and region.b == -1:
+ return True
+ return False

0 comments on commit 4f4ed0e

Please sign in to comment.