Skip to content

Commit 0a9ad26

Browse files
lambdalisueMilly
andauthored
👍 Add a workaround for getreginfo in Vim (#158)
* 👍 Add a workaround for `getreginfo` in Vim Close #155 * Update denops_std/function/getreginfo.ts Co-authored-by: Milly <milly.ca@gmail.com> Co-authored-by: Milly <milly.ca@gmail.com>
1 parent a242f5a commit 0a9ad26

File tree

3 files changed

+76
-34
lines changed

3 files changed

+76
-34
lines changed

denops_std/function/_generated.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,40 +2834,6 @@ export function getreg(denops: Denops, ...args: unknown[]): Promise<unknown> {
28342834
return denops.call("getreg", ...args);
28352835
}
28362836

2837-
/**
2838-
* Returns detailed information about register {regname} as a
2839-
* Dictionary with the following entries:
2840-
* regcontents List of lines contained in register
2841-
* {regname}, like
2842-
* |getreg|({regname}, 1, 1).
2843-
* regtype the type of register {regname}, as in
2844-
* |getregtype()|.
2845-
* isunnamed Boolean flag, v:true if this register
2846-
* is currently pointed to by the unnamed
2847-
* register.
2848-
* points_to for the unnamed register, gives the
2849-
* single letter name of the register
2850-
* currently pointed to (see |quotequote|).
2851-
* For example, after deleting a line
2852-
* with `dd`, this field will be "1",
2853-
* which is the register that got the
2854-
* deleted text.
2855-
* The {regname} argument is a string. If {regname} is invalid
2856-
* or not set, an empty Dictionary will be returned.
2857-
* If {regname} is not specified, |v:register| is used.
2858-
* The returned Dictionary can be passed to |setreg()|.
2859-
* In |Vim9-script| {regname} must be one character.
2860-
* Can also be used as a |method|:
2861-
* GetRegname()->getreginfo()
2862-
*/
2863-
export function getreginfo(denops: Denops, regname?: unknown): Promise<unknown>;
2864-
export function getreginfo(
2865-
denops: Denops,
2866-
...args: unknown[]
2867-
): Promise<unknown> {
2868-
return denops.call("getreginfo", ...args);
2869-
}
2870-
28712837
/**
28722838
* The result is a String, which is type of register {regname}.
28732839
* The value will be one of:

denops_std/function/_manual.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from "./buffer.ts";
22
export * from "./common.ts";
33
export * from "./cursor.ts";
4+
export * from "./getreginfo.ts";
45
export * from "./input.ts";
56
export * from "./types.ts";
67
export * from "./various.ts";

denops_std/function/getreginfo.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import type { Denops } from "https://deno.land/x/denops_core@v3.2.2/mod.ts";
2+
import { lt } from "https://deno.land/std@0.166.0/semver/mod.ts";
3+
import { execute } from "../helper/mod.ts";
4+
import { generateUniqueString } from "../util.ts";
5+
6+
const cacheKey = Symbol("denops_std/function/getreginfo.ts");
7+
const suffix = generateUniqueString();
8+
9+
async function ensurePrerequisites(denops: Denops): Promise<string> {
10+
if (cacheKey in denops.context) {
11+
return suffix;
12+
}
13+
denops.context[cacheKey] = true;
14+
const script = `
15+
function! DenopsStdFunctionGetreginfo_${suffix}(...) abort
16+
let l:result = call('getreginfo', a:000)
17+
if !has_key(l:result, 'isunnamed')
18+
return l:result
19+
endif
20+
return extend(l:result, {'isunnamed': l:result.isunnamed ? v:true : v:false})
21+
endfunction
22+
`;
23+
await execute(denops, script);
24+
return suffix;
25+
}
26+
27+
export type GetreginfoResult = {
28+
regcontents: string[];
29+
regtype: string;
30+
isunnamed?: boolean;
31+
points_to?: string;
32+
} | Record<string, never>;
33+
34+
/**
35+
* Returns detailed information about register {regname} as a
36+
* Dictionary with the following entries:
37+
* regcontents List of lines contained in register
38+
* {regname}, like
39+
* |getreg|({regname}, 1, 1).
40+
* regtype the type of register {regname}, as in
41+
* |getregtype()|.
42+
* isunnamed Boolean flag, v:true if this register
43+
* is currently pointed to by the unnamed
44+
* register.
45+
* points_to for the unnamed register, gives the
46+
* single letter name of the register
47+
* currently pointed to (see |quotequote|).
48+
* For example, after deleting a line
49+
* with `dd`, this field will be "1",
50+
* which is the register that got the
51+
* deleted text.
52+
* The {regname} argument is a string. If {regname} is invalid
53+
* or not set, an empty Dictionary will be returned.
54+
* If {regname} is not specified, |v:register| is used.
55+
* The returned Dictionary can be passed to |setreg()|.
56+
* In |Vim9-script| {regname} must be one character.
57+
* Can also be used as a |method|:
58+
* GetRegname()->getreginfo()
59+
*/
60+
export function getreginfo(
61+
denops: Denops,
62+
regname?: string,
63+
): Promise<GetreginfoResult>;
64+
export async function getreginfo(
65+
denops: Denops,
66+
...args: unknown[]
67+
): Promise<unknown> {
68+
if (denops.meta.host === "vim" && lt(denops.meta.version, "9.0.936")) {
69+
// Vim prior to 9.0.0936 need a workaround
70+
// https://github.com/vim/vim/issues/11598
71+
const suffix = await ensurePrerequisites(denops);
72+
return denops.call(`DenopsStdFunctionGetreginfo_${suffix}`, ...args);
73+
}
74+
return denops.call("getreginfo", ...args);
75+
}

0 commit comments

Comments
 (0)