From 66f713050c69bf88706d8d17ed2e32c73b12ee57 Mon Sep 17 00:00:00 2001
From: Max Christian Pohle
Date: Sat, 21 Oct 2023 02:32:31 +0200
Subject: Improved code folding, because tree-sitter broke it

---
 .exrc              |   9 +++
 after/syntax/c.vim |   4 ++
 init.lua           |  13 +++-
 vimrc              |  30 ++++----
 vimrc-common       | 197 ++++++++++++++++++++++++++---------------------------
 5 files changed, 133 insertions(+), 120 deletions(-)
 create mode 100644 .exrc

diff --git a/.exrc b/.exrc
new file mode 100644
index 0000000..13bb1c7
--- /dev/null
+++ b/.exrc
@@ -0,0 +1,9 @@
+" vim: tabstop=2 softtabstop=2 shiftwidth=2
+set tabstop=2
+set softtabstop=2
+set shiftwidth=2
+
+
+
+
+
diff --git a/after/syntax/c.vim b/after/syntax/c.vim
index cbdd42b..4c3b3f0 100644
--- a/after/syntax/c.vim
+++ b/after/syntax/c.vim
@@ -34,6 +34,10 @@ set formatoptions+=1 " Don't break a line after a one-letter word.
 " open a corresponding header file
 nnorem <leader>gh      :execute 'edit '.findfile(substitute(expand('%:t'),'\.[ch]$','.h',''))<CR>
 
+if filereadable("/usr/bin/vendor_perl/ack")
+  autocmd FileType c,cpp  set grepprg=/usr/bin/vendor_perl/ack\ --type=cc\ --nogroup\ --column\ $*
+  autocmd FileType c,cpp  set grepformat=%f:%l:%c:%m
+endif
 
 " multiple single line comments in a row " broken!
 " syn region myCComment start="/\*" end="\*/" fold keepend transparent
diff --git a/init.lua b/init.lua
index bbc9f05..2dc45ee 100644
--- a/init.lua
+++ b/init.lua
@@ -1,13 +1,17 @@
 vim.cmd('source ~/.vim/vimrc')
 
-vim.o.termguicolors = true
-vim.o.exrc = true
+vim.opt.termguicolors = true
+vim.opt.exrc = true
+vim.opt.foldmethod = 'syntax'
 
 if vim.fn.has("win32") then
   vim.opt.rtp:append(vim.fn.expand("$HOME\\scoop\\shims"))
 end
 
 vim.opt.runtimepath:remove("/usr/share/vim/vimfiles")
+vim.keymap.set('n', '<F12>', ':Buffers<CR>')
+
+
 
 -- vim.o.shadafile = "/tmp/shada"
 
@@ -201,4 +205,9 @@ require'nvim-treesitter.configs'.setup {
   },
 }
 
+-- vim.wo.foldtext = 'v:lua.vim.treesitter.foldtext()' -- not available yet in my installation
+vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
+vim.wo.foldlevel = 1
+
+
 -- vim: tabstop=2 shiftwidth=2 softtabstop=2
diff --git a/vimrc b/vimrc
index 4a81724..424f5f0 100644
--- a/vimrc
+++ b/vimrc
@@ -1,12 +1,19 @@
 exec ':source '.fnamemodify($MYVIMRC,':h').'/'.'vimrc-common' 
 set packpath+=pack/submodules
 
-set isfname-==
-set modeline
-
-set signcolumn=yes
-set foldcolumn=1
+if has("nvim")
+  set shadafile="/tmp/shada"
+endif
 
+if exists("g:neovide")
+  " neovide specific
+  set guifont=monospace:h11:b
+  " :#e-subpixelantialias:#h-full
+  let g:neovide_cursor_animation_length=0.03
+  let g:neovide_cursor_trail_size=0.8
+  let g:neovide_scroll_animation_length = 0.05
+  let g:neovide_transparency = 0.9
+endif
 
 " if ($XDG_SESSION_TYPE ==# 'wayland' || ! empty($WAYLAND_DISPLAY))
 "   autocmd TextYankPost  *  call system("wl-copy", get(v:event, 'regcontents'))
