Revisión | 47c92fa04bdfe749611ef22e077bc691c162a827 (tree) |
---|---|
Tiempo | 2023-05-09 15:34:22 |
Autor | Markus Prepens <markus.prepens@gmai...> |
Commiter | Markus Prepens |
latest files from Mercurial
@@ -0,0 +1,4 @@ | ||
1 | +setlocal noexpandtab " should be default | |
2 | +setlocal tabstop=4 | |
3 | +setlocal list | |
4 | +setlocal listchars=tab:<->,lead:., |
@@ -0,0 +1,25 @@ | ||
1 | +" TODO | |
2 | +" - cope with engineering units m,k,u,n | |
3 | +" - keep the trailing chars behind result (may be a added comment you want to keep) | |
4 | + | |
5 | +function! s:MarkdownCalcLine() | |
6 | + let equation_orig = substitute(matchstr(getline('.'), '^[^=]*'), '\s\+$', '', 'g') | |
7 | + let b:equation_nospc = substitute(equation_orig, '\s\+', '', 'g') | |
8 | + py3 import decimal | |
9 | + py3 b = vim.current.buffer | |
10 | + py3 d = decimal.Decimal(str(eval(b.vars["equation_nospc"]))) | |
11 | + " use str() to avoid float-noise in the significant | |
12 | + py3 b.vars["result"] = d.normalize().to_eng_string() | |
13 | + let replace_line = printf("%s = %s", equation_orig, b:result) | |
14 | + call setline(line("."), replace_line) | |
15 | + unlet b:result | |
16 | + unlet b:equation_nospc | |
17 | +endfunction | |
18 | + | |
19 | +" Buffer-local command | |
20 | +command! -buffer -nargs=0 Calc call <SID>MarkdownCalcLine() | |
21 | + | |
22 | +" Mappings | |
23 | +nnoremap <buffer> <A-CR> <Cmd>Calc<CR> | |
24 | +imap <buffer> <A-CR> <Esc><A-CR> | |
25 | + |
@@ -0,0 +1,45 @@ | ||
1 | +" Preview Markdown as HTML | |
2 | + | |
3 | +let b:markdown_css_file = stdpath("config") .. "\\templates\\simple.css" | |
4 | +if !filereadable(b:markdown_css_file) | |
5 | + let b:markdown_css_file = "" | |
6 | +else | |
7 | + let b:markdown_css_file = " --css=" .. b:markdown_css_file | |
8 | +endif | |
9 | + | |
10 | +let b:markdown_template_file = stdpath("config") .. "\\templates\\template.html" | |
11 | +if !filereadable(b:markdown_template_file) | |
12 | + let b:markdown_template_file = "" | |
13 | +else | |
14 | + let b:markdown_template_file = " --template=" .. b:markdown_template_file | |
15 | +endif | |
16 | + | |
17 | +function! s:OpenHTML() | |
18 | + silent exe "!start" getenv("TEMP") .. g:slash .. expand("%:t") .. ".html" | |
19 | +endfunction | |
20 | + | |
21 | +function! s:ComputeCommand(file) | |
22 | + return "pandoc -f gfm -t html5 --toc --toc-depth=3" | |
23 | + \ .. b:markdown_css_file | |
24 | + \ .. b:markdown_template_file | |
25 | + \ .. " --metadata title=\"" .. expand("%:t:r") .. "\"" | |
26 | + \ .. " -o " .. getenv("TEMP") .. g:slash .. expand("%:t") .. ".html" | |
27 | + \ .. " " .. getenv("TEMP") .. g:slash.."_" .. expand("%:t") | |
28 | +endfunction | |
29 | + | |
30 | +function! s:MakeHTML(...) | |
31 | + if filereadable(expand("%")) | |
32 | + let b:markdown_command = s:ComputeCommand(expand("%")) | |
33 | + let b:markdown_temp_file = getenv("TEMP") .. g:slash .. "_" .. expand("%:t") | |
34 | + silent exe "write!" b:markdown_temp_file | |
35 | + silent exe "bwipeout!" b:markdown_temp_file | |
36 | + lua require"utils.run" | |
37 | + lua RunAsync.start({ command = vim.b.markdown_command, all_silent = true }) | |
38 | + endif | |
39 | +endfunction | |
40 | + | |
41 | +command! -buffer MarkdownOpenPreview call <SID>OpenHTML() | |
42 | +command! -buffer MarkdownUpdatePreview call <SID>MakeHTML() | |
43 | + | |
44 | +autocmd FocusLost <buffer> call s:MakeHTML() | |
45 | + |
@@ -0,0 +1,46 @@ | ||
1 | +" reStructuredText filetype plugin file | |
2 | +" A nice one: Learn RST her http://rst.ninjs.org/ | |
3 | +" Desciption: Preview in HTML | |
4 | + | |
5 | +let b:rst_css_file = stdpath("config") .. "\\templates\\simple.css" | |
6 | +if !filereadable(b:rst_css_file) | |
7 | + let b:rst_css_file = "" | |
8 | +else | |
9 | + let b:rst_css_file = " --css=" .. b:rst_css_file | |
10 | +endif | |
11 | + | |
12 | +let b:rst_template_file = stdpath("config") .. "\\templates\\template.html" | |
13 | +if !filereadable(b:rst_template_file) | |
14 | + let b:rst_template_file = "" | |
15 | +else | |
16 | + let b:rst_template_file = " --template=" .. b:rst_template_file | |
17 | +endif | |
18 | + | |
19 | +function! s:OpenHTML() | |
20 | + silent exe "!start" getenv("TEMP") .. g:slash .. expand("%:t") .. ".html" | |
21 | +endfunction | |
22 | + | |
23 | +function! s:ComputeCommand(file) | |
24 | + return "pandoc -f rst -t html5 --toc --toc-depth=3" | |
25 | + \ .. b:rst_css_file | |
26 | + \ .. b:rst_template_file | |
27 | + \ .. " --metadata title=\"" .. expand("%:t:r") .. "\"" | |
28 | + \ .. " -o " .. getenv("TEMP") .. g:slash .. expand("%:t") .. ".html" | |
29 | + \ .. " " .. getenv("TEMP") .. g:slash .. "_" .. expand("%:t") | |
30 | +endfunction | |
31 | + | |
32 | +function! s:MakeHTML(...) | |
33 | + if filereadable(expand("%")) | |
34 | + let b:rst_command = s:ComputeCommand(expand("%")) | |
35 | + let b:rst_temp_file = getenv("TEMP") .. g:slash .. "_" .. expand("%:t") | |
36 | + silent exe "write!" b:rst_temp_file | |
37 | + silent exe "bwipeout!" b:rst_temp_file | |
38 | + lua require"utils.run" | |
39 | + lua RunAsync.start({ command = vim.b.markdown_command, all_silent = true }) | |
40 | + endif | |
41 | +endfunction | |
42 | + | |
43 | +command! -buffer RstOpenPreview call <SID>OpenHTML() | |
44 | +command! -buffer RstUpdatePreview call <SID>MakeHTML() | |
45 | + | |
46 | +autocmd FocusLost <buffer> call <SID>MakeHTML() |
@@ -0,0 +1,129 @@ | ||
1 | +" A Vim color theme | |
2 | +" Maintainer: Markus Prepens | |
3 | + | |
4 | +if exists("syntax_on") | |
5 | + syntax reset | |
6 | +endif | |
7 | + | |
8 | +hi clear | |
9 | +set background=light | |
10 | +let g:colors_name = "multicolor" | |
11 | + | |
12 | + | |
13 | +let s:black = "#1b1f23" | |
14 | +let s:white = "#ffffff" | |
15 | +let s:gray = ["#24292e", "#2f363d", "#444d56", "#586069", "#6a737d", "#959da5", "#d1d5da", "#e1e4e8", "#f6f8fa", "#fafbfc", ] | |
16 | +let s:blue = ["#05264c", "#032f62", "#044289", "#005cc5", "#0366d6", "#2188ff", "#79b8ff", "#c8e1ff", "#dbedff", "#f1f8ff", ] | |
17 | +let s:green = ["#144620", "#165c26", "#176f2c", "#22863a", "#28a745", "#34d058", "#85e89d", "#bef5cb", "#dcffe4", "#f0fff4", ] | |
18 | +let s:yellow = ["#735c0f", "#b08800", "#dbab09", "#f9c513", "#ffd33d", "#ffdf5d", "#ffea7f", "#fff5b1", "#fffbdd", "#fffdef", ] | |
19 | +let s:orange = ["#a04100", "#c24e00", "#d15704", "#e36209", "#f66a0a", "#fb8532", "#ffab70", "#ffd1ac", "#ffebda", "#fff8f2", ] | |
20 | +let s:red = ["#86181d", "#9e1c23", "#b31d28", "#cb2431", "#d73a49", "#ea4a5a", "#f97583", "#fdaeb7", "#ffdce0", "#ffeef0", ] | |
21 | +let s:purple = ["#29134e", "#3a1d6e", "#4c2889", "#5a32a3", "#6f42c1", "#8a63d2", "#b392f0", "#d1bcf9", "#e6dcfd", "#f5f0ff", ] | |
22 | +let s:pink = ["#6d224f", "#99306f", "#b93a86", "#d03592", "#ea4aaa", "#ec6cb9", "#f692ce", "#f9b3dd", "#fedbf0", "#ffeef8", ] | |
23 | + | |
24 | +let Fg = { str -> empty(str) ? "" : "guifg=" .. str } | |
25 | +let Bg = { str -> empty(str) ? "" : "guibg=" .. str } | |
26 | +let Attr = { str -> empty(str) ? "" : "gui=" .. str } | |
27 | +let Cterm = { str -> empty(str) ? "" : "cterm=" .. str } | |
28 | + | |
29 | +" Basics | |
30 | +execute "hi Bold" Fg(s:gray[2]) Attr("bold") | |
31 | +execute "hi Cursor" Fg(s:yellow[8]) Bg(s:blue[2]) | |
32 | +execute "hi CursorLine" Bg(s:gray[8]) Cterm("NONE") | |
33 | +execute "hi CursorLineNr" Fg(s:green[3]) Bg(s:gray[7]) Attr("bold") | |
34 | +execute "hi ErrorMsg" Fg(s:red[3]) Bg(s:red[8]) | |
35 | +execute "hi IncSearch" Fg(s:black) Bg(s:green[7]) Attr("NONE") Cterm("NONE") | |
36 | +execute "hi Italic" Fg(s:gray[2]) Attr("NONE") | |
37 | +execute "hi LineNr" Fg(s:blue[3]) Bg(s:gray[9]) Attr("bold") | |
38 | +execute "hi LineNrAbove" Fg(s:gray[6]) Bg("bg") Attr("bold") | |
39 | +execute "hi LineNrBelow" Fg(s:gray[6]) Bg("bg") Attr("bold") | |
40 | +execute "hi MatchParen" Fg(s:green[4]) Bg(s:green[8]) Attr("bold") | |
41 | +execute "hi ModeMsg" Fg(s:gray[2]) Bg("bg") | |
42 | +execute "hi NonText" Fg(s:blue[6]) Bg(s:white) | |
43 | +execute "hi Normal" Fg(s:gray[3]) Bg(s:white) Attr("NONE") | |
44 | +execute "hi Pmenu" Fg(s:purple[3]) Bg(s:purple[7]) Attr("NONE") | |
45 | +execute "hi PmenuSbar" Fg(s:gray[3]) Bg(s:gray[8]) | |
46 | +execute "hi PmenuSel" Fg(s:purple[8]) Bg(s:purple[4]) Attr("NONE") | |
47 | +execute "hi PmenuThumb" Fg(s:blue[2]) Bg(s:gray[0]) | |
48 | +execute "hi Question" Fg(s:orange[3]) Bg(s:orange[8]) | |
49 | +execute "hi QuickFixLine" Fg(s:blue[3]) Bg(s:gray[9]) Attr("NONE") | |
50 | +execute "hi Search" Fg(s:black) Bg(s:yellow[7]) Attr("NONE") | |
51 | +execute "hi CurSearch" Fg(s:black) Bg(s:yellow[5]) Attr("NONE") | |
52 | +execute "hi StatusLine" Fg(s:white) Bg(s:purple[3]) Attr("NONE") Cterm("NONE") | |
53 | +execute "hi StatusLineNC" Fg(s:gray[2]) Bg(s:gray[6]) Attr("NONE") Cterm("NONE") | |
54 | +execute "hi Terminal" Fg(s:green[3]) Bg(s:black) | |
55 | +execute "hi Title" Fg(s:green[3]) | |
56 | +execute "hi User1" Fg(s:white) Bg(s:blue[4]) | |
57 | +execute "hi User2" Fg(s:white) Bg(s:blue[5]) | |
58 | +execute "hi VertSplit" Fg(s:gray[7]) Bg(s:gray[6]) Attr("NONE") | |
59 | +execute "hi Visual" Fg(s:black) Bg(s:blue[8]) | |
60 | +execute "hi WarningMsg" Fg(s:blue[1]) Bg(s:blue[8]) | |
61 | +execute "hi WinBar" Fg(s:purple[3]) Bg(s:purple[8]) Attr("None") | |
62 | +execute "hi qfFileName" Fg(s:blue[4]) | |
63 | +execute "hi qfSeparator" Fg("fg") | |
64 | + | |
65 | +highlight! link CursorColumn CursorLine | |
66 | +highlight! link FoldColumn Normal | |
67 | +highlight! link Folded Normal | |
68 | +highlight! link SignColumn Normal | |
69 | +highlight! link StatusLineTerm StatusLine | |
70 | +highlight! link StatusLineTermNC StatusLineNC | |
71 | +highlight! link TabLineSel StatusLine | |
72 | +highlight! link TabLine StatusLineNC | |
73 | +highlight! link TabLineFill Normal | |
74 | +highlight! link User3 StatusLine | |
75 | +highlight! link User4 StatusLine | |
76 | +highlight! link WildMenu IncSearch | |
77 | +highlight! link qfLineNr LineNr | |
78 | + | |
79 | +" Code | |
80 | +execute "hi Statement" Fg(s:blue[6]) | |
81 | +execute "hi Conditional" Fg(s:blue[3]) Attr("bold") | |
82 | +execute "hi Type" Fg(s:purple[2]) Attr("NONE") | |
83 | +execute "hi Structure" Fg(s:blue[6]) | |
84 | +execute "hi StorageClass" Fg(s:blue[5]) | |
85 | +execute "hi PreProc" Fg(s:blue[3]) Attr("bold") | |
86 | +execute "hi PreCondit" Fg(s:blue[6]) Attr("bold,italic") | |
87 | +execute "hi Define" Fg(s:blue[8]) Attr("bold") | |
88 | +execute "hi Comment" Fg(s:green[4]) | |
89 | +execute "hi Function" Fg(s:blue[4]) Attr("bold") | |
90 | +execute "hi Identifier" Fg(s:purple[3]) | |
91 | +execute "hi Special" Fg(s:green[4]) | |
92 | +execute "hi Constant" Fg(s:pink[3]) | |
93 | +execute "hi Number" Fg(s:purple[3]) | |
94 | +execute "hi Todo" Fg(s:red[4]) Bg(s:red[9]) | |
95 | +execute "hi Error" Fg(s:red[3]) Bg(s:red[8]) | |
96 | +execute "hi Directory" Fg(s:blue[3]) Attr("underline") | |
97 | + | |
98 | +" Filetype C | |
99 | +execute "hi cCppOut" Fg(s:gray[3]) | |
100 | +execute "hi cCppOutIf2" Fg(s:gray[3]) | |
101 | +execute "hi cParen" Fg(s:gray[3]) | |
102 | +execute "hi cBlock" Fg(s:gray[3]) | |
103 | + | |
104 | +" filetype HTML | |
105 | +execute "hi htmlH1" Fg(s:green[3]) Attr("bold") | |
106 | +execute "hi htmlH2" Fg(s:green[3]) Attr("bold") | |
107 | +execute "hi htmlH3" Fg(s:green[2]) Attr("bold") | |
108 | + | |
109 | +" markdown | |
110 | +execute "hi markdownCode" Fg(s:gray[5]) Bg(s:gray[8]) | |
111 | +execute "hi markdownCodeBlock" Fg(s:gray[2]) | |
112 | +execute "hi markdownUrl" Fg(s:gray[2]) Bg(s:gray[0]) Attr("underline") | |
113 | +execute "hi markdownLinkText" Fg(s:blue[2]) Attr("NONE") | |
114 | + | |
115 | +" restructured text | |
116 | +execute "hi rstEmphasis" Fg(s:green[2]) | |
117 | +execute "hi rstStrongEmphasis" Fg(s:green[2]) Attr("bold") | |
118 | + | |
119 | +" Diffs | |
120 | +execute "hi DiffChange" Fg(s:blue[6]) Bg(s:blue[9]) | |
121 | +execute "hi DiffText" Fg(s:blue[6]) Bg(s:blue[9]) Attr("bold") | |
122 | +execute "hi DiffDelete" Fg(s:red[6]) Bg(s:red[9]) | |
123 | +execute "hi DiffAdd" Fg(s:green[6]) Bg(s:green[9]) Attr("bold") | |
124 | + | |
125 | +unlet Fg | |
126 | +unlet Bg | |
127 | +unlet Attr | |
128 | +unlet Cterm | |
129 | + |
@@ -0,0 +1,42 @@ | ||
1 | +@setlocal enableextensions & python -x %~f0 %* & goto :EOF | |
2 | +### Python code: | |
3 | + | |
4 | +import os | |
5 | +import requests | |
6 | +import zipfile | |
7 | + | |
8 | +unpack_to_start = [ | |
9 | + "pack/unzipped/start/", | |
10 | + "https://github.com/mhinz/vim-signify/archive/refs/heads/master.zip", | |
11 | + "https://github.com/godlygeek/tabular/archive/refs/heads/master.zip", | |
12 | + "https://github.com/aklt/plantuml-syntax/archive/refs/heads/master.zip" | |
13 | + "https://github.com/preservim/tagbar", | |
14 | + ] | |
15 | + | |
16 | +unpack_to_opt = [ | |
17 | + "pack/unzipped/opt/", | |
18 | + "https://github.com/junegunn/vim-easy-align/archive/refs/heads/master.zip", | |
19 | + "https://github.com/lilydjwg/colorizer/archive/refs/heads/master.zip", | |
20 | + ] | |
21 | + | |
22 | +zip_fname = os.getenv("TEMP") + os.sep + "pack_download.zip" | |
23 | +pop_back_dir = os.getcwd() | |
24 | + | |
25 | +def unpack_list(list): | |
26 | + if not os.path.isdir(list[0]): | |
27 | + os.makedirs(list[0]) | |
28 | + print("for base dir {0}".format(list[0])) | |
29 | + for url in list[1:]: | |
30 | + print("get %s" % (url), end = "") | |
31 | + r = requests.get(url) | |
32 | + if os.path.isfile(zip_fname): | |
33 | + os.remove(zip_fname) | |
34 | + open(zip_fname, 'wb').write(r.content) | |
35 | + with zipfile.ZipFile(zip_fname, 'r') as zip_ref: | |
36 | + zip_ref.extractall(list[0]) | |
37 | + print(", unzipped in " + zip_ref.namelist()[0]) | |
38 | + | |
39 | +unpack_list(unpack_to_start) | |
40 | +unpack_list(unpack_to_opt) | |
41 | + | |
42 | +# vim:ft=python: |
@@ -0,0 +1,63 @@ | ||
1 | + | |
2 | +let g:notes_files = [] | |
3 | + | |
4 | +function s:NotesBufferSettings() | |
5 | + setfiletype markdown | |
6 | + nnoremap <buffer> <A-PageDown> <Cmd>call NotesBacklog(+1)<CR> | |
7 | + nnoremap <buffer> <A-PageUp> <Cmd>call NotesBacklog(-1)<CR> | |
8 | +endfunction | |
9 | + | |
10 | +function! NotesToday() | |
11 | + execute "drop" strftime("~/.notes/note-%d-%m-%y.md") | |
12 | + call s:NotesBufferSettings() | |
13 | + let g:notes_files = NotesUpdateBacklog(60) | |
14 | + let g:notes_file_idx = 0 | |
15 | +endfunction | |
16 | + | |
17 | +function! NotesUpdateBacklog(days) | |
18 | + let one_day = 86400 | |
19 | + let now = localtime() | |
20 | + let files = [] | |
21 | + for day in range(0, -a:days, -1) | |
22 | + let file_candidate = expand(strftime("~/.notes/note-%d-%m-%y.md", (now - now % one_day) + (day * one_day ))) | |
23 | + if bufexists(file_candidate) | |
24 | + call add(files, file_candidate) | |
25 | + elseif filereadable(file_candidate) | |
26 | + call add(files, file_candidate) | |
27 | + endif | |
28 | + endfor | |
29 | + return files | |
30 | +endfunction | |
31 | + | |
32 | +function! NotesBacklog(dir) | |
33 | + let one_day = 86400 | |
34 | + let now = localtime() | |
35 | + let g:notes_files = NotesUpdateBacklog(60) | |
36 | + let last_idx = len(g:notes_files) - 1 | |
37 | + | |
38 | + let g:notes_file_idx += a:dir | |
39 | + if g:notes_file_idx <= 0 | |
40 | + echohl WarningMsg | |
41 | + echomsg "-- today --" | |
42 | + echohl None | |
43 | + let g:notes_file_idx = 0 | |
44 | + elseif g:notes_file_idx >= last_idx | |
45 | + echohl WarningMsg | |
46 | + echomsg "-- last --" | |
47 | + echohl None | |
48 | + let g:notes_file_idx = last_idx | |
49 | + endif | |
50 | + try | |
51 | + if bufexists(g:notes_files[g:notes_file_idx]) | |
52 | + execute "buffer" g:notes_files[g:notes_file_idx] | |
53 | + else | |
54 | + execute "drop" g:notes_files[g:notes_file_idx] | |
55 | + endif | |
56 | + call s:NotesBufferSettings() | |
57 | + catch /.*/ | |
58 | + endtry | |
59 | +endfunction | |
60 | + | |
61 | +execute mkdir(expand("~/.notes"), "p") | |
62 | +nnoremap <Leader>n <Cmd>call NotesToday()<CR> | |
63 | + |
@@ -1,4 +1,5 @@ | ||
1 | 1 | require("utils.run") |
2 | +local cvt = require("utils.convert") | |
2 | 3 | |
3 | 4 | -- Find In Files: a grep wrapper |
4 | 5 | rg_glob_patterns = { |
@@ -11,34 +12,39 @@ rg_glob_patterns = { | ||
11 | 12 | cmake = " -tcmake", |
12 | 13 | } |
13 | 14 | |
14 | -function rg_options() | |
15 | +function rg_cmd_options() | |
15 | 16 | local file_pattern = rg_glob_patterns[vim.o.filetype] or " -g *" |
17 | + local file_exclude = "" | |
16 | 18 | local text = " " .. vim.fn.expand("<cword>") |
17 | 19 | |
18 | 20 | vim.g.rg_excludes = vim.g.rg_excludes or { ".*" } |
19 | 21 | vim.g.rg_paths = vim.g.rg_paths or { "." } |
20 | 22 | |
21 | - local file_exclude = "" | |
22 | - for i = 1, #vim.g.rg_excludes do | |
23 | - file_exclude = file_exclude .. " -g !" .. vim.g.rg_excludes[i] | |
24 | - end | |
23 | + file_exclude = "-g !" .. cvt.table_to_string(vim.g.rg_excludes, " -g !") | |
24 | + | |
25 | + return file_pattern .. " " .. file_exclude .. text | |
26 | +end | |
25 | 27 | |
28 | +function rg_cmd_paths() | |
26 | 29 | local search_paths = "" |
27 | - for i = 1, #vim.g.rg_paths do | |
28 | - search_paths = search_paths .. " " .. vim.g.rg_paths[i] | |
30 | + | |
31 | + if type(vim.g.rg_paths) == "table" then | |
32 | + search_paths = cvt.table_to_string(vim.g.rg_paths, " ") | |
33 | + elseif type(vim.g.rg_paths) == "string" then | |
34 | + search_paths = vim.g.rg_paths | |
29 | 35 | end |
30 | 36 | |
31 | - -- Prepare globals strings to store them in session files | |
32 | - -- refer to :help 'sessionoption', globals | |
33 | - vim.g.RgPaths = table.concat(vim.g.rg_paths, " ") | |
34 | - vim.g.RgExcludes = table.concat(vim.g.rg_excludes, " ") | |
35 | - return file_pattern .. file_exclude .. text .. search_paths | |
37 | + return search_paths | |
38 | +end | |
39 | + | |
40 | +function rg_cmd_complete() | |
41 | + return rg_cmd_options() .. " " .. rg_cmd_paths() | |
36 | 42 | end |
37 | 43 | |
38 | 44 | function rg_find_files(str) |
39 | 45 | local options = "" |
40 | 46 | for token in string.gmatch(str, "[^%s]+") do |
41 | - options = options .. " -g " .. token | |
47 | + options = options .. " -g" .. token | |
42 | 48 | end |
43 | 49 | local command = "rg --files --glob-case-insensitive " .. options .. " ." |
44 | 50 | local handle = io.popen(command) |
@@ -48,7 +54,7 @@ function rg_find_files(str) | ||
48 | 54 | |
49 | 55 | vim.cmd("enew") |
50 | 56 | for token in string.gmatch(result, "[^%s]+") do |
51 | - table.insert( matches, token) | |
57 | + table.insert(matches, token) | |
52 | 58 | end |
53 | 59 | vim.api.nvim_buf_set_lines(0, 0, 0, false, matches) |
54 | 60 | vim.api.nvim_buf_set_option(0, "modified", false) |
@@ -57,8 +63,9 @@ end | ||
57 | 63 | function run_rg(options) |
58 | 64 | RunAsync.start({ |
59 | 65 | command = "rg --vimgrep " .. options, |
60 | - live_update = false, | |
61 | - popup_time = nil, | |
66 | + notify_on_exit = "compact", | |
67 | + notify_during_run = false, | |
68 | + redirect_err = true, | |
62 | 69 | regexp = vim.o.grepformat, |
63 | 70 | }) |
64 | 71 | end |
@@ -69,14 +76,14 @@ vim.opt.grepformat = "%f:%l:%c:%m" | ||
69 | 76 | vim.api.nvim_set_keymap( |
70 | 77 | "n", |
71 | 78 | "<Leader>r", |
72 | - ":Rg <C-r>=v:lua.rg_options()<CR><CR>", | |
79 | + ":Rg <C-r>=v:lua.rg_cmd_complete()<CR><CR>", | |
73 | 80 | { noremap = true, silent = true, expr = false } |
74 | 81 | ) |
75 | 82 | |
76 | 83 | vim.api.nvim_set_keymap( |
77 | 84 | "n", |
78 | 85 | "<Leader>R", |
79 | - ":Rg <C-r>=v:lua.rg_options()<CR>", | |
86 | + ":Rg <C-r>=v:lua.rg_cmd_complete()<CR>", | |
80 | 87 | { noremap = true, expr = false } |
81 | 88 | ) |
82 | 89 |
@@ -0,0 +1,8 @@ | ||
1 | + | |
2 | +-- list = vim.api.nvim_list_bufs() | |
3 | +-- for i, buf in ipairs(list) do | |
4 | +-- if vim.api.nvim_buf_is_loaded(buf) | |
5 | +-- and vim.api.nvim_buf_get_var(buf, "&buftype") == "" then | |
6 | +-- print(buf) | |
7 | +-- end | |
8 | +-- end |
@@ -0,0 +1,70 @@ | ||
1 | +require("utils.lookat") | |
2 | + | |
3 | +local function kill_blank_lines() | |
4 | + local save_reg = vim.fn.getreg("/") | |
5 | + | |
6 | + while vim.fn.line(".") > 1 do | |
7 | + next_line = vim.fn.getline(vim.fn.line(".") - 1) | |
8 | + if next_line:match("%S") ~= nil then | |
9 | + break | |
10 | + end | |
11 | + vim.cmd("normal k") | |
12 | + end | |
13 | + | |
14 | + del_line = vim.fn.getline(".") | |
15 | + while del_line:match("%S") == nil do -- and vim.fn.line(".") > vim.fn.line("$") do | |
16 | + vim.cmd("normal dd") | |
17 | + del_line = vim.fn.getline(".") | |
18 | + end | |
19 | + vim.fn.histdel("search", -1) | |
20 | + vim.fn.setreg("/", save_reg) | |
21 | +end | |
22 | + | |
23 | +-- Delete all spaces but one at cursor positon. | |
24 | +local function kill_whitespace() | |
25 | + while LookAtNextChar() == " " do | |
26 | + vim.cmd([[ normal "_xh ]]) | |
27 | + end | |
28 | + while LookAtPrevChar() == " " do | |
29 | + vim.cmd([[ normal "_Xh ]]) | |
30 | + end | |
31 | +end | |
32 | + | |
33 | +-- Kill all whitespace chars around current cursor position | |
34 | +function WhitespaceMelt() | |
35 | + kill_whitespace() | |
36 | + kill_blank_lines() | |
37 | +end | |
38 | + | |
39 | +-- Remove trailing spaces, replace existing tabs with spaces and remove | |
40 | +-- trailing Ctrl-M on each line. The amount of spaces is set by 'tabstop'. This | |
41 | +-- is done by :retab and option 'expandtab'. Do not touch buffers not in Normal | |
42 | +-- mode. | |
43 | +function WhitespaceCleanup() | |
44 | + if vim.bo.modifiable and (vim.fn.mode() == "n") then | |
45 | + local save_view = vim.fn.winsaveview() | |
46 | + local save_reg = vim.fn.getreg("/") | |
47 | + vim.bo.expandtab = true | |
48 | + vim.cmd("silent retab") | |
49 | + vim.cmd("silent %s/\\s\\+$//e") | |
50 | + vim.cmd("silent %s/\\r//e") | |
51 | + vim.fn.histdel("search", -1) | |
52 | + vim.fn.setreg("/", save_reg) | |
53 | + vim.fn.winrestview(save_view) | |
54 | + end | |
55 | +end | |
56 | + | |
57 | +gid_whitespace = vim.api.nvim_create_augroup("GroupMelt", { clear = true }) | |
58 | + | |
59 | +vim.api.nvim_create_autocmd({ "BufWritePost" }, { | |
60 | + group = gid_whitespace, | |
61 | + pattern = { "*.c", "*.h", "*.vim", "*.lua", "*.py", "*.md", "*.txt" }, | |
62 | + callback = WhitespaceCleanup, | |
63 | +}) | |
64 | + | |
65 | +vim.api.nvim_set_keymap( | |
66 | + "n", | |
67 | + "<Leader><Leader>", | |
68 | + ":lua WhitespaceMelt()<CR>", | |
69 | + { silent = true, noremap = true } | |
70 | +) |
@@ -0,0 +1,17 @@ | ||
1 | +# Keep ordered! | |
2 | +AlignConsecutiveAssignments: true | |
3 | +AlignConsecutiveDeclarations: false | |
4 | +AlignConsecutiveMacros: true | |
5 | +AlignEscapedNewlines: Left | |
6 | +AllowShortBlocksOnASingleLine: Never | |
7 | +AllowShortIfStatementsOnASingleLine: false | |
8 | +BreakBeforeBinaryOperators: NonAssignment | |
9 | +BreakBeforeBraces: Allman | |
10 | +ColumnLimit: 0 | |
11 | +FixNamespaceComments: false | |
12 | +IndentCaseLabels: true | |
13 | +IndentWidth: 4 | |
14 | +NamespaceIndentation: None | |
15 | +PointerAlignment: Middle | |
16 | +SortIncludes: false | |
17 | +UseTab: Never |
@@ -0,0 +1,5 @@ | ||
1 | +set guifont=Courier\ Prime:h11 | |
2 | +set linespace=4 | |
3 | + | |
4 | +" make the server public for nvr.bat | |
5 | +NvrHere |
@@ -0,0 +1,30 @@ | ||
1 | +" Options for the Ctags executable | |
2 | +let g:ctags_options = [ "-R", "src", "inc" ] | |
3 | + | |
4 | +" for plugin/rg.vim | |
5 | +let g:rg_paths = [ "src", "inc" ] | |
6 | +let g:rg_excludes = [ "Build" ] | |
7 | + | |
8 | +" Set Ripgrep as grep with project-specific Ripgrep options | |
9 | +"set grepprg=rg\ --vimgrep\ -g\ *.[ch]\ $*\ Software | |
10 | +"set grepformat=%f:%l:%c:%m | |
11 | + | |
12 | +" Look-up path for :find, 'gf' and friends | |
13 | +set path=src,inc/**,inc,, | |
14 | + | |
15 | +" case-sensitive tag search | |
16 | +set tagcase=match | |
17 | + | |
18 | +" Set compiler (sets 'errorformat') and 'makeprg' | |
19 | +compiler gcc | |
20 | +set makeprg=make | |
21 | + | |
22 | +augroup GroupLocal | |
23 | + au! | |
24 | + " Markdown, please | |
25 | + au BufRead *.txt setfiletype markdown | |
26 | + " Remember last state of work | |
27 | + autocmd VimLeave * mksession! .session | |
28 | + " reload in case clang-format has done its job in make | |
29 | + autocmd QuickFixCmdPost * checktime | |
30 | +augroup END |