Support custom filename formatting #168

Open
jayeheffernan wants to merge 1 commit from jayeheffernan/config_format_filenames into master
jayeheffernan commented 2025-02-27 03:11:59 -06:00 (Migrated from github.com)

This PR adds a way to control the format of the question filenames, by passing a function in your config. Here's a sample config that uses it:

return {
  "kawre/leetcode.nvim",
  build = ":TSUpdate html", -- if you have `nvim-treesitter` installed
  dependencies = {
    -- "nvim-telescope/telescope.nvim",
    "ibhagwan/fzf-lua",
    "nvim-lua/plenary.nvim",
    "MunifTanjim/nui.nvim",
  },
  opts = {
    lang = "rust",
    storage = {
      home = vim.fn.stdpath("data") .. "/leetcode/src/bin",
      cache = vim.fn.stdpath("cache") .. "/leetcode",
      format = function(opts)
        local fn = ("%s__%s%s.%s"):format(opts.id, opts.slug, opts.ft_alt, opts.ft)
        return fn
      end,
    },
  },
}

Motivation

I wanted to use src/bin in a Rust project as a home folder, so that LSP stuff and commands like cargo fmt and cargo test work smoothly. But I ran into this problem (e.g. running cargo test):

error: invalid character `'.'` in crate name: `9.palindrome-number`

So I want the filenames not to include ".".

This PR adds a way to control the format of the question filenames, by passing a function in your config. Here's a sample config that uses it: ```lua return { "kawre/leetcode.nvim", build = ":TSUpdate html", -- if you have `nvim-treesitter` installed dependencies = { -- "nvim-telescope/telescope.nvim", "ibhagwan/fzf-lua", "nvim-lua/plenary.nvim", "MunifTanjim/nui.nvim", }, opts = { lang = "rust", storage = { home = vim.fn.stdpath("data") .. "/leetcode/src/bin", cache = vim.fn.stdpath("cache") .. "/leetcode", format = function(opts) local fn = ("%s__%s%s.%s"):format(opts.id, opts.slug, opts.ft_alt, opts.ft) return fn end, }, }, } ``` ### Motivation I wanted to use `src/bin` in a Rust project as a home folder, so that LSP stuff and commands like `cargo fmt` and `cargo test` work smoothly. But I ran into this problem (e.g. running `cargo test`): ```txt error: invalid character `'.'` in crate name: `9.palindrome-number` ``` So I want the filenames not to include ".".
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin jayeheffernan/config_format_filenames:jayeheffernan/config_format_filenames
git switch jayeheffernan/config_format_filenames

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff jayeheffernan/config_format_filenames
git switch jayeheffernan/config_format_filenames
git rebase master
git switch master
git merge --ff-only jayeheffernan/config_format_filenames
git switch jayeheffernan/config_format_filenames
git rebase master
git switch master
git merge --no-ff jayeheffernan/config_format_filenames
git switch master
git merge --squash jayeheffernan/config_format_filenames
git switch master
git merge --ff-only jayeheffernan/config_format_filenames
git switch master
git merge jayeheffernan/config_format_filenames
git push origin master
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
arduinohatesme/leetcode.nvim!168
No description provided.