@@ -14,19 +21,6 @@ set foldcolumn=1
 "   nnoremap P   :silent  put!   =system('wl-paste')<CR>
 " endif
 
-
-if has("nvim")
-  set shadafile="/tmp/shada"
-endif
-
-" neovide specific
-set guifont=monospace:h11:b
-" :#e-subpixelantialias:#h-full
-let g:neovide_cursor_animation_length=0.03
-let g:neovide_cursor_trail_size=0.8
-let g:neovide_scroll_animation_length = 0.05
-let g:neovide_transparency = 0.9
-
 " scripts from the default vim installation, which do not get loaded by default, but are useful.
 " if filereadable($VIMRUNTIME.'/macros/editexisting.vim')
 "     packadd! editexisting
diff --git a/vimrc-common b/vimrc-common
index fb760cb..dc48045 100644
--- a/vimrc-common
+++ b/vimrc-common
@@ -1,7 +1,5 @@
 "=======================================================================================================================
-" GENERAL:
-" It is likely, that you will want to overwrite these settings with a
-" project-local .vimrc file (activated with exrc setting)
+" GENERAL
 "=======================================================================================================================
 
 filetype on
@@ -9,97 +7,28 @@ filetype plugin on
 filetype indent on
 
 syntax on                                 | " enable syntax highlighting
-syntax sync minlines=60                   | " how many preceding lines will be parsed? (has performance impact)
+syntax sync minlines=60                   | " how many preceding lines will be parsed? (high performance impact)
 
 set secure                                | " to ensure, that modelines do not contain executable code
 set noexrc                                | " exrc was nice, but has too many security problems. Now using editorconfig instead (see plugins)
 set modeline                              | " set variables specific to a file, like indentation by adding a comment (TODO: should probably be replaced by editorconfig)
-set ts=4 sts=4 sw=4 expandtab textwidth=0 | " better done with a modeline or local exrc
 set virtualedit=all                       | " virtual edit should be default behaviour, because I don't see any reason against
 set nonumber norelativenumber             | " do not show numbers by default, because that causes a performance loss, instead activate them on a file type basis
 set ignorecase smartcase                  | " search with ignore case by default, but use case sensitive search when one capital char is contained and highlight while typing (even though its slower)
 set hlsearch incsearch                    | " highlight pattern while entering it (performance wise this isn't that good)
-" set cindent cinoptions+=(0              | " indent at parentheses
 
 
 "=======================================================================================================================
-" PATH -- where to search for includes (e.g. `gf` or `:find`)
-"=======================================================================================================================
-set path+=**4                                                                                        | " allow recursive searches for files (limit depth by 4)
-let &path = &path.",/usr/lib/modules/".substitute(system('uname -r'), "\n", "", "")."/build/include" | " TODO: could fail under windows (no uname)
-
-"=======================================================================================================================
-" SPELL_CHECKING:
-"=======================================================================================================================
-let g:spellfile_URL='http://ftp.vim.org/vim/runtime/spell'
-" add local user default spell file as primary source for words
-let &spellfile=fnamemodify($MYVIMRC, ":p:h")."/spell/spellfile-user.UTF-8.add"
-
-set nospell          | " disable spell checker by default
-set spelllang=en,de  | " languages for the spell checker
-set spellsuggest=10  | " how many words will z= suggest?
-set thesaurus+=~/.vim/thesaurus/php.txt
-
-
-"=======================================================================================================================
-" UNDO:
-" Persistent undo behaviour, also keeps undo history between starts
-"=======================================================================================================================
-if has('persistent_undo')
-  if isdirectory('/dev/shm')
-    set undodir=/dev/shm/     | " save undo file in memory. That is volatile, but fast and we have GIT for longer lasting undoes
-    set directory=/dev/shm/   | " swap file directory to RAM
-    set swapfile
-  elseif isdirectory('/tmp/')
-    set undodir=/tmp/
-  endif
-  set undofile                  | " preserve undo history when closing and reopening buffers (see :help undo-persistence)
-endif
-
-
-"=======================================================================================================================
-" MULTI_BYTE:
+" BASIC CODE STYLE
 "=======================================================================================================================
