-
Notifications
You must be signed in to change notification settings - Fork 15
/
orglist.py
105 lines (96 loc) · 3.21 KB
/
orglist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import sublime
import sublime_plugin
import datetime
import re
from pathlib import Path
import os
import fnmatch
import OrgExtended.orgparse.loader as loader
import OrgExtended.orgparse.node as node
import OrgExtended.orgparse.date as orgdate
from OrgExtended.orgparse.sublimenode import *
import OrgExtended.orgutil.util as util
import OrgExtended.orgutil.navigation as nav
import OrgExtended.orgutil.template as templateEngine
import logging
import sys
import traceback
import OrgExtended.orgfolding as folding
import OrgExtended.orgdb as db
import OrgExtended.asettings as sets
import OrgExtended.pymitter as evt
import OrgExtended.orgproperties as props
import OrgExtended.orgdatepicker as datep
import OrgExtended.orginsertselected as insSel
import OrgExtended.orglinks as orglink
import OrgExtended.orgneovi as nvi
import OrgExtended.orgagenda as oa
import OrgExtended.orgcheckbox as checkbox
import OrgExtended.orgnumberedlist as numberedlist
log = logging.getLogger(__name__)
RE_LIST_REPLACE = re.compile(r'\s*(([0-9]+[.)])|[-+])\s+')
def isListLine(l):
return RE_LIST_REPLACE.search(l)
class ListData:
def __init__(self,view=None,pt=None):
if(view != None):
reg = view.line(pt)
line = view.substr(reg)
if(numberedlist.isNumberedLine(view,reg)):
wasNumbered = True
self.data = numberedlist.getListAtPoint(view,pt)
elif(checkbox.isUnorderedList(line)):
self.data = checkbox.getListAtPoint(view,pt)
else:
self.data = None
else:
self.data = []
@staticmethod
def CreateListFromList(lst):
ls = ListData()
for l in lst:
l = RE_LIST_REPLACE.sub("",l)
ls.data.append([None,l])
return ls
def __iter__(self):
return self.Iterate()
def Iterate(self):
for row in self.data:
yield row[1]
return None
RE_ISCOMMENT = re.compile(r"^\s*[#][+]")
def LookupNamedListInFile(name):
l = None
view = sublime.active_window().active_view()
if(view):
node = db.Get().AtInView(view)
if(node):
# Look for named objects in the file.
names = node.names
if(names and name in names):
row = names[name]['row']
last_row = view.lastRow()
for r in range(row,last_row):
pt = view.text_point(r, 0)
line = view.substr(view.line(pt))
m = RE_ISCOMMENT.search(line)
if(m):
continue
elif(line.strip() == ""):
continue
else:
row = r
break
pt = view.text_point(row,0)
reg = view.line(pt)
line = view.substr(reg)
if(numberedlist.isNumberedLine(view,reg) or checkbox.isUnorderedList(line)):
l = ListData(view,pt)
return l
def IfListExtract(view,pt):
l = None
reg = view.line(pt)
line = view.substr(reg)
if(numberedlist.isNumberedLine(view,reg) or checkbox.isUnorderedList(line)):
l = ListData(view,pt)
return l