|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 |
|
3 |
| -""" |
4 |
| - vimbuffer |
5 |
| - ~~~~~~~~~~ |
| 3 | + """ |
| 4 | + vimbuffer |
| 5 | + ~~~~~~~~~~ |
6 | 6 |
|
7 |
| - VimBuffer and VimBufferContent are the interface between liborgmode and |
8 |
| - vim. |
| 7 | + VimBuffer and VimBufferContent are the interface between liborgmode and |
| 8 | + vim. |
9 | 9 |
|
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. |
15 | 15 |
|
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 | + """ |
20 | 20 |
|
21 | 21 |
|
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 |
26 | 26 |
|
27 |
| -import vim |
| 27 | + import vim |
| 28 | + import re |
28 | 29 |
|
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 |
33 | 34 |
|
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 * |
36 | 37 |
|
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): |
39 | 41 | u"""
|
40 | 42 | :bufnr: 0: current buffer, every other number refers to another buffer
|
41 | 43 | """
|
| 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 | + |
42 | 78 | Document.__init__(self)
|
43 |
| - self._bufnr = vim.current.buffer.number if bufnr == 0 else bufnr |
| 79 | + self._bufnr = _bufnr |
44 | 80 | self._changedtick = -1
|
45 | 81 | 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) |
58 | 83 |
|
59 | 84 | self.update_changedtick()
|
60 | 85 | self._orig_changedtick = self._changedtick
|
|
0 commit comments