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

Refresh syntax on saving #97

Closed
wants to merge 1 commit into from
Closed
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
30 changes: 16 additions & 14 deletions babi/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,21 @@ def __init__(
self.selection = Selection()
self._file_hls: Tuple[FileHL, ...] = ()

def refresh_syntax(self) -> None:
file_hls = []
for factory in self._hl_factories:
if self.filename is not None:
hl = factory.file_highlighter(self.filename, self.buf[0])
file_hls.append(hl)
else:
file_hls.append(factory.blank_file_highlighter())
self._file_hls = (
*file_hls,
self._trailing_whitespace, self._replace_hl, self.selection,
)
for file_hl in self._file_hls:
file_hl.register_callbacks(self.buf)

def ensure_loaded(
self,
status: Status,
Expand Down Expand Up @@ -253,20 +268,7 @@ def ensure_loaded(
status.update(f'mixed newlines will be converted to {self.nl!r}')
self.modified = True

file_hls = []
for factory in self._hl_factories:
if self.filename is not None:
hl = factory.file_highlighter(self.filename, self.buf[0])
file_hls.append(hl)
else:
file_hls.append(factory.blank_file_highlighter())
self._file_hls = (
*file_hls,
self._trailing_whitespace, self._replace_hl, self.selection,
)
for file_hl in self._file_hls:
file_hl.register_callbacks(self.buf)

self.refresh_syntax()
self.go_to_line(self.initial_line, margin)

def __repr__(self) -> str:
Expand Down
2 changes: 2 additions & 0 deletions babi/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ def save(self) -> Optional[PromptResult]:
action.end_modified = not first
action.start_modified = True
first = False

self.file.refresh_syntax()
return None

def save_filename(self) -> Optional[PromptResult]:
Expand Down