yatex

view yahtml.el @ 573:9e07513fc2ef

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