-if has("multi_byte")
-  scriptencoding utf-8        | " tell vim that we are using UTF-8 here
-  set encoding=utf-8          | " we need default UTF-8 encoding to use cool chars as line break and so on (see below)
-  set termencoding=utf-8      | " we just assume that this is supported.
-
-  set fillchars=              | " initialize empty fillchars
-  set listchars=              | " initialize empty listchars
-
-  if &term ==# 'linux'
-    set fillchars+=vert:\│    | " cool vertical split char
-  else
-    set fillchars+=vert:\║    | " cool vertical split char
-  endif
-
-  set fillchars+=fold:\       | "
-  set fillchars+=diff:\       | " a white space gets used here
-
-  set listchars+=extends:»    | " symbols used when using :set list (which displays non-printable chars)
-  set listchars+=precedes:«   | " symbols used when using :set list (which displays non-printable chars)
-
-  set listchars+=tab:▏\       | "
-  set listchars+=trail:·      | " symbols used when using :set list (which displays non-printable chars)
-  " set listchars+=eol:↲        | " symbols used when using :set list (which displays non-printable chars)
-  " set listchars+=space:⸳ | " ·      | " symbols used when using :set list (which displays non-printable chars)
-  set showbreak+=›            | " symbol used in the beginning of a wrapped line
-
-  " automatically enter list mode when going in insert mode (makes above syntax command temporarily ineffective)
-  set nolist  
-
-  autocmd InsertEnter *  set list
-  autocmd InsertLeave *  set list&
-
-
-  autocmd InsertEnter *  set colorcolumn=80,120
-  autocmd InsertLeave *  set colorcolumn&
+" set cindent cinoptions+=(0              | " indents at the level of parentheses -- if desired
+set expandtab                             | " replace tabs with spaces
+set textwidth=0                           | " should be set file type specific, colorcolumns is there to assist anyways
+set tabstop=4
+set shiftwidth=4
+set softtabstop=4
 
 
-  " set fillchars+=stlnc:\―       | "
-end
-
 " ======================================================================================================================
 "  SETTINGS:
 " ======================================================================================================================
@@ -144,7 +73,7 @@ set writedelay=0
 " display and performance
 set lazyredraw                | " disables redraw during macro execution (improves performance, but causes problems with solid backgrounds)
 set cmdheight=2               | " sets the command line's height
-set signcolumn=auto           | " auto=auto hide, yes=always, no=never show the column with error indicators
+set signcolumn=yes            | " auto=auto hide, yes=always, no=never show the column with error indicators
 set nocursorcolumn            | " turn visual cursor column off (improves performance)
 set updatetime=80             | " updates the screen more often
 set redrawtime=1500           | " Timeout in milliseconds for redrawing the screen (switches syntax off when ssh too slow) / CTRL+L to retry
@@ -158,6 +87,7 @@ set wildmode=longest:full     | " do not preselect any entry and show all possib
 
 " code completion
 " set dictionary=/usr/share/dict/cracklib-small
+set isfname-==                | " remove = as char in filenames, because most FSs do not support it
 set complete+=d               | " scan current and included files for defined name or macro
 set complete+=i               | " scan current and included files for completions
 set complete+=k               | " make default completer <C-N> respect the dictionary
@@ -178,20 +108,19 @@ set foldcolumn=0              | " I think I don't need this second indicator
 " set foldmethod=syntax         | " foldlevel: syntax, indent, manual / foldmethod=syntax makes Vim incredible slow
 set foldnestmax=1             | " top level folding only
 set foldopen=block,hor,search | " when do we unfold?
