Skip to content

Commit cc2182b

Browse files
author
troiganto
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 0e3b666 commit cc2182b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lua/orgmode/org/indent.lua

+7-5
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,16 @@ local function get_is_list_item(line)
112112
return line_numbered_list_item or line_unordered_list_item
113113
end
114114

115-
local function indentexpr()
115+
local function indentexpr(linenr, mode)
116+
linenr = linenr or vim.v.lnum
117+
mode = mode or vim.fn.mode()
116118
local noindent_mode = config.org_indent_mode == 'noindent'
117119
query = query or vim.treesitter.query.get('org', 'org_indent')
118120

119-
local prev_linenr = vim.fn.prevnonblank(vim.v.lnum - 1)
121+
local prev_linenr = vim.fn.prevnonblank(linenr - 1)
120122

121123
local matches = get_matches(0)
122-
local match = matches[vim.v.lnum]
124+
local match = matches[linenr]
123125
local prev_line_match = matches[prev_linenr]
124126

125127
if not match and not prev_line_match then
@@ -142,11 +144,11 @@ local function indentexpr()
142144

143145
if match.type == 'list' and prev_line_match.type == 'list' then
144146
local prev_line_list_item = get_is_list_item(vim.fn.getline(prev_linenr))
145-
local cur_line_list_item = get_is_list_item(vim.fn.getline(vim.v.lnum))
147+
local cur_line_list_item = get_is_list_item(vim.fn.getline(linenr))
146148

147149
if cur_line_list_item then
148150
local diff = match.indent - vim.fn.indent(match.line_nr)
149-
local indent = vim.fn.indent(vim.v.lnum)
151+
local indent = vim.fn.indent(linenr)
150152
return indent - diff
151153
end
152154

0 commit comments

Comments
 (0)