A readme explaining how to make neovim work fast
better comment fold for python
1 file changed, +8 -9
+8-9lua/config/autocmds/init.lua
| @@ -99,26 +99,25 @@ _G.CommentFoldExpr = function() | ||
| 99 | 99 | local line = vim.fn.getline(vim.v.lnum) |
| 100 | 100 | local ft = vim.bo.filetype |
| 101 | 101 | 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 | |
| 103 | 104 | if ft == "python" then |
| 104 | 105 | if line:match('""".*"""') then |
| 105 | - return "=" | |
| 106 | - elseif line:match('"""') then | |
| 106 | + return "0" | |
| 107 | + end | |
| 108 | + if line:match('"""') then | |
| 107 | 109 | if _G.in_docstring then |
| 108 | 110 | _G.in_docstring = false |
| 109 | - return "s1" -- end fold | |
| 110 | 111 | else |
| 111 | 112 | _G.in_docstring = true |
| 112 | - return "a1" -- begin fold | |
| 113 | + should_fold = true | |
| 113 | 114 | end |
| 114 | 115 | end |
| 115 | 116 | end |
| 116 | - -- dynamically fold comments | |
| 117 | - if line:match("^%s*" .. cs) then | |
| 117 | + if should_fold then | |
| 118 | 118 | return 1 |
| 119 | - else | |
| 120 | - return 0 | |
| 121 | 119 | end |
| 120 | + return 0 | |
| 122 | 121 | end |
| 123 | 122 | local foldexpr = "v:lua.CommentFoldExpr()" |
| 124 | 123 | vim.api.nvim_create_user_command("UseFoldTreesitter", function() |