]> git.rmz.io Git - dotfiles.git/commitdiff
nvim: use nvim-origami for folds
authorSamir Benmendil <me@rmz.io>
Sat, 13 Dec 2025 15:34:53 +0000 (15:34 +0000)
committerSamir Benmendil <me@rmz.io>
Sat, 13 Dec 2025 15:34:53 +0000 (15:34 +0000)
It supports syntax highlighting of the folded first line and adds
virtual text to show the line numbers and diagnostics.

There's some settings that needed disabling though. I'd also like to
place the virtual text on the right. So maybe I'll want to roll my own
at some point.

nvim/lazy-lock.json
nvim/lua/config/options.lua
nvim/lua/plugins/editor.lua
nvim/lua/rmz/util/init.lua
vim/ftplugin/cpp.vim

index aa69e776bea02da89f4d0ee4301f089ffa494514..72f9e86cf9525dd46870159ca1f5ff0f63995f34 100644 (file)
@@ -53,6 +53,7 @@
   "nvim-lspconfig": { "branch": "master", "commit": "a2bd1cf7b0446a7414aaf373cea5e4ca804c9c69" },
   "nvim-navic": { "branch": "master", "commit": "7d914a39a1ef8f4e22c2c4381abeef7c556f5a13" },
   "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" },
   "nvim-lspconfig": { "branch": "master", "commit": "a2bd1cf7b0446a7414aaf373cea5e4ca804c9c69" },
   "nvim-navic": { "branch": "master", "commit": "7d914a39a1ef8f4e22c2c4381abeef7c556f5a13" },
   "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" },
+  "nvim-origami": { "branch": "main", "commit": "ad252be766e7d07e0f1998d84deadb972736db08" },
   "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
   "nvim-treesitter-textobjects": { "branch": "master", "commit": "5ca4aaa6efdcc59be46b95a3e876300cfead05ef" },
   "nvim-ts-autotag": { "branch": "main", "commit": "c4ca798ab95b316a768d51eaaaee48f64a4a46bc" },
   "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
   "nvim-treesitter-textobjects": { "branch": "master", "commit": "5ca4aaa6efdcc59be46b95a3e876300cfead05ef" },
   "nvim-ts-autotag": { "branch": "main", "commit": "c4ca798ab95b316a768d51eaaaee48f64a4a46bc" },
index 31f96b7e47e9e90415e53ba51ce3f46bdf518fb9..d960d6087d5a3f43b5aa89610bbf0ee65696bac7 100644 (file)
@@ -31,8 +31,6 @@ opt.signcolumn = "yes" -- Always show the signcolumn, otherwise it would shift t
 opt.updatetime = 200 -- Save swap file and trigger CursorHold
 opt.splitkeep = "screen"
 opt.shortmess:append({ C = true })
 opt.updatetime = 200 -- Save swap file and trigger CursorHold
 opt.splitkeep = "screen"
 opt.shortmess:append({ C = true })
-opt.foldmethod = "expr"
-opt.foldexpr = "v:lua.require'rmz.util'.foldexpr()"
 
 -- do not let markdown plugin change indent
 vim.g.markdown_recommended_style = 0
 
 -- do not let markdown plugin change indent
 vim.g.markdown_recommended_style = 0
index f5bfd74a67b3b2b7349a1f0dbe303b77717c38a1..249ac6d16f9745bcf2375f29585af5da5e2b7ae9 100644 (file)
@@ -182,6 +182,23 @@ return {
       end,
     },
   },
       end,
     },
   },
+  { "chrisgrieser/nvim-origami", -- fold with elegance
+    event = "VeryLazy",
+    opts = {
+      foldKeymaps = { setup = false },
+      foldtext = {
+        padding = 1,
+        lineCount = {
+          template = "…  %d lines"
+        }
+      }
+    },
+    init = function()
+      -- disable vim's folding
+      vim.opt.foldlevel = 99
+      vim.opt.foldlevelstart = 99
+    end
+  },
 
   -- TODO: currently unused plugins, check and enable/remove
   { "MagicDuck/grug-far.nvim", enabled = false,
 
   -- TODO: currently unused plugins, check and enable/remove
   { "MagicDuck/grug-far.nvim", enabled = false,
index abf0c2130696a451af9a400b1e93e07d88e61089..54d8f6b7dec0ccf867d4333d175b6cd8dd83f76c 100644 (file)
@@ -21,21 +21,4 @@ function M.dedup(list)
   return ret
 end
 
   return ret
 end
 
-function M.foldexpr()
-  local buf = vim.api.nvim_get_current_buf()
-  if vim.b[buf].ts_folds == nil then
-    -- as long as we don't have a filetype, don't bother
-    -- checking if treesitter is available (it won't)
-    if vim.bo[buf].filetype == "" then
-      return "0"
-    end
-    if vim.bo[buf].filetype:find("dashboard") then
-      vim.b[buf].ts_folds = false
-    else
-      vim.b[buf].ts_folds = pcall(vim.treesitter.get_parser, buf)
-    end
-  end
-  return vim.b[buf].ts_folds and vim.treesitter.foldexpr() or "0"
-end
-
 return M
 return M
index d24f1ff44a570d2def86a18b419ee117f6f0e73b..a039bacdca9557403cef9ca2c6b0a8a3b7eb5b55 100644 (file)
@@ -76,30 +76,3 @@ function! s:Debug(...)
 endfunction
 command! -nargs=* -complete=file -bang Debug call <SID>Debug() | Termdebug<bang> <args>
 command! -nargs=+ -complete=file -bang DebugCommand call <SID>Debug() | TermdebugCommand<bang> <args>
 endfunction
 command! -nargs=* -complete=file -bang Debug call <SID>Debug() | Termdebug<bang> <args>
 command! -nargs=+ -complete=file -bang DebugCommand call <SID>Debug() | TermdebugCommand<bang> <args>
-
-setlocal foldmethod=syntax
-" set foldlevel according to number of matches of 'namespace' and 'class' not
-" containing ';'
-function! InitialFoldLevel()
-    let v:errmsg = ""
-    keepjumps keeppatterns silent! 1,/}/s/^\(namespace\|class\) \+[^;]*$//n
-    if v:errmsg == ""
-        let &l:foldlevel=str2nr(split(v:statusmsg)[0])
-    endif
-endf
-call InitialFoldLevel()
-
-function! MyCppFoldText()
-  let l:line = getline(v:foldstart)
-  " expand tabs in line, foldtext does not do it on its own
-  let l:line = substitute(l:line, "\t", repeat(" ", shiftwidth()), "g")
-  let l:width = min([&textwidth, winwidth(0)])
-  let l:lineinfo = printf("%d", v:foldend - v:foldstart)
-  let l:ellipsis = "…"
-  return printf("%.*s%s%*d",
-        \ l:width - strdisplaywidth(l:ellipsis..l:lineinfo), l:line,
-        \ l:ellipsis,
-        \ l:width - strdisplaywidth(l:line..l:ellipsis),     l:lineinfo)
-endfunction
-setlocal foldtext=MyCppFoldText()
-setlocal fillchars+=fold:\