robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
2f2f434613
master
1" Vim formatting plugin file 2" Language: Java 3" Maintainer: Aliaksei Budavei <0x000c70 AT gmail DOT com> 4" Repository: https://github.com/zzzyxwvut/java-vim.git 5" Last Change: 2024 Sep 26 6 7" Documented in ":help ft-java-plugin". 8if & cp || exists ( "g:loaded_javaformat" ) || exists ( "g:java_ignore_javadoc" ) || exists ( "g:java_ignore_markdown" ) 9finish 10endif 11 12let g: loaded_javaformat = 1 13 14"""" STRIVE TO REMAIN COMPATIBLE FOR AT LEAST VIM 7.0. 15 16function ! javaformat#RemoveCommonMarkdownWhitespace () abort 17if mode () != 'n' 18return 0 19endif 20 21let pattern = '\(^\s*///\)\(\s*\)\(.*\)' 22 23" E121 for v:numbermax before v8.2.2388. 24" E15 for expr-<< before v8.2.5003. 25let common = 0x7fffffff 26let comments = [] 27 28for n in range ( v: lnum , ( v: lnum + v: count - 1 )) 29let parts = matchlist ( getline ( n ), pattern ) 30let whitespace = get ( parts , 2 , '' ) 31let nonwhitespace = get ( parts , 3 , '' ) 32 33if ! empty ( whitespace ) 34let common = min ([ common , strlen ( whitespace )]) 35elseif ! empty ( nonwhitespace ) || empty ( parts ) 36" No whitespace prefix or not a Markdown comment. 37return 0 38endif 39 40call add ( comments , [ whitespace , parts [ 1 ], nonwhitespace ]) 41endfor 42 43let cursor = v: lnum 44 45for line in comments 46call setline ( cursor , join ( line [ 1 :], strpart ( line [ 0 ], common ))) 47let cursor += 1 48endfor 49 50return 0 51endfunction 52 53" See ":help vim9-mix". 54if ! has ( "vim9script" ) 55finish 56endif 57 58def ! g:javaformat#RemoveCommonMarkdownWhitespace(): number 59if mode () != 'n' 60return 0 61endif 62 63const pattern : string = '\(^\s*///\)\(\s*\)\(.*\)' 64var common: number = v:numbermax 65var comments: list<list<string>> = [] 66 67for n in range ( v: lnum , ( v: lnum + v: count - 1 )) 68const parts : list<string> = matchlist(getline(n), pattern) 69const whitespace : string = get(parts,2, '') 70const nonwhitespace : string = get(parts,3, '') 71 72if ! empty ( whitespace ) 73common = min([common, strlen(whitespace)]) 74elseif ! empty ( nonwhitespace ) || empty ( parts ) 75 #No whitespace prefix or not aMarkdown comment. 76return 0 77endif 78 79add (comments, [whitespace, parts[1], nonwhitespace]) 80endfor 81 82var cursor: number = v:lnum 83 84for line in comments 85setline (cursor, join(line[1 :], strpart(line[0], common))) 86cursor += 1 87endfor 88 89return 0 90enddef 91 92" vim: fdm=syntax sw=4 ts=8 noet sta