@@ -266,7 +266,35 @@ local function indentexpr(linenr, bufnr)
266266
267267 local new_indent = get_indent_for_match (indentexpr_cache .matches , linenr , mode , bufnr )
268268 local match = indentexpr_cache .matches [linenr ]
269+
269270 if match then
271+ -- Attempt to calculate indentation from the block filetype
272+ if match .indent_type == ' block' and linenr > match .line_nr and linenr < match .line_end_nr then
273+ local block_parameters = match .node :field (' parameter' )
274+
275+ if block_parameters and block_parameters [1 ] then
276+ local block_ft = vim .treesitter .get_node_text (block_parameters [1 ], bufnr )
277+
278+ if block_ft and block_ft ~= vim .bo .filetype then
279+ local curr_indentexpr = vim .filetype .get_option (block_ft , ' indentexpr' ) --[[ @as string]]
280+
281+ if curr_indentexpr and curr_indentexpr ~= ' ' then
282+ curr_indentexpr = curr_indentexpr :gsub (' %(%)$' , ' ' )
283+
284+ local buf_shiftwidth = vim .bo .shiftwidth
285+ vim .bo .shiftwidth = vim .filetype .get_option (block_ft , ' shiftwidth' )
286+ local ok , block_ft_indent = pcall (function ()
287+ return vim .fn [curr_indentexpr ]()
288+ end )
289+ if ok then
290+ new_indent = math.max (block_ft_indent , vim .fn .indent (match .line_nr ))
291+ end
292+
293+ vim .bo .shiftwidth = buf_shiftwidth
294+ end
295+ end
296+ end
297+ end
270298 match .indent = new_indent
271299 end
272300 indentexpr_cache .prev_linenr = linenr
0 commit comments