Skip to content

Commit d66a7b5

Browse files
liskintbabej
authored andcommitted
cache: Mark buffer as modified on push
When a (task)wiki file is opened, viewports are refreshed but the buffer is not marked as modified and therefore a subsequent :xa doesn't update the file. This is, IMO, undesired. vim documentation for the 'modified' option: This option is not set when a change is made to the buffer as the result of a BufNewFile, BufRead/BufReadPost, BufWritePost, FileAppendPost or VimLeave autocommand event. See |gzip-example| for an explanation.
1 parent 1e3ccb1 commit d66a7b5

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

taskwiki/cache.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ def obtain(self):
2222

2323
def push(self):
2424
with util.current_line_preserved():
25+
buffer = util.get_buffer(self.buffer_number)
2526
# Only set the buffer contents if the data is changed.
2627
# Avoids extra undo events with empty diff.
27-
if util.get_buffer(self.buffer_number)[:] != self.data:
28-
util.get_buffer(self.buffer_number)[:] = self.data
28+
if buffer[:] != self.data:
29+
buffer[:] = self.data
30+
buffer.options['modified'] = True
2931

3032
def __getitem__(self, index):
3133
try:

tests/test_viewport.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
import os
23
from datetime import datetime
34
from tests.base import MultiSyntaxIntegrationTest
45

@@ -614,3 +615,31 @@ def execute(self):
614615
assert task['description'] == 'hard task'
615616
assert task['status'] == 'pending'
616617
assert task['tags'] == set(['work', 'hard'])
618+
619+
620+
class TestViewportBufferModified(MultiSyntaxIntegrationTest):
621+
622+
viminput = """
623+
HEADER2(Work tasks |)
624+
* [ ] a task #{uuid}
625+
"""
626+
627+
tasks = [
628+
dict(description="a task", tags=['work']),
629+
]
630+
631+
def execute(self):
632+
testfile2 = os.path.join(self.dir, "testwiki2.txt")
633+
testfile3 = os.path.join(self.dir, "testwiki3.txt")
634+
635+
self.command("w", regex="written$", lines=1)
636+
self.command("w {}".format(testfile2), regex="written$", lines=1)
637+
self.command("1w {}".format(testfile3), regex="written$", lines=1)
638+
639+
# testfile2 has the task, so refresh on open shouldn't change anything
640+
self.client.edit(testfile2)
641+
assert self.client.eval('&modified') == '0'
642+
643+
# testfile3 only has header, so refresh on open makes changes
644+
self.client.edit(testfile3)
645+
assert self.client.eval('&modified') == '1'

0 commit comments

Comments
 (0)