-set foldtext=printf('%*s%.*S',indent(v:foldstart),'',&textwidth-indent(v:foldstart),substitute(substitute(join(getline(v:foldstart,v:foldend),'\ '),'[[:space:]*/]\\+','\ ','g'),'^[[:space:]*]','','g'))
+" set foldtext=printf('%*s%.*S',indent(v:foldstart),'',&textwidth-indent(v:foldstart),substitute(substitute(join(getline(v:foldstart,v:foldend),'\ '),'[[:space:]*/]\\+','\ ','g'),'^[[:space:]*]','','g'))
+set foldtext=repeat('\ ',indent(v:foldstart)-1).join(getline(v:foldstart,v:foldend))[:winwidth(0)]->substitute('[[:space:]]\\+','\ ','g')
 
 " works ...
 " set foldexpr=match(synIDattr(synID(v:lnum,indent(v:lnum)+1,0),'name'),'Comment')>-1
 set foldexpr=!empty(filter(synstack(v:lnum,indent(v:lnum)+1),{_,val->match(synIDattr(val,'name'),'Comment')>-1}))
 
-
 " vim window behaviour
 set splitbelow                | " open new windows below the current one (i find that more intuitive)
 set splitright                | " this also works for me and makes better use of the scren space I think
 set winminwidth=0             | " (and all other windows, so TODO: watch out)
 set winwidth=30               | " keep NERDTreeWindow at least this size
 
-
 " vim session handling and restore behaviour
 set viminfo+=%                | " restore buffer list
 set sessionoptions=
@@ -213,6 +142,88 @@ set noshiftround              | " indent/un-indent sna=ps to multiple of shiftwi
 set noequalalways             | " do not evenly size windows when opening new or closing old
 set nocursorline              | " turn visual cursor line off (improves performance)
 
+
+"=======================================================================================================================
+" PATH -- where to search for includes (e.g. `gf` or `:find`)
+"=======================================================================================================================
+set path+=**4                             | " allow recursive searches for files (limit depth by 4) 
+if executable("uname") " does not work under Windows
+  let &path = &path.",/usr/lib/modules/".substitute(system('uname -r'), "\n", "", "")."/build/include"
+endif
+
+
+"=======================================================================================================================
+" SPELL_CHECKING:
+"=======================================================================================================================
+let g:spellfile_URL = 'http://ftp.vim.org/vim/runtime/spell'
+" add local user default spell file as primary source for words
+let &spellfile=fnamemodify($MYVIMRC, ":p:h")."/spell/spellfile-user.UTF-8.add"
+
+set nospell          | " disable spell checker by default
+set spelllang=en,de  | " languages for the spell checker
+set spellsuggest=10  | " how many words will z= suggest?
+set thesaurus+=~/.vim/thesaurus/php.txt
+
+
+"=======================================================================================================================
+" UNDO:
+" Persistent undo behaviour, also keeps undo history between starts
+"=======================================================================================================================
+if has('persistent_undo')
+  if isdirectory('/dev/shm')
+    set undodir=/dev/shm/     | " save undo file in memory. That is volatile, but fast and we have GIT for longer lasting undoes
+    set directory=/dev/shm/   | " swap file directory to RAM
+    set swapfile
+  elseif isdirectory('/tmp/')
+    set undodir=/tmp/
+  endif
+  set undofile                  | " preserve undo history when closing and reopening buffers (see :help undo-persistence)
+endif
+
+
+"=======================================================================================================================
+" DISPLAY & MULTI_BYTE
+"=======================================================================================================================
+if has("multi_byte")
+  scriptencoding utf-8        | " tell vim that we are using UTF-8 here
+  set encoding=utf-8          | " we need default UTF-8 encoding to use cool chars as line break and so on (see below)
+  set termencoding=utf-8      | " we just assume that this is supported.
+
+  set fillchars=              | " initialize empty fillchars
+  set listchars=              | " initialize empty listchars
+
+  if &term ==# 'linux'
+    set fillchars+=vert:\│    | " cool vertical split char
+  else
+    set fillchars+=vert:\║    | " cool vertical split char
+  endif
+
+  set fillchars+=fold:\       | "
+  set fillchars+=diff:\       | " a white space gets used here
+
+  set listchars+=extends:»    | " symbols used when using :set list (which displays non-printable chars)
+  set listchars+=precedes:«   | " symbols used when using :set list (which displays non-printable chars)
+
+  set listchars+=tab:▏\       | "
+  set listchars+=trail:·      | " symbols used when using :set list (which displays non-printable chars)
+  " set listchars+=eol:↲        | " symbols used when using :set list (which displays non-printable chars)
+  " set listchars+=space:⸳ | " ·      | " symbols used when using :set list (which displays non-printable chars)
+  set showbreak+=›            | " symbol used in the beginning of a wrapped line
+
+  " automatically enter list mode when going in insert mode (makes above syntax command temporarily ineffective)
+  set nolist  
+
+  autocmd InsertEnter *  set list
+  autocmd InsertLeave *  set list&
+
+  autocmd InsertEnter *  set colorcolumn=80,120
+  autocmd InsertLeave *  set colorcolumn&
+  " set fillchars+=stlnc:\―       | "
+end
+
+
+"=======================================================================================================================
+" AUTOCMDs and FileType specific stuff
 "=======================================================================================================================
 if has("autocmd")
   " use the shada/viminfo file to return the cursor to where it was...
