From 3355282d8c651fa4e8cf4c819095e47b9fb4bfeb Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Mon, 5 Oct 2009 17:01:38 +0100 Subject: [PATCH] Signs tidyup. Maintain a list of signs and (un)define them dynamically. We don't have arrays in Vim 6 so use some string trickery for this. Place signs in a loop and replace Prep_Signs() with calls to Prep_Sign() within the sign loop. --- .vimrc | 210 ++++++++++++++++++++------------------------------------- 1 file changed, 73 insertions(+), 137 deletions(-) diff --git a/.vimrc b/.vimrc index 21a9d0f..21de57f 100644 --- a/.vimrc +++ b/.vimrc @@ -650,33 +650,6 @@ fun! Prep_Sign(sign) "{{{2 endif endfun "}}}2 -fun! Prep_Signs() "{{{2 - call Prep_Sign("dot") - call Prep_Sign("dash") - call Prep_Sign("quote") - call Prep_Sign("caret") - call Prep_Sign("less") - call Prep_Sign("greater") - call Prep_Sign("left") - call Prep_Sign("right") - call Prep_Sign("squareleft") - call Prep_Sign("squareright") - call Prep_Sign("braceleft") - call Prep_Sign("braceright") - call Prep_Sign("a") - call Prep_Sign("b") - call Prep_Sign("c") - call Prep_Sign("d") - call Prep_Sign("e") - call Prep_Sign("f") - call Prep_Sign("A") - call Prep_Sign("B") - call Prep_Sign("C") - call Prep_Sign("D") - call Prep_Sign("E") - call Prep_Sign("F") -endfun! "}}}2 - fun! Place_Sign(number, line, old, name) "{{{2 if a:line == a:old return a:old @@ -693,33 +666,30 @@ fun! Highlight_Signs(...) "{{{2 return endif - call Prep_Signs() - - let b:signdot = Place_Sign(0, line("'."), b:signdot, "MarkDot") - let b:signdash = Place_Sign(1, line("''"), b:signdash, "MarkDash") - let b:signquote = Place_Sign(2, line("'\""), b:signquote, "MarkQuote") - let b:signcaret = Place_Sign(3, line("'^"), b:signcaret, "MarkCaret") - let b:signless = Place_Sign(4, line("'<"), b:signless, "MarkLess") - let b:signgreater = Place_Sign(5, line("'>"), b:signgreater, "MarkGreater") - let b:signleft = Place_Sign(6, line("'("), b:signleft, "MarkLeft") - let b:signright = Place_Sign(7, line("')"), b:signright, "MarkRight") - let b:signsquareleft = Place_Sign(8, line("'["), b:signsquareleft, "MarkSquareLeft") - let b:signsquareright = Place_Sign(9, line("']"), b:signsquareright, "MarkSquareRight") - let b:signbraceleft = Place_Sign(10, line("'{"), b:signbraceleft, "MarkBraceLeft") - let b:signbraceright = Place_Sign(11, line("'}"), b:signbraceright, "MarkBraceRight") - - let b:signa = Place_Sign(12, line("'a"), b:signa, "Marka") - let b:signb = Place_Sign(13, line("'b"), b:signb, "Markb") - let b:signc = Place_Sign(15, line("'c"), b:signc, "Markc") - let b:signd = Place_Sign(16, line("'d"), b:signd, "Markd") - let b:signe = Place_Sign(17, line("'e"), b:signe, "Marke") - let b:signf = Place_Sign(18, line("'f"), b:signf, "Markf") - let b:signA = Place_Sign(19, line("'A"), b:signA, "MarkA") - let b:signB = Place_Sign(20, line("'B"), b:signB, "MarkB") - let b:signC = Place_Sign(21, line("'C"), b:signC, "MarkC") - let b:signD = Place_Sign(22, line("'D"), b:signD, "MarkD") - let b:signE = Place_Sign(23, line("'E"), b:signE, "MarkE") - let b:signF = Place_Sign(24, line("'F"), b:signF, "MarkF") + let l:signs = g:iainsigns + let l:sign = "" + let l:i = 0 + while strlen(l:signs) + let l:sign = matchstr(l:signs, '^[A-Za-z]\+\(:.\)*[.=-][^ ]\+') + + let l:name = substitute(l:sign, '[:.=-].*', "", "") + let l:var = tolower(l:name) + let l:sign = substitute(l:sign, '^[A-Za-z]\+', "", "") + let l:ascii = matchstr(l:sign, '^:.') + let l:mark = substitute(l:sign, '^\(:.\)*[.-=]', "", "") + if strlen(l:ascii) + let l:ascii = substitute(l:ascii, '^:', "", "") + else + let l:ascii = l:mark + endif + let l:ascii = substitute(l:ascii, '"', '\\"', "") + + call Prep_Sign(l:var) + exe "let " . l:var . " = Place_Sign(" . l:i . ", line(\"'" . l:ascii . "\"), b:sign" . l:var . ", \"Mark" . l:name . "\")" + let l:i = l:i + 1 + + let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "") + endwhile endfun "}}}2 " Toggle signs. @@ -730,98 +700,64 @@ fun! Cycle_Signs(resize) "{{{2 call Iain_Vars() let g:marksigns = ! g:marksigns - if g:marksigns - " Signs to highlight marks. - " Syntax won't work properly in Vim 6. + " Retrofit arrays on to Vim 6. + if ! exists("g:iainsigns") + " Signs are defined in g:iainsigns. The syntax is as follows: + " + " Sign ::= Name (':' Mark)* Type Symbol + " Type ::= '=' | '-' | '.' + " + " Signs with Type '=' will be highlighted with the MarkSign group. + " Signs with Type '-' will be highlighted with the MarkLine group. + " Signs with Type '.' will be highlighted with the MarkDot group. + " Define the Mark where Symbol is not also the mark name, eg "']". if Has_Unicode() - sign define MarkDash text=’ texthl=MarkSign - sign define MarkDot text=• texthl=MarkDot - sign define MarkQuote text=” texthl=MarkSign - sign define MarkCaret text=ʌ texthl=MarkDot + let g:iainsigns = "Dash:'=’ Dot:..• Quote:\"=” Caret:^.ʌ" else - sign define MarkDash text=' texthl=MarkSign - sign define MarkDot text=* texthl=MarkDot - sign define MarkQuote text=" texthl=MarkSign - sign define MarkCaret text=^ texthl=MarkDot + let g:iainsigns = "Dash=' Dot:..* Quote=\" Caret.^" endif - sign define MarkLess text=< texthl=MarkSign - sign define MarkGreater text=> texthl=MarkSign - sign define MarkLeft text=( texthl=MarkSign - sign define MarkRight text=) texthl=MarkSign - sign define MarkSquareLeft text=[ texthl=MarkSign - sign define MarkSquareRight text=] texthl=MarkSign - sign define MarkBraceLeft text={ texthl=MarkSign - sign define MarkBraceRight text=} texthl=MarkSign - sign define Marka text=a texthl=MarkSign linehl=MarkLine - sign define Markb text=b texthl=MarkSign linehl=MarkLine - sign define Markc text=c texthl=MarkSign linehl=MarkLine - sign define Markd text=d texthl=MarkSign linehl=MarkLine - sign define Marke text=e texthl=MarkSign linehl=MarkLine - sign define Markf text=f texthl=MarkSign linehl=MarkLine - sign define MarkA text=A texthl=MarkSign linehl=MarkLine - sign define MarkB text=B texthl=MarkSign linehl=MarkLine - sign define MarkC text=C texthl=MarkSign linehl=MarkLine - sign define MarkD text=D texthl=MarkSign linehl=MarkLine - sign define MarkE text=E texthl=MarkSign linehl=MarkLine - sign define MarkF text=F texthl=MarkSign linehl=MarkLine + let g:iainsigns = g:iainsigns . " Less=< Greater=> Left=( Right=) SquareLeft=[ SquareRight=] BraceLeft={ BraceRight=} a-a b-b c-c d-d e-e f-f A-A B-B C-C D-D E-E F-F" + endif + + if g:marksigns + " Signs to highlight marks. + " Syntax won't work properly in Vim 6. + let l:signs = g:iainsigns + let l:sign = "" + while strlen(l:signs) + let l:sign = matchstr(l:signs, '^[A-Za-z]\+\(:.\)*[.=-][^ ]\+') + + let l:sign = substitute(l:sign, ':.', "", "") + let l:sign = substitute(l:sign, '=', " texthl=MarkSign text=", "") + let l:sign = substitute(l:sign, '\.', " texthl=MarkDot text=", "") + let l:sign = substitute(l:sign, '-', " texthl=MarkLine text=", "") + + exe "sign define Mark" . l:sign + + let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "") + endwhile if a:resize call Resize_Columns("+", 2) endif call Highlight_Signs() else - exe "sign unplace " . (g:firstsign + 0) - exe "sign unplace " . (g:firstsign + 1) - exe "sign unplace " . (g:firstsign + 2) - exe "sign unplace " . (g:firstsign + 3) - exe "sign unplace " . (g:firstsign + 4) - exe "sign unplace " . (g:firstsign + 5) - exe "sign unplace " . (g:firstsign + 6) - exe "sign unplace " . (g:firstsign + 7) - exe "sign unplace " . (g:firstsign + 8) - exe "sign unplace " . (g:firstsign + 9) - exe "sign unplace " . (g:firstsign + 10) - exe "sign unplace " . (g:firstsign + 11) - exe "sign unplace " . (g:firstsign + 12) - exe "sign unplace " . (g:firstsign + 13) - exe "sign unplace " . (g:firstsign + 14) - exe "sign unplace " . (g:firstsign + 15) - exe "sign unplace " . (g:firstsign + 16) - exe "sign unplace " . (g:firstsign + 17) - exe "sign unplace " . (g:firstsign + 18) - exe "sign unplace " . (g:firstsign + 19) - exe "sign unplace " . (g:firstsign + 20) - exe "sign unplace " . (g:firstsign + 21) - exe "sign unplace " . (g:firstsign + 22) - exe "sign unplace " . (g:firstsign + 23) - exe "sign unplace " . (g:firstsign + 24) - - sign undefine MarkDash - sign undefine MarkDot - sign undefine MarkQuote - sign undefine MarkCaret - sign undefine MarkLess - sign undefine MarkGreater - sign undefine MarkLeft - sign undefine MarkRight - sign undefine MarkSquareLeft - sign undefine MarkSquareRight - sign undefine MarkBraceLeft - sign undefine MarkBraceRight - sign undefine Marka - sign undefine Markb - sign undefine Markc - sign undefine Markd - sign undefine Marke - sign undefine Markf - sign undefine MarkA - sign undefine MarkB - sign undefine MarkC - sign undefine MarkD - sign undefine MarkE - sign undefine MarkF - - call Prep_Signs() + let l:i = 0 + while l:i < 25 + exe "sign unplace " . (g:firstsign + l:i) + let l:i = l:i + 1 + endwhile + + let l:signs = g:iainsigns + let l:sign = "" + while strlen(l:signs) + let l:sign = matchstr(l:signs, '^[A-Za-z]\+') + + exe "sign undefine Mark" . l:sign + call Prep_Sign(tolower(l:sign)) + let l:signs = substitute(l:signs, '^[^ ]\+ *', "", "") + endwhile + if a:resize call Resize_Columns("-", 2) endif -- 2.20.1