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

Add a feature to change roman table #6

Merged
merged 1 commit into from
Feb 16, 2023
Merged
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
5 changes: 5 additions & 0 deletions autoload/kensaku.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ function! kensaku#query_async(value, success, ...) abort
let l:Failure = a:0 ? a:1 : { e -> s:failure(e) }
return denops#request_async('kensaku', 'query', [a:value], a:success, l:Failure)
endfunction

function! kensaku#set_roman_table(romanTable) abort
call denops#plugin#wait_async('kensaku', {
\ -> denops#notify('kensaku', 'setRomanTable', [a:romanTable]) })
endfunction
6 changes: 5 additions & 1 deletion denops/kensaku/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Denops } from "https://deno.land/x/[email protected]/mod.ts";
import * as unknownutil from "https://deno.land/x/[email protected]/mod.ts";
import { query } from "./migemo.ts";
import { query, setRomanTable } from "./migemo.ts";

export function main(denops: Denops): void {
denops.dispatcher = {
Expand All @@ -13,5 +13,9 @@ export function main(denops: Denops): void {
unknownutil.assertString(value);
return query(denops, value);
},
setRomanTable(romanTable: unknown) {
unknownutil.assertArray<[string, string, number?]>(romanTable);
return setRomanTable(denops, romanTable);
},
uga-rosa marked this conversation as resolved.
Show resolved Hide resolved
};
}
21 changes: 19 additions & 2 deletions denops/kensaku/migemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as fs from "https://deno.land/[email protected]/fs/mod.ts";
import * as unknownutil from "https://deno.land/x/[email protected]/mod.ts";
import * as batch from "https://deno.land/x/[email protected]/batch/mod.ts";
import * as vars from "https://deno.land/x/[email protected]/variable/mod.ts";
import * as jsmigemo from "https://cdn.jsdelivr.net/npm/[email protected].3/dist/jsmigemo.min.mjs";
import * as jsmigemo from "https://cdn.jsdelivr.net/npm/[email protected].4/dist/jsmigemo.min.mjs";

let migemo: jsmigemo.Migemo | undefined;

Expand Down Expand Up @@ -42,9 +42,26 @@ async function readOrFetch(url: string, cache: string): Promise<Uint8Array> {
}
}

export async function query(denops: Denops, value: string): Promise<string> {
async function getMigemo(denops: Denops): Promise<jsmigemo.Migemo> {
if (!migemo) {
migemo = await init(denops);
}
return migemo;
}

export async function query(denops: Denops, value: string): Promise<string> {
const migemo = await getMigemo(denops);
return migemo.query(value);
}

export async function setRomanTable(
denops: Denops,
romanTable: [string, string, number?][],
): Promise<void> {
const migemo = await getMigemo(denops);
const romanEntries = romanTable.map(([a, b, c]) =>
new jsmigemo.RomanEntry(a, b, c || 0)
);
const rp = new jsmigemo.RomajiProcessor1(romanEntries);
migemo.setRomajiProcessor(rp);
}
15 changes: 15 additions & 0 deletions doc/kensaku.jax
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,20 @@ kensaku#query_async({value}, {success}[, {failure}])
\)
<

*kensaku#set_roman_table()*
kensaku#set_roman_table({romanTable})
ローマ字の変換ルールを定義します。azikなどに対応できます。
{romanTable}は、[roman: string, hiragana: string, remain: number?]の配
列です。romanがhiraganaに変換され、remainの数だけromanが残ります。例え
ば、["qq", "っ", 1]は、「qq」を入力すると「っq」に変換されるルールにな
ります。remainは省略可能で、その場合は0になります。
uga-rosa marked this conversation as resolved.
Show resolved Hide resolved
>
call kensaku#set_roman_table([
\ ["qq", "っ", 1],
\ ["kz", "かん", 0],
\ ...
\])
<

=============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl