| 
 | 1 | +import type { Denops } from "https://deno.land/x/[email protected]/mod.ts";  | 
 | 2 | +import { lt } from "https://deno.land/[email protected]/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