eraserhd / parinfer-rust

A Rust port of parinfer.
ISC License
546 stars 42 forks source link

hard to add new filetypes #53

Closed andreyorst closed 5 years ago

andreyorst commented 5 years ago

In order to have parinfer for racket language I have to install kakoune-racket and add such configuration to my kakrc:

plug "eraserhd/parinfer-rust" do %{
    cargo install --force --path . --locked
    cargo clean
} config %{
    hook -group parinfer global WinSetOption filetype=(clojure|lisp|scheme|racket) %{
        require-module parinfer
        parinfer -if-enabled -paren
        hook -group parinfer window NormalKey .* %{ parinfer -if-enabled -smart }
        hook -group parinfer window InsertChar (?!\n).* %{ parinfer -if-enabled -smart }
        hook -group parinfer window InsertDelete .* %{ parinfer -if-enabled -smart }
    }

    hook -group parinfer global WinSetOption filetype=(?!clojure)(?!lisp)(?!scheme)(?!racket).* %{
        remove-hooks window parinfer
    }
}

Basically copying your hooks from rc/. Maybe put those into function parinfer-enable -params 1 that accepts a mode as a parameter? And parinfer-disable will remove the hooks.

after that user will able to define it's own hooks in configuration for only filetypes they need.

eraserhd commented 5 years ago

First, I think this should enable for racket out of the box. But there are other, weird lispy things, too.

How about a parinfer_filetypes option?

It would be a little tricky, since either filetype or parinfer_filetypes could be set first in a window context, but then you'd just have set-option -add global parinfer_filetypes racket in your config section.

andreyorst commented 5 years ago

First, I think this should enable for racket out of the box. But there are other, weird lispy things, too.

I think it's not. There are too many dialects, so a generic method for enabling or disabling parinfer for current mode is a better option.

How about a parinfer_filetypes option?

Why not to make a command that sets window local hooks for parinfer and let users configure filetypes by hooks? E.g. I have several plugins that do this, for example smarttab.kak configuration:

hook global WinSetOption filetype=(rust|markdown|kak|lisp|scheme|sh|perl) expandtab
hook global WinSetOption filetype=(makefile|gas) noexpandtab
hook global WinSetOption filetype=(c|cpp) smarttab

Or, tagbar.kak configuration:

hook global WinSetOption filetype=(c|cpp|rust|gas) tagbar-enable

This way user will be able to just do:

hook global WinSetOption filetype=(racket|arc-lisp) %{ parinfer-enable-buffer -smart }
hook global WinSetOption filetype=(scheme) %{ parinfer-enable-buffer -indent }
eraserhd commented 5 years ago

OK, you've convinced me.

andreyorst commented 5 years ago

I can create PR if you sort on time!)

eraserhd commented 5 years ago

That would be awesome!