Skip to content

Commit 2b6b90a

Browse files
whitespace damage - implement in-buffer TODO keyword definition parsing
1 parent 984df1a commit 2b6b90a

File tree

1 file changed

+65
-40
lines changed

1 file changed

+65
-40
lines changed

ftplugin/orgmode/vimbuffer.py

Lines changed: 65 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,85 @@
11
# -*- coding: utf-8 -*-
22

3-
"""
4-
vimbuffer
5-
~~~~~~~~~~
3+
"""
4+
vimbuffer
5+
~~~~~~~~~~
66
7-
VimBuffer and VimBufferContent are the interface between liborgmode and
8-
vim.
7+
VimBuffer and VimBufferContent are the interface between liborgmode and
8+
vim.
99
10-
VimBuffer extends the liborgmode.document.Document().
11-
Document() is just a general implementation for loading an org file. It
12-
has no interface to an actual file or vim buffer. This is the task of
13-
vimbuffer.VimBuffer(). It is the interfaces to vim. The main tasks for
14-
VimBuffer are to provide read and write access to a real vim buffer.
10+
VimBuffer extends the liborgmode.document.Document().
11+
Document() is just a general implementation for loading an org file. It
12+
has no interface to an actual file or vim buffer. This is the task of
13+
vimbuffer.VimBuffer(). It is the interfaces to vim. The main tasks for
14+
VimBuffer are to provide read and write access to a real vim buffer.
1515
16-
VimBufferContent is a helper class for VimBuffer. Basically, it hides the
17-
details of encoding - everything read from or written to VimBufferContent
18-
is UTF-8.
19-
"""
16+
VimBufferContent is a helper class for VimBuffer. Basically, it hides the
17+
details of encoding - everything read from or written to VimBufferContent
18+
is UTF-8.
19+
"""
2020

2121

22-
try:
23-
from collections import UserList
24-
except:
25-
from UserList import UserList
22+
try:
23+
from collections import UserList
24+
except:
25+
from UserList import UserList
2626

27-
import vim
27+
import vim
28+
import re
2829

29-
from orgmode import settings
30-
from orgmode.exceptions import BufferNotFound, BufferNotInSync
31-
from orgmode.liborgmode.documents import Document, MultiPurposeList, Direction
32-
from orgmode.liborgmode.headings import Heading
30+
from orgmode import settings
31+
from orgmode.exceptions import BufferNotFound, BufferNotInSync
32+
from orgmode.liborgmode.documents import Document, MultiPurposeList, Direction
33+
from orgmode.liborgmode.headings import Heading
3334

34-
from orgmode.py3compat.encode_compatibility import *
35-
from orgmode.py3compat.unicode_compatibility import *
35+
from orgmode.py3compat.encode_compatibility import *
36+
from orgmode.py3compat.unicode_compatibility import *
3637

37-
class VimBuffer(Document):
38-
def __init__(self, bufnr=0):
38+
IN_BUF_TODO_KEYWORDS_REGEX = re.compile("^#\+.*TODO:(.*)$")
39+
class VimBuffer(Document):
40+
def __init__(self, bufnr=0):
3941
u"""
4042
:bufnr: 0: current buffer, every other number refers to another buffer
4143
"""
44+
_buffer = None
45+
_bufnr = 0
46+
47+
if bufnr == 0:
48+
_bufnr = vim.current.buffer.number
49+
_buffer = vim.current.buffer
50+
else:
51+
_bufnr = bufnr
52+
for b in vim.buffers:
53+
if bufnr == b.number:
54+
_buffer = b
55+
break
56+
if not _buffer:
57+
raise BufferNotFound(u'Unable to locate buffer number #%d' % self._bufnr)
58+
59+
def match_in_buffer_keywords(line):
60+
ret = False
61+
62+
m = IN_BUF_TODO_SPEC_REGEX.match(line);
63+
if m:
64+
ret = "[%s]" % m.group(1)
65+
66+
return ret
67+
68+
list_of_todo_keywords = filter(None, map(match_in_buffer_keywords, _buffer))
69+
string_todo_keywords = "[%s]" % ",".join(list_of_todo_keywords)
70+
71+
settings.set(u"org_todo_keywords", string_todo_keywords, SCOPE_BUFFER, True)
72+
73+
# :let g:org_todo_keywords = [['TODO(t)', '|', 'DONE(d)'],
74+
# \ ['REPORT(r)', 'BUG(b)', 'KNOWNCAUSE(k)', '|', 'FIXED(f)'],
75+
# \ ['CANCELED(c)']]
76+
77+
4278
Document.__init__(self)
43-
self._bufnr = vim.current.buffer.number if bufnr == 0 else bufnr
79+
self._bufnr = _bufnr
4480
self._changedtick = -1
4581
self._cached_heading = None
46-
if self._bufnr == vim.current.buffer.number:
47-
self._content = VimBufferContent(vim.current.buffer)
48-
else:
49-
_buffer = None
50-
for b in vim.buffers:
51-
if self._bufnr == b.number:
52-
_buffer = b
53-
break
54-
55-
if not _buffer:
56-
raise BufferNotFound(u'Unable to locate buffer number #%d' % self._bufnr)
57-
self._content = VimBufferContent(_buffer)
82+
self._content = VimBufferContent(_buffer)
5883

5984
self.update_changedtick()
6085
self._orig_changedtick = self._changedtick

0 commit comments

Comments
 (0)