Skip to content

Commit

Permalink
feat: support ignore_filetype
Browse files Browse the repository at this point in the history
  • Loading branch information
VidocqH committed Oct 23, 2023
1 parent 972026d commit 2de38d2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

A simple util providing auto indent like VSCode when cursor at the first column and press \<TAB\> key


https://github.com/VidocqH/auto-indent.nvim/assets/16725418/b0eda63f-9b7d-4708-8477-00bde49d8f40


## Installation

### Lazy
Expand All @@ -25,8 +23,9 @@ requir("lazy").setup({

```lua
{
lightmode = true, -- Lightmode assumes tabstop and indentexpr not change within buffer's lifetime
indentexpr = nil, -- Use vim.bo.indentexpr by default
lightmode = true, -- Lightmode assumes tabstop and indentexpr not change within buffer's lifetime
indentexpr = nil, -- Use vim.bo.indentexpr by default, see 'Custom Indent Evaluate Method'
ignore_filetype = {}, -- Disable plugin for specific filetypes, e.g. ignore_filetype = { 'javascript' }
}
```

Expand Down
2 changes: 2 additions & 0 deletions lua/auto-indent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ local module = require("auto-indent.module")
---@class Config
---@field lightmode boolean
---@field indentexpr nil | fun(lnum: integer): integer
---@field ignore_filetype string[]
local config = {
lightmode = true,
indentexpr = nil,
ignore_filetype = {},
}

---@class MyModule
Expand Down
17 changes: 17 additions & 0 deletions lua/auto-indent/utils.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---@class Utils
local M = {}

---@generic T
---@param arr T[]
---@param val T
---@return boolean
M.array_contains = function(arr, val)
for _, v in ipairs(arr) do
if val == v then
return true
end
end
return false
end

return M
7 changes: 7 additions & 0 deletions plugin/auto-indent.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
local utils = require("auto-indent.utils")

vim.api.nvim_create_user_command("AutoIndentGetIndents", require("auto-indent").check_indent, {})

vim.api.nvim_create_autocmd("BufRead", {
callback = function(e)
local config = require("auto-indent").config

local buf = e.buf

if utils.array_contains(config.ignore_filetype, vim.api.nvim_buf_get_option(buf, "filetype")) then
return
end

if config.lightmode then
require("auto-indent.module").fetch_buf_indent_info(buf, config.indentexpr)
end
Expand Down

0 comments on commit 2de38d2

Please sign in to comment.