Olical / dotfiles

Configuration for Linux, i3, Kitty, Fish, Neovim and more
https://oli.me.uk
The Unlicense
508 stars 45 forks source link

Issues with autopairs setup #17

Open necabo opened 1 year ago

necabo commented 1 year ago

I'm in the process of yoinking some of your configuration (thank you for providing that, the plugins and blog posts) and noticed some small issues in the autopairs setup.

  1. It looks like you forgot to finish writing disable-rule-for-filetypes so that it accepts and makes use of the arguments you provide when calling it. It instead always uses autopairs.get_rule for "'" and the lisps table (the latter doesn't really matter).
  2. Making that change myself I noticed that it doesn't work for "`". Running :lua require(vim.inspect(require('nvim-autopairs').get_rule("`"))) reveals that because only a single rule exists, it can't be indexed.
  3. When debugging this, I noticed that there are two rules for "'", the second one being exclusive to Rust and more importantly, the first one excluding Rust using not_filetypes = { "rust" } (these rules disable autopairs for "'" when used in lifetime annotation position). Since your current code uses assoc-in, it overrides the existing table of excluded filetypes essentially disabling the rather useful rules for Rust.

Here is my (likely unidiomatic, this is my first LISP) code to address these issues:

(module dotfiles.plugin.autopairs
  {autoload {a aniseed.core}})

(def- lisps [:scheme :lisp :clojure :fennel])

(defn- extend [tbl items]
  (let [tbl (if (a.nil? tbl) [] tbl)]
    (each [_ item (ipairs items)]
      (table.insert tbl item))
    tbl))

(defn- get-if-not-nil [tbl index]
  (let [val (. tbl index)]
    (if (a.nil? val)
        tbl
        val)))

(let [(ok? autopairs) (pcall require :nvim-autopairs)]
  (when ok?
    (defn- disable-rule-for-filetypes [rule filetypes]
      (let [rule (autopairs.get_rule rule)]
        (let [rule (get-if-not-nil rule 1)]
          (a.assoc rule
                   :not_filetypes
                   (extend (. rule :not_filetypes) filetypes)))))

    (autopairs.setup)
    (disable-rule-for-filetypes "'" lisps)
    (disable-rule-for-filetypes "`" lisps)))

I hope this is useful to you :slightly_smiling_face: