Skip to content
This repository has been archived by the owner on May 29, 2021. It is now read-only.

Commit

Permalink
kak-spell-list: just show the buffer that was filled by the `kak-sp…
Browse files Browse the repository at this point in the history
…ell` command

Fix #9
  • Loading branch information
dmerejkowsky committed Apr 16, 2020
1 parent fd0e042 commit 45208f9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
5 changes: 3 additions & 2 deletions kak_spell/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def check(
checker = Checker(lang=lang)
errors = checker.check(path, filetype=filetype)
if kakoune:
kak.set_spell_errors(errors, timestamp=kak_timestamp)
# We need a real list because we'll iterate on it twice
kak.handle_spelling_errors(list(errors), timestamp=kak_timestamp)
return True
else:
ok = True
Expand Down Expand Up @@ -115,7 +116,7 @@ def main(argv: Optional[List[str]] = None) -> None:
if not ok:
sys.exit(1)
elif args.command == "list":
kak.list(args.path, lang=lang, filetype=args.filetype)
kak.show_spelling_buffer()
elif args.command == "replace":
word = args.word
kakoune = args.kakoune
Expand Down
48 changes: 28 additions & 20 deletions kak_spell/kak.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
from typing import Any, List, Tuple, Optional
from path import Path
from typing import Any, List, Tuple
from . import log
from .checker import Checker, Error
from .checker import Error


def set_spell_errors(errors: Any, *, timestamp: int) -> None:
cmd = f"set-option buffer spell_errors {timestamp}"
def handle_spelling_errors(errors: List[Error], *, timestamp: int) -> None:
insert_errors_in_scratch_buffer(errors)
set_spell_errors(errors, timestamp=timestamp)


def show_spelling_buffer() -> None:
print("edit -existing *spelling*")


def insert_errors_in_scratch_buffer(errors: Any) -> None:
# TODO: -fifo ?
print("edit -scratch *spelling*")
cmd = "execute-keys \\% <ret> d i %{"
for error in errors:
line, col, length = error_to_range(error)
cmd += f"{line}.{col},{line}.{col+length-1} {error.word}<ret>"
cmd += "}"
cmd += "<esc> gg"
cmd += "\n" "hook buffer -group kak-spell NormalKey <ret> kak-spell-jump"
cmd += "\n" "execute-keys <esc> ga"
log(cmd)
print(cmd)


def set_spell_errors(errors: List[Error], *, timestamp: int) -> None:
n = 0
cmd = f"set-option buffer spell_errors {timestamp}"
for error in errors:
(line, col, length) = error_to_range(error)
cmd += f" {line}.{col}+{length}|Error"
Expand Down Expand Up @@ -39,21 +62,6 @@ def menu_from_replacements(replacements: List[str]) -> None:
print(cmd)


def list(path: Path, *, lang: str, filetype: Optional[str] = None,) -> None:
checker = Checker(lang=lang)
errors = checker.check(path, filetype=filetype)
print("edit -scratch *spelling*")
cmd = "execute-keys \\% <ret> d i %{"
for error in errors:
line, col, length = error_to_range(error)
cmd += f"{line}.{col},{line}.{col+length-1} {error.word}<ret>"
cmd += "}"
cmd += "<esc> gg"
cmd += "\nhook buffer -group kak-spell NormalKey <ret> kak-spell-jump"
log(cmd)
print(cmd)


def show_no_errors() -> None:
print("echo -markup {green} no spelling errors")

Expand Down

0 comments on commit 45208f9

Please sign in to comment.