Skip to content

Commit 28f6ac9

Browse files
committed
feat: new setup options, docs fixed, CI improvements
Signed-off-by: Guennadi Maximov C <g.maxc.fox@protonmail.com>
1 parent d9e8fa7 commit 28f6ac9

4 files changed

Lines changed: 60 additions & 18 deletions

File tree

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Toggle `true` and `false` values under your cursor.
1414
- [`paq-nvim`](#paq-nvim)
1515
- [`vim.pack`](#vimpack)
1616
- [LuaRocks](#luarocks)
17+
- [Configuration](#configuration)
18+
- [Defaults](#defaults)
19+
- [License](#license)
1720

1821
---
1922

@@ -126,7 +129,11 @@ By default, `setup()` loads with the following options:
126129

127130
```lua
128131
{
129-
auto_write = false, -- Whether to automatically save the file when a boolean is changed
132+
-- Whether to automatically save the file when a boolean is changed
133+
auto_write = false,
134+
135+
-- A list of strings with the filetypes for which this plugin will be deactivated
136+
ignore_ft = {}
130137

131138
-- Normal mode keymaps
132139
--
@@ -148,4 +155,8 @@ By default, `setup()` loads with the following options:
148155

149156
---
150157

158+
## License
159+
160+
[GPLv2](https://github.com/DrKJeff16/boolean-toggle.nvim/blob/main/LICENSE)
161+
151162
<!-- vim: set ts=2 sts=2 sw=2 et ai si sta: -->

lua/boolean-toggle.lua

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ function M.setup(opts)
9191
end
9292
end
9393

94-
vim.api.nvim_create_user_command(
95-
'Bool',
96-
M.cursor_toggle_boolean,
97-
{ desc = 'Invert Boolean Value on Cursor' }
98-
)
94+
vim.api.nvim_create_user_command('Bool', M.cursor_toggle_boolean, { desc = 'Invert Boolean Value on Cursor' })
9995
end
10096

10197
---@return boolean is_boolean
@@ -133,8 +129,20 @@ function M.boolean_under_cursor()
133129
end
134130

135131
function M.cursor_toggle_boolean()
132+
local bufnr = vim.api.nvim_get_current_buf()
136133
local ok, start_col, end_col = M.boolean_under_cursor()
137-
if not (ok and start_col and end_col) then
134+
if
135+
not (
136+
ok
137+
and start_col
138+
and end_col
139+
and vim.list_contains({ 'acwrite', '' }, vim.api.nvim_get_option_value('buftype', { buf = bufnr }))
140+
)
141+
then
142+
return
143+
end
144+
145+
if vim.list_contains(Config.config.ignore_ft, vim.api.nvim_get_option_value('filetype', { buf = bufnr })) then
138146
return
139147
end
140148

@@ -161,8 +169,20 @@ function M.cursor_toggle_boolean()
161169
end
162170

163171
function M.cursor_set_to_false()
172+
local bufnr = vim.api.nvim_get_current_buf()
164173
local ok, start_col, end_col = M.boolean_under_cursor()
165-
if not (ok and start_col and end_col) then
174+
if
175+
not (
176+
ok
177+
and start_col
178+
and end_col
179+
and vim.list_contains({ 'acwrite', '' }, vim.api.nvim_get_option_value('buftype', { buf = bufnr }))
180+
)
181+
then
182+
return
183+
end
184+
185+
if vim.list_contains(Config.config.ignore_ft, vim.api.nvim_get_option_value('filetype', { buf = bufnr })) then
166186
return
167187
end
168188

@@ -176,8 +196,7 @@ function M.cursor_set_to_false()
176196
local pos = vim.api.nvim_win_get_cursor(win)
177197
local before, after = get_boolean_surround(line, start_col, end_col)
178198
if not vim.list_contains({ 't', 'T' }, line:sub(pos[2] + 1, pos[2] + 1)) then
179-
pos[2] = pos[2]
180-
+ (line:len() > (before .. convert_to_false[current_bool] .. after):len() and -1 or 1)
199+
pos[2] = pos[2] + (line:len() > (before .. convert_to_false[current_bool] .. after):len() and -1 or 1)
181200
end
182201

183202
vim.api.nvim_set_current_line(before .. convert_to_false[line:sub(start_col, end_col)] .. after)
@@ -190,8 +209,20 @@ function M.cursor_set_to_false()
190209
end
191210

192211
function M.cursor_set_to_true()
212+
local bufnr = vim.api.nvim_get_current_buf()
193213
local ok, start_col, end_col = M.boolean_under_cursor()
194-
if not (ok and start_col and end_col) then
214+
if
215+
not (
216+
ok
217+
and start_col
218+
and end_col
219+
and vim.list_contains({ 'acwrite', '' }, vim.api.nvim_get_option_value('buftype', { buf = bufnr }))
220+
)
221+
then
222+
return
223+
end
224+
225+
if vim.list_contains(Config.config.ignore_ft, vim.api.nvim_get_option_value('filetype', { buf = bufnr })) then
195226
return
196227
end
197228

@@ -205,8 +236,7 @@ function M.cursor_set_to_true()
205236
local pos = vim.api.nvim_win_get_cursor(win)
206237
local before, after = get_boolean_surround(line, start_col, end_col)
207238
if not vim.list_contains({ 't', 'T' }, line:sub(pos[2] + 1, pos[2] + 1)) then
208-
pos[2] = pos[2]
209-
+ (line:len() > (before .. convert_to_true[current_bool] .. after):len() and -1 or 1)
239+
pos[2] = pos[2] + (line:len() > (before .. convert_to_true[current_bool] .. after):len() and -1 or 1)
210240
end
211241

212242
vim.api.nvim_set_current_line(before .. convert_to_true[line:sub(start_col, end_col)] .. after)
@@ -218,7 +248,5 @@ function M.cursor_set_to_true()
218248
end
219249
end
220250

221-
function M.setup_keymaps() end
222-
223251
return M
224252
-- vim: set ts=2 sts=2 sw=2 et ai si sta:

lua/boolean-toggle/config.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
local Util = require('boolean-toggle.util')
2-
31
---@class BooleanToggleOpts.Keymaps
42
---@field to_false? string|nil
53
---@field to_true? string|nil
@@ -12,12 +10,16 @@ local Util = require('boolean-toggle.util')
1210

1311
---@class BooleanToggleOpts
1412
---@field auto_write? boolean
13+
---@field ignore_ft? string[]
1514
---@field keymaps? BooleanToggleOpts.Keymaps|nil
1615

1716
---@class BooleanToggleDefaults: BooleanToggleOpts
1817
---@field auto_write boolean
18+
---@field ignore_ft string[]
1919
---@field keymaps BooleanToggleDefaults.Keymaps
2020

21+
local Util = require('boolean-toggle.util')
22+
2123
---@class BooleanToggle.Config
2224
---@field config BooleanToggleDefaults
2325
local M = {}
@@ -26,6 +28,7 @@ local M = {}
2628
function M.get_defaults()
2729
return { ---@type BooleanToggleDefaults
2830
auto_write = false,
31+
ignore_ft = {},
2932
keymaps = { toggle = nil, to_false = nil, to_true = nil },
3033
}
3134
end

stylua.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
call_parentheses = "Always"
22
collapse_simple_statement = "Never"
3-
column_width = 100
3+
column_width = 120
44
indent_type = "Spaces"
55
indent_width = 2
66
line_endings = "Unix"

0 commit comments

Comments
 (0)