Olical / Olical/dotfiles

Issues with autopairs setup

Open
#17 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Fennel
Stars
536
Forks
47
PR merge metrics
No merged PRs in 30d

Description

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 🙂

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the dotfiles.plugin.autopairs module and inspect nvim-autopairs.get_rule for the apostrophe and backtick rules. Verify how disable-rule-for-filetypes receives its arguments, handles single and multiple rules, and preserves existing Rust exclusions; done means the listed Lisp filetypes are disabled without removing those exclusions.

Written by the indexing model from the issue text.

Assessment

Tech stack
neovim
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.