Skip to content

Commit 36c13b2

Browse files
committed
Make indentexpr() slightly easier to debug.
This simply turns the indentation line number and the current mode into optional arguments. If they're not passed, `vim.v.lnum` and `vim.fn.mode()` are used as usual. However, this allows calling a *hyptothetical* `indentexpr()` from the command line for debugging. Note that `indentexpr()` currently doesn't *use* `vim.fn.mode()`. It will in a future commit, though.
1 parent c362ad2 commit 36c13b2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lua/orgmode/org/indent.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,16 @@ local function get_is_list_item(line)
113113
return line_numbered_list_item or line_unordered_list_item
114114
end
115115

116-
local function indentexpr()
116+
local function indentexpr(linenr, mode)
117+
linenr = linenr or vim.v.lnum
118+
mode = mode or vim.fn.mode()
117119
local noindent_mode = config.org_indent_mode == 'noindent'
118120
query = query or ts.get_query('org', 'org_indent')
119121

120-
local prev_linenr = vim.fn.prevnonblank(vim.v.lnum - 1)
122+
local prev_linenr = vim.fn.prevnonblank(linenr - 1)
121123

122124
local matches = get_matches(0)
123-
local match = matches[vim.v.lnum]
125+
local match = matches[linenr]
124126
local prev_line_match = matches[prev_linenr]
125127

126128
if not match and not prev_line_match then
@@ -143,11 +145,11 @@ local function indentexpr()
143145

144146
if match.type == 'list' and prev_line_match.type == 'list' then
145147
local prev_line_list_item = get_is_list_item(vim.fn.getline(prev_linenr))
146-
local cur_line_list_item = get_is_list_item(vim.fn.getline(vim.v.lnum))
148+
local cur_line_list_item = get_is_list_item(vim.fn.getline(linenr))
147149

148150
if cur_line_list_item then
149151
local diff = match.indent - vim.fn.indent(match.line_nr)
150-
local indent = vim.fn.indent(vim.v.lnum)
152+
local indent = vim.fn.indent(linenr)
151153
return indent - diff
152154
end
153155

0 commit comments

Comments
 (0)