Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom UUID char #437

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions after/syntax/vimwiki.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ endif
" Detect if conceal feature is available
let s:conceal = exists("+conceallevel") ? ' conceal': ''

let s:uuid_char = '#'
if exists("g:taskwiki_uuid_char")
let s:uuid_char = g:taskwiki_uuid_char
endif

syntax match TaskWikiTask /\s*\* \[.\]\s.*$/ contains=@TaskWikiTaskContains
syntax cluster TaskWikiTaskContains
\ contains=VimwikiListTodo,
Expand All @@ -29,8 +34,8 @@ syntax cluster TaskWikiTaskContains
\ @Spell

" Conceal the UUID
execute 'syn match TaskWikiTaskUuid containedin=TaskWikiTask /\v#([A-Z]:)?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/'.s:conceal
execute 'syn match TaskWikiTaskUuid containedin=TaskWikiTask /\v#([A-Z]:)?[0-9a-fA-F]{8}$/'.s:conceal
execute 'syn match TaskWikiTaskUuid containedin=TaskWikiTask /\V'.s:uuid_char.'\v([A-Z]:)?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/'.s:conceal
execute 'syn match TaskWikiTaskUuid containedin=TaskWikiTask /\V'.s:uuid_char.'\v([A-Z]:)?[0-9a-fA-F]{8}$/'.s:conceal
highlight link TaskWikiTaskUuid Comment

" Conceal header definitions
Expand All @@ -40,11 +45,11 @@ endfor

