rev |
line source |
yuuji@286
|
1 ;;; yahtml.el --- Yet Another HTML mode -*- coding: sjis -*-
|
yuuji@294
|
2 ;;; (c) 1994-2013 by HIROSE Yuuji [yuuji(@)yatex.org]
|
yuuji@294
|
3 ;;; Last modified Mon Apr 1 22:42:29 2013 on firestorm
|
yuuji@121
|
4 ;;; $Id$
|
yuuji@54
|
5
|
yuuji@271
|
6 (defconst yahtml-revision-number "1.76"
|
yuuji@72
|
7 "Revision number of running yahtml.el")
|
yuuji@72
|
8
|
yuuji@286
|
9 ;;; Commentary:
|
yuuji@286
|
10
|
yuuji@58
|
11 ;;;[Installation]
|
yuuji@58
|
12 ;;;
|
yuuji@58
|
13 ;;; First, you have to install YaTeX and make sure it works fine. Then
|
yuuji@58
|
14 ;;; put these expressions into your ~/.emacs
|
yuuji@58
|
15 ;;;
|
yuuji@58
|
16 ;;; (setq auto-mode-alist
|
yuuji@58
|
17 ;;; (cons (cons "\\.html$" 'yahtml-mode) auto-mode-alist))
|
yuuji@58
|
18 ;;; (autoload 'yahtml-mode "yahtml" "Yet Another HTML mode" t)
|
yuuji@115
|
19 ;;; (setq yahtml-www-browser "firefox")
|
yuuji@115
|
20 ;;; ;Write your favorite browser. But firefox is advantageous.
|
yuuji@58
|
21 ;;; (setq yahtml-path-url-alist
|
yuuji@58
|
22 ;;; '(("/home/yuuji/public_html" . "http://www.mynet/~yuuji")
|
yuuji@58
|
23 ;;; ("/home/staff/yuuji/html" . "http://www.othernet/~yuuji")))
|
yuuji@58
|
24 ;;; ;Write correspondence alist from ABSOLUTE unix path name to URL path.
|
yuuji@58
|
25 ;;;
|
yuuji@64
|
26 ;;;[インストール方法]
|
yuuji@64
|
27 ;;;
|
yuuji@64
|
28 ;;; yahtml.el, yatexlib.el, yatexprc.el を load-path の通ったディレクト
|
yuuji@64
|
29 ;;; リにインストールしてください。その後、以下を参考に ~/.emacs に設定を
|
yuuji@64
|
30 ;;; 追加して下さい。
|
yuuji@64
|
31 ;;;
|
yuuji@64
|
32 ;;; (setq auto-mode-alist
|
yuuji@64
|
33 ;;; (cons (cons "\\.html$" 'yahtml-mode) auto-mode-alist))
|
yuuji@64
|
34 ;;; (autoload 'yahtml-mode "yahtml" "Yet Another HTML mode" t)
|
yuuji@115
|
35 ;;; (setq yahtml-www-browser "firefox")
|
yuuji@115
|
36 ;;; ;お気に入りのブラウザを書いて下さい。firefoxが便利です。
|
yuuji@64
|
37 ;;; (setq yahtml-path-url-alist
|
yuuji@64
|
38 ;;; '(("/home/yuuji/public_html" . "http://www.mynet/~yuuji")
|
yuuji@64
|
39 ;;; ("/home/staff/yuuji/html" . "http://www.othernet/~yuuji")))
|
yuuji@64
|
40 ;;; ;UNIXの絶対パスと対応するURLのリストを書いて下さい。
|
yuuji@64
|
41 ;;;
|
yuuji@77
|
42 ;;; HTMLファイル漢字コードが正しく判別されるようにホームディレクトリに
|
yuuji@77
|
43 ;;; .htaccess ファイルを作り以下のどれか1行を選んで書いて下さい。
|
yuuji@77
|
44 ;;;
|
yuuji@77
|
45 ;;; AddType "text/html; charset=Shift_JIS" .html (SJISの場合)
|
yuuji@77
|
46 ;;; AddType "text/html; charset=iso2022-jp" .html (JISの場合)
|
yuuji@77
|
47 ;;; AddType "text/html; charset=EUC-JP" .html (EUCの場合)
|
yuuji@102
|
48 ;;; AddType "text/html; charset=utf-8" .html (UTF-8の場合)
|
yuuji@77
|
49 ;;;
|
yuuji@77
|
50 ;;; .htaccess が作れない場合は
|
yuuji@77
|
51 ;;; (setq yahtml-kanji-code 2)
|
yuuji@102
|
52 ;;; ;HTMLファイルの漢字コードを変更する場合は
|
yuuji@102
|
53 ;;; ;1=SJIS、2=JIS、3=EUC 4=UTF-8
|
yuuji@77
|
54 ;;; ;で設定して下さい。デフォルトは 2 です。
|
yuuji@77
|
55 ;;;
|
yuuji@77
|
56 ;;; を適切に書き換えて ~/.emacs に足して下さい。
|
yuuji@77
|
57 ;;;
|
yuuji@54
|
58 ;;;[Commentary]
|
yuuji@13
|
59 ;;;
|
yuuji@54
|
60 ;;; It is assumed you are already familiar with YaTeX. The following
|
yuuji@54
|
61 ;;; completing featureas are available: ([prefix] means `C-c' by default)
|
yuuji@54
|
62 ;;;
|
yuuji@54
|
63 ;;; * [prefix] b X Complete environments such as `H1' which
|
yuuji@57
|
64 ;;; normally requires closing tag `</H1>
|
yuuji@57
|
65 ;;; <a href=foo> ... </a> is also classified into
|
yuuji@57
|
66 ;;; this group
|
yuuji@59
|
67 ;;; When input `href=...', you can complete file
|
yuuji@59
|
68 ;;; name or label(href="#foo") by typing TAB.
|
yuuji@54
|
69 ;;; * [prefix] l Complete typeface-changing commands such as
|
yuuji@54
|
70 ;;; `<i> ... </i>' or `<samp> ... </samp>'
|
yuuji@60
|
71 ;;; This completion can be used to make in-line
|
yuuji@60
|
72 ;;; tags which is normally completed with [prefix] b.
|
yuuji@64
|
73 ;;; * [prefix] s Complete declarative notations such as
|
yuuji@64
|
74 ;;; `<img src="foo.gif">'
|
yuuji@64
|
75 ;;; `<input name="var" ...>'
|
yuuji@57
|
76 ;;; * [prefix] m Complete single commands such as
|
yuuji@58
|
77 ;;; `<br>' or `<hr> or <li>...'
|
yuuji@64
|
78 ;;; * [prefix] p Insert <p></p> on the point
|
yuuji@59
|
79 ;;; * M-RET Intelligent newline; if current TAG is one of
|
yuuji@59
|
80 ;;; ul, ol, or dl. insert newline and <li> or
|
yuuji@59
|
81 ;;; <dt> or <dd> suitable for current condition.
|
yuuji@54
|
82 ;;; * menu-bar yahtml Complete all by selecting a menu item (Though I
|
yuuji@54
|
83 ;;; hate menu, this is most useful)
|
yuuji@58
|
84 ;;; * [prefix] g Goto corresponding Tag or HREF such as
|
yuuji@59
|
85 ;;; <dl> <-> </dl> or href="xxx".
|
yuuji@59
|
86 ;;; Or invoke image viewer if point is on <img src=...>.
|
yuuji@58
|
87 ;;; * [prefix] k Kill html tags on the point. If you provide
|
yuuji@58
|
88 ;;; universal-argument, kill surrounded contents too.
|
yuuji@58
|
89 ;;; * [prefix] c Change html tags on the point.
|
yuuji@59
|
90 ;;; When typeing [prefix] c on `href="xxx"', you can
|
yuuji@59
|
91 ;;; change the reference link with completion.
|
yuuji@60
|
92 ;;; * [prefix] t j Call weblint on current file.
|
yuuji@60
|
93 ;;; * [prefix] t p View current html with WWW browser
|
yuuji@58
|
94 ;;; (To activate this, never fail to set the lisp
|
yuuji@58
|
95 ;;; variable yahtml-www-browser. Recommended value
|
yuuji@115
|
96 ;;; is "firefox")
|
yuuji@59
|
97 ;;; * [prefix] a YaTeX's accent mark's equivalent of yahtml.
|
yuuji@59
|
98 ;;; This function can input $lt, $gt or so.
|
yuuji@69
|
99 ;;; * [prefix] ; Translate chars of `>', `<', `&', and `"' to
|
yuuji@69
|
100 ;;; `>', `<', `&', `"' respectively
|
yuuji@69
|
101 ;;; in the region.
|
yuuji@69
|
102 ;;; * [prefix] : Do translation opposite to above, in the region.
|
yuuji@69
|
103 ;;; * [prefix] # Translate unsafe-chars and unreserved-chars to
|
yuuji@69
|
104 ;;; URLencoded string in the region.
|
yuuji@58
|
105 ;;;
|
yuuji@64
|
106 ;;;[キーの説明]
|
yuuji@64
|
107 ;;;
|
yuuji@64
|
108 ;;; 以下の説明において、特にカスタマイズをしていない限り、[prefix] は
|
yuuji@64
|
109 ;;; C-c キーを意味します。
|
yuuji@64
|
110 ;;;
|
yuuji@64
|
111 ;;; * [prefix] b X `</H1>' といった終了タグが必要となる`H1'のよう
|
yuuji@64
|
112 ;;; な環境を補完入力します。<a href=foo> ... </a>
|
yuuji@64
|
113 ;;; もこのグループです。
|
yuuji@64
|
114 ;;; `href=...' と入力した後、TABキーを押すことで、
|
yuuji@64
|
115 ;;; ファイル名や (href="#foo") のようなラベルも補完
|
yuuji@64
|
116 ;;; できます。
|
yuuji@64
|
117 ;;; * [prefix] s 以下のような宣言の補完を行います。
|
yuuji@64
|
118 ;;; `<img src="foo.gif">'
|
yuuji@64
|
119 ;;; `<input name="var" ...>'
|
yuuji@64
|
120 ;;; * [prefix] l `<i> ... </i>' や `<samp> ... </samp>' のよう
|
yuuji@64
|
121 ;;; なテキストスタイル指定のタグを補完します。
|
yuuji@64
|
122 ;;; この補完機能は通常 [prefix] b で補完できるものを
|
yuuji@64
|
123 ;;; 一行内で書きたいときにも用いることが出来ます。
|
yuuji@64
|
124 ;;; * [prefix] m `<br>' や `<hr> '、`<li>' 等の単体タグの補完
|
yuuji@64
|
125 ;;; を行います。
|
yuuji@64
|
126 ;;; * [prefix] p カーソル位置に<p></p>を挿入します。
|
yuuji@64
|
127 ;;; * M-RET おまかせ改行; もしul、ol、dl等のタグ(リスト)を
|
yuuji@64
|
128 ;;; 使っている場合に、環境に合わせて改行と <li>、
|
yuuji@64
|
129 ;;; <dt>、<dd>を入力します。
|
yuuji@64
|
130 ;;; * menu-bar yahtml 選択したアイテムをメニューより補完できます。
|
yuuji@64
|
131 ;;; (私はメニューが嫌いなんですが、htmlに関してはメ
|
yuuji@64
|
132 ;;; ニューは一番ありがたいかも)
|
yuuji@64
|
133 ;;; * [prefix] g 対応するタグ、<dl> <-> </dl> や href="xxx" の
|
yuuji@64
|
134 ;;; ような TAG にジャンプします。
|
yuuji@64
|
135 ;;; <img src=...> の場合はイメージビューワを呼び出
|
yuuji@64
|
136 ;;; します。href=hoge.html の場合はhoge.htmlに飛びま
|
yuuji@64
|
137 ;;; す。
|
yuuji@64
|
138 ;;; * [prefix] k ポイント上の HTML タグを消去します。
|
yuuji@64
|
139 ;;; もし universal-argument を付けた場合(C-uを先に押
|
yuuji@64
|
140 ;;; す)HTMLタグで囲まれた内容も同時に消去します。
|
yuuji@64
|
141 ;;; * [prefix] c ポイント上のタグを変更します。
|
yuuji@64
|
142 ;;; `href="xxx"'の上で [prefix] c を利用した場合は、
|
yuuji@64
|
143 ;;; 参照しているリンクを補完機能を使いながら変更で
|
yuuji@64
|
144 ;;; きます。
|
yuuji@64
|
145 ;;; * [prefix] t j カレントファイルに対して jweblint を呼び出しま
|
yuuji@160
|
146 ;;; す。ファイル先頭付近に
|
yuuji@160
|
147 ;;; <!-- #lint コマンド -->
|
yuuji@160
|
148 ;;; と書いておくとそのコマンドを呼びます。
|
yuuji@64
|
149 ;;; * [prefix] t p WWW ブラウザでカレントファイルを表示します。
|
yuuji@64
|
150 ;;; (lisp変数 yahtml-www-browser の設定をお忘れな
|
yuuji@115
|
151 ;;; く。お推めは "firefox" です)
|
yuuji@64
|
152 ;;; * [prefix] a YaTeX のアクセント記号補完と同じです。
|
yuuji@64
|
153 ;;; < > 等が入力できます。
|
yuuji@69
|
154 ;;; * [prefix] ; 指定したリジョン中の > < & " をそれぞれ
|
yuuji@69
|
155 ;;; > < & " に変換します。
|
yuuji@69
|
156 ;;; * [prefix] : 指定したリジョン中で上と逆の変換をします。
|
yuuji@69
|
157 ;;; * [prefix] # 指定したリジョン中で%エンコードの必要な文字が
|
yuuji@69
|
158 ;;; あればそれらをエンコードします。
|
yuuji@160
|
159 ;;; * [prefix] } リジョン内の特定文字区切りのレコードを <td> 並びに
|
yuuji@160
|
160 ;;; 変換します。C-u (universal-argument) 付きで起動
|
yuuji@160
|
161 ;;; するとtd以外の任意要素で括ります。thdを指定する
|
yuuji@160
|
162 ;;; と最初の1つだけth,残りすべてをtdで括ります。
|
yuuji@160
|
163 ;;; * [prefix] ] リジョン内のすべての行をフィールドごとにtdで括り,
|
yuuji@160
|
164 ;;; さらに各行をtrで括ります。universal-argument を
|
yuuji@160
|
165 ;;; 付けるとフィールド括りをtd以外に指定できます。
|
yuuji@72
|
166 ;;; * [prefix] ESC yahtml-mode を抜け yahtml-mode に入る前に動作し
|
yuuji@72
|
167 ;;; ていたメジャーモードに戻ります。
|
yuuji@64
|
168 ;;;
|
yuuji@64
|
169 ;;; [謝辞]
|
yuuji@64
|
170 ;;;
|
yuuji@64
|
171 ;;; fj野鳥の会の皆さんには貴重な助言を頂きました。また、下に示す方々には
|
yuuji@64
|
172 ;;; 特に大きな協力を頂きました。あわせてここに感謝申し上げます。
|
yuuji@64
|
173 ;;;
|
yuuji@64
|
174 ;;; * 横田和也さん(マツダ)
|
yuuji@64
|
175 ;;; マニュアルの和訳をして頂きました。
|
yuuji@64
|
176 ;;; * 吉田尚志さん(NTT Data)
|
yuuji@64
|
177 ;;; Mule for Win32 での動作のさせ方を教えて頂きました。
|
yuuji@64
|
178 ;;; (というかほとんどやってもらった ^^;)
|
yuuji@64
|
179 ;;;
|
yuuji@54
|
180
|
yuuji@286
|
181 ;;; Code:
|
yuuji@13
|
182
|
yuuji@64
|
183 (require 'yatexlib)
|
yuuji@60
|
184 ;;; --- customizable variable starts here ---
|
yuuji@64
|
185 (defvar yahtml-prefix "\C-c"
|
yuuji@64
|
186 "*Prefix key stroke of yahtml functions.")
|
yuuji@80
|
187 (defvar yahtml-image-viewer "display" "*Image viewer program")
|
yuuji@80
|
188 (defvar yahtml-www-browser "firefox" "*WWW Browser command")
|
yuuji@58
|
189 (defvar yahtml-kanji-code 2
|
yuuji@88
|
190 "*Kanji coding system number of html file; 1=sjis, 2=jis, 3=euc, 4=UTF-8")
|
yuuji@69
|
191 ;;(defvar yahtml-coding-system
|
yuuji@69
|
192 ;; (cdr (assq yahtml-kanji-code YaTeX-kanji-code-alist))
|
yuuji@69
|
193 ;; "Kanji coding system")
|
yuuji@69
|
194 (and (featurep 'mule)
|
yuuji@69
|
195 (integerp yahtml-kanji-code)
|
yuuji@69
|
196 (setq yahtml-kanji-code
|
yuuji@69
|
197 (cdr (assq yahtml-kanji-code YaTeX-kanji-code-alist))))
|
yuuji@69
|
198
|
yuuji@64
|
199 (defvar yahtml-fill-column 72 "*fill culumn used for yahtml-mode")
|
yuuji@64
|
200 (defvar yahtml-fill-prefix nil "*fill prefix for yahtml-mode")
|
yuuji@64
|
201
|
yuuji@58
|
202 ;;(defvar yahtml-www-server "www" "*Host name of your domain's WWW server")
|
yuuji@58
|
203 (defvar yahtml-path-url-alist nil
|
yuuji@58
|
204 "*Alist of unix path name vs. URL name of WWW server.
|
yuuji@58
|
205 Ex.
|
yuuji@58
|
206 '((\"/usr/home/yuuji/http\" . \"http://www.comp.ae.keio.ac.jp/~yuuji\")
|
yuuji@70
|
207 (\"/home/yuuji/http\" . \"http://www.gentei.org/~yuuji\"))")
|
yuuji@58
|
208 (defvar yahtml-directory-index "index.html"
|
yuuji@58
|
209 "*Directory index file name;
|
yuuji@58
|
210 Consult your site's WWW administrator.")
|
yuuji@57
|
211
|
yuuji@64
|
212 (defvar yahtml-environment-indent 1
|
yuuji@60
|
213 "*Indentation depth of HTML's listing environment")
|
yuuji@60
|
214
|
yuuji@79
|
215 ;; YaTeX-japan is defined in yatexlib.el
|
yuuji@60
|
216 (defvar yahtml-lint-program (if YaTeX-japan "jweblint" "weblint")
|
yuuji@60
|
217 "*Program name to lint HTML file")
|
yuuji@60
|
218 (defvar yahtml-hate-too-deep-indentation nil
|
yuuji@60
|
219 "*Non-nil for this variable suppress deep indentation in listing environments.")
|
yuuji@60
|
220
|
yuuji@80
|
221 (defvar yahtml-always-/p t
|
yuuji@64
|
222 "*Those who always use <p> with </p> set this to t.")
|
yuuji@80
|
223 (defvar yahtml-always-/li nil
|
yuuji@80
|
224 "*Those who always use <li> with </li> set this to t.")
|
yuuji@80
|
225 (defvar yahtml-always-/dt nil
|
yuuji@80
|
226 "*Those who always use <dt> with </dt> set this to t.")
|
yuuji@80
|
227 (defvar yahtml-always-/dd nil
|
yuuji@80
|
228 "*Those who always use <dd> with </dd> set this to t.")
|
yuuji@64
|
229
|
yuuji@70
|
230 (defvar yahtml-p-prefered-env-regexp "^\\(body\\|dl\\|blockquote\\)"
|
yuuji@64
|
231 "*Regexp of envs where paragraphed sentences are prefered.")
|
yuuji@64
|
232
|
yuuji@80
|
233 (defvar yahtml-template-file "~/public_html/template.html"
|
yuuji@64
|
234 "*Template HTML file. It'll be inserted to empty file.")
|
yuuji@64
|
235
|
yuuji@69
|
236 (defvar yahtml-prefer-upcases nil
|
yuuji@69
|
237 "*Non-nil for preferring upcase TAGs")
|
yuuji@69
|
238
|
yuuji@69
|
239 (defvar yahtml-prefer-upcase-attributes nil
|
yuuji@69
|
240 "*Non-nil for preferring upcase attributes")
|
yuuji@69
|
241
|
yuuji@80
|
242 (defvar yahtml-server-type 'apache "*WWW server program type")
|
yuuji@69
|
243
|
yuuji@69
|
244 (defvar yahtml-apache-access-file ".htaccess"
|
yuuji@69
|
245 "*Server access file name for apache")
|
yuuji@69
|
246
|
yuuji@69
|
247 (defvar yahtml-use-css t "*Use stylesheet or not")
|
yuuji@69
|
248
|
yuuji@161
|
249 (defvar yahtml-image-inspection-bytes 500000
|
yuuji@70
|
250 "*Number of bytes to inspect the image for geometry information")
|
yuuji@70
|
251 (defvar yahtml:img-default-alt-format "%xx%y(%sbytes)"
|
yuuji@70
|
252 "*Default format of img entity's ALT attributes.
|
yuuji@70
|
253 %x: width, %y: height, %s: size in bytes, %c: first comment string,
|
yuuji@70
|
254 %f: filename")
|
yuuji@70
|
255
|
yuuji@203
|
256 (defvar yahtml-faithful-to-htmllint yahtml-always-/li
|
yuuji@190
|
257 "*Non-nil doesn't put space after opening tags.")
|
yuuji@190
|
258
|
yuuji@72
|
259 (defvar yahtml-error-line-regexp
|
yuuji@72
|
260 "^\\(.*\\)(\\([0-9]+\\)):\\|^line \\([0-9]+\\)"
|
yuuji@72
|
261 "*Regexp of error position which is produced by lint program.")
|
yuuji@72
|
262
|
yuuji@72
|
263 (defvar yahtml-translate-hyphens-when-comment-region t
|
yuuji@72
|
264 "*Non-nil for translate hyphens to - when comment-region")
|
yuuji@72
|
265 (defvar yahtml-escape-chars 'ask
|
yuuji@72
|
266 "*Escape reserved characters to URL-encoding or not.
|
yuuji@72
|
267 Nil for never, t for everytime, and 'ask for inquiring
|
yuuji@72
|
268 at each reserved chars.")
|
yuuji@72
|
269
|
yuuji@72
|
270 (defvar yahtml-use-font-lock (and (featurep 'font-lock)
|
yuuji@72
|
271 (fboundp 'font-lock-fontify-region))
|
yuuji@72
|
272 "*Non-nil means to use font-lock to fontify buffer.")
|
yuuji@72
|
273
|
yuuji@72
|
274 (defvar yahtml-use-hilit19 (and (featurep 'hilit19)
|
yuuji@72
|
275 (not yahtml-use-font-lock))
|
yuuji@72
|
276 "*Non-nil means to Use hilit19 to highlight buffer")
|
yuuji@70
|
277
|
yuuji@73
|
278 (defvar yahtml-mode-abbrev-table nil
|
yuuji@73
|
279 "*Abbrev table in use in yahtml-mode buffers.")
|
yuuji@73
|
280 (define-abbrev-table 'yahtml-mode-abbrev-table ())
|
yuuji@73
|
281
|
yuuji@73
|
282 (defvar yahtml-indentation-boundary "^\\s *<h[1-3]>"
|
yuuji@73
|
283 "*Boundary regexp for indentation calculation.")
|
yuuji@73
|
284
|
yuuji@80
|
285 (defvar yahtml-html4-strict t
|
yuuji@80
|
286 "*Non-nil means editing HTML 4.01 Strict.
|
yuuji@80
|
287 Completing read for obsoleted attributes disabled.")
|
yuuji@80
|
288
|
yuuji@60
|
289 ;;; --- customizable variable ends here ---
|
yuuji@60
|
290 (defvar yahtml-prefix-map nil)
|
yuuji@60
|
291 (defvar yahtml-mode-map nil "Keymap used in yahtml-mode.")
|
yuuji@60
|
292 (defvar yahtml-lint-buffer-map nil "Keymap used in lint buffer.")
|
yuuji@60
|
293 (defvar yahtml-shell-command-option
|
yuuji@60
|
294 (or (and (boundp 'shell-command-option) shell-command-option)
|
yuuji@60
|
295 (if (eq system-type 'ms-dos) "/c" "-c")))
|
yuuji@72
|
296 (defvar yahtml-use-highlighting (or yahtml-use-font-lock yahtml-use-hilit19))
|
yuuji@60
|
297
|
yuuji@57
|
298 (defun yahtml-define-begend-key-normal (key env &optional map)
|
yuuji@60
|
299 "Define short cut yahtml-insert-begend key."
|
yuuji@57
|
300 (YaTeX-define-key
|
yuuji@57
|
301 key
|
yuuji@57
|
302 (list 'lambda '(arg) '(interactive "P")
|
yuuji@60
|
303 (list 'yahtml-insert-begend 'arg env))
|
yuuji@57
|
304 map))
|
yuuji@57
|
305
|
yuuji@57
|
306 (defun yahtml-define-begend-region-key (key env &optional map)
|
yuuji@60
|
307 "Define short cut yahtml-insert-begend-region key."
|
yuuji@57
|
308 (YaTeX-define-key key (list 'lambda nil '(interactive)
|
yuuji@60
|
309 (list 'yahtml-insert-begend t env)) map))
|
yuuji@57
|
310
|
yuuji@57
|
311 (defun yahtml-define-begend-key (key env &optional map)
|
yuuji@57
|
312 "Define short cut key for begin type completion both for
|
yuuji@57
|
313 normal and region mode. To customize yahtml, user should use this function."
|
yuuji@57
|
314 (yahtml-define-begend-key-normal key env map)
|
yuuji@57
|
315 (if YaTeX-inhibit-prefix-letter nil
|
yuuji@57
|
316 (yahtml-define-begend-region-key
|
yuuji@61
|
317 (concat (upcase (substring key 0 1)) (substring key 1)) env map)))
|
yuuji@57
|
318
|
yuuji@13
|
319 (if yahtml-mode-map nil
|
yuuji@57
|
320 (setq yahtml-mode-map (make-sparse-keymap)
|
yuuji@57
|
321 yahtml-prefix-map (make-sparse-keymap))
|
yuuji@64
|
322 (define-key yahtml-mode-map yahtml-prefix yahtml-prefix-map)
|
yuuji@58
|
323 (define-key yahtml-mode-map "\M-\C-@" 'yahtml-mark-begend)
|
yuuji@58
|
324 (if (and (boundp 'window-system) (eq window-system 'x) YaTeX-emacs-19)
|
yuuji@58
|
325 (define-key yahtml-mode-map [?\M-\C- ] 'yahtml-mark-begend))
|
yuuji@54
|
326 (define-key yahtml-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment)
|
yuuji@57
|
327 (define-key yahtml-mode-map "\M-\C-e" 'YaTeX-end-of-environment)
|
yuuji@58
|
328 (define-key yahtml-mode-map "\M-\C-m" 'yahtml-intelligent-newline)
|
yuuji@80
|
329 (define-key yahtml-mode-map "\M-\C-j" 'yahtml-intelligent-newline)
|
yuuji@58
|
330 (define-key yahtml-mode-map "\C-i" 'yahtml-indent-line)
|
yuuji@70
|
331 (define-key yahtml-mode-map "&" 'yahtml-insert-amps)
|
yuuji@57
|
332 (let ((map yahtml-prefix-map))
|
yuuji@57
|
333 (YaTeX-define-key "^" 'yahtml-visit-main map)
|
yuuji@57
|
334 (YaTeX-define-key "4^" 'yahtml-visit-main-other-window map)
|
yuuji@57
|
335 (YaTeX-define-key "4g" 'yahtml-goto-corresponding-*-other-window map)
|
yuuji@57
|
336 (YaTeX-define-key "44" 'YaTeX-switch-to-window map)
|
yuuji@57
|
337 (and YaTeX-emacs-19 window-system
|
yuuji@57
|
338 (progn
|
yuuji@57
|
339 (YaTeX-define-key "5^" 'yahtml-visit-main-other-frame map)
|
yuuji@57
|
340 (YaTeX-define-key "5g" 'yahtml-goto-corresponding-*-other-frame map)
|
yuuji@57
|
341 (YaTeX-define-key "55" 'YaTeX-switch-to-window map)))
|
yuuji@72
|
342 (YaTeX-define-key "v" 'yahtml-version map)
|
yuuji@57
|
343 (YaTeX-define-key "s" 'yahtml-insert-form map)
|
yuuji@57
|
344 (YaTeX-define-key "l" 'yahtml-insert-tag map)
|
yuuji@61
|
345 (YaTeX-define-key "L" 'yahtml-insert-tag-region map)
|
yuuji@57
|
346 (YaTeX-define-key "m" 'yahtml-insert-single map)
|
yuuji@61
|
347 (YaTeX-define-key "n" '(lambda () (interactive) (insert (if yahtml-prefer-upcases "<BR>" "<br>"))) map)
|
yuuji@61
|
348 (YaTeX-define-key "-" '(lambda () (interactive) (insert (if yahtml-prefer-upcases "<HR>" "<hr>") "\n")) map)
|
yuuji@64
|
349 (YaTeX-define-key "p" 'yahtml-insert-p map)
|
yuuji@57
|
350 (if YaTeX-no-begend-shortcut
|
yuuji@57
|
351 (progn
|
yuuji@57
|
352 (YaTeX-define-key "B" 'yahtml-insert-begend-region map)
|
yuuji@57
|
353 (YaTeX-define-key "b" 'yahtml-insert-begend map))
|
yuuji@60
|
354 (yahtml-define-begend-key "bh" "html" map)
|
yuuji@60
|
355 (yahtml-define-begend-key "bH" "head" map)
|
yuuji@60
|
356 (yahtml-define-begend-key "bt" "title" map)
|
yuuji@59
|
357 (yahtml-define-begend-key "bT" "table" map)
|
yuuji@60
|
358 (yahtml-define-begend-key "bb" "body" map)
|
yuuji@60
|
359 (yahtml-define-begend-key "bc" "center" map)
|
yuuji@60
|
360 (yahtml-define-begend-key "bd" "dl" map)
|
yuuji@60
|
361 (yahtml-define-begend-key "bu" "ul" map)
|
yuuji@80
|
362 (yahtml-define-begend-key "bo" "ol" map)
|
yuuji@60
|
363 (yahtml-define-begend-key "b1" "h1" map)
|
yuuji@60
|
364 (yahtml-define-begend-key "b2" "h2" map)
|
yuuji@60
|
365 (yahtml-define-begend-key "b3" "h3" map)
|
yuuji@57
|
366 (yahtml-define-begend-key "ba" "a" map)
|
yuuji@57
|
367 (yahtml-define-begend-key "bf" "form" map)
|
yuuji@57
|
368 (yahtml-define-begend-key "bs" "select" map)
|
yuuji@79
|
369 (yahtml-define-begend-key "bv" "div" map)
|
yuuji@80
|
370 (yahtml-define-begend-key "bS" "span" map)
|
yuuji@79
|
371 (yahtml-define-begend-key "bp" "pre" map)
|
yuuji@57
|
372 (YaTeX-define-key "b " 'yahtml-insert-begend map)
|
yuuji@102
|
373 (YaTeX-define-key "B " 'yahtml-insert-begend-region map))
|
yuuji@58
|
374 (YaTeX-define-key "e" 'YaTeX-end-environment map)
|
yuuji@57
|
375 (YaTeX-define-key ">" 'yahtml-comment-region map)
|
yuuji@57
|
376 (YaTeX-define-key "<" 'yahtml-uncomment-region map)
|
yuuji@57
|
377 (YaTeX-define-key "g" 'yahtml-goto-corresponding-* map)
|
yuuji@58
|
378 (YaTeX-define-key "k" 'yahtml-kill-* map)
|
yuuji@58
|
379 (YaTeX-define-key "c" 'yahtml-change-* map)
|
yuuji@58
|
380 (YaTeX-define-key "t" 'yahtml-browse-menu map)
|
yuuji@59
|
381 (YaTeX-define-key "a" 'yahtml-complete-mark map)
|
yuuji@60
|
382 (YaTeX-define-key "'" 'yahtml-prev-error map)
|
yuuji@69
|
383 (YaTeX-define-key ";" 'yahtml-translate-region map)
|
yuuji@69
|
384 (YaTeX-define-key ":" 'yahtml-translate-reverse-region map)
|
yuuji@69
|
385 (YaTeX-define-key "#" 'yahtml-escape-chars-region map)
|
yuuji@154
|
386 (YaTeX-define-key "}" 'yahtml-td-region map)
|
yuuji@154
|
387 (YaTeX-define-key "]" 'yahtml-tr-region map)
|
yuuji@58
|
388 ;;;;;(YaTeX-define-key "i" 'yahtml-fill-item map)
|
yuuji@102
|
389 (YaTeX-define-key "\e" 'yahtml-quit map))
|
yuuji@72
|
390 (substitute-all-key-definition
|
yuuji@72
|
391 'fill-paragraph 'yahtml-fill-paragraph yahtml-mode-map)
|
yuuji@72
|
392 (substitute-all-key-definition
|
yuuji@72
|
393 'kill-buffer 'YaTeX-kill-buffer yahtml-mode-map))
|
yuuji@60
|
394
|
yuuji@60
|
395 (if yahtml-lint-buffer-map nil
|
yuuji@60
|
396 (setq yahtml-lint-buffer-map (make-keymap))
|
yuuji@60
|
397 (define-key yahtml-lint-buffer-map " " 'yahtml-jump-to-error-line))
|
yuuji@60
|
398
|
yuuji@54
|
399
|
yuuji@59
|
400 (defvar yahtml-paragraph-start
|
yuuji@59
|
401 (concat
|
yuuji@61
|
402 "^$\\|<!--\\|^[ \t]*</?\\(h[1-6]\\|p\\|d[ldt]\\|[bhtd][rdh]\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\|table\\|center\\|blockquote\\)\\b")
|
yuuji@59
|
403 "*Regexp of html paragraph separater")
|
yuuji@57
|
404 (defvar yahtml-paragraph-separate
|
yuuji@57
|
405 (concat
|
yuuji@61
|
406 "^$\\|<!--\\|^[ \t]*</?\\(h[1-6]\\|p\\|[bhtd][ldt]\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\|table\\|center\\|blockquote\\|!--\\)\\b")
|
yuuji@57
|
407 "*Regexp of html paragraph separater")
|
yuuji@54
|
408 (defvar yahtml-syntax-table nil
|
yuuji@64
|
409 "*Syntax table for yahtml-mode")
|
yuuji@54
|
410
|
yuuji@54
|
411 (if yahtml-syntax-table nil
|
yuuji@54
|
412 (setq yahtml-syntax-table
|
yuuji@54
|
413 (make-syntax-table (standard-syntax-table)))
|
yuuji@61
|
414 (modify-syntax-entry ?\< "(>" yahtml-syntax-table)
|
yuuji@61
|
415 (modify-syntax-entry ?\> ")<" yahtml-syntax-table)
|
yuuji@102
|
416 (modify-syntax-entry ?\n " " yahtml-syntax-table))
|
yuuji@102
|
417
|
yuuji@54
|
418 (defvar yahtml-command-regexp "[A-Za-z0-9]+"
|
yuuji@54
|
419 "Regexp of constituent of html commands.")
|
yuuji@54
|
420
|
yuuji@54
|
421 ;;; Completion tables for `form'
|
yuuji@57
|
422 (defvar yahtml-form-table
|
yuuji@69
|
423 '(("img") ("input") ("link") ("meta")))
|
yuuji@54
|
424 (defvar yahtml-user-form-table nil)
|
yuuji@54
|
425 (defvar yahtml-tmp-form-table nil)
|
yuuji@64
|
426 (defvar yahtml-last-form "img")
|
yuuji@54
|
427
|
yuuji@54
|
428 (defvar yahtml-env-table
|
yuuji@60
|
429 '(("html") ("head") ("title") ("body") ("dl") ("ul") ("ol") ("pre")
|
yuuji@60
|
430 ("a") ("form") ("select") ("center") ("textarea") ("blockquote")
|
yuuji@58
|
431 ("OrderedList" . "ol")
|
yuuji@58
|
432 ("UnorderedList" . "ul")
|
yuuji@58
|
433 ("DefinitionList" . "dl")
|
yuuji@59
|
434 ("Preformatted" . "pre")
|
yuuji@80
|
435 ("table") ("thead") ("tbody") ("tfoot") ("tr") ("th") ("td")
|
yuuji@136
|
436 ("address") ("button")
|
yuuji@61
|
437 ("h1") ("h2") ("h3") ("h4") ("h5") ("h6")
|
yuuji@64
|
438 ;; ("p") ;This makes indentation screwed up!
|
yuuji@80
|
439 ("style") ("script") ("noscript") ("div") ("object") ("ins") ("del")
|
yuuji@64
|
440 ))
|
yuuji@57
|
441
|
yuuji@80
|
442 (if yahtml-html4-strict
|
yuuji@80
|
443 (setq yahtml-env-table
|
yuuji@80
|
444 (delete (assoc "center" yahtml-env-table) yahtml-env-table)))
|
yuuji@80
|
445
|
yuuji@69
|
446 ;(defvar yahtml-itemizing-regexp
|
yuuji@69
|
447 ; "\\(ul\\|ol\\|dl\\)"
|
yuuji@69
|
448 ; "Regexp of itemizing forms")
|
yuuji@58
|
449
|
yuuji@57
|
450 (defvar yahtml-user-env-table nil)
|
yuuji@57
|
451 (defvar yahtml-tmp-env-table nil)
|
yuuji@54
|
452
|
yuuji@54
|
453 ;;; Completion tables for typeface designator
|
yuuji@64
|
454 (and yahtml-always-/p
|
yuuji@64
|
455 (or (assoc "p" yahtml-env-table)
|
yuuji@64
|
456 (setq yahtml-env-table (cons '("p") yahtml-env-table))))
|
yuuji@80
|
457 (and yahtml-always-/li
|
yuuji@80
|
458 (or (assoc "li" yahtml-env-table)
|
yuuji@80
|
459 (setq yahtml-env-table (cons '("li") yahtml-env-table))))
|
yuuji@80
|
460 (and yahtml-always-/dt
|
yuuji@80
|
461 (or (assoc "dt" yahtml-env-table)
|
yuuji@80
|
462 (setq yahtml-env-table (cons '("dt") yahtml-env-table))))
|
yuuji@80
|
463 (and yahtml-always-/dd
|
yuuji@80
|
464 (or (assoc "dd" yahtml-env-table)
|
yuuji@80
|
465 (setq yahtml-env-table (cons '("dd") yahtml-env-table))))
|
yuuji@64
|
466
|
yuuji@54
|
467 (defvar yahtml-typeface-table
|
yuuji@60
|
468 (append
|
yuuji@80
|
469 '(("dfn") ("em") ("cite") ("code") ("kbd") ("samp") ("caption")
|
yuuji@80
|
470 ("strong") ("var") ("b") ("i") ("tt") ("big") ("small")
|
yuuji@80
|
471 ("sup") ("sub") ("span") ("abbr"))
|
yuuji@80
|
472 (if (not yahtml-html4-strict)
|
yuuji@80
|
473 '(("strike") ("s") ("u") ("font")))
|
yuuji@60
|
474 yahtml-env-table)
|
yuuji@54
|
475 "Default completion table of typeface designator")
|
yuuji@54
|
476 (defvar yahtml-user-typeface-table nil)
|
yuuji@54
|
477 (defvar yahtml-tmp-typeface-table nil)
|
yuuji@64
|
478 (defvar yahtml-last-typeface-cmd "a")
|
yuuji@54
|
479
|
yuuji@57
|
480 (defvar yahtml-single-cmd-table
|
yuuji@80
|
481 '(("hr") ("br") ("option")
|
yuuji@80
|
482 ("HorizontalRule" . "hr")
|
yuuji@58
|
483 ("BreakLine" . "br")
|
yuuji@80
|
484 ("exec" . "!--#exec")
|
yuuji@80
|
485 ("!--#exec")
|
yuuji@80
|
486 ("include" . "!--#include")
|
yuuji@80
|
487 ("!--#include")
|
yuuji@80
|
488 ;; ("Item" . "li")
|
yuuji@80
|
489 ;; ("DefineTerm" . "dt")
|
yuuji@80
|
490 ;; ("Description" . "dd")
|
yuuji@80
|
491 ;; ("dd") ("dt") ("li")
|
yuuji@58
|
492 )
|
yuuji@57
|
493 "Default completion table of HTML single command.")
|
yuuji@57
|
494 (defvar yahtml-user-single-cmd-table nil)
|
yuuji@57
|
495 (defvar yahtml-tmp-single-cmd-table nil)
|
yuuji@57
|
496 (defvar yahtml-last-single-cmd nil)
|
yuuji@57
|
497
|
yuuji@70
|
498 (defvar yahtml-current-completion-type nil
|
yuuji@70
|
499 "Has current completion type. This may be used in yahtml addin functions.")
|
yuuji@70
|
500
|
yuuji@57
|
501 (defvar yahtml-struct-name-regexp
|
yuuji@61
|
502 (concat
|
yuuji@61
|
503 "\\<\\("
|
yuuji@70
|
504 ;(mapconcat 'car yahtml-typeface-table "\\|")
|
yuuji@70
|
505 (mapconcat 'car yahtml-env-table "\\|")
|
yuuji@61
|
506 "\\)\\b")
|
yuuji@61
|
507 "Regexp of structure beginning.")
|
yuuji@70
|
508
|
yuuji@70
|
509 (defvar yahtml-closable-regexp
|
yuuji@70
|
510 (concat
|
yuuji@70
|
511 "\\<\\("
|
yuuji@70
|
512 (mapconcat 'car yahtml-typeface-table "\\|")
|
yuuji@70
|
513 (mapconcat 'car yahtml-env-table "\\|")
|
yuuji@70
|
514 "\\)\\b")
|
yuuji@70
|
515 "Regexp of any closable elemnts.")
|
yuuji@73
|
516
|
yuuji@73
|
517 (defvar yahtml-indent-listing-constant t
|
yuuji@73
|
518 "*Nil means indentation for listing obeys the column of `>'.
|
yuuji@73
|
519 T for static indentation depth")
|
yuuji@70
|
520
|
yuuji@64
|
521 (or (assoc "p" yahtml-env-table)
|
yuuji@64
|
522 (setq yahtml-env-table (cons '("p") yahtml-env-table)))
|
yuuji@57
|
523
|
yuuji@70
|
524
|
yuuji@70
|
525 (defun yahtml-get-user-httpconf-entry (regexp)
|
yuuji@69
|
526 (cond
|
yuuji@69
|
527 ((and (eq yahtml-server-type 'apache) ;;check .htaccess
|
yuuji@69
|
528 buffer-file-name)
|
yuuji@69
|
529 (let ((dir default-directory)
|
yuuji@69
|
530 charset af ext (ldir "")
|
yuuji@70
|
531 line
|
yuuji@69
|
532 (case-fold-search t)
|
yuuji@69
|
533 (uid (car (cdr (cdr (file-attributes "."))))))
|
yuuji@69
|
534 (if (string-match "^[A-Z]:" dir)
|
yuuji@69
|
535 (setq dir (substring dir 2))) ;remove drive letter
|
yuuji@69
|
536 (while (and dir
|
yuuji@69
|
537 (not (string= dir ldir))
|
yuuji@69
|
538 (equal uid (car (cdr (cdr (file-attributes dir))))))
|
yuuji@69
|
539 (setq af (expand-file-name yahtml-apache-access-file dir))
|
yuuji@69
|
540 (if (file-exists-p af)
|
yuuji@69
|
541 (save-excursion
|
yuuji@69
|
542 (set-buffer (find-file-noselect af))
|
yuuji@69
|
543 (save-excursion
|
yuuji@69
|
544 (goto-char (point-min))
|
yuuji@70
|
545 (if (re-search-forward regexp nil t)
|
yuuji@70
|
546 (setq line (buffer-substring
|
yuuji@70
|
547 (point-beginning-of-line)
|
yuuji@70
|
548 (point-end-of-line))
|
yuuji@70
|
549 dir nil)))
|
yuuji@69
|
550 (kill-buffer (current-buffer))))
|
yuuji@70
|
551 (if dir
|
yuuji@70
|
552 (setq ldir dir
|
yuuji@70
|
553 dir (substring dir 0 (string-match "/$" dir))
|
yuuji@70
|
554 dir (file-name-directory dir))))
|
yuuji@102
|
555 line))
|
yuuji@102
|
556 (t nil)))
|
yuuji@69
|
557
|
yuuji@70
|
558 (defun yahtml-dir-default-charset ()
|
yuuji@70
|
559 (let*((fn (file-name-nondirectory (or buffer-file-name "")))
|
yuuji@70
|
560 (ext (substring fn (or (string-match "\\.[a-z0-9]+$" fn) 0)))
|
yuuji@70
|
561 (ptn (format "^\\s *AddType.*charset=\\(.*\\)\\%s$" ext))
|
yuuji@77
|
562 (case-fold-search t)
|
yuuji@70
|
563 line
|
yuuji@70
|
564 charset)
|
yuuji@70
|
565 (if (setq line (yahtml-get-user-httpconf-entry ptn))
|
yuuji@70
|
566 (progn
|
yuuji@70
|
567 (string-match ptn line)
|
yuuji@70
|
568 (setq charset
|
yuuji@70
|
569 (substring line (match-beginning 1) (match-end 1)))
|
yuuji@70
|
570 (cond
|
yuuji@70
|
571 ((string-match "iso-2022-jp" charset)
|
yuuji@70
|
572 (setq charset 2))
|
yuuji@70
|
573 ((string-match "euc-jp" charset)
|
yuuji@70
|
574 (setq charset 3))
|
yuuji@70
|
575 ((string-match "shift_jis" charset)
|
yuuji@70
|
576 (setq charset 1))
|
yuuji@80
|
577 ((string-match "utf-8" charset)
|
yuuji@80
|
578 (setq charset 4))
|
yuuji@70
|
579 (t (setq charset nil)))
|
yuuji@70
|
580 (setq dir "")))
|
yuuji@70
|
581 (if (featurep 'mule)
|
yuuji@70
|
582 (setq charset (cdr (assq charset YaTeX-kanji-code-alist))))
|
yuuji@70
|
583 charset))
|
yuuji@70
|
584
|
yuuji@70
|
585 (defun yahtml-get-directory-index ()
|
yuuji@70
|
586 (let ((line (yahtml-get-user-httpconf-entry "^\\s *DirectoryIndex"))
|
yuuji@70
|
587 x index-list)
|
yuuji@70
|
588 ;;s/\\s *$//;
|
yuuji@70
|
589 (if line
|
yuuji@70
|
590 (progn
|
yuuji@70
|
591 (if (string-match "DirectoryIndex\\s +\\(.*\\)\\s *$" line)
|
yuuji@70
|
592 (setq line (substring line (match-beginning 1) (match-end 1))))
|
yuuji@70
|
593 (while (string< "" line)
|
yuuji@70
|
594 (if (setq x (string-match "\\(\\s +\\)" line))
|
yuuji@70
|
595 (setq index-list (cons (substring line 0 x) index-list)
|
yuuji@70
|
596 line (substring line (match-end 1)))
|
yuuji@70
|
597 (setq index-list (cons line index-list)
|
yuuji@102
|
598 line "")))
|
yuuji@70
|
599 (or (nreverse index-list)
|
yuuji@70
|
600 (if (listp yahtml-directory-index)
|
yuuji@70
|
601 yahtml-directory-index
|
yuuji@70
|
602 (list yahtml-directory-index)))))))
|
yuuji@70
|
603
|
yuuji@72
|
604 (defvar yahtml-mode-old-mode nil)
|
yuuji@13
|
605 (defun yahtml-mode ()
|
yuuji@13
|
606 (interactive)
|
yuuji@73
|
607 (let ((old-mm major-mode)) ;Emacs21.0.95 resets major-mode
|
yuuji@73
|
608 (kill-all-local-variables) ;with kill-all-local-variables
|
yuuji@73
|
609 (if (not (eq 'yahtml-mode old-mm))
|
yuuji@73
|
610 (set (make-local-variable 'yahtml-mode-old-mode) old-mm)))
|
yuuji@69
|
611 (let ((coding (or (yahtml-dir-default-charset) yahtml-kanji-code)))
|
yuuji@69
|
612 (cond
|
yuuji@79
|
613 ((null coding) nil)
|
yuuji@69
|
614 ((and YaTeX-emacs-20 (boundp 'buffer-file-coding-system))
|
yuuji@72
|
615 (setq buffer-file-coding-system
|
yuuji@72
|
616 (or (and (fboundp 'set-auto-coding) buffer-file-name
|
yuuji@80
|
617 (save-excursion
|
yuuji@80
|
618 (goto-char (point-min))
|
yuuji@80
|
619 (set-auto-coding buffer-file-name (buffer-size))))
|
yuuji@72
|
620 coding)))
|
yuuji@69
|
621 ((featurep 'mule)
|
yuuji@69
|
622 (set-file-coding-system coding))
|
yuuji@69
|
623 ((boundp 'NEMACS)
|
yuuji@69
|
624 (make-local-variable 'kanji-fileio-code)
|
yuuji@69
|
625 (setq kanji-fileio-code coding))))
|
yuuji@13
|
626 (setq major-mode 'yahtml-mode
|
yuuji@72
|
627 mode-name "yahtml"
|
yuuji@73
|
628 YaTeX-current-file-name (file-name-nondirectory
|
yuuji@73
|
629 (or (buffer-file-name) ""))
|
yuuji@73
|
630 local-abbrev-table yahtml-mode-abbrev-table)
|
yuuji@64
|
631 (mapcar
|
yuuji@64
|
632 (function (lambda (x)
|
yuuji@64
|
633 (make-local-variable (car x))
|
yuuji@64
|
634 (set (car x) (if (and (symbolp (cdr x))
|
yuuji@64
|
635 (boundp (cdr x)))
|
yuuji@64
|
636 (symbol-value (cdr x))
|
yuuji@64
|
637 (cdr x)))))
|
yuuji@64
|
638 '((YaTeX-ec . "")
|
yuuji@64
|
639 (YaTeX-struct-begin . "<%1%2")
|
yuuji@64
|
640 (YaTeX-struct-end . "</%1>")
|
yuuji@70
|
641 (YaTeX-struct-name-regexp . yahtml-closable-regexp)
|
yuuji@80
|
642 (YaTeX-comment-prefix . "<!--[^#]")
|
yuuji@69
|
643 (YaTeX-coding-system . yahtml-kanji-code) ;necessary?
|
yuuji@64
|
644 (YaTeX-typesetting-mode-map . yahtml-lint-buffer-map)
|
yuuji@64
|
645 (fill-prefix . yahtml-fill-prefix) (fill-column . yahtml-fill-column)
|
yuuji@64
|
646 (paragraph-start . yahtml-paragraph-start)
|
yuuji@64
|
647 (paragraph-separate . yahtml-paragraph-separate)
|
yuuji@64
|
648 (comment-start . "<!-- ") (comment-end . " -->")
|
yuuji@64
|
649 (comment-start-skip . comment-start)
|
yuuji@64
|
650 (indent-line-function . yahtml-indent-line)))
|
yuuji@64
|
651
|
yuuji@72
|
652 (if yahtml-use-font-lock
|
yuuji@72
|
653 (progn
|
yuuji@72
|
654 (yahtml-font-lock-set-default-keywords)
|
yuuji@72
|
655 (or (featurep 'xemacs)
|
yuuji@72
|
656 (progn
|
yuuji@72
|
657 (set (make-local-variable 'font-lock-defaults)
|
yuuji@72
|
658 '(yahtml-font-lock-keywords nil t))
|
yuuji@72
|
659 ;;(font-lock-mode -1)
|
yuuji@72
|
660 (font-lock-mode 1) ;;Why should I fontify again???
|
yuuji@72
|
661 ;; in yatex-mode, there's no need to refontify...
|
yuuji@102
|
662 (font-lock-fontify-buffer)))))
|
yuuji@54
|
663 (set-syntax-table yahtml-syntax-table)
|
yuuji@13
|
664 (use-local-map yahtml-mode-map)
|
yuuji@64
|
665 (YaTeX-read-user-completion-table)
|
yuuji@69
|
666 (yahtml-css-scan-styles)
|
yuuji@64
|
667 (turn-on-auto-fill) ;Sorry, this is prerequisite
|
yuuji@64
|
668 (and (= 0 (buffer-size)) (file-exists-p yahtml-template-file)
|
yuuji@64
|
669 (y-or-n-p (format "Insert %s?" yahtml-template-file))
|
yuuji@64
|
670 (insert-file-contents (expand-file-name yahtml-template-file)))
|
yuuji@72
|
671 (run-hooks 'text-mode-hook 'yahtml-mode-hook)
|
yuuji@72
|
672
|
yuuji@72
|
673 ;; This warning should be removed after a while(2000/12/2)
|
yuuji@72
|
674 (let ((fld (or (and (local-variable-p 'font-lock-defaults (current-buffer))
|
yuuji@72
|
675 font-lock-defaults)
|
yuuji@72
|
676 (get 'yahtml-mode 'font-lock-defaults))))
|
yuuji@72
|
677 (and fld (not (memq 'yahtml-font-lock-keywords fld))
|
yuuji@72
|
678 (YaTeX-warning-font-lock "yahtml"))))
|
yuuji@72
|
679
|
yuuji@72
|
680 (defun yahtml-version ()
|
yuuji@72
|
681 "Return string of the version of running yahtml."
|
yuuji@72
|
682 (interactive)
|
yuuji@72
|
683 (message
|
yuuji@72
|
684 (concat "Yet Another HTML-mode "
|
yuuji@72
|
685 (if YaTeX-japan "「HTML屋」" "`yahtml'")
|
yuuji@72
|
686 " Revision "
|
yuuji@72
|
687 yahtml-revision-number)))
|
yuuji@72
|
688
|
yuuji@72
|
689 (defun yahtml-quit ()
|
yuuji@72
|
690 (interactive)
|
yuuji@72
|
691 (and yahtml-mode-old-mode
|
yuuji@72
|
692 (fboundp yahtml-mode-old-mode)
|
yuuji@72
|
693 (funcall yahtml-mode-old-mode)))
|
yuuji@54
|
694
|
yuuji@54
|
695 (defun yahtml-define-menu (keymap bindlist)
|
yuuji@64
|
696 (cond
|
yuuji@64
|
697 ((featurep 'xemacs)
|
yuuji@64
|
698 (let ((name (keymap-name (symbol-value keymap))))
|
yuuji@64
|
699 (set keymap nil)
|
yuuji@64
|
700 (mapcar
|
yuuji@64
|
701 (function
|
yuuji@64
|
702 (lambda (bind)
|
yuuji@64
|
703 (setq bind (cdr bind))
|
yuuji@64
|
704 (if (eq (car (cdr bind)) 'lambda)
|
yuuji@64
|
705 (setcar (cdr bind) 'progn))
|
yuuji@64
|
706 (if (stringp (car (cdr bind)))
|
yuuji@64
|
707 (set keymap (cons (cdr bind) (symbol-value keymap)))
|
yuuji@64
|
708 (set keymap (cons (vector (car bind) (cdr bind) t)
|
yuuji@64
|
709 (symbol-value keymap))))))
|
yuuji@64
|
710 bindlist)
|
yuuji@64
|
711 (set keymap (cons name (symbol-value keymap)))))
|
yuuji@64
|
712 (t
|
yuuji@64
|
713 (mapcar
|
yuuji@64
|
714 (function
|
yuuji@64
|
715 (lambda (bind)
|
yuuji@64
|
716 (define-key (symbol-value keymap) (vector (car bind)) (cdr bind))))
|
yuuji@64
|
717 bindlist))))
|
yuuji@54
|
718
|
yuuji@54
|
719 (defvar yahtml-menu-map nil "Menu map of yahtml")
|
yuuji@54
|
720 (defvar yahtml-menu-map-sectioning nil "Menu map of yahtml(sectioning)")
|
yuuji@54
|
721 (defvar yahtml-menu-map-listing nil "Menu map of yahtml(listing)")
|
yuuji@54
|
722 (defvar yahtml-menu-map-logical nil "Menu map of yahtml(logical tags)")
|
yuuji@54
|
723 (defvar yahtml-menu-map-typeface nil "Menu map of yahtml(typeface tags)")
|
yuuji@54
|
724
|
yuuji@54
|
725 ;;; Variables for mosaic url history
|
yuuji@54
|
726 (defvar yahtml-urls nil "Alist of global history")
|
yuuji@64
|
727 (defvar yahtml-urls-private nil)
|
yuuji@64
|
728 (defvar yahtml-urls-local nil)
|
yuuji@54
|
729
|
yuuji@54
|
730 (cond
|
yuuji@54
|
731 ((and YaTeX-emacs-19 (null yahtml-menu-map))
|
yuuji@64
|
732 (setq yahtml-menu-map (make-sparse-keymap "yahtml"))
|
yuuji@54
|
733 (setq yahtml-menu-map-sectioning (make-sparse-keymap "sectioning menu"))
|
yuuji@64
|
734 (YaTeX-define-menu
|
yuuji@64
|
735 'yahtml-menu-map-sectioning
|
yuuji@54
|
736 (nreverse
|
yuuji@58
|
737 '((1 "H1" . (lambda () (interactive) (yahtml-insert-begend nil "H1")))
|
yuuji@58
|
738 (2 "H2" . (lambda () (interactive) (yahtml-insert-begend nil "H2")))
|
yuuji@58
|
739 (3 "H3" . (lambda () (interactive) (yahtml-insert-begend nil "H3")))
|
yuuji@58
|
740 (4 "H4" . (lambda () (interactive) (yahtml-insert-begend nil "H4")))
|
yuuji@58
|
741 (5 "H5" . (lambda () (interactive) (yahtml-insert-begend nil "H5")))
|
yuuji@58
|
742 (6 "H6" . (lambda () (interactive) (yahtml-insert-begend nil "H6")))
|
yuuji@54
|
743 )))
|
yuuji@54
|
744 (setq yahtml-menu-map-logical (make-sparse-keymap "logical tags"))
|
yuuji@64
|
745 (YaTeX-define-menu
|
yuuji@64
|
746 'yahtml-menu-map-logical
|
yuuji@54
|
747 (nreverse
|
yuuji@54
|
748 '((em "Embolden" .
|
yuuji@58
|
749 (lambda () (interactive) (yahtml-insert-tag nil "EM")))
|
yuuji@60
|
750 (dfn "Define a word" .
|
yuuji@60
|
751 (lambda () (interactive) (yahtml-insert-tag nil "DFN")))
|
yuuji@54
|
752 (cite "Citation" .
|
yuuji@58
|
753 (lambda () (interactive) (yahtml-insert-tag nil "CITE")))
|
yuuji@54
|
754 (code "Code" .
|
yuuji@58
|
755 (lambda () (interactive) (yahtml-insert-tag nil "CODE")))
|
yuuji@54
|
756 (kbd "Keyboard" .
|
yuuji@58
|
757 (lambda () (interactive) (yahtml-insert-tag nil "KBD")))
|
yuuji@54
|
758 (samp "Sample display" .
|
yuuji@58
|
759 (lambda () (interactive) (yahtml-insert-tag nil "SAMP")))
|
yuuji@54
|
760 (strong "Strong" .
|
yuuji@58
|
761 (lambda () (interactive) (yahtml-insert-tag nil "STRONG")))
|
yuuji@54
|
762 (VAR "Variable notation" .
|
yuuji@180
|
763 (lambda () (interactive) (yahtml-insert-tag nil "var"))))))
|
yuuji@54
|
764 (setq yahtml-menu-map-typeface (make-sparse-keymap "typeface tags"))
|
yuuji@64
|
765 (YaTeX-define-menu
|
yuuji@64
|
766 'yahtml-menu-map-typeface
|
yuuji@54
|
767 (nreverse
|
yuuji@54
|
768 '((b "Bold" .
|
yuuji@180
|
769 (lambda () (interactive) (yahtml-insert-tag nil "b")))
|
yuuji@54
|
770 (i "Italic" .
|
yuuji@180
|
771 (lambda () (interactive) (yahtml-insert-tag nil "i")))
|
yuuji@54
|
772 (tt "Typewriter" .
|
yuuji@180
|
773 (lambda () (interactive) (yahtml-insert-tag nil "tt")))
|
yuuji@54
|
774 (u "Underlined" .
|
yuuji@180
|
775 (lambda () (interactive) (yahtml-insert-tag nil "u"))))))
|
yuuji@54
|
776 (setq yahtml-menu-map-listing (make-sparse-keymap "listing"))
|
yuuji@64
|
777 (YaTeX-define-menu
|
yuuji@64
|
778 'yahtml-menu-map-listing
|
yuuji@54
|
779 (nreverse
|
yuuji@58
|
780 '((ul "Unordered" .
|
yuuji@180
|
781 (lambda () (interactive) (yahtml-insert-begend nil "ul")))
|
yuuji@58
|
782 (ol "Ordered" .
|
yuuji@180
|
783 (lambda () (interactive) (yahtml-insert-begend nil "ol")))
|
yuuji@58
|
784 (dl "Definition" .
|
yuuji@180
|
785 (lambda () (interactive) (yahtml-insert-begend nil "dl"))))))
|
yuuji@57
|
786 (setq yahtml-menu-map-item (make-sparse-keymap "item"))
|
yuuji@64
|
787 (YaTeX-define-menu
|
yuuji@64
|
788 'yahtml-menu-map-item
|
yuuji@57
|
789 (nreverse
|
yuuji@57
|
790 '((li "Simple item" .
|
yuuji@57
|
791 (lambda () (interactive) (yahtml-insert-single "li")))
|
yuuji@57
|
792 (dt "Define term" .
|
yuuji@57
|
793 (lambda () (interactive) (yahtml-insert-single "dt")))
|
yuuji@57
|
794 (dd "Description of term" .
|
yuuji@102
|
795 (lambda () (interactive) (yahtml-insert-single "dd"))))))
|
yuuji@54
|
796 (define-key yahtml-mode-map [menu-bar yahtml]
|
yuuji@54
|
797 (cons "yahtml" yahtml-menu-map))
|
yuuji@64
|
798 (YaTeX-define-menu
|
yuuji@64
|
799 'yahtml-menu-map
|
yuuji@54
|
800 (nreverse
|
yuuji@54
|
801 (list
|
yuuji@54
|
802 (cons (list 'sect "Sectioning")
|
yuuji@54
|
803 (cons "sectioning" yahtml-menu-map-sectioning))
|
yuuji@54
|
804 (cons (list 'list "Listing")
|
yuuji@54
|
805 (cons "Listing" yahtml-menu-map-listing))
|
yuuji@57
|
806 (cons (list 'item "Item")
|
yuuji@57
|
807 (cons "Itemizing" yahtml-menu-map-item));;;
|
yuuji@54
|
808 (cons (list 'logi "Logical tags")
|
yuuji@54
|
809 (cons "logical" yahtml-menu-map-logical))
|
yuuji@54
|
810 (cons (list 'type "Typeface tags")
|
yuuji@102
|
811 (cons "typeface" yahtml-menu-map-typeface)))))
|
yuuji@64
|
812 (if (featurep 'xemacs)
|
yuuji@64
|
813 (add-hook 'yahtml-mode-hook
|
yuuji@64
|
814 '(lambda ()
|
yuuji@64
|
815 (or (assoc "yahtml" current-menubar)
|
yuuji@64
|
816 (progn
|
yuuji@64
|
817 (set-buffer-menubar (copy-sequence current-menubar))
|
yuuji@102
|
818 (add-submenu nil yahtml-menu-map))))))))
|
yuuji@54
|
819
|
yuuji@57
|
820 ;;; ----------- Completion ----------
|
yuuji@57
|
821 (defvar yahtml-last-begend "html")
|
yuuji@58
|
822 (defun yahtml-insert-begend (&optional region env)
|
yuuji@57
|
823 "Insert <cmd> ... </cmd>."
|
yuuji@57
|
824 (interactive "P")
|
yuuji@70
|
825 (setq yahtml-current-completion-type 'multiline)
|
yuuji@58
|
826 (let*((completion-ignore-case t)
|
yuuji@58
|
827 (cmd
|
yuuji@58
|
828 (or env
|
yuuji@58
|
829 (YaTeX-cplread-with-learning
|
yuuji@57
|
830 (format "Environment(default %s): " yahtml-last-begend)
|
yuuji@58
|
831 'yahtml-env-table 'yahtml-user-env-table 'yahtml-tmp-env-table)))
|
yuuji@58
|
832 (bolp (save-excursion
|
yuuji@58
|
833 (skip-chars-backward " \t" (point-beginning-of-line)) (bolp)))
|
yuuji@58
|
834 (cc (current-column)))
|
yuuji@57
|
835 (if (string< "" cmd) (setq yahtml-last-begend cmd))
|
yuuji@58
|
836 (setq yahtml-last-begend
|
yuuji@58
|
837 (or (cdr (assoc yahtml-last-begend yahtml-env-table))
|
yuuji@58
|
838 yahtml-last-begend))
|
yuuji@57
|
839 (setq cmd yahtml-last-begend)
|
yuuji@180
|
840 (setq cmd (funcall (if yahtml-prefer-upcases 'upcase 'downcase) cmd))
|
yuuji@57
|
841 (if region
|
yuuji@69
|
842 ;; We want to keep region effective for new tagged environment
|
yuuji@69
|
843 ;; to enable continuous regioning by another environment
|
yuuji@57
|
844 (let ((beg (region-beginning))
|
yuuji@57
|
845 (end (region-end))
|
yuuji@57
|
846 (addin (yahtml-addin cmd)))
|
yuuji@69
|
847 (save-excursion
|
yuuji@69
|
848 (goto-char end)
|
yuuji@69
|
849 (insert-before-markers (format "</%s>%s" cmd (if bolp "\n" "")))
|
yuuji@69
|
850 (goto-char beg)
|
yuuji@69
|
851 (insert (format "<%s%s>%s" cmd addin (if bolp "\n" "")))))
|
yuuji@58
|
852 (insert (format "<%s%s>" cmd (yahtml-addin cmd)))
|
yuuji@58
|
853 (save-excursion
|
yuuji@60
|
854 (insert "\n")
|
yuuji@60
|
855 (indent-to-column cc)
|
yuuji@60
|
856 (insert (format "</%s>" cmd)))
|
yuuji@64
|
857 (if (string-match "^a\\|p$" cmd) ;aとp決め打ちってのが美しくない…
|
yuuji@64
|
858 (newline)
|
yuuji@64
|
859 (yahtml-intelligent-newline nil))
|
yuuji@64
|
860 (yahtml-indent-line))))
|
yuuji@57
|
861
|
yuuji@57
|
862 (defun yahtml-insert-begend-region ()
|
yuuji@57
|
863 "Call yahtml-insert-begend in the region mode."
|
yuuji@57
|
864 (interactive)
|
yuuji@57
|
865 (yahtml-insert-begend t))
|
yuuji@57
|
866
|
yuuji@57
|
867
|
yuuji@54
|
868 (defun yahtml-insert-form (&optional form)
|
yuuji@57
|
869 "Insert <FORM option=\"argument\">."
|
yuuji@54
|
870 (interactive)
|
yuuji@70
|
871 (setq yahtml-current-completion-type 'single)
|
yuuji@54
|
872 (or form
|
yuuji@60
|
873 (let ((completion-ignore-case t))
|
yuuji@60
|
874 (setq form
|
yuuji@60
|
875 (YaTeX-cplread-with-learning
|
yuuji@64
|
876 (format "Form(default %s): " yahtml-last-form)
|
yuuji@60
|
877 'yahtml-form-table 'yahtml-user-form-table
|
yuuji@60
|
878 'yahtml-tmp-form-table))))
|
yuuji@57
|
879 (let ((p (point)) q)
|
yuuji@64
|
880 (if (string= form "") (setq form yahtml-last-form))
|
yuuji@64
|
881 (setq yahtml-last-form form)
|
yuuji@60
|
882 (if yahtml-prefer-upcases (setq form (upcase form)))
|
yuuji@58
|
883 (insert (format "<%s%s>" form (yahtml-addin form)))
|
yuuji@57
|
884 ;;(indent-relative-maybe)
|
yuuji@57
|
885 (if (cdr (assoc form yahtml-form-table))
|
yuuji@57
|
886 (save-excursion (insert (format "</%s>" form))))
|
yuuji@54
|
887 (if (search-backward "\"\"" p t) (forward-char 1))))
|
yuuji@54
|
888
|
yuuji@80
|
889 (defun yahtml-read-css (alist)
|
yuuji@80
|
890 (let ((completion-ignore-case t) (delim " ")
|
yuuji@80
|
891 (minibuffer-completion-table alist))
|
yuuji@80
|
892 (read-from-minibuffer
|
yuuji@80
|
893 (substitute-command-keys
|
yuuji@80
|
894 (if YaTeX-japan
|
yuuji@80
|
895 "クラス(複数指定は\\[quoted-insert] SPCで区切る): "
|
yuuji@80
|
896 "class(or class list delimited by \\[quoted-insert] SPC): "))
|
yuuji@80
|
897 nil YaTeX-minibuffer-completion-map nil)))
|
yuuji@80
|
898
|
yuuji@138
|
899 (defvar yahtml-newpage-command "newpage.rb"
|
yuuji@138
|
900 "*Command name to create new HTML file referring to index.html.
|
yuuji@138
|
901 This command should create new HTML file named argument 1 and
|
yuuji@138
|
902 output string like `<a href=\"newfile.html\">anchor tag</a>'.
|
yuuji@138
|
903 This program should take -o option to overwrite existing HTML file.")
|
yuuji@138
|
904 (defun yahtml-newpage (file ov)
|
yuuji@138
|
905 "Create newpage via newpage script"
|
yuuji@138
|
906 (interactive
|
yuuji@138
|
907 (list
|
yuuji@138
|
908 (let (insert-default-directory)
|
yuuji@138
|
909 (read-file-name "New webpage file name: " ""))
|
yuuji@138
|
910 current-prefix-arg))
|
yuuji@138
|
911 (if (and (file-exists-p file) (not ov))
|
yuuji@138
|
912 (error "%s already exists. Call this with universal argument to force overwrite." file))
|
yuuji@138
|
913 (insert (substring
|
yuuji@138
|
914 (YaTeX-command-to-string
|
yuuji@138
|
915 (concat yahtml-newpage-command " " (if ov "-o ") file))
|
yuuji@138
|
916 0 -1)))
|
yuuji@138
|
917
|
yuuji@59
|
918 ;;; ---------- Add-in ----------
|
yuuji@54
|
919 (defun yahtml-addin (form)
|
yuuji@54
|
920 "Check add-in function's existence and call it if exists."
|
yuuji@69
|
921 (let ((addin (concat "yahtml:" (downcase form))) s a)
|
yuuji@69
|
922 (concat
|
yuuji@70
|
923 (and (setq a (yahtml-css-get-element-completion-alist form))
|
yuuji@290
|
924 (not (equal (YaTeX-last-key) ?\C-j))
|
yuuji@70
|
925 (memq yahtml-current-completion-type '(multiline inline))
|
yuuji@147
|
926 (not (string-match "#" form))
|
yuuji@70
|
927 (yahtml-make-optional-argument ;should be made generic?
|
yuuji@80
|
928 "class" (yahtml-read-css a)))
|
yuuji@69
|
929 (if (and (intern-soft addin) (fboundp (intern-soft addin))
|
yuuji@69
|
930 (stringp (setq s (funcall (intern addin))))
|
yuuji@69
|
931 (string< "" s))
|
yuuji@69
|
932 (if (eq (aref s 0) ? ) s (concat " " s))
|
yuuji@69
|
933 ""))))
|
yuuji@54
|
934
|
yuuji@59
|
935 (defvar yahtml-completing-buffer nil)
|
yuuji@59
|
936 (defun yahtml-collect-labels (&optional file)
|
yuuji@68
|
937 "Collect current buffers label (<?? name=...>).
|
yuuji@59
|
938 If optional argument FILE is specified collect labels in FILE."
|
yuuji@69
|
939 (let (list end)
|
yuuji@59
|
940 (save-excursion
|
yuuji@59
|
941 (set-buffer yahtml-completing-buffer)
|
yuuji@60
|
942 (if file (let (hilit-auto-highlight)
|
yuuji@60
|
943 (set-buffer (find-file-noselect file))))
|
yuuji@59
|
944 (save-excursion
|
yuuji@59
|
945 (goto-char (point-min))
|
yuuji@69
|
946 (while ;(re-search-forward "<\\w+\\b" nil t)
|
yuuji@69
|
947 (re-search-forward "\\(name\\|id\\)\\s *=" nil t)
|
yuuji@69
|
948 ;(setq bound (match-end 0))
|
yuuji@69
|
949 ;(search-forward ">" nil t)
|
yuuji@69
|
950 (setq end (match-end 0))
|
yuuji@69
|
951 (if (and ;(re-search-backward "\\(name\\|id\\)\\s *=" bound t)
|
yuuji@69
|
952 (yahtml-on-assignment-p)
|
yuuji@69
|
953 (progn
|
yuuji@69
|
954 (goto-char end)
|
yuuji@69
|
955 (skip-chars-forward " \t\n")
|
yuuji@69
|
956 (looking-at "\"?#?\\([^\">]+\\)\"?\\b")))
|
yuuji@59
|
957 (setq list (cons
|
yuuji@59
|
958 (list (concat "#" (YaTeX-match-string 1)))
|
yuuji@59
|
959 list))))
|
yuuji@102
|
960 list))))
|
yuuji@59
|
961
|
yuuji@58
|
962 (defvar yahtml-url-completion-map nil "Key map used in URL completion buffer")
|
yuuji@58
|
963 (if yahtml-url-completion-map nil
|
yuuji@58
|
964 (setq yahtml-url-completion-map
|
yuuji@58
|
965 (copy-keymap minibuffer-local-completion-map))
|
yuuji@58
|
966 (define-key yahtml-url-completion-map "\t" 'yahtml-complete-url)
|
yuuji@102
|
967 (define-key yahtml-url-completion-map " " 'yahtml-complete-url))
|
yuuji@58
|
968
|
yuuji@58
|
969 (defun yahtml-complete-url ()
|
yuuji@58
|
970 "Complete external URL from history or local file name."
|
yuuji@58
|
971 (interactive)
|
yuuji@72
|
972 (let ((p (point)) initial i2 cmpl path dir file listfunc beg labels
|
yuuji@73
|
973 (lim (YaTeX-minibuffer-begin))
|
yuuji@73
|
974 (min (if (fboundp 'field-beginning) (field-beginning) (point-min))))
|
yuuji@72
|
975 (setq initial (YaTeX-minibuffer-string))
|
yuuji@58
|
976 (cond
|
yuuji@58
|
977 ((string-match "^http:" initial)
|
yuuji@58
|
978 (setq cmpl (try-completion initial yahtml-urls)
|
yuuji@58
|
979 listfunc (list 'lambda nil
|
yuuji@58
|
980 (list 'all-completions initial 'yahtml-urls))
|
yuuji@73
|
981 beg min))
|
yuuji@59
|
982 ((setq beg (string-match "#" initial))
|
yuuji@59
|
983 (or (equal beg 0) ;begin with #
|
yuuji@59
|
984 (progn
|
yuuji@59
|
985 (setq path (substring initial 0 beg))
|
yuuji@59
|
986 (if (string-match "^/" path)
|
yuuji@59
|
987 (setq path (yahtml-url-to-path path)))))
|
yuuji@59
|
988 (setq initial (substring initial beg))
|
yuuji@59
|
989 (setq labels (yahtml-collect-labels path)
|
yuuji@59
|
990 cmpl (try-completion initial labels)
|
yuuji@59
|
991 listfunc (list 'lambda ()
|
yuuji@59
|
992 (list 'all-completions
|
yuuji@59
|
993 initial (list 'quote labels)))
|
yuuji@73
|
994 beg (+ min beg)))
|
yuuji@58
|
995 (t
|
yuuji@58
|
996 (setq path (if (string-match "^/" initial)
|
yuuji@64
|
997 (or (yahtml-url-to-path initial) initial)
|
yuuji@58
|
998 initial))
|
yuuji@58
|
999 (setq dir (or (file-name-directory path) ".")
|
yuuji@58
|
1000 file (file-name-nondirectory path)
|
yuuji@58
|
1001 initial file
|
yuuji@58
|
1002 cmpl (file-name-completion file dir)
|
yuuji@58
|
1003 listfunc (list 'lambda nil
|
yuuji@58
|
1004 (list 'file-name-all-completions
|
yuuji@58
|
1005 file dir))
|
yuuji@72
|
1006 beg (save-excursion (skip-chars-backward "^/" lim) (point)))))
|
yuuji@58
|
1007 (cond
|
yuuji@58
|
1008 ((stringp cmpl)
|
yuuji@58
|
1009 (if (string= initial cmpl)
|
yuuji@58
|
1010 (with-output-to-temp-buffer "*Completions*"
|
yuuji@58
|
1011 (princ "Possible completinos are:\n")
|
yuuji@58
|
1012 (princ
|
yuuji@58
|
1013 (mapconcat '(lambda (x) x) (funcall listfunc) "\n")))
|
yuuji@58
|
1014 (delete-region (point) beg)
|
yuuji@58
|
1015 (insert cmpl)))
|
yuuji@58
|
1016 ((null cmpl)
|
yuuji@58
|
1017 (ding))
|
yuuji@58
|
1018 ((eq t cmpl)
|
yuuji@58
|
1019 (save-excursion
|
yuuji@58
|
1020 (unwind-protect
|
yuuji@58
|
1021 (progn
|
yuuji@58
|
1022 (goto-char p)
|
yuuji@58
|
1023 (insert " [Sole completion]"))
|
yuuji@58
|
1024 (delete-region p (point-max))))))))
|
yuuji@69
|
1025
|
yuuji@69
|
1026 ;
|
yuuji@69
|
1027 ; Subject: [yatex:02849] Re: [yahtml] tilda in href tag
|
yuuji@193
|
1028 ; From: Masayasu Ishikawa <mimasa<at>sfc.keio.ac.jp>
|
yuuji@193
|
1029 ; To: yatex<at>arcadia.jaist.ac.jp
|
yuuji@69
|
1030 ; Date: Mon, 31 May 1999 21:09:31 +0900
|
yuuji@69
|
1031 ; RFC 2396 の "2.4.3. Excluded US-ASCII Characters" によると、以下の文字
|
yuuji@69
|
1032 ; は必ずエスケープしないといけません。
|
yuuji@69
|
1033 ;
|
yuuji@69
|
1034 ; control = <US-ASCII coded characters 00-1F and 7F hexadecimal>
|
yuuji@69
|
1035 ; space = <US-ASCII coded character 20 hexadecimal>
|
yuuji@69
|
1036 ; delims = "<" | ">" | "#" | "%" | <">
|
yuuji@69
|
1037 ; unwise = "{" | "}" | "|" | "\" | "^" | "[" | "]" | "`"
|
yuuji@69
|
1038 (defvar yahtml-unsafe-chars-regexp
|
yuuji@69
|
1039 "[][\x0- \x7f <>%\"{}|\\^`]" ;#は除去する
|
yuuji@69
|
1040 "Characters regexp which must be escaped in URI.")
|
yuuji@69
|
1041 ;
|
yuuji@69
|
1042 ; また、以下の文字は予約された用法以外に用いる場合にはエスケープしないと
|
yuuji@69
|
1043 ; いけないことになっています。
|
yuuji@69
|
1044 ;
|
yuuji@69
|
1045 ; reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
|
yuuji@69
|
1046 ; "$" | ","
|
yuuji@69
|
1047 (defvar yahtml-unreserved-chars-regexp
|
yuuji@69
|
1048 "[;/?:@&=+$,]"
|
yuuji@69
|
1049 "Characters regexp which should be escaped in URI on certain conditions.
|
yuuji@69
|
1050 Not used yet.")
|
yuuji@69
|
1051
|
yuuji@69
|
1052 (defun yahtml-escape-chars-string (str)
|
yuuji@69
|
1053 "Translate reserved chars to URL encoded string."
|
yuuji@69
|
1054 (let ((p 0) (target "")
|
yuuji@69
|
1055 (ask (eq yahtml-escape-chars 'ask)))
|
yuuji@69
|
1056 (cond
|
yuuji@69
|
1057 ((null yahtml-escape-chars) str)
|
yuuji@69
|
1058 (t
|
yuuji@69
|
1059 (while (and (string< "" str)
|
yuuji@69
|
1060 (setq p (string-match yahtml-unsafe-chars-regexp str)))
|
yuuji@69
|
1061 (if (and ask (y-or-n-p (format "Escape char [%c] of `%s'"
|
yuuji@69
|
1062 (aref str p) (substring str 0 (1+ p)))))
|
yuuji@69
|
1063 (setq target (concat target
|
yuuji@69
|
1064 (substring str 0 p)
|
yuuji@69
|
1065 (format "%%%x" (aref str p))))
|
yuuji@69
|
1066 (setq target (concat target (substring str 0 (1+ p)))))
|
yuuji@69
|
1067 (setq str (substring str (1+ p))))
|
yuuji@69
|
1068 (concat target str)))))
|
yuuji@69
|
1069
|
yuuji@153
|
1070 (defun yahtml-unescape-string (str)
|
yuuji@153
|
1071 "Untranslate reserved URL-encoded string."
|
yuuji@153
|
1072 (let ((p 0) c (target "") (md (match-data)) (case-fold-search nil))
|
yuuji@153
|
1073 (unwind-protect
|
yuuji@153
|
1074 (progn
|
yuuji@153
|
1075 (while (string-match "%\\([0-9a-f][0-9a-f]\\)" str p)
|
yuuji@153
|
1076 (setq target (concat target
|
yuuji@153
|
1077 (substring str p (1- (match-beginning 1))))
|
yuuji@153
|
1078 p (match-end 0)
|
yuuji@153
|
1079 c (YaTeX-hex (substring
|
yuuji@153
|
1080 str (match-beginning 1) (match-end 1)))
|
yuuji@153
|
1081 target (concat target (format "%c" c))))
|
yuuji@153
|
1082 (concat target (substring str p)))
|
yuuji@153
|
1083 (store-match-data md))))
|
yuuji@153
|
1084
|
yuuji@69
|
1085 (defun yahtml-escape-chars-region (beg end)
|
yuuji@69
|
1086 "Translate reserved chars to encoded string in the region."
|
yuuji@69
|
1087 (interactive "r")
|
yuuji@69
|
1088 (save-excursion
|
yuuji@69
|
1089 (let ((e (set-marker (make-marker) end)) c m yes)
|
yuuji@69
|
1090 (goto-char beg)
|
yuuji@69
|
1091 (while (and (< (point) e)
|
yuuji@69
|
1092 (re-search-forward
|
yuuji@69
|
1093 (concat yahtml-unsafe-chars-regexp "\\|"
|
yuuji@69
|
1094 yahtml-unreserved-chars-regexp) e t))
|
yuuji@69
|
1095 (sit-for 0)
|
yuuji@69
|
1096 ; (setq m (buffer-modified-p)
|
yuuji@69
|
1097 ; c (char-after (1- (point))))
|
yuuji@69
|
1098 ; (save-excursion (backward-char 1) (insert " ==>"))
|
yuuji@69
|
1099 ; (unwind-protect
|
yuuji@69
|
1100 ; (setq yes (y-or-n-p (format "Replace: [%c]" c)))
|
yuuji@69
|
1101 ; (save-excursion
|
yuuji@69
|
1102 ; (backward-char 1)
|
yuuji@69
|
1103 ; (delete-backward-char 4))
|
yuuji@69
|
1104 ; (set-buffer-modified-p m))
|
yuuji@69
|
1105 (message "Replace: [%c] (y or n):" (setq c (char-after (1- (point)))))
|
yuuji@69
|
1106 (if (memq (read-char) '(?y ?Y))
|
yuuji@69
|
1107 (progn
|
yuuji@69
|
1108 (delete-region (match-beginning 0) (match-end 0))
|
yuuji@69
|
1109 (insert (format "%%%x" c)))))
|
yuuji@69
|
1110 (set-marker e nil))))
|
yuuji@69
|
1111 ;; ab%defgls/.|
|
yuuji@69
|
1112
|
yuuji@57
|
1113 (defun yahtml:a ()
|
yuuji@54
|
1114 "Add-in function for <a>"
|
yuuji@64
|
1115 (let ((href ""))
|
yuuji@64
|
1116 (setq yahtml-completing-buffer (current-buffer)
|
yuuji@69
|
1117 yahtml-urls (append yahtml-urls-private yahtml-urls-local)
|
yuuji@69
|
1118 href (yahtml-escape-chars-string
|
yuuji@69
|
1119 (read-from-minibuffer "href: " "" yahtml-url-completion-map)))
|
yuuji@64
|
1120 (prog1
|
yuuji@64
|
1121 (concat (yahtml-make-optional-argument
|
yuuji@64
|
1122 "href" href)
|
yuuji@64
|
1123 (yahtml-make-optional-argument
|
yuuji@64
|
1124 "name" (read-string "name: ")))
|
yuuji@64
|
1125 (if (and (string-match "^http://" href)
|
yuuji@69
|
1126 (null (assoc href yahtml-urls-private))
|
yuuji@69
|
1127 (null (assoc href yahtml-urls-local)))
|
yuuji@64
|
1128 (YaTeX-update-table
|
yuuji@64
|
1129 (list href)
|
yuuji@102
|
1130 'yahtml-urls-private 'yahtml-urls-private 'yahtml-urls-local)))))
|
yuuji@57
|
1131
|
yuuji@60
|
1132 (defvar yahtml-parameters-completion-alist
|
yuuji@61
|
1133 '(("align" ("top") ("middle") ("bottom") ("left") ("right") ("center"))
|
yuuji@70
|
1134 ("clear" ("left") ("right") ("center") ("all") ("none"))
|
yuuji@80
|
1135 ("lang" ("ja") ("en") ("kr") ("ch") ("fr"))
|
yuuji@80
|
1136 ("src" . file) ("file" . file)
|
yuuji@70
|
1137 ("background" . file)
|
yuuji@70
|
1138 ("class file name" . file) ("data" . file)
|
yuuji@69
|
1139 ("method" ("POST") ("GET"))
|
yuuji@69
|
1140 ("rev" . yahtml-link-types-alist)
|
yuuji@69
|
1141 ("rel" . yahtml-link-types-alist)
|
yuuji@70
|
1142 ("type" . yahtml-content-types-alist)
|
yuuji@73
|
1143 ("codetype" . yahtml-content-types-alist)
|
yuuji@73
|
1144 ("http-equiv" ("Refresh"))))
|
yuuji@60
|
1145
|
yuuji@69
|
1146 (defvar yahtml-link-types-alist
|
yuuji@69
|
1147 '(("alternate") ("stylesheet") ("start") ("next") ("prev")
|
yuuji@69
|
1148 ("contents") ("index") ("glossary") ("chapter") ("section")
|
yuuji@69
|
1149 ("subsection") ("appendix") ("help") ("bookmark")))
|
yuuji@69
|
1150
|
yuuji@69
|
1151 (defvar yahtml-content-types-alist
|
yuuji@69
|
1152 '(("text/css") ("text/html") ("text/plain") ("text/richtext")
|
yuuji@69
|
1153 ("text/sgml") ("text/xml")
|
yuuji@80
|
1154 ("text/javascript") ("text/tcl") ("text/vbscript")
|
yuuji@69
|
1155 ("application/octet-stream") ("application/postscript") ("application/pdf")
|
yuuji@70
|
1156 ("application/java")
|
yuuji@70
|
1157 ("image/jpeg") ("image/gif") ("image/tiff") ("image/png") ("video/mpeg"))
|
yuuji@69
|
1158 "Alist of content-types")
|
yuuji@69
|
1159
|
yuuji@69
|
1160 (defun yahtml-read-parameter (par &optional default alist)
|
yuuji@69
|
1161 (let* ((alist
|
yuuji@69
|
1162 (cdr-safe (assoc (downcase par)
|
yuuji@69
|
1163 (or alist yahtml-parameters-completion-alist))))
|
yuuji@60
|
1164 (prompt (concat par ": "))
|
yuuji@60
|
1165 v)
|
yuuji@60
|
1166 (cond
|
yuuji@60
|
1167 ((eq alist 'file)
|
yuuji@80
|
1168 (let ((insert-default-directory))
|
yuuji@80
|
1169 (read-file-name prompt "" default nil "")))
|
yuuji@147
|
1170 ((eq alist 'command)
|
yuuji@147
|
1171 (if (fboundp 'read-shell-command)
|
yuuji@147
|
1172 (read-shell-command prompt)
|
yuuji@147
|
1173 (read-string prompt)))
|
yuuji@70
|
1174 ((and alist (symbolp alist))
|
yuuji@69
|
1175 (completing-read prompt (symbol-value alist) nil nil default))
|
yuuji@60
|
1176 (alist
|
yuuji@69
|
1177 (completing-read prompt alist nil nil default))
|
yuuji@60
|
1178 (t
|
yuuji@69
|
1179 (read-string prompt default)))))
|
yuuji@60
|
1180
|
yuuji@64
|
1181 (defun yahtml-make-optional-argument (opt arg)
|
yuuji@64
|
1182 "Make optional argument string."
|
yuuji@80
|
1183 (if (or (null arg) (string= "" arg))
|
yuuji@64
|
1184 ""
|
yuuji@69
|
1185 (concat " "
|
yuuji@69
|
1186 (if yahtml-prefer-upcase-attributes (upcase opt) (downcase opt))
|
yuuji@64
|
1187 "=\"" arg "\"")))
|
yuuji@64
|
1188
|
yuuji@80
|
1189 (defun yahtml:html ()
|
yuuji@80
|
1190 "Add-in for <html>"
|
yuuji@80
|
1191 (setq yahtml-last-begend "head" yahtml-last-typeface-cmd "head")
|
yuuji@80
|
1192 (yahtml-make-optional-argument
|
yuuji@80
|
1193 "lang" (yahtml-read-parameter "lang" (if YaTeX-japan "ja"))))
|
yuuji@80
|
1194
|
yuuji@80
|
1195 (defun yahtml:head ()
|
yuuji@80
|
1196 "Add-in for <head>"
|
yuuji@80
|
1197 (setq yahtml-last-begend "title" yahtml-last-typeface-cmd "title")
|
yuuji@80
|
1198 "")
|
yuuji@80
|
1199
|
yuuji@64
|
1200 (defun yahtml:body ()
|
yuuji@64
|
1201 "Add-in function for <body>"
|
yuuji@80
|
1202 (cond
|
yuuji@80
|
1203 (yahtml-html4-strict nil)
|
yuuji@80
|
1204 (t
|
yuuji@80
|
1205 (let ((b (read-string "bgcolor="))
|
yuuji@80
|
1206 (bg (yahtml-read-parameter "background" ""))
|
yuuji@80
|
1207 (x (read-string "text color="))
|
yuuji@80
|
1208 (l (read-string "link color="))
|
yuuji@80
|
1209 (v (read-string "vlink color=")))
|
yuuji@80
|
1210 (concat
|
yuuji@80
|
1211 (yahtml-make-optional-argument "bgcolor" b)
|
yuuji@80
|
1212 (yahtml-make-optional-argument "background" bg)
|
yuuji@80
|
1213 (yahtml-make-optional-argument "text" x)
|
yuuji@80
|
1214 (yahtml-make-optional-argument "link" l)
|
yuuji@80
|
1215 (yahtml-make-optional-argument "vlink" v))))))
|
yuuji@80
|
1216
|
yuuji@80
|
1217 (defun yahtml-make-style-parameter (proplist)
|
yuuji@80
|
1218 "Make CSS property definitions in style attribute."
|
yuuji@80
|
1219 (mapconcat
|
yuuji@80
|
1220 '(lambda (x) (if (and (cdr x) (string< "" (cdr x)))
|
yuuji@80
|
1221 (format "%s: %s;" (car x) (cdr x))))
|
yuuji@80
|
1222 (delq nil proplist)
|
yuuji@80
|
1223 " "))
|
yuuji@64
|
1224
|
yuuji@57
|
1225 (defun yahtml:img ()
|
yuuji@57
|
1226 "Add-in function for <img>"
|
yuuji@60
|
1227 (let ((src (yahtml-read-parameter "src"))
|
yuuji@60
|
1228 (alg (yahtml-read-parameter "align"))
|
yuuji@70
|
1229 alt
|
yuuji@64
|
1230 (brd (read-string "border="))
|
yuuji@70
|
1231 (l yahtml-prefer-upcase-attributes)
|
yuuji@70
|
1232 info width height bytes comments)
|
yuuji@70
|
1233 (and (stringp src) (string< "" src) (file-exists-p src)
|
yuuji@70
|
1234 (setq info (yahtml-get-image-info src))
|
yuuji@70
|
1235 (car info)
|
yuuji@70
|
1236 (setq width (int-to-string (car info))
|
yuuji@70
|
1237 height (int-to-string (car (cdr info)))
|
yuuji@70
|
1238 bytes (car (cdr (cdr info)))
|
yuuji@70
|
1239 comments (nth 4 info)))
|
yuuji@70
|
1240 (if info
|
yuuji@70
|
1241 (setq alt
|
yuuji@70
|
1242 (YaTeX-replace-formats
|
yuuji@70
|
1243 yahtml:img-default-alt-format
|
yuuji@70
|
1244 (list (cons "x" width)
|
yuuji@70
|
1245 (cons "y" height)
|
yuuji@70
|
1246 (cons "s" (int-to-string bytes))
|
yuuji@70
|
1247 (cons "f" (file-name-nondirectory src))
|
yuuji@70
|
1248 (cons "c" (car comments))))))
|
yuuji@70
|
1249
|
yuuji@70
|
1250 (setq alt (yahtml-read-parameter "alt" alt))
|
yuuji@70
|
1251 (setq width (yahtml-read-parameter "width" width)
|
yuuji@70
|
1252 height (yahtml-read-parameter "height" height))
|
yuuji@60
|
1253 (concat (if l "SRC" "src") "=\"" src "\""
|
yuuji@64
|
1254 (yahtml-make-optional-argument "alt" alt)
|
yuuji@70
|
1255 (yahtml-make-optional-argument "width" width)
|
yuuji@70
|
1256 (yahtml-make-optional-argument "height" height)
|
yuuji@80
|
1257 (if yahtml-html4-strict
|
yuuji@80
|
1258 (yahtml-make-optional-argument
|
yuuji@80
|
1259 "style"
|
yuuji@80
|
1260 (if (or brd alg)
|
yuuji@80
|
1261 (yahtml-make-style-parameter
|
yuuji@80
|
1262 (list
|
yuuji@80
|
1263 (if (string< "" alg)
|
yuuji@80
|
1264 (cons "align" alg))
|
yuuji@80
|
1265 (if (string< "" brd)
|
yuuji@80
|
1266 (cons "border"
|
yuuji@80
|
1267 (format "%dpx" (string-to-int brd))))))))
|
yuuji@80
|
1268 (concat
|
yuuji@80
|
1269 (yahtml-make-optional-argument "border" brd)
|
yuuji@80
|
1270 (yahtml-make-optional-argument "align" alg))))))
|
yuuji@57
|
1271
|
yuuji@70
|
1272 (defun yahtml-file-truename (file)
|
yuuji@70
|
1273 (cond
|
yuuji@70
|
1274 ((fboundp 'file-truename) (file-truename (expand-file-name file)))
|
yuuji@70
|
1275 (t (let ((new file))
|
yuuji@70
|
1276 (while (and (stringp (setq new (nth 0 (file-attributes file))))
|
yuuji@70
|
1277 (not (equal new file)))
|
yuuji@70
|
1278 (setq file new))
|
yuuji@70
|
1279 file))))
|
yuuji@70
|
1280
|
yuuji@70
|
1281 (defun yahtml-hex-value (point length &optional little-endian)
|
yuuji@70
|
1282 "Return the hex value the POINT positions LENGTH byte stream represents.
|
yuuji@70
|
1283 Optional third argument LITTLE-ENDIAN is self extplanatory."
|
yuuji@70
|
1284 (setq point (1+ point)) ;translate file offset to Emacs's point value
|
yuuji@70
|
1285 (let ((mlt 1)
|
yuuji@70
|
1286 (pos (if little-endian point (+ point length -1)))
|
yuuji@70
|
1287 (direc (if little-endian 1 -1))
|
yuuji@70
|
1288 (value 0))
|
yuuji@70
|
1289 (while (> length 0)
|
yuuji@70
|
1290 (setq value (+ value (* mlt (char-after pos)))
|
yuuji@70
|
1291 pos (+ pos direc)
|
yuuji@70
|
1292 mlt (* mlt 256)
|
yuuji@70
|
1293 length (1- length)))
|
yuuji@70
|
1294 value))
|
yuuji@70
|
1295
|
yuuji@70
|
1296 (defun yahtml-get-image-info (file)
|
yuuji@70
|
1297 "Return the information on the image file FILE.
|
yuuji@70
|
1298 Returns list of '(WIDTH HEIGHT BYTES DEPTH COMMENTLIST)."
|
yuuji@70
|
1299 (save-excursion
|
yuuji@70
|
1300 (let*((tmpbuf (get-buffer-create " *imgheader*"))
|
yuuji@70
|
1301 width height bytes depth comment
|
yuuji@70
|
1302 (file-coding-system-alist (list (cons "." 'no-conversion))) ;20
|
yuuji@70
|
1303 (file-coding-system-for-read (and (boundp '*noconv*) *noconv*)) ;19
|
yuuji@72
|
1304 (coding-system-for-read 'no-conversion)
|
yuuji@70
|
1305 (seekpoint 1)
|
yuuji@70
|
1306 c1 c2 c3 c4 beg end
|
yuuji@70
|
1307 (case-fold-search nil))
|
yuuji@70
|
1308 (setq bytes (nth 7 (file-attributes (yahtml-file-truename file))))
|
yuuji@70
|
1309 (set-buffer tmpbuf)
|
yuuji@70
|
1310 (if (boundp 'mc-flag) (set (make-local-variable 'mc-flag) nil))
|
yuuji@70
|
1311 (erase-buffer)
|
yuuji@70
|
1312 (if (fboundp 'set-buffer-multibyte) (set-buffer-multibyte nil))
|
yuuji@70
|
1313 (unwind-protect
|
yuuji@70
|
1314 (progn
|
yuuji@70
|
1315 (message "Inspecting image information of %s..." file)
|
yuuji@70
|
1316 ;; Read 4bytes-more than inspection-bytes in case that
|
yuuji@70
|
1317 ;; JPEG marker delimiter (4bytes) is on the alignment.
|
yuuji@70
|
1318 (YaTeX-insert-file-contents
|
yuuji@70
|
1319 file nil 0 (+ yahtml-image-inspection-bytes 4))
|
yuuji@70
|
1320 (goto-char (point-min)) ;assertion
|
yuuji@70
|
1321 (setq c1 (char-after 1) ;cache first 4 bytes
|
yuuji@70
|
1322 c2 (char-after 2)
|
yuuji@70
|
1323 c3 (char-after 3)
|
yuuji@70
|
1324 c4 (char-after 4))
|
yuuji@70
|
1325 (cond
|
yuuji@73
|
1326 ((and (eq c1 ?\377) (eq c2 ?\330)) ; 0xff 0xd8
|
yuuji@70
|
1327 ;;JPEG images need JPEG markers inspection
|
yuuji@70
|
1328 ;;JPEG markers consist of [ 0xff ID(B) LEN(S) CONTENTS... ]
|
yuuji@70
|
1329 ;; Warning: here seekpoint is measured by Emacs's point value
|
yuuji@70
|
1330 ;; while yahtml-hex-vale requires file offset
|
yuuji@70
|
1331 (setq seekpoint 3) ;where the first JPEG marker exists
|
yuuji@70
|
1332 (catch 'exit
|
yuuji@70
|
1333 (while (< seekpoint (- (buffer-size) 4))
|
yuuji@70
|
1334 (cond
|
yuuji@73
|
1335 ((not (eq (char-after seekpoint) ?\377))
|
yuuji@70
|
1336 ;maybe corrupted, exit from loop
|
yuuji@70
|
1337 (throw 'exit t))
|
yuuji@73
|
1338 ((memq
|
yuuji@73
|
1339 (char-after (1+ seekpoint))
|
yuuji@73
|
1340 '(?\300 ?\301 ?\302 ?\303
|
yuuji@73
|
1341 ?\305 ?\306 ?\307 ?\311 ?\312 ?\313 ?\315 ?\316 ?\317))
|
yuuji@73
|
1342 ;;'(192 193 194 195 197 198 199 201 202 203 205 206 207
|
yuuji@70
|
1343 ;;found!
|
yuuji@70
|
1344 (setq height (yahtml-hex-value (+ seekpoint 4) 2)
|
yuuji@70
|
1345 width (yahtml-hex-value (+ seekpoint 6) 2)
|
yuuji@70
|
1346 depth (yahtml-hex-value (+ seekpoint 3) 1)))
|
yuuji@73
|
1347 ((eq (char-after (1+ seekpoint)) ?\376) ;0xFE = comment
|
yuuji@70
|
1348 ;; JPEG comment area
|
yuuji@70
|
1349 (setq beg (+ seekpoint 2 2)
|
yuuji@70
|
1350 end (+ seekpoint
|
yuuji@70
|
1351 (yahtml-hex-value (1+ seekpoint) 2) 2))
|
yuuji@70
|
1352 (setq comment (cons (buffer-substring beg end) comment)))
|
yuuji@70
|
1353 (t ;other markers
|
yuuji@70
|
1354 nil)) ;just skip it
|
yuuji@70
|
1355 (setq seekpoint (+ seekpoint 2)
|
yuuji@70
|
1356 seekpoint (+ seekpoint
|
yuuji@70
|
1357 (yahtml-hex-value (1- seekpoint) 2))))))
|
yuuji@73
|
1358 ((and (eq c1 ?\211) ;0x89
|
yuuji@70
|
1359 (eq c2 ?P) (eq c3 ?N) (eq c4 ?G))
|
yuuji@70
|
1360 ;;PNG Image data X=@0x10(L), Y=@0x14(L), D=@0x18(B)
|
yuuji@70
|
1361 (setq width (yahtml-hex-value 16 4)
|
yuuji@70
|
1362 height (yahtml-hex-value 20 4)
|
yuuji@70
|
1363 depth (yahtml-hex-value 24 1)))
|
yuuji@70
|
1364 ((looking-at "GIF8")
|
yuuji@70
|
1365 ;;GIF Image data X=@0x6(leshort), Y=@0x8(leshort)
|
yuuji@70
|
1366 (setq width (yahtml-hex-value 6 2 t)
|
yuuji@70
|
1367 height (yahtml-hex-value 8 2 t)))
|
yuuji@70
|
1368 ((looking-at "BM")
|
yuuji@70
|
1369 ;;# OS/2, Windoze BMP files
|
yuuji@70
|
1370 ;;@0x0e = 12 -> OS/2 1.x - X=@0x12(leshort), Y=@0x14(leshort)
|
yuuji@70
|
1371 ;;@0x0e = 64 -> OS/2 2.x - X=@0x12(leshort), Y=@0x14(leshort)
|
yuuji@70
|
1372 ;;@0x0e = 40 -> Windows 3.x - X=@0x12(lelong), Y=@0x16(lelong)
|
yuuji@70
|
1373 (cond
|
yuuji@70
|
1374 ((eq (yahtml-hex-value 14 2 t) 40)
|
yuuji@70
|
1375 (setq width (yahtml-hex-value 18 4 t)
|
yuuji@70
|
1376 height (yahtml-hex-value 22 4 t)))
|
yuuji@70
|
1377 (t
|
yuuji@70
|
1378 (setq width (yahtml-hex-value 18 2 t)
|
yuuji@102
|
1379 height (yahtml-hex-value 20 2 t)))))))
|
yuuji@70
|
1380 (message "")
|
yuuji@70
|
1381 (kill-buffer tmpbuf))
|
yuuji@70
|
1382 (list width height bytes depth (nreverse comment)))))
|
yuuji@70
|
1383
|
yuuji@57
|
1384 (defun yahtml:form ()
|
yuuji@57
|
1385 "Add-in function `form' input format"
|
yuuji@57
|
1386 (concat
|
yuuji@162
|
1387 " " (if yahtml-prefer-upcase-attributes "METHOD" "method") "=\""
|
yuuji@60
|
1388 (completing-read "Method: " '(("POST") ("GET")) nil t)
|
yuuji@162
|
1389 "\""
|
yuuji@162
|
1390 (yahtml-make-optional-argument
|
yuuji@162
|
1391 (if yahtml-prefer-upcase-attributes "ENCTYPE" "enctype")
|
yuuji@162
|
1392 (completing-read
|
yuuji@162
|
1393 "Enctype: "
|
yuuji@162
|
1394 '(("application/x-www-form-urlencoded") ("multipart/form-data"))))
|
yuuji@69
|
1395 " " (if yahtml-prefer-upcase-attributes "ACTION" "action") "=\""
|
yuuji@102
|
1396 (read-string "Action: ") "\""))
|
yuuji@57
|
1397
|
yuuji@57
|
1398 (defun yahtml:select ()
|
yuuji@57
|
1399 "Add-in function for `select' input format"
|
yuuji@57
|
1400 (setq yahtml-last-single-cmd "option")
|
yuuji@69
|
1401 (concat " " (if yahtml-prefer-upcase-attributes "NAME" "name") "=\""
|
yuuji@60
|
1402 (read-string "name: ") "\""))
|
yuuji@57
|
1403
|
yuuji@58
|
1404 (defun yahtml:ol ()
|
yuuji@73
|
1405 "Add-in function for <ol>"
|
yuuji@73
|
1406 (setq yahtml-last-single-cmd "li")
|
yuuji@243
|
1407 (let ((start (YaTeX-read-string-or-skip "start="))
|
yuuji@243
|
1408 (type (YaTeX-completing-read-or-skip
|
yuuji@73
|
1409 "type=" '(("1") ("a") ("A") ("i") ("I")) nil t)))
|
yuuji@73
|
1410 (concat
|
yuuji@73
|
1411 (yahtml-make-optional-argument "start" start)
|
yuuji@73
|
1412 (yahtml-make-optional-argument "type" type))))
|
yuuji@58
|
1413 (defun yahtml:ul ()
|
yuuji@58
|
1414 (setq yahtml-last-single-cmd "li") "")
|
yuuji@58
|
1415 (defun yahtml:dl ()
|
yuuji@58
|
1416 (setq yahtml-last-single-cmd "dt") "")
|
yuuji@58
|
1417 (defun yahtml:dt ()
|
yuuji@58
|
1418 (setq yahtml-last-single-cmd "dd") "")
|
yuuji@58
|
1419
|
yuuji@61
|
1420 (defun yahtml:p ()
|
yuuji@80
|
1421 (if yahtml-html4-strict nil
|
yuuji@80
|
1422 (let ((alg (yahtml-read-parameter "align")))
|
yuuji@80
|
1423 (yahtml-make-optional-argument "align" alg))))
|
yuuji@58
|
1424
|
yuuji@57
|
1425 (defvar yahtml-input-types
|
yuuji@57
|
1426 '(("text") ("password") ("checkbox") ("radio") ("submit")
|
yuuji@60
|
1427 ("reset") ("image") ("hidden") ("file")))
|
yuuji@57
|
1428
|
yuuji@57
|
1429 (defun yahtml:input ()
|
yuuji@57
|
1430 "Add-in function for `input' form"
|
yuuji@60
|
1431 (let ((size "") name type value checked (maxlength "")
|
yuuji@69
|
1432 (l yahtml-prefer-upcase-attributes))
|
yuuji@57
|
1433 (setq name (read-string "name: ")
|
yuuji@243
|
1434 type (YaTeX-completing-read-or-skip "type (default=text): "
|
yuuji@57
|
1435 yahtml-input-types nil t)
|
yuuji@243
|
1436 value (YaTeX-read-string-or-skip "value: "))
|
yuuji@57
|
1437 (if (string-match "text\\|password\\|^$" type)
|
yuuji@243
|
1438 (setq size (YaTeX-read-string-or-skip "size: ")
|
yuuji@243
|
1439 maxlength (YaTeX-read-string-or-skip "maxlength: ")))
|
yuuji@57
|
1440 (concat
|
yuuji@60
|
1441 (if l "NAME" "name") "=\"" name "\""
|
yuuji@64
|
1442 (yahtml-make-optional-argument "type" type)
|
yuuji@64
|
1443 (yahtml-make-optional-argument "value" value)
|
yuuji@64
|
1444 (yahtml-make-optional-argument "size" size)
|
yuuji@102
|
1445 (yahtml-make-optional-argument "maxlength" maxlength))))
|
yuuji@59
|
1446
|
yuuji@59
|
1447 (defun yahtml:textarea ()
|
yuuji@59
|
1448 "Add-in function for `textarea'"
|
yuuji@59
|
1449 (interactive)
|
yuuji@59
|
1450 (let (name rows cols)
|
yuuji@59
|
1451 (setq name (read-string "Name: ")
|
yuuji@60
|
1452 cols (read-string "Columns: ")
|
yuuji@60
|
1453 rows (read-string "Rows: "))
|
yuuji@59
|
1454 (concat
|
yuuji@69
|
1455 (concat (if yahtml-prefer-upcase-attributes "NAME=" "name=")
|
yuuji@59
|
1456 "\"" name "\"")
|
yuuji@64
|
1457 (yahtml-make-optional-argument "cols" cols)
|
yuuji@64
|
1458 (yahtml-make-optional-argument "rows" rows))))
|
yuuji@59
|
1459
|
yuuji@64
|
1460 (defun yahtml:table ()
|
yuuji@64
|
1461 "Add-in function for `table'"
|
yuuji@69
|
1462 (let ((b (read-string "border="))
|
yuuji@80
|
1463 (a (yahtml-read-parameter
|
yuuji@80
|
1464 "align" nil '(("align" ("right")("center"))))))
|
yuuji@80
|
1465 (if yahtml-html4-strict
|
yuuji@80
|
1466 (yahtml-make-optional-argument
|
yuuji@80
|
1467 "style"
|
yuuji@80
|
1468 (if (or (string< "" b) (string< "" a))
|
yuuji@80
|
1469 (yahtml-make-style-parameter
|
yuuji@80
|
1470 (append
|
yuuji@80
|
1471 (if (string< "" b)
|
yuuji@80
|
1472 (list
|
yuuji@80
|
1473 (cons "border" (format "%dpx solid" (string-to-int b)))
|
yuuji@80
|
1474 (cons "border-collapse" "collapse")))
|
yuuji@80
|
1475 (if (string< "" a)
|
yuuji@80
|
1476 (cond
|
yuuji@80
|
1477 ((string-match "right" a)
|
yuuji@80
|
1478 (list (cons "margin-left" "auto")
|
yuuji@80
|
1479 (cons "margin-right" "0")))
|
yuuji@80
|
1480 ((string-match "center" a)
|
yuuji@80
|
1481 (list (cons "margin-left" "auto")
|
yuuji@80
|
1482 (cons "margin-right" "auto")))))))))
|
yuuji@80
|
1483 (concat
|
yuuji@80
|
1484 (yahtml-make-optional-argument "border" b)
|
yuuji@80
|
1485 (yahtml-make-optional-argument "align" a)))))
|
yuuji@80
|
1486
|
yuuji@69
|
1487 ;(fset 'yahtml:caption 'yahtml:p)
|
yuuji@69
|
1488 (defun yahtml:caption ()
|
yuuji@69
|
1489 "Add-in function for `caption' in table tag"
|
yuuji@80
|
1490 (let ((par (yahtml-read-parameter "align")))
|
yuuji@80
|
1491 (if yahtml-html4-strict
|
yuuji@80
|
1492 (yahtml-make-optional-argument
|
yuuji@80
|
1493 "style" (if par (yahtml-make-style-parameter
|
yuuji@80
|
1494 (list (cons "caption-side" par)))))
|
yuuji@80
|
1495 (yahtml-make-optional-argument "align" par))))
|
yuuji@64
|
1496
|
yuuji@64
|
1497 (defun yahtml:font ()
|
yuuji@64
|
1498 "Add-in function for `font'"
|
yuuji@68
|
1499 (concat
|
yuuji@68
|
1500 (yahtml-make-optional-argument "color" (read-string "color="))
|
yuuji@68
|
1501 (yahtml-make-optional-argument "size" (read-string "size="))))
|
yuuji@59
|
1502
|
yuuji@69
|
1503 (defun yahtml:style ()
|
yuuji@69
|
1504 "Add-in function for `style'"
|
yuuji@69
|
1505 (yahtml-make-optional-argument
|
yuuji@69
|
1506 "type" (read-string "type=" "text/css")))
|
yuuji@69
|
1507
|
yuuji@80
|
1508 (defun yahtml:script ()
|
yuuji@80
|
1509 "Add-in function for `script'"
|
yuuji@80
|
1510 (concat
|
yuuji@80
|
1511 (yahtml-make-optional-argument
|
yuuji@80
|
1512 "type" (yahtml-read-parameter "type" "text/javascript"))
|
yuuji@80
|
1513 (yahtml-make-optional-argument
|
yuuji@80
|
1514 "src" (yahtml-read-parameter "src" ""))))
|
yuuji@80
|
1515
|
yuuji@69
|
1516 (defun yahtml:tr ()
|
yuuji@69
|
1517 "Add-in function for `tr'"
|
yuuji@69
|
1518 (setq ;yahtml-last-begend "td" ;; which do you prefer?
|
yuuji@69
|
1519 yahtml-last-typeface-cmd "td")
|
yuuji@69
|
1520 "")
|
yuuji@69
|
1521
|
yuuji@69
|
1522 (defun yahtml:link ()
|
yuuji@69
|
1523 "Add-in function for `link' (まだちょっと良く分かってない)"
|
yuuji@69
|
1524 (let (rel rev type href)
|
yuuji@69
|
1525 (setq rel (yahtml-read-parameter "rel"))
|
yuuji@69
|
1526 (cond
|
yuuji@69
|
1527 ((equal rel "")
|
yuuji@69
|
1528 (concat (yahtml-make-optional-argument
|
yuuji@69
|
1529 "rev" (yahtml-read-parameter "rev"))
|
yuuji@69
|
1530 (yahtml-make-optional-argument
|
yuuji@69
|
1531 "href" (yahtml-read-parameter "href")
|
yuuji@69
|
1532 ;;他に良く使うのって何?
|
yuuji@69
|
1533 )))
|
yuuji@69
|
1534 ((string-match "stylesheet" rel)
|
yuuji@69
|
1535 (concat
|
yuuji@69
|
1536 (yahtml-make-optional-argument "rel" rel)
|
yuuji@69
|
1537 (yahtml-make-optional-argument
|
yuuji@69
|
1538 "type" (yahtml-read-parameter "type" "text/css"))
|
yuuji@69
|
1539 (progn
|
yuuji@69
|
1540 (setq href
|
yuuji@69
|
1541 (read-from-minibuffer "href: " "" yahtml-url-completion-map))
|
yuuji@69
|
1542 (if (string< "" href)
|
yuuji@69
|
1543 (progn
|
yuuji@69
|
1544 (if (and (file-exists-p (yahtml-url-to-path href))
|
yuuji@69
|
1545 (y-or-n-p "Load css symbols now? "))
|
yuuji@69
|
1546 (setq yahtml-css-class-alist
|
yuuji@69
|
1547 (yahtml-css-collect-classes-file
|
yuuji@69
|
1548 (yahtml-url-to-path href) yahtml-css-class-alist)))
|
yuuji@69
|
1549 (message "")
|
yuuji@69
|
1550 (yahtml-make-optional-argument "href" href))))))
|
yuuji@80
|
1551 (t
|
yuuji@80
|
1552 (concat
|
yuuji@80
|
1553 (yahtml-make-optional-argument "rel" rel)
|
yuuji@80
|
1554 (yahtml-make-optional-argument
|
yuuji@80
|
1555 "type" (yahtml-read-parameter "type" "text/css"))
|
yuuji@80
|
1556 (yahtml-make-optional-argument
|
yuuji@102
|
1557 "href"
|
yuuji@102
|
1558 (read-from-minibuffer "href: " "" yahtml-url-completion-map)))))))
|
yuuji@69
|
1559
|
yuuji@73
|
1560 (defvar yahtml:meta-names
|
yuuji@73
|
1561 '(("name" ("keywords")("author")("copyright")("date")("GENERATOR"))))
|
yuuji@73
|
1562
|
yuuji@73
|
1563 (defun yahtml:meta ()
|
yuuji@73
|
1564 (let ((name (yahtml-make-optional-argument
|
yuuji@73
|
1565 "name"
|
yuuji@73
|
1566 (yahtml-read-parameter "name" nil yahtml:meta-names)))
|
yuuji@73
|
1567 http-equiv content)
|
yuuji@73
|
1568 (if (string= "" name)
|
yuuji@73
|
1569 (if (string-match
|
yuuji@73
|
1570 "Content-type"
|
yuuji@73
|
1571 (setq http-equiv (yahtml-make-optional-argument
|
yuuji@73
|
1572 "http-equiv"
|
yuuji@73
|
1573 (yahtml-read-parameter "http-equiv" nil))))
|
yuuji@73
|
1574 (error "It's very bad idea to set Content-type in META. %s"
|
yuuji@73
|
1575 "See docs/qanda")
|
yuuji@73
|
1576 (concat http-equiv
|
yuuji@73
|
1577 (yahtml-make-optional-argument
|
yuuji@73
|
1578 "content" (yahtml-read-parameter "content"))))
|
yuuji@73
|
1579 (concat
|
yuuji@73
|
1580 name
|
yuuji@73
|
1581 (yahtml-make-optional-argument
|
yuuji@73
|
1582 "content"
|
yuuji@73
|
1583 (cond
|
yuuji@73
|
1584 ((string-match "date" name)
|
yuuji@73
|
1585 (read-string "Date: " (current-time-string)))
|
yuuji@73
|
1586 ((string-match "author" name)
|
yuuji@73
|
1587 (read-string "Author: "
|
yuuji@73
|
1588 (if (and (user-full-name) (string< "" (user-full-name)))
|
yuuji@73
|
1589 (user-full-name)
|
yuuji@73
|
1590 (user-login-name))))
|
yuuji@73
|
1591 ((string-match "GENERATOR" name)
|
yuuji@73
|
1592 (setq content (read-string "Generator: " "User-agent: "))
|
yuuji@73
|
1593 (if (string-match "yahtml" content)
|
yuuji@73
|
1594 (message "Thank you!"))
|
yuuji@73
|
1595 content)
|
yuuji@73
|
1596 (t (read-string (concat name ": ")))))))))
|
yuuji@73
|
1597
|
yuuji@70
|
1598 (defun yahtml:br ()
|
yuuji@70
|
1599 (yahtml-make-optional-argument "clear" (yahtml-read-parameter "clear")))
|
yuuji@70
|
1600
|
yuuji@70
|
1601 (defun yahtml:object ()
|
yuuji@70
|
1602 (let ((codetype (yahtml-read-parameter "codetype" "application/java"))
|
yuuji@70
|
1603 data classid)
|
yuuji@70
|
1604 (cond
|
yuuji@70
|
1605 ((string-match "java" codetype)
|
yuuji@70
|
1606 (let ((completion-ignored-extensions
|
yuuji@70
|
1607 ;;any extensions except ".class"
|
yuuji@70
|
1608 '(".java" ".html" ".htm" ".gif" ".jpg" ".jpeg" ".png")))
|
yuuji@70
|
1609 (setq classid (concat "java:"
|
yuuji@70
|
1610 (yahtml-read-parameter "class file name"))))
|
yuuji@70
|
1611 (concat
|
yuuji@70
|
1612 (yahtml-make-optional-argument "codetype" codetype)
|
yuuji@70
|
1613 (yahtml-make-optional-argument "classid" classid)
|
yuuji@70
|
1614 (yahtml-make-optional-argument
|
yuuji@70
|
1615 "width" (yahtml-read-parameter "width"))
|
yuuji@70
|
1616 (yahtml-make-optional-argument
|
yuuji@70
|
1617 "height" (yahtml-read-parameter "height"))
|
yuuji@70
|
1618 (yahtml-make-optional-argument
|
yuuji@102
|
1619 "align" (yahtml-read-parameter "align"))))
|
yuuji@70
|
1620 (t
|
yuuji@102
|
1621 ""))))
|
yuuji@70
|
1622
|
yuuji@80
|
1623 (defun yahtml:abbr ()
|
yuuji@80
|
1624 "Add-in function for abbr."
|
yuuji@80
|
1625 (yahtml-make-optional-argument "title" (yahtml-read-parameter "title")))
|
yuuji@80
|
1626
|
yuuji@136
|
1627 (defun yahtml:button ()
|
yuuji@136
|
1628 (concat
|
yuuji@136
|
1629 (yahtml-make-optional-argument
|
yuuji@136
|
1630 "name" (yahtml-read-parameter "name"))
|
yuuji@136
|
1631 (yahtml-make-optional-argument
|
yuuji@136
|
1632 "type" (yahtml-read-parameter
|
yuuji@137
|
1633 "type" "button" '(("submit")("reset")("button"))))
|
yuuji@137
|
1634 (yahtml-make-optional-argument
|
yuuji@137
|
1635 "value" (yahtml-read-parameter "value"))))
|
yuuji@136
|
1636
|
yuuji@59
|
1637 ;;; ---------- Simple tag ----------
|
yuuji@58
|
1638 (defun yahtml-insert-tag (region-mode &optional tag)
|
yuuji@54
|
1639 "Insert <TAG> </TAG> and put cursor inside of them."
|
yuuji@58
|
1640 (interactive "P")
|
yuuji@70
|
1641 (setq yahtml-current-completion-type 'inline)
|
yuuji@58
|
1642 (or tag
|
yuuji@60
|
1643 (let ((completion-ignore-case t))
|
yuuji@60
|
1644 (setq tag
|
yuuji@60
|
1645 (YaTeX-cplread-with-learning
|
yuuji@64
|
1646 (format "Tag %s(default %s): "
|
yuuji@60
|
1647 (if region-mode "region: " "") yahtml-last-typeface-cmd)
|
yuuji@60
|
1648 'yahtml-typeface-table 'yahtml-user-typeface-table
|
yuuji@60
|
1649 'yahtml-tmp-typeface-table))))
|
yuuji@58
|
1650 (if (string= "" tag) (setq tag yahtml-last-typeface-cmd))
|
yuuji@60
|
1651 (setq tag (or (cdr (assoc tag yahtml-typeface-table)) tag))
|
yuuji@60
|
1652 (setq yahtml-last-typeface-cmd tag
|
yuuji@60
|
1653 tag (funcall (if yahtml-prefer-upcases 'upcase 'downcase) tag))
|
yuuji@58
|
1654 (if region-mode
|
yuuji@58
|
1655 (if (if (string< "19" emacs-version) (mark t) (mark))
|
yuuji@58
|
1656 (save-excursion
|
yuuji@58
|
1657 (if (> (point) (mark)) (exchange-point-and-mark))
|
yuuji@60
|
1658 (insert (format "<%s%s>" tag (yahtml-addin tag)))
|
yuuji@58
|
1659 (exchange-point-and-mark)
|
yuuji@58
|
1660 (insert "</" tag ">"))
|
yuuji@58
|
1661 (message "No mark set now"))
|
yuuji@60
|
1662 (insert (format "<%s%s>" tag (yahtml-addin tag)))
|
yuuji@58
|
1663 (save-excursion (insert (format "</%s>" tag)))))
|
yuuji@54
|
1664
|
yuuji@61
|
1665 (defun yahtml-insert-tag-region (&optional tag)
|
yuuji@61
|
1666 "Call yahtml-insert-tag with region mode."
|
yuuji@61
|
1667 (interactive)
|
yuuji@61
|
1668 (yahtml-insert-tag t tag))
|
yuuji@61
|
1669
|
yuuji@80
|
1670 (defvar yahtml-need-single-closer nil) ;for test
|
yuuji@57
|
1671 (defun yahtml-insert-single (cmd)
|
yuuji@57
|
1672 "Insert <CMD>."
|
yuuji@57
|
1673 (interactive
|
yuuji@58
|
1674 (list
|
yuuji@58
|
1675 (let ((completion-ignore-case t))
|
yuuji@58
|
1676 (YaTeX-cplread-with-learning
|
yuuji@58
|
1677 (format "Command%s: "
|
yuuji@58
|
1678 (if yahtml-last-single-cmd
|
yuuji@58
|
1679 (concat "(default " yahtml-last-single-cmd ")") ""))
|
yuuji@58
|
1680 'yahtml-single-cmd-table 'yahtml-user-single-cmd-table
|
yuuji@58
|
1681 'yahtml-tmp-single-cmd-table))))
|
yuuji@60
|
1682 (if (string= "" cmd) (setq cmd yahtml-last-single-cmd))
|
yuuji@58
|
1683 (setq yahtml-last-single-cmd
|
yuuji@60
|
1684 (or (cdr (assoc cmd yahtml-single-cmd-table)) cmd))
|
yuuji@60
|
1685 (setq cmd (funcall (if yahtml-prefer-upcases 'upcase 'downcase)
|
yuuji@60
|
1686 yahtml-last-single-cmd))
|
yuuji@80
|
1687 (insert (format "<%s%s%s>"
|
yuuji@80
|
1688 cmd
|
yuuji@80
|
1689 (yahtml-addin cmd)
|
yuuji@80
|
1690 (if (and yahtml-need-single-closer
|
yuuji@80
|
1691 (assoc cmd '(("br")("hr"))))
|
yuuji@80
|
1692 " /" "")))
|
yuuji@80
|
1693 (if (assoc cmd yahtml-env-table)
|
yuuji@80
|
1694 (save-excursion (insert (format "</%s>" cmd)))))
|
yuuji@57
|
1695
|
yuuji@64
|
1696 (defun yahtml-insert-p (&optional arg)
|
yuuji@64
|
1697 "Convenient function to insert <p></p>"
|
yuuji@64
|
1698 (interactive "P")
|
yuuji@80
|
1699 (if (or yahtml-always-/p arg) (yahtml-insert-tag arg "p")
|
yuuji@68
|
1700 (yahtml-insert-single "p")))
|
yuuji@64
|
1701
|
yuuji@70
|
1702 (defun yahtml-insert-amps (arg)
|
yuuji@70
|
1703 "Insert char-entity references via ampersand"
|
yuuji@70
|
1704 ;; Thanks; http://www.tsc.co.jp/~asada/html/wdg40_f/entities/
|
yuuji@70
|
1705 (interactive "P")
|
yuuji@70
|
1706 (let*((mess "") c
|
yuuji@70
|
1707 (list (append yahtml-entity-reference-chars-alist-default
|
yuuji@70
|
1708 yahtml-entity-reference-chars-alist))
|
yuuji@70
|
1709 (l list))
|
yuuji@70
|
1710 (while l
|
yuuji@70
|
1711 (setq mess (format "%s %c" mess (car (car l)) (cdr (car l)))
|
yuuji@70
|
1712 l (cdr l)))
|
yuuji@70
|
1713 (message "Char-entity reference: %s SPC=& RET=&; Other=&#..;" mess)
|
yuuji@70
|
1714 (setq c (read-char))
|
yuuji@70
|
1715 (cond
|
yuuji@70
|
1716 ((equal c (car-safe (assoc c list)))
|
yuuji@70
|
1717 (insert (format "&%s;" (cdr (assoc c list)))))
|
yuuji@70
|
1718 ((or (equal c ?\n) (equal c ?\r))
|
yuuji@70
|
1719 (insert "&;")
|
yuuji@70
|
1720 (forward-char -1))
|
yuuji@70
|
1721 ((equal c ? )
|
yuuji@70
|
1722 (insert ?&))
|
yuuji@70
|
1723 (t (insert (format "&#%d;" c))))))
|
yuuji@70
|
1724
|
yuuji@80
|
1725 (defun yahtml:!--\#include ()
|
yuuji@80
|
1726 (let ((file (yahtml-read-parameter "file" "")))
|
yuuji@80
|
1727 (format "%s=\"%s\"--" (if (string-match "/" file) "virtual" "file") file)))
|
yuuji@80
|
1728
|
yuuji@80
|
1729 (defun yahtml:!--\#exec ()
|
yuuji@147
|
1730 (format "cmd=\"%s\"--"
|
yuuji@147
|
1731 (yahtml-read-parameter "cmd" "" '(("cmd" . command)))))
|
yuuji@80
|
1732
|
yuuji@57
|
1733 ;;; ---------- Jump ----------
|
yuuji@57
|
1734 (defun yahtml-on-href-p ()
|
yuuji@57
|
1735 "Check if point is on href clause."
|
yuuji@60
|
1736 (let ((p (point)) e cmd (case-fold-search t))
|
yuuji@57
|
1737 (save-excursion
|
yuuji@69
|
1738 (and ;;(string= (YaTeX-inner-environment t) "a") ;aでなくても許可にした
|
yuuji@60
|
1739 (save-excursion
|
yuuji@69
|
1740 ;;(search-forward "</a>" nil t) ;aでなくても許可にした
|
yuuji@69
|
1741 (search-forward "[\" \t\n]" nil t)
|
yuuji@60
|
1742 (setq e (point)))
|
yuuji@69
|
1743 ;(goto-char (get 'YaTeX-inner-environment 'point))
|
yuuji@69
|
1744 (re-search-backward "<\\(a\\|link\\)\\>" nil t)
|
yuuji@60
|
1745 (search-forward "href" e t)
|
yuuji@60
|
1746 (search-forward "=" e t)
|
yuuji@64
|
1747 (progn
|
yuuji@64
|
1748 (skip-chars-forward " \t\n")
|
yuuji@64
|
1749 (looking-at "\"?\\([^\"> \t\n]+\\)\"?"))
|
yuuji@57
|
1750 (< p (match-end 0))
|
yuuji@153
|
1751 (yahtml-unescape-string (YaTeX-match-string 1))))))
|
yuuji@57
|
1752
|
yuuji@58
|
1753 (defun yahtml-netscape-sentinel (proc mes)
|
yuuji@58
|
1754 (cond
|
yuuji@58
|
1755 ((null (buffer-name (process-buffer proc)))
|
yuuji@58
|
1756 (set-process-buffer proc nil))
|
yuuji@58
|
1757 ((eq (process-status proc) 'exit)
|
yuuji@58
|
1758 (let ((cb (current-buffer)))
|
yuuji@58
|
1759 (set-buffer (process-buffer proc))
|
yuuji@58
|
1760 (goto-char (point-min))
|
yuuji@58
|
1761 (if (search-forward "not running" nil t)
|
yuuji@58
|
1762 (progn
|
yuuji@58
|
1763 (message "Starting netscape...")
|
yuuji@58
|
1764 (start-process
|
yuuji@60
|
1765 "browser" (process-buffer proc)
|
yuuji@60
|
1766 shell-file-name yahtml-shell-command-option
|
yuuji@60
|
1767 (format "%s \"%s\"" yahtml-www-browser
|
yuuji@58
|
1768 (get 'yahtml-netscape-sentinel 'url)))
|
yuuji@58
|
1769 (message "Starting netscape...Done")))
|
yuuji@58
|
1770 (set-buffer cb)))))
|
yuuji@58
|
1771
|
yuuji@58
|
1772 (defvar yahtml-browser-process nil)
|
yuuji@58
|
1773
|
yuuji@58
|
1774 (defun yahtml-browse-html (href)
|
yuuji@58
|
1775 "Call WWW Browser to see HREF."
|
yuuji@58
|
1776 (let ((pb "* WWW Browser *") (cb (current-buffer)))
|
yuuji@58
|
1777 (cond
|
yuuji@64
|
1778 ((string-match "^start\\>" yahtml-www-browser)
|
yuuji@64
|
1779 (if (get-buffer pb)
|
yuuji@64
|
1780 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
|
yuuji@64
|
1781 (put 'yahtml-netscape-sentinel 'url href)
|
yuuji@64
|
1782 (set-process-sentinel
|
yuuji@64
|
1783 (setq yahtml-browser-process
|
yuuji@64
|
1784 (start-process
|
yuuji@64
|
1785 "browser" pb shell-file-name yahtml-shell-command-option
|
yuuji@64
|
1786 (format "%s \"%s\"" yahtml-www-browser href)))
|
yuuji@64
|
1787 'yahtml-netscape-sentinel))
|
yuuji@86
|
1788 ((and (string-match
|
yuuji@86
|
1789 "[Nn]etscape\\|[Ff]irefox\\|[Mm]ozilla" yahtml-www-browser)
|
yuuji@60
|
1790 (not (eq system-type 'windows-nt)))
|
yuuji@58
|
1791 (if (get-buffer pb)
|
yuuji@58
|
1792 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
|
yuuji@58
|
1793 (put 'yahtml-netscape-sentinel 'url href)
|
yuuji@58
|
1794 (set-process-sentinel
|
yuuji@58
|
1795 (setq yahtml-browser-process
|
yuuji@58
|
1796 (start-process
|
yuuji@60
|
1797 "browser" pb shell-file-name yahtml-shell-command-option ;"-c"
|
yuuji@60
|
1798 (format "%s -remote \"openURL(%s)\"" yahtml-www-browser href)))
|
yuuji@58
|
1799 'yahtml-netscape-sentinel))
|
yuuji@58
|
1800 ((and (string= "w3" yahtml-www-browser) (fboundp 'w3-fetch))
|
yuuji@58
|
1801 (w3-fetch href))
|
yuuji@58
|
1802 ((stringp yahtml-www-browser)
|
yuuji@60
|
1803 (if (and yahtml-browser-process
|
yuuji@60
|
1804 (eq (process-status yahtml-browser-process) 'run))
|
yuuji@58
|
1805 (message "%s is already running" yahtml-www-browser)
|
yuuji@58
|
1806 (setq yahtml-browser-process
|
yuuji@58
|
1807 (start-process
|
yuuji@60
|
1808 "browser" "* WWW Browser *"
|
yuuji@60
|
1809 shell-file-name yahtml-shell-command-option
|
yuuji@60
|
1810 (format "%s \"%s\"" yahtml-www-browser href)))))
|
yuuji@58
|
1811 (t
|
yuuji@58
|
1812 (message "Sorry, jump across http is not supported.")))))
|
yuuji@58
|
1813
|
yuuji@57
|
1814 (defun yahtml-goto-corresponding-href (&optional other)
|
yuuji@57
|
1815 "Go to corresponding name."
|
yuuji@64
|
1816 (let ((href (yahtml-on-href-p)) file name (parent buffer-file-name))
|
yuuji@57
|
1817 (if href
|
yuuji@57
|
1818 (cond
|
yuuji@80
|
1819 ((string-match "^\\(ht\\|f\\)tps?:" href)
|
yuuji@58
|
1820 (yahtml-browse-html href))
|
yuuji@57
|
1821 (t (setq file (substring href 0 (string-match "#" href)))
|
yuuji@57
|
1822 (if (string-match "#" href)
|
yuuji@57
|
1823 (setq name (substring href (1+ (string-match "#" href)))))
|
yuuji@57
|
1824 (if (string< "" file)
|
yuuji@57
|
1825 (progn
|
yuuji@57
|
1826 (if (string-match "/$" file)
|
yuuji@70
|
1827 (or (catch 'dirindex
|
yuuji@70
|
1828 (mapcar
|
yuuji@72
|
1829 (function
|
yuuji@72
|
1830 (lambda (f)
|
yuuji@72
|
1831 (if (file-exists-p (concat file f))
|
yuuji@72
|
1832 (throw 'dirindex
|
yuuji@72
|
1833 (setq file (concat file f))))))
|
yuuji@73
|
1834 (yahtml-get-directory-index))
|
yuuji@73
|
1835 nil)
|
yuuji@70
|
1836 (setq file (concat file yahtml-directory-index))))
|
yuuji@58
|
1837 (if (string-match "^/" file)
|
yuuji@58
|
1838 (setq file (yahtml-url-to-path file)))
|
yuuji@57
|
1839 (if other (YaTeX-switch-to-buffer-other-window file)
|
yuuji@64
|
1840 (YaTeX-switch-to-buffer file))
|
yuuji@64
|
1841 (or YaTeX-parent-file (setq YaTeX-parent-file parent))))
|
yuuji@57
|
1842 (if name
|
yuuji@57
|
1843 (progn (set-mark-command nil) (yahtml-jump-to-name name)))
|
yuuji@57
|
1844 t)))))
|
yuuji@57
|
1845
|
yuuji@57
|
1846 (defun yahtml-jump-to-name (name)
|
yuuji@57
|
1847 "Jump to html's named tag."
|
yuuji@69
|
1848 (setq name (format "\\(name\\|id\\)\\s *=\\s *\"?%s\\>\"?" name))
|
yuuji@57
|
1849 (or (and (re-search-forward name nil t) (goto-char (match-beginning 0)))
|
yuuji@57
|
1850 (and (re-search-backward name nil t) (goto-char (match-beginning 0)))
|
yuuji@57
|
1851 (message "Named tag `%s' not found" (substring href 1))))
|
yuuji@57
|
1852
|
yuuji@57
|
1853 (defun yahtml-on-begend-p (&optional p)
|
yuuji@57
|
1854 "Check if point is on begend clause."
|
yuuji@60
|
1855 (let ((p (or p (point))) cmd (case-fold-search t))
|
yuuji@57
|
1856 (save-excursion
|
yuuji@60
|
1857 (goto-char p)
|
yuuji@58
|
1858 (if (equal (char-after (point)) ?<) (forward-char 1))
|
yuuji@57
|
1859 (if (and (re-search-backward "<" nil t)
|
yuuji@57
|
1860 (looking-at
|
yuuji@70
|
1861 ;(concat "<\\(/?" yahtml-struct-name-regexp "\\)\\b")
|
yuuji@102
|
1862 "<\\(/?[A-Z][A-Z0-9]*\\)\\b")
|
yuuji@57
|
1863 (condition-case nil
|
yuuji@58
|
1864 (forward-list 1)
|
yuuji@58
|
1865 (error nil))
|
yuuji@57
|
1866 (< p (point)))
|
yuuji@57
|
1867 (YaTeX-match-string 1)))))
|
yuuji@57
|
1868
|
yuuji@58
|
1869 (defun yahtml-goto-corresponding-begend (&optional noerr)
|
yuuji@58
|
1870 "Go to corresponding opening/closing tag.
|
yuuji@58
|
1871 Optional argument NOERR causes no error for unballanced tag."
|
yuuji@58
|
1872 (let ((cmd (yahtml-on-begend-p)) m0
|
yuuji@58
|
1873 (p (point)) (case-fold-search t) func str (nest 0))
|
yuuji@58
|
1874 (cond
|
yuuji@58
|
1875 (cmd
|
yuuji@58
|
1876 (setq m0 (match-beginning 0))
|
yuuji@58
|
1877 (if (= (aref cmd 0) ?/) ;on </cmd> line
|
yuuji@58
|
1878 (setq cmd (substring cmd 1)
|
yuuji@58
|
1879 str (format "\\(<%s\\)\\|\\(</%s\\)" cmd cmd)
|
yuuji@58
|
1880 func 're-search-backward)
|
yuuji@58
|
1881 (setq str (format "\\(</%s\\)\\|\\(<%s\\)" cmd cmd)
|
yuuji@58
|
1882 func 're-search-forward))
|
yuuji@58
|
1883 (while (and (>= nest 0) (funcall func str nil t))
|
yuuji@58
|
1884 (if (equal m0 (match-beginning 0))
|
yuuji@58
|
1885 nil
|
yuuji@58
|
1886 (setq nest (+ nest (if (match-beginning 1) -1 1)))))
|
yuuji@58
|
1887 (if (< nest 0)
|
yuuji@58
|
1888 (goto-char (match-beginning 0))
|
yuuji@58
|
1889 (funcall
|
yuuji@58
|
1890 (if noerr 'message 'error)
|
yuuji@58
|
1891 "Corresponding tag of `%s' not found." cmd)
|
yuuji@58
|
1892 (goto-char p)
|
yuuji@58
|
1893 nil))
|
yuuji@58
|
1894 (t nil))))
|
yuuji@58
|
1895
|
yuuji@58
|
1896 (defun yahtml-current-tag ()
|
yuuji@80
|
1897 "Return the current tag name including #exec and #include."
|
yuuji@58
|
1898 (save-excursion
|
yuuji@58
|
1899 (let ((p (point)) b tag)
|
yuuji@58
|
1900 (or (bobp)
|
yuuji@58
|
1901 (looking-at "<")
|
yuuji@58
|
1902 (progn (skip-chars-backward "^<") (forward-char -1)))
|
yuuji@58
|
1903 (setq b (point))
|
yuuji@58
|
1904 (skip-chars-forward "<")
|
yuuji@80
|
1905 (setq tag (YaTeX-buffer-substring
|
yuuji@58
|
1906 (point) (progn (skip-chars-forward "^ \t\n") (point))))
|
yuuji@58
|
1907 (goto-char b)
|
yuuji@58
|
1908 (forward-list 1)
|
yuuji@58
|
1909 (and (< p (point)) tag))))
|
yuuji@58
|
1910
|
yuuji@68
|
1911 (defun yahtml-get-attrvalue (attr)
|
yuuji@68
|
1912 "Extract current tag's attribute value from buffer."
|
yuuji@68
|
1913 (let (e (case-fold-search t))
|
yuuji@68
|
1914 (save-excursion
|
yuuji@68
|
1915 (or (looking-at "<")
|
yuuji@68
|
1916 (progn (skip-chars-backward "^<") (backward-char 1)))
|
yuuji@68
|
1917 (setq e (save-excursion (forward-list 1) (point)))
|
yuuji@68
|
1918 (if (and
|
yuuji@68
|
1919 (re-search-forward (concat "\\b" attr "\\b") e t)
|
yuuji@68
|
1920 (progn (skip-chars-forward " \t\n=")
|
yuuji@68
|
1921 (looking-at "\"?\\([^\"> \t\n]+\\)\"?")))
|
yuuji@68
|
1922 (YaTeX-match-string 1)))))
|
yuuji@68
|
1923
|
yuuji@80
|
1924 (defun yahtml-goto-corresponding-img ()
|
yuuji@80
|
1925 "View image on point"
|
yuuji@80
|
1926 (let ((tag (yahtml-current-tag)) image (p (point)) (case-fold-search t))
|
yuuji@80
|
1927 (if (and tag
|
yuuji@80
|
1928 (string-match "img" tag)
|
yuuji@153
|
1929 (setq image
|
yuuji@153
|
1930 (yahtml-unescape-string (yahtml-get-attrvalue "src"))))
|
yuuji@80
|
1931 (progn
|
yuuji@80
|
1932 (message "Invoking %s %s..." yahtml-image-viewer image)
|
yuuji@80
|
1933 (start-process
|
yuuji@80
|
1934 "Viewer" " * Image Viewer *"
|
yuuji@80
|
1935 shell-file-name yahtml-shell-command-option ;"-c"
|
yuuji@80
|
1936 (concat yahtml-image-viewer " " image))
|
yuuji@80
|
1937 (message "Invoking %s %s...Done" yahtml-image-viewer image)))))
|
yuuji@80
|
1938
|
yuuji@68
|
1939 (defun yahtml-goto-corresponding-source (&optional other)
|
yuuji@80
|
1940 "Goto applet's or script's source."
|
yuuji@68
|
1941 (let ((env (yahtml-current-tag)) s (p (point)))
|
yuuji@68
|
1942 (cond
|
yuuji@68
|
1943 ((string-match "applet" env)
|
yuuji@153
|
1944 (if (setq s (yahtml-unescape-string (yahtml-get-attrvalue "code")))
|
yuuji@68
|
1945 (progn
|
yuuji@68
|
1946 (setq s (YaTeX-match-string 1)
|
yuuji@68
|
1947 s (concat
|
yuuji@68
|
1948 (substring s 0 (string-match "\\.[A-Za-z]+$" s))
|
yuuji@68
|
1949 ".java"))
|
yuuji@68
|
1950 (if other (YaTeX-switch-to-buffer-other-window s)
|
yuuji@68
|
1951 (YaTeX-switch-to-buffer s))
|
yuuji@68
|
1952 s) ;return source file name
|
yuuji@68
|
1953 (message "No applet source specified")
|
yuuji@68
|
1954 (sit-for 1)
|
yuuji@68
|
1955 nil))
|
yuuji@80
|
1956 ((string-match "script" env)
|
yuuji@80
|
1957 (if (setq s (yahtml-get-attrvalue "src"))
|
yuuji@80
|
1958 (progn
|
yuuji@80
|
1959 (funcall (if other 'YaTeX-switch-to-buffer-other-window
|
yuuji@80
|
1960 'YaTeX-switch-to-buffer)
|
yuuji@80
|
1961 (yahtml-url-to-path s))
|
yuuji@80
|
1962 s)))
|
yuuji@68
|
1963 ((string-match "!--#include" env)
|
yuuji@68
|
1964 (cond
|
yuuji@68
|
1965 ((setq s (yahtml-get-attrvalue "file")) ;<!--#include file="foo"-->
|
yuuji@68
|
1966 (if other (YaTeX-switch-to-buffer-other-window s)
|
yuuji@68
|
1967 (YaTeX-switch-to-buffer s))
|
yuuji@68
|
1968 s)
|
yuuji@68
|
1969 ((setq s (yahtml-get-attrvalue "virtual"));<!--#include virtual="foo"-->
|
yuuji@68
|
1970 (setq s (yahtml-url-to-path s))
|
yuuji@68
|
1971 (if other (YaTeX-switch-to-buffer-other-window s)
|
yuuji@68
|
1972 (YaTeX-switch-to-buffer s))
|
yuuji@68
|
1973 s)))
|
yuuji@68
|
1974 ((and (string-match "!--#exec" env)
|
yuuji@68
|
1975 (setq s (yahtml-get-attrvalue "cmd")))
|
yuuji@68
|
1976 (setq s (substring s 0 (string-match " \t\\?" s))) ;get argv0
|
yuuji@68
|
1977 (let ((b " *yahtmltmp*")) ;peek a little
|
yuuji@68
|
1978 (unwind-protect
|
yuuji@68
|
1979 (progn
|
yuuji@68
|
1980 (set-buffer (get-buffer-create b))
|
yuuji@70
|
1981 (YaTeX-insert-file-contents s nil 0 100)
|
yuuji@68
|
1982 (if (looking-at "#!")
|
yuuji@68
|
1983 (if other (YaTeX-switch-to-buffer-other-window s)
|
yuuji@68
|
1984 (YaTeX-switch-to-buffer s))))
|
yuuji@68
|
1985 (kill-buffer (get-buffer b)))
|
yuuji@68
|
1986 (get-file-buffer s))))))
|
yuuji@68
|
1987
|
yuuji@57
|
1988 (defun yahtml-goto-corresponding-* (&optional other)
|
yuuji@57
|
1989 "Go to corresponding object."
|
yuuji@80
|
1990 (interactive "P")
|
yuuji@57
|
1991 (cond
|
yuuji@57
|
1992 ((yahtml-goto-corresponding-href other))
|
yuuji@58
|
1993 ((yahtml-goto-corresponding-img))
|
yuuji@80
|
1994 ((yahtml-goto-corresponding-source other))
|
yuuji@58
|
1995 ((yahtml-goto-corresponding-begend))
|
yuuji@102
|
1996 (t (message "I don't know where to go."))))
|
yuuji@57
|
1997
|
yuuji@57
|
1998 (defun yahtml-goto-corresponding-*-other-window ()
|
yuuji@57
|
1999 "Go to corresponding object."
|
yuuji@57
|
2000 (interactive)
|
yuuji@57
|
2001 (yahtml-goto-corresponding-* t))
|
yuuji@57
|
2002
|
yuuji@64
|
2003 (defun yahtml-visit-main ()
|
yuuji@64
|
2004 "Go to parent file from where you visit current file."
|
yuuji@64
|
2005 (interactive)
|
yuuji@64
|
2006 (if YaTeX-parent-file (YaTeX-switch-to-buffer YaTeX-parent-file)))
|
yuuji@64
|
2007
|
yuuji@58
|
2008 ;;; ---------- killing ----------
|
yuuji@58
|
2009 (defun yahtml-kill-begend (&optional whole)
|
yuuji@68
|
2010 (let ((tag (yahtml-on-begend-p)) p q r bbolp)
|
yuuji@58
|
2011 (if tag
|
yuuji@64
|
2012 (save-excursion
|
yuuji@58
|
2013 (or (looking-at "<")
|
yuuji@58
|
2014 (progn (skip-chars-backward "^<") (forward-char -1)))
|
yuuji@64
|
2015 (setq p (point))
|
yuuji@58
|
2016 (yahtml-goto-corresponding-begend)
|
yuuji@58
|
2017 (or (looking-at "<")
|
yuuji@58
|
2018 (progn (skip-chars-backward "^<") (forward-char -1)))
|
yuuji@64
|
2019 (if (< (point) p) ;if on the opening tag
|
yuuji@64
|
2020 (progn (setq q p p (point))
|
yuuji@64
|
2021 (goto-char q))
|
yuuji@64
|
2022 (setq q (point))) ;now q has end-line's (point)
|
yuuji@64
|
2023 (if (not whole)
|
yuuji@64
|
2024 (kill-region
|
yuuji@68
|
2025 (progn (skip-chars-backward " \t")
|
yuuji@68
|
2026 (if (setq bbolp (bolp)) (point) q))
|
yuuji@64
|
2027 (progn (forward-list 1)
|
yuuji@64
|
2028 (setq r (point))
|
yuuji@64
|
2029 (skip-chars-forward " \t")
|
yuuji@68
|
2030 (if (and bbolp (eolp) (not (eobp))) (1+ (point)) r))))
|
yuuji@58
|
2031 (goto-char p)
|
yuuji@64
|
2032 (skip-chars-backward " \t")
|
yuuji@64
|
2033 (if (not whole)
|
yuuji@64
|
2034 (progn
|
yuuji@64
|
2035 (kill-append
|
yuuji@64
|
2036 (buffer-substring
|
yuuji@68
|
2037 (setq p (if (setq bbolp (bolp)) (point) p))
|
yuuji@64
|
2038 (setq q (progn
|
yuuji@64
|
2039 (forward-list 1)
|
yuuji@64
|
2040 (setq r (point))
|
yuuji@64
|
2041 (skip-chars-forward " \t")
|
yuuji@68
|
2042 (if (and bbolp (eolp) (not (eobp)))
|
yuuji@68
|
2043 (1+ (point))
|
yuuji@68
|
2044 r))))
|
yuuji@64
|
2045 t)
|
yuuji@64
|
2046 (delete-region p q))
|
yuuji@64
|
2047 (kill-region
|
yuuji@64
|
2048 (if (bolp) (point) p)
|
yuuji@64
|
2049 (progn (goto-char q)
|
yuuji@64
|
2050 (forward-list 1)
|
yuuji@64
|
2051 (setq r (point))
|
yuuji@64
|
2052 (skip-chars-forward " \t")
|
yuuji@64
|
2053 (if (and (eolp) (not (eobp))) (1+ (point)) r))))
|
yuuji@58
|
2054 tag))))
|
yuuji@58
|
2055
|
yuuji@58
|
2056 (defun yahtml-kill-* (whole)
|
yuuji@58
|
2057 "Kill current position's HTML tag (set)."
|
yuuji@58
|
2058 (interactive "P")
|
yuuji@58
|
2059 (cond
|
yuuji@102
|
2060 ((yahtml-kill-begend whole))))
|
yuuji@58
|
2061
|
yuuji@58
|
2062
|
yuuji@58
|
2063 ;;; ---------- changing ----------
|
yuuji@60
|
2064 (defun yahtml-on-assignment-p ()
|
yuuji@60
|
2065 "Return if current point is on parameter assignment.
|
yuuji@60
|
2066 If so, return parameter name, otherwise nil.
|
yuuji@60
|
2067 This function should be able to treat white spaces in value, but not yet."
|
yuuji@60
|
2068 (let ((p (point)))
|
yuuji@60
|
2069 (save-excursion
|
yuuji@60
|
2070 (put 'yahtml-on-assignment-p 'region nil)
|
yuuji@70
|
2071 (skip-chars-backward "^ \t\n")
|
yuuji@60
|
2072 (and (looking-at "\\([A-Za-z0-9]+\\)\\s *=\\s *\"?\\([^ \t\"]+\\)\"?")
|
yuuji@60
|
2073 (< p (match-end 0))
|
yuuji@60
|
2074 (>= p (1- (match-beginning 2)))
|
yuuji@60
|
2075 (put 'yahtml-on-assignment-p 'region
|
yuuji@60
|
2076 (cons (match-beginning 2) (match-end 2)))
|
yuuji@60
|
2077 (YaTeX-match-string 1)))))
|
yuuji@60
|
2078
|
yuuji@58
|
2079 (defun yahtml-change-begend ()
|
yuuji@58
|
2080 (let ((tag (yahtml-on-begend-p))
|
yuuji@58
|
2081 (completion-ignore-case t)
|
yuuji@60
|
2082 (case-fold-search t)
|
yuuji@58
|
2083 (p (point)) (q (make-marker))
|
yuuji@58
|
2084 (default (append yahtml-env-table yahtml-typeface-table))
|
yuuji@58
|
2085 (user (append yahtml-user-env-table yahtml-user-typeface-table))
|
yuuji@58
|
2086 (tmp (append yahtml-tmp-env-table yahtml-tmp-typeface-table))
|
yuuji@69
|
2087 href b1 e1 attr new css)
|
yuuji@59
|
2088 (cond
|
yuuji@59
|
2089 (tag
|
yuuji@59
|
2090 (cond
|
yuuji@60
|
2091 ((and (string-match "^a$" tag)
|
yuuji@59
|
2092 (save-excursion
|
yuuji@59
|
2093 (and
|
yuuji@60
|
2094 (re-search-backward "<a\\b" nil t)
|
yuuji@64
|
2095 (progn
|
yuuji@64
|
2096 (goto-char (match-end 0))
|
yuuji@64
|
2097 (skip-chars-forward " \t\n")
|
yuuji@64
|
2098 (setq b1 (point))
|
yuuji@64
|
2099 (search-forward ">" nil t))
|
yuuji@60
|
2100 (setq e1 (match-beginning 0))
|
yuuji@60
|
2101 (goto-char b1)
|
yuuji@60
|
2102 (re-search-forward "href\\s *=" e1 t)
|
yuuji@59
|
2103 (>= p (point))
|
yuuji@64
|
2104 (progn
|
yuuji@64
|
2105 (goto-char (match-end 0))
|
yuuji@64
|
2106 (skip-chars-forward " \t\n")
|
yuuji@64
|
2107 (looking-at "\"?\\([^\"> \t\n]+\\)\"?"))
|
yuuji@59
|
2108 (< p (match-end 0)))))
|
yuuji@59
|
2109 (setq b1 (match-beginning 1) e1 (match-end 1)
|
yuuji@60
|
2110 yahtml-completing-buffer (current-buffer)
|
yuuji@64
|
2111 ;; yahtml-urls-local is buffer-local, so we must put
|
yuuji@64
|
2112 ;; that into yahtml-urls here
|
yuuji@64
|
2113 yahtml-urls (append yahtml-urls-private yahtml-urls-local)
|
yuuji@59
|
2114 href (read-from-minibuffer
|
yuuji@59
|
2115 "Change href to: " "" yahtml-url-completion-map))
|
yuuji@59
|
2116 (if (string< "" href)
|
yuuji@59
|
2117 (progn
|
yuuji@60
|
2118 ;;(setq href ;??
|
yuuji@60
|
2119 ;; (if yahtml-prefer-upcases (upcase href) (downcase href)))
|
yuuji@59
|
2120 (delete-region b1 e1)
|
yuuji@59
|
2121 (goto-char b1)
|
yuuji@59
|
2122 (insert href))))
|
yuuji@69
|
2123 ((setq attr (yahtml-on-assignment-p)) ;if on the assignment to attr
|
yuuji@69
|
2124 (if (and (equal attr "class") ;treat "class" attribute specially
|
yuuji@70
|
2125 (setq css (yahtml-css-get-element-completion-alist tag)))
|
yuuji@80
|
2126
|
yuuji@80
|
2127 (setq new (yahtml-read-css css))
|
yuuji@69
|
2128 ;;other than "class", read parameter normally
|
yuuji@69
|
2129 (setq new (yahtml-read-parameter attr)))
|
yuuji@69
|
2130 (goto-char (car (get 'yahtml-on-assignment-p 'region)))
|
yuuji@69
|
2131 (delete-region (point) (cdr (get 'yahtml-on-assignment-p 'region)))
|
yuuji@69
|
2132 (insert new))
|
yuuji@59
|
2133 (t
|
yuuji@58
|
2134 (save-excursion
|
yuuji@58
|
2135 (if (= (aref tag 0) ?/) (setq tag (substring tag 1)))
|
yuuji@58
|
2136 (or (= (char-after (point)) ?<) (skip-chars-backward "^<"))
|
yuuji@58
|
2137 (skip-chars-forward "^A-Za-z")
|
yuuji@58
|
2138 (set-marker q (point))
|
yuuji@58
|
2139 (setq p (point))
|
yuuji@58
|
2140 (yahtml-goto-corresponding-begend)
|
yuuji@58
|
2141 (or (= (char-after (point)) ?<)
|
yuuji@58
|
2142 (skip-chars-backward "^<"))
|
yuuji@58
|
2143 (skip-chars-forward "^A-Za-z")
|
yuuji@58
|
2144 (if (= (char-after (1- (point))) ?/)
|
yuuji@58
|
2145 (progn
|
yuuji@58
|
2146 (set-marker q (point))
|
yuuji@58
|
2147 (goto-char p)))
|
yuuji@60
|
2148 (setq tag (let ((completion-ignore-case t))
|
yuuji@60
|
2149 (YaTeX-cplread-with-learning
|
yuuji@60
|
2150 (format "Change `%s' to(default %s): "
|
yuuji@60
|
2151 tag yahtml-last-begend)
|
yuuji@60
|
2152 'default 'user 'tmp)))
|
yuuji@58
|
2153 (delete-region (point) (progn (skip-chars-forward "^>") (point)))
|
yuuji@58
|
2154 (if (string= "" tag) (setq tag yahtml-last-begend))
|
yuuji@58
|
2155 (setq yahtml-last-begend
|
yuuji@58
|
2156 (or (cdr (assoc tag yahtml-env-table)) tag)
|
yuuji@58
|
2157 tag yahtml-last-begend)
|
yuuji@60
|
2158 (setq tag (if yahtml-prefer-upcases (upcase tag) (downcase tag)))
|
yuuji@58
|
2159 (insert (format "%s%s" tag (yahtml-addin tag)))
|
yuuji@58
|
2160 (goto-char q)
|
yuuji@68
|
2161 (set-marker q nil)
|
yuuji@58
|
2162 (delete-region (point) (progn (skip-chars-forward "^>") (point)))
|
yuuji@60
|
2163 (insert tag))))
|
yuuji@60
|
2164 t))))
|
yuuji@60
|
2165
|
yuuji@60
|
2166 (defun yahtml-change-command ()
|
yuuji@60
|
2167 (let ((p (point)) (case-fold-search t) cmd par new
|
yuuji@60
|
2168 (beg (make-marker)) (end (make-marker)))
|
yuuji@60
|
2169 (skip-chars-backward "^<")
|
yuuji@60
|
2170 (if (and
|
yuuji@60
|
2171 (looking-at yahtml-command-regexp)
|
yuuji@60
|
2172 (progn
|
yuuji@60
|
2173 (set-marker beg (match-beginning 0))
|
yuuji@60
|
2174 (set-marker end (match-end 0))
|
yuuji@60
|
2175 t) ;for further work
|
yuuji@60
|
2176 (progn
|
yuuji@60
|
2177 (forward-char -1)
|
yuuji@60
|
2178 (condition-case nil
|
yuuji@60
|
2179 (forward-list 1)
|
yuuji@60
|
2180 (error nil))
|
yuuji@60
|
2181 (< p (point))))
|
yuuji@60
|
2182 (progn
|
yuuji@60
|
2183 (goto-char p)
|
yuuji@60
|
2184 (if (setq par (yahtml-on-assignment-p))
|
yuuji@60
|
2185 (progn
|
yuuji@60
|
2186 (setq new (yahtml-read-parameter par))
|
yuuji@60
|
2187 (set-marker beg (car (get 'yahtml-on-assignment-p 'region)))
|
yuuji@60
|
2188 (set-marker end (cdr (get 'yahtml-on-assignment-p 'region))))
|
yuuji@60
|
2189 (setq new
|
yuuji@60
|
2190 (YaTeX-cplread-with-learning
|
yuuji@60
|
2191 "Change form to: "
|
yuuji@60
|
2192 'yahtml-form-table 'yahtml-user-form-table
|
yuuji@60
|
2193 'yahtml-tmp-form-table)))
|
yuuji@60
|
2194 (delete-region beg end)
|
yuuji@60
|
2195 (goto-char beg)
|
yuuji@68
|
2196 (set-marker beg nil)
|
yuuji@68
|
2197 (set-marker end nil)
|
yuuji@60
|
2198 (insert new)
|
yuuji@60
|
2199 t)
|
yuuji@60
|
2200 (goto-char p)
|
yuuji@60
|
2201 nil)))
|
yuuji@58
|
2202
|
yuuji@58
|
2203 (defun yahtml-change-* ()
|
yuuji@58
|
2204 "Change current position's HTML tag (set)."
|
yuuji@58
|
2205 (interactive)
|
yuuji@58
|
2206 (cond
|
yuuji@58
|
2207 ((yahtml-change-begend))
|
yuuji@102
|
2208 ((yahtml-change-command))))
|
yuuji@58
|
2209
|
yuuji@57
|
2210 ;;; ---------- commenting ----------
|
yuuji@69
|
2211
|
yuuji@64
|
2212 (defun yahtml-comment-region (&optional uncom)
|
yuuji@64
|
2213 "Comment out region or environment."
|
yuuji@64
|
2214 (interactive)
|
yuuji@72
|
2215 (let ((e (make-marker)) be beg p)
|
yuuji@64
|
2216 (cond
|
yuuji@72
|
2217 (;(marker-position (set-marker e (yahtml-on-begend-p)))
|
yuuji@72
|
2218 (setq be (yahtml-on-begend-p))
|
yuuji@64
|
2219 (save-excursion
|
yuuji@64
|
2220 (setq p (point))
|
yuuji@72
|
2221 (if (string-match "^/" be)
|
yuuji@64
|
2222 (setq beg (progn (forward-line 1) (point)))
|
yuuji@64
|
2223 (setq beg (progn (beginning-of-line) (point))))
|
yuuji@64
|
2224 (goto-char p)
|
yuuji@64
|
2225 (yahtml-goto-corresponding-begend)
|
yuuji@72
|
2226 (if (string-match "^/" be)
|
yuuji@64
|
2227 (beginning-of-line)
|
yuuji@64
|
2228 (forward-line 1))
|
yuuji@69
|
2229 (set-marker e (point))
|
yuuji@102
|
2230 ;(comment-region beg (point) (if uncom (list 4)))))
|
yuuji@103
|
2231 ))
|
yuuji@69
|
2232 (t ;(comment-region (region-beginning) (region-end) (if uncom (list 4)))
|
yuuji@69
|
2233 (setq beg (region-beginning))
|
yuuji@69
|
2234 (set-marker e (region-end))))
|
yuuji@69
|
2235 (if yahtml-translate-hyphens-when-comment-region
|
yuuji@69
|
2236 (let ((yahtml-entity-reference-chars-alist-default nil)
|
yuuji@69
|
2237 (yahtml-entity-reference-chars-alist '((?- . "#45")))
|
yuuji@69
|
2238 yahtml-entity-reference-chars-regexp
|
yuuji@69
|
2239 yahtml-entity-reference-chars-reverse-regexp)
|
yuuji@69
|
2240 (yahtml-entity-reference-chars-setup)
|
yuuji@69
|
2241 (funcall
|
yuuji@69
|
2242 (if uncom 'yahtml-translate-reverse-region
|
yuuji@69
|
2243 'yahtml-translate-region)
|
yuuji@69
|
2244 beg e)))
|
yuuji@69
|
2245 (comment-region beg e (if uncom (list 4)))
|
yuuji@69
|
2246 (set-marker e nil)))
|
yuuji@57
|
2247
|
yuuji@64
|
2248 (defun yahtml-uncomment-region ()
|
yuuji@64
|
2249 (interactive)
|
yuuji@64
|
2250 (yahtml-comment-region t))
|
yuuji@57
|
2251
|
yuuji@69
|
2252 ;;; ---------- translate to entity references ----------
|
yuuji@69
|
2253 (defvar yahtml-entity-reference-chars-alist-default
|
yuuji@69
|
2254 ;'((?> . "gt") (?< . "lt") (?& . "amp") (?\" . "quot") (?' . "apos"))
|
yuuji@69
|
2255 '((?> . "gt") (?< . "lt") (?& . "amp") (?\" . "quot"))
|
yuuji@69
|
2256 "Default translation table from character to entity reference")
|
yuuji@69
|
2257 (defvar yahtml-entity-reference-chars-alist nil
|
yuuji@69
|
2258 "*Translation table from character to entity reference")
|
yuuji@69
|
2259 (defvar yahtml-entity-reference-chars-regexp nil)
|
yuuji@69
|
2260 (defvar yahtml-entity-reference-chars-reverse-regexp nil)
|
yuuji@57
|
2261
|
yuuji@69
|
2262 (defun yahtml-entity-reference-chars-setup ()
|
yuuji@69
|
2263 (let ((list (append yahtml-entity-reference-chars-alist-default
|
yuuji@69
|
2264 yahtml-entity-reference-chars-alist)))
|
yuuji@69
|
2265 (setq yahtml-entity-reference-chars-regexp "["
|
yuuji@69
|
2266 yahtml-entity-reference-chars-reverse-regexp "&\\(")
|
yuuji@69
|
2267 (while list
|
yuuji@69
|
2268 (setq yahtml-entity-reference-chars-regexp
|
yuuji@69
|
2269 (concat yahtml-entity-reference-chars-regexp
|
yuuji@69
|
2270 (char-to-string (car (car list))))
|
yuuji@69
|
2271 yahtml-entity-reference-chars-reverse-regexp
|
yuuji@69
|
2272 (concat yahtml-entity-reference-chars-reverse-regexp
|
yuuji@69
|
2273 (cdr (car list))
|
yuuji@69
|
2274 (if (cdr list) "\\|")))
|
yuuji@69
|
2275 (setq list (cdr list)))
|
yuuji@69
|
2276 (setq yahtml-entity-reference-chars-regexp
|
yuuji@69
|
2277 (concat yahtml-entity-reference-chars-regexp "]")
|
yuuji@69
|
2278 yahtml-entity-reference-chars-reverse-regexp
|
yuuji@69
|
2279 (concat yahtml-entity-reference-chars-reverse-regexp "\\);"))))
|
yuuji@69
|
2280
|
yuuji@69
|
2281 (yahtml-entity-reference-chars-setup)
|
yuuji@69
|
2282
|
yuuji@69
|
2283 (defun yahtml-translate-region (beg end)
|
yuuji@69
|
2284 "Translate inhibited literals."
|
yuuji@69
|
2285 (interactive "r")
|
yuuji@69
|
2286 (save-excursion
|
yuuji@69
|
2287 (save-restriction
|
yuuji@69
|
2288 (narrow-to-region beg end)
|
yuuji@69
|
2289 (let ((ct (append yahtml-entity-reference-chars-alist
|
yuuji@69
|
2290 yahtml-entity-reference-chars-alist-default)))
|
yuuji@69
|
2291 (goto-char beg)
|
yuuji@69
|
2292 (while (re-search-forward yahtml-entity-reference-chars-regexp nil t)
|
yuuji@69
|
2293 ;(setq c (preceding-char))
|
yuuji@69
|
2294 (replace-match
|
yuuji@69
|
2295 (concat "&" (cdr (assoc (preceding-char) ct)) ";")))))))
|
yuuji@69
|
2296
|
yuuji@69
|
2297 (defun yahtml-translate-reverse-region (beg end)
|
yuuji@69
|
2298 "Translate entity references to literals."
|
yuuji@69
|
2299 (interactive "r")
|
yuuji@69
|
2300 (save-excursion
|
yuuji@69
|
2301 (save-restriction
|
yuuji@69
|
2302 (narrow-to-region beg end)
|
yuuji@69
|
2303 (let ((ct (append yahtml-entity-reference-chars-alist
|
yuuji@69
|
2304 yahtml-entity-reference-chars-alist-default))
|
yuuji@69
|
2305 ec)
|
yuuji@69
|
2306 (goto-char beg)
|
yuuji@69
|
2307 (while (re-search-forward
|
yuuji@69
|
2308 yahtml-entity-reference-chars-reverse-regexp nil t)
|
yuuji@69
|
2309 ;(setq c (preceding-char))
|
yuuji@69
|
2310 (setq ec (YaTeX-match-string 1))
|
yuuji@69
|
2311 (delete-region (match-end 0) (match-beginning 0))
|
yuuji@69
|
2312 (insert (car (YaTeX-rassoc ec ct))))))))
|
yuuji@57
|
2313
|
yuuji@60
|
2314 (defun yahtml-inner-environment-but (exclude &optional quick)
|
yuuji@60
|
2315 "Return the inner environment but matches with EXCLUDE tag."
|
yuuji@64
|
2316 (let (e (case-fold-search t))
|
yuuji@60
|
2317 (save-excursion
|
yuuji@60
|
2318 (while (and (setq e (YaTeX-inner-environment quick))
|
yuuji@60
|
2319 (string-match exclude e))
|
yuuji@60
|
2320 (goto-char (get 'YaTeX-inner-environment 'point))))
|
yuuji@60
|
2321 e))
|
yuuji@60
|
2322
|
yuuji@145
|
2323 (defun yahtml-untranslate-string (str)
|
yuuji@145
|
2324 "Untranslate entity reference."
|
yuuji@145
|
2325 (let ((md (match-data)) (left "") (right str) b0 ch
|
yuuji@145
|
2326 (ct (append yahtml-entity-reference-chars-alist
|
yuuji@145
|
2327 yahtml-entity-reference-chars-alist-default))
|
yuuji@145
|
2328 (revrex yahtml-entity-reference-chars-reverse-regexp))
|
yuuji@145
|
2329 (unwind-protect
|
yuuji@145
|
2330 (progn
|
yuuji@145
|
2331 (while (string< "" right)
|
yuuji@145
|
2332 (cond
|
yuuji@145
|
2333 ((string-match revrex right)
|
yuuji@145
|
2334 (setq ch (YaTeX-rassoc
|
yuuji@145
|
2335 (substring right (match-beginning 1) (match-end 1)))
|
yuuji@145
|
2336 b0 (substring right 0 (match-beginning 0))
|
yuuji@145
|
2337 right (substring right (match-end 0))
|
yuuji@145
|
2338 left (concat left
|
yuuji@145
|
2339 (substring right 0 (match-beginning 0))
|
yuuji@145
|
2340 (char-to-string ch))))
|
yuuji@145
|
2341 ((string-match "\\&#\\(x\\)?\\([0-9a-f]+\\);" right)
|
yuuji@145
|
2342 (setq ch (substring right (match-beginning 2) (match-end 2))
|
yuuji@145
|
2343 b0 (substring right 0 (match-beginning 0))
|
yuuji@145
|
2344 right (substring right (match-end 0))
|
yuuji@145
|
2345 left (concat left
|
yuuji@145
|
2346 b0
|
yuuji@145
|
2347 (char-to-string
|
yuuji@145
|
2348 (if (match-beginning 1)
|
yuuji@145
|
2349 (YaTeX-hex ch)
|
yuuji@145
|
2350 (string-to-number ch))))))
|
yuuji@145
|
2351 (t (setq left (concat left right)
|
yuuji@145
|
2352 right ""))))
|
yuuji@145
|
2353 left)
|
yuuji@145
|
2354 (store-match-data md))))
|
yuuji@145
|
2355
|
yuuji@154
|
2356 ;;; ---------- table-ize region ----------
|
yuuji@154
|
2357 (defun yahtml-td-region (e delim beg end)
|
yuuji@154
|
2358 "Enclose each item in a region with <td>..</td>.
|
yuuji@154
|
2359 Interactive prefix argument consults enclosing element other than td."
|
yuuji@154
|
2360 (interactive "P\nsDelimiter(s): \nr")
|
yuuji@156
|
2361 (let ((e (cond
|
yuuji@156
|
2362 ((null e) "td")
|
yuuji@156
|
2363 ((stringp e) e)
|
yuuji@157
|
2364 (t (read-string "Enclose with(`thd' means th td td..): " "th"))))
|
yuuji@157
|
2365 (ws "[ \t]")
|
yuuji@157
|
2366 elm p i)
|
yuuji@154
|
2367 (if (string= delim "") (setq delim " \t\n"))
|
yuuji@157
|
2368 (setq delim (concat "[" delim "]+")
|
yuuji@157
|
2369 elm (if (string= "thd" e)
|
yuuji@157
|
2370 (cons "th" "td")
|
yuuji@157
|
2371 (cons e e)))
|
yuuji@154
|
2372 (save-excursion
|
yuuji@154
|
2373 (save-restriction
|
yuuji@154
|
2374 (narrow-to-region beg end)
|
yuuji@154
|
2375 (goto-char (setq p (point-min)))
|
yuuji@157
|
2376 (setq i 0 e (car elm))
|
yuuji@154
|
2377 (while (re-search-forward delim nil t)
|
yuuji@157
|
2378 (setq e (if (= (setq i (1+ i)) 1) (car elm) (cdr elm)))
|
yuuji@154
|
2379 (goto-char (match-beginning 0))
|
yuuji@154
|
2380 (insert "</" e ">")
|
yuuji@154
|
2381 (save-excursion
|
yuuji@154
|
2382 (goto-char p)
|
yuuji@154
|
2383 (insert "<" e ">"))
|
yuuji@154
|
2384 (setq p (point))
|
yuuji@155
|
2385 (while (and (not (eobp)) (looking-at ws))
|
yuuji@155
|
2386 (delete-char 1))
|
yuuji@155
|
2387 (if (looking-at delim) (delete-char 1)))
|
yuuji@154
|
2388 (insert "<" e ">")
|
yuuji@154
|
2389 (goto-char (point-max))
|
yuuji@154
|
2390 (insert "</" e ">")))))
|
yuuji@154
|
2391
|
yuuji@154
|
2392 (defun yahtml-tr-region (e delim beg end)
|
yuuji@154
|
2393 "Enclose lines in a form tab-sv/csv with <tr><td>..</td></tr>."
|
yuuji@154
|
2394 (interactive "P\nsDelimiter(s): \nr")
|
yuuji@157
|
2395 (setq e (if (and e (listp e))
|
yuuji@157
|
2396 (read-string "Enclose with(td or th, `thd' -> th td td td...: "
|
yuuji@157
|
2397 "th")))
|
yuuji@156
|
2398 (save-excursion
|
yuuji@156
|
2399 (save-restriction
|
yuuji@156
|
2400 (narrow-to-region (point) (mark))
|
yuuji@156
|
2401 (goto-char (point-min))
|
yuuji@156
|
2402 (while (not (eobp))
|
yuuji@156
|
2403 (insert "<tr>")
|
yuuji@156
|
2404 (yahtml-td-region e delim (point) (point-end-of-line))
|
yuuji@156
|
2405 (end-of-line)
|
yuuji@156
|
2406 (insert "</tr>")
|
yuuji@156
|
2407 (forward-line 1)))))
|
yuuji@154
|
2408
|
yuuji@58
|
2409 ;;; ---------- filling ----------
|
yuuji@60
|
2410 (defvar yahtml-saved-move-to-column (symbol-function 'move-to-column))
|
yuuji@60
|
2411 (defun yahtml-move-to-column (col &optional force)
|
yuuji@60
|
2412 (beginning-of-line)
|
yuuji@60
|
2413 (let ((ccol 0))
|
yuuji@60
|
2414 (while (and (> col ccol) (not (eolp)))
|
yuuji@60
|
2415 (if (eq (following-char) ?\<)
|
yuuji@60
|
2416 (progn
|
yuuji@60
|
2417 (while (and (not (eq (following-char) ?\>))
|
yuuji@60
|
2418 (not (eolp)))
|
yuuji@60
|
2419 (forward-char))
|
yuuji@60
|
2420 (or (eolp) (forward-char)))
|
yuuji@60
|
2421 (or (eolp) (forward-char))
|
yuuji@60
|
2422 (if (eq (preceding-char) ?\t)
|
yuuji@60
|
2423 (let ((wd (- 8 (% (+ ccol 8) 8))))
|
yuuji@60
|
2424 (if (and force (< col (+ ccol wd)))
|
yuuji@60
|
2425 (progn
|
yuuji@60
|
2426 (backward-char 1)
|
yuuji@60
|
2427 (insert-char ?\ (- col ccol))
|
yuuji@60
|
2428 (setq ccol col))
|
yuuji@60
|
2429 (setq ccol (+ ccol wd))))
|
yuuji@60
|
2430 (setq ccol (1+ ccol)))
|
yuuji@60
|
2431 (if (and YaTeX-japan
|
yuuji@69
|
2432 (or
|
yuuji@69
|
2433 (and (fboundp 'char-category)
|
yuuji@69
|
2434 (string-match "[chj]" (char-category (preceding-char))))
|
yuuji@69
|
2435 (and (fboundp 'char-charset)
|
yuuji@69
|
2436 (not (eq (char-charset (preceding-char)) 'ascii)))))
|
yuuji@60
|
2437 (setq ccol (1+ ccol)))))
|
yuuji@60
|
2438 (if (and force (> col ccol))
|
yuuji@60
|
2439 (progn
|
yuuji@60
|
2440 (insert-char ?\ (- col ccol))
|
yuuji@60
|
2441 col)
|
yuuji@60
|
2442 ccol)))
|
yuuji@60
|
2443
|
yuuji@58
|
2444 (defun yahtml-fill-paragraph (arg)
|
yuuji@58
|
2445 (interactive "P")
|
yuuji@68
|
2446 (let*((case-fold-search t) (p (point)) fill-prefix
|
yuuji@61
|
2447 (e (or (yahtml-inner-environment-but "^\\(a\\|p\\)\\b" t) "html"))
|
yuuji@68
|
2448 indent
|
yuuji@68
|
2449 (startp (get 'YaTeX-inner-environment 'point))
|
yuuji@60
|
2450 (prep (string-match "^pre$" e))
|
yuuji@60
|
2451 (ps1 (if prep (default-value 'paragraph-start)
|
yuuji@60
|
2452 paragraph-start))
|
yuuji@60
|
2453 (ps2 (if prep (concat (default-value 'paragraph-start)
|
yuuji@69
|
2454 "$\\|^\\s *</?pre>")
|
yuuji@60
|
2455 paragraph-start)))
|
yuuji@58
|
2456 (save-excursion
|
yuuji@60
|
2457 (unwind-protect
|
yuuji@60
|
2458 (progn
|
yuuji@60
|
2459 (if prep
|
yuuji@60
|
2460 (fset 'move-to-column 'yahtml-move-to-column))
|
yuuji@68
|
2461 (save-excursion
|
yuuji@68
|
2462 (beginning-of-line)
|
yuuji@68
|
2463 (indent-to-column (yahtml-this-indent))
|
yuuji@68
|
2464 (setq fill-prefix
|
yuuji@68
|
2465 (buffer-substring (point) (point-beginning-of-line)))
|
yuuji@68
|
2466 (delete-region (point) (point-beginning-of-line)))
|
yuuji@60
|
2467 (fill-region-as-paragraph
|
yuuji@60
|
2468 (progn (re-search-backward paragraph-start nil t)
|
yuuji@60
|
2469 (or (save-excursion
|
yuuji@64
|
2470 (goto-char (match-beginning 0))
|
yuuji@64
|
2471 (if (looking-at "<")
|
yuuji@64
|
2472 (forward-list)
|
yuuji@64
|
2473 (goto-char (match-end 0))
|
yuuji@64
|
2474 (skip-chars-forward " \t>"))
|
yuuji@60
|
2475 (if (looking-at "[ \t]*$")
|
yuuji@60
|
2476 (progn (forward-line 1) (point))))
|
yuuji@60
|
2477 (point)))
|
yuuji@60
|
2478 (progn (goto-char p)
|
yuuji@60
|
2479 (re-search-forward ps2 nil t)
|
yuuji@69
|
2480 (match-beginning 0))))
|
yuuji@60
|
2481 (fset 'move-to-column yahtml-saved-move-to-column)))))
|
yuuji@60
|
2482
|
yuuji@60
|
2483 ;(defun yahtml-indent-new-commnet-line ()
|
yuuji@60
|
2484 ; (unwind-protect
|
yuuji@60
|
2485 ; (progn
|
yuuji@60
|
2486 ; (fset 'move-to-column 'yahtml-move-to-column)
|
yuuji@60
|
2487 ; (apply 'YaTeX-saved-indent-new-comment-line (if soft (list soft))))
|
yuuji@60
|
2488 ; (fset 'move-to-column yahtml-saved-move-to-column)))
|
yuuji@58
|
2489
|
yuuji@58
|
2490 ;;;
|
yuuji@58
|
2491 ;;; ---------- indentation ----------
|
yuuji@58
|
2492 ;;;
|
yuuji@58
|
2493 (defun yahtml-indent-line ()
|
yuuji@64
|
2494 "Indent a line (faster wrapper)"
|
yuuji@58
|
2495 (interactive)
|
yuuji@64
|
2496 (let (indent)
|
yuuji@64
|
2497 (if (and (save-excursion
|
yuuji@64
|
2498 (beginning-of-line) (skip-chars-forward "\t ")
|
yuuji@64
|
2499 (not (looking-at "<")))
|
yuuji@64
|
2500 (save-excursion
|
yuuji@64
|
2501 (forward-line -1)
|
yuuji@64
|
2502 (while (and (not (bobp)) (looking-at "^\\s *$"))
|
yuuji@64
|
2503 (forward-line -1))
|
yuuji@64
|
2504 (skip-chars-forward "\t ")
|
yuuji@64
|
2505 (setq indent (current-column))
|
yuuji@64
|
2506 (not (looking-at "<"))))
|
yuuji@64
|
2507 (progn
|
yuuji@64
|
2508 (save-excursion
|
yuuji@64
|
2509 (beginning-of-line)
|
yuuji@64
|
2510 (skip-chars-forward " \t")
|
yuuji@64
|
2511 (or (= (current-column) indent)
|
yuuji@64
|
2512 (YaTeX-reindent indent)))
|
yuuji@64
|
2513 (and (bolp) (skip-chars-forward " \t")))
|
yuuji@64
|
2514 (yahtml-indent-line-real))))
|
yuuji@64
|
2515
|
yuuji@68
|
2516 (defun yahtml-this-indent ()
|
yuuji@190
|
2517 (let ((envs "[uod]l\\|table\\|[ht][rhd0-6]\\|select\\|blockquote\\|center\\|menu\\|dir\\|d[td]\\|li")
|
yuuji@190
|
2518 (itemizing-envs "^\\([uod]l\\|menu\\|dir\\|li\\|d[td]\\)$")
|
yuuji@61
|
2519 (itms "<\\(dt\\|dd\\|li\\|t[rdh]\\|option\\)\\b")
|
yuuji@70
|
2520 (excludes
|
yuuji@190
|
2521 "\\b\\(a\\|p\\|span\\|code\\|tt\\|em\\|u\\|i\\|big\\|small\\|font\\)\\b")
|
yuuji@58
|
2522 inenv p col peol (case-fold-search t))
|
yuuji@58
|
2523 (save-excursion
|
yuuji@58
|
2524 (beginning-of-line)
|
yuuji@70
|
2525 (setq inenv (or (yahtml-inner-environment-but excludes t)
|
yuuji@61
|
2526 "html")
|
yuuji@58
|
2527 col (get 'YaTeX-inner-environment 'indent)
|
yuuji@58
|
2528 p (get 'YaTeX-inner-environment 'point)
|
yuuji@64
|
2529 op nil))
|
yuuji@58
|
2530 (save-excursion
|
yuuji@58
|
2531 (cond
|
yuuji@70
|
2532 ((string-match (concat "^\\(" envs "\\)") inenv)
|
yuuji@58
|
2533 (save-excursion
|
yuuji@58
|
2534 (beginning-of-line)
|
yuuji@58
|
2535 (skip-chars-forward " \t")
|
yuuji@64
|
2536 (cond ;lookup current line's tag
|
yuuji@58
|
2537 ((looking-at (concat "</\\(" envs "\\)>"))
|
yuuji@68
|
2538 col)
|
yuuji@64
|
2539 ((looking-at itms)
|
yuuji@68
|
2540 (+ col yahtml-environment-indent))
|
yuuji@64
|
2541 ((and yahtml-hate-too-deep-indentation
|
yuuji@64
|
2542 (looking-at (concat "<\\(" envs "\\)")))
|
yuuji@68
|
2543 (+ col (* 2 yahtml-environment-indent)))
|
yuuji@58
|
2544 ((and (< p (point))
|
yuuji@64
|
2545 (string-match itemizing-envs inenv)
|
yuuji@58
|
2546 (save-excursion
|
yuuji@58
|
2547 (and
|
yuuji@58
|
2548 (setq op (point))
|
yuuji@58
|
2549 (goto-char p)
|
yuuji@58
|
2550 (re-search-forward itms op t)
|
yuuji@64
|
2551 (progn
|
yuuji@73
|
2552 (if yahtml-indent-listing-constant
|
yuuji@73
|
2553 (setq col (+ (current-column)
|
yuuji@73
|
2554 (if yahtml-faithful-to-htmllint 1 2)))
|
yuuji@73
|
2555 (skip-chars-forward "^>")
|
yuuji@73
|
2556 (skip-chars-forward ">")
|
yuuji@73
|
2557 (skip-chars-forward " \t")
|
yuuji@73
|
2558 (setq col (if (looking-at "$")
|
yuuji@73
|
2559 (+ col yahtml-environment-indent)
|
yuuji@73
|
2560 (current-column))))))))
|
yuuji@68
|
2561 col)
|
yuuji@58
|
2562 (t
|
yuuji@68
|
2563 (+ col yahtml-environment-indent)))))
|
yuuji@68
|
2564 (t col)))))
|
yuuji@68
|
2565
|
yuuji@68
|
2566 (defun yahtml-indent-line-real ()
|
yuuji@68
|
2567 "Indent current line."
|
yuuji@68
|
2568 (interactive)
|
yuuji@68
|
2569 (YaTeX-reindent (yahtml-this-indent))
|
yuuji@68
|
2570 (if (bolp) (skip-chars-forward " \t"))
|
yuuji@70
|
2571 (let (peol col inenv)
|
yuuji@68
|
2572 (if (and (setq inenv (yahtml-on-begend-p))
|
yuuji@68
|
2573 (string-match
|
yuuji@68
|
2574 (concat "^\\<\\(" yahtml-struct-name-regexp "\\)") inenv))
|
yuuji@68
|
2575 (save-excursion
|
yuuji@68
|
2576 (setq peol (point-end-of-line))
|
yuuji@68
|
2577 (or (= (char-after (point)) ?<)
|
yuuji@68
|
2578 (progn (skip-chars-backward "^<") (forward-char -1)))
|
yuuji@68
|
2579 (setq col (current-column))
|
yuuji@68
|
2580 (if (and (yahtml-goto-corresponding-begend t)
|
yuuji@68
|
2581 (> (point) peol)) ;if on the different line
|
yuuji@68
|
2582 (YaTeX-reindent col))))))
|
yuuji@58
|
2583
|
yuuji@58
|
2584 ;(defun yahtml-fill-item ()
|
yuuji@58
|
2585 ; "Fill item HTML version"
|
yuuji@58
|
2586 ; (interactive)
|
yuuji@58
|
2587 ; (let (inenv p fill-prefix peol (case-fold-search t))
|
yuuji@58
|
2588 ; (setq inenv (or (YaTeX-inner-environment) "html")
|
yuuji@58
|
2589 ; p (get 'YaTeX-inner-environment 'point))
|
yuuji@58
|
2590 ; (cond
|
yuuji@58
|
2591 ; ((string-match "^[uod]l" inenv)
|
yuuji@58
|
2592 ; (save-excursion
|
yuuji@58
|
2593 ; (if (re-search-backward "<\\(d[td]\\|li\\)>[ \t\n]*" p t)
|
yuuji@58
|
2594 ; (progn
|
yuuji@58
|
2595 ; (goto-char (match-end 0))
|
yuuji@58
|
2596 ; (setq col (current-column)))
|
yuuji@58
|
2597 ; (error "No <li>, <dt>, <dd>")))
|
yuuji@58
|
2598 ; (save-excursion
|
yuuji@58
|
2599 ; (end-of-line)
|
yuuji@58
|
2600 ; (setq peol (point))
|
yuuji@58
|
2601 ; (newline)
|
yuuji@58
|
2602 ; (indent-to-column col)
|
yuuji@58
|
2603 ; (setq fill-prefix (buffer-substring (point) (1+ peol)))
|
yuuji@58
|
2604 ; (delete-region (point) peol)
|
yuuji@58
|
2605 ; (fill-region-as-paragraph
|
yuuji@58
|
2606 ; (progn (re-search-backward paragraph-start nil t) (point))
|
yuuji@58
|
2607 ; (progn (re-search-forward paragraph-start nil t 2)
|
yuuji@58
|
2608 ; (match-beginning 0)))))
|
yuuji@58
|
2609 ; (t nil))))
|
yuuji@58
|
2610
|
yuuji@58
|
2611 ;;;
|
yuuji@60
|
2612 ;;; ---------- Lint and Browsing ----------
|
yuuji@58
|
2613 ;;;
|
yuuji@58
|
2614 (defun yahtml-browse-menu ()
|
yuuji@138
|
2615 "Browsing or other external process invokation menu."
|
yuuji@58
|
2616 (interactive)
|
yuuji@138
|
2617 (message "J)weblint p)Browse R)eload N)ewpage...")
|
yuuji@58
|
2618 (let ((c (char-to-string (read-char))))
|
yuuji@58
|
2619 (cond
|
yuuji@60
|
2620 ((string-match "j" c)
|
yuuji@60
|
2621 (yahtml-lint-buffer (current-buffer)))
|
yuuji@60
|
2622 ((string-match "[bp]" c)
|
yuuji@58
|
2623 (yahtml-browse-current-file))
|
yuuji@58
|
2624 ((string-match "r" c)
|
yuuji@138
|
2625 (yahtml-browse-reload))
|
yuuji@138
|
2626 ((string-match "n" c)
|
yuuji@138
|
2627 (call-interactively 'yahtml-newpage)))))
|
yuuji@58
|
2628
|
yuuji@72
|
2629 (if (fboundp 'wrap-function-to-control-ime)
|
yuuji@72
|
2630 (wrap-function-to-control-ime 'yahtml-browse-menu t nil))
|
yuuji@72
|
2631
|
yuuji@60
|
2632 (defvar yahtml-lint-buffer "*weblint*")
|
yuuji@60
|
2633
|
yuuji@60
|
2634 (defun yahtml-lint-buffer (buf)
|
yuuji@60
|
2635 "Call lint on buffer BUF."
|
yuuji@64
|
2636 (require 'yatexprc)
|
yuuji@60
|
2637 (interactive "bCall lint on buffer: ")
|
yuuji@60
|
2638 (setq buf (get-buffer buf))
|
yuuji@60
|
2639 (YaTeX-save-buffers)
|
yuuji@145
|
2640 (let ((bcmd (YaTeX-get-builtin "lint")))
|
yuuji@145
|
2641 (and bcmd (setq bcmd (yahtml-untranslate-string bcmd)))
|
yuuji@145
|
2642 (YaTeX-typeset
|
yuuji@145
|
2643 (concat (or bcmd yahtml-lint-program)
|
yuuji@145
|
2644 " " (file-name-nondirectory (buffer-file-name buf)))
|
yuuji@145
|
2645 yahtml-lint-buffer "lint" "lint")))
|
yuuji@60
|
2646
|
yuuji@58
|
2647 (defun yahtml-file-to-url (file)
|
yuuji@58
|
2648 "Convert local unix file name to URL.
|
yuuji@58
|
2649 If no matches found in yahtml-path-url-alist, return raw file name."
|
yuuji@58
|
2650 (let ((list yahtml-path-url-alist) p url)
|
yuuji@58
|
2651 (if (file-directory-p file)
|
yuuji@58
|
2652 (setq file (expand-file-name yahtml-directory-index file))
|
yuuji@58
|
2653 (setq file (expand-file-name file)))
|
yuuji@60
|
2654 (if (string-match "^[A-Za-z]:/" file)
|
yuuji@60
|
2655 (progn
|
yuuji@64
|
2656 ;; (aset file 1 ?|) ;これは要らないらしい…
|
yuuji@60
|
2657 (setq file (concat "///" file))))
|
yuuji@58
|
2658 (while list
|
yuuji@58
|
2659 (if (string-match (concat "^" (regexp-quote (car (car list)))) file)
|
yuuji@58
|
2660 (setq url (cdr (car list))
|
yuuji@58
|
2661 file (substring file (match-end 0))
|
yuuji@58
|
2662 url (concat url file)
|
yuuji@58
|
2663 list nil))
|
yuuji@58
|
2664 (setq list (cdr list)))
|
yuuji@58
|
2665 (or url (concat "file:" file))))
|
yuuji@58
|
2666
|
yuuji@58
|
2667 (defun yahtml-url-to-path (file &optional basedir)
|
yuuji@58
|
2668 "Convert local URL name to unix file name."
|
yuuji@58
|
2669 (let ((list yahtml-path-url-alist) url realpath docroot
|
yuuji@58
|
2670 (dirsufp (string-match "/$" file)))
|
yuuji@58
|
2671 (setq basedir (or basedir
|
yuuji@58
|
2672 (file-name-directory
|
yuuji@58
|
2673 (expand-file-name default-directory))))
|
yuuji@58
|
2674 (cond
|
yuuji@58
|
2675 ((string-match "^/" file)
|
yuuji@58
|
2676 (while list
|
yuuji@59
|
2677 (if (file-directory-p (car (car list)))
|
yuuji@58
|
2678 (progn
|
yuuji@58
|
2679 (setq url (cdr (car list)))
|
yuuji@58
|
2680 (if (string-match "\\(http://[^/]*\\)/" url)
|
yuuji@58
|
2681 (setq docroot (substring url (match-end 1)))
|
yuuji@58
|
2682 (setq docroot url))
|
yuuji@64
|
2683 (cond
|
yuuji@64
|
2684 ((string-match (concat "^" (regexp-quote docroot)) file)
|
yuuji@64
|
2685 (setq realpath
|
yuuji@64
|
2686 (expand-file-name
|
yuuji@64
|
2687 (substring
|
yuuji@64
|
2688 file
|
yuuji@64
|
2689 (if (= (aref file (1- (match-end 0))) ?/)
|
yuuji@64
|
2690 (match-end 0) ; "/foo"
|
yuuji@64
|
2691 (min (1+ (match-end 0)) (length file)))) ; "/~foo"
|
yuuji@64
|
2692 (car (car list))))))
|
yuuji@58
|
2693 (if realpath
|
yuuji@58
|
2694 (progn (setq list nil)
|
yuuji@58
|
2695 (if (and dirsufp (not (string-match "/$" realpath)))
|
yuuji@58
|
2696 (setq realpath (concat realpath "/")))))))
|
yuuji@58
|
2697 (setq list (cdr list)))
|
yuuji@58
|
2698 realpath)
|
yuuji@58
|
2699 (t file))))
|
yuuji@58
|
2700
|
yuuji@58
|
2701 (defun yahtml-browse-current-file ()
|
yuuji@58
|
2702 "Call WWW browser on current file."
|
yuuji@58
|
2703 (interactive)
|
yuuji@58
|
2704 (basic-save-buffer)
|
yuuji@58
|
2705 (yahtml-browse-html (yahtml-file-to-url (buffer-file-name))))
|
yuuji@58
|
2706
|
yuuji@58
|
2707 (defun yahtml-browse-reload ()
|
yuuji@115
|
2708 "Send `reload' event to netscape."
|
yuuji@58
|
2709 (let ((pb "* WWW Browser *") (cb (current-buffer)))
|
yuuji@58
|
2710 (cond
|
yuuji@58
|
2711 ((string-match "[Nn]etscape" yahtml-www-browser)
|
yuuji@58
|
2712 (if (get-buffer pb)
|
yuuji@58
|
2713 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
|
yuuji@58
|
2714 ;;(or (get 'yahtml-netscape-sentinel 'url)
|
yuuji@58
|
2715 ;; (error "Reload should be called after Browsing."))
|
yuuji@58
|
2716 (put 'yahtml-netscape-sentinel 'url
|
yuuji@58
|
2717 (yahtml-file-to-url (buffer-file-name)))
|
yuuji@58
|
2718 (basic-save-buffer)
|
yuuji@58
|
2719 (set-process-sentinel
|
yuuji@58
|
2720 (setq yahtml-browser-process
|
yuuji@58
|
2721 (start-process
|
yuuji@60
|
2722 "browser" pb shell-file-name yahtml-shell-command-option ;"-c"
|
yuuji@58
|
2723 (format "%s -remote 'reload'" yahtml-www-browser)))
|
yuuji@58
|
2724 'yahtml-netscape-sentinel))
|
yuuji@58
|
2725 (t
|
yuuji@58
|
2726 (message "Sorry, RELOAD is supported only for Netscape.")))))
|
yuuji@58
|
2727
|
yuuji@58
|
2728 ;;; ---------- Intelligent newline ----------
|
yuuji@58
|
2729 (defun yahtml-intelligent-newline (arg)
|
yuuji@58
|
2730 "Intelligent newline for HTML"
|
yuuji@58
|
2731 (interactive "P")
|
yuuji@60
|
2732 (let (env func)
|
yuuji@60
|
2733 (end-of-line)
|
yuuji@64
|
2734 (setq env (downcase (or (yahtml-inner-environment-but "^\\(a\\|p\\)\\b" t)
|
yuuji@64
|
2735 "html")))
|
yuuji@58
|
2736 (setq func (intern-soft (concat "yahtml-intelligent-newline-" env)))
|
yuuji@58
|
2737 (newline)
|
yuuji@58
|
2738 (if (and env func (fboundp func))
|
yuuji@64
|
2739 ;; if intelligent line function is defined, call that
|
yuuji@64
|
2740 (funcall func)
|
yuuji@64
|
2741 ;; else do the default action
|
yuuji@64
|
2742 (if (string-match yahtml-p-prefered-env-regexp env)
|
yuuji@64
|
2743 (yahtml-insert-p)))))
|
yuuji@58
|
2744
|
yuuji@58
|
2745 (defun yahtml-intelligent-newline-ul ()
|
yuuji@58
|
2746 (interactive)
|
yuuji@64
|
2747 (yahtml-insert-single "li")
|
yuuji@80
|
2748 (or yahtml-always-/li yahtml-faithful-to-htmllint (insert " "))
|
yuuji@58
|
2749 (yahtml-indent-line))
|
yuuji@58
|
2750
|
yuuji@58
|
2751 (fset 'yahtml-intelligent-newline-ol 'yahtml-intelligent-newline-ul)
|
yuuji@58
|
2752
|
yuuji@58
|
2753 (defun yahtml-intelligent-newline-dl ()
|
yuuji@58
|
2754 (interactive)
|
yuuji@58
|
2755 (let ((case-fold-search t))
|
yuuji@58
|
2756 (if (save-excursion
|
yuuji@73
|
2757 (re-search-backward "<\\(\\(dt\\)\\|\\(dd\\)\\)[ \t>]"
|
yuuji@58
|
2758 (get 'YaTeX-inner-environment 'point) t))
|
yuuji@58
|
2759 (cond
|
yuuji@58
|
2760 ((match-beginning 2)
|
yuuji@64
|
2761 (yahtml-insert-single "dd")
|
yuuji@80
|
2762 (or yahtml-always-/dd yahtml-faithful-to-htmllint (insert " "))
|
yuuji@58
|
2763 (setq yahtml-last-single-cmd "dt"))
|
yuuji@58
|
2764 ((match-beginning 3)
|
yuuji@64
|
2765 (yahtml-insert-single "dt")
|
yuuji@80
|
2766 (or yahtml-always-/dt yahtml-faithful-to-htmllint (insert " "))
|
yuuji@58
|
2767 (setq yahtml-last-single-cmd "dd")))
|
yuuji@121
|
2768 (yahtml-insert-single "dt")
|
yuuji@121
|
2769 (or yahtml-always-/li yahtml-faithful-to-htmllint (insert " "))
|
yuuji@64
|
2770 (setq yahtml-last-single-cmd "dd"))
|
yuuji@64
|
2771 (yahtml-indent-line)
|
yuuji@64
|
2772 (and (string-match yahtml-p-prefered-env-regexp "dl")
|
yuuji@64
|
2773 (string-equal yahtml-last-single-cmd "dt")
|
yuuji@64
|
2774 (yahtml-insert-p nil))))
|
yuuji@58
|
2775
|
yuuji@59
|
2776 (defun yahtml-intelligent-newline-select ()
|
yuuji@59
|
2777 (interactive)
|
yuuji@59
|
2778 (insert "<" (if yahtml-prefer-upcases "OPTION" "option") "> ")
|
yuuji@59
|
2779 (yahtml-indent-line))
|
yuuji@59
|
2780
|
yuuji@70
|
2781 (defun yahtml-intelligent-newline-style ()
|
yuuji@70
|
2782 (interactive)
|
yuuji@70
|
2783 (if (save-excursion
|
yuuji@70
|
2784 (and
|
yuuji@70
|
2785 (re-search-backward "<style\\|<!-- " nil t)
|
yuuji@70
|
2786 (looking-at "<style")))
|
yuuji@70
|
2787 (let (c)
|
yuuji@70
|
2788 (yahtml-indent-line)
|
yuuji@70
|
2789 (setq c (current-column))
|
yuuji@70
|
2790 (insert "<!--\n")
|
yuuji@70
|
2791 (YaTeX-reindent c)
|
yuuji@70
|
2792 (insert "-->")
|
yuuji@70
|
2793 (beginning-of-line)
|
yuuji@70
|
2794 (open-line 1)
|
yuuji@70
|
2795 (YaTeX-reindent c))))
|
yuuji@70
|
2796
|
yuuji@80
|
2797 (defun yahtml-intelligent-newline-head ()
|
yuuji@80
|
2798 (let ((title (read-string "Document title: "))
|
yuuji@80
|
2799 (b "<title>") (e "</title>") p)
|
yuuji@80
|
2800 (yahtml-indent-line)
|
yuuji@80
|
2801 (insert (format "%s" (if yahtml-prefer-upcases (upcase b) b)))
|
yuuji@80
|
2802 (setq p (point))
|
yuuji@80
|
2803 (insert (format "%s%s" title (if yahtml-prefer-upcases (upcase e) e)))
|
yuuji@80
|
2804 (if (string= "" title) (goto-char p))
|
yuuji@80
|
2805 (setq yahtml-last-begend "body")))
|
yuuji@80
|
2806
|
yuuji@80
|
2807 (defun yahtml-intelligent-newline-script ()
|
yuuji@80
|
2808 (let ((p (point)) b)
|
yuuji@80
|
2809 (if (save-excursion
|
yuuji@80
|
2810 (and
|
yuuji@80
|
2811 (setq b (re-search-backward "<script\\>" nil t))
|
yuuji@80
|
2812 (re-search-forward
|
yuuji@80
|
2813 "\\(javascript\\)\\|\\(tcl\\)\\|\\(vbscript\\)" p t)))
|
yuuji@80
|
2814 (let ((js (match-end 1)) (tcl (match-end 2)) (vb (match-end 3))
|
yuuji@80
|
2815 c (srcp (re-search-backward "src=" b t)))
|
yuuji@80
|
2816 (goto-char p)
|
yuuji@80
|
2817 (yahtml-indent-line)
|
yuuji@80
|
2818 (setq c (current-column))
|
yuuji@80
|
2819 (if srcp
|
yuuji@80
|
2820 nil
|
yuuji@80
|
2821 (insert "<!--\n" (cond (js "//") (tcl "#") (vb "'")) " -->")
|
yuuji@80
|
2822 (beginning-of-line)
|
yuuji@80
|
2823 (open-line 1)
|
yuuji@80
|
2824 (YaTeX-reindent c))))))
|
yuuji@80
|
2825
|
yuuji@86
|
2826 (defun yahtml-intelligent-newline-table ()
|
yuuji@86
|
2827 (let ((cp (point)) (p (point)) tb rb (cols 0) th line (i 0) fmt
|
yuuji@86
|
2828 (ptn "\\(<t[dh]\\>\\)\\|<t\\(r\\|head\\|body\\)\\>"))
|
yuuji@86
|
2829 (cond
|
yuuji@86
|
2830 ((save-excursion (setq tb (YaTeX-beginning-of-environment "table")))
|
yuuji@86
|
2831 (while (and (setq rb (re-search-backward ptn tb t))
|
yuuji@86
|
2832 (match-beginning 1))
|
yuuji@86
|
2833 (setq th (looking-at "<th")) ;Remember if first-child is tr or not
|
yuuji@86
|
2834 (goto-char (match-end 0))
|
yuuji@86
|
2835 (skip-chars-forward " \t\n")
|
yuuji@86
|
2836 (if (and (search-forward "colspan\\s *=" p t)
|
yuuji@86
|
2837 (progn
|
yuuji@86
|
2838 (skip-chars-forward "\"' \t\n")
|
yuuji@86
|
2839 (looking-at "[0-9]+")))
|
yuuji@86
|
2840 (setq cols (+ (string-to-int (YaTeX-match-string 0)) cols))
|
yuuji@86
|
2841 (setq cols (1+ cols)))
|
yuuji@86
|
2842 (goto-char rb)
|
yuuji@86
|
2843 (setq p (point)))
|
yuuji@86
|
2844 (if (> cols 0)
|
yuuji@86
|
2845 (message "%s columns found. %s"
|
yuuji@86
|
2846 cols (if YaTeX-japan "新しいtr(N)? 前のtrの複写?(D)?: "
|
yuuji@86
|
2847 "New tr?(N) or Duplicate")))
|
yuuji@86
|
2848 (cond
|
yuuji@86
|
2849 ((and (> cols 0)
|
yuuji@86
|
2850 (memq (read-char) '(?d ?D))) ;Duplication mode
|
yuuji@135
|
2851 (setq line (YaTeX-buffer-substring (point) (1- cp))))
|
yuuji@86
|
2852 (t ;empty cells
|
yuuji@86
|
2853 (setq line "<tr>" i 0)
|
yuuji@86
|
2854 (if (> cols 0)
|
yuuji@86
|
2855 (while (> cols i)
|
yuuji@86
|
2856 (setq line (concat line (if (and (= i 0) th) "<th></th>"
|
yuuji@86
|
2857 "<td></td>"))
|
yuuji@86
|
2858 th nil i (1+ i)))
|
yuuji@86
|
2859 (setq fmt (read-string "`th' or `td' format: " "th td td"))
|
yuuji@86
|
2860 (while (string-match "t\\(h\\)\\|td" fmt i)
|
yuuji@86
|
2861 (setq line (concat line (if (match-beginning 1) "<th></th>"
|
yuuji@86
|
2862 "<td></td>"))
|
yuuji@86
|
2863 i (match-end 0))))
|
yuuji@86
|
2864 (setq line (concat line "</tr>"))))
|
yuuji@86
|
2865 (goto-char cp)
|
yuuji@86
|
2866 (if th
|
yuuji@86
|
2867 (message
|
yuuji@86
|
2868 "Type `%s' to change td from/to th."
|
yuuji@86
|
2869 (key-description (car (where-is-internal 'yahtml-change-*)))))
|
yuuji@86
|
2870 (if (string< "" line)
|
yuuji@86
|
2871 (progn
|
yuuji@86
|
2872 (insert line)
|
yuuji@86
|
2873 (goto-char (+ 8 cp))
|
yuuji@86
|
2874 (yahtml-indent-line)))))))
|
yuuji@86
|
2875
|
yuuji@58
|
2876 ;;; ---------- Marking ----------
|
yuuji@58
|
2877 (defun yahtml-mark-begend ()
|
yuuji@58
|
2878 "Mark current tag"
|
yuuji@58
|
2879 (interactive)
|
yuuji@58
|
2880 (YaTeX-beginning-of-environment)
|
yuuji@58
|
2881 (let ((p (point)))
|
yuuji@58
|
2882 (save-excursion
|
yuuji@58
|
2883 (skip-chars-backward " \t" (point-beginning-of-line))
|
yuuji@58
|
2884 (if (bolp) (setq p (point))))
|
yuuji@58
|
2885 (push-mark p t))
|
yuuji@58
|
2886 (yahtml-goto-corresponding-begend)
|
yuuji@58
|
2887 (forward-list 1)
|
yuuji@58
|
2888 (if (eolp) (forward-char 1)))
|
yuuji@58
|
2889
|
yuuji@59
|
2890 ;;; ---------- complete marks ----------
|
yuuji@59
|
2891 (defun yahtml-complete-mark ()
|
yuuji@60
|
2892 "Complete >, <, &ersand, and "e."
|
yuuji@59
|
2893 (interactive)
|
yuuji@69
|
2894 (message "1:< 2:> 3:& 4:\" 5:' 6:nbsp")
|
yuuji@59
|
2895 (let ((c (read-char)))
|
yuuji@69
|
2896 (setq c (if (or (< c ?0) (> c ?7))
|
yuuji@59
|
2897 (string-match (regexp-quote (char-to-string c)) "<>&\"")
|
yuuji@59
|
2898 (- c ?1)))
|
yuuji@69
|
2899 (if (or (< c 0) (> c 6))
|
yuuji@59
|
2900 nil
|
yuuji@69
|
2901 (insert (format "&%s;"
|
yuuji@69
|
2902 (nth c '("lt" "gt" "amp" "quot" "apos" "nbsp")))))))
|
yuuji@59
|
2903
|
yuuji@59
|
2904
|
yuuji@60
|
2905 ;;; ---------- jump to error line ----------
|
yuuji@60
|
2906 (defun yahtml-prev-error ()
|
yuuji@60
|
2907 "Jump to previous error seeing lint buffer."
|
yuuji@60
|
2908 (interactive)
|
yuuji@60
|
2909 (or (get-buffer yahtml-lint-buffer)
|
yuuji@60
|
2910 (error "No lint program ran."))
|
yuuji@60
|
2911 (YaTeX-showup-buffer yahtml-lint-buffer nil t)
|
yuuji@64
|
2912 (yahtml-jump-to-error-line t))
|
yuuji@60
|
2913
|
yuuji@64
|
2914 (defun yahtml-jump-to-error-line (&optional sit)
|
yuuji@64
|
2915 (interactive "P")
|
yuuji@60
|
2916 (let ((p (point)) (e (point-end-of-line)))
|
yuuji@60
|
2917 (end-of-line)
|
yuuji@60
|
2918 (if (re-search-backward yahtml-error-line-regexp nil t)
|
yuuji@72
|
2919 (let ((f (if (string= "" (YaTeX-match-string 1))
|
yuuji@72
|
2920 YaTeX-current-file-name
|
yuuji@72
|
2921 (YaTeX-match-string 1)))
|
yuuji@72
|
2922 (l (string-to-int (or (YaTeX-match-string 2)
|
yuuji@72
|
2923 (YaTeX-match-string 3)))))
|
yuuji@64
|
2924 (if sit (sit-for 1))
|
yuuji@60
|
2925 (forward-line -1)
|
yuuji@64
|
2926 (YaTeX-showup-buffer (YaTeX-switch-to-buffer f t) nil t)
|
yuuji@60
|
2927 (goto-line l))
|
yuuji@60
|
2928 (message "No line number usage"))))
|
yuuji@69
|
2929
|
yuuji@69
|
2930 ;;; ---------- Style Sheet Support ----------
|
yuuji@69
|
2931 (defvar yahtml-css-class-alist nil
|
yuuji@69
|
2932 "Alist of elements vs. their classes")
|
yuuji@69
|
2933
|
yuuji@69
|
2934 (defun yahtml-css-collect-classes-region (beg end &optional initial)
|
yuuji@70
|
2935 (save-excursion
|
yuuji@70
|
2936 (save-restriction
|
yuuji@69
|
2937 (narrow-to-region beg end)
|
yuuji@69
|
2938 (goto-char (point-min))
|
yuuji@70
|
2939 (let ((alist initial) b e element class a)
|
yuuji@69
|
2940 (setq b (point))
|
yuuji@80
|
2941 (while (re-search-forward "\\({\\)\\|\\(@import\\)" nil t)
|
yuuji@80
|
2942 (if (match-beginning 2)
|
yuuji@80
|
2943 (let ((f (YaTeX-buffer-substring
|
yuuji@80
|
2944 (progn (skip-chars-forward "^\"")(1+ (point)))
|
yuuji@80
|
2945 (progn (forward-char 1)
|
yuuji@80
|
2946 (skip-chars-forward "^\"")(point)))))
|
yuuji@80
|
2947 (if (file-exists-p f)
|
yuuji@80
|
2948 (setq alist
|
yuuji@286
|
2949 (append alist (yahtml-css-collect-classes-file
|
yuuji@286
|
2950 f initial)))))
|
yuuji@80
|
2951 (setq e (point))
|
yuuji@80
|
2952 (goto-char b)
|
yuuji@80
|
2953 (while (re-search-forward ;ちょといい加減なREGEXP
|
yuuji@86
|
2954 "\\([a-z*][-a-z0-9]*\\)?\\.\\([-a-z0-9][-a-z0-9]*\\)\\>"
|
yuuji@80
|
2955 e t)
|
yuuji@80
|
2956 (setq element (YaTeX-match-string 1)
|
yuuji@80
|
2957 class (YaTeX-match-string 2))
|
yuuji@80
|
2958 ;;if starts with period (match-string 1 is nil),
|
yuuji@80
|
2959 ;;this is global class
|
yuuji@86
|
2960 (setq element (downcase (or element "*")))
|
yuuji@80
|
2961 (if (setq a (assoc element alist))
|
yuuji@80
|
2962 (or (assoc class (cdr a))
|
yuuji@80
|
2963 (setcdr a (cons (list class) (cdr a))))
|
yuuji@80
|
2964 (setq alist (cons (list element (list class)) alist))))
|
yuuji@80
|
2965 (goto-char (1- e))
|
yuuji@199
|
2966 (search-forward "}" nil 1) ;1=move to limit when not found.
|
yuuji@80
|
2967 (setq b (point))))
|
yuuji@70
|
2968 alist))))
|
yuuji@69
|
2969
|
yuuji@69
|
2970 (defun yahtml-css-collect-classes-buffer (&optional initial)
|
yuuji@69
|
2971 (interactive)
|
yuuji@69
|
2972 (yahtml-css-collect-classes-region (point-min) (point-max) initial))
|
yuuji@69
|
2973
|
yuuji@69
|
2974 (defun yahtml-css-collect-classes-file (file &optional initial)
|
yuuji@70
|
2975 (let*((hilit-auto-highlight nil)
|
yuuji@86
|
2976 (buf (get-buffer-create
|
yuuji@86
|
2977 (format " *css-collection*%s" (file-name-nondirectory file))))
|
yuuji@86
|
2978 (cb (current-buffer)))
|
yuuji@86
|
2979 (unwind-protect
|
yuuji@86
|
2980 (progn
|
yuuji@86
|
2981 (set-buffer buf)
|
yuuji@86
|
2982 (insert-file-contents file)
|
yuuji@86
|
2983 (cd (or (file-name-directory file) "."))
|
yuuji@86
|
2984 (yahtml-css-collect-classes-buffer initial))
|
yuuji@86
|
2985 (if (eq buf cb)
|
yuuji@86
|
2986 nil
|
yuuji@86
|
2987 (kill-buffer buf)
|
yuuji@86
|
2988 (set-buffer cb)))))
|
yuuji@69
|
2989
|
yuuji@69
|
2990 (defun yahtml-css-scan-styles ()
|
yuuji@69
|
2991 (save-excursion
|
yuuji@69
|
2992 (goto-char (point-min))
|
yuuji@69
|
2993 (set (make-local-variable 'yahtml-css-class-alist) nil)
|
yuuji@72
|
2994 (let (b tag type e href alist)
|
yuuji@72
|
2995 (while (re-search-forward "<\\(style\\|link\\)" nil t)
|
yuuji@72
|
2996 (setq b (match-beginning 0)
|
yuuji@72
|
2997 tag (YaTeX-match-string 1))
|
yuuji@69
|
2998 (cond
|
yuuji@69
|
2999 ((string-match "style" tag)
|
yuuji@69
|
3000 (goto-char b)
|
yuuji@69
|
3001 (save-excursion (forward-list 1) (setq e (point)))
|
yuuji@69
|
3002 (cond
|
yuuji@69
|
3003 ((search-forward "text/css" e 1) ;css definition starts
|
yuuji@69
|
3004 (setq alist
|
yuuji@69
|
3005 (yahtml-css-collect-classes-region
|
yuuji@69
|
3006 (point) (progn (search-forward "</style>") (point))
|
yuuji@69
|
3007 alist)))))
|
yuuji@69
|
3008 ((and (string-match "link" tag)
|
yuuji@72
|
3009 (stringp (setq type (yahtml-get-attrvalue "type")))
|
yuuji@72
|
3010 (string-match "text/css" type)
|
yuuji@69
|
3011 (setq href (yahtml-get-attrvalue "href"))
|
yuuji@69
|
3012 (file-exists-p (yahtml-url-to-path href)))
|
yuuji@69
|
3013 (setq alist
|
yuuji@69
|
3014 (yahtml-css-collect-classes-file
|
yuuji@69
|
3015 (yahtml-url-to-path href) alist))))
|
yuuji@69
|
3016 (setq yahtml-css-class-alist alist)))))
|
yuuji@69
|
3017
|
yuuji@70
|
3018 (defun yahtml-css-get-element-completion-alist (element)
|
yuuji@73
|
3019 (let ((alist (cdr-safe (assoc (downcase element) yahtml-css-class-alist)))
|
yuuji@86
|
3020 (global (cdr-safe (assoc "*" yahtml-css-class-alist))))
|
yuuji@70
|
3021 (and (or alist global)
|
yuuji@70
|
3022 (append alist global))))
|
yuuji@70
|
3023
|
yuuji@57
|
3024 ;;; ---------- ----------
|
yuuji@57
|
3025
|
yuuji@57
|
3026 ;;;
|
yuuji@57
|
3027 ;;hilit19
|
yuuji@57
|
3028 ;;;
|
yuuji@57
|
3029 (defvar yahtml-default-face-table
|
yuuji@57
|
3030 '(
|
yuuji@57
|
3031 (form black/ivory white/hex-442233 italic)
|
yuuji@57
|
3032 ))
|
yuuji@57
|
3033 (defvar yahtml-hilit-patterns-alist
|
yuuji@57
|
3034 '(
|
yuuji@70
|
3035 'case-fold
|
yuuji@57
|
3036 ;; comments
|
yuuji@57
|
3037 ("<!--\\s " "-->" comment)
|
yuuji@57
|
3038 ;; include&exec
|
yuuji@69
|
3039 ("<!--#\\(include\\|exec\\|config\\|fsize\\|flastmod\\)" "-->" include)
|
yuuji@57
|
3040 ;; string
|
yuuji@68
|
3041 (hilit-string-find ?\\ string)
|
yuuji@80
|
3042 (yahtml-hilit-region-tag "<\\(strong\\|b\\)\\>" bold)
|
yuuji@57
|
3043 ("</?[uod]l>" 0 decl)
|
yuuji@57
|
3044 ("<\\(di\\|dt\\|li\\|dd\\)>" 0 label)
|
yuuji@80
|
3045 (yahtml-hilit-region-tag "<\\(em\\|i\\>\\)" italic)
|
yuuji@72
|
3046 ;("<a\\s +href" "</a>" crossref) ;good for hilit19, but odd for font-lock..
|
yuuji@72
|
3047 (yahtml-hilit-region-tag "<\\(a\\)\\s +href" crossref)
|
yuuji@64
|
3048 (yahtml-hilit-region-tag-itself "</?\\sw+\\>" decl)
|
yuuji@57
|
3049 ))
|
yuuji@57
|
3050
|
yuuji@57
|
3051 (defun yahtml-hilit-region-tag (tag)
|
yuuji@57
|
3052 "Return list of start/end point of <TAG> form."
|
yuuji@72
|
3053 (if (re-search-forward tag nil t)
|
yuuji@72
|
3054 (let ((m0 (match-beginning 0)) (e0 (match-end 0))
|
yuuji@72
|
3055 (elm (YaTeX-match-string 1)))
|
yuuji@72
|
3056 (skip-chars-forward "^>")
|
yuuji@72
|
3057 (prog1
|
yuuji@72
|
3058 (cons (1+ (point))
|
yuuji@72
|
3059 (progn (re-search-forward (concat "</" elm ">") nil t)
|
yuuji@72
|
3060 (match-beginning 0)))
|
yuuji@72
|
3061 (goto-char e0)))))
|
yuuji@57
|
3062
|
yuuji@64
|
3063 (defun yahtml-hilit-region-tag-itself (ptn)
|
yuuji@64
|
3064 "Return list of start/end point of <tag options...> itself."
|
yuuji@64
|
3065 (if (re-search-forward ptn nil t)
|
yuuji@73
|
3066 (let ((m0 (match-beginning 0)) (e0 (match-end 0)))
|
yuuji@73
|
3067 (skip-chars-forward "^<>")
|
yuuji@73
|
3068 (if (eq (char-after (point)) ?<) nil
|
yuuji@73
|
3069 (prog1
|
yuuji@73
|
3070 (cons m0 (min (point-max) (1+ (point))))
|
yuuji@73
|
3071 (goto-char e0))))))
|
yuuji@64
|
3072
|
yuuji@57
|
3073 ;(setq hilit-patterns-alist (delq (assq 'yahtml-mode hilit-patterns-alist) hilit-patterns-alist))
|
yuuji@70
|
3074 (and yahtml-use-hilit19
|
yuuji@64
|
3075 (or (assq 'yahtml-mode hilit-patterns-alist)
|
yuuji@64
|
3076 (setq hilit-patterns-alist
|
yuuji@64
|
3077 (cons (cons 'yahtml-mode yahtml-hilit-patterns-alist)
|
yuuji@64
|
3078 hilit-patterns-alist))))
|
yuuji@72
|
3079 ;;;
|
yuuji@72
|
3080 ;; for font-lock
|
yuuji@72
|
3081 ;;;
|
yuuji@72
|
3082
|
yuuji@72
|
3083 ; <<STATIC KEYWORDS BELOW NOT USED>>
|
yuuji@72
|
3084 ;(defvar yahtml-font-lock-keywords
|
yuuji@72
|
3085 ; '(
|
yuuji@72
|
3086 ; ;; comments
|
yuuji@72
|
3087 ; ("<!--\\s .* -->" . font-lock-comment-face)
|
yuuji@72
|
3088 ; ;; include&exec
|
yuuji@72
|
3089 ; ("<!--#\\(include\\|exec\\|config\\|fsize\\|flastmod\\).*-->"
|
yuuji@72
|
3090 ; 0 font-lock-include-face keep)
|
yuuji@72
|
3091 ; ;; string
|
yuuji@72
|
3092 ; ;(hilit-string-find ?\\ string)
|
yuuji@72
|
3093 ; ;(yahtml-hilit-region-tag "\\(em\\|strong\\)" bold)
|
yuuji@72
|
3094 ; ("</?[uod]l>" 0 font-lock-keyword-face)
|
yuuji@72
|
3095 ; ("<\\(di\\|dt\\|li\\|dd\\)>" 0 font-lock-label-face)
|
yuuji@72
|
3096 ; ("<a\\s +href=.*</a>" (0 font-lock-crossref-face keep))
|
yuuji@72
|
3097 ; ;(yahtml-hilit-region-tag-itself "</?\\sw+\\>" decl)
|
yuuji@72
|
3098 ; ("</?\\sw+\\>" (yahtml-fontify-to-tagend nil nil))
|
yuuji@72
|
3099 ; )
|
yuuji@72
|
3100 ; "*Defualt font-lock-keywords for yahtml-mode.")
|
yuuji@72
|
3101 (defvar yahtml-font-lock-keywords
|
yuuji@72
|
3102 (YaTeX-convert-pattern-hilit2fontlock yahtml-hilit-patterns-alist)
|
yuuji@72
|
3103 "Default fontifying patterns for yahtml-mode")
|
yuuji@72
|
3104
|
yuuji@72
|
3105 (defun yahtml-font-lock-set-default-keywords ()
|
yuuji@72
|
3106 (put 'yahtml-mode 'font-lock-defaults
|
yuuji@72
|
3107 '(yahtml-font-lock-keywords nil t)))
|
yuuji@72
|
3108
|
yuuji@72
|
3109 (if yahtml-use-font-lock
|
yuuji@72
|
3110 (progn
|
yuuji@72
|
3111 (if (and (boundp 'hilit-mode-enable-list) hilit-mode-enable-list)
|
yuuji@72
|
3112 ;;for those who use both hilit19 and font-lock
|
yuuji@72
|
3113 (if (eq (car hilit-mode-enable-list) 'not)
|
yuuji@72
|
3114 (or (member 'yahtml-mode hilit-mode-enable-list)
|
yuuji@72
|
3115 (nconc hilit-mode-enable-list (list 'yahtml-mode)))
|
yuuji@72
|
3116 (setq hilit-mode-enable-list
|
yuuji@72
|
3117 (delq 'yahtml-mode hilit-mode-enable-list))))
|
yuuji@72
|
3118 (yahtml-font-lock-set-default-keywords)))
|
yuuji@72
|
3119
|
yuuji@73
|
3120 (defun yahtml-font-lock-recenter (&optional arg)
|
yuuji@73
|
3121 (interactive "P")
|
yuuji@73
|
3122 (font-lock-mode -1) ;is stupid, but sure.
|
yuuji@73
|
3123 (font-lock-mode 1))
|
yuuji@73
|
3124
|
yuuji@68
|
3125 (run-hooks 'yahtml-load-hook)
|
yuuji@54
|
3126 (provide 'yahtml)
|
yuuji@54
|
3127
|
yuuji@54
|
3128 ; Local variables:
|
yuuji@54
|
3129 ; fill-prefix: ";;; "
|
yuuji@54
|
3130 ; paragraph-start: "^$\\|\\|;;;$"
|
yuuji@54
|
3131 ; paragraph-separate: "^$\\|\\|;;;$"
|
yuuji@80
|
3132 ; coding: sjis
|
yuuji@54
|
3133 ; End:
|