@@ -263,23 +274,11 @@ if has("autocmd")
           \ :nnoremap
           \ <leader>=
           \ vat:'<,'>!tidy -xml --wrap 0 --sort-attributes alpha 2>/dev/null<CR>vat=
-
-    if filereadable("/usr/bin/vendor_perl/ack")
-      autocmd FileType c,cpp  set grepprg=/usr/bin/vendor_perl/ack\ --type=cc\ --nogroup\ --column\ $*
-      autocmd FileType c,cpp  set grepformat=%f:%l:%c:%m
-    endif
   augroup END
 endif
 
 " ======================================================================================================================
 augroup CUSTOM_COMMANDS
-  command! Vimls
-        \ call setloclist(0, map(getbufinfo({'buflisted':1}),
-        \ "{'bufnr': v:val.bufnr,
-        \   'lnum': v:val.lnum,
-        \   'text': '='.printf('%*s, % 3d: %s [%s]', winwidth(0) / 2, '', v:val.bufnr, v:val.name, getbufvar(v:val.bufnr, '&buftype')),
-        \   'pattern': 'not loaded'}
-        \ "))
   command! Qfls call setqflist([],'r',{ 'title':'listed buffers', 'items':map(getbufinfo({"buflisted":1}), '{"bufnr":get(v:val,"bufnr"),"lnum":get(v:val,"lnum"),"module":printf("%-*s",winwidth(0)-4,fnamemodify(get(v:val,"name"),":t"))}') })
   command! Ctoggle
         \ if(get(getqflist({'winid':1}), 'winid') == win_getid())|cclose|else|botright copen|endif
@@ -304,16 +303,14 @@ augroup KEYBOARD_MAPPING
   nnoremap <S-PageUp>    :N<CR>
   nnoremap <S-PageDown>  :n<CR>
 
-
   nnoremap <F4>          :wincmd c<CR>
-
   nnoremap <F5>          :make!<CR>
   nnoremap <F6>          :silent syntax sync fromstart<CR>:nohlsearch<CR>:silent match<CR>:silent 2match<CR>:silent 3match<CR>
   nnoremap <F7>          :Ltoggle<CR>
   nnoremap <F8>          :Ctoggle<CR>
-
   nnoremap <F9>          :TagbarToggle<CR>
-  nnoremap <F12>         :Vimls<CR>:Ltoggle<CR>
+  "" remap <..>
+  nnoremap <F12>         :Qfls<CR>:Ctoggle<CR>
 
   " close current buffer with <leader>q...
   nnoremap <leader>q           :bp<bar>sp<bar>bn<bar>bd<CR>.
-- 
cgit v1.2.3