" Define active and deleted task regions
" Will be colored dynamically by Meta().source_tw_colors()
syntax match TaskWikiTaskActive containedin=TaskWikiTask contained contains=@TaskWikiTaskContains /\s*\*\s\[S\]\s[^#]*/
syntax match TaskWikiTaskCompleted containedin=TaskWikiTask contained contains=@TaskWikiTaskContains /\s*\*\s\[X\]\s[^#]*/
syntax match TaskWikiTaskDeleted containedin=TaskWikiTask contained contains=@TaskWikiTaskContains /\s*\*\s*\[D\]\s[^#]*/
syntax match TaskWikiTaskRecurring containedin=TaskWikiTask contained contains=@TaskWikiTaskContains /\s*\*\s\[R\]\s[^#]*/
syntax match TaskWikiTaskWaiting containedin=TaskWikiTask contained contains=@TaskWikiTaskContains /\s*\*\s\[W\]\s[^#]*/
execute 'syntax match TaskWikiTaskActive containedin=TaskWikiTask contained contains=@TaskWikiTaskContains /\s*\*\s\[S\]\s[^'.s:uuid_char.']*/'
execute 'syntax match TaskWikiTaskCompleted containedin=TaskWikiTask contained contains=@TaskWikiTaskContains /\s*\*\s\[X\]\s[^'.s:uuid_char.']*/'
execute 'syntax match TaskWikiTaskDeleted containedin=TaskWikiTask contained contains=@TaskWikiTaskContains /\s*\*\s*\[D\]\s[^'.s:uuid_char.']*/'
execute 'syntax match TaskWikiTaskRecurring containedin=TaskWikiTask contained contains=@TaskWikiTaskContains /\s*\*\s\[R\]\s[^'.s:uuid_char.']*/'
execute 'syntax match TaskWikiTaskWaiting containedin=TaskWikiTask contained contains=@TaskWikiTaskContains /\s*\*\s\[W\]\s[^'.s:uuid_char.']*/'
syntax match TaskWikiTaskPriority contained /\( \)\@<=\(!\|!!\|!!!\)\( \)\@=/
syntax cluster TaskWikiTaskContains add=TaskWikiTaskPriority

Expand Down
4 changes: 3 additions & 1 deletion taskwiki/regexp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import re

from taskwiki.util import uuid_char

# Unnamed building blocks
UUID_UNNAMED = r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}'
UUID_UNNAMED_SHORT = r'[0-9a-fA-F]{8}'
Expand Down Expand Up @@ -30,7 +32,7 @@
'(', PRIORITY, FINAL_SEGMENT_SEPARATOR_UNNAMED, ')?',
'(', DUE, FINAL_SEGMENT_SEPARATOR_UNNAMED, ')?',
'(',
'#',
re.escape(uuid_char),
'(', SOURCE_INDICATOR, ')?',
'(', UUID, ')?',
')?', # UUID is not there for new tasks
Expand Down
2 changes: 2 additions & 0 deletions taskwiki/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from taskwiki.errors import TaskWikiException
from taskwiki import regexp

uuid_char = vim.eval("g:taskwiki_uuid_char") if vim.eval("exists('g:taskwiki_uuid_char')") == '1' else '#'

# Detect if command AnsiEsc is available
ANSI_ESC_AVAILABLE = vim.eval('exists(":AnsiEsc")') == '2'
NEOVIM = (vim.eval('has("nvim")') == "1")
Expand Down
3 changes: 2 additions & 1 deletion taskwiki/vwtask.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from taskwiki import regexp
from taskwiki import util
from taskwiki.util import uuid_char
from taskwiki.short import ShortUUID


Expand Down Expand Up @@ -337,7 +338,7 @@ def __str__(self):
if self['description'] else 'TEXT MISSING?',
' ' + '!' * self.priority_from_tw_format if self['priority'] else '',
due_str,
' #' + self.uuid.vim_representation(self.cache) if self.uuid else '',
' ' + uuid_char + self.uuid.vim_representation(self.cache) if self.uuid else '',
])

def find_parent_task(self):
Expand Down
65 changes: 33 additions & 32 deletions tests/test_choose.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# -*- coding: utf-8 -*-
from taskwiki.util import uuid_char
from tests.base import IntegrationTest


class TestChooseProject(IntegrationTest):

viminput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

vimoutput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

tasks = [
Expand All @@ -36,13 +37,13 @@ def execute(self):
class TestChooseProjectUnset(IntegrationTest):

viminput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

vimoutput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

tasks = [
Expand All @@ -67,13 +68,13 @@ def execute(self):
class TestChooseProjectCanceled(IntegrationTest):

viminput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

vimoutput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

tasks = [
Expand All @@ -98,13 +99,13 @@ def execute(self):
class TestChooseTag(IntegrationTest):

viminput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

vimoutput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

tasks = [
Expand All @@ -129,13 +130,13 @@ def execute(self):
class TestChooseTagCancelled(IntegrationTest):

viminput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

vimoutput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

tasks = [
Expand All @@ -160,13 +161,13 @@ def execute(self):
class TestChooseTagNoSelected(IntegrationTest):

viminput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

vimoutput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

tasks = [
Expand All @@ -191,13 +192,13 @@ def execute(self):
class TestChooseProjectUnicode(IntegrationTest):

viminput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

vimoutput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

tasks = [
Expand All @@ -222,13 +223,13 @@ def execute(self):
class TestChooseTagUnicode(IntegrationTest):

viminput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

vimoutput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

tasks = [
Expand Down
11 changes: 6 additions & 5 deletions tests/test_completion.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from taskwiki.completion import Completion
from taskwiki.util import uuid_char
from tests.base import IntegrationTest


Expand Down Expand Up @@ -57,8 +58,8 @@ def test_omni(self):
c = Completion(FakeTW())
assert c.omni_modstring_findstart("* [ ] x") == -1
assert c.omni_modstring_findstart("* [ ] x --") == -1
assert c.omni_modstring_findstart("* [ ] x #12345678 --") == -1
assert c.omni_modstring_findstart("* [ ] x -- #12345678") == -1
assert c.omni_modstring_findstart("* [ ] x "+uuid_char+"12345678 --") == -1
assert c.omni_modstring_findstart("* [ ] x -- "+uuid_char+"12345678") == -1
assert c.omni_modstring_findstart("* [ ] x -- ") == 11
assert c.omni_modstring_findstart("* [ ] x -- x") == 11
assert c.omni_modstring_findstart("* [ ] x -- xy") == 11
Expand All @@ -67,8 +68,8 @@ def test_omni(self):

class TestCompletionIntegMod(IntegrationTest):
viminput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

tasks = [
Expand All @@ -89,7 +90,7 @@ def execute(self):

class TestCompletionIntegOmni(IntegrationTest):
viminput = """
* [ ] test task 1 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
"""

tasks = [
Expand Down
41 changes: 21 additions & 20 deletions tests/test_mappings.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# -*- coding: utf-8 -*-
from taskwiki.util import uuid_char
from tests.base import IntegrationTest


class TestDefaultMapping(IntegrationTest):

viminput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

vimoutput = """
* [X] test task 1 #{uuid}
* [X] test task 2 #{uuid}
* [X] test task 1 """+uuid_char+"""{uuid}
* [X] test task 2 """+uuid_char+"""{uuid}
"""

tasks = [
Expand All @@ -34,13 +35,13 @@ def execute(self):
class TestSuppressedMapping(IntegrationTest):

viminput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

vimoutput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

tasks = [
Expand All @@ -67,13 +68,13 @@ def execute(self):
class TestCustomMapping(IntegrationTest):

viminput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

vimoutput = """
* [X] test task 1 #{uuid}
* [X] test task 2 #{uuid}
* [X] test task 1 """+uuid_char+"""{uuid}
* [X] test task 2 """+uuid_char+"""{uuid}
"""

tasks = [
Expand All @@ -100,13 +101,13 @@ def execute(self):
class TestColonRemap(IntegrationTest):

viminput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

vimoutput = """
* [X] test task 1 #{uuid}
* [X] test task 2 #{uuid}
* [X] test task 1 """+uuid_char+"""{uuid}
* [X] test task 2 """+uuid_char+"""{uuid}
"""

tasks = [
Expand Down Expand Up @@ -134,13 +135,13 @@ def execute(self):
class TestColonRemapWithCustomMap(IntegrationTest):

viminput = """
* [ ] test task 1 #{uuid}
* [ ] test task 2 #{uuid}
* [ ] test task 1 """+uuid_char+"""{uuid}
* [ ] test task 2 """+uuid_char+"""{uuid}
"""

vimoutput = """
* [X] test task 1 #{uuid}
* [X] test task 2 #{uuid}
* [X] test task 1 """+uuid_char+"""{uuid}
* [X] test task 2 """+uuid_char+"""{uuid}
"""

tasks = [
Expand Down
Loading