46 lines
2.1 KiB
Fennel
46 lines
2.1 KiB
Fennel
;; config/parinfer.fnl - Parinfer + vim-sexp insert mode coordination
|
|
;;
|
|
;; Single source of truth for whether parinfer is on/off by default
|
|
;; and what that means for vim-sexp's auto-insert bracket mappings.
|
|
;;
|
|
;; When parinfer is ON: it manages closing parens via indentation,
|
|
;; so vim-sexp auto-insert is disabled.
|
|
;; When parinfer is OFF: vim-sexp auto-insert is re-enabled so you
|
|
;; get closing brackets when typing openers.
|
|
|
|
;; ── Configuration ────────────────────────────────────────────────
|
|
;; Change this single flag to flip the default for all sexp filetypes.
|
|
|
|
(local default-enabled true)
|
|
|
|
;; ── Implementation ───────────────────────────────────────────────
|
|
|
|
(local sexp-insert-keys ["(" ")" "[" "]" "{" "}" "\"" "<BS>"])
|
|
|
|
(fn enable-sexp-insert []
|
|
"Restore vim-sexp insert-mode bracket mappings in the current buffer."
|
|
(vim.cmd "imap <silent><buffer> ( <Plug>(sexp_insert_opening_round)")
|
|
(vim.cmd "imap <silent><buffer> ) <Plug>(sexp_insert_closing_round)")
|
|
(vim.cmd "imap <silent><buffer> [ <Plug>(sexp_insert_opening_square)")
|
|
(vim.cmd "imap <silent><buffer> ] <Plug>(sexp_insert_closing_square)")
|
|
(vim.cmd "imap <silent><buffer> { <Plug>(sexp_insert_opening_curly)")
|
|
(vim.cmd "imap <silent><buffer> } <Plug>(sexp_insert_closing_curly)")
|
|
(vim.cmd "imap <silent><buffer> \" <Plug>(sexp_insert_double_quote)")
|
|
(vim.cmd "imap <silent><buffer> <BS> <Plug>(sexp_insert_backspace)"))
|
|
|
|
(fn disable-sexp-insert []
|
|
"Remove vim-sexp insert-mode bracket mappings from the current buffer."
|
|
(each [_ key (ipairs sexp-insert-keys)]
|
|
(pcall vim.api.nvim_buf_del_keymap 0 "i" key)))
|
|
|
|
(fn toggle []
|
|
"Toggle parinfer in the current buffer and sync vim-sexp insert mappings."
|
|
(vim.cmd "ParinferToggle")
|
|
(let [on (= (vim.api.nvim_buf_get_var 0 "parinfer_enabled") 1)]
|
|
(if on
|
|
(disable-sexp-insert)
|
|
(enable-sexp-insert))))
|
|
|
|
{:default-enabled default-enabled
|
|
:toggle toggle}
|