Skip to content

Commit

Permalink
whitespace damage - implement in-buffer TODO keyword definition parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMickler committed Oct 21, 2019
1 parent 984df1a commit 2b6b90a
Showing 1 changed file with 65 additions and 40 deletions.
105 changes: 65 additions & 40 deletions ftplugin/orgmode/vimbuffer.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,85 @@
# -*- coding: utf-8 -*-

"""
vimbuffer
~~~~~~~~~~
"""
vimbuffer
~~~~~~~~~~
VimBuffer and VimBufferContent are the interface between liborgmode and
vim.
VimBuffer and VimBufferContent are the interface between liborgmode and
vim.
VimBuffer extends the liborgmode.document.Document().
Document() is just a general implementation for loading an org file. It
has no interface to an actual file or vim buffer. This is the task of
vimbuffer.VimBuffer(). It is the interfaces to vim. The main tasks for
VimBuffer are to provide read and write access to a real vim buffer.
VimBuffer extends the liborgmode.document.Document().
Document() is just a general implementation for loading an org file. It
has no interface to an actual file or vim buffer. This is the task of
vimbuffer.VimBuffer(). It is the interfaces to vim. The main tasks for
VimBuffer are to provide read and write access to a real vim buffer.
VimBufferContent is a helper class for VimBuffer. Basically, it hides the
details of encoding - everything read from or written to VimBufferContent
is UTF-8.
"""
VimBufferContent is a helper class for VimBuffer. Basically, it hides the
details of encoding - everything read from or written to VimBufferContent
is UTF-8.
"""


try:
from collections import UserList
except:
from UserList import UserList
try:
from collections import UserList
except:
from UserList import UserList

import vim
import vim
import re

from orgmode import settings
from orgmode.exceptions import BufferNotFound, BufferNotInSync
from orgmode.liborgmode.documents import Document, MultiPurposeList, Direction
from orgmode.liborgmode.headings import Heading
from orgmode import settings
from orgmode.exceptions import BufferNotFound, BufferNotInSync
from orgmode.liborgmode.documents import Document, MultiPurposeList, Direction
from orgmode.liborgmode.headings import Heading

from orgmode.py3compat.encode_compatibility import *
from orgmode.py3compat.unicode_compatibility import *
from orgmode.py3compat.encode_compatibility import *
from orgmode.py3compat.unicode_compatibility import *

class VimBuffer(Document):
def __init__(self, bufnr=0):
IN_BUF_TODO_KEYWORDS_REGEX = re.compile("^#\+.*TODO:(.*)$")
class VimBuffer(Document):
def __init__(self, bufnr=0):
u"""
:bufnr: 0: current buffer, every other number refers to another buffer
"""
_buffer = None
_bufnr = 0

if bufnr == 0:
_bufnr = vim.current.buffer.number
_buffer = vim.current.buffer
else:
_bufnr = bufnr
for b in vim.buffers:
if bufnr == b.number:
_buffer = b
break
if not _buffer:
raise BufferNotFound(u'Unable to locate buffer number #%d' % self._bufnr)

def match_in_buffer_keywords(line):
ret = False

m = IN_BUF_TODO_SPEC_REGEX.match(line);
if m:
ret = "[%s]" % m.group(1)

return ret

list_of_todo_keywords = filter(None, map(match_in_buffer_keywords, _buffer))
string_todo_keywords = "[%s]" % ",".join(list_of_todo_keywords)

settings.set(u"org_todo_keywords", string_todo_keywords, SCOPE_BUFFER, True)

# :let g:org_todo_keywords = [['TODO(t)', '|', 'DONE(d)'],
# \ ['REPORT(r)', 'BUG(b)', 'KNOWNCAUSE(k)', '|', 'FIXED(f)'],
# \ ['CANCELED(c)']]


Document.__init__(self)
self._bufnr = vim.current.buffer.number if bufnr == 0 else bufnr
self._bufnr = _bufnr
self._changedtick = -1
self._cached_heading = None
if self._bufnr == vim.current.buffer.number:
self._content = VimBufferContent(vim.current.buffer)
else:
_buffer = None
for b in vim.buffers:
if self._bufnr == b.number:
_buffer = b
break

if not _buffer:
raise BufferNotFound(u'Unable to locate buffer number #%d' % self._bufnr)
self._content = VimBufferContent(_buffer)
self._content = VimBufferContent(_buffer)

self.update_changedtick()
self._orig_changedtick = self._changedtick
Expand Down

0 comments on commit 2b6b90a

Please sign in to comment.