Skip to content

Commit

Permalink
👍 Add gin-diff filetype
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Aug 2, 2022
1 parent cd4ef7c commit f055071
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 36 deletions.
47 changes: 11 additions & 36 deletions denops/gin/feat/diff/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,16 @@ export async function exec(
}

export async function read(denops: Denops): Promise<void> {
const [env, verbose, bufnr, bname, cmdarg, disableDefaultMappings] =
await batch.gather(
denops,
async (denops) => {
await fn.environ(denops);
await option.verbose.get(denops);
await fn.bufnr(denops, "%");
await fn.bufname(denops, "%");
await vars.v.get(denops, "cmdarg");
await vars.g.get(
denops,
"gin_diff_disable_default_mappings",
false,
);
},
) as [Record<string, string>, number, number, string, string, unknown];
unknownutil.assertBoolean(disableDefaultMappings);
const [env, verbose, bufnr, bname, cmdarg] = await batch.gather(
denops,
async (denops) => {
await fn.environ(denops);
await option.verbose.get(denops);
await fn.bufnr(denops, "%");
await fn.bufname(denops, "%");
await vars.v.get(denops, "cmdarg");
},
) as [Record<string, string>, number, number, string, string, unknown];
const [opts, _] = parseOpts(cmdarg.split(" "));
validateOpts(opts, builtinOpts);
const { expr, params, fragment } = bufname.parse(bname);
Expand Down Expand Up @@ -167,7 +160,7 @@ export async function read(denops: Denops): Promise<void> {
}
await buffer.ensure(denops, bufnr, async () => {
await batch.batch(denops, async (denops) => {
await option.filetype.setLocal(denops, "diff");
await option.filetype.setLocal(denops, "gin-diff");
await option.bufhidden.setLocal(denops, "unload");
await option.buftype.setLocal(denops, "nofile");
await option.swapfile.setLocal(denops, false);
Expand All @@ -190,24 +183,6 @@ export async function read(denops: Denops): Promise<void> {
noremap: true,
},
);
if (!disableDefaultMappings) {
await mapping.map(
denops,
"g<CR>",
"<Plug>(gin-diffjump-old)zv",
{
buffer: true,
},
);
await mapping.map(
denops,
"<CR>",
"<Plug>(gin-diffjump-new)zv",
{
buffer: true,
},
);
}
});
});
await buffer.assign(denops, bufnr, stdout, {
Expand Down
11 changes: 11 additions & 0 deletions ftplugin/gin-diff.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if exists('b:did_ftplugin')
finish
endif
runtime ftplugin/diff.vim

if !get(g:, 'gin_diff_disable_default_mappings')
nmap <buffer> g<CR> <Plug>(gin-diffjump-old)zv
nmap <buffer> <CR> <Plug>(gin-diffjump-new)zv
endif

let b:did_ftplugin = 1
6 changes: 6 additions & 0 deletions syntax/gin-diff.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if exists('b:current_syntax')
finish
endif
runtime syntax/diff.vim

let b:current_syntax = 'gin-diff'

0 comments on commit f055071

Please sign in to comment.