Skip to content

Commit 7e8a304

Browse files
committed
👍 Add getbufvar() to buffer-function
1 parent 08016ef commit 7e8a304

File tree

2 files changed

+45
-39
lines changed

2 files changed

+45
-39
lines changed

denops_std/function/_generated.ts

Lines changed: 0 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

denops_std/function/buffer.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,51 @@ export async function getbufline(
433433
return await denops.call("getbufline", buf, lnum, end) as string[];
434434
}
435435

436+
/**
437+
* The result is the value of option or local buffer variable
438+
* **{varname}** in buffer **{buf}**. Note that the name without "b:"
439+
* must be used.
440+
* The **{varname}** argument is a string.
441+
* When **{varname}** is empty returns a `Dictionary` with all the
442+
* buffer-local variables.
443+
* When **{varname}** is equal to "&" returns a `Dictionary` with all
444+
* the buffer-local options.
445+
* Otherwise, when **{varname}** starts with "&" returns the value of
446+
* a buffer-local option.
447+
* This also works for a global or buffer-local option, but it
448+
* doesn't work for a global variable, window-local variable or
449+
* window-local option.
450+
* For the use of **{buf}**, see `bufname()` above.
451+
* When the buffer or variable doesn't exist **{def}** or an empty
452+
* string is returned, there is no error message.
453+
* Examples:
454+
*
455+
* :let bufmodified = getbufvar(1, "&mod")
456+
* :echo "todo myvar = " .. getbufvar("todo", "myvar")
457+
*
458+
* Can also be used as a `method`:
459+
*
460+
* GetBufnr()->getbufvar(varname)
461+
*/
462+
export function getbufvar(
463+
denops: Denops,
464+
buf: BufNameArg,
465+
varname: "" | "&",
466+
def?: unknown,
467+
): Promise<Record<string, unknown>>;
468+
export function getbufvar(
469+
denops: Denops,
470+
buf: BufNameArg,
471+
varname: string,
472+
def?: unknown,
473+
): Promise<unknown>;
474+
export function getbufvar(
475+
denops: Denops,
476+
...args: unknown[]
477+
): Promise<unknown> {
478+
return denops.call("getbufvar", ...args);
479+
}
480+
436481
/**
437482
* Set line **{lnum}** to **{text}** in buffer **{buf}**. This works like
438483
* `setline()` for the specified buffer.

0 commit comments

Comments
 (0)