def new_fm_buffer(nvim: Nvim, settings: Settings) -> Buffer: buf = create_buf(nvim, listed=False, scratch=True, wipe=False, nofile=True) buf_set_option(nvim, buf=buf, key="modifiable", val=False) buf_set_option(nvim, buf=buf, key="filetype", val=FM_FILETYPE) km = Keymap() km.n("{") << f"{settings.page_increment}<up>" km.n("}") << f"{settings.page_increment}<down>" for function, mappings in settings.keymap.items(): for mapping in mappings: km.n(mapping, noremap=True, silent=True, nowait=True) << f"<cmd>lua {function}(false)<cr>" km.v(mapping, noremap=True, silent=True, nowait=True) << f"<esc><cmd>lua {function}(true)<cr>" km.drain(buf=buf).commit(nvim) return buf
def set_options(nvim: Nvim, mapping: KeyMapping, fast_close: bool) -> None: settings = Settings() keymap = Keymap() settings["completefunc"] = f"v:lua.{NAMESPACE}.{omnifunc.name}" if mapping.eval_snips: (keymap.n(mapping.eval_snips) << f"<cmd>lua {NAMESPACE}.{eval_snips.name}(false)<cr>") (keymap.v(mapping.eval_snips) << rf"<c-\><c-n><cmd>lua {NAMESPACE}.{eval_snips.name}(true)<cr>") if mapping.bigger_preview: (keymap.i(mapping.bigger_preview, expr=True) << f"(pumvisible() && complete_info(['mode']).mode ==# 'eval') ? {preview_preview.name}() : '{mapping.bigger_preview}'" ) if mapping.jump_to_mark: keymap.n(mapping.jump_to_mark ) << f"<cmd>lua {NAMESPACE}.{nav_mark.name}()<cr>" (keymap.iv(mapping.jump_to_mark) << rf"<c-\><c-n><cmd>lua {NAMESPACE}.{nav_mark.name}()<cr>") if mapping.repeat: keymap.n(mapping.repeat) << f"<cmd>lua {NAMESPACE}.{repeat.name}()<cr>" if mapping.manual_complete: (keymap.i(mapping.manual_complete, expr=True) << "pumvisible() ? '<c-e><c-x><c-u>' : '<c-x><c-u>'") keymap.nv(mapping.manual_complete) << r"<c-\><c-n>i<c-x><c-u>" settings["completeopt"] += ( "noinsert", "menuone", *(() if mapping.pre_select else ("noselect", )), ) if mapping.recommended: keymap.i("<esc>", expr=True) << "pumvisible() ? '<c-e><esc>' : '<esc>'" keymap.i("<c-c>", expr=True) << "pumvisible() ? '<c-e><c-c>' : '<c-c>'" keymap.i("<bs>", expr=True) << "pumvisible() ? '<c-e><bs>' : '<bs>'" keymap.i("<c-w>", expr=True) << "pumvisible() ? '<c-e><c-w>' : '<c-w>'" keymap.i("<c-u>", expr=True) << "pumvisible() ? '<c-e><c-u>' : '<c-u>'" (keymap.i("<cr>", expr=True) << "pumvisible() ? (complete_info(['selected']).selected == -1 ? '<c-e><cr>' : '<c-y>') : '<cr>'" ) keymap.i("<tab>", expr=True) << "pumvisible() ? '<c-n>' : '<tab>'" keymap.i("<s-tab>", expr=True) << "pumvisible() ? '<c-p>' : '<bs>'" if fast_close: settings["shortmess"] += "c" (settings.drain() + keymap.drain(buf=None)).commit(nvim)