添付ファイルの情報



[添付ファイル一覧] [全ページの添付ファイル一覧]

filesnipet.mac.js
格納ファイル名:attach/4D6163726F2FC5EAB9C62F313839_736E697065742E6D61632E6A73
ページ:Macro/投稿/189
格納ファイル名:attach/4D6163726F2FC5EAB9C62F313839_736E697065742E6D61632E6A73
MD5ハッシュ値:89b3b75dc0f22c6bfbe37979a48340df
サイズ:59.3KB (60718 bytes)
Content-type:application/octet-stream
登録日時:2010/04/25 20:29:59
アクセス数:687
MD5ハッシュ値:89b3b75dc0f22c6bfbe37979a48340df
filesnipet.mac.js
   0
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
// snipet.js
// SakuraEditor JScript macro
//   sakura 1.5.5.0 以上
// コード補完用スニペット/コマンダー
// Copyright (c) 2010 Moca. All right reserved.
//
// Shift+EnterかAlt+Enterあたりに割り当てるなどして利用してください。
 
function main()
{
    try{
        debug.setTrace(false);
        InsConvertSnipett();
    }catch(e){
        debug.traceFlash();
        throw e;
    }
    debug.traceFlash();
}
 
var snipetjs = {};
snipetjs.VER_STR = "00_00_2010021802";
snipetjs.STR_COPYRIGHT = "Copyright (c) 2010 Moca. All right reserved.";
 
// コマンド識別用マークを指定します。
// マクロ実行行のもっとも右側にあるマークがコマンドとして識別されます。
// snipetjs.CommandMark = [':', ';', '@'];
// :;@の場合、「 :first test@example」   => @example になります。
snipetjs.CommandMark = [':'];
 
// マークの直前が以下の文字列に一致する場合、マークとして処理せずさらに左側を探します。
// 入力文字列は、行頭からマークまでです。
snipetjs.CommandPrevIgnoreRe = [
    /((http(s))|(ftp)):$/i,
    /(TODO|FIXME):$i/i
];
 
// ファイル名に部分一致するnameFilter:がある場合にそのtypes:で指定したsnip.type(+ALL)のみ実行します。
// extSupListの上から順に探して、最初に一致した定義のみ有効です。
// これにより同じsnip.keyでも拡張子ごとなどに違うコードを呼び出せます。
// snipの一致はtypesの定義順(左側から)で探します。
// 色々定義してありますが、snip自体は定義していません。
snipetjs.extSupList = [
    // extSup のリスト
    // nameFilter: 小文字で書いてください。末尾は|で指定できます。
    // types: snipet.typeを|で区切って並べてください
    {nameFilter:'\\snipet.mac.js|', types:'snipet|skr-mac|js|cF'},
    {nameFilter:'.mac.js|',     types:'skr-mac|wsh-js|js|cF'},
    {nameFilter:'.mac.vbs|',    types:'skr-mac|wsh-vbs|vbs'},
    {nameFilter:'.mac|',        types:'skr-mac'},
    {nameFilter:'.ppa|',        types:'skr-mac|ppa'},
    {nameFilter:'.txt|',        types:'text'},
 
    {nameFilter:'.htm|',        types:'html|css|js|xmlF|xhtml'},
    {nameFilter:'.html|',       types:'html|css|js|xmlF|xhtml'},
    {nameFilter:'.xhtml|',      types:'xhtml|xml|xmlF|css|js|html'},
    {nameFilter:'.css|',        types:'css'},
    {nameFilter:'.json|',       types:'json|js'},
    {nameFilter:'.js|',         types:'js|json|cF|html|css'},
 
    {nameFilter:'.bat|',        types:'bat'},
    {nameFilter:'.cmd|',        types:'bat'},
    {nameFilter:'.vbs|',        types:'wsh-vbs|vbs|'},
//	{nameFilter:'wsh.js|',      types:'wsh-js|js|cF},
    {nameFilter:'.pls|',        types:'wsh-pls|perls|perl'},
 
    {nameFilter:'.c|',          types:'c|cF'},
    {nameFilter:'.cpp|',        types:'cpp|c|cF'},
    {nameFilter:'.cxx|',        types:'cpp|c|cF'},
    {nameFilter:'.h|',          types:'c|cpp|cF'},
    {nameFilter:'.rc|',         types:'rc'},
    {nameFilter:'.cs|',         types:'cs|cF'},
    {nameFilter:'.vb|',         types:'vbnet|vb'},
    {nameFilter:'.xaml|',       types:'xamlxmlF'},
 
    {nameFilter:'.java|',       types:'java|cF'},
    {nameFilter:'.jav|',        types:'java|cF'},
    {nameFilter:'.pl|',         types:'perl'},
    {nameFilter:'.rb|',         types:'ruby'},
    {nameFilter:'.py|',         types:'python'},
    {nameFilter:'.as|',         types:'ascript|ecma4s|js|cF'},
    {nameFilter:'.mxml|',       types:'mxml|xmlF'},
//	{nameFilter:'.as|',         types:'hsp'},
    {nameFilter:'.hsp|',        types:'hsp'},
 
    {nameFilter:'.shtml|',      types:'html|css|js'},
    {nameFilter:'.shm|',        types:'html|css|js'},
    {nameFilter:'.cgi|',        types:'perl|html|css|js'},
    {nameFilter:'.jsp|',        types:'jsp|java|cF|html|css|js'},
    {nameFilter:'.php|',        types:'php|html|css|js'},
    {nameFilter:'.asp|',        types:'asp|html|css|js'},
    {nameFilter:'.aspx|',       types:'vbaspx|html|css|js'},
//	{nameFilter:'.aspx|',       types:'csaspx|html|css|js'},
 
    {nameFilter:'.yaml|',       types:'yaml'},
    {nameFilter:'.yml|',        types:'yaml'},
    {nameFilter:'.sql|',        types:'sql'},
 
    {nameFilter:'.xml|',        types:'xhtml|mathml|svg|xml|xmlF'},
//	{nameFilter:'.xml|',        types:'xml|xmlF'},
//	{nameFilter:'.rss|',        types:'rss|xml|xmlF'},
//	{nameFilter:'.rdf|',        types:'rss|xml|xmlF'},
    {nameFilter:'.svg|',        types:'svg|xml|xmlF'},
//	{nameFilter:'.svgg|',       types:'svg|xml|xmlF'},
    {nameFilter:'.xsd|',        types:'xsd|xml|xmlF'},
    {nameFilter:'.mml|',        types:'mathml|xml|xmlF'},
    {nameFilter:'.xsl|',        types:'xslt|xml|xmlF'},
    {nameFilter:'.xslt|',       types:'xslt|xml|xmlF'},
//	{nameFilter:'.dtd|',        types:'xmldtd|sgmldtd|xmlF'},
 
    {nameFilter:'.bash|',       types:'bash'},
    {nameFilter:'.sh|',         types:'shell'},
 
    {nameFilter:'.mak|',        types:'make'},
    {nameFilter:'\\makefile|',  types:'make'},
    {nameFilter:'\\readme|',    types:'txt'},
    {nameFilter:'\\license|',   types:'txt'},
    {nameFilter:'||',           types:'NONE'}
    // ここに追加する場合は行末の,に注意。上優先にも注意
];
 
// 未定義のフィルターの場合、デフォルトはALLのみ
snipetjs.DefaultTypes = ['ALL'];
 
// ファイルが未保存(無題)の場合、デフォルトはnull = すべてのタイプ
snipetjs.UnSaveDocTypes = null;
 
