irongit

A readme explaining how to make neovim work fast

better comment fold for python

huncholanehuncholaneauthored
parent b773903commit 63e787ec835a7cf27fdb3daf65f5db44bc5117aeBrowse files

1 file changed, +8 -9

+8-9lua/config/autocmds/init.lua
@@ -99,26 +99,25 @@ _G.CommentFoldExpr = function()
9999 local line = vim.fn.getline(vim.v.lnum)
100100 local ft = vim.bo.filetype
101101 local cs = vim.bo.commentstring:gsub("%%s", ""):gsub(" ", ""):gsub("([^%w])", "%%%1")
102- -- fold python docstrings
102+ local should_fold = line:match("^%s*" .. cs) or _G.in_docstring
103+ -- python docstrings
103104 if ft == "python" then
104105 if line:match('""".*"""') then
105- return "="
106- elseif line:match('"""') then
106+ return "0"
107+ end
108+ if line:match('"""') then
107109 if _G.in_docstring then
108110 _G.in_docstring = false
109- return "s1" -- end fold
110111 else
111112 _G.in_docstring = true
112- return "a1" -- begin fold
113+ should_fold = true
113114 end
114115 end
115116 end
116- -- dynamically fold comments
117- if line:match("^%s*" .. cs) then
117+ if should_fold then
118118 return 1
119- else
120- return 0
121119 end
120+ return 0
122121 end
123122 local foldexpr = "v:lua.CommentFoldExpr()"
124123 vim.api.nvim_create_user_command("UseFoldTreesitter", function()