-
Notifications
You must be signed in to change notification settings - Fork 0
/
yahtml.el
3133 lines (2934 loc) · 109 KB
/
yahtml.el
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
;;; yahtml.el --- Yet Another HTML mode -*- coding: sjis -*-
;;; (c) 1994-2013 by HIROSE Yuuji [yuuji(@)yatex.org]
;;; Last modified Mon Apr 1 22:42:29 2013 on firestorm
;;; $Id$
(defconst yahtml-revision-number "1.76"
"Revision number of running yahtml.el")
;;; Commentary:
;;;[Installation]
;;;
;;; First, you have to install YaTeX and make sure it works fine. Then
;;; put these expressions into your ~/.emacs
;;;
;;; (setq auto-mode-alist
;;; (cons (cons "\\.html$" 'yahtml-mode) auto-mode-alist))
;;; (autoload 'yahtml-mode "yahtml" "Yet Another HTML mode" t)
;;; (setq yahtml-www-browser "firefox")
;;; ;Write your favorite browser. But firefox is advantageous.
;;; (setq yahtml-path-url-alist
;;; '(("/home/yuuji/public_html" . "http://www.mynet/~yuuji")
;;; ("/home/staff/yuuji/html" . "http://www.othernet/~yuuji")))
;;; ;Write correspondence alist from ABSOLUTE unix path name to URL path.
;;;
;;;[インストール方法]
;;;
;;; yahtml.el, yatexlib.el, yatexprc.el を load-path の通ったディレクト
;;; リにインストールしてください。その後、以下を参考に ~/.emacs に設定を
;;; 追加して下さい。
;;;
;;; (setq auto-mode-alist
;;; (cons (cons "\\.html$" 'yahtml-mode) auto-mode-alist))
;;; (autoload 'yahtml-mode "yahtml" "Yet Another HTML mode" t)
;;; (setq yahtml-www-browser "firefox")
;;; ;お気に入りのブラウザを書いて下さい。firefoxが便利です。
;;; (setq yahtml-path-url-alist
;;; '(("/home/yuuji/public_html" . "http://www.mynet/~yuuji")
;;; ("/home/staff/yuuji/html" . "http://www.othernet/~yuuji")))
;;; ;UNIXの絶対パスと対応するURLのリストを書いて下さい。
;;;
;;; HTMLファイル漢字コードが正しく判別されるようにホームディレクトリに
;;; .htaccess ファイルを作り以下のどれか1行を選んで書いて下さい。
;;;
;;; AddType "text/html; charset=Shift_JIS" .html (SJISの場合)
;;; AddType "text/html; charset=iso2022-jp" .html (JISの場合)
;;; AddType "text/html; charset=EUC-JP" .html (EUCの場合)
;;; AddType "text/html; charset=utf-8" .html (UTF-8の場合)
;;;
;;; .htaccess が作れない場合は
;;; (setq yahtml-kanji-code 2)
;;; ;HTMLファイルの漢字コードを変更する場合は
;;; ;1=SJIS、2=JIS、3=EUC 4=UTF-8
;;; ;で設定して下さい。デフォルトは 2 です。
;;;
;;; を適切に書き換えて ~/.emacs に足して下さい。
;;;
;;;[Commentary]
;;;
;;; It is assumed you are already familiar with YaTeX. The following
;;; completing featureas are available: ([prefix] means `C-c' by default)
;;;
;;; * [prefix] b X Complete environments such as `H1' which
;;; normally requires closing tag `</H1>
;;; <a href=foo> ... </a> is also classified into
;;; this group
;;; When input `href=...', you can complete file
;;; name or label(href="#foo") by typing TAB.
;;; * [prefix] l Complete typeface-changing commands such as
;;; `<i> ... </i>' or `<samp> ... </samp>'
;;; This completion can be used to make in-line
;;; tags which is normally completed with [prefix] b.
;;; * [prefix] s Complete declarative notations such as
;;; `<img src="foo.gif">'
;;; `<input name="var" ...>'
;;; * [prefix] m Complete single commands such as
;;; `<br>' or `<hr> or <li>...'
;;; * [prefix] p Insert <p></p> on the point
;;; * M-RET Intelligent newline; if current TAG is one of
;;; ul, ol, or dl. insert newline and <li> or
;;; <dt> or <dd> suitable for current condition.
;;; * menu-bar yahtml Complete all by selecting a menu item (Though I
;;; hate menu, this is most useful)
;;; * [prefix] g Goto corresponding Tag or HREF such as
;;; <dl> <-> </dl> or href="xxx".
;;; Or invoke image viewer if point is on <img src=...>.
;;; * [prefix] k Kill html tags on the point. If you provide
;;; universal-argument, kill surrounded contents too.
;;; * [prefix] c Change html tags on the point.
;;; When typeing [prefix] c on `href="xxx"', you can
;;; change the reference link with completion.
;;; * [prefix] t j Call weblint on current file.
;;; * [prefix] t p View current html with WWW browser
;;; (To activate this, never fail to set the lisp
;;; variable yahtml-www-browser. Recommended value
;;; is "firefox")
;;; * [prefix] a YaTeX's accent mark's equivalent of yahtml.
;;; This function can input $lt, $gt or so.
;;; * [prefix] ; Translate chars of `>', `<', `&', and `"' to
;;; `>', `<', `&', `"' respectively
;;; in the region.
;;; * [prefix] : Do translation opposite to above, in the region.
;;; * [prefix] # Translate unsafe-chars and unreserved-chars to
;;; URLencoded string in the region.
;;;
;;;[キーの説明]
;;;
;;; 以下の説明において、特にカスタマイズをしていない限り、[prefix] は
;;; C-c キーを意味します。
;;;
;;; * [prefix] b X `</H1>' といった終了タグが必要となる`H1'のよう
;;; な環境を補完入力します。<a href=foo> ... </a>
;;; もこのグループです。
;;; `href=...' と入力した後、TABキーを押すことで、
;;; ファイル名や (href="#foo") のようなラベルも補完
;;; できます。
;;; * [prefix] s 以下のような宣言の補完を行います。
;;; `<img src="foo.gif">'
;;; `<input name="var" ...>'
;;; * [prefix] l `<i> ... </i>' や `<samp> ... </samp>' のよう
;;; なテキストスタイル指定のタグを補完します。
;;; この補完機能は通常 [prefix] b で補完できるものを
;;; 一行内で書きたいときにも用いることが出来ます。
;;; * [prefix] m `<br>' や `<hr> '、`<li>' 等の単体タグの補完
;;; を行います。
;;; * [prefix] p カーソル位置に<p></p>を挿入します。
;;; * M-RET おまかせ改行; もしul、ol、dl等のタグ(リスト)を
;;; 使っている場合に、環境に合わせて改行と <li>、
;;; <dt>、<dd>を入力します。
;;; * menu-bar yahtml 選択したアイテムをメニューより補完できます。
;;; (私はメニューが嫌いなんですが、htmlに関してはメ
;;; ニューは一番ありがたいかも)
;;; * [prefix] g 対応するタグ、<dl> <-> </dl> や href="xxx" の
;;; ような TAG にジャンプします。
;;; <img src=...> の場合はイメージビューワを呼び出
;;; します。href=hoge.html の場合はhoge.htmlに飛びま
;;; す。
;;; * [prefix] k ポイント上の HTML タグを消去します。
;;; もし universal-argument を付けた場合(C-uを先に押
;;; す)HTMLタグで囲まれた内容も同時に消去します。
;;; * [prefix] c ポイント上のタグを変更します。
;;; `href="xxx"'の上で [prefix] c を利用した場合は、
;;; 参照しているリンクを補完機能を使いながら変更で
;;; きます。
;;; * [prefix] t j カレントファイルに対して jweblint を呼び出しま
;;; す。ファイル先頭付近に
;;; <!-- #lint コマンド -->
;;; と書いておくとそのコマンドを呼びます。
;;; * [prefix] t p WWW ブラウザでカレントファイルを表示します。
;;; (lisp変数 yahtml-www-browser の設定をお忘れな
;;; く。お推めは "firefox" です)
;;; * [prefix] a YaTeX のアクセント記号補完と同じです。
;;; < > 等が入力できます。
;;; * [prefix] ; 指定したリジョン中の > < & " をそれぞれ
;;; > < & " に変換します。
;;; * [prefix] : 指定したリジョン中で上と逆の変換をします。
;;; * [prefix] # 指定したリジョン中で%エンコードの必要な文字が
;;; あればそれらをエンコードします。
;;; * [prefix] } リジョン内の特定文字区切りのレコードを <td> 並びに
;;; 変換します。C-u (universal-argument) 付きで起動
;;; するとtd以外の任意要素で括ります。thdを指定する
;;; と最初の1つだけth,残りすべてをtdで括ります。
;;; * [prefix] ] リジョン内のすべての行をフィールドごとにtdで括り,
;;; さらに各行をtrで括ります。universal-argument を
;;; 付けるとフィールド括りをtd以外に指定できます。
;;; * [prefix] ESC yahtml-mode を抜け yahtml-mode に入る前に動作し
;;; ていたメジャーモードに戻ります。
;;;
;;; [謝辞]
;;;
;;; fj野鳥の会の皆さんには貴重な助言を頂きました。また、下に示す方々には
;;; 特に大きな協力を頂きました。あわせてここに感謝申し上げます。
;;;
;;; * 横田和也さん(マツダ)
;;; マニュアルの和訳をして頂きました。
;;; * 吉田尚志さん(NTT Data)
;;; Mule for Win32 での動作のさせ方を教えて頂きました。
;;; (というかほとんどやってもらった ^^;)
;;;
;;; Code:
(require 'yatexlib)
;;; --- customizable variable starts here ---
(defvar yahtml-prefix "\C-c"
"*Prefix key stroke of yahtml functions.")
(defvar yahtml-image-viewer "display" "*Image viewer program")
(defvar yahtml-www-browser "firefox" "*WWW Browser command")
(defvar yahtml-kanji-code 2
"*Kanji coding system number of html file; 1=sjis, 2=jis, 3=euc, 4=UTF-8")
;;(defvar yahtml-coding-system
;; (cdr (assq yahtml-kanji-code YaTeX-kanji-code-alist))
;; "Kanji coding system")
(and (featurep 'mule)
(integerp yahtml-kanji-code)
(setq yahtml-kanji-code
(cdr (assq yahtml-kanji-code YaTeX-kanji-code-alist))))
(defvar yahtml-fill-column 72 "*fill culumn used for yahtml-mode")
(defvar yahtml-fill-prefix nil "*fill prefix for yahtml-mode")
;;(defvar yahtml-www-server "www" "*Host name of your domain's WWW server")
(defvar yahtml-path-url-alist nil
"*Alist of unix path name vs. URL name of WWW server.
Ex.
'((\"/usr/home/yuuji/http\" . \"http://www.comp.ae.keio.ac.jp/~yuuji\")
(\"/home/yuuji/http\" . \"http://www.gentei.org/~yuuji\"))")
(defvar yahtml-directory-index "index.html"
"*Directory index file name;
Consult your site's WWW administrator.")
(defvar yahtml-environment-indent 1
"*Indentation depth of HTML's listing environment")
;; YaTeX-japan is defined in yatexlib.el
(defvar yahtml-lint-program (if YaTeX-japan "jweblint" "weblint")
"*Program name to lint HTML file")
(defvar yahtml-hate-too-deep-indentation nil
"*Non-nil for this variable suppress deep indentation in listing environments.")
(defvar yahtml-always-/p t
"*Those who always use <p> with </p> set this to t.")
(defvar yahtml-always-/li nil
"*Those who always use <li> with </li> set this to t.")
(defvar yahtml-always-/dt nil
"*Those who always use <dt> with </dt> set this to t.")
(defvar yahtml-always-/dd nil
"*Those who always use <dd> with </dd> set this to t.")
(defvar yahtml-p-prefered-env-regexp "^\\(body\\|dl\\|blockquote\\)"
"*Regexp of envs where paragraphed sentences are prefered.")
(defvar yahtml-template-file "~/public_html/template.html"
"*Template HTML file. It'll be inserted to empty file.")
(defvar yahtml-prefer-upcases nil
"*Non-nil for preferring upcase TAGs")
(defvar yahtml-prefer-upcase-attributes nil
"*Non-nil for preferring upcase attributes")
(defvar yahtml-server-type 'apache "*WWW server program type")
(defvar yahtml-apache-access-file ".htaccess"
"*Server access file name for apache")
(defvar yahtml-use-css t "*Use stylesheet or not")
(defvar yahtml-image-inspection-bytes 500000
"*Number of bytes to inspect the image for geometry information")
(defvar yahtml:img-default-alt-format "%xx%y(%sbytes)"
"*Default format of img entity's ALT attributes.
%x: width, %y: height, %s: size in bytes, %c: first comment string,
%f: filename")
(defvar yahtml-faithful-to-htmllint yahtml-always-/li
"*Non-nil doesn't put space after opening tags.")
(defvar yahtml-error-line-regexp
"^\\(.*\\)(\\([0-9]+\\)):\\|^line \\([0-9]+\\)"
"*Regexp of error position which is produced by lint program.")
(defvar yahtml-translate-hyphens-when-comment-region t
"*Non-nil for translate hyphens to - when comment-region")
(defvar yahtml-escape-chars 'ask
"*Escape reserved characters to URL-encoding or not.
Nil for never, t for everytime, and 'ask for inquiring
at each reserved chars.")
(defvar yahtml-use-font-lock (and (featurep 'font-lock)
(fboundp 'font-lock-fontify-region))
"*Non-nil means to use font-lock to fontify buffer.")
(defvar yahtml-use-hilit19 (and (featurep 'hilit19)
(not yahtml-use-font-lock))
"*Non-nil means to Use hilit19 to highlight buffer")
(defvar yahtml-mode-abbrev-table nil
"*Abbrev table in use in yahtml-mode buffers.")
(define-abbrev-table 'yahtml-mode-abbrev-table ())
(defvar yahtml-indentation-boundary "^\\s *<h[1-3]>"
"*Boundary regexp for indentation calculation.")
(defvar yahtml-html4-strict t
"*Non-nil means editing HTML 4.01 Strict.
Completing read for obsoleted attributes disabled.")
;;; --- customizable variable ends here ---
(defvar yahtml-prefix-map nil)
(defvar yahtml-mode-map nil "Keymap used in yahtml-mode.")
(defvar yahtml-lint-buffer-map nil "Keymap used in lint buffer.")
(defvar yahtml-shell-command-option
(or (and (boundp 'shell-command-option) shell-command-option)
(if (eq system-type 'ms-dos) "/c" "-c")))
(defvar yahtml-use-highlighting (or yahtml-use-font-lock yahtml-use-hilit19))
(defun yahtml-define-begend-key-normal (key env &optional map)
"Define short cut yahtml-insert-begend key."
(YaTeX-define-key
key
(list 'lambda '(arg) '(interactive "P")
(list 'yahtml-insert-begend 'arg env))
map))
(defun yahtml-define-begend-region-key (key env &optional map)
"Define short cut yahtml-insert-begend-region key."
(YaTeX-define-key key (list 'lambda nil '(interactive)
(list 'yahtml-insert-begend t env)) map))
(defun yahtml-define-begend-key (key env &optional map)
"Define short cut key for begin type completion both for
normal and region mode. To customize yahtml, user should use this function."
(yahtml-define-begend-key-normal key env map)
(if YaTeX-inhibit-prefix-letter nil
(yahtml-define-begend-region-key
(concat (upcase (substring key 0 1)) (substring key 1)) env map)))
(if yahtml-mode-map nil
(setq yahtml-mode-map (make-sparse-keymap)
yahtml-prefix-map (make-sparse-keymap))
(define-key yahtml-mode-map yahtml-prefix yahtml-prefix-map)
(define-key yahtml-mode-map "\M-\C-@" 'yahtml-mark-begend)
(if (and (boundp 'window-system) (eq window-system 'x) YaTeX-emacs-19)
(define-key yahtml-mode-map [?\M-\C- ] 'yahtml-mark-begend))
(define-key yahtml-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment)
(define-key yahtml-mode-map "\M-\C-e" 'YaTeX-end-of-environment)
(define-key yahtml-mode-map "\M-\C-m" 'yahtml-intelligent-newline)
(define-key yahtml-mode-map "\M-\C-j" 'yahtml-intelligent-newline)
(define-key yahtml-mode-map "\C-i" 'yahtml-indent-line)
(define-key yahtml-mode-map "&" 'yahtml-insert-amps)
(let ((map yahtml-prefix-map))
(YaTeX-define-key "^" 'yahtml-visit-main map)
(YaTeX-define-key "4^" 'yahtml-visit-main-other-window map)
(YaTeX-define-key "4g" 'yahtml-goto-corresponding-*-other-window map)
(YaTeX-define-key "44" 'YaTeX-switch-to-window map)
(and YaTeX-emacs-19 window-system
(progn
(YaTeX-define-key "5^" 'yahtml-visit-main-other-frame map)
(YaTeX-define-key "5g" 'yahtml-goto-corresponding-*-other-frame map)
(YaTeX-define-key "55" 'YaTeX-switch-to-window map)))
(YaTeX-define-key "v" 'yahtml-version map)
(YaTeX-define-key "s" 'yahtml-insert-form map)
(YaTeX-define-key "l" 'yahtml-insert-tag map)
(YaTeX-define-key "L" 'yahtml-insert-tag-region map)
(YaTeX-define-key "m" 'yahtml-insert-single map)
(YaTeX-define-key "n" '(lambda () (interactive) (insert (if yahtml-prefer-upcases "<BR>" "<br>"))) map)
(YaTeX-define-key "-" '(lambda () (interactive) (insert (if yahtml-prefer-upcases "<HR>" "<hr>") "\n")) map)
(YaTeX-define-key "p" 'yahtml-insert-p map)
(if YaTeX-no-begend-shortcut
(progn
(YaTeX-define-key "B" 'yahtml-insert-begend-region map)
(YaTeX-define-key "b" 'yahtml-insert-begend map))
(yahtml-define-begend-key "bh" "html" map)
(yahtml-define-begend-key "bH" "head" map)
(yahtml-define-begend-key "bt" "title" map)
(yahtml-define-begend-key "bT" "table" map)
(yahtml-define-begend-key "bb" "body" map)
(yahtml-define-begend-key "bc" "center" map)
(yahtml-define-begend-key "bd" "dl" map)
(yahtml-define-begend-key "bu" "ul" map)
(yahtml-define-begend-key "bo" "ol" map)
(yahtml-define-begend-key "b1" "h1" map)
(yahtml-define-begend-key "b2" "h2" map)
(yahtml-define-begend-key "b3" "h3" map)
(yahtml-define-begend-key "ba" "a" map)
(yahtml-define-begend-key "bf" "form" map)
(yahtml-define-begend-key "bs" "select" map)
(yahtml-define-begend-key "bv" "div" map)
(yahtml-define-begend-key "bS" "span" map)
(yahtml-define-begend-key "bp" "pre" map)
(YaTeX-define-key "b " 'yahtml-insert-begend map)
(YaTeX-define-key "B " 'yahtml-insert-begend-region map))
(YaTeX-define-key "e" 'YaTeX-end-environment map)
(YaTeX-define-key ">" 'yahtml-comment-region map)
(YaTeX-define-key "<" 'yahtml-uncomment-region map)
(YaTeX-define-key "g" 'yahtml-goto-corresponding-* map)
(YaTeX-define-key "k" 'yahtml-kill-* map)
(YaTeX-define-key "c" 'yahtml-change-* map)
(YaTeX-define-key "t" 'yahtml-browse-menu map)
(YaTeX-define-key "a" 'yahtml-complete-mark map)
(YaTeX-define-key "'" 'yahtml-prev-error map)
(YaTeX-define-key ";" 'yahtml-translate-region map)
(YaTeX-define-key ":" 'yahtml-translate-reverse-region map)
(YaTeX-define-key "#" 'yahtml-escape-chars-region map)
(YaTeX-define-key "}" 'yahtml-td-region map)
(YaTeX-define-key "]" 'yahtml-tr-region map)
;;;;;(YaTeX-define-key "i" 'yahtml-fill-item map)
(YaTeX-define-key "\e" 'yahtml-quit map))
(substitute-all-key-definition
'fill-paragraph 'yahtml-fill-paragraph yahtml-mode-map)
(substitute-all-key-definition
'kill-buffer 'YaTeX-kill-buffer yahtml-mode-map))
(if yahtml-lint-buffer-map nil
(setq yahtml-lint-buffer-map (make-keymap))
(define-key yahtml-lint-buffer-map " " 'yahtml-jump-to-error-line))
(defvar yahtml-paragraph-start
(concat
"^$\\|<!--\\|^[ \t]*</?\\(h[1-6]\\|p\\|d[ldt]\\|[bhtd][rdh]\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\|table\\|center\\|blockquote\\)\\b")
"*Regexp of html paragraph separater")
(defvar yahtml-paragraph-separate
(concat
"^$\\|<!--\\|^[ \t]*</?\\(h[1-6]\\|p\\|[bhtd][ldt]\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\|table\\|center\\|blockquote\\|!--\\)\\b")
"*Regexp of html paragraph separater")
(defvar yahtml-syntax-table nil
"*Syntax table for yahtml-mode")
(if yahtml-syntax-table nil
(setq yahtml-syntax-table
(make-syntax-table (standard-syntax-table)))
(modify-syntax-entry ?\< "(>" yahtml-syntax-table)
(modify-syntax-entry ?\> ")<" yahtml-syntax-table)
(modify-syntax-entry ?\n " " yahtml-syntax-table))
(defvar yahtml-command-regexp "[A-Za-z0-9]+"
"Regexp of constituent of html commands.")
;;; Completion tables for `form'
(defvar yahtml-form-table
'(("img") ("input") ("link") ("meta")))
(defvar yahtml-user-form-table nil)
(defvar yahtml-tmp-form-table nil)
(defvar yahtml-last-form "img")
(defvar yahtml-env-table
'(("html") ("head") ("title") ("body") ("dl") ("ul") ("ol") ("pre")
("a") ("form") ("select") ("center") ("textarea") ("blockquote")
("OrderedList" . "ol")
("UnorderedList" . "ul")
("DefinitionList" . "dl")
("Preformatted" . "pre")
("table") ("thead") ("tbody") ("tfoot") ("tr") ("th") ("td")
("address") ("button")
("h1") ("h2") ("h3") ("h4") ("h5") ("h6")
;; ("p") ;This makes indentation screwed up!
("style") ("script") ("noscript") ("div") ("object") ("ins") ("del")
))
(if yahtml-html4-strict
(setq yahtml-env-table
(delete (assoc "center" yahtml-env-table) yahtml-env-table)))
;(defvar yahtml-itemizing-regexp
; "\\(ul\\|ol\\|dl\\)"
; "Regexp of itemizing forms")
(defvar yahtml-user-env-table nil)
(defvar yahtml-tmp-env-table nil)
;;; Completion tables for typeface designator
(and yahtml-always-/p
(or (assoc "p" yahtml-env-table)
(setq yahtml-env-table (cons '("p") yahtml-env-table))))
(and yahtml-always-/li
(or (assoc "li" yahtml-env-table)
(setq yahtml-env-table (cons '("li") yahtml-env-table))))
(and yahtml-always-/dt
(or (assoc "dt" yahtml-env-table)
(setq yahtml-env-table (cons '("dt") yahtml-env-table))))
(and yahtml-always-/dd
(or (assoc "dd" yahtml-env-table)
(setq yahtml-env-table (cons '("dd") yahtml-env-table))))
(defvar yahtml-typeface-table
(append
'(("dfn") ("em") ("cite") ("code") ("kbd") ("samp") ("caption")
("strong") ("var") ("b") ("i") ("tt") ("big") ("small")
("sup") ("sub") ("span") ("abbr"))
(if (not yahtml-html4-strict)
'(("strike") ("s") ("u") ("font")))
yahtml-env-table)
"Default completion table of typeface designator")
(defvar yahtml-user-typeface-table nil)
(defvar yahtml-tmp-typeface-table nil)
(defvar yahtml-last-typeface-cmd "a")
(defvar yahtml-single-cmd-table
'(("hr") ("br") ("option")
("HorizontalRule" . "hr")
("BreakLine" . "br")
("exec" . "!--#exec")
("!--#exec")
("include" . "!--#include")
("!--#include")
;; ("Item" . "li")
;; ("DefineTerm" . "dt")
;; ("Description" . "dd")
;; ("dd") ("dt") ("li")
)
"Default completion table of HTML single command.")
(defvar yahtml-user-single-cmd-table nil)
(defvar yahtml-tmp-single-cmd-table nil)
(defvar yahtml-last-single-cmd nil)
(defvar yahtml-current-completion-type nil
"Has current completion type. This may be used in yahtml addin functions.")
(defvar yahtml-struct-name-regexp
(concat
"\\<\\("
;(mapconcat 'car yahtml-typeface-table "\\|")
(mapconcat 'car yahtml-env-table "\\|")
"\\)\\b")
"Regexp of structure beginning.")
(defvar yahtml-closable-regexp
(concat
"\\<\\("
(mapconcat 'car yahtml-typeface-table "\\|")
(mapconcat 'car yahtml-env-table "\\|")
"\\)\\b")
"Regexp of any closable elemnts.")
(defvar yahtml-indent-listing-constant t
"*Nil means indentation for listing obeys the column of `>'.
T for static indentation depth")
(or (assoc "p" yahtml-env-table)
(setq yahtml-env-table (cons '("p") yahtml-env-table)))
(defun yahtml-get-user-httpconf-entry (regexp)
(cond
((and (eq yahtml-server-type 'apache) ;;check .htaccess
buffer-file-name)
(let ((dir default-directory)
charset af ext (ldir "")
line
(case-fold-search t)
(uid (car (cdr (cdr (file-attributes "."))))))
(if (string-match "^[A-Z]:" dir)
(setq dir (substring dir 2))) ;remove drive letter
(while (and dir
(not (string= dir ldir))
(equal uid (car (cdr (cdr (file-attributes dir))))))
(setq af (expand-file-name yahtml-apache-access-file dir))
(if (file-exists-p af)
(save-excursion
(set-buffer (find-file-noselect af))
(save-excursion
(goto-char (point-min))
(if (re-search-forward regexp nil t)
(setq line (buffer-substring
(point-beginning-of-line)
(point-end-of-line))
dir nil)))
(kill-buffer (current-buffer))))
(if dir
(setq ldir dir
dir (substring dir 0 (string-match "/$" dir))
dir (file-name-directory dir))))
line))
(t nil)))
(defun yahtml-dir-default-charset ()
(let*((fn (file-name-nondirectory (or buffer-file-name "")))
(ext (substring fn (or (string-match "\\.[a-z0-9]+$" fn) 0)))
(ptn (format "^\\s *AddType.*charset=\\(.*\\)\\%s$" ext))
(case-fold-search t)
line
charset)
(if (setq line (yahtml-get-user-httpconf-entry ptn))
(progn
(string-match ptn line)
(setq charset
(substring line (match-beginning 1) (match-end 1)))
(cond
((string-match "iso-2022-jp" charset)
(setq charset 2))
((string-match "euc-jp" charset)
(setq charset 3))
((string-match "shift_jis" charset)
(setq charset 1))
((string-match "utf-8" charset)
(setq charset 4))
(t (setq charset nil)))
(setq dir "")))
(if (featurep 'mule)
(setq charset (cdr (assq charset YaTeX-kanji-code-alist))))
charset))
(defun yahtml-get-directory-index ()
(let ((line (yahtml-get-user-httpconf-entry "^\\s *DirectoryIndex"))
x index-list)
;;s/\\s *$//;
(if line
(progn
(if (string-match "DirectoryIndex\\s +\\(.*\\)\\s *$" line)
(setq line (substring line (match-beginning 1) (match-end 1))))
(while (string< "" line)
(if (setq x (string-match "\\(\\s +\\)" line))
(setq index-list (cons (substring line 0 x) index-list)
line (substring line (match-end 1)))
(setq index-list (cons line index-list)
line "")))
(or (nreverse index-list)
(if (listp yahtml-directory-index)
yahtml-directory-index
(list yahtml-directory-index)))))))
(defvar yahtml-mode-old-mode nil)
(defun yahtml-mode ()
(interactive)
(let ((old-mm major-mode)) ;Emacs21.0.95 resets major-mode
(kill-all-local-variables) ;with kill-all-local-variables
(if (not (eq 'yahtml-mode old-mm))
(set (make-local-variable 'yahtml-mode-old-mode) old-mm)))
(let ((coding (or (yahtml-dir-default-charset) yahtml-kanji-code)))
(cond
((null coding) nil)
((and YaTeX-emacs-20 (boundp 'buffer-file-coding-system))
(setq buffer-file-coding-system
(or (and (fboundp 'set-auto-coding) buffer-file-name
(save-excursion
(goto-char (point-min))
(set-auto-coding buffer-file-name (buffer-size))))
coding)))
((featurep 'mule)
(set-file-coding-system coding))
((boundp 'NEMACS)
(make-local-variable 'kanji-fileio-code)
(setq kanji-fileio-code coding))))
(setq major-mode 'yahtml-mode
mode-name "yahtml"
YaTeX-current-file-name (file-name-nondirectory
(or (buffer-file-name) ""))
local-abbrev-table yahtml-mode-abbrev-table)
(mapcar
(function (lambda (x)
(make-local-variable (car x))
(set (car x) (if (and (symbolp (cdr x))
(boundp (cdr x)))
(symbol-value (cdr x))
(cdr x)))))
'((YaTeX-ec . "")
(YaTeX-struct-begin . "<%1%2")
(YaTeX-struct-end . "</%1>")
(YaTeX-struct-name-regexp . yahtml-closable-regexp)
(YaTeX-comment-prefix . "<!--[^#]")
(YaTeX-coding-system . yahtml-kanji-code) ;necessary?
(YaTeX-typesetting-mode-map . yahtml-lint-buffer-map)
(fill-prefix . yahtml-fill-prefix) (fill-column . yahtml-fill-column)
(paragraph-start . yahtml-paragraph-start)
(paragraph-separate . yahtml-paragraph-separate)
(comment-start . "<!-- ") (comment-end . " -->")
(comment-start-skip . comment-start)
(indent-line-function . yahtml-indent-line)))
(if yahtml-use-font-lock
(progn
(yahtml-font-lock-set-default-keywords)
(or (featurep 'xemacs)
(progn
(set (make-local-variable 'font-lock-defaults)
'(yahtml-font-lock-keywords nil t))
;;(font-lock-mode -1)
(font-lock-mode 1) ;;Why should I fontify again???
;; in yatex-mode, there's no need to refontify...
(font-lock-fontify-buffer)))))
(set-syntax-table yahtml-syntax-table)
(use-local-map yahtml-mode-map)
(YaTeX-read-user-completion-table)
(yahtml-css-scan-styles)
(turn-on-auto-fill) ;Sorry, this is prerequisite
(and (= 0 (buffer-size)) (file-exists-p yahtml-template-file)
(y-or-n-p (format "Insert %s?" yahtml-template-file))
(insert-file-contents (expand-file-name yahtml-template-file)))
(run-hooks 'text-mode-hook 'yahtml-mode-hook)
;; This warning should be removed after a while(2000/12/2)
(let ((fld (or (and (local-variable-p 'font-lock-defaults (current-buffer))
font-lock-defaults)
(get 'yahtml-mode 'font-lock-defaults))))
(and fld (not (memq 'yahtml-font-lock-keywords fld))
(YaTeX-warning-font-lock "yahtml"))))
(defun yahtml-version ()
"Return string of the version of running yahtml."
(interactive)
(message
(concat "Yet Another HTML-mode "
(if YaTeX-japan "「HTML屋」" "`yahtml'")
" Revision "
yahtml-revision-number)))
(defun yahtml-quit ()
(interactive)
(and yahtml-mode-old-mode
(fboundp yahtml-mode-old-mode)
(funcall yahtml-mode-old-mode)))
(defun yahtml-define-menu (keymap bindlist)
(cond
((featurep 'xemacs)
(let ((name (keymap-name (symbol-value keymap))))
(set keymap nil)
(mapcar
(function
(lambda (bind)
(setq bind (cdr bind))
(if (eq (car (cdr bind)) 'lambda)
(setcar (cdr bind) 'progn))
(if (stringp (car (cdr bind)))
(set keymap (cons (cdr bind) (symbol-value keymap)))
(set keymap (cons (vector (car bind) (cdr bind) t)
(symbol-value keymap))))))
bindlist)
(set keymap (cons name (symbol-value keymap)))))
(t
(mapcar
(function
(lambda (bind)
(define-key (symbol-value keymap) (vector (car bind)) (cdr bind))))
bindlist))))
(defvar yahtml-menu-map nil "Menu map of yahtml")
(defvar yahtml-menu-map-sectioning nil "Menu map of yahtml(sectioning)")
(defvar yahtml-menu-map-listing nil "Menu map of yahtml(listing)")
(defvar yahtml-menu-map-logical nil "Menu map of yahtml(logical tags)")
(defvar yahtml-menu-map-typeface nil "Menu map of yahtml(typeface tags)")
;;; Variables for mosaic url history
(defvar yahtml-urls nil "Alist of global history")
(defvar yahtml-urls-private nil)
(defvar yahtml-urls-local nil)
(cond
((and YaTeX-emacs-19 (null yahtml-menu-map))
(setq yahtml-menu-map (make-sparse-keymap "yahtml"))
(setq yahtml-menu-map-sectioning (make-sparse-keymap "sectioning menu"))
(YaTeX-define-menu
'yahtml-menu-map-sectioning
(nreverse
'((1 "H1" . (lambda () (interactive) (yahtml-insert-begend nil "H1")))
(2 "H2" . (lambda () (interactive) (yahtml-insert-begend nil "H2")))
(3 "H3" . (lambda () (interactive) (yahtml-insert-begend nil "H3")))
(4 "H4" . (lambda () (interactive) (yahtml-insert-begend nil "H4")))
(5 "H5" . (lambda () (interactive) (yahtml-insert-begend nil "H5")))
(6 "H6" . (lambda () (interactive) (yahtml-insert-begend nil "H6")))
)))
(setq yahtml-menu-map-logical (make-sparse-keymap "logical tags"))
(YaTeX-define-menu
'yahtml-menu-map-logical
(nreverse
'((em "Embolden" .
(lambda () (interactive) (yahtml-insert-tag nil "EM")))
(dfn "Define a word" .
(lambda () (interactive) (yahtml-insert-tag nil "DFN")))
(cite "Citation" .
(lambda () (interactive) (yahtml-insert-tag nil "CITE")))
(code "Code" .
(lambda () (interactive) (yahtml-insert-tag nil "CODE")))
(kbd "Keyboard" .
(lambda () (interactive) (yahtml-insert-tag nil "KBD")))
(samp "Sample display" .
(lambda () (interactive) (yahtml-insert-tag nil "SAMP")))
(strong "Strong" .
(lambda () (interactive) (yahtml-insert-tag nil "STRONG")))
(VAR "Variable notation" .
(lambda () (interactive) (yahtml-insert-tag nil "var"))))))
(setq yahtml-menu-map-typeface (make-sparse-keymap "typeface tags"))
(YaTeX-define-menu
'yahtml-menu-map-typeface
(nreverse
'((b "Bold" .
(lambda () (interactive) (yahtml-insert-tag nil "b")))
(i "Italic" .
(lambda () (interactive) (yahtml-insert-tag nil "i")))
(tt "Typewriter" .
(lambda () (interactive) (yahtml-insert-tag nil "tt")))
(u "Underlined" .
(lambda () (interactive) (yahtml-insert-tag nil "u"))))))
(setq yahtml-menu-map-listing (make-sparse-keymap "listing"))
(YaTeX-define-menu
'yahtml-menu-map-listing
(nreverse
'((ul "Unordered" .
(lambda () (interactive) (yahtml-insert-begend nil "ul")))
(ol "Ordered" .
(lambda () (interactive) (yahtml-insert-begend nil "ol")))
(dl "Definition" .
(lambda () (interactive) (yahtml-insert-begend nil "dl"))))))
(setq yahtml-menu-map-item (make-sparse-keymap "item"))
(YaTeX-define-menu
'yahtml-menu-map-item
(nreverse
'((li "Simple item" .
(lambda () (interactive) (yahtml-insert-single "li")))
(dt "Define term" .
(lambda () (interactive) (yahtml-insert-single "dt")))
(dd "Description of term" .
(lambda () (interactive) (yahtml-insert-single "dd"))))))
(define-key yahtml-mode-map [menu-bar yahtml]
(cons "yahtml" yahtml-menu-map))
(YaTeX-define-menu
'yahtml-menu-map
(nreverse
(list
(cons (list 'sect "Sectioning")
(cons "sectioning" yahtml-menu-map-sectioning))
(cons (list 'list "Listing")
(cons "Listing" yahtml-menu-map-listing))
(cons (list 'item "Item")
(cons "Itemizing" yahtml-menu-map-item));;;
(cons (list 'logi "Logical tags")
(cons "logical" yahtml-menu-map-logical))
(cons (list 'type "Typeface tags")
(cons "typeface" yahtml-menu-map-typeface)))))
(if (featurep 'xemacs)
(add-hook 'yahtml-mode-hook
'(lambda ()
(or (assoc "yahtml" current-menubar)
(progn
(set-buffer-menubar (copy-sequence current-menubar))
(add-submenu nil yahtml-menu-map))))))))
;;; ----------- Completion ----------
(defvar yahtml-last-begend "html")
(defun yahtml-insert-begend (&optional region env)
"Insert <cmd> ... </cmd>."
(interactive "P")
(setq yahtml-current-completion-type 'multiline)
(let*((completion-ignore-case t)
(cmd
(or env
(YaTeX-cplread-with-learning
(format "Environment(default %s): " yahtml-last-begend)
'yahtml-env-table 'yahtml-user-env-table 'yahtml-tmp-env-table)))
(bolp (save-excursion
(skip-chars-backward " \t" (point-beginning-of-line)) (bolp)))
(cc (current-column)))
(if (string< "" cmd) (setq yahtml-last-begend cmd))
(setq yahtml-last-begend
(or (cdr (assoc yahtml-last-begend yahtml-env-table))
yahtml-last-begend))
(setq cmd yahtml-last-begend)
(setq cmd (funcall (if yahtml-prefer-upcases 'upcase 'downcase) cmd))
(if region
;; We want to keep region effective for new tagged environment
;; to enable continuous regioning by another environment
(let ((beg (region-beginning))
(end (region-end))
(addin (yahtml-addin cmd)))
(save-excursion
(goto-char end)
(insert-before-markers (format "</%s>%s" cmd (if bolp "\n" "")))
(goto-char beg)
(insert (format "<%s%s>%s" cmd addin (if bolp "\n" "")))))
(insert (format "<%s%s>" cmd (yahtml-addin cmd)))
(save-excursion
(insert "\n")
(indent-to-column cc)
(insert (format "</%s>" cmd)))
(if (string-match "^a\\|p$" cmd) ;aとp決め打ちってのが美しくない…
(newline)
(yahtml-intelligent-newline nil))
(yahtml-indent-line))))
(defun yahtml-insert-begend-region ()
"Call yahtml-insert-begend in the region mode."
(interactive)
(yahtml-insert-begend t))
(defun yahtml-insert-form (&optional form)
"Insert <FORM option=\"argument\">."
(interactive)
(setq yahtml-current-completion-type 'single)
(or form
(let ((completion-ignore-case t))
(setq form
(YaTeX-cplread-with-learning
(format "Form(default %s): " yahtml-last-form)
'yahtml-form-table 'yahtml-user-form-table
'yahtml-tmp-form-table))))
(let ((p (point)) q)
(if (string= form "") (setq form yahtml-last-form))
(setq yahtml-last-form form)
(if yahtml-prefer-upcases (setq form (upcase form)))
(insert (format "<%s%s>" form (yahtml-addin form)))
;;(indent-relative-maybe)
(if (cdr (assoc form yahtml-form-table))
(save-excursion (insert (format "</%s>" form))))
(if (search-backward "\"\"" p t) (forward-char 1))))
(defun yahtml-read-css (alist)
(let ((completion-ignore-case t) (delim " ")
(minibuffer-completion-table alist))
(read-from-minibuffer
(substitute-command-keys
(if YaTeX-japan
"クラス(複数指定は\\[quoted-insert] SPCで区切る): "
"class(or class list delimited by \\[quoted-insert] SPC): "))
nil YaTeX-minibuffer-completion-map nil)))
(defvar yahtml-newpage-command "newpage.rb"
"*Command name to create new HTML file referring to index.html.
This command should create new HTML file named argument 1 and
output string like `<a href=\"newfile.html\">anchor tag</a>'.
This program should take -o option to overwrite existing HTML file.")
(defun yahtml-newpage (file ov)
"Create newpage via newpage script"
(interactive
(list
(let (insert-default-directory)
(read-file-name "New webpage file name: " ""))
current-prefix-arg))
(if (and (file-exists-p file) (not ov))
(error "%s already exists. Call this with universal argument to force overwrite." file))
(insert (substring
(YaTeX-command-to-string
(concat yahtml-newpage-command " " (if ov "-o ") file))
0 -1)))
;;; ---------- Add-in ----------
(defun yahtml-addin (form)
"Check add-in function's existence and call it if exists."
(let ((addin (concat "yahtml:" (downcase form))) s a)
(concat
(and (setq a (yahtml-css-get-element-completion-alist form))
(not (equal (YaTeX-last-key) ?\C-j))
(memq yahtml-current-completion-type '(multiline inline))
(not (string-match "#" form))
(yahtml-make-optional-argument ;should be made generic?
"class" (yahtml-read-css a)))
(if (and (intern-soft addin) (fboundp (intern-soft addin))
(stringp (setq s (funcall (intern addin))))
(string< "" s))
(if (eq (aref s 0) ? ) s (concat " " s))
""))))
(defvar yahtml-completing-buffer nil)
(defun yahtml-collect-labels (&optional file)
"Collect current buffers label (<?? name=...>).
If optional argument FILE is specified collect labels in FILE."
(let (list end)
(save-excursion
(set-buffer yahtml-completing-buffer)
(if file (let (hilit-auto-highlight)
(set-buffer (find-file-noselect file))))
(save-excursion
(goto-char (point-min))
(while ;(re-search-forward "<\\w+\\b" nil t)
(re-search-forward "\\(name\\|id\\)\\s *=" nil t)
;(setq bound (match-end 0))
;(search-forward ">" nil t)
(setq end (match-end 0))
(if (and ;(re-search-backward "\\(name\\|id\\)\\s *=" bound t)
(yahtml-on-assignment-p)
(progn
(goto-char end)
(skip-chars-forward " \t\n")
(looking-at "\"?#?\\([^\">]+\\)\"?\\b")))
(setq list (cons
(list (concat "#" (YaTeX-match-string 1)))
list))))
list))))
(defvar yahtml-url-completion-map nil "Key map used in URL completion buffer")
(if yahtml-url-completion-map nil
(setq yahtml-url-completion-map
(copy-keymap minibuffer-local-completion-map))
(define-key yahtml-url-completion-map "\t" 'yahtml-complete-url)
(define-key yahtml-url-completion-map " " 'yahtml-complete-url))
(defun yahtml-complete-url ()
"Complete external URL from history or local file name."
(interactive)
(let ((p (point)) initial i2 cmpl path dir file listfunc beg labels
(lim (YaTeX-minibuffer-begin))
(min (if (fboundp 'field-beginning) (field-beginning) (point-min))))
(setq initial (YaTeX-minibuffer-string))
(cond
((string-match "^http:" initial)
(setq cmpl (try-completion initial yahtml-urls)
listfunc (list 'lambda nil
(list 'all-completions initial 'yahtml-urls))
beg min))
((setq beg (string-match "#" initial))
(or (equal beg 0) ;begin with #
(progn
(setq path (substring initial 0 beg))
(if (string-match "^/" path)
(setq path (yahtml-url-to-path path)))))
(setq initial (substring initial beg))
(setq labels (yahtml-collect-labels path)
cmpl (try-completion initial labels)
listfunc (list 'lambda ()
(list 'all-completions
initial (list 'quote labels)))
beg (+ min beg)))
(t
(setq path (if (string-match "^/" initial)
(or (yahtml-url-to-path initial) initial)
initial))
(setq dir (or (file-name-directory path) ".")
file (file-name-nondirectory path)