File: html-helper-mode.el

package info (click to toggle)
html-helper-mode 3.0.4kilo-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, squeeze, wheezy
  • size: 284 kB
  • ctags: 262
  • sloc: lisp: 2,756; makefile: 42; sh: 32
file content (2512 lines) | stat: -rw-r--r-- 97,640 bytes parent folder | download
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
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
;;; html-helper-mode.el --- Major mode for composing html files.
;;; v 3.0.4kilo

;; Mantainer : Gian Uberto "Saint" Lauri <saint@eng.it>
;;                                       <saint@dei.unipd.it>*
;;                                * works only from DEI, Padova.
;;             http://www.gest.unipd.it/~saint/
;; Original Author: Nelson Minar <nelson@santafe.edu>
;; Original version Maintainer: Nelson Minar <nelson@santafe.edu>
;; Changes by by: Gian Uberto Lauri <lauri@eng.it>, <saint@dei.unipd.it>*
;;                                * works only from DEI, Padova.
;; Credits : Larry Smith and Tony Graham for the ASP/PHP matching regexp
;;           prototype.
;;           Stan Lanning for the defadvice code that prevents indenting
;;           of <PRE></PRE>, for the defadvice code that leaves the cursor
;;           where it is during narrowing to script code, enhancments to
;;           the scripting narrowing
;;           Charles Curley for the commentary of tempo.el behaviour
;;           Samir Barjoud for giving me the luser cap when I didn't notice
;;           that *ALL* I needed to write  html-helper-match-asp-php was in
;;           font-lock.el.
;;           Theodore A. Jump for fixing fold tags in this source (after I
;;           broke them
;;           David J. Biesack for suggesting a good version checking.

;; URL: http://www.gest.unipd.it/~saint/html-helper-mode.el.gz

;; Created: 01 Feb 1994
;; $Id: html-helper-mode.el,v 3.0.4kilo 1998/08/06 18:53:03 nelson Exp $
;; Keywords: HTML major-mode

;; LCD Archive Entry:
;; html-helper-mode|Gian Uberto Lauri|lauri@eng.it|
;; Major mode for editing HTML.|
;; 26-Oct-99|Version 3.?.?|http://www.gest.unipd.it/~saint/html-helper-mode.el.gz

;; Copyright (C) 1994 Nelson Minar
;; Copyright (C) 1995 Nelson Minar and Ulrik Dickow
;; Copyright (C) 1999 Nelson Minar, Ulrik Dickow and Gian Uberto Lauri

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to
;; the Free Software Foundation, 675 Massachusettes Ave,
;; Cambridge, MA 02139, USA.

;;{{{ Commentary

;; Installation:
;;   Add this line in your .emacs:
;;     (autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
;;   To invoke html-helper-mode automatically on .html files, do this:
;;     (setq auto-mode-alist (cons '("\\.html$" . html-helper-mode) auto-mode-alist))
;;   To invoke html-helper-mode automatically on .asp files, do this:
;;     (setq auto-mode-alist (cons '("\\.asp$" . html-helper-mode) auto-mode-alist))
;;   To invoke html-helper-mode automatically on .phtml files, do this:
;;     (setq auto-mode-alist (cons '("\\.phtml$" . html-helper-mode) auto-mode-alist))

;;
;;   This mode requires another lisp file, tempo.el. This can be
;;     retrieved from ftp://ftp.lysator.liu.se/pub/emacs/tempo.el
;;   Xemacs users need to have auc-menu installed.
;;   Emacs 18 users need to have auc-menu and add-hook installed.
;;   If your OS has broken 14 character filenames
;;      this mode will also work with the name "html-mode.el".

;; Configuration:
;;   see the "user variables" section, or the documentation on configuration
;;   in http://www.santafe.edu/~nelson/tools/. There are variables you want to
;;   configure, particularly html-helper-address-string and
;;   html-helper-use-expert-menu

;; See also: http://www.gest.unipd.it/~saint/hth.html for further details
;; regarding server code support.

;; Description:
;;   html-helper-mode makes it easier to write HTML documents. This mode
;;   handles inserting HTML codes in a variety of ways (keybindings, menus,
;;   completion in the buffer). It also supports indentation, timestamps,
;;   skeletons for new documents, hilit19 patterns, and a variety of other
;;   things. For the full skinny, see the HTML documentation that comes
;;   with the package or is at http://www.santafe.edu/~nelson/tools/

;; Thank yous:
;;   David Kgedal <davidk@lysator.liu.se> for the tempo code which
;;     forms the core of the HTML insertion, as well as the HTML+ tag.
;;   Marc Hedlund <march@europa.com> for general encouragement and
;;     many helpful suggestions, especially with HTML/2.0 compliance
;;     and form design.
;;   Ulrik Dickow <dickow@nbi.dk> for the font-lock code
;;   Denis Howe <dbh@doc.ic.ac.uk> for writing browse-url.
;;   Magnus Homann <d0asta@dtek.chalmers.se> and Jamshid Afshar
;;     <jamshid@ses.com> for timestamp suggestions.
;;   Everyone who sent me a version of menus (16 in all!)
;;   Marc Andreessen <marca@mcom.com> for writing the original html-mode

;; The newest version of html-helper-mode should always be available from
;;   http://www.gest.unipd.it/~saint/hth.html

;; Changes moved to hhm-changelog

;; This code was writting using folding.el, a wonderful folding editor
;; minor mode for emacs. That's what the strange {{{ comments are for.

;;}}}

;;{{{ Code:

(defconst html-helper-mode-version
  (progn
    (let ((revs "$Revision: 3.0.4kilo$")
	  (lastchar 0))
      ; revs is a string of single byte characters
      (set 'lastchar (1- (string-width revs)))
      (substring revs 11 lastchar))))

;;{{{ user variables

;;{{{ defcustoms
(defgroup html-helper nil
  "Customizing html-helper-mode"
  :group 'languages
  :group 'hypermedia
  :group 'local)

(defgroup html-helper-faces nil
  "Customizing html-helper-mode custom faces"
  :group 'html-helper
  :group 'faces)

;; Default distribution doesn't include visual-basic-mode
(defcustom html-helper-mode-uses-visual-basic nil
  "Non nil to require visual-basic-mode"
  :type 'boolean
  :initialize 'custom-initialize-default
  :group 'html-helper
  :require 'html-helper-mode)

;; Default distribution doesn't include jde
;;
;; Suggestion by :
;; Jari Aalto <jari.aalto@poboxes.com>
;;
;;    I think that people that have installed JDE, use it, so
;;    it would be logical to preset this automatically using
;;    `locate-library'
(defcustom html-helper-mode-uses-JDE nil
  "No nil to use jde instead of java-mode"
  :type 'boolean
  :initialize 'custom-initialize-default
  :group 'html-helper
  :require 'html-helper-mode)

(defcustom html-helper-mode-uses-bold-italic nil
  "Non nil to use the bold-italic font (if your font supports it)"
  :type 'boolean
  :initialize 'custom-initialize-default
  :group 'html-helper
  :require 'html-helper-mode)

(defcustom html-helper-mode-uses-KG-style nil
  "Non nil to make Emacs consider PHP/ASP code blocks beginning in
the first column"
  :type 'boolean
  :initialize 'custom-initialize-default
  :group 'html-helper
  :require 'html-helper-mode)

(defcustom html-helper-mode-global-JSP-not-ASP t
  "Non nil to make Emacs consider <% %> blocks as JSP (global default behaviour)"
  :type 'boolean
  :initialize 'custom-initialize-default
  :group 'html-helper
  :require 'html-helper-mode)

(defcustom html-helper-mode-insert-attributes-always t
  "non nil to make Emacs insert empty tag attributes when tempo-interactive is nil"
  :type 'boolean
  :initialize 'custom-initialize-default
  :group 'html-helper
  :require 'html-helper-mode)
;;}}}

;;{{{ defvars...
(defvar html-helper-mode-local-JSP-not-ASP
  html-helper-mode-global-JSP-not-ASP
  "Non nil to make Emacs consider <% %> blocks as JSP (buffer local behaviour)")

(defvar html-helper-mode-run-the-mode t "When t, make the local variables, else skip")
;; Visual basic mode is not in the standard distribution, so I let the user
;; override html-helper-mode-uses-visual-basic with a nil value.
(cond (html-helper-mode-uses-visual-basic (require 'visual-basic-mode)))
(cond (html-helper-mode-uses-JDE (require 'jde)))
(require 'cc-mode)
(require 'cl)

;; Set this to be whatever signature you want on the bottom of your pages.
(defvar html-helper-address-string ""
  "*The default author string of each file.")

;; Features; these are all good to have on. (see also tempo.el)

(defvar html-helper-use-expert-menu t
  "*If not nil, then use the full HTML menu.")

(defvar html-helper-do-write-file-hooks t
  "*If not nil, then modify `local-write-file-hooks' to do timestamps.")

(defvar html-helper-build-new-buffer t
  "*If not nil, then insert `html-helper-new-buffer-strings' for new buffers.")

;; variables to configure (these defaults are reasonable.)

(defvar html-helper-htmldtd-version "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n"
  "*Version of HTML DTD you're using.")

(defvar html-helper-user-menu nil
  "*Extra items to put in the HTML expert menu.
The value of this symbol is appended to the beginning of the expert
menu that is handed off to easymenu for definition. It should be a
list of vectors or lists which themselves are vectors (for submenus).")

(defvar html-helper-basic-offset 2
  "*Basic indentation size used for list indentation")

;; Wed Jan 10 09:35:53 2001 Saint
;;
;; fixing indentation
;;(defvar html-helper-item-continue-indent 2
;;  "*Indentation of lines that follow a <li> item.
;;Default is 2, the length of things like \"<li>\" and \"<dd>\".")

(defvar html-helper-never-indent nil
  "*If not nil, the indentation code for html-helper is turned off.")

;; hooks (see also tempo.el)

;; On prompts... Charles Curley (http://w3.trib.com/~ccurley/): It took
;; some time to figure this out... The (p "prompt: ") and (r "prompt:
;; ") entries indicate where the prompting mode should prompt for a
;; field in the tag. (p ) indicates a parameter, such as the color of a
;; <font> tag. (r ) indicates a region, where the text to be surrounded
;; by the tag should go, such as the text to be turned that color. The
;; difference is this: when prompting mode is turned off and the user
;; is surrounding a region with the tag, the (r ) (region) parameter
;; indicates where the surrounded region will go. The first (p )
;; (parameter) is where the cursor will go, ready to input the first
;; parameter to the tag.

;; So when you have prompting on, and use the font with color and size
;; tag, put the cursor where you want the modified text to go. Start
;; inserting the tag. You will be prompted for the color, the size, and
;; then the text to display that way. When you have prompting turned
;; off, and don't have a region blocked, insert the font tag, and the
;; cursor will be at the the first parameter. Then tab over to the
;; space between the two parts of the tag, and type in your text. If
;; you have region blocked, C-u followed by the tag will surround the
;; region with the tag. The blocked region goes into the (r )
;; parameter. Then the cursor is placed at the first (p ) location,
;; ready for you to type in a parameter, such as the color of the text.

(defvar html-helper-mode-hook nil
  "*Hook run when html-helper-mode is started.")

(defvar html-helper-load-hook nil
  "*Hook run when html-helper-mode is loaded.")

(defvar html-helper-timestamp-hook 'html-helper-default-insert-timestamp
  "*Hook called for timestamp insertion.
Override this for your own timestamp styles.")

;; strings you might want to change

(defvar html-helper-new-buffer-template
  '(html-helper-htmldtd-version
    "<html>\n<head>\n"
    "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-15\">\n"
    "<title>" p "</title>\n</head>\n\n"
    "<body>\n"
    "<h1>" p "</h1>\n\n"
    p
    "\n\n<hr>\n"
    "<address>" html-helper-address-string "</address>\n"
    html-helper-timestamp-start
    html-helper-timestamp-end
    "\n</body> </html>\n")
  "*Template for new buffers.
Inserted by `html-helper-insert-new-buffer-strings' if
`html-helper-build-new-buffer' is set to t")

(defvar html-helper-new-ASP-buffer-template
  '("<%@ LANGUAGE=\"" p "\" %>\n"
    "<html> <head>\n"
    "<%\n\n%>\n"
    "</head><body>\n"
    "<% '<!-- " html-helper-timestamp-start "  " html-helper-timestamp-end
    " --> %>\n"
    "\n</body></html>\n")
"*Template for new ASP buffers.
Inserted by `html-helper-insert-new-ASP-buffer-strings' if
`html-helper-build-new-buffer' is set to t")

(defvar html-helper-new-PHP-buffer-template
  '("<html> <head>\n"
    "<? PHP\n\n?>"
    "</head><body>\n"
    "<? /* " html-helper-timestamp-start "\n\n"
    html-helper-timestamp-end
    " */ ?>\n"
    "\n</body></html>\n"
    )
"*Template for new PHP buffers.
Inserted by `html-helper-insert-new-PHP-buffer-strings' if
`html-helper-build-new-buffer' is set to t")

;; Someone has some better idea ?
(defvar html-helper-new-JSP-buffer-template
  '("<html> <head>\n"
    "<%\n\n%>\n"
    "</head><body>\n"
    "<% '<!-- " html-helper-timestamp-start "  " html-helper-timestamp-end
    " --> %>\n"
    "\n</body></html>\n")
"*Template for new JSP buffers.
Inserted by `html-helper-insert-new-ASP-buffer-strings' if
`html-helper-build-new-buffer' is set to t")

(defvar html-helper-timestamp-start "<!-- hhmts start -->"
  "*Start delimiter for timestamps.
Everything between `html-helper-timestamp-start' and
`html-helper-timestamp-end' will be deleted and replaced with the output
of the functions `html-helper-timestamp-hook' if
`html-helper-do-write-file-hooks' is t")

(defvar html-helper-timestamp-end "<!-- hhmts end -->"
  "*End delimiter for timestamps.
Everything between `html-helper-timestamp-start' and
`html-helper-timestamp-end' will be deleted and replaced with the output
of the function `html-helper-insert-timestamp' if
`html-helper-do-write-file-hooks' is t")

;; control over what types of tags to load. By default, we load all the
;; ones we know of.

(defvar html-helper-types-to-install
  '(anchor list header logical phys textel entity image table head form script)
  "*List of tag types to install when html-helper-mode is first loaded.
If you want to not install some type of tag, override this variable.
Order is significant: menus go in this order.")

;; emacs18 detection.

(defvar html-helper-emacs18
  (and (boundp 'emacs-version)
       (or (and (boundp 'epoch::version) epoch::version)
           (string-lessp emacs-version "19")))
  "I'll do minimal emacs18 support, grumble.")
;;}}} end of defvars

;;}}} end of user variables

;;{{{ Prologue

(require 'tempo)			;essential part of html-helper-mode
(condition-case nil			;menu support, standard in emacs19
    (require 'auc-menu)			;add-on for XEmacs. *why* does this
  (error (require 'easymenu)))		;package have to have two names?

;; Wed Mar 28 09:55:29 2001 Saint
;;
;; Placing here (require 'psgml-html ) after a suggestion from Graham
;; Gough who explored the faces problem with XEmacs (many thanks)
(if (string-match "XEmacs\\|Lucid" (emacs-version))
      ;; This will initialize html-helper-bold-face
      (require 'psgml-html))

(require 'font-lock)
;;}}}

;;{{{ html-helper-mode-syntax-table and html-helper-mode-abbrev-table

;; emacs doesn't seem to be able to really handle SGML like syntax. In
;; particular, comments are a loss.
;; We do try this, though: give < and > matching semantics

(defvar html-helper-mode-syntax-table nil
  "Syntax table for html-helper.")

(if html-helper-mode-syntax-table
    ()
  (setq html-helper-mode-syntax-table (make-syntax-table text-mode-syntax-table))
  (modify-syntax-entry ?<  "(>  " html-helper-mode-syntax-table)
  (modify-syntax-entry ?>  ")<  " html-helper-mode-syntax-table)
  (modify-syntax-entry ?\" ".   " html-helper-mode-syntax-table)
  (modify-syntax-entry ?\\ ".   " html-helper-mode-syntax-table)
  (modify-syntax-entry ?'  "w   " html-helper-mode-syntax-table))

(defvar html-helper-mode-abbrev-table nil
  "Abbrev table used while in html-helper-mode.")
(define-abbrev-table 'html-helper-mode-abbrev-table ())

;;}}}

;;{{{ type based keymap and menu variable and function setup

;; Our basic keymap.
(defvar html-helper-mode-map (make-sparse-keymap)
  "Keymap for html-helper")
(defvar html-helper-mode-menu nil
  "Menu for html-helper. Clobbered and rebuilt by `html-helper-install-menu'")

;; html-helper-mode has a concept of "type" of tags. Each type is a
;; list of tags that all go together in one keymap and one menu.
;; Types can be added to the system after html-helper has been loaded,
;; briefly by doing html-helper-add-type-to-alist, then
;; html-helper-install-type, then html-helper-add-tag (for each tag)
;; then html-helper-rebuild-menu. See the mode documentation for more detail.

(defconst html-helper-type-alist nil
  "Alist: type of tag -> keymap, keybinding, menu, menu string.
Add to this with `html-helper-add-type-to-alist'.")

(defun html-helper-keymap-for (type)
  "Accessor function for alist: for type, return keymap or nil"
  (nth 0 (cdr-safe (assq type html-helper-type-alist))))

(defun html-helper-key-for (type)
  "Accessor function for alist: for type, return keybinding or nil"
  (nth 1 (cdr-safe (assq type html-helper-type-alist))))

(defun html-helper-menu-for (type)
  "Accessor function for alist: for type, return menu or nil"
  (nth 2 (cdr-safe (assq type html-helper-type-alist))))

(defun html-helper-menu-string-for (type)
  "Accessor function for alist: for type, return menustring or nil"
  (nth 3 (cdr-safe (assq type html-helper-type-alist))))

(defun html-helper-normalized-menu-for (type)
  "Helper function for building menus from submenus: add on string to menu."
  (cons (html-helper-menu-string-for type)
	(eval (html-helper-menu-for type))))

(defun html-helper-add-type-to-alist (type)
  "Add a type specification to the alist.
The spec goes (type . (keymap-symbol keyprefix menu-symbol menu-string)).
See code for an example."
  (setq html-helper-type-alist (cons type html-helper-type-alist)))

;; Here are the types provided by html-helper-mode.
(mapcar 'html-helper-add-type-to-alist
  '((entity  . (nil nil html-helper-entity-menu "Insert Character Entities"))
    (textel  . (nil nil html-helper-textel-menu "Insert Text Elements"))
    (head    . (html-helper-head-map "\C-c\C-h"
				     html-helper-head-menu
				     "Insert Structural Elements"))
    (header  . (html-helper-header-map "\C-c\M-h"
				       html-helper-header-menu
				       "Insert Headers"))
    (anchor  . (html-helper-anchor-map "\C-c\C-a"
				       html-helper-anchor-menu
				       "Insert Hyperlinks"))
    (logical . (html-helper-logical-map "\C-c\M-l"
					html-helper-logical-menu
					"Insert Logical Styles"))
    (phys    . (html-helper-phys-map "\C-c\C-p"
				     html-helper-phys-menu
				     "Insert Physical Styles"))
    (list    . (html-helper-list-map "\C-c\C-l"
				     html-helper-list-menu
				     "Insert List Elements"))
    (form    . (html-helper-form-map "\C-c\C-f"
				     html-helper-form-menu
				     "Insert Form Elements"))
    (image   . (html-helper-image-map "\C-c\C-i"
				      html-helper-image-menu
				      "Insert Inlined Images"))
    (table   . (html-helper-table-map "\C-c\C-t"
				      html-helper-table-menu
				      "Insert Tables"))
    (script  . (html-helper-script-map "\C-c\C-s"
				       html-helper-script-menu
				       "Insert Scripts"))
    ))

;; Once html-helper-mde is aware of a type, it can then install the
;; type: arrange for keybindings, menus, etc.

(defconst html-helper-installed-types nil
  "The types that have been installed (used when building menus).
There is no support for removing a type once it has been installed.")

;; For easy ASP/JSP switch
(defun html-helper-use-JSP-this-buffer ()
  (interactive)
  (setq html-helper-mode-local-JSP-not-ASP t)
  (setq mode-name "HTML/JSP helper")
  (setq major-mode 'jsp-html-helper-mode))

(defun html-helper-use-ASP-this-buffer ()
  (interactive)
  (cond (html-helper-mode-uses-visual-basic
	 (setq html-helper-mode-local-JSP-not-ASP nil)
	 (setq mode-name "HTML/ASP helper")
	 (setq major-mode 'asp-html-helper-mode))
	(t (error "Visual basic mode required for ASP"))))

(defun html-helper-install-type (type)
  "Install a new tag type: add it to the keymap, menu structures, etc.
For this to work, the type must first have been added to the list of types
with html-helper-add-type-to-alist."
  (setq html-helper-installed-types (cons type html-helper-installed-types))
  (let ((keymap (html-helper-keymap-for type))
	(key (html-helper-key-for type))
	(menu (html-helper-menu-for type))
	(menu-string (html-helper-menu-string-for type)))
    (and key
	 (progn
	   (set keymap nil)
	   (define-prefix-command keymap)
	   (if html-helper-emacs18
	       (progn
		 (set keymap (make-sparse-keymap))
		 (define-key html-helper-mode-map key (eval keymap)))
	     (define-key html-helper-mode-map key keymap))))
    (and menu
	 (progn
	   (set menu nil)))))

;; install the default types.
(mapcar 'html-helper-install-type html-helper-types-to-install)

;; special mode keys
(mapcar
 (function (lambda (l) (define-key html-helper-mode-map (car l) (nth 1 l))))
 '(("\M-\C-f" tempo-forward-mark)
   ("\M-\C-b" tempo-backward-mark)
   ("\M-\t"   tempo-complete-tag)))

;; Extra commands that HTML helper supports that aren't insertions
(defvar html-helper-mode-functions-map nil
  "Keymap for extra HTML mode functions")

(define-prefix-command 'html-helper-mode-functions-map)
(define-key html-helper-mode-map "\C-c\C-z"
  'html-helper-mode-functions-map)
(define-key html-helper-mode-functions-map "t"
  'html-helper-insert-timestamp-delimiter-at-point)
(define-key html-helper-mode-functions-map "a"
  'html-script-narrow-to-asp)
(define-key html-helper-mode-functions-map "p"
  'html-script-narrow-to-php)
(define-key html-helper-mode-functions-map "b"
  'html-script-narrow-to-vbscript)
(define-key html-helper-mode-functions-map "j"
  'html-script-narrow-to-javascript)
(define-key html-helper-mode-functions-map "c"
  'html-script-narrow-to-css)

;; indentation keys - only rebind these if the user wants indentation
(if html-helper-never-indent
    ()
  (define-key html-helper-mode-map "\t" 'html-helper-indent-command)
  (define-key html-helper-mode-map "\C-m" 'newline-and-indent))

;; browse url stuff
(if (fboundp 'browse-url-of-file)
    (define-key html-helper-mode-functions-map "v" 'browse-url-of-file))

;; Fri Jan 12 18:30:32 2001 Saint
;;
;; Jack Vinson supplies this code to handle the case when
;; browse-url-browser-function is a list and not a function (it can be
;; a list, says its documentation)
;;
;; Replacing :
;; (if (and (boundp 'browse-url-browser-function)
;; 	 (fboundp browse-url-browser-function))
;;     (define-key html-helper-mode-functions-map "u"
;;       browse-url-browser-function))

(if (boundp 'browse-url-browser-function)
    (let ((bf browse-url-browser-function)
	  re)
      (while (consp bf)
	(setq re (car (car bf))
	      bf (if (string-match re "http")
		     (cdr (car bf))	; The function
		   (cdr bf))))		; More pairs
      (or bf (error "No browser in browse-url-browser-function for =
general URL's"))
      (fboundp bf)
      (define-key html-helper-mode-functions-map "u" bf)
      ))

;;}}}

;;{{{ html-helper-add-tag function for building basic tags

(defvar html-helper-tempo-tags nil
  "List of tags used in completion.")

;; this while loop is awfully Cish
;; isn't there an emacs lisp function to do this?
(defun html-helper-string-to-symbol (input-string)
  "Given a string, downcase it and replace spaces with -.
We use this to turn menu entries into good symbols for functions.
It's not entirely successful, but fortunately emacs lisp is forgiving."
  (let* ((s (copy-sequence input-string))
	 (l (1- (length s))))
    (while (> l 0)
      (if (char-equal (aref s l) ?\ )
	  (aset s l ?\-))
      (setq l (1- l)))
    (concat "html-" (downcase s))))


(defun html-helper-add-tag (l)
  "Add a new tag to html-helper-mode.
Builds a tempo-template for the tag and puts it into the
appropriate keymap if a key is requested. Format:
`(html-helper-add-tag '(type keybinding completion-tag menu-name template doc)'"
  (let* ((type (car l))
	 (keymap (html-helper-keymap-for type))
	 (menu (html-helper-menu-for type))
	 (key (nth 1 l))
	 (completer (nth 2 l))
	 (name (nth 3 l))
	 (tag (nth 4 l))
	 (doc (nth 5 l))
	 (command (if (string-equal completer "function")
		      (nth 4 l)
		      (tempo-define-template (html-helper-string-to-symbol name)
					 tag completer doc
					 'html-helper-tempo-tags))))

    (if (null (memq type html-helper-installed-types))    ;type loaded?
	t                                                 ;no, do nothing.
      (if (stringp key)			                  ;bind key somewhere?
	  (if keymap			                  ;special keymap?
	      (define-key (eval keymap) key command)      ;t:   bind to prefix
	    (define-key html-helper-mode-map key command));nil: bind to global
	t)
      (if menu				                  ;is there a menu?
	  (set menu			                  ;good, cons it in
	       (cons (vector name command t) (eval menu))))
      )))

;; for backwards compatability
(fset 'html-helper-add-cookie 'html-helper-add-tag)

;;}}}

;;{{{ most of the HTML tags


(defun html-helper-insert-or-wipe (string)
  "Propmts for the value of an optional attribute named STRING and
inserts it in the current buffer. Inserts nothing if the users replies
with a null string."
  (cond ((and (stringp string)
	      tempo-interactive)
	 (let ((val (read-from-minibuffer (concat string " :"))))
	   (cond ((> (string-width val) 0)
		  (insert-string (concat " " string "=\"" val "\"" )))
	  )))
	;; just to tell that there's something weird in the calling
	;; code... But behaves like a no op if tempo-interactive is
	;; nil
	(tempo-interactive
	 (error (concat "Wrong type argument: stringp, " string)))
	;; Wed Mar 28 10:06:24 2001 Saint
	;;
 	;; To insert empty attributes if
	;; html-helper-mode-insert-attributes-always is non nil
	((and (stringp string)
	      html-helper-mode-insert-attributes-always)
	 (insert-string (concat " " string "=\"\"" )))
	      ))

;; These tags are an attempt to be HTML/2.0 compliant, with the exception
;; of container <p>, <li>, <dd>, <dt> (we adopt 3.0 behaviour).
;; For reference see <URL:http://www.w3.org/hypertext/WWW/MarkUp/MarkUp.html>

;; order here is significant: within a tag type, menus and mode help
;; go in the reverse order of what you see here. Sorry about that, it's
;; not easy to fix.

(mapcar
 'html-helper-add-tag
 '(
   ;;entities
   (entity  "\C-c#"   "&#"              "Ascii Code"      ("&#" (r "Ascii: ") ";"))
   (entity  "\C-c\""  "&quot;"          "Quotation mark"  ("&quot;"))
   (entity  "\C-c$"   "&reg;"           "Registered"      ("&reg;"))
   (entity  "\C-c@"   "&copy;"          "Copyright"       ("&copy;"))
   (entity  "\C-c-"   "&shy;"           "Soft Hyphen"     ("&shy;"))
   (entity  "\C-c "   "&nbsp;"		"Nonbreaking Space"  ("&nbsp;"))
   (entity  "\C-c&"   "&amp;"		"Ampersand"	  ("&amp;"))
   (entity  "\C-c>"   "&gt;"	  	"Greater Than"       ("&gt;"))
   (entity  "\C-c<"   "&lt;"		"Less Than"	  ("&lt;"))
   ;; letters with accents common in italian
   (entity  "\C-ca"   "&agrave;"        "a` (&&agrave;)"          ("&agrave;"))
   (entity  "\C-ce"   "&egrave;"        "e` (&&egrave;)"          ("&egrave;"))
   (entity  "\C-cE"   "&eacute;"        "e' (&&eacute;)"          ("&eacute;"))
   (entity  "\C-co"   "&ograve;"        "o` (&&ograve;)"          ("&ograve;"))
   (entity  "\C-ci"   "&igrave;"        "i` (&&igrave;)"          ("&igrave;"))
   (entity  "\C-cu"   "&ugrave;"        "u` (&&ugrave;)"          ("&ugrave;"))

   ;; logical styles
   (logical "b"       "<blockquote>"	"Blockquote"
	    ("<blockquote>" (r "Quote: ") "</blockquote>"))
   (logical "c"       "<code>"		"Code"
	    ("<code>" (r "Code: ") "</code>"))
   (logical "x"       "<samp>"		"Sample"
	    ("<samp>" (r "Sample code: ") "</samp>"))
   (logical "r"       "<cite>"		"Citation"
	    ("<cite>" (r "Citation: ") "</cite>"))
   (logical "k"       "<kbd>"		"Keyboard Input"
	    ("<kbd>" (r "Keyboard: ") "</kbd>"))
   (logical "v"       "<var>"		"Variable"
	    ("<var>" (r "Variable: ") "</var>"))
   (logical "d"       "<dfn>"		"Definition"
	    ("<dfn>" (r "Definition: ") "</dfn>"))
   (logical "a"	      "<address>"	"Address"
	    ("<address>" r "</address>"))
   (logical "e"       "<em>"		"Emphasized"
	    ("<em>" (r "Text: ") "</em>"))
   (logical "s"       "<strong>"	"Strong"
	    ("<strong>" (r "Text: ") "</strong>"))
   (logical "p"       "<pre>"		"Preformatted"
	    ("<pre>" (r "Text: ") "</pre>"))

   ;;physical styles
   (phys    "s"       "<strike>"	"Strikethru"
	    ("<strike>" (r "Text: ") "</strike>"))
   (phys    "u"       "<u>"		"Underline"
	    ("<u>" (r "Text: ") "</u>"))
   (phys    "i"       "<i>"		"Italic"
	    ("<i>" (r "Text: ") "</i>"))
   (phys    "b"	      "<b>"    		"Bold"
	    ("<b>" (r "Text: ") "</b>"))
   (phys    "f"       "<tt>"		"Fixed"
	    ("<tt>" (r "Text: ") "</tt>"))
   (phys    "c"       "<center>"        "Center"
	    ("<center>" (r "Text: ") "</center>"))

;; html4.0 stuff, omitted

   (phys    "5" "<span style=" "Spanning style"
	     ("<span style=\"" (p "style: ") "\">" 'r "</span>"))
   (phys    "l" "<span class=" "Spanning class"
	     ("<span class=\"" (p "class: ") "\">" 'r "</span>"))


   ;;headers
   (header  "6"       "<h6>"		"Header 6"
	    ("<h6>" (r "Header: ") "</h6>"))
   (header  "5"       "<h5>"		"Header 5"
	    ("<h5>" (r "Header: ") "</h5>"))
   (header  "4"       "<h4>"		"Header 4"
	    ("<h4>" (r "Header: ") "</h4>"))
   (header  "3"       "<h3>"		"Header 3"
	    ("<h3>" (r "Header: ") "</h3>"))
   (header  "2"       "<h2>"		"Header 2"
	    ("<h2>" (r "Header: ") "</h2>"))
   (header  "1"	      "<h1>"     	"Header 1"
	    ("<h1>" (r "Header: ") "</h1>"))

   ;; forms
   (form    "o"       "<option>"        "Option"
	    (& "<option>" > ))
   (form    "v"       "<option value"   "Option with Value"
	    (& "<option value=\"" (r "Value: ") "\">" >))
   (form    "s"       "<select"		"Selections"
	    ("<select"
	     (html-helper-insert-or-wipe "name") ">\n<option>" > "\n</select>")"<select")
   (form    "z"	      "<input"		"Reset Form"
	    ("<input type=\"RESET\""
	     (html-helper-insert-or-wipe "value") ">"))
   (form    "m"	      "<input"		"Submit Form"
	    ("<input type=\"SUBMIT\""
	     (html-helper-insert-or-wipe "value") ">"))
   (form    "b"       "<input"          "Button"
	    ("<input type=\"BUTTON\""
	     (html-helper-insert-or-wipe "value")
	     (html-helper-insert-or-wipe "name") ">"))
   (form    "i"	      "<input"		"Image Field"
	    ("<input type=\"IMAGE\""
	     (html-helper-insert-or-wipe "Name")
	     (html-helper-insert-or-wipe "src") ">"))
   (form    "h"       "<input"          "Hidden Field"
	    ("<input type=\"HIDDEN\""
	     (html-helper-insert-or-wipe "name")
	     (html-helper-insert-or-wipe "value") ">"))
   (form    "p"	      "<textarea"	"Text Area"
	    ("<textarea"
	     (html-helper-insert-or-wipe "name")
	     (html-helper-insert-or-wipe "rows")
	     (html-helper-insert-or-wipe "cols") ">" r "</textarea>"))
   (form    "c"	      "<input"		"Checkbox"
	    ("<input type=\"CHECKBOX\""
	     (html-helper-insert-or-wipe "name") ">"))
   (form    "r"	      "<input"		"Radiobutton"
	    ("<input type=\"RADIO\""
	     (html-helper-insert-or-wipe "Name") ">"))
   (form    "t"	      "<input"		"Text Field"
	    ("<input type=\"TEXT\""
	     (html-helper-insert-or-wipe "name")
	     (html-helper-insert-or-wipe "size") ">"))
   (form    "f"	      "<form"           "Form"
	    ("<form"
	     (html-helper-insert-or-wipe "action")
	     (html-helper-insert-or-wipe "method") ">\n</form>\n"))

   ;;lists
   (list    "t"       "<dt>"            "Definition Item"
	    (& "<dt>" > (r "Term: ") "\n<dd>" >
	       (r "Definition: ")))
   (list    "l"       "<li>"            "List Item"
	    (& "<li>" > (r "Item: ") > "</li>"))
   (list    "r"	      "<dir>"		"DirectoryList"
	    (& "<dir>" > "\n<li>" > (r "Item: ") "\n</li>" > "\n</dir>" >))
   (list    "m"	      "<menu>"		"Menu List"
	    (& "<menu>" > "\n<li>" > (r "Item: ") "\n</li>" > "\n</menu>" >))
   (list    "o"	      "<ol>"		"Ordered List"
	    (& "<ol>" > "\n<li>" > (r "Item: ") "\n</li>" > "\n</ol>" >))
   (list    "d"	      "<dl>"		"Definition List"
	    (& "<dl>" > "\n<dt>" >
	       (p "Term: ") "\n<dd>" >
	       (r "Definition: ") "\n</dl>" >))
   (list    "u"	      "<ul>"		"Unordered List"
	    (& "<ul>" > "\n<li>" > (r "Item: ") "\n</li>\n</ul>" >))

   ;;anchors
   (anchor  "n"	      "<a name="	"Link Target"
	    ("<a " (html-helper-insert-or-wipe "name") ">"
	     (r "Anchor text: ") "</a>"))
   (anchor  "l"	      "<a href="        "Hyperlink"
	    ("<a href=\"" (p "href: ") "\" >"
	     (r "Anchor text: ") "</a>"))

   ;;graphics
;    (image   "a"       nil               "Aligned Image"
; 	    ("<img align=\""
; 	     (r "Alignment: ") "\" src=\"" (r "Image URL: ") "\">"))
;    (image   "i"       "<img src="	"Image"
; 	    ("<img src=\""
; 	     (r "Image URL: ") "\">"))
;    (image   "e"       "<img align="     "Aligned Image With Alt. Text"
; 	    ("<img align=\""
; 	     (r "Alignment: ") "\" src=\""
; 	     (r "Image URL: ") "\" alt=\""
; 	     (r "Text URL: ") "\">"))
;    (image   "t"       "<img alt="	"Image With Alternate Text"
; 	    ("<img alt=\""
; 	     (r "Text URL: ") "\" src=\""
; 	     (r "Image URL: ") "\">"))
;; New, (almost) all including, single menu item entry
;; src has to be there!
   (image	"a"	nil	"Image"
		("<img src=\""
		 (p "src" ) "\" "
		 (html-helper-insert-or-wipe  "alt" )
		 (html-helper-insert-or-wipe  "height" )
		 (html-helper-insert-or-wipe  "width" )
		 (html-helper-insert-or-wipe  "align" )
		 ">"))
   ;; table
   (table   "t"       "<table>"         "Table"
	    ("<table"
	     (html-helper-insert-or-wipe  "border" )
	     (html-helper-insert-or-wipe "width" )">\n</table>"))
   (table   "r"       "<tr>"         "Table Row"
	    ("<TR>\n</TR>"))
   (table   "h"       "<th>"         "Table Header"
	    ("<TH"
	     (html-helper-insert-or-wipe "rowspan" )
	     (html-helper-insert-or-wipe "colspan")">\n</TH>"))
   (table   "d"       "<td>"         "Table Data"
	    ("<TD"
	     (html-helper-insert-or-wipe "align" )
	     (html-helper-insert-or-wipe "colspan")"></TD>"))
   (table   "p"	"<caption>"	"html table caption"
	    ("<caption>" (r . "Table: ") "</caption>"))
   ;;text elements
   (textel  "\C-c="    nil		"Horizontal Line"
	    (& "<hr>\n"))
   (textel  "\C-c\C-m" nil		"Line Break"
	    ("<br>\n"))
   (textel  "\e\C-m"  nil		"Paragraph"
	    ("<p>"
	     (r "Text: ") "</p>"))

   ;;head elements
   (head    "H"       "<head>"          "Head"
	    ("<head>\n" "</head>\n"))
   (head    "B"       "<body>"          "Body"
	    ("<body>\n" "</body>\n"))
   (head    "i"	      "<isindex>"	"Isindex"
	    ("<isindex>\n"))
   (head    "n"	      "<nextid>"	"Nextid"
	    ("<nextid>\n"))
   (head    "h"       "<meta http-equiv=" "HTTP Equivalent"
	    ("<meta"
	     (html-helper-insert-or-wipe "http-equiv") " content=\""
	     (r "Content: ") "\">\n"))
   (head    "m"       "<meta name="     "Meta Name"
	    ("<meta"
	     (html-helper-insert-or-wipe "name") " content=\""
	     (r "Content: ") "\">\n"))
   (head    "l"	      "<link"		"Link"
	    ("<link href=\"" p "\">"))
   (head    "b"       "<base"		"Base"
	    ("<base href=\"" r "\">"))
   (head    "t"	      "<title>"		"Title"
	    ("<title>" (r "Document title: ") "</title>"))
   ;; scripting elements
   (script  "j"    "<SCRIPT>"       "JavaScript"
	    ("<SCRIPT TYPE=\"text/javascript\">\n"
	     (r "Script: ") "</SCRIPT>"))
   (script  "v"    "<SCRIPT>"       "VBScript"
	    ("<SCRIPT TYPE=\"text/vbscript\">\n"
	     (r "Script: ") "</SCRIPT>"))
   (script  "%"    "<%="            "ASP output"
	    ("<%="(p " Variable: ")"%>"))
   (script  "a"    "<%xx%>"         "JSP/ASP code"
	    ("<%\n"(r "Code: " )"\n%>"))
   (script  "<"    "<%xx%>"         "JSP/ASP break"
	    ("%>\n"(r "Code: " )"\n<%"))
   (script  "="    "<?="            "PHP output"
	    ("<?="(p " Variable: ")"?>"))
   (script  "p"    "<?xx?>"         "PHP code"
	    ("<? PHP\n"(r "Code: " )"\n?>"))
   (script  "?"    "<?xx?>"         "PHP break"
	    ("?>\n"(r " Code: " )"\n<? PHP"))
   ))

;;}}}

;;{{{ html-helper-smart-insert-item

;; there are two different kinds of items in HTML - those in regular
;; lists <li> and those in dictionaries <dt>..<dd>
;; This command will insert the appropriate one depending on context.

(defun html-helper-smart-insert-item (&optional arg)
  "Insert a new item, either in a regular list or a dictionary."
  (interactive "*P")
  (let ((case-fold-search t))
    (if
        (save-excursion
          (re-search-backward "<li>\\|<dt>\\|<ul>\\|<ol>\\|<dd>\\|<menu>\\|<dir>\\|<dl>" nil t)
          (looking-at "<dt>\\|<dl>\\|<dd>"))
        (tempo-template-html-definition-item arg)
      (tempo-template-html-list-item arg))))

;; special keybindings in the prefix maps (not in the list of tags)
(and (boundp 'html-helper-list-map)
     (define-key html-helper-list-map "i" 'html-helper-smart-insert-item))

;; and, special menu bindings
(and (boundp 'html-helper-list-menu)
     (setq html-helper-list-menu
	   (cons '["List Item" html-helper-smart-insert-item t] html-helper-list-menu)))

;;}}}

;;{{{ menu support

;; menus are built for easymenu. html-helper-add-tag builds
;; submenus based on tag type, the expert menu code lumps them
;; together into one list and calls easy-menu-define

(defvar html-helper-novice-menu
  '("HTML"
    ["Insert Paragraph" tempo-template-html-paragraph t]
    ["Insert Hyperlink" tempo-template-html-hyperlink t]
    ["Insert Big Header" tempo-template-html-header-2 t]
    ["Insert Unordered List" tempo-template-html-unordered-list t]
    ["Insert List Item" html-helper-smart-insert-item t]
    ["Insert Inlined Image" tempo-template-html-image-with-alternate-text t]
    ["Turn on Expert Menu" html-helper-toggle-expert-menu t])
  "Menu for novices, only installed if `html-helper-use-expert-menu is nil'")

(defun html-helper-menu nil
  "Return the proper menu. Looks at `html-helper-use-expert-menu'"
  (if html-helper-use-expert-menu
      (html-helper-expert-menu)
    html-helper-novice-menu))

(defun html-helper-rebuild-menu nil
  "Rebuild and install the HTML menu (using `easy-menu-define').
If `html-helper-use-expert-menu' is nil, then just use a novice menu."
  (let ((menu (html-helper-menu)))
    (easy-menu-remove menu)
    (easy-menu-define html-helper-mode-menu-symbol
		      html-helper-mode-map "HTML menus" menu)
    (easy-menu-add menu html-helper-mode-map)))

(defun html-helper-toggle-expert-menu (&optional arg)
  "Toggle full HTML menus. Optional arg acts like minor-mode args."
  (interactive "P")
  (setq html-helper-use-expert-menu
	(if (null arg) (not html-helper-use-expert-menu)
	  (> (prefix-numeric-value arg) 0)))
  (html-helper-rebuild-menu))

;; If browse-url loaded, add this in the novice menu.
(if (fboundp 'browse-url-of-file)
    (setq html-helper-novice-menu
	  (append html-helper-novice-menu
		  (list ["Load This Buffer in Browser" browse-url-of-file t]))))

;; Narrrowing to scripts, this don't use tempo because has to call functions
;; and not insert templates


;; Expert menus: consed up out of html-helper-installed-types
(defun html-helper-expert-menu ()
  "This menu is based on the current value of `html-helper-installed-types'.
This function can be called again, it redoes the entire menu."
  ;; first, reset this so we can call this again and again.
  (setq html-helper-mode-menu nil)

  ;; Cons in the toggle of the menu
  (setq html-helper-mode-menu
	(cons '["Turn on Novice Menu"
		html-helper-toggle-expert-menu t]
	      html-helper-mode-menu))

  ;; Now add in user-provided menu stuff
  (setq html-helper-mode-menu
	(append html-helper-user-menu html-helper-mode-menu))

  ;; Now cons in the browse-url functions
  (if (fboundp 'browse-url-of-file)
    (setq html-helper-mode-menu
	  (cons '["Load this Buffer in Browser" browse-url-of-file t]
		html-helper-mode-menu)))

  ;; Mon Jan 15 07:49:39 2001 Saint
  ;;
  ;; Jack Vinson supplied this code to handle the case where
  ;; browse-url-browser-function is a list, too
  (if (boundp 'browse-url-browser-function)
      (let ((bf browse-url-browser-function)
	    re)
	(while (consp bf)
	  (setq re (car (car bf))
		bf (if (string-match re "http")
		       (cdr (car bf))	; The function
		     (cdr bf))))		; More pairs
	(or bf
	    (error
	     "No browser in browse-url-browser-function for general URL's"))
	(fboundp bf)
	(setq html-helper-mode-menu
	      (cons (vector "Browse URL at point" bf t)
		    html-helper-mode-menu))))

  ;; cons in the timestamp delimiters
  (setq html-helper-mode-menu
	(cons '["Insert Timestamp Delimiter"
		html-helper-insert-timestamp-delimiter-at-point t]
	      html-helper-mode-menu))

  ;; cons script narrowing
  (setq html-helper-mode-menu
	(append html-helper-mode-menu
		(list ["Narrow to ASP" html-script-narrow-to-asp t])))
  (setq html-helper-mode-menu
	(append html-helper-mode-menu
		(list ["Narrow to PHP" html-script-narrow-to-php t])))
  (setq html-helper-mode-menu
	(append html-helper-mode-menu
		(list ["Narrow to VBScript" html-script-narrow-to-vbscript t])))
   (setq html-helper-mode-menu
	 (append html-helper-mode-menu
		 (list ["Narrow to JavaScript" html-script-narrow-to-javascript t])))
   (setq html-helper-mode-menu
	 (append html-helper-mode-menu
		 (list ["Narrow to CSS" html-script-narrow-to-css t])))
   (setq html-helper-mode-menu
	 (append html-helper-mode-menu
		 (list ["Use ASP" html-helper-use-ASP-this-buffer  t])))

   (setq html-helper-mode-menu
	 (append html-helper-mode-menu
		 (list ["Use JSP" html-helper-use-JSP-this-buffer t])))

  ;; now cons up the main menu out of the submenus
  (mapcar
   (function (lambda (type)
	       (setq html-helper-mode-menu
		     (cons (html-helper-normalized-menu-for type)
			   html-helper-mode-menu))))
	  html-helper-installed-types)

  ;; now tack on our name
  (setq html-helper-mode-menu (cons "HTML" html-helper-mode-menu))
  html-helper-mode-menu)

(html-helper-rebuild-menu)

;;}}}

;;{{{ context guessing

;; guess where we are in indented lists based on the last list token.
;; it would be much better to try to match </ul> to <ul>, and </ol> to <ol>
;; etc, but that is pretty unwieldy and slow.
;; Note, we make select/option look like a list structure too, so indentation
;; works. This is a bit weird, but it's ok.

;; Wed Jan 10 09:01:06 2001 Saint
;;
;; Changed regexps to handle tags with attributes
(defvar html-helper-any-list-item-start
  ;;  "<li>\\|<dt>\\|<dd>\\|<option\\|<th>\\|<td>")
  "<li\W\\|<dt\\|<dd\\|<option\\|<th\\|<td\\|<tbody\\|<div")
(defvar html-helper-any-list-item-end "</li>\\|</dt>\\|</dd>\\|</th\\|</td\\|</tbody>\\|</div>")
(defvar html-helper-any-list-start
  ;;  "<dl>\\|<ul>\\|<ol>\\|<menu>\\|<dir>\\|<select\\|<table\\|<tr>")
  "<dl\\|<ul\\|<ol\\|<menu\\|<dir\\|<select\\|<table\\|<tr")
(defvar html-helper-any-list-end "</dl>\\|</ul>\\|</ol>\\|</menu>\\|</dir>\\|</select>\\|</table>\\|</tr>")
(defvar html-helper-any-list
  (format "\\(%s\\)\\|\\(%s\\)\\|\\(%s\\)\\|\\(%s\\)"
	  html-helper-any-list-start
	  html-helper-any-list-end
	  html-helper-any-list-item-start
	  html-helper-any-list-item-end))
;; Wed Jan 10 09:50:53 2001 Saint
;;
;; New indentation. As for other modes leave a single indentation
;; sensible tag on each line.
(defvar html-helper-indentation-list html-helper-any-list)
  ;;  (format "\\(%s\\)\\|\\(%s\\)\\|\\(%s\\)"
  ;;	  html-helper-any-list-start
  ;;	  html-helper-any-list-end
  ;;	  html-helper-any-list-item-start))
(defvar html-helper-search-limit 2000 "limit on how far back we search")

(defun html-helper-context-symbol ()
  "Return the symbol the last match (against `html-helper-any-list') found."
  (cond ((match-beginning 1) 'list-start)
	((match-beginning 2) 'list-end)
	((match-beginning 3) 'item-start)
	((match-beginning 4) 'item-end)
	(t 'error)))

; Wed Jan 10 09:53:46 2001 Saint
;
; Doesn't ignore item-end any more.
(defun html-helper-guess-prev-context ()
  "Figure out the last list-type tag before point relevant to indentation.
Returns 'item-start if the last list tag is a list item start
        'list-start if the last list tag is the start of a list
        'item-end   if the last list tag is the end of a list item
        'list-end   if the last list tag is the end of a list."
  (save-excursion
    (let* ((lim (max (point-min) (- (point) html-helper-search-limit)))
	   (context (if (re-search-backward html-helper-indentation-list lim t)
			(html-helper-context-symbol)
		      nil)))
      (cons context (current-indentation)))))

(defun html-helper-print-prev-context ()
  (interactive)
  (message "%s" (html-helper-guess-prev-context)))

;;}}}

;;{{{ indentation
(defvar html-helper-buffers nil "buffers using html-helper-mode alist")

(defvar html-helper-print-indent-info nil
  "If t, indent will print out information as a message.")

(defun html-helper-indent-command ()
  "Command for indenting HTML to the appropriate column.
Calls `html-helper-indent' which tries to examine how many levels down
in nested lists we are and does the appropriate indentation.'
See also `html-helper-basic-offset' and `html-helper-never-indent'."
  (interactive)
  (html-helper-indent))

;; some ideas borrowed from cc-mode.el.
;; Basic logic:
;;   if this line is some sort of list token, indent according to prev context:
;;     if previous context was a list-end or item-start, use its indentation
;;     if previous context was a list start, indent forward basic-offset
;;     ignore previous list-ends, their indentation is unreliable.
;;     then if this is some sort of list-item, do special case fixups:
;;       if this is a item start or end and previous was a list end, go back
;;           item-continue-indent (the </ul> is probably indented for an <li>
;;       if this is a list end and previous was a list end, go back
;;           item-continue-indent (the </ul> is probably indented for an <li>
;;       if this is a list end and prev *not* a list end, go back basic-offset
;;   else if this line is not a list item, and previous line is a item-start
;;     indent continue-indent, because this is part of the item

;; code to never indent <PRE></PRE> sections. Many thanks to
;; Stan Lanning <lanning@pobox.com>
(defun html-helper-indent-leave-alone-p ()
  (let* ((pre (save-excursion (search-backward "<pre>" nil t)))
	 (endpre (save-excursion (search-backward "</pre>" pre t))))
    (and pre (null endpre))))

(defadvice html-helper-indent (around leave-pre-alone activate)
  (cond ((not (html-helper-indent-leave-alone-p))
	 ad-do-it)
	(html-helper-print-indent-info
	 (message "In <pre> -- skipping indentation"))
	(t nil)))

(defun html-helper-indent ()
  "Indentation workhorse function."
  (if html-helper-never-indent
      ()
    (let ((m (point-marker))
	  (bol (progn (beginning-of-line) (point))))

      ;; unindent the line
      (delete-region (point) (progn (back-to-indentation) (point)))

      (let* ((where (html-helper-guess-prev-context))
	     (prev-context (car where))
	     (this-context nil)
	     (previ (cdr where))
	     (newi (cond
		    ((eq prev-context 'list-end) previ)
		    ((eq prev-context 'item-start) previ)
		    ((eq prev-context 'list-start) (+ previ html-helper-basic-offset))
		    (t previ))))

	;; newi is set to the basic indentation, now adjust indentation
	;; based on what the current line is.
	(if (looking-at html-helper-any-list)
	    (progn
	      (setq this-context (html-helper-context-symbol))
	      (cond
	       ;; item start or end and last line was a list-end: go backwards
	       ((and
		 (or (eq this-context 'item-start) (eq this-context 'item-end))
		 (eq prev-context 'list-end))
		(setq newi (- newi html-helper-basic-offset)))

	       ;; end of list and last line was an end: go backwards twice
	       ((and (eq this-context 'list-end) (eq prev-context 'list-end))
		;; Wed Jan 10 09:35:53 2001 Saint
		;;
		;; fixing indentation
		;;		(setq newi (- newi html-helper-basic-offset html-helper-item-continue-indent)))
		(setq newi (- newi html-helper-basic-offset)))

	       ;; Any other end of list? Indent negative
	       ((and (eq this-context 'list-end))
		(setq newi (- newi html-helper-basic-offset)))

	       ;; start of list and last line beginning of item, go forwards
	       ((and (eq this-context 'list-start)
		     (eq prev-context 'item-start))
		(setq newi (+ newi html-helper-basic-offset)))))

	  ;; default: no special case, indent forward for text
	  (cond
	   ;; last line an item? Beginning of continued item - go forward
	   ((eq prev-context 'item-start)
	    (setq newi (+ newi html-helper-basic-offset)))))

	(if html-helper-print-indent-info
	    (message
	     "Last Context: %s, This Context: %s, Previous: %s New: %s"
	     prev-context this-context previ newi))

	;; just in case
	(if (< newi 0)
	    (setq newi 0))
	(indent-to newi newi)

	;; adjust point to where it was before, or at start of indentation
	(goto-char (marker-position m))
	(if (< (current-column) (current-indentation))
	    (back-to-indentation))))))

;;}}}

;;{{{ completion finder for tempo

(defvar html-helper-completion-finder
  (if html-helper-emacs18
      'html-helper-emacs18-completion-finder
    "\\(\\(<\\|&\\).*\\)\\=")
  "Passed to tempo-use-tag-list, used to find tags to complete.")

;; The regexp finds everything between the last < or & and point,
;; which is good enough to match the tags HTML might complete.
;; emacs18 doesn't have the \= for regexps, though, so we do something
;; more hackish.

(defun html-helper-emacs18-completion-finder ()
  "Unfortunately emacs18 doesn't support \\= in regexps, so we do this hack.
If you have problems with it, maybe you should upgrade to emacs19 :-)"
  (let* ((where nil)
         (s (buffer-substring
             (point)
             (setq where (save-excursion
                           (re-search-backward "<\\|&" (min (point-min) 100) t)
                           (point))))))
    (cons s where)))

;;}}}

;;{{{ timestamps

(defun html-helper-update-timestamp ()
  "Basic function for updating timestamps.
It finds the timestamp in the buffer by looking for
`html-helper-timestamp-start', deletes all text up to
`html-helper-timestamp-end', and runs `html-helper-timestamp-hook' which
will should insert an appropriate timestamp in the buffer."
  (save-excursion
    (goto-char (point-max))
    (if (not (search-backward html-helper-timestamp-start nil t))
	(message "timestamp delimiter start was not found")
      (let ((ts-start (+ (point) (length html-helper-timestamp-start)))
	    (ts-end (if (search-forward html-helper-timestamp-end nil t)
			(- (point) (length html-helper-timestamp-end))
		      nil)))
	(if (not ts-end)
	    (message "timestamp delimiter end was not found. Type C-c C-t to insert one.")
	  (delete-region ts-start ts-end)
	  (goto-char ts-start)
	  (run-hooks 'html-helper-timestamp-hook)))))
  nil)

(defun html-helper-default-insert-timestamp ()
  "Default timestamp insertion function."
  (let ((time (current-time-string)))
    (insert "Last modified: "
	    (substring time 0 20)
	    (nth 1 (current-time-zone))
	    " "
	    (substring time -4)
	    " ")))

(defun html-helper-insert-timestamp-delimiter-at-point ()
  "Simple function that inserts timestamp delimiters at point.
Useful for adding timestamps to existing buffers."
  (interactive)
  (insert html-helper-timestamp-start)
  (insert html-helper-timestamp-end))

;;}}}

;;{{{ html-helper-insert-new-buffer-strings

(tempo-define-template "html-skeleton" html-helper-new-buffer-template
		       nil
		       "Insert a skeleton for a HTML document")

(tempo-define-template "ASP-skeleton" html-helper-new-ASP-buffer-template
		       nil
		       "Insert a skeleton for a ASP document")

(tempo-define-template "PHP-skeleton" html-helper-new-PHP-buffer-template
		       nil
		       "Insert a skeleton for a PHP document")

(tempo-define-template "JSP-skeleton" html-helper-new-JSP-buffer-template
		       nil
		       "Insert a skeleton for a JSP document")

(defun html-helper-insert-new-buffer-strings ()
  "Insert `html-helper-new-buffer-strings'."
  (tempo-template-html-skeleton))

(defun html-helper-insert-new-ASP-buffer-strings ()
  "Insert `html-helper-new-ASP-buffer-strings' or `html-helper-new-JSP-buffer-string'."
  (cond (html-helper-mode-local-JSP-not-ASP
	 (tempo-template-JSP-skeleton))
	(t
	 (tempo-template-ASP-skeleton))))

(defun html-helper-insert-new-PHP-buffer-strings ()
  "Insert `html-helper-new-PHP-buffer-strings'."
  (tempo-template-PHP-skeleton))

;;}}}

;;{{{ html-helper-mode

(defun base-html-helper-mode (mode)
  "basic mode, called by the exported modes with MODE telling what
is the mode to run (that's the skeleton to insert in empty files)"
  (kill-all-local-variables)

  (use-local-map html-helper-mode-map)
  (setq local-abbrev-table html-helper-mode-abbrev-table)
  (set-syntax-table html-helper-mode-syntax-table)

  (cond (html-helper-mode-run-the-mode
	 (make-local-variable 'comment-start)
	 (make-local-variable 'comment-end)
	 (make-local-variable 'comment-column)
	 (make-local-variable 'comment-start-skip)
	 (make-local-variable 'indent-line-function)
	 (make-local-variable 'html-helper-count)
	 (make-local-variable 'html-helper-mode-local-JSP-not-ASP)
	 (make-variable-buffer-local 'html-helper-mode-run-the-mode)
	 (set 'html-helper-mode-run-the-mode nil)
	 (html-helper-add-buffer (current-buffer) mode)))

  ;; font-lock setup for various emacsen: XEmacs, Emacs 19.29+, Emacs <19.29.
  ;; By Ulrik Dickow <dickow@nbi.dk>.  (Last update: 05-Sep-1995).
  (cond	((string-match "XEmacs\\|Lucid" (emacs-version)) ; XEmacs/Lucid
	 (put major-mode 'font-lock-keywords-case-fold-search t)
	 )
	;; XEmacs (19.13, at least) guesses the rest correctly.
	;; If any older XEmacsen don't, then tell me.
	;;
	((string-lessp "19.28.89" emacs-version) ; Emacs 19.29 and later
	 (make-local-variable 'font-lock-defaults)
	 (setq font-lock-defaults '(html-helper-font-lock-keywords t t)))
	;;
	(t ; Emacs 19.28 and older
	 (make-local-variable 'font-lock-keywords-case-fold-search)
	 (make-local-variable 'font-lock-keywords)
	 (make-local-variable 'font-lock-no-comments)
	 (setq font-lock-keywords-case-fold-search t)
	 (setq font-lock-keywords html-helper-font-lock-keywords)
	 (setq font-lock-no-comments t)))

  (setq comment-start "<!-- "
	comment-end " -->"
	comment-start-skip "<!--[ \t]*"
	comment-column 0
	indent-line-function 'html-helper-indent)

  (tempo-use-tag-list 'html-helper-tempo-tags html-helper-completion-finder)

  (if html-helper-do-write-file-hooks
      (add-hook 'local-write-file-hooks 'html-helper-update-timestamp))

  (if (and html-helper-build-new-buffer (zerop (buffer-size)))
      (cond ((string= mode "HTML")
	     (html-helper-insert-new-buffer-strings))
	    ((string= mode "ASP")
	     (html-helper-insert-new-ASP-buffer-strings))
	    ((string= mode "PHP")
	     (html-helper-insert-new-PHP-buffer-strings))
	    ))

  (easy-menu-add (html-helper-menu) html-helper-mode-map)

  (run-hooks 'text-mode-hook)
  (run-hooks 'html-mode-hook)
;; qui i keybinding
  (run-hooks 'html-helper-mode-hook))

(cond (html-helper-mode-uses-visual-basic
       (defun asp-html-helper-mode ()
  "Mode for editing HTML documents with ASP server scripts.

The main function html-helper-mode provides is a menu and keybindings
for the HTML tags one inserts when writing HTML documents. Selecting
the menu item or typing the key sequence for a command inserts the
corresponding tag and places point in the right place. If a prefix
argument is supplied, the tags is instead wrapped around the region.
Alternately, one can type in part of the tag and complete it with M-TAB.

There is also code for indentation, timestamps, skeletons for new
documents, and lots of other neat features.

Uses :`visual-basic-mode'  for ASP e VBSCript
      `easymenu' for menu creation
      `cc-mode'  for javascript support
      `tempo'    for templates
Supports server (actually ASP & PHP, JSP) and client
(JavaScript, VBScript) scripting

Customizable flags you would like to alter

`html-helper-mode-uses-visual-basic' : non nil requires visual-basic-mode and activates ASP and VBScript support functions
`html-helper-mode-uses-bold-italic' : non nil creates a bold italic face (could fail if there's not such face available)
`html-helper-mode-uses-KG-style' : nil to make Emacs consider PHP/JSP/ASP code blocks beginning in the first colum
`html-helper-mode-global-JSP-not-ASP' : non nil to make Emacs consider <% %> sequence as JSP blocks by default in html-helper-mode, set to nil in asp-html-helper-mode, set to t in jsp-html-helper-mode.
Alter the behaviour locally by changing html-helper-mode-local-JSP-not-ASP value


Special command (not in menu - default bound to [f4]): attempts a smart narrowing to the current scripting block. Fails in client script containing server script sections.
\\{html-helper-mode-map}
Written by nelson@santafe.edu, http://www.santafe.edu/~nelson/
Mantained by lauri@eng.it, http:/www.gest.unipd.it/~saint/"
  (interactive)
  (html-helper-add-buffer (current-buffer) "ASP")
  (asp-html-helper-mode-run)))
)

;;
(defun asp-html-helper-mode-run ()
  (base-html-helper-mode "ASP")
  (setq html-helper-mode-local-JSP-not-ASP nil)
  (setq mode-name "HTML/ASP helper")
  ;; Mon Jun 25 16:14:44 2001 Saint
  ;;
  ;; Supporto imenu (da cui discende il supporto Speedbar)
  (setq imenu-generic-expression
	'(( "VBA Variables" "\\([Dd][Ii][Mm][ \t]+\\)\\([a-z0-9]+\\)" 2)
	  ( "ASP Output" "^.*\\(<%=[ \t]*\\)\\([a-z0-9]+\\)" 2)
	  ( "ASP Block" "^.*\\(<%[^=][\t\n ]+\\)\\([a-z0-9]+\\)" 2)
	  ( "VBA Sub" "^.*\\([sS]ub[\t\n ]+\\)\\([a-z0-9]+\\)" 2)
	  ( "VBA Function" "^.*\\([fF]unciton[\t\n ]+\\)\\([a-z0-9]+\\)" 2)))
  (speedbar-add-supported-extension ".asp")
  ;;/Saint
  (setq major-mode 'asp-html-helper-mode))

(defun jsp-html-helper-mode ()
  "Mode for editing HTML documents with ASP server scripts.

The main function html-helper-mode provides is a menu and keybindings
for the HTML tags one inserts when writing HTML documents. Selecting
the menu item or typing the key sequence for a command inserts the
corresponding tag and places point in the right place. If a prefix
argument is supplied, the tags is instead wrapped around the region.
Alternately, one can type in part of the tag and complete it with M-TAB.

There is also code for indentation, timestamps, skeletons for new
documents, and lots of other neat features.

Uses :`visual-basic-mode'  for ASP e VBSCript
      `easymenu' for menu creation
      `cc-mode'  for javascript support
      `tempo'    for templates
Supports server (actually ASP & PHP, JSP) and client
(JavaScript, VBScript) scripting

Customizable flags you would like to alter

`html-helper-mode-uses-visual-basic' : non nil requires visual-basic-mode and activates ASP and VBScript support functions
`html-helper-mode-uses-bold-italic' : non nil creates a bold italic face (could fail if there's not such face available)
`html-helper-mode-uses-KG-style' : nil to make Emacs consider PHP/JSP/ASP code blocks beginning in the first colum
`html-helper-mode-global-JSP-not-ASP' : non nil to make Emacs consider <% %> sequence as JSP blocks by default in html-helper-mode, set to nil in asp-html-helper-mode, set to t in jsp-html-helper-mode.
Alter the behaviour locally by changing html-helper-mode-local-JSP-not-ASP value


Special command (not in menu - default bound to [f4]): attempts a smart narrowing to the current scripting block. Fails in client script containing server script sections.
\\{html-helper-mode-map}
Written by nelson@santafe.edu, http://www.santafe.edu/~nelson/
Mantained by lauri@eng.it, http:/www.gest.unipd.it/~saint/"
  (interactive)
  (html-helper-add-buffer (current-buffer) "JSP")
  (jsp-html-helper-mode-run)
)

(defun jsp-html-helper-mode-run ()
  (interactive)
  (base-html-helper-mode "JSP")
  (setq html-helper-mode-local-JSP-not-ASP t)
  (setq mode-name "HTML/JSP helper")
  (setq major-mode 'jsp-html-helper-mode))

(defun html-helper-mode ()
  "Mode for editing HTML documents.

The main function html-helper-mode provides is a menu and keybindings
for the HTML tags one inserts when writing HTML documents. Selecting
the menu item or typing the key sequence for a command inserts the
corresponding tag and places point in the right place. If a prefix
argument is supplied, the tags is instead wrapped around the region.
Alternately, one can type in part of the tag and complete it with M-TAB.

There is also code for indentation, timestamps, skeletons for new
documents, and lots of other neat features.

Uses :`visual-basic-mode' (optional - see below ) for ASP and VBScript
      `easymenu' for menu creation
      `cc-mode'  for javascript support
      `tempo'    for templates

Supports server (actually ASP & PHP, JSP) and client
(JavaScript, VBScript) scripting

Customizable flags you would like to alter

`html-helper-mode-uses-visual-basic' : non nil requires visual-basic-mode and activates ASP and VBScript support functions
`html-helper-mode-uses-bold-italic' : non nil creates a bold italic face (could fail if there's not such face available)
`html-helper-mode-uses-KG-style' : nil to make Emacs consider PHP/JSP/ASP code blocks beginning in the first colum
`html-helper-mode-global-JSP-not-ASP' : non nil to make Emacs consider <% %> sequence as JSP blocks by default in html-helper-mode, set to nil in asp-html-helper-mode, set to t in jsp-html-helper-mode.
Alter the behaviour locally by changing html-helper-mode-local-JSP-not-ASP value

Special command (not in menu - default bound to [f4]): attempts a smart narrowing to the current scripting block. Fails in client script containing server script sections.
\\{html-helper-mode-map}
Written by nelson@santafe.edu, http://www.santafe.edu/~nelson/
Mantained by lauri@eng.it, http:/www.gest.unipd.it/~saint/
"
  (interactive)
  (html-helper-add-buffer (current-buffer) "HTML")
  (html-helper-mode-run))

(defun html-helper-mode-run ()
  (interactive)
  (base-html-helper-mode "HTML")
  (setq mode-name "HTML helper")
  (setq html-helper-mode-local-JSP-not-ASP html-helper-mode-global-JSP-not-ASP)
  (setq major-mode 'html-helper-mode))

(defun php-html-helper-mode ()
  "Mode for editing HTML documents with PHP server scripts.

The main function html-helper-mode provides is a menu and keybindings
for the HTML tags one inserts when writing HTML documents. Selecting
the menu item or typing the key sequence for a command inserts the
corresponding tag and places point in the right place. If a prefix
argument is supplied, the tags is instead wrapped around the region.
Alternately, one can type in part of the tag and complete it with M-TAB.

There is also code for indentation, timestamps, skeletons for new
documents, and lots of other neat features.

Uses :`visual-basic-mode' (optional) for ASP e VBSCript
      `easymenu' for menu creation
      `cc-mode'  for javascript support
      `tempo'    for templates

Supports server (actually ASP & PHP, JSP) and client
(JavaScript, VBScript) scripting

Customizable flags you would like to alter

`html-helper-mode-uses-visual-basic' : non nil requires visual-basic-mode and activates ASP and VBScript support functions
`html-helper-mode-uses-bold-italic' : non nil creates a bold italic face (could fail if there's not such face available)
`html-helper-mode-uses-KG-style' : nil to make Emacs consider PHP/JSP/ASP code blocks beginning in the first colum
`html-helper-mode-global-JSP-not-ASP' : non nil to make Emacs consider <% %> sequence as JSP blocks by default in html-helper-mode, set to nil in asp-html-helper-mode, set to t in jsp-html-helper-mode.
Alter the behaviour locally by changing html-helper-mode-local-JSP-not-ASP value

Special command (not in menu - default bound to [f4]): attempts a smart narrowing to the current scripting block. Fails in client script containing server script sections.
\\{html-helper-mode-map}
Written by nelson@santafe.edu, http://www.santafe.edu/~nelson/
Mantained by lauri@eng.it, http:/www.gest.unipd.it/~saint/
"
(interactive)
  (html-helper-add-buffer (current-buffer) "HTML")
  (php-html-helper-mode-run))

(defun php-html-helper-mode-run ()
  (interactive)
  (base-html-helper-mode "PHP")
  (setq mode-name "HTML/PHP helper")
  (setq major-mode 'php-html-helper-mode))

;;}}}

;;{{{ text faces

;; By Ulrik Dickow <dickow@nbi.dk>.
;;
;; Originally aimed at Emacs 19.29.  Later on disabled syntactic fontification
;; and reordered regexps completely, to be compatible with XEmacs (it doesn't
;; understand OVERRIDE=`keep').
;;
;; We make an effort on handling nested tags intelligently.

(make-face 'info-menu-6)

;; font-lock compatibility with XEmacs/Lucid and older Emacsen (<19.29).
;;
(if (string-match "XEmacs\\|Lucid" (emacs-version))
    ;; XEmacs/Lucid
    ;; Make needed faces if the user hasn't already done so.
    ;; Respect X resources (`make-face' uses them when they exist).
    (let ((change-it
 	   (function (lambda (face)
 		       (or (if (fboundp 'facep)
 			       (facep face)
 			     (memq face (face-list)))
 			   (make-face face))
 		       (not (face-differs-from-default-p face))))))
      (if (funcall change-it 'html-helper-bold-face)
 	  (progn (make-face 'html-helper-bold-face)
 		 (make-face-bold 'html-helper-bold-face)
		 (set-face-foreground html-helper-bold-face "peru")))
      (if (funcall change-it 'html-helper-italic-face)
 	  (progn (make-face 'html-helper-italic-face)
 		 (make-face-italic 'html-helper-italic-face)
		 (set-face-foreground 'html-helper-italic-face "medium sea green")))
      (if (funcall change-it 'html-helper-underline-face)
 	  (set-face-underline-p 'html-helper-underline-face t))
      (if (funcall change-it 'font-lock-variable-name-face)
 	  (set-face-foreground 'font-lock-variable-name-face "salmon"))
      (if (funcall change-it 'font-lock-reference-face)
 	  (set-face-foreground 'font-lock-reference-face "violet"))
      ; experimental code
      (if (funcall change-it 'html-helper-bold-italic-face)
 	  (progn (cond (html-helper-mode-uses-bold-italic
			(make-face 'html-helper-bold-italic-face)
			(make-face-bold-italic 'html-helper-bold-italic-face)
			(set-face-foreground 'html-helper-bold-italic-face "orange")))))
      (if (funcall change-it 'html-helper-underline-face)
	  (progn (make-face 'html-helper-underline-face)
		 (set-face-underline-p 'html-helper-underline-face t)
		 (set-face-foreground html-helper-underline-face "goldenrod")))
      ;; Cheap hack to avoid autoload failure - lawrencc@debian.org
      (defvar html-tag-face 
        (make-face 'html-tag-face))
      (make-face-bold 'html-tag-face)
	;; PETER Neergaard <turtle@bu.edu> says
	;;
	;; "Another issue I just noticed is that font-lock-builtin-face
	;; is not a face defined Xemacs; instead they use
	;; font-lock-preprocessor-face (I too fail to see any good
	;; reasons that they have made this design choice).  I did not
	;; notice this at first because I hack define
	;; font-lock-builtin-face in my .emacs as I had some packages
	;; using font-lock-builtin-face when I started using Xemacs,
	;; but this has been changed now."  Then suggests this change :
      (make-face 'html-helper-builtin-face)
      (copy-face 'font-lock-preprocessor-face
		 'html-helper-builtin-face)))
  ;; Emacs
  ;;
  ;; Note that Emacs evaluates the face entries in `font-lock-keywords',
  ;; while XEmacs doesn't.  So XEmacs doesn't use the following *variables*,
  ;; but instead the faces with the same names as the variables.

  ;; New predicate on suggestion by "David J. Biesack" <sasdjb@unx.sas.com>
  (if (or (not (boundp 'emacs-major-version)) ; t if prior to 19.23
	   (< emacs-major-version 20)         ; t if prior to 20.0.0
	   (and (= emacs-major-version 20)    ; t if prior to 20.4.1
		(< emacs-minor-version 4)))
       (progn
	(defvar html-helper-bold-face
	  (make-face 'html-helper-bold-face))
	(make-face-bold 'html-helper-bold-face)
	(defvar html-helper-italic-face
	  (make-face 'html-helper-italic-face))
	(make-face-italic 'html-helper-italic-face)
	(cond (html-helper-mode-uses-bold-italic
	       (defvar html-helper-bold-italic-face
		 (make-face 'html-helper-bold-italic-face))
	       (make-face-bold-italic 'html-helper-bold-italic-face)))
	(defvar html-helper-underline-face
	  (make-face 'html-helper-underline-face))
	(set-face-underline-p 'html-helper-underline-face t)
	(defvar html-tag-face
	  (make-face 'html-tag-face))
	(make-face-bold 'html-tag-face)

	(defvar html-helper-builtin-face
	  (make-face 'html-helper-builtin-face))
	(copy-face 'font-lock-builtin-face
		   'html-helper-builtin-face)
	;; Support for both old font-lock-background-mode and new
	;; frame-background-mode, plus a default value if neither of the two
	;; is non nil
	(let ((internal-background-mode
	       (or (if (boundp 'font-lock-background-mode)
                  font-lock-background-mode frame-background-mode)
              (setq internal-background-mode 'light))))
	  (progn
	    (cond ((eq internal-background-mode 'light)
		   (set-face-foreground html-tag-face "dodger blue"))
		  ((eq internal-background-mode 'dark)
		   (set-face-foreground html-tag-face "deep sky blue")))
	    (cond ((eq internal-background-mode 'light)
		   (set-face-foreground html-helper-bold-face "peru"))
		  ((eq internal-background-mode 'dark)
		   (set-face-foreground 'html-helper-bold-face "wheat")))
	    (cond ((eq internal-background-mode 'light)
		   (set-face-foreground 'html-helper-italic-face "medium sea green"))
		  ((eq internal-background-mode 'dark)
		   (set-face-foreground 'html-helper-italic-face "spring green")))
	    (cond (html-helper-mode-uses-bold-italic
		   (cond ((eq internal-background-mode 'light)
			  (set-face-foreground 'html-helper-bold-italic-face "orange"))
			 ((eq internal-background-mode 'dark)
			  (set-face-foreground 'html-helper-bold-italic-face "peachpuff")))))
	    (cond ((eq internal-background-mode 'light)
		   (set-face-foreground html-helper-underline-face "goldenrod"))
		  ((eq internal-background-mode 'dark)
		   (set-face-foreground 'html-helper-underline-face "cornsilk"))))))
    ;; Use customization. I don't recall if earier version support it...
    (progn
      (defvar html-tag-face
	(defface html-tag-face
	  '((((class color)
	      (background dark))
	     (:foreground "deep sky blue" :bold t))
	    (((class color)
	      (background light))
	     (:foreground "dodger blue" :bold t))
	    (t
	     (:foreground "dodger blue" :bold t)))
	  "Face to use for HTML tags."
	  :group 'html-helper-faces))
      (defvar html-helper-bold-face
	(defface html-helper-bold-face
	  '((((class color)
	      (background dark))
	     (:foreground "wheat" :bold t))
	    (((class color)
	      (background light))
	     (:foreground "peru" :bold t))
	    (t
	     (:foreground "peru" :bold t)))
	  "Custom bold face."
	  :group 'html-helper-faces))
	  (defvar html-helper-italic-face
	    (defface html-helper-italic-face
	      '((((class color)
		  (background dark))
		 (:foreground "spring green" :italic t))
		(((class color)
		  (background light))
		 (:foreground "medium sea green" :italic t))
		(t
		 (:foreground "medium sea green" :italic t)))
	      "Custom italic face."
	      :group 'html-helper-faces))
	  (cond (html-helper-mode-uses-bold-italic
		 (defvar html-helper-bold-italic-face
		   (defface html-helper-bold-italic-face
		     '((((class color)
			 (background dark))
			(:foreground "peachpuff" :bold t:italic t))
		       (((class color)
			 (background light))
			(:foreground "orange" :bold t :italic t))
		       (t
			(:foreground "orange" :bold t :italic t)))
		     "Custom bold italic face."
		     :group 'html-helper-faces))))
	  (defvar html-helper-underline-face
	    (defface html-helper-underline-face
	      '((((class color)
		  (background dark))
		 (:foreground "cornsilk" :underline t))
		(((class color)
		  (background light))
		 (:foreground "goldenrod" :underline t))
		(t
		 (:foreground "goldenrod" :underline t)))
	      "Custom underline face."
	      :group 'html-helper-faces))
	  (defvar html-helper-builtin-face
	    (defface html-helper-builtin-face
	      '((((class color)
		  (background dark))
		 (:foreground "light goldenrod" :underline nil))
		(((class color)
		  (background light))
		 (:foreground "dark goldenrod" :underline nil))
		(t
		 (:foreground "light goldenrod" :underline nil)))
	      "Custom Server Script face."
	      :group 'html-helper-faces))))

  ;;
  (if (string-lessp "19.28.89" emacs-version)
      ()
    ;; Emacs 19.28 and older
    ;; Define face variables that don't exist until Emacs 19.29.
    (defvar html-helper-builtin-face (html-helper-emacs-19-build-face))
    (defvar font-lock-variable-name-face 'font-lock-doc-string-face
      "Face to use for variable names -- and some HTML keywords.")
    (defvar font-lock-reference-face 'underline ; Ugly at line breaks
      "Face to use for references -- including HTML hyperlink texts."))

(defun html-helper-emacs-19-build-face ()
  (let ((x (make-face 'font-lock-builtin-face)))
    (set-face-foreground x "Orchid")
    x))


; (defvar html-helper-builtin-face
;   (let ((bux (make-face 'html-helper-builtin-face)))
;     (copy-face
;      ;; XEmacs doesn't have font-lock-builtin-face
;      (cond ((string-match "XEmacs\\|Lucid" emacs-version)
; 	    font-lock-preprocessor-face)
; 	   ;; GNU Emacs 19 doesn't have it either
; 	   ((string-match "GNU Emacs 19" emacs-version)
; 	    html-helper-emacs-19-build-face)
; 	   ;; Emacs
; 	   (t font-lock-builtin-face)) bux  )
;     bux))

(copy-face
 (cond ((string-match "XEmacs\\|Lucid" emacs-version)
	font-lock-preprocessor-face)
       ;; GNU Emacs 19 doesn't have it either
       ((string-match "GNU Emacs 19" emacs-version)
	html-helper-emacs-19-build-face)
       ;; Emacs
       (t font-lock-builtin-face)) html-helper-builtin-face)

;; Tue Jan 09 12:29:45 2001 Saint
;;
;; Time to KISS syntax highlight.
;;
;; All tags get the same highlight with attributes highlighted
; (defvar html-helper-font-lock-keywords
;   (let (;; Titles and H1's, like function defs.
; 	;;   We allow for HTML 3.0 attributes, like `<h1 align=center>'.
; 	;; All tokens get the same higlighting
; 	(tword "\\(h1\\|title\\)\\([ \t\n]+[^>]+\\)?")
; 	;; Names of tags to boldify.
; 	(bword "\\(b\\|h[2-4]\\|strong\\)\\([ \t\n]+[^>]+\\)?")
; 	;; Names of tags to italify.
; 	(iword "\\(address\\|cite\\|em\\|i\\|var\\)\\([ \t\n]+[^>]+\\)?")
; 	;; Regexp to match shortest sequence that surely isn't a bold end.
; 	;; We simplify a bit by extending "</strong>" to "</str.*".
; 	;; Do similarly for non-italic and non-title ends.
; 	(not-bend (concat "\\([^<%?]\\|<\\([^/]\\|/\\([^bhs]\\|"
; 			  "b[^>]\\|"
; 			  "h\\([^2-4]\\|[2-4][^>]\\)\\|"
; 			  "s\\([^t]\\|t[^r]\\)\\)\\)\\)"))
; 	(not-iend (concat "\\([^<%?]\\|<\\([^/]\\|/\\([^aceiv]\\|"
; 			  "a\\([^d]\\|d[^d]\\)\\|"
; 			  "c\\([^i]\\|i[^t]\\)\\|"
; 			  "e\\([^m]\\|m[^>]\\)\\|"
; 			  "i[^>]\\|"
; 			  "v\\([^a]\\|a[^r]\\)\\)\\)\\)"))
; 	(not-tend (concat "\\([^<%?]\\|<\\([^/]\\|/\\([^ht]\\|"
; 			  "h[^1]\\|t\\([^i]\\|i[^t]\\)\\)\\)\\)")))
;     (list
;      ;; Avoid use of `keep', since XEmacs will treat it the same as `t'.
;      ;; First fontify the text of a HREF anchor.  It may be overridden later.
;      ;; Anchors in headings will be made bold, for instance
;      '("<a\\s-+href[^>]*>\\([^>]+\\)</a>"
;        1 font-lock-warning-face t)
;      ;; Titles and level 1 headings (anchors do sometimes appear in h1's)
;      (list (concat "<" tword ">\\(" not-tend "*\\)</\\1>")
; 	   0 'font-lock-function-name-face t)
;      ;; Underline is rarely used. Only handle it when no tags inside.
;      '("<u>\\([^<]*\\)</u>" 1 html-helper-underline-face t)
;      ;; Forms, anchors & images (also fontify strings inside)
;      '("<\\(i\\(mg\\|nput\\)\|a\\)\\>[^>\n]*>"
;        0  font-lock-constant-face t)
;      ;; Any tag, general rule, just after bold/italic stuff.
;      ;; w3 org says that a tag is <element-name> not < element-name>
;      '("\\(<[^%a=> \t][^>]*>\\)" 1 font-lock-function-name-face t)
;      '("\\(<[^%a=> \t][^>\n]*>\\)" 1 html-tag-face t)
;      ;; Large-scale structure keywords (like "program" in Fortran).
;      ;;   "<html>" "</html>" "<body>" "</body>" "<head>" "</head>" "</form>"
;      '("\\(</?\\(body\\|form\\|h\\(ead\\|tml\\)\\)[^>\n]*>\\)"
;        0 font-lock-variable-name-face t)
;      ;; SGML things like <!DOCTYPE ...> with possible <!ENTITY...> inside.
;      '("<![a-z]+\\>[^<>]*\\(<[^>]*>[^<>]*\\)*>"
;        0 font-lock-keyword-face t)
;      ;; Paint [PA][HS]P skripts in font-lock-builtin-face,
;      '("<[?%]=\\([^%?]\\|[?%][^>]\\)*[%?]>" 0 html-helper-builtin-face t t)
;      '(html-helper-match-asp-php 0 html-helper-builtin-face t t)
;      ;; This one is to pick
;      ;; Tag pairs like <b>...</b> etc.
;      ;; Cunning repeated fontification to handle common cases of overlap.
;      ;; Bold complex --- possibly with arbitrary other non-bold stuff inside.
;      (list (concat "<" bword ">\\(" not-bend "*\\)</\\1>")
; 	   0 'html-helper-bold-face t)
;      ;; Italic complex --- possibly with arbitrary non-italic kept inside.
;      (list (concat "<" iword ">\\(" not-iend "*\\)</\\1>")
; 	   0 'html-helper-italic-face t)
;      ;; Bold simple --- first fontify bold regions with no tags inside.
;      (list (concat "<" bword ">\\("  "[^<]"  "*\\)</\\1>")
; 	   0 'html-helper-bold-face t)
;      ;; string stuff is pretty weird with asp. You can have strings
;      ;; containing asp code containing strings and empty
;      ;; strings. Replaced original [^\"] with this one...
;      '("[=(&]?[ \t\n]*\\(\"[^\"\n]*<%[^\"\n]*\\(\"[^\"\n]*\"\\)[^\"\n]*%>[^\"\n]*\\)" 1 font-lock-string-face t)
;      '("[=(&]?[ \t\n]*\\(\"[^\"\n]*\"\\)"  1 font-lock-string-face t)
;      ;; HTML special characters
;      '("&[a-zA-Z0-9#]+;" 0 font-lock-warning-face t)
; 					; after painting strings, you have to restore asp stuff inside strings
;      '("\\(<%=\\w\\)" 1 html-helper-builtin-face t)
;      '("\\(\")[^\"\n]*%>\\)" 1 html-helper-builtin-face t)
;      '("\\(<%=[^%]*%>\\)" 1 html-helper-builtin-face t)
;      '("\\(<\\?=\\w\\)" 1 html-helper-builtin-face t)
;      '("\\(\")[^\"\n]*\\?>\\)" 1 html-helper-builtin-face t)
;      '("\\(<\\?=[^%]*\\?>\\)" 1 html-helper-builtin-face t)
;      ;; That's krazy, strings higlight matches ) too, so i paint
;      ;; parantheses...
;      '("\\(<%\\|\\s(\\)" 1 font-lock-function-name-face t)
;      '("\\(\\s)\\|%>\\)" 1 font-lock-function-name-face t)
;      '("\\(<\\?\\|\\s(\\)" 1 font-lock-function-name-face t)
;      '("\\(\\s)\\|\\?>\\)" 1 font-lock-function-name-face t)
;      '("\\([\"]\\)" 0 font-lock-string-face t)
;      ;; Comment declarations according to the HTML 2.0 spec at
;      ;; <URL:http://www.w3.org/pub/WWW/MarkUp/html-spec/html-spec_3.html>.
;      ;; Usually `<!-- ... -->', but also e.g the single, complete declaration
;      ;; `<!--c1--  -- c2 -- -->c3 (still comment) ----c4- c4--   >'.
;      ;; Note that e.g. Netscape 3.01 Gold doesn't fully live up to the spec.

;      ;; A Regexp doesn't work well with big blocks...
;      ;;      '("<!--\\(.\\|[\n]\\--[ \t]*[^>]\\)*--[ \t]*>" 0
;      ;;	font-lock-comment-face t)))
;      '(html-helper-match-comments 0 font-lock-comment-face t t)
;      '(html-helper-match-attributes 0 font-lock-variable-face t t)))
;     "Additional expressions to highlight in HTML helper mode.")

;; New highlighting
(defvar html-helper-font-lock-keywords
    (list
     ;; Avoid use of `keep', since XEmacs will treat it the same as `t'.
     ;; First fontify the text of a HREF anchor.  It may be overridden later.
     ;; Anchors in headings will be made bold, for instance
     '("<a\\s-+href[^>]*>\\([^>]+\\)</a>"
       1 font-lock-warning-face t)
     ;; Underline is rarely used. Only handle it when no tags inside.
     '("<u>\\([^<]*\\)</u>" 1 html-helper-underline-face t)
     '(html-helper-match-bold
	   0 'html-helper-bold-face t)
     ;; Italic
     '(html-helper-match-italics
	   0 'html-helper-italic-face t)
     ;; w3 org says that a tag is <element-name> not < element-name>
     ;; I don't know of any non alphabetic HTML entity, if you know
     ;; about one, please drop me a mail
     ;;						Saint
     '("\\(</?[A-Za-z0-9]+\\)" 1 html-tag-face t)
     ;; SGML things like <!DOCTYPE ...> with possible <!ENTITY...> inside.
     '("<![a-z]+\\>[^<>]*\\(<[^>]*>[^<>]*\\)*>"
       0 font-lock-keyword-face t)
     ;; Paint [PA][HS]P skripts in font-lock-builtin-face,
     '("<[?%]=\\([^%?]\\|[?%][^>]\\)*[%?]>" 0 html-helper-builtin-face t t)
     '(html-helper-match-asp-php 0 html-helper-builtin-face t t)
     ;; string stuff is pretty weird with asp. You can have strings
     ;; containing asp code containing strings and empty
     ;; strings. Replaced original [^\"] with this one...
     '("[=(&]?[ \t\n]*\\(\"[^\"\n]*<%[^\"\n]*\\(\"[^\"\n]*\"\\)[^\"\n]*%>[^\"\n]*\\)" 1 font-lock-string-face t)
     '("[=(&]?[ \t\n]*\\(\"[^\"\n]*\"\\)"  1 font-lock-string-face t)
     ;; after painting strings, you have to restore asp stuff inside strings
     '("\\(<%=\\w\\)" 1 html-helper-builtin-face t)
     '("\\(\")[^\"\n]*%>\\)" 1 html-helper-builtin-face t)
     '("\\(<%=[^%]*%>\\)" 1 html-helper-builtin-face t)
     '("\\(<\\?=\\w\\)" 1 html-helper-builtin-face t)
     '("\\(\")[^\"\n]*\\?>\\)" 1 html-helper-builtin-face t)
     '("\\(<\\?=[^%]*\\?>\\)" 1 html-helper-builtin-face t)
     ;; Comment declarations according to the HTML 2.0 spec at
     ;; <URL:http://www.w3.org/pub/WWW/MarkUp/html-spec/html-spec_3.html>.
     ;; Usually `<!-- ... -->', but also e.g the single, complete declaration
     ;; `<!--c1--  -- c2 -- -->c3 (still comment) ----c4- c4--   >'.
     ;; Note that e.g. Netscape 3.01 Gold doesn't fully live up to the spec.

     ;; That's krazy, strings higlight matches ) too, so i paint
     ;; parantheses...
     '("\\(<%\\|\\s(\\)" 1 font-lock-function-name-face t)
     '("\\(\\s)\\|%>\\)" 1 font-lock-function-name-face t)
     '("\\(<\\?\\|\\s(\\)" 1 font-lock-function-name-face t)
     '("\\(\\s)\\|\\?>\\)" 1 font-lock-function-name-face t)
     '("\\([\"]\\)" 0 font-lock-string-face t)
     ;; A Regexp doesn't work well with big blocks...
     ;;      '("<!--\\(.\\|[\n]\\--[ \t]*[^>]\\)*--[ \t]*>" 0
     ;;	font-lock-comment-face t)))
     '(html-helper-match-comments 0 font-lock-comment-face t t)
     '(html-helper-match-attributes 0 font-lock-variable-name-face t t)
     ;; HTML special characters
     '("&[a-zA-Z0-9#]+;" 0 font-lock-warning-face t))
    "Additional expressions to highlight in HTML helper mode.")

;; internal variables

(defvar html-helper-count 0 "Counter during server script matching")

(defvar html-helper-verbose t
  "Non nil to show a counter during server script matching")

(defun html-helper-ticker ()
  "Returns the next prop image"
  (set 'html-helper-count (mod (incf html-helper-count) 8))
  (make-string html-helper-count 46))

;; Function to match an asp script (hopefully) without overflowing the
;; regexp stack (not inline <%= ... %>)
;;
;;
(defun html-helper-match-asp-php (last)
  (cond (html-helper-verbose
	 (message "Fontifying %s... (PHP/ASP %s)" bufname
		  (html-helper-ticker))))
  (cond ((search-forward-regexp "[^\"]<[?%][^=]" last t) ; match inline elsewhere
	 (backward-char 1)
	 (let ((beg (point)))
;	   (cond ((search-forward-regexp "\\([^%?\n]\\|[%?][^>]\\|\\(\"\\([%?]>\\|.\\)*\"\\)\\)*[?%]>" last t)
	   (cond ((search-forward-regexp "\\([^\%\?\n\"]\\|[%?][^>]\\)*[?%]>" last t)
		  (set-match-data (list beg (point)))
		  t )
		 (t nil))))
	(t nil)))

;; Html comments can overflow the buffer if used to hide the code
;; from older browser
(defun  html-helper-match-comments (last)
  "Matches comments in HTML from point to LAST"
  (cond (html-helper-verbose
	 (message "Fontifying %s... (Comments..%s)" bufname
		  (html-helper-ticker))))
  (cond ((search-forward "<!--" last t) ; match inline elsewhere
	 (backward-char 4)
	 (let ((beg (point)))
	   (cond ((search-forward-regexp "--[ \t]*>" last t)
		  (set-match-data (list beg (point)))
		  t )
		 (t nil))))
	(t nil)))

;; match html tag attributes
(defun html-helper-match-attributes (last)
  "Matches tag attributes in HTML from point to LAST"
  (cond (html-helper-verbose
	 (message "Fontifying %s... (Attributes %s)" bufname
		  (html-helper-ticker))))
  (cond ((search-forward-regexp "[A-Za-z]+=" last t)
	 (let ((endolo (point))
	       (beg (progn (backward-word 1)(point)))
	       (firstop (cond ((search-backward-regexp
				"<\\(@\\|[A-Za-z]+\\)" 1 t)
			       (point))
			      (t nil)))
	       (firstclo (cond ((search-forward ">" last t)
			       (point))
			      (t nil))))
	   (cond (firstop
		  (cond (firstclo
			 (cond ((and (< firstop beg)
				     (> firstclo endolo))
				(goto-char endolo)
				(set-match-data (list beg endolo))
				t )
			       (t
				(goto-char endolo)
				(set-match-data nil)
				t)))
			(t (goto-char endolo)
			   (set-match-data (list beg endolo))
			   t)))
		  (t
		   (goto-char endolo)
		   (set-match-data nil)
		   t))))
	(t nil)))

(defun html-helper-match-bold (last)
  (html-helper-match-ib
   "\\(<\\(b\\|h[1-4]\\|strong\\|title\\)\\(>\\|\\W\[^>]*>\\)\\)" 
   "</\\(b\\|h[1-4]\\|strong\\|title\\)" last))

(defun html-helper-match-italics (last)
  (html-helper-match-ib "\\(<\\(i\\|em\\)\\(>\\|\\W\[^>]*>\\)\\)"
			"</\\(i\\|em\\)"
			last))

(defun html-helper-match-ib (bmat emat last)
  "Matches text between BMAT and EMAT from point to LAST"
  (cond (html-helper-verbose
	 (message "Fontifying %s... (Bold/Italics %s)" bufname
		  (html-helper-ticker))))
  (cond ((search-forward-regexp bmat last t)
	 (let ((beg (point))
	       (endolo (cond ((search-forward-regexp emat last t)
			      (backward-word 1)
			      (backward-char 2)
			      (point))
			     (t nil))))
	   (cond (endolo
		  (set-match-data (list beg endolo))))
	   t))
	(t nil)))

(defun html-helper-fontify-region (beg end verbose)
  (setq html-helper-count 0)
  (setq html-helper-count2 0)
  (let ((loudly (and verbose
		     (> (- end beg) (/ (buffer-size) 2)))))
    (setq html-helper-verbose loudly)
    (font-lock-default-fontify-region beg end loudly)))

(set (make-local-variable font-lock-fontify-region-function)
     'html-helper-fontify-region)

(defun html-helper-fontify-buffer ()
  (setq html-helper-count 0)
  (setq html-helper-count2 0)
  (setq html-helper-verbose (if (numberp font-lock-verbose)
				(> (buffer-size) font-lock-verbose)
			      font-lock-verbose))
  (font-lock-default-fontify-buffer))

(set (make-local-variable font-lock-fontify-buffer-function)
     'html-helper-fontify-buffer)

;;}}} faces

;;{{{ patterns for hilit19

;; Define some useful highlighting patterns for the hilit19 package.
;; These will activate only if hilit19 has already been loaded.
;; Thanks to <dickow@nbi.dk> for some pattern suggestions

(if (featurep 'hilit19)
    (hilit-set-mode-patterns
     'html-helper-mode
     '(("<!--" "-->" comment)
       ("<![a-z]+\\>[^<>]*\\(<[^>]*>[^<>]*\\)*>" nil comment) ;<!DOCTYPE ...>
       ("<title>" "</title>" defun)
       ("<h[1-6]>" "</h[1-6]>" bold) ;only colour inside tag
       ("<a\\b" ">" define)
       ("</a>" nil define)
       ("<img\\b" ">" include)
       ("<option\\|</?select\\|<input\\|</?form\\|</?textarea" ">" include)
       ;; First <i> highlighting just handles unnested tags, then do nesting
       ("<i>[^<]*</i>" nil italic)
       ("<b>" "</b>" bold)
       ("<i>" "</i>" italic)
       ("<u>" "</u>" underline)
       ("&[^;\n]*;" nil string)
       ;; w3 org says that a tag is <element-name> not < element-name>
       ("<[^ \t]" ">" keyword))
     nil 'case-insensitive)
  nil)
;;}}}

;;{{{ indentation

(defvar html-helper-print-indent-info nil
  "If t, indent will print out information as a message.")

;; some ideas borrowed from cc-mode.el.
;; Basic logic:
;;   if this line is some sort of list token, indent according to prev context:
;;     if previous context was a list-end or item-start, use its indentation
;;     if previous context was a list start, indent forward basic-offset
;;     ignore previous list-ends, their indentation is unreliable.
;;     then if this is some sort of list-item, do special case fixups:
;;       if this is a item start or end and previous was a list end, go back
;;           item-continue-indent (the </ul> is probably indented for an <li>
;;       if this is a list end and previous was a list end, go back
;;           item-continue-indent (the </ul> is probably indented for an <li>
;;       if this is a list end and prev *not* a list end, go back basic-offset
;;   else if this line is not a list item, and previous line is a item-start
;;     indent continue-indent, because this is part of the item

;;}}}

;;{{{ Script Narrowing and mode switch
;; These are for supporting html-script. With small changes can be useful for
;; javascript

;; Stan Lanning <lanning@pobox.com> wrote these defadvice to preserve
;; cursor position. Thank you very much Stan!
(defadvice html-script-narrow-to-asp (around save-excursion activate)
  (save-excursion
    ad-do-it))
(defadvice html-script-narrow-to-php (around save-excursion activate)
  (save-excursion
    ad-do-it))
(defadvice html-script-narrow-to-vbscript (around save-excursion activate)
  (save-excursion
    ad-do-it))
(defadvice html-script-narrow-to-javascript (around save-excursion activate)
  (save-excursion
    ad-do-it))
(defadvice html-script-narrow-to-css (around save-excursion activate)
  (save-excursion
    ad-do-it))

(defadvice html-script-release-region (around save-excursion activate)
  (save-excursion
    ad-do-it))



(defun html-script-narrow-to-asp ()
  "Narrows to an JSP/ASP script and switches to either java-mode/JDE or visual-basic-mode.
Does nothing if both html-helper-mode-uses-visual-basic and
html-helper-mode-local-JSP-not-ASP are nil"
  (interactive)
  (cond ((html-script-choose-mode)
	 (html-script-search-start-tag)
	 (let ((beg (point)))
	   (html-script-search-end-tag)
	   (narrow-to-region beg (point)))
	 (html-script-choose-server-mode)
	 (goto-char 0))))


(defun html-script-search-start-tag ()
 (cond ( html-helper-mode-uses-KG-style
		 (search-backward-regexp "^<%") )
	       (t (search-backward "<%" ))))

(defun html-script-search-end-tag ()
  (cond ( html-helper-mode-uses-KG-style
	  (search-forward-regexp "^%>" ))
	( t (search-forward "%>" nil t))))

(defun html-script-choose-mode ()
  (or html-helper-mode-uses-visual-basic
	     html-helper-mode-local-JSP-not-ASP))

(defun html-script-choose-server-mode ()
  (cond (html-helper-mode-local-JSP-not-ASP
	 (cond (html-helper-mode-uses-JDE (html-helper-enters-jde-mode))
	       (t (java-mode))))
	(t
	 (visual-basic-mode))))

(defun html-script-narrow-to-php ()
  "Narrows to an ASP script and setups c-mode"
  (interactive)
  (search-backward "<?")
  (let ((beg (point)))
    (search-forward "?>" nil t)
    (narrow-to-region beg (point)))
  (c-mode)
  (goto-char 0))

(defun html-script-narrow-to-vbscript ()
  "Narrows to a VB Script script and setups visual basic mode. Does nothing if html-helper-mode-uses-visual-basic is nil"
  (interactive)
  (cond (html-helper-mode-uses-visual-basic
	 (search-backward-regexp "<SCRIPT[ \t]+\\(LANGUAGE=\"VBScript\"\\|TYPE=\"text/vbscript\"\\)[ \t]*>")
	 (let ((beg (point)))
	   (search-forward "</SCRIPT>" nil t)
	   (narrow-to-region beg (point)))
	 (visual-basic-mode)
	 (goto-char 0))))

(defun html-script-narrow-to-javascript ()
  "Narrows to a JavaScript script and setups java mode"
  (interactive)
  (search-backward-regexp "<SCRIPT[ \t]+\\(LANGUAGE=\"JavaScript\"\\|TYPE=\"text/javascript\"\\)[ \t]*>")
  (let ((beg (point)))
    (search-forward "</SCRIPT>" nil t)
    (narrow-to-region beg (point)))
  (cond (html-helper-mode-uses-JDE (jde-mode))
	(t java-mode))
  (goto-char 0))

(defun html-script-narrow-to-css ()
  "Narrows to a style area  and setups css mode"
  (interactive)
  (search-backward-regexp "<STYLE>")
  (let ((beg (point)))
    (search-forward "</Style>" nil t)
    (narrow-to-region beg (point)))
  (css-mode)
  (goto-char 0))

(defun html-helper-add-buffer (buffer tag)
  (cond ((and html-helper-buffers
	      (html-helper-buffer-listed))
	 (set 'html-helper-buffers
	      (cons (cons buffer tag) html-helper-buffers )))
	(t (set 'html-helper-buffers (list (cons buffer tag))))))

;; Fri Aug 03 18:12:14 2001 Saint
;;
;; This function checks if the current buffer is not in
;; html-herlper-buffer list
(defun html-helper-buffer-listed ()
  (let ((retval t))
    (mapcar (lambda (a)
	    (cond ((eq (current-buffer) (car a))
		   (set 'retval nil))))
	    html-helper-buffers)
    retval))
;;/Saint

(defun html-helper-remove-buffer ()
  (let ((nl nil))
    (while html-helper-buffers
      (cond ((not (eq (current-buffer)
	      (car (car html-helper-buffers))))
	     (set 'nl (cons (car html-helper-buffers) nl))
	     (set 'html-helper-buffers (cdr html-helper-buffers)))
	    (t (set 'html-helper-buffers (cdr html-helper-buffers)))))
    (set 'html-helper-buffers nl)))

(defun html-script-release-region ()
   "widens the window to the complete buffer and runs html-helper-mode. MUST be interactive."
  (interactive)
  (mapcar (lambda (a)
	    (cond ((eq (current-buffer) (car a))
		   (html-helper-seletct-appropriate-mode (cdr a)))))
	  html-helper-buffers))

(defun html-helper-seletct-appropriate-mode( html-helper-used-mode)
   (interactive)
   (goto-char 0)
   (widen)
   (cond ((string= "HTML" html-helper-used-mode)
	  (html-helper-mode-run))
	 ((string= "ASP" html-helper-used-mode)
	  (asp-html-helper-mode-run))
	 ((string= "JSP" html-helper-used-mode)
	  (jsp-html-helper-mode-run))
	 ((string= "PHP" html-helper-used-mode)
	  (php-html-helper-mode-run))))

(defun html-script-release-setup()
  (interactive)
  (local-set-key html-script-toggle-key 'html-script-release-region))

(cond (html-helper-mode-uses-visual-basic
      (cond
       (visual-basic-mode-hook
	(add-hook 'visual-basic-mode-hook 'html-script-release-setup))
       (t (setq visual-basic-mode-hook 'html-script-release-setup)))))

(cond
 (c-mode-hook
  (add-hook 'c-mode-hook 'html-script-release-setup))
 (t (setq c-mode-hook 'html-script-release-setup)))

(condition-case nil
    (cond
     ((or (boundp css-mode-hook) css-mode-hook)
      (add-hook 'css-mode-hook 'html-script-release-setup))
     (t (setq css-mode-hook 'html-script-release-setup)))
  (error (setq css-mode-hook 'html-script-release-setup)))

;; Very Very ALPHA!!!
;;
;; Adding html-script-release-setup to jde-entering-java-buffer-hooks
;;
(cond (html-helper-mode-uses-JDE
       (if (and html-helper-mode-uses-JDE (fboundp 'jde-mode))
	      (add-hook 'jde-mode-hook 'html-script-release-setup)))
       (t
	(cond
	 (java-mode-hook
	  (add-hook 'java-mode-hook
		    'html-script-release-setup))
	 (t (setq java-mode-hook
		  'html-script-release-setup))))
       )

(defun html-helper-enters-jde-mode()
  (interactive)
  (and html-helper-mode-uses-JDE (fboundp 'jde-mode))
   (add-hook 'jde-mode-hook 'html-script-release-setup)
  (jde-mode))

;; Still from Stan Lanning here it comes the code for a "smart switch" to
;; the appropriate scripting mode.

(defvar html-script-toggle-key [f4])

(defvar html-script-narrow-alist
  `((,(regexp-quote "<%") . html-script-narrow-to-asp)
    (,(regexp-quote "<?") . html-script-narrow-to-php)
    ("<SCRIPT[ \t]+LANGUAGE=\"VBScript\"[ \t]*>" . html-script-narrow-to-vbscript)
    ("<SCRIPT[ \t]+TYPE=\"text/vbscript\"[ \t]*>" . html-script-narrow-to-vbscript)
    ("<SCRIPT[ \t]+LANGUAGE=\"JavaScript\"[ \t]*>" . html-script-narrow-to-javascript)
    ("<SCRIPT[ \t]+TYPE=\"text/javascript\"[ \t]*>" . html-script-narrow-to-javascript)
    ("<STYLE>" . html-helper-narrow-to-css)))

(defvar html-script-start-regexp
  (concat "\\(" (mapconcat (lambda (x) (car x)) html-script-narrow-alist "\\|") "\\)"))

(defun html-script-toggle-narrow ()
  (interactive)
  (let ((handler-fn (save-excursion
		      (if (re-search-backward html-script-start-regexp nil t)
			  (catch 'handler-found
			    (mapcar (lambda (p)
				      (if (looking-at (car p))
					  (throw 'handler-found (cdr p))))
				    html-script-narrow-alist)
			    nil)))))
    (if handler-fn
	(apply handler-fn nil)
      (error "No script tag found"))))

(defun html-script-install-toggle-key ()
  (local-set-key html-script-toggle-key 'html-script-toggle-narrow))

(add-hook 'html-helper-mode-hook 'html-script-install-toggle-key)

(defadvice html-script-release-setup (after key-binding activate)
  (local-set-key html-script-toggle-key 'html-script-release-region))
;;}}}

;; folding tags: End of code tree
;;}}}

;;{{{ Epilogue

(provide 'html-helper-mode)
(provide 'php-html-helper-mode)
(provide 'asp-html-helper-mode)
(provide 'jsp-html-helper-mode)
(provide 'html-mode)			;for 14 character filename
(cond ((boundp 'kill-buffer-hook)
       (add-hook 'kill-buffer-hook 'html-helper-remove-buffer))
      (t (set 'kill-buffer-hook 'html-helper-remove-buffer)))
(run-hooks 'html-load-hook)
(run-hooks 'html-helper-load-hook)

;;}}}

;;; html-helper-mode.el ends here