3
3
" Maintainer: Charles E. Campbell
4
4
" Authors: Charles E. Campbell <[email protected] > - NOSPAM
5
5
" Sylvain Viart ([email protected] )
6
- " Version: 12
7
- " Date: Mar 12 , 2013
6
+ " Version: 13
7
+ " Date: Nov 25 , 2013
8
8
"
9
9
" Quick Setup: {{{1
10
10
" tar -oxvf DrawIt.tar
41
41
if &cp || exists (" g:loaded_DrawIt" )
42
42
finish
43
43
endif
44
- let g: loaded_DrawIt= " v12 "
44
+ let g: loaded_DrawIt= " v13 "
45
45
if v: version < 700
46
46
echohl WarningMsg
47
47
echo " ***warning*** this version of DrawIt needs vim 7.0"
@@ -66,7 +66,7 @@ if !exists("g:drawit_xstrlen")
66
66
endif
67
67
endif
68
68
if ! exists (" g:drawit_mode" )
69
- let g: drawit_mode= ' N' " other options: =S (single-line utf-8 ,cp437) or =D (double-line utf-8 ,cp437)
69
+ let g: drawit_mode= ' N' " other options: =S (single-line utf-* ,cp437) or =D (double-line utf-* ,cp437)
70
70
endif
71
71
if ! exists (" s:saveposn_count" )
72
72
let s: saveposn_count= 0
@@ -84,9 +84,9 @@ fun! DrawIt#DrawItStart(...)
84
84
" call Dfunc("DrawItStart()")
85
85
86
86
if a: 0 > 0
87
- if exists (" bz :di_gfxchr" ) && b: di_gfxchr && (a: 1 == ' S' || a: 1 == ' s' )
87
+ if exists (" b :di_gfxchr" ) && b: di_gfxchr && (a: 1 == ' S' || a: 1 == ' s' )
88
88
DIsngl
89
- elseif exists (" bz :di_gfxchr" ) && b: di_gfxchr && (a: 1 == ' D' || a: 1 == ' d' )
89
+ elseif exists (" b :di_gfxchr" ) && b: di_gfxchr && (a: 1 == ' D' || a: 1 == ' d' )
90
90
DIdbl
91
91
elseif ! exists (" g:drawit_mode" )
92
92
let g: drawit_mode= ' N'
@@ -109,7 +109,7 @@ fun! DrawIt#DrawItStart(...)
109
109
if ! exists (" b:drawit_keep_mouse" )
110
110
let b: drawit_keep_mouse= &mouse
111
111
endif
112
- setlocal mouse = a
112
+ setl mouse = a
113
113
114
114
" DrawItStart: set up DrawIt commands {{{3
115
115
com ! -nargs =1 - range SetBrush <line1> ,<line2> call DrawIt#SetBrush (<q-args> )
@@ -125,10 +125,11 @@ fun! DrawIt#DrawItStart(...)
125
125
if ! exists (" b:di_ellipse" )|let b: di_ellipse = ' *' |endif
126
126
127
127
let b: di_gfxchr= 1
128
- if &enc == ' utf-8'
129
- " Box drawing characters using utf-8
128
+ if &enc == ' utf-8' || & enc == ' utf-16 ' || & enc == " ucs-4 "
129
+ " Box drawing characters using unicode
130
130
" │ ─ ┌ ┐ └ ┘ ┬ ┴ ├ ┤ ┼ ╱ ╲ ╳
131
131
" ║ ═ ╔ ╗ ╚ ╝ ╦ ╩ ╠ ╣ ╬
132
+ " call Decho("box drawing characters using unicode")
132
133
if ! exists (" b:di_Svert" ) |let b: di_Svert = ' │' |endif
133
134
if ! exists (" b:di_Dvert" ) |let b: di_Dvert = ' ║' |endif
134
135
if ! exists (" b:di_Shoriz" ) |let b: di_Shoriz = ' ─' |endif
@@ -155,7 +156,7 @@ fun! DrawIt#DrawItStart(...)
155
156
if ! exists (" b:di_Supleft" ) |let b: di_Supleft = " ╲" |endif " same as Sdownright
156
157
if ! exists (" b:di_Scross" ) |let b: di_Scross = " ╳" |endif
157
158
158
- " Mixed Single-Double utf-8 box drawing characters
159
+ " Mixed Single-Double unicode box drawing characters
159
160
" ╞ ╟ ╡ ╢ ╤ ╥ ╧ ╪ ╫
160
161
if ! exists (" b:di_DhSd" ) |let b: di_DhSd = ' ╤' |endif
161
162
if ! exists (" b:di_DhSu" ) |let b: di_DhSu = ' ╧' |endif
@@ -170,7 +171,7 @@ fun! DrawIt#DrawItStart(...)
170
171
if ! exists (" b:di_SuDh" ) |let b: di_SuDh = ' ╧' |endif
171
172
if ! exists (" b:di_SuDr" ) |let b: di_SuDr = ' ╞' |endif
172
173
173
- " Mixed Single-Double utf-8 box drawing corner characters
174
+ " Mixed Single-Double unicode box drawing corner characters
174
175
" ╒ ╓ ╕ ╖ ╘ ╙ ╛ ╜
175
176
if ! exists (" b:di_cSdDr" )| let b: di_cSdDr= ' ╒' | endif
176
177
if ! exists (" b:di_cDdSr" )| let b: di_cDdSr= ' ╓' | endif
@@ -180,8 +181,10 @@ fun! DrawIt#DrawItStart(...)
180
181
if ! exists (" b:di_cSrDu" )| let b: di_cSrDu= ' ╙' | endif
181
182
if ! exists (" b:di_cDlSu" )| let b: di_cDlSu= ' ╛' | endif
182
183
if ! exists (" b:di_cSlDu" )| let b: di_cSlDu= ' ╜' | endif
184
+
183
185
elseif &enc == ' cp437'
184
186
" Box drawing characters using cp437 (dos)
187
+ " call Decho("box drawing characters using cp437")
185
188
if ! exists (" b:di_Svert" ) |let b: di_Svert = nr2char (179 ) |endif " │
186
189
if ! exists (" b:di_Dvert" ) |let b: di_Dvert = nr2char (186 ) |endif " ║
187
190
if ! exists (" b:di_Shoriz" ) |let b: di_Shoriz = nr2char (196 ) |endif " ─
@@ -231,32 +234,16 @@ fun! DrawIt#DrawItStart(...)
231
234
if ! exists (" b:di_cSrDu" )| let b: di_cSrDu= nr2char (211 )| endif " ╙
232
235
if ! exists (" b:di_cDlSu" )| let b: di_cDlSu= nr2char (190 )| endif " ╛
233
236
if ! exists (" b:di_cSlDu" )| let b: di_cSlDu= nr2char (189 )| endif " ╜
237
+
234
238
else
235
- let b: di_gfxchr= 0
239
+ " call Decho("regular box drawing characters only")
240
+ let b: di_gfxchr = 0
236
241
endif
237
242
238
243
" set up initial DrawIt behavior (as opposed to erase behavior)
239
244
let b: di_erase = 0
240
245
241
- " DrawItStart: option recording {{{3
242
- let b: di_aikeep = &l: ai
243
- let b: di_cinkeep = &l: cin
244
- let b: di_cpokeep = &l: cpo
245
- let b: di_etkeep = &l: et
246
- let b: di_fokeep = &l: fo
247
- let b: di_gdkeep = &l: gd
248
- let b: di_gokeep = &l: go
249
- let b: di_magickeep = &l: magic
250
- let b: di_remapkeep = &l: remap
251
- let b: di_repkeep = &l: report
252
- let b: di_sikeep = &l: si
253
- let b: di_stakeep = &l: sta
254
- let b: di_vekeep = &l: ve
255
- setlocal cpo &vim
256
- setlocal nocin noai nosi nogd sta et ve = all report = 10000
257
- setlocal go -= aA
258
- setlocal fo -= a
259
- setlocal remap magic
246
+ call s: DrawItSaveUserSettings ()
260
247
261
248
" DrawItStart: save and unmap user maps {{{3
262
249
let b: lastdir = 1
@@ -495,7 +482,61 @@ fun! DrawIt#DrawItStop()
495
482
" DrawItStop: restore user map(s), if any {{{3
496
483
call RestoreUserMaps (" DrawIt" )
497
484
498
- " DrawItStop: restore user's options {{{3
485
+ call s: DrawItRestoreUserSettings ()
486
+
487
+ " DrawItStop: DrChip menu support: {{{3
488
+ if has (" gui_running" ) && has (" menu" ) && &go = ~# ' m'
489
+ exe ' menu ' .g: DrChipTopLvlMenu .' DrawIt.Start\ DrawIt<tab>\\di <Leader>di'
490
+ exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Stop\ \ DrawIt'
491
+ exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Toggle\ Erase\ Mode'
492
+ exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Draw\ Arrow'
493
+ exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Draw\ Box'
494
+ exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Draw\ Ellipse'
495
+ exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Draw\ Flood'
496
+ exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Draw\ Line'
497
+ exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Make\ Blank\ Zone'
498
+ exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Append\ Blanks'
499
+ endif
500
+ " call Dret("DrawItStop")
501
+ endfun
502
+
503
+ " ---------------------------------------------------------------------
504
+ " s:DrawItSaveUserSettings: saves user settings, changes them to be safe for DrawIt {{{2
505
+ " Use s:DrawItRestoreUserSettings() to restore.
506
+ fun ! s: DrawItSaveUserSettings ()
507
+ " call Dfunc("s:DrawItSaveUserSettings()")
508
+ " save user settings
509
+ let b: di_aikeep = &l: ai
510
+ let b: di_cedit = &cedit
511
+ let b: di_cinkeep = &l: cin
512
+ let b: di_cpokeep = &l: cpo
513
+ let b: di_etkeep = &l: et
514
+ let b: di_fokeep = &l: fo
515
+ let b: di_gdkeep = &l: gd
516
+ let b: di_gokeep = &l: go
517
+ let b: di_magickeep = &l: magic
518
+ let b: di_remapkeep = &l: remap
519
+ let b: di_repkeep = &l: report
520
+ let b: di_sikeep = &l: si
521
+ let b: di_stakeep = &l: sta
522
+ let b: di_vekeep = &l: ve
523
+
524
+ " change user settings to something safe for DrawIt
525
+ setl cpo &vim
526
+ setl nocin noai nosi nogd sta et ve = all report = 10000
527
+ setl go -= aA
528
+ setl fo -= a
529
+ setl remap magic
530
+ set cedit &
531
+ " call Dret("s:DrawItSaveUserSettings")
532
+ endfun
533
+
534
+ " ---------------------------------------------------------------------
535
+ " s:DrawItRestoreUserSettings: restore user settings {{{2
536
+ fun ! s: DrawItRestoreUserSettings ()
537
+ " call Dfunc("s:DrawItRestoreUserSettings()")
538
+
539
+ " restore user's settings
499
540
let &l: ai = b: di_aikeep
500
541
let &l: cin = b: di_cinkeep
501
542
let &l: cpo = b: di_cpokeep
@@ -522,35 +563,21 @@ fun! DrawIt#DrawItStop()
522
563
unlet b: di_sikeep
523
564
unlet b: di_stakeep
524
565
unlet b: di_vekeep
525
-
526
- " DrawItStop: DrChip menu support: {{{3
527
- if has (" gui_running" ) && has (" menu" ) && &go = ~# ' m'
528
- exe ' menu ' .g: DrChipTopLvlMenu .' DrawIt.Start\ DrawIt<tab>\\di <Leader>di'
529
- exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Stop\ \ DrawIt'
530
- exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Toggle\ Erase\ Mode'
531
- exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Draw\ Arrow'
532
- exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Draw\ Box'
533
- exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Draw\ Ellipse'
534
- exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Draw\ Flood'
535
- exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Draw\ Line'
536
- exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Make\ Blank\ Zone'
537
- exe ' unmenu ' .g: DrChipTopLvlMenu .' DrawIt.Append\ Blanks'
538
- endif
539
- " call Dret("DrawItStop")
566
+ " call Dret("s:DrawItRestoreUserSettings")
540
567
endfun
541
568
542
569
" ---------------------------------------------------------------------
543
570
" DrawIt#SetMode: sets normal, single, double drawing mode, and ensures that DrawIt mode is on {{{2
544
571
fun ! DrawIt#SetMode (mode )
545
572
" call Dfunc("DrawIt#SetMode(mode=".a:mode.")")
546
- if &enc == ' utf-8' || &enc == ' cp437'
573
+ if &enc == ' utf-8' || &enc == ' cp437' || & enc == ' utf-16 ' || & enc == ' ucs-4 '
547
574
let b: di_gfxchr= 1
548
575
else
549
576
let b: di_gfxchr= 0
550
577
endif
551
578
if b: di_gfxchr == 0
552
579
let g: drawit_mode= ' N'
553
- elseif &enc != ' utf-8' && &enc != ' cp437'
580
+ elseif &enc != ' utf-8' && &enc != ' cp437' && & enc != ' utf-16 ' && & enc != ' ucs-4 '
554
581
let g: drawit_mode = ' N'
555
582
let b: di_gfxchr = 0
556
583
elseif a: mode = ~ ' ^[sS]$'
@@ -1851,7 +1878,7 @@ endfun
1851
1878
" s:DrawFatRArrow: ----|> {{{2
1852
1879
fun ! s: DrawFatRArrow ()
1853
1880
" call Dfunc("s:DrawFatRArrow()")
1854
- if g: drawit_mode == ' N' || & enc != ' utf-8 '
1881
+ if g: drawit_mode == ' N' || ! b: di_gfxchr
1855
1882
call s: MoveRight ()
1856
1883
norm! r |
1857
1884
call s: MoveRight ()
@@ -1867,7 +1894,7 @@ endfun
1867
1894
" s:DrawFatLArrow: <|---- {{{2
1868
1895
fun ! s: DrawFatLArrow ()
1869
1896
" call Dfunc("s:DrawFatLArrow()")
1870
- if g: drawit_mode == ' N' || & enc != ' utf-8 '
1897
+ if g: drawit_mode == ' N' || ! b: di_gfxchr
1871
1898
call s: MoveLeft ()
1872
1899
norm! r |
1873
1900
call s: MoveLeft ()
@@ -1885,7 +1912,7 @@ endfun
1885
1912
" |
1886
1913
fun ! s: DrawFatUArrow ()
1887
1914
" call Dfunc("s:DrawFatUArrow()")
1888
- if g: drawit_mode == ' N' || & enc != ' utf-8 '
1915
+ if g: drawit_mode == ' N' || ! b: di_bfxchr
1889
1916
call s: MoveUp ()
1890
1917
norm! r_
1891
1918
call s: MoveRight ()
@@ -1909,7 +1936,7 @@ endfun
1909
1936
" '
1910
1937
fun ! s: DrawFatDArrow ()
1911
1938
" call Dfunc("s:DrawFatDArrow()")
1912
- if g: drawit_mode == ' N' || & enc != ' utf-8 '
1939
+ if g: drawit_mode == ' N' || ! b: di_gfxchr
1913
1940
call s: MoveRight ()
1914
1941
norm! r_
1915
1942
call s: MoveLeft ()
@@ -2068,7 +2095,7 @@ fun! s:Flood()
2068
2095
" call Dfunc("s:Flood()")
2069
2096
2070
2097
let s: bndry = b: di_vert .b: di_horiz .b: di_plus .b: di_upright .b: di_upleft .b: di_cross .b: di_ellipse
2071
- if & enc == ' utf-8 ' || & enc == ' cp437 '
2098
+ if b: di_gfxchr
2072
2099
let s: bndry= s: bndry .b: di_Svert .b: di_Dvert .b: di_Shoriz .b: di_Dhoriz .b: di_Sulcorn .b: di_Dulcorn .b: di_Surcorn .b: di_Durcorn .b: di_Sllcorn .b: di_Dllcorn .b: di_Slrcorn .b: di_Dlrcorn .b: di_Splus .b: di_Dplus .b: di_Sdnplus .b: di_Ddnplus .b: di_Supplus .b: di_Dupplus .b: di_Slplus .b: di_Dlplus .b: di_Srplus .b: di_Drplus .b: di_Supright .b: di_Supleft .b: di_Scross
2073
2100
let s: bndry= s: bndry .b: di_DhSd .b: di_DhSu .b: di_DuSl .b: di_DuSlr .b: di_DuSr .b: di_ShDd .b: di_ShDu .b: di_SuDl .b: di_SuDlr .b: di_SdDh .b: di_SuDh .b: di_SuDr .b: di_cSdDr .b: di_cDdSr .b: di_cDlSd .b: di_cSlDd .b: di_cDrSu .b: di_cSrDu .b: di_cDlSu .b: di_cSlDu
2074
2101
endif
@@ -2364,7 +2391,10 @@ endfun
2364
2391
fun ! s: Strlen (x )
2365
2392
" call Dfunc("s:Strlen(x<".a:x.">")
2366
2393
2367
- if g: drawit_xstrlen == 1
2394
+ if v: version >= 703 && exists (" *strdisplaywidth" )
2395
+ let ret = strdisplaywidth (a: x )
2396
+
2397
+ elseif g: drawit_xstrlen == 1
2368
2398
" number of codepoints (Latin a + combining circumflex is two codepoints)
2369
2399
" (comment from TM, solution from NW)
2370
2400
let ret = strlen (substitute (a: x ,' .' ,' c' ,' g' ))
@@ -2390,11 +2420,7 @@ fun! s:Strlen(x)
2390
2420
2391
2421
else
2392
2422
" at least give a decent default
2393
- if v: version >= 703
2394
- let ret = strdisplaywidth (a: x )
2395
- else
2396
- let ret = strlen (a: x )
2397
- endif
2423
+ let ret = strlen (a: x )
2398
2424
endif
2399
2425
2400
2426
" call Dret("s:Strlen ".ret)
@@ -2588,14 +2614,17 @@ fun! s:DrawLine(x0, y0, x1, y1, horiz)
2588
2614
let y0 = a: y1
2589
2615
let x1 = a: x0
2590
2616
let y1 = a: y0
2617
+ " call Decho("swap points: p0(".x0.",".y0.") p1(".x1.",".y1.")")
2591
2618
else
2592
2619
let x0 = a: x0
2593
2620
let y0 = a: y0
2594
2621
let x1 = a: x1
2595
2622
let y1 = a: y1
2623
+ " call Decho("points: p0(".x0.",".y0.") p1(".x1.",".y1.")")
2596
2624
endif
2597
2625
let dy = y1 - y0
2598
2626
let dx = x1 - x0
2627
+ " call Decho("[dx=x1-x0]=".dx." [dy=y1-y0]=".dy)
2599
2628
2600
2629
if dy < 0
2601
2630
let dy = - dy
@@ -2625,43 +2654,51 @@ fun! s:DrawLine(x0, y0, x1, y1, horiz)
2625
2654
endif
2626
2655
2627
2656
if dx > dy
2628
- " move under x
2657
+ " call Decho("case dx>dy : Δ=".dx.",".dy." step=".stepx.",".stepy)
2629
2658
let char = horiz
2630
2659
call s: SetCharAt (char, x0, y0)
2631
- let fraction = dy - (dx / 2 ) " same as 2*dy - dx
2660
+ let fraction = dy - (dx / 2 ) " same as 2*Δy - Δx
2632
2661
while x0 != x1
2633
2662
let char = horiz
2634
2663
if fraction >= 0
2635
2664
if stepx > 0
2665
+ " call Decho("..case [fraction=".fraction."]≥0 and [stepx=".stepx."]>0: go upleft")
2636
2666
let char = (g: drawit_mode == ' N' )? b: di_upleft : b: di_Supleft
2637
2667
else
2668
+ " call Decho("..case [fraction=".fraction."]≥0 and [stepx=".stepx."]≤0: go upright")
2638
2669
let char = (g: drawit_mode == ' N' )? b: di_upright : b: di_Supright
2639
2670
endif
2640
- let y0 = y0 + stepy
2641
- let fraction = fraction - dx " same as fraction -= 2*dx
2671
+ let y0 = y0 + stepy
2672
+ let fraction = fraction - dx " same as fraction -= 2*Δx
2673
+ " call Decho("....[y0+=stepy]=".y0." [fraction-=dx]=".fraction)
2642
2674
endif
2643
- let x0 = x0 + stepx
2644
- let fraction = fraction + dy " same as fraction = fraction - 2*dy
2675
+ let x0 = x0 + stepx
2676
+ let fraction = fraction + dy " same as fraction = fraction - 2*Δy
2677
+ " call Decho("..[x0+=stepx]=".x0." [fraction-=dy]=".fraction)
2645
2678
call s: SetCharAt (char, x0, y0)
2646
2679
endw
2647
2680
else
2648
- " move under y
2681
+ " call Decho("case dx≤dy : Δ=".dx.",".dy." step=".stepx.",".stepy)
2649
2682
let char = vertline
2650
2683
call s: SetCharAt (char, x0, y0)
2651
2684
let fraction = dx - (dy / 2 )
2652
2685
while y0 != y1
2653
2686
let char = (g: drawit_mode == ' N' )? b: di_vert : ((g: drawit_mode == ' S' )? b: di_Svert : b: di_Dvert )
2654
2687
if fraction >= 0
2655
- if stepy > 0 || stepx < 0
2688
+ if stepx > 0
2689
+ " call Decho("..case [fraction=".fraction."]≥0 and [stepx=".stepx."]>0: go upleft")
2656
2690
let char = (g: drawit_mode == ' N' )? b: di_upleft : b: di_Supleft
2657
2691
else
2692
+ " call Decho("..case [fraction=".fraction."]≥0 and [stepx=".stepy."]≤0: go upright")
2658
2693
let char = (g: drawit_mode == ' N' )? b: di_upright : b: di_Supright
2659
2694
endif
2660
- let x0 = x0 + stepx
2695
+ let x0 = x0 + stepx
2661
2696
let fraction = fraction - dy
2697
+ " call Decho("....[x0+=stepx]=".x0." [fraction-=dy]=".fraction)
2662
2698
endif
2663
- let y0 = y0 + stepy
2699
+ let y0 = y0 + stepy
2664
2700
let fraction = fraction + dx
2701
+ " call Decho("..[y0+=stepy]=".y0." [fraction-=dy]=".fraction)
2665
2702
call s: SetCharAt (char, x0, y0)
2666
2703
endw
2667
2704
endif
0 commit comments