// コマンド対応表です。
snipetjs.snipBuiltInList = [
    // 現在の制限:未実装 argl,argm   bakは必ず1 @@@は必ず処理される。
    // 仕様:
    //           改行は\nを指定します。出力時に、エディタの設定に従い変換します
    // tx @@@以外は使用できません。その代わり軽いです。$$も処理されません。
    // tr $${t}: コマンド実行行の行頭のスペース・タブ部分
    //    $${1}: コマンドの引数1番目
    //    $${2}: コマンドの引数2番目 ...argm番目まで。引数がない場合は""に置換されます
    //    $${a}: ..$${1}におなじ(本来はtm用)
    // tm reps:
    //      trおよび $${a} $${a+1} $${a+2} $${a-1} $${a-2}...
    //      repf 1つめのメタ文字で消費するiの数を指定します
    //      repe 最後のメタ文字で消費するiの数を指定します
    //           (引数の数 - repf - repe) = 真ん中のループ数です。
    //           repsが4つ以上の配列の場合、先頭と最後以外をループします。
    //        repf:1, repe:1 reps:['A$${a}','B$${a}','C$${a}']      #:cmd 1 2 3 4 => A1B2B3C4
    //        repf:1, repe:0 reps:['A$${a}','B$${a}','C']           #:cmd 1 2 3 4 => A1B2B3B4C
    //        repf:0, repe:1 reps:['A','B$${a}','C$${a}']           #:cmd 1 2 3 4 => AB1B2B3C4
    //        repf:1, repe:1 reps:['A','B$${a}', 'C$${a}','D$${a}'] #:cmd 1 2 3 4 5 6 => A1B2C3B4C5D6
    //  内蔵関数も指定できますが、暫定です。変更されるかもしれません。
    //  関数内ではエスケープが有効です。  $< = {  $> = }  $t =       $s = ' ' $h = /  $n = \n  $d = $
    //  imp_func_meta_rep を見てください。
    //    lc<NUM>{STR}   A$$lc5{1234567}B => A12345B    A$$lc5{1234}B     => A1234B
    //    rc<NUM>{STR}   A$$rc5{1234567}B => A54567B    A$$rc5{1234}B     => A1234B
    //    lp<NUM>{PSTR}  A$$lp5{1234567}B => A1234567B  A$$lp5{@123}B     => A123@@B
    //    rp<NUM>{PSTR}  A$$rp5{1234567}B => A1234567B  A$$rp5{@123}B     => A@@123B
    //    ll<NUM>{PSTR}  A$$ll5{1234567}B => A12345B    A$$ll5{@123}B     => A123@@B
    //    rl<NUM>{PSTR}  A$$rl5{1234567}B => A45678B    A$$rl5{@123}B     => A@@123B
    //    cl{STR}        A$$cl{STRstr}  => strstr
    //    cu{STR}        A$$cu{STRstr}  => STRSTR
    //    ct{STR}        A$$ct{STRstr}  => Strstr
    //    s<NUK>{STR}    A$$s4{STR}     => STRSTRSTRSTR
    //    eu{STR}        A$$eu{STR}     => 
    //    euc{STR}       A$$euc{STR}    => 
    //    du{STR}        A$$du{STR}     => 
    //    duc{STR}       A$$duc{STR}    => 
    //    eq{STR}        A$$eq{ESCSTR}  => ESCSTR
    //    ev{STR}        A$$ev{METASTR} => METASTR
    //    ej{STR}        A$$ej{0|"STR" + 2 * 4 + s}  =>ASTR80
    //             名前(コマンド名)引数最小/最大 戻る0しない/1@@@  置換種類, tr-文字列 tm-ループ付き文字列, fn関数実行 tx指定文字列をそのまま
//SNIPET_AUTO_CONFIG_BEGIN
    { type:"js",    key:"fn",       argl:0, argm:20, bak:1, rept:"tm", repv: {repf:2, repe:0, reps:["function $${1}($${2}", ", $${a}", "){\n$${t}\t@@@\n$${t}}\n"]}, help:"function定義引数付"},
    { type:"js",    key:"var",      argl:1, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["var $${1}", ", $${a}", ";\n"]}, help:"<変数名...>: var x;"},
    { type:"js",    key:"vari",     argl:1, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["var $${1}=0", ", $${a}=0", ";\n"]}, help:"<変数名...>: var n=0;"},
    { type:"js",    key:"vars",     argl:1, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["var $${1}=\"\"", ", $${a}=\"\"", ";\n"]}, help:"<変数名...>: var s=\"\";"},
    { type:"js",    key:"vara",     argl:1, argm:20, bak:1, rept:"tm", repv: {repf:2, repe:0, reps:["var $${1}=[$${2}", ", $${a}", "];\n"]}, help:"<変数名> [配列要素*]: var a=[];"},
    { type:"js",    key:"varo",     argl:1, argm:20, bak:1, rept:"tm", repv: {repf:2, repe:0, reps:["var $${1}={$${2}", ", $${a}", "};\n"]}, help:"<変数名> [名前値対*]: var o={};"},
    { type:"json",  key:"arr",      argl:0, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["[$${1}", ", $${a}", "]\n"]}, help:"[配列要素*]: [] / [a, b, .. n]"},
    { type:"json",  key:"obj",      argl:0, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["{$${1}", ", $${a}", "}\n"]}, help:"[名前値対*]: {} / {a, b, .. n}"},
    { type:"json",  key:"objv",     argl:1, argm:20, bak:1, rept:"tm", repv: {repf:2, repe:0, reps:["{\"$${2}\": $${1}", ", \"$${a}\": $${1}", "}\n"]}, help:"<v> [名前リスト*]: {\"a\": v, \"b\": v, ..\"n\": v}"},
    { type:"cF",    key:"if",       argl:0, argm:0,  bak:1, rept:"tr", repv: "if( @@@ ){\n$${t}\t\n$${t}}\n",  help:"if文空定義"},
    { type:"cF",    key:"ifelse",   argl:0, argm:0,  bak:1, rept:"tr", repv: "if( @@@ ){\n$${t}\t\n$${t}}else{\n$${t}}\n",  help:"if,else文空定義"},
    { type:"cF",    key:"ifelseif", argl:0, argm:0,  bak:1, rept:"tr", repv: "if( @@@ ){\n$${t}\t\n$${t}}else if(  ){\n$${t}}\n",  help:"if,else if文空定義"},
    { type:"cF",    key:"if",       argl:1, argm:10, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:[ "if( $${1}", " $${a}", " ){\n$${t}\t@@@\n$${t}}\n"]},  help:"if文"},
    { type:"cF",    key:"ifelse",   argl:1, argm:10, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:[ "if( $${1}", " $${a}", " ){\n$${t}\t@@@\n$${t}}else{\n$${t}}\n"]},  help:"if,else文"},
    { type:"cF",    key:"ifelseif", argl:1, argm:10, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:[ "if( $${1}", " $${a}", " ){\n$${t}\t@@@\n$${t}}else if(  ){\n$${t}}\n"]},  help:"if,else if文"},
    { type:"cF",    key:"for",      argl:0, argm:0,  bak:1, rept:"tr", repv: "for( @@@; ; ){\n$${t}\t\n$${t}}\n",  help:"for文空定義"},
    { type:"cF",    key:"loopn",    argl:2, argm:2,  bak:1, rept:"tr", repv: "for( $${1} = 0; $${1} < $${2}; ++$${1} ){\n$${t}\t@@@\n$${t}}\n",  help:"<ループ変数> <ループ回数>:昇順ループ for(a=0;a<b;++a){}"},
    { type:"cF",    key:"loopr",    argl:2, argm:2,  bak:1, rept:"tr", repv: "for( $${1} = $${2}; 0 <= $${1}; --$${1} ){\n$${t}\t@@@\n$${t}}\n", help:"<ループ変数> <ループ回数>:降順ループ for(a=b;0<=a;--a)}{}"},
    { type:"cF",    key:"while",    argl:1, argm:10, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["while ($${1}", " $${a}", "){\n$${t}\t@@@\n$${t}}\n"]}, help:"while(){}"},
    { type:"cF",    key:"switch",   argl:0, argm:1,  bak:1, rept:"tr", repv: "switch( $${1} ){\n$${t}case @@@:\n$${t}\tbreak;\n$${t}default:\n$${t}\tbreak;\n$${t}\t\n$${t}}\n", help:"[switch-var] swich case template"},
    { type:"cF",    key:"switch",   argl:2, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["switch(@@@$${1}){\n", "$${t}case $${a}:\n$${t}\tbreak;\n", "$${t}default:\n$${t}\tbreak;\n$${t}\t\n$${t}}\n"]}, help:"<swich-var> [case-vales*]: swich cases"},
    { type:"cF",    key:"switchn",  argl:1, argm:1,  bak:1, rept:"tr", repv: "switch( @@@ ){\n$$ev{$$eq{$d$ds$${1}{$${t}case :\n$${t}\tbreak;\n}}}$${t}default:\n$${t}\tbreak;\n$${t}}\n", help:"<swich-var> [case-vales*]: swich cases"},
    { type:"cF",    key:"do",       argl:0, argm:1,  bak:1, rept:"tr", repv: "do{\n$${t}\t@@@\n$${t}}while( );\n", help:"do while" },
    { type:"cF",    key:"{",        argl:0, argm:0,  bak:1, rept:"tr", repv: "{\n$${t}\t@@@\n$${t}}\n", help:"{}補完"},
    { type:"c",     key:"template", argl:0, argm:0,  bak:1, rept:"tr", repv: "#include <stdio.h>\n#include <stdlib.h>\n\nint main(int argc, char **argv){\n\t@@@\n\treturn 0;\n}\n", help:"C mainテンプレート"},
    { type:"cpp",   key:"class",    argl:1, argm:1,  bak:1, rept:"tr", repv: "class $${1}\n$${t}{\n$${t}public:\n$${t}\t$${1}();\n$${t}\t~$${1}();\n$${t}\t@@@\n$${t}private:\n$${t}};\n", help:"class "},
    { type:"cpp",   key:"class",    argl:2, argm:2,  bak:1, rept:"tr", repv: "class $${1}: $${2}\n$${t}{\n$${t}public:\n$${t}\t$${1}();\n$${t}\t~$${1}();\n$${t}\t@@@\n$${t}private:\n$${t}};\n", help:"class "},
    { type:"psF",   key:"begin",    argl:0, argm:0,  bak:1, rept:"tr", repv: "begin\n$${t}\t@@@\n$${t}end\n", help:"begin end補完"},
    { type:"psF",   key:"Begin",    argl:0, argm:0,  bak:1, rept:"tr", repv: "Begin\n$${t}\t@@@\n$${t}End\n", help:"Begin End補完"},
    { type:"html",  key:"dtd",      argl:0, argm:0,  bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n \"http://www.w3.org/TR/html4/loose.dtd\">\n", help:"DTD HTML HTML 4.01 Transitional" },
    { type:"html",  key:"dtd-401",  argl:0, argm:0,  bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n \"http://www.w3.org/TR/html4/loose.dtd\">\n", help:"DTD HTML HTML 4.01 Transitional" },
    { type:"html",  key:"dtd-401t", argl:0, argm:0,  bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n \"http://www.w3.org/TR/html4/loose.dtd\">\n", help:"DTD HTML HTML 4.01 Transitional" },
    { type:"html",  key:"dtd-401tp",argl:0, argm:0,  bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n", help:"DTD HTML 4.01 Transitional(PUBLIC only)" },
    { type:"html",  key:"dtd-401s", argl:0, argm:0,  bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n", help:"DTD HTML 4.01 Strict" },
    { type:"html",  key:"dtd-401sp",argl:0, argm:0,  bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n", help:"DTD HTML 4.01 Strict(PUBLIC only)" },
    { type:"html",  key:"dtd-401f", argl:0, argm:0,  bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">\n", help:"DTD HTML 4.01 Frameset" },
    { type:"html",  key:"dtd-401fp",argl:0, argm:0,  bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\">\n", help:"DTD HTML 4.01 Frameset(PUBLIC only)" },
    { type:"html",  key:"dtd-5",    argl:0, argm:0,  bak:1, rept:"tx", repv: "<!DOCTYPE html>", help:"HTML5 doctype" },
    { type:"xhtml", key:"dtd",      argl:0, argm:0,  bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n", help:"DTD XHTML 1.0 Transitional" },
    { type:"xhtml", key:"dtd-10t",  argl:0, argm:0,  bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n", help:"DTD XHTML 1.0 Transitional" },
    { type:"xhtml", key:"dtd-10s",  argl:0, argm:0,  bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n", help:"DTD XHTML 1.0 Transitional" },
    { type:"xhtml", key:"dtd-10f",  argl:0, argm:0,  bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n", help:"DTD XHTML 1.0 Frameset" },
    { type:"html",  key:"template", argl:0, argm:0,  bak:1, rept:"tx", repv: "<html>\n<head>\n<title>@@@ </title>\n</head>\n<body>\n</body>\n</html>\n", help:"HTML テンプレート" },
    { type:"html",  key:"css",      argl:0, argm:0,  bak:1, rept:"tr", repv: "<link rel=\"stylesheet\" type=\"text/css\" href=\"$${1}@@@.css\">\n", help:"<filename>: link css" },
    { type:"html",  key:"script",   argl:0, argm:0,  bak:1, rept:"tr", repv: "<script type=\"text/javascript\" src=\"@@@$${1}\"></script>\n", help:"<filename>: link js" },
    { type:"html",  key:"br",       argl:2, argm:2,  bak:0, rept:"tx", repv: "<br>\n", help:"HTML改行" },
    { type:"html",  key:"urllink",  argl:1, argm:2,  bak:1, rept:"tr", repv: "<a href=\"$${1}\">@@@$${2}</a>\n", help:"HTML Aリンク作成" },
    { type:"html",  key:"table",    argl:0, argm:0,  bak:1, rept:"tr", repv: "<table>\n$${t}\t<tr><td>@@@</td><td></td></tr>\n$${t}\t<tr><td></td><td></td></tr>\n$${t}</table>\n", help:"HTML table作成" },
    { type:"html",  key:"tablen",   argl:2, argm:3,  bak:1, rept:"tr", repv: "<table>@@@\n$$ev{$$eq{$d$ds$${1}{$${t}\t<tr>$d$ds$${2}{<td>$${3}</td>}</tr>\n}}}$${t}</table>\n", help:"<行数> <列数> [セルの内容]:HTML table作成 tr単位で改行" },
    { type:"html",  key:"table-td", argl:2, argm:3,  bak:1, rept:"tr", repv: "<table>@@@\n$$ev{$$eq{$d$ds$${1}{$${t}\t<tr>\n$d$ds$${2}{$${t}\t\t<td>$${3}</td>\n}$${t}\t</tr>\n}}}$${t}</table>\n", help:"<行数> <列数> [セルの内容]:HTML table作成 trで改行" },
    { type:"html",  key:"trtd",     argl:1, argm:20, bak:1, rept:"tm", repv: {repf:0, repe:0, reps:["<tr>", "<td>$${a}</td>", "</tr>\n"]}, help:"<内容>+:tr td を1行分生成"},
    { type:"html",  key:"trth",     argl:1, argm:20, bak:1, rept:"tm", repv: {repf:0, repe:0, reps:["<tr>", "<th>$${a}</th>", "</tr>\n"]}, help:"<内容>+:tr th を1行分生成"},
    { type:"html",  key:"trthtd",   argl:1, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["<tr><th>$${1}</th>", "<td>$${a}</td>", "</tr>\n"]}, help:"<内容>+:tr th td ..を1行分生成"},
    { type:"html",  key:"trthtd",   argl:1, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["<tr><th>$${1}</th>", "<td>$${a}</td>", "</tr>\n"]}, help:"<内容>+:tr th td ..を1行分生成"},
    { type:"html",  key:"select",   argl:0, argm:4,  bak:1, rept:"tr", repv: "<select id=\"$${1}\">\n<option value=\"@@@$${2}\" selected>$${2}</option>\n$${t}<option value=\"$${3}\">$${3}</option>\n$${t}<option value=\"$${4}\">$${4}</option>\n$${t}</select>\n", help:"<id> [val-list{1,3}]: HTML ブルダウンメニュー作成(3つ)" },
    { type:"html",  key:"selectn",  argl:0, argm:20, bak:1, rept:"tm", repv: {repf:2, repe:0, reps:["<select id=\"$${1}\">\n$${t}<option value=\"@@@$${2}\" selected>$${2}</option>\n","$${t}<option value=\"$${a}\">$${a}</option>\n" ,"$${t}</select>\n"]}, help:"<id> [val-list*]: HTML ブルダウンメニュー作成" },
    { type:"xhtml", key:"template", argl:0, argm:0,  bak:1, rept:"tx", repv: "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"ja\" xml:lang=\"ja\">\n<head>\n<title>@@@ </title>\n</head>\n<body>\n</body>\n</html>\n", help:"XHTML テンプレート" },
    { type:"xhtml", key:"br",       argl:2, argm:2,  bak:0, rept:"tx", repv: "<br />\n", help:"XHTML改行" },
    { type:"xmlF",  key:"tag",      argl:1, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["<$${1}", " $${a}", "=\"$${a}\"", ">@@@</$${1}>\n"]}, help:"TAG 属性"},
    { type:"xmlF",  key:"tage",     argl:1, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["<$${1}", " $${a}", "=\"$${a}\"", " />@@@\n"]}, help:"TAG 属性(empty tag)"},
    { type:"xmlF",  key:"tag-list", argl:1, argm:20, bak:1, rept:"tm", repv: {repf:0, repe:0, reps:["@@@", "<$${a}></$${a}>", "</$${1}>\n"]}, help:"TAG 連続"},
    { type:"xmlF",  key:"tag-nest2",argl:2, argm:2,  bak:1, rept:"tr", repv: "<$${1}><$${2}>@@@</$${2}></$${1}>\n", help:"TAG 連続"},
    { type:"xmlF",  key:"tag-nest3",argl:3, argm:3,  bak:1, rept:"tr", repv: "<$${1}><$${2}><$${3}></$${3}>@@@</$${2}></$${1}>\n", help:"TAG 連続"},
    { type:"xmlF",  key:"tag-nest4",argl:4, argm:4,  bak:1, rept:"tr", repv: "<$${1}><$${2}><$${3}><$${4}>@@@</$${4}></$${3}></$${2}></$${1}>\n", help:"TAG 連続"},
    { type:"xmlF",  key:"xml",      argl:0, argm:0,  bak:1, rept:"tx", repv: "<?xml version=\'1.0\'?>\n", help:"XML宣言"},
    { type:"xmlF",  key:"xmleu",    argl:0, argm:0,  bak:1, rept:"tx", repv: "<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n", help:"XML宣言 UTF-8"},
    { type:"xmlF",  key:"xmles",    argl:0, argm:0,  bak:1, rept:"tx", repv: "<?xml version=\'1.0\' encoding=\'Shift_JIS\'?>\n", help:"XML宣言 Shift_JIS"},
    { type:"xmlF",  key:"xmls",     argl:0, argm:0,  bak:1, rept:"tx", repv: "<?xml version=\'1.0\' standalone=\'yes\'?>\n", help:"XML宣言 standaone "},
    { type:"xmlF",  key:"xmleus",   argl:0, argm:0,  bak:1, rept:"tx", repv: "<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\'?>\n", help:"XML宣言 UTF-8 standaone "},
    { type:"xmlF",  key:"xmless",   argl:0, argm:0,  bak:1, rept:"tx", repv: "<?xml version=\'1.0\' encoding=\'Shift_JIS\' standalone=\'yes\'?>\n", help:"XML宣言 Shift_JIS standaone"},
    { type:"xmlF",  key:"cdata",    argl:0, argm:0,  bak:1, rept:"tx", repv: "<![CDATA[@@@]]>\n", help:"CDATA"},
    { type:"xmlF",  key:"!--",      argl:0, argm:0,  bak:1, rept:"tx", repv: "<!--@@@-->\n", help:"comment <!-- -->"},
    { type:"ALL",   key:"calc",     argl:0, argm:20, bak:1, rept:"tr", repv: "$$ev{$$eq{$d$ej{|$${all}}}\n", help:"JavaScriptで計算します"},
    { type:"ALL",   key:"snipet-meta",       argl:1, argm:20, bak:1, rept:"fn", repv: func_exeMeta,     help: "<meta> [arg*]:指定したメタ文字を実行"},
    { type:"ALL",   key:"snipet-meta-test",  argl:1, argm:20, bak:1, rept:"fn", repv: func_exeMetaTest, help: "<meta> [arg*]:メタ文字を残して指定したメタ文字を実行"},
    { type:"ALL",   key:"help",           argl:0, argm:1,  bak:0, rept:"fn", repv: func_funcHelp, help: "<cmd>:コマンドごとのヘルプを表示 <必須引数> [省略引数] 0以上* 1以上+ 2つ{2} 2つから5つまで{2,5}"}, // 各タイプでオーバーライド可能
    { type:"ALL",   key:"cmd-help",       argl:0, argm:1,  bak:0, rept:"fn", repv: func_funcHelp, help: "<cmd>:コマンドごとのヘルプを表示 <必須引数> [省略引数] 0以上* 1以上+ 2つ{2} 2つから5つまで{2,5}"},
    { type:"ALL",   key:"cmd-type",       argl:0, argm:1,  bak:0, rept:"fn", repv: func_funcType, help: "<type> <cmd> [cmd-arg*]:指定したtypeでコマンドを実行します。"},
    { type:"ALL",   key:"snipet",         argl:0, argm:0,  bak:0, rept:"tx", repv: "snipet.js へようこそ!\n ヘルプを表示するには :snipet-help\n", help: ""},
    { type:"ALL",   key:"snipet-help",    argl:0, argm:0,  bak:0, rept:"fn", repv: func_viewHelp, help: "snipet関連コマンドのヘルプを表示"},
    { type:"ALL",   key:"snipet-find",    argl:0, argm:2,  bak:0, rept:"fn", repv: func_find,     help: "<cmd-part-regex> :cmd(JScript正規表現)に部分一致した有効なコマンド一覧を表示 例:aを含む'a'  aで始まる'^a' aで終わる'a$'"},
    { type:"ALL",   key:"snipet-lookup",  argl:0, argm:2,  bak:0, rept:"fn", repv: func_lookUp,   help: "[type]:有効なコマンド一覧を表示 typeが省略された場合は現在の文書でのtype-list"},
    { type:"ALL",   key:"snipet-type",    argl:0, argm:0,  bak:0, rept:"fn", repv: func_viewType, help: "現在のファイルで有効なtype一覧を表示"},
    { type:"ALL",   key:"snipet-edit",    argl:0, argm:0,  bak:0, rept:"fn", repv: func_snipetEdit, help: "snipet.mac.jpを開く"},
    { type:"ALL",   key:"snipet-version", argl:0, argm:0,  bak:0, rept:"fn", repv: func_version,  help: "snipet.jsのバージョンを表示"},
    { type:"ALL",   key:"snipet-debug-rept-err", argl:0, argm:0, bak:1, rept:"xx", repv: "",  help: "rept定義エラーテスト"},
//SNIPET_AUTO_CONFIG_END
    { type:"snipet",  key:"snipet-add",  argl:8, argm:8,  bak:0, rept:"tr", repv: '\t{ type:"$${1}",  $$lp16{ key:"$${2}",} argl:$${3}, argm:$$lp4{ $${4}, }bak:$${5}, rept:"$${6}", repv: $${7}, help:"$${8}"},\n', help:"snipet定義行追加" }
];
 
// 現在有効のスニペットリスト(ファイル読み込みなどの将来の拡張用)
snipetjs.snipList = snipetjs.snipBuiltInList;
 
 
// return RetValues
function func_rep_default_tr(snip, cmdparams)
{
    return  imp_func_expand_meta(cmdparams, snip.argm, snip.repv, 1);
}
 
// return RetValues
function imp_func_expand_meta(cmdparams, argm, repss, cur)
{
    // 再帰で変化しない引数群をまとめる
    var metap = {cmdparams:cmdparams, argm:argm, cur:cur, repssorg:repss, incvar:1};
    debug.trace("func in imp_func_expand_meta()");
    debug.traceObject(metap, "metap");
    return imp_sub_func_expand_meta(metap, repss, 0, false);
}
 
function imp_func_unescape(str)
{
    var retstr = str;
    if(-1 != str.indexOf("$")){
        retstr = (str.replace(/\$</g, "{")
            .replace(/\$>/g, "}")
            .replace(/\$t/g, "\t")
            .replace(/\$s/g, " ")
            .replace(/\$h/g, "/")
            .replace(/\$n/g, "\n")
            .replace(/\$d/g, "$")  );
        debug.trace("unescape() " + str + " => " + retstr);
    }
    return retstr;
}
 
// return RetValues
function imp_sub_func_expand_meta(metap, repss, repssorg_pos, esc)
{
    debug.trace("func in imp_sub_func_expand_meta()");
    debug.indentTrace();
    debug.trace("repss:" + repss);
    debug.trace("repssorg_pos:" + repssorg_pos);
    debug.traceFlash();
    var snipRet = new RetValues();
    // o abc
    // o $$S1{abc}
    // o abc$$S1{def}
    // o $$S1{abc}def
    // o abc$$S1{abc}def
    // o abc$$S1{def}$$S1{ghi}
    // x abc$$S1{$$S1{def}}
    // x abc$$S1{def}$$S1{$$S1{ghi}}
    // x abc$$S1{def$$S1{ghi}jkl}$$S1{$$S1{mnl}}opq
    
    // ALL : ELEM* 
    // ELEM : STR | FUNC
    // FUNC : $$ FNAME { ALL }
    
    // 本来はネストを処理するがとりあえずネスト未対応版
    
    var loopFlag = true;
    var fi = 0;
    var re;
    var retArray = [];
    var p;
    var mtret;
    var pushstr;
    var i;
    snipRet.status = true;
    var cs_undefined = "undefined";
 
    while(loopFlag){
        if( -1 < (fi = repss.indexOf("$$")) ){
            debug.trace("debug:push $$ left = " + repss.substring(0, fi));
            pushstr = repss.substring(0, fi);
            if(esc){
                pushstr = imp_func_unescape(pushstr);
            }
            retArray.push(pushstr);
            pushstr = null;
            p = repss.substring(fi); // $$...
            
            // $${1}.$${2}...
            if(mtret = p.match(/^\$\$\{([0-9]+)\}/)){
                debug.trace("debug:$${n} repss = " + p.substring(mtret[0].length));
                repss = p.substring(mtret[0].length);
                repssorg_pos += mtret[0].length + fi;
                p = null;
                i = parseInt(mtret[1]);
                if(metap.argm < i){
                    // Error?
                }
                if(typeof metap.cmdparams.cmdvars[i] != cs_undefined){
                    debug.trace("debug:push 1 " + mtret[0] + " => " + metap.cmdparams.cmdvars[i]);
                    retArray.push(metap.cmdparams.cmdvars[i]);
                }
                mtret = null;
            }else
            // $${a+1}.$${a-1}.. を処理
            if(mtret = p.match(/^\$\$\{(a[\-\+][1-9]+[0-9]{0,8})\}/)){
                debug.trace("debug:$${a+-i} repss = " + p.substring(mtret[0].length));
                repss = p.substring(mtret[0].length);
                repssorg_pos += mtret[0].length + fi;
                p = null;
                i = parseInt(mtret[1].substring(1));
                if(metap.argm < metap.cur + i){
                    // Error?
                }
                if(typeof (metap.cmdparams.cmdvars[metap.cur + i]) != cs_undefined){
                    debug.trace("debug:push 2 " + mtret[0] + " => " + metap.cmdparams.cmdvars[metap.cur + i]);
                    retArray.push(metap.cmdparams.cmdvars[metap.cur + i]);
                }
                mtret = null;
            }else
            // $${a} を処理
            if(mtret = p.match(/^\$\$\{a\}/)){
                debug.trace("debug:$${a} repss = " + p.substring(mtret[0].length));
                repss = p.substring(mtret[0].length);
                repssorg_pos += mtret[0].length + fi;
                p = null;
                if(typeof (metap.cmdparams.cmdvars[metap.cur]) != cs_undefined){
                    debug.trace("debug:push 3 "+ mtret[0] + " => " + metap.cmdparams.cmdvars[metap.cur]);
                    retArray.push(metap.cmdparams.cmdvars[metap.cur]);
                }
                mtret = null;
            }else
            if(mtret = p.match(/^\$\$\{all}/)){
                debug.trace("debug:$${n} repss = " + p.substring(mtret[0].length));
                repss = p.substring(mtret[0].length);
                repssorg_pos += mtret[0].length + fi;
                p = null;
                mtret = null;
                for( i = 0; i < metap.cmdparams.cmdvars.length; ++i ){
                    retArray.push(metap.cmdparams.cmdvars[i]);
                }
            }else
            // $${t} を処理
            if(mtret = p.match(/^\$\$\{t\}/)){
                debug.trace("debug:$${t} repss = " + p.substring(mtret[0].length));
                repss = p.substring(mtret[0].length);
                repssorg_pos += mtret[0].length + fi;
                p = null;
                debug.trace("debug:push 4 "+ mtret[0] + " => " + metap.cmdparams.tabs);
                mtret = null;
                retArray.push(metap.cmdparams.tabs);
            }else
            // $${inc} を処理
            if(mtret = p.match(/^\$\$\{i\}/)){
                debug.trace("debug:$${inc} repss = " + p.substring(mtret[0].length));
                repss = p.substring(mtret[0].length);
                repssorg_pos += mtret[0].length + fi;
                p = null;
                debug.trace("debug:push 4 "+ mtret[0] + " => " + metap.incvar);
                mtret = null;
                retArray.push(metap.incvar);
                metap.incvar += metap.incvar;
            }else
            if(mtret = p.match(/^\$\$[a-z0-9A-Z_]+\x7b/)){ //}
                // 関数のネストを調べる
                var pafter = p.substring(mtret[0].length);
                var newRepssPos = -1;
                var nest = 1;
                var maxnest = nest;
                var nestPos = []; 
                var pc;
                nestPos.push(-1);
                for(var nfi = 0;nfi < pafter.length; ++nfi){
                    pc = pafter.charCodeAt(nfi);
                    if(pc === 0x007b){ // "{"
                        ++nest;
                        nestPos.push(nfi);
                        if(maxnest < nest){
                            maxnest = nest;
                        }
                    }else if(pc === 0x007d){ // "}"
                        --nest;
                        nestPos.pop();
                        if(0 === nest){
                            newRepssPos = nfi;
                            break;
                        }else if(nest < 0){
                            snipRet.status = false;
                            snipRet.errorCode = 100;
                            snipRet.errorMessge = ("メタ文字列:異常な \x7d が見つかりました index: "
                                (repssorg_pos + fi + mtret[0].length + nfi) + " 関数"+ 
                                mtret[0].substring(0, mtret[0].length - 2) + " in [" + repssorg + "]");
                            break; // for
                        }
                    }
                }
                if(0 != nest){
                    snipRet.status = false;
                    snipRet.errorCode = 100;
                    snipRet.errorMessge = ("メタ文字列: \x7b に対応する \x7d が見つかりませんでした index: " +
                        (repssorg_pos + fi + mtret[0].length + nestPos.pop()) + " 関数"+ 
                        mtret[0].substring(0, mtret[0].length - 2) + " in [" + metap.repssorg + "]");
                }
                nestPos = null;
                if(false === snipRet.status){ // while
                    break;
                }
                var funcParam = "";
                if(2 <= maxnest){
                    // 関数はネストされている
                    // $$CurrentFunc{xxx$$InnnerFunc{test}hoge}suffix
                    // => xxx$$InnnerFunc{test}hogeを渡す
                    var nestOrgPos = repssorg_pos + fi + mtret[0].length;
                    nestSnipRet = imp_sub_func_expand_meta(metap, pafter.substring(0,newRepssPos), nestOrgPos, true);
                    if(false === nestSnipRet.status){ // while
                        CopyErrorRetValues(snipRet, nestSnipRet);
                        nestSnipRet = null;
                        break;
                    }
                    funcParam = nestSnipRet.retStr;
                    nestSnipRet = null;
                }else{
                    funcParam = pafter.substring(0,newRepssPos);
                    debug.trace("funcParam :" + funcParam + "");
                    // エスケープ解除
                    if(-1 != funcParam.indexOf("$")){
                        funcParam = imp_func_unescape(funcParam);
                        debug.trace("funcParam unescape :" + funcParam);
                    }
                }
                p = null;
                // 関数呼び出し
                // TODO:エラー処理
                var meta_rep = imp_func_meta_rep(mtret[0].substring(2,mtret[0].length - 1), funcParam,
                    metap, repssorg_pos)
                debug.trace("debug:push 5 "+ mtret[0].substring(2,mtret[0].length - 1) + " => " + meta_rep);
                retArray.push(meta_rep);
                meta_rep = null;
                debug.trace("debug:func repss = " + pafter.substring(newRepssPos + 1));
                repss = pafter.substring(newRepssPos + 1);
                repssorg_pos += mtret[0].length + newRepssPos + fi;
                pafter = null;
                mtret = null;
            }else{
                // $$だけしかなかった
                debug.trace("debug:push 6 repss = " + repss);
                pushstr = repss;
                if(esc){
                    pushstr = imp_func_unescape(pushstr);
                }
                retArray.push(pushstr);
                pushstr = null;
                loopFlag = false;
            }
        }else{
            // $$がなかった=ただの文字列(正常)
            debug.trace("debug:push 7 repss = " + repss);
            pushstr = repss;
            if(esc){
                pushstr = imp_func_unescape(pushstr);
            }
            retArray.push(pushstr);
            pushstr = null;
            loopFlag = false;
        }
    }
    if(snipRet.status){
        snipRet.retStr = retArray.join("");
    }
    debug.unindentTrace();
    debug.trace("func out imp_sub_func_expand_meta()");
    debug.traceObject(snipRet, "snipRet");
    return snipRet;
}
 
snipetjs.metaRepLoopCount = 0;
function imp_func_meta_rep(funcName, param, metap, repss, repssorg_pos){
    var s;
    var re;
    var retStr;
    debug.trace("func in imp_func_meta_rep() " + funcName + "{" + param + "}");
    
    // lc 指定した長さになるまで切り取る 左を残す
    //    hoge$$lc5{ABC}ijkl      => hogeABCijkl
    //    hoge$$lc5{ABCDEFGH}ijkl => hogeABCDEijkl
    if(null != (re = funcName.match(/^lc([0-9]{1,5})$/))){
        var ci = parseInt(re[1],10);
        retStr = param.substring(0, ci);
    }
    // rc (指定した長さになるまで切り取る 右を残す
    //    hoge$$rc5{ABC}ijkl      => hogeABCijkl
    //    hoge$$rc5{ABCDEFGH}ijkl => hogeDEFGHijkl
    else if(null != (re = funcName.match(/^rc([0-9]{1,5})$/))){
        var ci = parseInt(re[1],10);
        if(ci < param.length){
            retStr = param.substring(param.length - ci);
        }else{
            retStr = param;
        }
    }
    // lp 長さ指定左揃え(指定した長さになるまでPADを右に詰める)
    //    hoge$$lp5{*123}ijkl => hoge123**ijkl
    //    hoge$$lp5{*1234567}ijkl => hoge1234567ijkl
    else if(null != (re = funcName.match(/^lp[0-9]{1,5}$/))){
        var ci = parseInt(re[1],10);
        retStr = param.substring(1);
        if(retStr.length < ci){
            var pad = param.substring(0,1);
            if(pad === ""){
                pad = " ";
            }
            while(retStr.length < ci){
                retStr += pad;
            }
        }
    }
    // rp 長さ指定右揃え(指定した長さになるまでPADを左に詰める)
    //    hoge$$rp5{*123}ijkl     => hoge**123ijkl
    //    hoge$$rp5{*1234567}ijkl => hoge1234567ijkl
    else if(null != (re = funcName.match(/^rp[0-9]{1,5}$/))){
        var ci = parseInt(re[1],10);
        retStr = param.substring(1);
        if(retStr.length < ci){
            var pad = param.substring(0,1);
            if(pad === ""){
                pad = " ";
            }
            while(retStr.length < ci){
                retStr = pad + retStr;
            }
        }
    }
    // ll 長さ指定(LP & LC)
    //    hoge$$ll5{*123}ijkl     => hoge123**ijkl
    //    hoge$$ll5{*1234567}ijkl => hoge12345ijkl
    else if(null != (re = funcName.match(/^ll[0-9]{1,5}$/))){
        var ci = parseInt(re[1],10);
        retStr = param.substring(1);
        if(retStr.length < ci){
            var pad = param.substring(0,1);
            if(pad === ""){
                pad = " ";
            }
            while(retStr.length < ci){
                retStr += pad;
            }
        }else{
            retStr = retStr.substring(0, ci);
        }
    }
    // rl 長さ指定(RP & RC)
    //    hoge$$RL5{*123}ijkl     => hoge**123ijkl
    //    hoge$$RL5{*1234567}ijkl => hoge34567ijkl
    else if(null != (re = funcName.match(/^rl[0-9]{1,5}$/))){
        var ci = parseInt(re[1],10);
        retStr = param.substring(1);
        if(retStr.length < ci){
            var pad = param.substring(0,1);
            if(pad === ""){
                pad = " ";
            }
            while(retStr.length < ci){
                retStr = pad + retStr;
            }
        }else{
            retStr = retStr.substring(retStr.length - ci);
        }
    }
    // cl 小文字にする
    //    hoge$$cl{abcdEFGH}ijkl => hogeabcdeijkl Right を 5文字
    else if(funcName === "cl"){
        retStr = param.toLowerCase();
    }
    // cu 大文字にする
    //    hoge$$cu{abcdEFGH}ijkl => hogeabcdeijkl Right を 5文字
    else if(funcName === "cu"){
        retStr = param.toUpperCase();
    }
    // 先頭のみ大文字にする
    // hoge$$ct{abcdEFGH}ijkl => hogeAbcdeijkl 
    else if(funcName === "ct"){
        if(1 <= param.length){
            param = param.substring(0,1).toUpperCase() + param.substring(1).toLowerCase();
        }
        retStr = param;
    }
    // _-の直後のみ大文字にして-_を取り除く
    // hoge$$ct{abcdEFGH}ijkl => hogeAbcdeijkl 
    else if(funcName === "ccamel"){
        if(1 <= param.length){
            param = param.replace(/[\-_][a-z]/g, function(r){
                return r.charAt(1).toUpperCase();
            });
        }
        retStr = param;
    }
    // 大文字の直前に_を挿入する
    // hoge$$cunder{abcdEfg}ijkl => hogeaabcd_efgijkl 
    else if(funcName === "cunder"){
        if(1 <= param.length){
            param = param.charAt(0) + param.substring(1).replace(/[A-Z]/g, function(r){
                return "_" + r;
            });
        }
        retStr = param;
    }
    // 大文字の直前に-を挿入する
    // hoge$$chyphen{abcdEfg}ijkl => hogeabcd-efgijkl 
    else if(funcName === "chyphen"){
        if(1 <= param.length){
            param = param.charAt(0) + param.substring(1).replace(/[A-Z]/g, function(r){
                return "-" + r;
            });
        }
        retStr = param;
    }
    // aをbに置換する
    // hoge$$gsub{abcdEfg}ijkl => hogeabcd-efgijkl 
    else if(funcName === "gsub"){
        if(2 <= param.length){
            param = param.substring(2).replace(new RegExp(param.charAt(0),g), param.charAt(1));
        }
        retStr = param;
    }
    // 繰り返し指定
    // hoge$$s10{a}b => hogeaaaaaaaaaab
    else if(null != (re = funcName.match(/^s([0-9]{1,5})$/))){
        var ci = parseInt(re[1],10);
        var ms = "";
        for(var si = ci; 0 < si; --si){
            ms += param;
        }
        retStr = ms;
    }
    // encodeURIする
    // hoge$$eu{abcdEFGH}ijkl => hogeAbcdeijkl 
    else if(funcName === "eu"){
        var cr = param;
        try{
            cr = encodeURI(param);
        }catch(e){}
        retStr = cr;
    }
    // encodeURIComponentする
    // hoge$$euc{abcdEFGH}ijkl => hogeAbcdeijkl 
    else if(funcName === "euc"){
        var cr = param;
        try{
            cr = encodeURIComponent(param);
        }catch(e){}
        retStr = cr;
    }
    // decodeURIする
    // hoge$$du{abcdEFGH}ijkl => hogeAbcdeijkl 
    else if(funcName === "du"){
        var cr = param;
        try{
            cr = decodeURI(param);
        }catch(e){}
        retStr = cr;
    }
    // decodeURIする
    // hoge$$duri{abcdEFGH}ijkl => hogeabcdEFGHijkl 
    else if(funcName === "duc"){
        var cr = param;
        try{
            cr = decodeURIComponent(param);
        }catch(e){}
        retStr = cr;
    }
    // eq そのまま出力します。$$のエスケープ処理などで使います。
    else if(funcName === "eq"){
        retStr = param;
    }
    // ev 入力をメタ文字列として再評価します。
    // 再帰は1000回で強制的に終了します。
    else if(funcName === "ev"){
        snipetjs.metaRepLoopCount++;
        if(snipetjs.metaRepLoopCount < 1000){
            var snipRet = imp_func_expand_meta(metap.cmdparams, metap.argm, param, metap.cur);
            snipetjs.metaRepLoopCount--;
            if(snipRet.status){
                retStr = snipRet.retStr;
                snipRet = null;
            }else{
                // error
                retStr = "";
            }
        }else{
            retStr = "再帰の制限を越えました:関数ev";
        }
    }
    // ej 入力のうち|より前を引数としたJavascriptとしてevalを実行します。
    // 引数は変数sに格納されています。
    // {}は$<$>と、エスケープしなければいけません。
    // $$ej{6|var x = parceInt(s), r=''; for(i=0;i<x;i++)\<r+=' '+i;\>;x}
    //  => 0 1 2 3 4 5
    else if(funcName === "ej"){
        var jsParamPos = param.indexOf("|");
        var jsParam = param.substring(0, jsParamPos);
        var jsCode  = param.substring(jsParamPos + 1);
        var evalParam = {};
        evalParam.s = jsParam;
        snipetjs.metaRepLoopCount++;
        if(snipetjs.metaRepLoopCount < 1000){
            with(evalParam){
                retStr = eval(jsCode);
            }
            snipetjs.metaRepLoopCount--;
        }else{
            retStr = "再帰の制限を越えました:関数ej";
        }
    }else{
        retStr = "不明な関数:" + funcName;
    }
    return retStr;
}
 
function func_rep_default_tm(snip, cmdparams)
{
    var snipRet = new RetValues();
    var snipRetMeta;
    var vlen = cmdparams.cmdvars.length - snip.repv.repe;
    var repsiEnd = snip.repv.reps.length - 1;
    snipRetMeta = imp_func_expand_meta(cmdparams, snip.argm, snip.repv.reps[0], 1);
    if(snipRetMeta.status){
        var retArray = [snipRetMeta.retStr];
        snipRetMeta = null;
        var repsi = 1;
        var i;
        for(i = snip.repv.repf + 1; i < vlen; ++i){
            snipRetMeta = imp_func_expand_meta(cmdparams, snip.argm, snip.repv.reps[repsi], i);
            if(!snipRetMeta.status){
                CopyErrorRetValues(snipRet, snipRetMeta);
                break;
            }
            retArray.push(snipRetMeta.retStr);
            snipRetMeta = null;
            ++repsi;
            if(!(repsi < repsiEnd)){
                repsi = 1;
            }
        }
        snipRetMeta = imp_func_expand_meta(cmdparams, snip.argm, snip.repv.reps[repsiEnd], i);
        if(snipRetMeta.status){
            retArray.push(snipRetMeta.retStr);
            snipRet.retStr = retArray.join("");
            snipRet.status = true;
        }else{
            CopyErrorRetValues(snipRet, snipRetMeta);
        }
    }else{
        snipRet = snipRetMeta;
    }
    return snipRet;
}
 
function func_version(snip, cmdparams)
{
    var snipRet = new RetValues();
    snipRet.retStr = "snipet.js version:" + snipetjs.VER_STR + "\n";
    snipRet.status = true;
    return snipRet;
}
 
function func_viewHelp(snip, cmdparams)
{
    var snipRet = new RetValues();
    var helpc = "\n";
    helpc += "    " + snipetjs.STR_COPYRIGHT + "\n";
    helpc += "    " + func_version().retStr;
    helpc += "    :コマンド 引数1 引数2 .. コロンに続いてコマンド、スペースで区切られた引数を指定します\n";
    helpc += "    snipet.js では ファイル名に基づいてtypeのリストを定義しています。snipetはtypeごとに指定できます\n";
    helpc += "    たとえば拡張子「.html」では デフォルトで html css js xmlF ALL の typeが指定されています\n";
    helpc += "    typeがALLのコマンドはいつでも使用可能です。\n";
    helpc += "    Fで終わるtypeのコマンドは いくつかのタイプで共通のフォーマット系コマンドです\n";
    helpc += "    ヘルプで用いる表記 cmd=「snipetコマンド名] arg=「cmdの引数」 type=「タイプ」";
    helpc += "        <必須引数> [省略引数] *=0以上 +=1以上 {2}=2つ {2,5}=2つから5つまで"
    helpc += "    :snipet-version         snipet.js の version を表示します\n";
    helpc += "    :snipet-type            現在のファイルで有効なsnipet typeの一覧を表示します\n"
    helpc += "    :snipet-lookup          現在のファイルで有効なすべてのsnipetの一覧を表示します\n";
    helpc += "    :snipet-lookup <type>   指定されたtypeに属するsnipetの一覧を表示します\n";
    helpc += "    :snipet-find <cmd-part> 現在のファイルで有効なsnipetの中からcmdに一致する すべてのsnipetの一覧を表示します\n";
    helpc += "    :snipet-edit            snipetファイルをサクラで開きます。\n";
    helpc += "    :help [cmd]             cmdのヘルプを表示します\n"
    helpc += "    :cmd-help [cmd]         helpの別名です。helpコマンドがオーバーロードされている場合に代わりに使えます\n"
    helpc += "    :cmd-type <type> <cmd> [arg*] typeで利用可能なcmdを実行します\n"
    helpc += "    通常のコマンドは、実行後「元に戻す(Ctrl+Z)」で戻せます\n"
    snipRet.retStr += helpc;
    snipRet.status = true;
    return snipRet;
}
 
function func_exeMeta(snip, cmdparams)
{
    var newCmdparams = {};
    var shiftVars = [];
    shiftVars[0] = cmdparams.cmdvars[0];
    for(var i = 2; i < cmdparams.cmdvars.length; i++){
        shiftVars[i - 1] = cmdparams.cmdvars[i];
    }
    newCmdparams.cmdvars = shiftVars;
    newCmdparams.tabs = cmdparams.tabs;
    newCmdparams.cmdline = cmdparams.cmdline;
    return imp_func_expand_meta(newCmdparams, snip.argm - 1, cmdparams.cmdvars[1], 1);
}
 
function func_exeMetaTest(snip, cmdparams)
{
    biOutputString(cmdparams.tabs + cmdparams.cmdline + "\n");
    return func_exeMeta(snip, cmdparams);
}
 
function func_lookUp(snip, cmdparams, rtype)
{
    var snipRet = new RetValues();
    var key = null;
    if( 1 < cmdparams.cmdvars.length ){
        rtype = cmdparams.cmdvars[1].split("|");
    }
    snipRet.retStr += "\nsnipet-lookup:\n";
    if(null != FindSnips(rtype, key, 0, -1, 
        (function(s){snipRet.retStr += s.type + "/" + s.key + "\t" + s.help + "\n";}), true)){
        snipRet.status = true;
    }else{
        snipRet.errorCode = 1;
        snipRet.errorMessge = "snipet-lookup: コマンドが見つかりませんでした" ;
    }
    return snipRet;
}
 
function func_find(snip, cmdparams, rtype)
{
    var snipRet = new RetValues();
    var key = null;
    if( 1 < cmdparams.cmdvars.length ){
        key = new RegExp(cmdparams.cmdvars[1]);
    }
    snipRet.retStr += "\nsnipet-find: " + (!rtype?"":rtype.join(",")) + "\n";
    if(null != FindSnips(rtype, key, 0, -1, 
        (function(s){snipRet.retStr += s.type + "/" + s.key + "\t" + s.help + "\n";}), true)){
        snipRet.status = true;
    }else{
        snipRet.errorCode = 1;
        snipRet.errorMessge = "snipet-find: コマンドが見つかりませんでした" ;
    }
    return snipRet;
}
 
 
function func_funcHelp(snip, cmdparams, rtype)
{
    var snipRet = new RetValues();
    var key;
    if(1 < cmdparams.cmdvars.length){
        key = cmdparams.cmdvars[1];
    }else{
        key = snip.key;
    }
    if(null != FindSnips(rtype, key, 0, -1, 
        (function(s){snipRet.retStr += s.type + "/" + s.key + "\t" + s.help + "\n";return true;}), true)){
        snipRet.status = true;
    }else{
        snipRet.errorCode = 1;
        snipRet.errorMessge = "help: コマンド '"+ key + "' が現在のtypeの中から見つかりませんでした";
    }
    return snipRet;
}
 
function func_funcType(snip, cmdparams, rtype)
{
    var snipRet = new RetValues();
    if(1 < cmdparams.cmdvars.length){
        if(2 < cmdparams.cmdvars.length){
            var newRtype = [cmdparams.cmdvars[1], 'ALL'];
            var key;
            var newCmdparams = {};
            var shiftVars = [];
            shiftVars[0] = cmdparams.cmdvars[0];
            for(var i = 3; i < cmdparams.cmdvars.length; i++){
                shiftVars[i - 2] = cmdparams.cmdvars[i];
            }
            newCmdparams.cmdvars = shiftVars;
            newCmdparams.tabs = cmdparams.tabs;
            newCmdparams.cmdline = (cmdparams.cmdline.charAt(0)
                + cmdparams.cmdline.substring(cmdparams.cmdvars[1].length + cmdparams.cmdvars[2].length + snip.key + 4));
            if(cmdparams.cmdvars[1] == 'NONE'){
                newRtype = null;
            }else{
                if(-1 < cmdparams.cmdvars[1].indexOf("|")){
                    newRtype = cmdparams.cmdvars[1].split("|").push('ALL');
                }
            }
            key = cmdparams.cmdvars[2];
            debug.trace("fncType:" + newRtype);
            snipRet = exeCmd(newRtype, key, newCmdparams);
            if(snipRet == null){
                snipRet.errorCode = 1;
                snipRet.errorMessge = "cmd-type: コマンド '"+ key + "' が見つかりませんでした";
            }
        }else{
            snipRet.errorCode = 2;
            snipRet.errorMessge = "cmd-type: <type-list> <cmd> [arg*]:コマンドを指定してください";
        }
    }else{
        snipRet.errorCode = 2;
        snipRet.errorMessge = "cmd-type: <type-list>] <cmd> [arg*]:typeを指定してください";
    }
    return snipRet;
}
 
function func_viewType(snip, cmdparams, rtype)
{
    var snipRet = new RetValues();
    var helpc = "";
    if(null == rtype){
        helpc = "すべてのtype が有効です。";
    }else{
        helpc = "このファイルで有効なtypeの一覧: " + rtype.join(", ") + "\n";
    }
    snipRet.retStr = helpc;
    snipRet.status = true;
    return snipRet;
}
 
function func_snipetEdit(snip, cmdparams, rtype)
{
    Editor.FileOpen( Editor.ExpandParameter("$M") );
    var snipRet = new RetValues();
    snipRet.retStr = "@@@\n";
    snipRet.status = true;
    return snipRet;
}
 
 
snipetjs.Output = false;
snipetjs.OutpuBuffer = "";
//	sipet組み込み用関数:出力
function biOutputString(str, isBuffer,isReplace)
{
    if(typeof isBuffer === "undefined"){isBuffer = true}
    if(typeof isReplace === "undefined"){isReplace = true}
    if(isReplace){
        var lineCode = Editor["GetLineCode"]();
        if(0 == lineCode){
            // CRLF
            str = str.replace(/\n/g, "\r\n");
        }else if(1 == lineCode){
            // CR
            str = str.replace(/\n/g, "\r");
        }
    }
    var outputStr = "";
    if(isBuffer){
        if(snipetjs.OutpuBuffer.length + str.length < 5120){
            snipetjs.OutpuBuffer += str;
            return false;
        }else{
            outputStr = snipetjs.OutpuBuffer + str;
            snipetjs.OutpuBuffer = "";
        }
    }else{
        outputStr = snipetjs.OutpuBuffer + str
    }
    if(false === snipetjs.Output){
        Editor["MoveHistSet"]();
        Editor["SelectLine"](0);
        snipetjs.Output = true;
    }
    Editor["InsText"](outputStr);
    return true;
}
 
// class
function RetValues()
{
    this.retStr = "";
    this.status = false;
    this.errorCode = 0;
    this.errorMessge = "";
    return this;
}
 
function CopyErrorRetValues(ret, org)
{
    if(false === org.status){
        ret.status = false;
        ret.errorCode = org.errorCode;
        ret.errorMessge = org.errorMessge;
    }
    return ret;
}
 
/* コマンド名/rtypeからsnipを探して実行する
	@return RetValues / null
*/
function exeCmd(rtype, key, cmdparams)
{
    var snipRet = new RetValues();
    var rets = null;
    var exeSuccess = false;
    var snipArgMiss = null;
    debug.indentTrace();
    if( FindSnips(rtype, key, 0, -1, function(aSnip){
                // 実行してみる
                // cmdparams.cmdvars.length は 引数+1なので注意
                if(aSnip.argl < cmdparams.cmdvars.length && cmdparams.cmdvars.length <= aSnip.argm + 1){
                    rets = exeSnip(aSnip, cmdparams, rtype);
                    if(rets.status){
                        snipRet.retStr += rets.retStr;
                        snipRet.status = true;
                        rets.retStr = null;
                        exeSuccess = true;
                        return false;
                    }
                    // 次を試してみる
                }else{
                    debug.trace("snip:key    ", aSnip.key);
                    debug.trace("snip:argl   ", aSnip.argl);
                    debug.trace("snip:argm   ", aSnip.argm);
                    debug.trace("cmdvars.len ", cmdparams.cmdvars.length);
                    // 最後に引数が合わなかったsnipを記憶
                    snipArgMiss = aSnip;
                }
                return true;
            }, true) ){
        if(false == exeSuccess){
            if(null == rets && snipArgMiss){
                snipRet.status = false;
                snipRet.errorCode = 2;
                snipRet.errorMessge = "引数が一致しません <cmd>=" + snipArgMiss.key;
            }else{
                CopyErrorRetValues(snipRet, rets);
            }
        }
    }else{
        // 見つからなかった nullをかえす
        snipRet = null;
    }
    debug.unindentTrace();
    return snipRet;
}
 
/*
	snip を snip.reptにしたがって実行する
	@return RetValues
*/
function exeSnip(snip, cmdparams, rtype)
{
    debug.trace("exeSnip()");
    debug.indentTrace();
    debug.traceObject(snip, "snip");
    debug.traceObject(cmdparams, "cmdparams");
    debug.traceObject(rtype, "rtype");
    var exeRet  = new RetValues();
    var snipRet;
    
    if(snip.rept === "tx"){
        exeRet.retStr = snip.repv;
        exeRet.status = true;
    }else{
        // arg チェック
        if(snip.rept === "tr"){
            snipRet = func_rep_default_tr(snip, cmdparams);
        }else if(snip.rept === "tm"){
            snipRet = func_rep_default_tm(snip, cmdparams);
        }else if(snip.rept === "fn"){
            snipRet = snip.repv(snip, cmdparams, rtype);
        }else{
            snipRet = new RetValues()
            snipRet.errorCode = 1;
            snipRet.errorMessge = "スニペットの定義が不正です。Snip.rept:'" + snip.rept +"'は未定義の種類です。";
        }
        
        if(snipRet.status){
            exeRet.retStr = snipRet.retStr;
            exeRet.status = true;
        }else{
            CopyErrorRetValues(exeRet, snipRet);
        }
    }
    debug.unindentTrace();
    return exeRet;
}
 
// SlipListからslipを検索
// rtype:string[] null = typeでフィルタしない / typesの[]表現
// key:string     null = すべて / コマンド名
// func_lambda:function(matchSlip:slip):boolean
//                finditem ヒットしたslip
//                戻り値  ループ処理を継続=true, キャンセル=false
// globalFlag:  (:undefined or :null) = falseに同じ
//              :boolean true = 一致するものすべてを処理する / false = 最初に見つかったもののみ処理
// 戻り値:      null = 見つからない
//              func_lambda指定時は、 null / true
//              Filter済みslipList (0 < .length)
function FindSnips(rtype, key, topIndex, lastIndex, /* option */func_lambda, /* option */globalFlag)
{
    var retValue = null;
    if(lastIndex < 0){lastIndex = snipetjs.snipList.length}
    if(!globalFlag){globalFlag = false}
    if(rtype != null){
        debug.trace( "func in FindSnips() typte != null" );
        debug.indentTrace();
        debug.traceObject( rtype, "rtype" );
        // rtype.length < snipList.lengthなので、先にsnipList.keyのフィルタを作ってからにする
        var keySlipList = FindSnips(null, key, topIndex, lastIndex, null, true);
        debug.traceObject( keySlipList, "keySlipList" );
        debug.unindentTrace();
        if(null === keySlipList){
            return null;
        }
        for(var k = 0; k < rtype.length; ++k){
            for(var i = 0; i < keySlipList.length; ++i){
                var aSlip = keySlipList[i];
                if( rtype[k] === aSlip.type ){
                    if(func_lambda){
                        if(false === func_lambda(aSlip)){
                            return true;
                        }
                    }
                    if(false === globalFlag){
                        return aSlip;
                    }
                    if(!func_lambda){
                        if(null == retValue){
                            retValue = [];
                        }
                        retValue.push(aSlip);
                    }else{
                        retValue = true;
                    }
                }
            }
        }
    }else{
        for(var i = topIndex; i < lastIndex; ++i){
            if(key === null || ((key instanceof RegExp) && key.test(snipetjs.snipList[i].key))
                    || snipetjs.snipList[i].key === key ){
                var aSlip = snipetjs.snipList[i];
                if(func_lambda){
                    if(false == func_lambda(aSlip)){
                        return true;
                    }
                }
                if(false === globalFlag){
                    return aSlip;
                }
                if(!func_lambda){
                    if(null == retValue){
                        retValue = [];
                    }
                    retValue.push(aSlip);
                }else{
                    retValue = true;
                }
            }
        }
    }
    return retValue;
}
 
function GetCommandPosition(line)
{
    var marki;
    var ci;
    var resetFlag = true;
    var spLine = line;
    do{
        resetFlag = false;
        for(marki = 0; marki < snipetjs.CommandMark.length; ++marki){
            ci = spLine.lastIndexOf(snipetjs.CommandMark[marki]);
            if(-1 != ci){
                var cmdstrPrev = spLine.substring(0,ci);
                var ignore = false;
                for(var igi =0; igi < snipetjs.CommandPrevIgnoreRe.length; ++igi){
                    if(-1 != cmdstrPrev.search(snipetjs.CommandPrevIgnoreRe[igi])){
                        ignore = true;
                        break;
                    }
                }
                if(ignore){
                    // コマンド探索範囲を前のほうだけにしてやりなおし
                    // prevs :urllink http:example.com/test ⇒
                    // prevs :urllink http
                    spLine = spLine.substring(0,ci - 1);
                    if(0 < spLine.length){
                        resetFlag = true;
                        break;
                    }
                }
            }
        }
    }while(resetFlag);
    return ci;
}
 
function GetRtype(fileName){
    var rtype = snipetjs.DefaultTypes;
    if(0 < fileName.length){
        var fileNameWithl = "|" + fileName + "|";
        for(var i = 0; i < snipetjs.extSupList.length; ++i){
            var extSup = snipetjs.extSupList[i];
            if( typeof extSup.nameFilter !== "string" && fileName.test(extSup.nameFilter)
                    || -1 != fileNameWithl.indexOf(extSup.nameFilter) ){
                rtype = extSup.types.split("|");
                rtype.push("ALL");
                break;
            }
        }
    }else{
        // 無題のときは、defaultではすべてのタイプ(ALLとは違うので注意)
        rtype = snipetjs.UnSaveDocTypes;
    }
    return rtype;
}
 
function InsConvertSnipett()
{
    var curline = Editor["GetLineStr"](0);
    var cmi = -1;
    cmi = GetCommandPosition(curline);
    if(0 <= cmi){
        var left = curline.substring(0,cmi);
        var fileName = Editor["GetFilename"](0).toLowerCase();
        var cmdlineWithMark = curline.substring(cmi).replace(/[\r\n]+/, "");
        var cmdline = curline.substring(cmi+1);
        var cmdvars = cmdline.replace(/[\r\n]+/, "").split(" ");
        // 特定ファイル名のとき、機能を限定する
        var rtype = GetRtype(fileName);
        // snipが何か出力するかもしれないので、先に出しておく。
        biOutputString(left, true, true);
        // インデント部分取得
        var tabStr = curline.match(/^[ \t]*/)[0];
        var keyName = cmdvars[0];
        cmdvars[0] = ""; // 予約
        var cmdparams = {cmdvars:cmdvars, tabs:tabStr, cmdline:cmdlineWithMark };
        var exeSuccess = false;
        var rets;
        debug.trace("snipet.js ---- start ------key:" + keyName);
        rets = exeCmd(rtype, keyName, cmdparams);
        debug.traceObject(rets, "rets");
        if(rets && rets.status){
            /// @@@処理
            var retexe2 = rets.retStr.replace(/\r\n/g, "\n");
            var curIndex = retexe2.lastIndexOf("@@@");
            var prevChar = "";
            var upCount = -1;
            var backCount = 0;
            var retexeStr;
            if(0 <= curIndex){
                if(1 <= curIndex){
                    prevChar = retexe2.charAt(curIndex - 1);
                }
                retexe2 = retexe2.substring(curIndex + 3);
                curIndex = 0;
                for(var npos = retexe2.length - 1; 0 <= npos; --npos){
                    if(retexe2.charCodeAt(npos) === 0x0a){
                        upCount++;
                        backCount = 1;
                    }else{
                        backCount++;
                    }
                }
                if(0 < backCount && prevChar == "\n"){
                    backCount = 0;
                    upCount++;
                }
                retexeStr = rets.retStr.replace(/@@@/g, "");
            }else{
                retexeStr = rets.retStr;
            }
            biOutputString(retexeStr, false, true);
            Editor.ReDraw(0);
            var c = 0;
            if(0 <= upCount){
                Editor["GoLineTop"](9);
            }
            for(var c = 0; c < upCount; c++){
                Editor["Up"]();
            }
            for(var c = 0; c < backCount; c++){
                Editor["Left"]();
            }
        }else{
            var errPut = false;
            if(rets != null){
                if(rets.errorCode != 0){
                    errPut =true;
                    biOutputString("error "+rets.errorCode+ ":" + rets.errorMessge + "\n", false, true);
                }else{
                    debug.traceObject(rets, "rets");
                    biOutputString("unknown error from " + cmdlineWithMark.replace("\r\n", "\n"), false, true);
                }
            }
            // コマンドが見つからなかった
        }
        return true;
    }
    return false;
}
 
 
function msgBox(str)
{
    var wss = new my_ActiveXObject("WScript.Shell");
    // MB_ICONEXCLAMATION | MB_OK
    wss["PopUp"](("" + str), void(0), "sakura", 0x30 );
    wss = null;
}
 
 
// ------------------------------
 
var debug = {};
 
// debug member
(function()
{
    var m_traceStr = "";
    var m_traceIndent = 0;
    var m_traceIndentStr = "";
    var m_msgBoxCount = 0;
    var m_msgBoxNormalCount = 10;
    var m_msgBoxVisible = true;
    var m_bufferSize = 4096;
    var m_enableTrace = true;
    var m_traceObjectLoop = 10;
    var m_traceObjectLoopCurrent = 0;
 
    function traceObject(obj, objName)
    {
        if(!m_enableTrace){return}
        if(m_traceObjectLoop < m_traceObjectLoopCurrent){return}
        var maxDepth = 100;
        function traceObject_sub(item, currentDepth, objName)
        {
            if(currentDepth < maxDepth){
                indentTrace();
                for( var i in item ){
                    if( typeof(item[i]) === "object" ){
                        var klass = "";
                        if( item[i] instanceof Array ){
                            klass = "(Array)";
                        }
                        if( item[i] instanceof RegExp ){
                            klass = "(RegExp)";
                        }
                        debug.trace(objName + "[" + i + "]:"+ typeof(item[i]) +" = \"" + item[i] + "\":" + klass + "");
                        traceObject_sub(item[i], currentDepth+1, objName+"["+i+"]");
                    }else{
                        if( typeof(item[i]) == "function" ){
                            debug.trace(objName + "[" + i + "]:function = \"###\"");
                        }else{
                            debug.trace(objName + "[" + i + "]:"+ typeof(item[i]) +" = \"" + item[i] + "\"");
                        }
                    }
                }
                unindentTrace();
            }
        }
        if(!objName){ objName = "(AC)"; }
        if(!(typeof(obj) == "object")){
            if( typeof(obj) == "function" ){
                debug.trace("TraceObjectName : " + objName + ":function = ###");
            }else{
                debug.trace("TraceObjectName : " + objName + ":" + typeof(obj) + " = \"" + obj + "\"");
            }
        }else{
            debug.trace("TraceObjectName : " + objName);
            traceObject_sub(obj, 1, objName);
        }
    }
 
    function trace(/* ... */)
    {
        if(!m_enableTrace) return;
        var str;
        var arr = [];
        arr.push.apply(arr, arguments);
        if( 0 < m_traceIndent ){
            str = m_traceIndentStr + arr.join();
        }else{
            str = arr.join();
        }
        arr = null;
        if( 0 < m_traceStr.length ){
            m_traceStr += str + "\r\n";
        }else{
            m_traceStr = str + "\r\n";
        }
        if( debug.bufferSize <= m_traceStr.length ){
            debug.MyTraceOut(m_traceStr);
            m_traceStr = "";
        }
    }
 
    function traceNoFormat(str)
    {
        if(!m_enableTrace) return;
        if( 0 < m_traceStr.length ){
            m_traceStr += str;
        }else{
            m_traceStr = str;
        }
        if( debug.bufferSize <= m_traceStr.length ){
            debug.MyTraceOut(m_traceStr);
            m_traceStr = "";
        }
    }
 
    function traceFlash()
    {
        if( 0 < m_traceStr.length ){
            debug.MyTraceOut(m_traceStr);
            m_traceStr = "";
        }
    }
 
    /* static */
    function MyTraceOut(str)
    {
        // sakuraのTraceOutはあまり長いと共有メモリーでバッファオーバーランします
        var len = str.length;
        var cur = 0;
        do{
            var outstr = str.substr(cur,30000);
            Editor.TraceOut(outstr, 0x02);
            cur += outstr.length;
        }while(cur < len);
    }
 
    function traceMsgBox(str)
    {
        if( m_msgBoxVisible ){
            m_msgBoxCount++;
            if(m_msgBoxCount < m_msgBoxNormalCount){
                return msgBox();
            }else{
                var wss = new my_ActiveXObject("WScript.Shell");
                var ret = wss["PopUp"](str + "\n[はい]続行  [いいえ]ダイアログなしで続行  [キャンセル]実行中止", 
                    void(0), "sakura debug", 0x33); // MB_ICONEXCLAMATION | MB_YESNOCANCEL
                wss = null;
                if( ret == 6 ){
                    // [はい]なにもしない
                }else if( ret == 7 ){
                    // [いいえ]ダイアログなし
                    m_msgBoxVisible = false;
                }else if( ret == 2 ){
                    //[キャンセル]
                    throw new debug.UserDebugException();
                }
            }
        }
    }
    
    /* class */
    function UserDebugException()
    {
    }
    UserDebugException.prototype.toString = function() {
        return "デバッグ ダイアログにより中止されました。"
    }
 
    function indentTrace()
    {
        return setIndentTrace(m_traceIndent + 1);
    }
    function unindentTrace()
    {
        return setIndentTrace(m_traceIndent - 1);
    }
    function setIndentTrace(indent)
    {
        m_traceIndent = indent;
        var s = "";
        for( var t = 0; t < m_traceIndent; t++ ){
            s += "  ";
        }
        m_traceIndentStr = s;
        return indent;
    }
    function setTrace(mode)
    {
        m_enableTrace = mode;
        return m_enableTrace;
    }
 
    debug.bufferSize = m_bufferSize;
 
    debug.trace = trace;
    debug.traceFlash = traceFlash;
    debug.traceObject = traceObject;
    debug.indentTrace = indentTrace;
    debug.unindentTrace = unindentTrace;
    debug.setIndentTrace = setIndentTrace;
    debug.traceMsgBox = traceMsgBox;
    debug.setTrace = setTrace;
 
    debug.MyTraceOut = MyTraceOut;
    debug.UserDebugException = UserDebugException;
})();
 
my_ActiveXObject = eval("ActiveXObject");
 
main();




    


    ホーム 一覧 単語検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS