yatex

view yahtml.el @ 607:157aa7974191

Release preparation for 1.83
author HIROSE Yuuji <yuuji@gentei.org>
date Sun, 25 Dec 2022 14:12:18 +0900
parents 38a414d755c1
children e87c3271b8fd
line source
1 ;;; yahtml.el --- Yet Another HTML mode -*- coding: sjis -*-
2 ;;; (c) 1994-2022 by HIROSE Yuuji [yuuji(@)yatex.org]
3 ;;; $Id$
5 (defconst yahtml-revision-number "1.83"
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 ("header") ("footer") ("article") ("section") ("nav") ("main") ("aside")
450 ))
452 (if yahtml-html4-strict
453 (setq yahtml-env-table
454 (delete (assoc "center" yahtml-env-table) yahtml-env-table)))
456 ;(defvar yahtml-itemizing-regexp
457 ; "\\(ul\\|ol\\|dl\\)"
458 ; "Regexp of itemizing forms")
460 (defvar yahtml-user-env-table nil)
461 (defvar yahtml-tmp-env-table nil)
463 ;;; Completion tables for typeface designator
464 (and yahtml-always-/p
465 (or (assoc "p" yahtml-env-table)
466 (setq yahtml-env-table (cons '("p") yahtml-env-table))))
467 (and yahtml-always-/li
468 (or (assoc "li" yahtml-env-table)
469 (setq yahtml-env-table (cons '("li") yahtml-env-table))))
470 (and yahtml-always-/dt
471 (or (assoc "dt" yahtml-env-table)
472 (setq yahtml-env-table (cons '("dt") yahtml-env-table))))
473 (and yahtml-always-/dd
474 (or (assoc "dd" yahtml-env-table)
475 (setq yahtml-env-table (cons '("dd") yahtml-env-table))))
477 (defvar yahtml-typeface-table
478 (append
479 '(("dfn") ("em") ("cite") ("code") ("kbd") ("samp") ("caption")
480 ("strong") ("var") ("b") ("i") ("tt") ("big") ("small")
481 ("sup") ("sub") ("span") ("abbr") ("label")
482 ;; HTML5
483 ("figcaption")
484 )
485 (if (not yahtml-html4-strict)
486 '(("strike") ("s") ("u") ("font")))
487 yahtml-env-table)
488 "Default completion table of typeface designator")
489 (defvar yahtml-user-typeface-table nil)
490 (defvar yahtml-tmp-typeface-table nil)
491 (defvar yahtml-last-typeface-cmd "a")
493 (defvar yahtml-single-cmd-table
494 '(("hr") ("br") ("option")
495 ("HorizontalRule" . "hr")
496 ("BreakLine" . "br")
497 ("exec" . "!--#exec")
498 ("!--#exec")
499 ("include" . "!--#include")
500 ("!--#include")
501 ;; ("Item" . "li")
502 ;; ("DefineTerm" . "dt")
503 ;; ("Description" . "dd")
504 ;; ("dd") ("dt") ("li")
505 )
506 "Default completion table of HTML single command.")
507 (defvar yahtml-user-single-cmd-table nil)
508 (defvar yahtml-tmp-single-cmd-table nil)
509 (defvar yahtml-last-single-cmd nil)
511 (defvar yahtml-current-completion-type nil
512 "Has current completion type. This may be used in yahtml addin functions.")
514 (defvar yahtml-struct-name-regexp
515 (concat
516 "\\<\\("
517 ;(mapconcat 'car yahtml-typeface-table "\\|")
518 (mapconcat 'car yahtml-env-table "\\|")
519 "\\)\\b")
520 "Regexp of structure beginning.")
522 (defvar yahtml-closable-regexp
523 (concat
524 "\\<\\("
525 (mapconcat 'car yahtml-typeface-table "\\|")
526 (mapconcat 'car yahtml-env-table "\\|")
527 "\\)\\b")
528 "Regexp of any closable elemnts.")
530 (defvar yahtml-indent-listing-constant t
531 "*Nil means indentation for listing obeys the column of `>'.
532 T for static indentation depth")
534 (or (assoc "p" yahtml-env-table)
535 (setq yahtml-env-table (cons '("p") yahtml-env-table)))
538 (defun yahtml-get-user-httpconf-entry (regexp)
539 (cond
540 ((and (eq yahtml-server-type 'apache) ;;check .htaccess
541 buffer-file-name)
542 (let ((dir default-directory)
543 charset af ext (ldir "")
544 line
545 (case-fold-search t)
546 (uid (car (cdr (cdr (file-attributes "."))))))
547 (if (string-match "^[A-Z]:" dir)
548 (setq dir (substring dir 2))) ;remove drive letter
549 (while (and dir
550 (not (string= dir ldir))
551 (equal uid (car (cdr (cdr (file-attributes dir))))))
552 (setq af (expand-file-name yahtml-apache-access-file dir))
553 (if (file-exists-p af)
554 (save-excursion
555 (set-buffer (find-file-noselect af))
556 (save-excursion
557 (goto-char (point-min))
558 (if (re-search-forward regexp nil t)
559 (setq line (buffer-substring
560 (point-beginning-of-line)
561 (point-end-of-line))
562 dir nil)))
563 (kill-buffer (current-buffer))))
564 (if dir
565 (setq ldir dir
566 dir (substring dir 0 (string-match "/$" dir))
567 dir (file-name-directory dir))))
568 line))
569 (t nil)))
571 (defun yahtml-dir-default-charset ()
572 (let*((fn (file-name-nondirectory (or buffer-file-name "")))
573 (ext (substring fn (or (string-match "\\.[a-z0-9]+$" fn) 0)))
574 (ptn (format "^\\s *AddType.*charset=\\(.*\\)\\%s\\>" ext))
575 (case-fold-search t)
576 line
577 charset)
578 (if (setq line (yahtml-get-user-httpconf-entry ptn))
579 (progn
580 (string-match ptn line)
581 (setq charset
582 (substring line (match-beginning 1) (match-end 1)))
583 (cond
584 ((string-match "iso-2022-jp" charset)
585 (setq charset 2))
586 ((string-match "euc-jp" charset)
587 (setq charset 3))
588 ((string-match "shift_jis" charset)
589 (setq charset 1))
590 ((string-match "utf-8" charset)
591 (setq charset 4))
592 (t (setq charset nil)))
593 (setq dir "")))
594 (if (featurep 'mule)
595 (setq charset (cdr (assq charset YaTeX-kanji-code-alist))))
596 charset))
598 (defun yahtml-get-directory-index ()
599 (let ((line (yahtml-get-user-httpconf-entry "^\\s *DirectoryIndex"))
600 x index-list)
601 ;;s/\\s *$//;
602 (if line
603 (progn
604 (if (string-match "DirectoryIndex\\s +\\(.*\\)\\s *$" line)
605 (setq line (substring line (match-beginning 1) (match-end 1))))
606 (while (string< "" line)
607 (if (setq x (string-match "\\(\\s +\\)" line))
608 (setq index-list (cons (substring line 0 x) index-list)
609 line (substring line (match-end 1)))
610 (setq index-list (cons line index-list)
611 line "")))
612 (or (nreverse index-list)
613 (if (listp yahtml-directory-index)
614 yahtml-directory-index
615 (list yahtml-directory-index)))))))
617 (defvar yahtml-mode-old-mode nil)
618 (defun yahtml-mode ()
619 (interactive)
620 (let ((old-mm major-mode)) ;Emacs21.0.95 resets major-mode
621 (kill-all-local-variables) ;with kill-all-local-variables
622 (if (not (eq 'yahtml-mode old-mm))
623 (set (make-local-variable 'yahtml-mode-old-mode) old-mm)))
624 (let ((coding (or (yahtml-dir-default-charset) yahtml-kanji-code)))
625 (cond
626 ((null coding) nil)
627 ((and YaTeX-emacs-20 (boundp 'buffer-file-coding-system))
628 (setq buffer-file-coding-system
629 (or (and (fboundp 'set-auto-coding) buffer-file-name
630 (save-excursion
631 (goto-char (point-min))
632 (set-auto-coding buffer-file-name (buffer-size))))
633 coding)))
634 ((featurep 'mule)
635 (set-file-coding-system coding))
636 ((boundp 'NEMACS)
637 (make-local-variable 'kanji-fileio-code)
638 (setq kanji-fileio-code coding))))
639 (setq major-mode 'yahtml-mode
640 mode-name "yahtml"
641 YaTeX-current-file-name (file-name-nondirectory
642 (or (buffer-file-name) ""))
643 local-abbrev-table yahtml-mode-abbrev-table)
644 (mapcar
645 (function (lambda (x)
646 (make-local-variable (car x))
647 (set (car x) (if (and (symbolp (cdr x))
648 (boundp (cdr x)))
649 (symbol-value (cdr x))
650 (cdr x)))))
651 '((YaTeX-ec . "")
652 (YaTeX-struct-begin . "<%1%2")
653 (YaTeX-struct-end . "</%1>")
654 (YaTeX-struct-name-regexp . yahtml-closable-regexp)
655 (YaTeX-comment-prefix . "<!--[^#]")
656 (YaTeX-coding-system . yahtml-kanji-code) ;necessary?
657 (YaTeX-typesetting-mode-map . yahtml-lint-buffer-map)
658 (fill-prefix . yahtml-fill-prefix) (fill-column . yahtml-fill-column)
659 (paragraph-start . yahtml-paragraph-start)
660 (paragraph-separate . yahtml-paragraph-separate)
661 (comment-start . "<!-- ") (comment-end . " -->")
662 (comment-start-skip . comment-start)
663 (indent-line-function . yahtml-indent-line)))
665 (if yahtml-use-font-lock
666 (progn
667 (yahtml-font-lock-set-default-keywords)
668 (or (featurep 'xemacs)
669 (progn
670 (set (make-local-variable 'font-lock-defaults)
671 '(yahtml-font-lock-keywords nil t))
672 ;;(font-lock-mode -1)
673 (font-lock-mode 1) ;;Why should I fontify again???
674 ;; in yatex-mode, there's no need to refontify...
675 (font-lock-fontify-buffer)))))
676 ;; +dnd for X11 w/ emacs23+
677 (and window-system (featurep 'dnd)
678 (set (make-local-variable 'dnd-protocol-alist)
679 (cons (cons "^\\(file\\|https?\\):" 'yahtml-dnd-handler)
680 dnd-protocol-alist)))
682 (set-syntax-table yahtml-syntax-table)
683 (use-local-map yahtml-mode-map)
684 (YaTeX-read-user-completion-table)
685 (yahtml-css-scan-styles)
686 ;(turn-on-auto-fill) ;Sorry, this is prerequisite
687 (and (= 0 (buffer-size)) (file-exists-p yahtml-template-file)
688 (y-or-n-p (format "Insert %s?" yahtml-template-file))
689 (insert-file-contents (expand-file-name yahtml-template-file)))
690 (if (fboundp 'electric-indent-local-mode)
691 (electric-indent-local-mode yahtml-electric-indent-mode))
692 (run-hooks 'text-mode-hook 'yahtml-mode-hook)
694 ;; This warning should be removed after a while(2000/12/2)
695 (let ((fld (or (and (local-variable-p 'font-lock-defaults (current-buffer))
696 font-lock-defaults)
697 (get 'yahtml-mode 'font-lock-defaults))))
698 (and fld (not (memq 'yahtml-font-lock-keywords fld))
699 (YaTeX-warning-font-lock "yahtml"))))
701 (defun yahtml-version ()
702 "Return string of the version of running yahtml."
703 (interactive)
704 (message
705 (concat "Yet Another HTML-mode "
706 (if YaTeX-japan "「HTML屋」" "`yahtml'")
707 " Revision "
708 yahtml-revision-number)))
710 (defun yahtml-quit ()
711 (interactive)
712 (and yahtml-mode-old-mode
713 (fboundp yahtml-mode-old-mode)
714 (funcall yahtml-mode-old-mode)))
716 (defun yahtml-define-menu (keymap bindlist)
717 (cond
718 ((featurep 'xemacs)
719 (let ((name (keymap-name (symbol-value keymap))))
720 (set keymap nil)
721 (mapcar
722 (function
723 (lambda (bind)
724 (setq bind (cdr bind))
725 (if (eq (car (cdr bind)) 'lambda)
726 (setcar (cdr bind) 'progn))
727 (if (stringp (car (cdr bind)))
728 (set keymap (cons (cdr bind) (symbol-value keymap)))
729 (set keymap (cons (vector (car bind) (cdr bind) t)
730 (symbol-value keymap))))))
731 bindlist)
732 (set keymap (cons name (symbol-value keymap)))))
733 (t
734 (mapcar
735 (function
736 (lambda (bind)
737 (define-key (symbol-value keymap) (vector (car bind)) (cdr bind))))
738 bindlist))))
740 (defvar yahtml-menu-map nil "Menu map of yahtml")
741 (defvar yahtml-menu-map-sectioning nil "Menu map of yahtml(sectioning)")
742 (defvar yahtml-menu-map-listing nil "Menu map of yahtml(listing)")
743 (defvar yahtml-menu-map-logical nil "Menu map of yahtml(logical tags)")
744 (defvar yahtml-menu-map-typeface nil "Menu map of yahtml(typeface tags)")
746 ;;; Variables for mosaic url history
747 (defvar yahtml-urls nil "Alist of global history")
748 (defvar yahtml-urls-private nil)
749 (defvar yahtml-urls-local nil)
751 (cond
752 ((and YaTeX-emacs-19 (null yahtml-menu-map))
753 (setq yahtml-menu-map (make-sparse-keymap "yahtml"))
754 (setq yahtml-menu-map-sectioning (make-sparse-keymap "sectioning menu"))
755 (YaTeX-define-menu
756 'yahtml-menu-map-sectioning
757 (nreverse
758 '((1 "H1" . (lambda () (interactive) (yahtml-insert-begend nil "H1")))
759 (2 "H2" . (lambda () (interactive) (yahtml-insert-begend nil "H2")))
760 (3 "H3" . (lambda () (interactive) (yahtml-insert-begend nil "H3")))
761 (4 "H4" . (lambda () (interactive) (yahtml-insert-begend nil "H4")))
762 (5 "H5" . (lambda () (interactive) (yahtml-insert-begend nil "H5")))
763 (6 "H6" . (lambda () (interactive) (yahtml-insert-begend nil "H6")))
764 )))
765 (setq yahtml-menu-map-logical (make-sparse-keymap "logical tags"))
766 (YaTeX-define-menu
767 'yahtml-menu-map-logical
768 (nreverse
769 '((em "Embolden" .
770 (lambda () (interactive) (yahtml-insert-tag nil "EM")))
771 (dfn "Define a word" .
772 (lambda () (interactive) (yahtml-insert-tag nil "DFN")))
773 (cite "Citation" .
774 (lambda () (interactive) (yahtml-insert-tag nil "CITE")))
775 (code "Code" .
776 (lambda () (interactive) (yahtml-insert-tag nil "CODE")))
777 (kbd "Keyboard" .
778 (lambda () (interactive) (yahtml-insert-tag nil "KBD")))
779 (samp "Sample display" .
780 (lambda () (interactive) (yahtml-insert-tag nil "SAMP")))
781 (strong "Strong" .
782 (lambda () (interactive) (yahtml-insert-tag nil "STRONG")))
783 (VAR "Variable notation" .
784 (lambda () (interactive) (yahtml-insert-tag nil "var"))))))
785 (setq yahtml-menu-map-typeface (make-sparse-keymap "typeface tags"))
786 (YaTeX-define-menu
787 'yahtml-menu-map-typeface
788 (nreverse
789 '((b "Bold" .
790 (lambda () (interactive) (yahtml-insert-tag nil "b")))
791 (i "Italic" .
792 (lambda () (interactive) (yahtml-insert-tag nil "i")))
793 (tt "Typewriter" .
794 (lambda () (interactive) (yahtml-insert-tag nil "tt")))
795 (u "Underlined" .
796 (lambda () (interactive) (yahtml-insert-tag nil "u"))))))
797 (setq yahtml-menu-map-listing (make-sparse-keymap "listing"))
798 (YaTeX-define-menu
799 'yahtml-menu-map-listing
800 (nreverse
801 '((ul "Unordered" .
802 (lambda () (interactive) (yahtml-insert-begend nil "ul")))
803 (ol "Ordered" .
804 (lambda () (interactive) (yahtml-insert-begend nil "ol")))
805 (dl "Definition" .
806 (lambda () (interactive) (yahtml-insert-begend nil "dl"))))))
807 (setq yahtml-menu-map-item (make-sparse-keymap "item"))
808 (YaTeX-define-menu
809 'yahtml-menu-map-item
810 (nreverse
811 '((li "Simple item" .
812 (lambda () (interactive) (yahtml-insert-single "li")))
813 (dt "Define term" .
814 (lambda () (interactive) (yahtml-insert-single "dt")))
815 (dd "Description of term" .
816 (lambda () (interactive) (yahtml-insert-single "dd"))))))
817 (define-key yahtml-mode-map [menu-bar yahtml]
818 (cons "yahtml" yahtml-menu-map))
819 (YaTeX-define-menu
820 'yahtml-menu-map
821 (nreverse
822 (list
823 (cons (list 'sect "Sectioning")
824 (cons "sectioning" yahtml-menu-map-sectioning))
825 (cons (list 'list "Listing")
826 (cons "Listing" yahtml-menu-map-listing))
827 (cons (list 'item "Item")
828 (cons "Itemizing" yahtml-menu-map-item));;;
829 (cons (list 'logi "Logical tags")
830 (cons "logical" yahtml-menu-map-logical))
831 (cons (list 'type "Typeface tags")
832 (cons "typeface" yahtml-menu-map-typeface)))))
833 (if (featurep 'xemacs)
834 (add-hook 'yahtml-mode-hook
835 (function
836 (lambda ()
837 (or (assoc "yahtml" current-menubar)
838 (progn
839 (set-buffer-menubar (copy-sequence current-menubar))
840 (add-submenu nil yahtml-menu-map)))))))))
842 ;;; ----------- Completion ----------
843 (defvar yahtml-last-begend "html")
844 (defun yahtml-insert-begend (&optional region env)
845 "Insert <cmd> ... </cmd>."
846 (interactive "P")
847 (setq yahtml-current-completion-type 'multiline
848 region (or region (YaTeX-region-active-p)))
849 (let*((completion-ignore-case t)
850 (cmd
851 (or env
852 (YaTeX-cplread-with-learning
853 (format "Environment(default %s): " yahtml-last-begend)
854 'yahtml-env-table 'yahtml-user-env-table 'yahtml-tmp-env-table)))
855 (bolp (save-excursion
856 (skip-chars-backward " \t" (point-beginning-of-line)) (bolp)))
857 (cc (current-column)))
858 (if (string< "" cmd) (setq yahtml-last-begend cmd))
859 (setq yahtml-last-begend
860 (or (cdr (assoc yahtml-last-begend yahtml-env-table))
861 yahtml-last-begend))
862 (setq cmd yahtml-last-begend)
863 (setq cmd (funcall (if yahtml-prefer-upcases 'upcase 'downcase) cmd))
864 (if region
865 ;; We want to keep region effective for new tagged environment
866 ;; to enable continuous regioning by another environment
867 (let ((beg (region-beginning))
868 (end (region-end))
869 (addin (yahtml-addin cmd)))
870 (save-excursion
871 (goto-char end)
872 (insert-before-markers (format "</%s>%s" cmd (if bolp "\n" "")))
873 (goto-char beg)
874 (insert (format "<%s%s>%s" cmd addin (if bolp "\n" "")))))
875 (insert (format "<%s%s>" cmd (yahtml-addin cmd)))
876 (save-excursion
877 (insert "\n")
878 (indent-to-column cc)
879 (insert (format "</%s>" cmd)))
880 (if (string-match "^[ap]$" cmd) ;aとp決め打ちってのが美しくない…
881 (newline)
882 (yahtml-intelligent-newline nil))
883 (yahtml-indent-line))))
885 (defun yahtml-insert-begend-region ()
886 "Call yahtml-insert-begend in the region mode."
887 (interactive)
888 (yahtml-insert-begend t))
891 (defun yahtml-insert-form (&optional form)
892 "Insert <FORM option=\"argument\">."
893 (interactive)
894 (setq yahtml-current-completion-type 'single)
895 (or form
896 (let ((completion-ignore-case t))
897 (setq form
898 (YaTeX-cplread-with-learning
899 (format "Form(default %s): " yahtml-last-form)
900 'yahtml-form-table 'yahtml-user-form-table
901 'yahtml-tmp-form-table))))
902 (let ((p (point)) q)
903 (if (string= form "") (setq form yahtml-last-form))
904 (setq yahtml-last-form form)
905 (if yahtml-prefer-upcases (setq form (upcase form)))
906 (insert (format "<%s%s>" form (yahtml-addin form)))
907 ;;(indent-relative-maybe)
908 (if (cdr (assoc form yahtml-form-table))
909 (save-excursion (insert (format "</%s>" form))))
910 (if (search-backward "\"\"" p t) (forward-char 1))))
912 (defun yahtml-read-css (alist &optional element)
913 (let ((completion-ignore-case t) (delim " ")
914 (minibuffer-completion-table alist)
915 (quotekey (substitute-command-keys "\\[quoted-insert]")))
916 (read-from-minibuffer-with-history
917 (if YaTeX-japan
918 (format "%sクラス(複数指定は%s SPCで区切る): "
919 (if element (concat element "の") "") quotekey)
920 (format "class%s(multiple class can be delimited by %s SPC): "
921 (if element (concat " for " element) "") quotekey))
922 nil YaTeX-minibuffer-completion-map nil)))
924 (defvar yahtml-newpage-command "newpage.rb"
925 "*Command name to create new HTML file referring to index.html.
926 This command should create new HTML file named argument 1 and
927 output string like `<a href=\"newfile.html\">anchor tag</a>'.
928 This program should take -o option to overwrite existing HTML file.")
929 (defun yahtml-newpage (file ov)
930 "Create newpage via newpage script"
931 (interactive
932 (list
933 (let (insert-default-directory)
934 (read-file-name "New webpage file name: " ""))
935 current-prefix-arg))
936 (if (and (file-exists-p file) (not ov))
937 (error "%s already exists. Call this with universal argument to force overwrite." file))
938 (insert (substring
939 (YaTeX-command-to-string
940 (concat yahtml-newpage-command " " (if ov "-o ") file))
941 0 -1)))
943 ;;; ---------- Add-in ----------
944 (defun yahtml-addin (form)
945 "Check add-in function's existence and call it if exists."
946 (let ((addin (concat "yahtml:" (downcase form))) s a)
947 (concat
948 (and (setq a (yahtml-css-get-element-completion-alist form))
949 (not (equal (YaTeX-last-key) ?\C-j))
950 (memq yahtml-current-completion-type '(multiline inline))
951 (not (string-match "#\\|source" form))
952 (yahtml-make-optional-argument ;should be made generic?
953 "class" (yahtml-read-css a form)))
954 (if (and (intern-soft addin) (fboundp (intern-soft addin))
955 (stringp (setq s (funcall (intern addin))))
956 (string< "" s))
957 (if (eq (aref s 0) ? ) s (concat " " s))
958 ""))))
960 (defvar yahtml-completing-buffer nil)
961 (defun yahtml-collect-labels (&optional file ptn withouthash)
962 "Collect current buffers label (<?? name=...>).
963 If optional argument FILE is specified collect labels in FILE."
964 (let ((attrptn (concat "\\(" (or ptn "name\\|id") "\\)\\s *="))
965 (hash (if withouthash "" "#"))
966 list end)
967 (save-excursion
968 (set-buffer (or yahtml-completing-buffer (current-buffer)))
969 (if file (let (hilit-auto-highlight)
970 (set-buffer (find-file-noselect file))))
971 (save-excursion
972 (goto-char (point-min))
973 (while ;(re-search-forward "<\\w+\\b" nil t)
974 (re-search-forward attrptn nil t)
975 ;(setq bound (match-end 0))
976 ;(search-forward ">" nil t)
977 (setq end (match-end 0))
978 (if (and ;(re-search-backward "\\(name\\|id\\)\\s *=" bound t)
979 (yahtml-on-assignment-p)
980 (progn
981 (goto-char end)
982 (skip-chars-forward " \t\n")
983 (looking-at "\"?#?\\([^\">]+\\)\"?\\b")))
984 (setq list (cons
985 (list (concat hash (YaTeX-match-string 1)))
986 list))))
987 list))))
989 (defun yahtml-collect-ids (&optional file)
990 (yahtml-collect-labels file "id" 'withouthash))
992 (defvar yahtml-url-completion-map nil "Key map used in URL completion buffer")
993 (if yahtml-url-completion-map nil
994 (setq yahtml-url-completion-map
995 (copy-keymap minibuffer-local-completion-map))
996 (define-key yahtml-url-completion-map "\t" 'yahtml-complete-url)
997 (define-key yahtml-url-completion-map " " 'yahtml-complete-url))
999 (defun yahtml-complete-url ()
1000 "Complete external URL from history or local file name."
1001 (interactive)
1002 (let ((p (point)) initial i2 cmpl path dir file listfunc beg labels
1003 (lim (YaTeX-minibuffer-begin))
1004 (min (if (fboundp 'field-beginning) (field-beginning) (point-min))))
1005 (setq initial (YaTeX-minibuffer-string))
1006 (cond
1007 ((string-match "^htt" initial)
1008 (setq cmpl (try-completion initial yahtml-urls)
1009 listfunc (list 'lambda nil
1010 (list 'all-completions initial 'yahtml-urls))
1011 beg min))
1012 ((setq beg (string-match "#" initial))
1013 (or (equal beg 0) ;begin with #
1014 (progn
1015 (setq path (substring initial 0 beg))
1016 (if (string-match "^/" path)
1017 (setq path (yahtml-url-to-path path)))))
1018 (setq initial (substring initial beg))
1019 (setq labels (yahtml-collect-labels path)
1020 cmpl (try-completion initial labels)
1021 listfunc (list 'lambda ()
1022 (list 'all-completions
1023 initial (list 'quote labels)))
1024 beg (+ min beg)))
1025 (t
1026 (setq path (if (string-match "^/" initial)
1027 (or (yahtml-url-to-path initial) initial)
1028 initial))
1029 (setq dir (or (file-name-directory path) ".")
1030 file (file-name-nondirectory path)
1031 initial file
1032 cmpl (file-name-completion file dir)
1033 listfunc (list 'lambda nil
1034 (list 'file-name-all-completions
1035 file dir))
1036 beg (save-excursion (skip-chars-backward "^/" lim) (point)))))
1037 (cond
1038 ((stringp cmpl)
1039 (if (string= initial cmpl)
1040 (with-output-to-temp-buffer "*Completions*"
1041 (princ "Possible completinos are:\n")
1042 (princ
1043 (mapconcat (function(lambda (x) x)) (funcall listfunc) "\n")))
1044 (delete-region (point) beg)
1045 (insert cmpl)))
1046 ((null cmpl)
1047 (ding))
1048 ((eq t cmpl)
1049 (save-excursion
1050 (unwind-protect
1051 (progn
1052 (goto-char p)
1053 (insert " [Sole completion]"))
1054 (delete-region p (point-max))))))))
1057 ; Subject: [yatex:02849] Re: [yahtml] tilda in href tag
1058 ; From: Masayasu Ishikawa <mimasa<at>sfc.keio.ac.jp>
1059 ; To: yatex<at>arcadia.jaist.ac.jp
1060 ; Date: Mon, 31 May 1999 21:09:31 +0900
1061 ; RFC 2396 の "2.4.3. Excluded US-ASCII Characters" によると、以下の文字
1062 ; は必ずエスケープしないといけません。
1064 ; control = <US-ASCII coded characters 00-1F and 7F hexadecimal>
1065 ; space = <US-ASCII coded character 20 hexadecimal>
1066 ; delims = "<" | ">" | "#" | "%" | <">
1067 ; unwise = "{" | "}" | "|" | "\" | "^" | "[" | "]" | "`"
1068 (defvar yahtml-unsafe-chars-regexp
1069 "[][\x0- \x7f <>%\"{}|\\^`]" ;#は除去する
1070 "Characters regexp which must be escaped in URI.")
1072 ; また、以下の文字は予約された用法以外に用いる場合にはエスケープしないと
1073 ; いけないことになっています。
1075 ; reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
1076 ; "$" | ","
1077 (defvar yahtml-unreserved-chars-regexp
1078 "[;/?:@&=+$,]"
1079 "Characters regexp which should be escaped in URI on certain conditions.
1080 Not used yet.")
1082 (defun yahtml-escape-chars-string (str)
1083 "Translate reserved chars to URL encoded string."
1084 (let ((p 0) (target "")
1085 (ask (eq yahtml-escape-chars 'ask)))
1086 (cond
1087 ((null yahtml-escape-chars) str)
1088 ((string-match "%[0-9A-F][0-9A-F]%[0-9A-F][0-9A-F]%[0-9A-F][0-9A-F]" str)
1089 str)
1090 (t
1091 (while (and (string< "" str)
1092 (setq p (string-match yahtml-unsafe-chars-regexp str)))
1093 (if (and ask (y-or-n-p (format "Escape char [%c] of `%s'"
1094 (aref str p) (substring str 0 (1+ p)))))
1095 (setq target (concat target
1096 (substring str 0 p)
1097 (format "%%%x" (aref str p))))
1098 (setq target (concat target (substring str 0 (1+ p)))))
1099 (setq str (substring str (1+ p))))
1100 (concat target str)))))
1102 (defun yahtml-unescape-string (str)
1103 "Untranslate reserved URL-encoded string."
1104 (let ((p 0) c (target "") (md (match-data)) (case-fold-search nil))
1105 (unwind-protect
1106 (progn
1107 (while (string-match "%\\([0-9a-f][0-9a-f]\\)" str p)
1108 (setq target (concat target
1109 (substring str p (1- (match-beginning 1))))
1110 p (match-end 0)
1111 c (YaTeX-hex (substring
1112 str (match-beginning 1) (match-end 1)))
1113 target (concat target (format "%c" c))))
1114 (concat target (substring str p)))
1115 (store-match-data md))))
1117 (defun yahtml-escape-chars-region (beg end)
1118 "Translate reserved chars to encoded string in the region."
1119 (interactive "r")
1120 (save-excursion
1121 (let ((e (set-marker (make-marker) end)) c m yes)
1122 (goto-char beg)
1123 (while (and (< (point) e)
1124 (re-search-forward
1125 (concat yahtml-unsafe-chars-regexp "\\|"
1126 yahtml-unreserved-chars-regexp) e t))
1127 (sit-for 0)
1128 ; (setq m (buffer-modified-p)
1129 ; c (char-after (1- (point))))
1130 ; (save-excursion (backward-char 1) (insert " ==>"))
1131 ; (unwind-protect
1132 ; (setq yes (y-or-n-p (format "Replace: [%c]" c)))
1133 ; (save-excursion
1134 ; (backward-char 1)
1135 ; (delete-backward-char 4))
1136 ; (set-buffer-modified-p m))
1137 (message "Replace: [%c] (y or n):" (setq c (char-after (1- (point)))))
1138 (if (memq (read-char) '(?y ?Y))
1139 (progn
1140 (delete-region (match-beginning 0) (match-end 0))
1141 (insert (format "%%%x" c)))))
1142 (set-marker e nil))))
1143 ;; ab%defgls/.|
1145 (defun yahtml-read-url (prompt)
1146 (let ((href ""))
1147 (setq yahtml-completing-buffer (current-buffer)
1148 yahtml-urls (append yahtml-urls-private yahtml-urls-local)
1149 href (yahtml-escape-chars-string
1150 (read-from-minibuffer-with-history
1151 prompt "" yahtml-url-completion-map)))
1152 (prog1
1153 href
1154 (if (and (string-match "^https?://" href)
1155 (null (assoc href yahtml-urls-private))
1156 (null (assoc href yahtml-urls-local)))
1157 (YaTeX-update-table
1158 (list href)
1159 'yahtml-urls-private 'yahtml-urls-private 'yahtml-urls-local)))))
1161 (defun yahtml:a ()
1162 "Add-in function for <a>"
1163 (let ((href (yahtml-read-url "href: ")))
1164 (concat (yahtml-make-optional-argument
1165 "href" href)
1166 (yahtml-make-optional-argument
1167 "name" (read-string-with-history "name: ")))))
1169 (defvar yahtml-parameters-completion-alist
1170 '(("align" ("top") ("middle") ("bottom") ("left") ("right") ("center"))
1171 ("clear" ("left") ("right") ("center") ("all") ("none"))
1172 ("lang" ("ja") ("en") ("kr") ("ch") ("fr"))
1173 ("src" . file) ("file" . file) ("poster" . file)
1174 ("background" . file)
1175 ("class file name" . file) ("data" . file)
1176 ("method" ("POST") ("GET"))
1177 ("rev" . yahtml-link-types-alist)
1178 ("rel" . yahtml-link-types-alist)
1179 ("type" . yahtml-content-types-alist)
1180 ("codetype" . yahtml-content-types-alist)
1181 ("http-equiv" ("Refresh") ("Content-Language") ("Content-Type"))
1182 ("charset"
1183 ("utf-8")("euc-jp")("iso-2022-jp")("iso-8859-1")("shift_jis"))))
1185 (defvar yahtml-link-types-alist
1186 '(("alternate") ("stylesheet") ("start") ("next") ("prev")
1187 ("contents") ("index") ("glossary") ("chapter") ("section")
1188 ("subsection") ("appendix") ("help") ("bookmark") ("manifest")))
1190 (defvar yahtml-content-types-alist
1191 '(("text/css") ("text/html") ("text/plain") ("text/richtext")
1192 ("text/sgml") ("text/xml")
1193 ("text/javascript") ("text/tcl") ("text/vbscript")
1194 ("application/octet-stream") ("application/postscript") ("application/pdf")
1195 ("application/java")
1196 ("image/jpeg") ("image/gif") ("image/tiff") ("image/png") ("video/mpeg"))
1197 "Alist of content-types")
1199 (defun yahtml-read-parameter (par &optional default alist predicate)
1200 (let* ((alist
1201 (cdr-safe (assoc (downcase par)
1202 (or alist yahtml-parameters-completion-alist))))
1203 (prompt (concat par ": "))
1204 v)
1205 (cond
1206 ((eq alist 'file)
1207 (let ((insert-default-directory))
1208 (read-file-name prompt "" default nil "" predicate)))
1209 ((eq alist 'command)
1210 (if (fboundp 'read-shell-command)
1211 (read-shell-command prompt)
1212 (read-string-with-history prompt)))
1213 ((and alist (symbolp alist))
1214 (completing-read-with-history
1215 prompt (symbol-value alist) nil nil default))
1216 (alist
1217 (completing-read-with-history prompt alist nil nil default))
1218 (t
1219 (read-string-with-history prompt default)))))
1221 (defun yahtml-read-file-name-regexp
1222 (prompt regexp &optional dir default-filename mustmatch initial)
1223 (let ((pred
1224 (function
1225 (lambda (f)
1226 (or (file-name-directory f)
1227 (string-match regexp f)))))
1228 (insert-default-directory nil))
1229 (read-file-name prompt dir default-filename mustmatch initial pred)))
1232 (defun yahtml-make-optional-argument (opt arg)
1233 "Make optional argument string."
1234 (if (or (null arg) (string= "" arg))
1235 ""
1236 (concat " "
1237 (if yahtml-prefer-upcase-attributes (upcase opt) (downcase opt))
1238 "=\"" arg "\"")))
1240 (defun yahtml:html ()
1241 "Add-in for <html>"
1242 (setq yahtml-last-begend "head" yahtml-last-typeface-cmd "head")
1243 (yahtml-make-optional-argument
1244 "lang" (yahtml-read-parameter "lang" (if YaTeX-japan "ja"))))
1246 (defun yahtml:head ()
1247 "Add-in for <head>"
1248 (setq yahtml-last-begend "title" yahtml-last-typeface-cmd "title")
1249 "")
1251 (defun yahtml:body ()
1252 "Add-in function for <body>"
1253 (cond
1254 (yahtml-html4-strict nil)
1255 (t
1256 (let ((b (read-string-with-history "bgcolor="))
1257 (bg (yahtml-read-parameter "background" ""))
1258 (x (read-string-with-history "text color="))
1259 (l (read-string-with-history "link color="))
1260 (v (read-string-with-history "vlink color=")))
1261 (concat
1262 (yahtml-make-optional-argument "bgcolor" b)
1263 (yahtml-make-optional-argument "background" bg)
1264 (yahtml-make-optional-argument "text" x)
1265 (yahtml-make-optional-argument "link" l)
1266 (yahtml-make-optional-argument "vlink" v))))))
1268 (defun yahtml-make-style-parameter (proplist)
1269 "Make CSS property definitions in style attribute."
1270 (mapconcat
1271 (function (lambda (x) (if (and (cdr x) (string< "" (cdr x)))
1272 (format "%s: %s;" (car x) (cdr x)))))
1273 (delq nil proplist)
1274 " "))
1276 (defun yahtml:img ()
1277 "Add-in function for <img>"
1278 (let ((src (yahtml-read-parameter "src"))
1279 (alg (if yahtml-html4-strict nil (yahtml-read-parameter "align")))
1280 alt
1281 (brd (read-string-with-history "border="))
1282 (l yahtml-prefer-upcase-attributes)
1283 info width height bytes comments)
1284 (and (stringp src) (string< "" src) (file-exists-p src)
1285 (setq info (yahtml-get-image-info src))
1286 (car info)
1287 (setq width (int-to-string (car info))
1288 height (int-to-string (car (cdr info)))
1289 bytes (car (cdr (cdr info)))
1290 comments (nth 4 info)))
1291 (if info
1292 (setq alt
1293 (YaTeX-replace-formats
1294 yahtml:img-default-alt-format
1295 (list (cons "x" width)
1296 (cons "y" height)
1297 (cons "s" (int-to-string bytes))
1298 (cons "f" (file-name-nondirectory src))
1299 (cons "c" (car comments))))))
1301 (setq alt (yahtml-read-parameter "alt" alt))
1302 (setq width (yahtml-read-parameter "width" width)
1303 height (yahtml-read-parameter "height" height))
1304 (concat (if l "SRC" "src") "=\"" src "\""
1305 (yahtml-make-optional-argument "alt" alt)
1306 (yahtml-make-optional-argument "width" width)
1307 (yahtml-make-optional-argument "height" height)
1308 (if yahtml-html4-strict
1309 (yahtml-make-optional-argument
1310 "style"
1311 (if (or brd alg)
1312 (yahtml-make-style-parameter
1313 (list
1314 (if (string< "" alg)
1315 (cons "align" alg))
1316 (if (string< "" brd)
1317 (cons "border"
1318 (format "%dpx" (YaTeX-str2int brd))))))))
1319 (concat
1320 (yahtml-make-optional-argument "border" brd)
1321 (yahtml-make-optional-argument "align" alg))))))
1323 (defun yahtml-file-truename (file)
1324 (cond
1325 ((fboundp 'file-truename) (file-truename (expand-file-name file)))
1326 (t (let ((new file))
1327 (while (and (stringp (setq new (nth 0 (file-attributes file))))
1328 (not (equal new file)))
1329 (setq file new))
1330 file))))
1332 (defun yahtml-hex-value (point length &optional little-endian)
1333 "Return the hex value the POINT positions LENGTH byte stream represents.
1334 Optional third argument LITTLE-ENDIAN is self extplanatory."
1335 (setq point (1+ point)) ;translate file offset to Emacs's point value
1336 (let ((mlt 1)
1337 (pos (if little-endian point (+ point length -1)))
1338 (direc (if little-endian 1 -1))
1339 (value 0))
1340 (while (> length 0)
1341 (setq value (+ value (* mlt (char-after pos)))
1342 pos (+ pos direc)
1343 mlt (* mlt 256)
1344 length (1- length)))
1345 value))
1347 (defun yahtml-get-image-info (file)
1348 "Return the information on the image file FILE.
1349 Returns list of '(WIDTH HEIGHT BYTES DEPTH COMMENTLIST)."
1350 (save-excursion
1351 (let*((tmpbuf (get-buffer-create " *imgheader*"))
1352 width height bytes depth comment
1353 (file-coding-system-alist (list (cons "." 'no-conversion))) ;20
1354 (file-coding-system-for-read (and (boundp '*noconv*) *noconv*)) ;19
1355 (coding-system-for-read 'no-conversion)
1356 (seekpoint 1)
1357 c1 c2 c3 c4 beg end
1358 (case-fold-search nil))
1359 (setq bytes (nth 7 (file-attributes (yahtml-file-truename file))))
1360 (set-buffer tmpbuf)
1361 (if (boundp 'mc-flag) (set (make-local-variable 'mc-flag) nil))
1362 (erase-buffer)
1363 (if (fboundp 'set-buffer-multibyte) (set-buffer-multibyte nil))
1364 (unwind-protect
1365 (progn
1366 (message "Inspecting image information of %s..." file)
1367 ;; Read 4bytes-more than inspection-bytes in case that
1368 ;; JPEG marker delimiter (4bytes) is on the alignment.
1369 (YaTeX-insert-file-contents
1370 file nil 0 (+ yahtml-image-inspection-bytes 4))
1371 (goto-char (point-min)) ;assertion
1372 (setq c1 (char-after 1) ;cache first 4 bytes
1373 c2 (char-after 2)
1374 c3 (char-after 3)
1375 c4 (char-after 4))
1376 (cond
1377 ((and (eq c1 ?\377) (eq c2 ?\330)) ; 0xff 0xd8
1378 ;;JPEG images need JPEG markers inspection
1379 ;;JPEG markers consist of [ 0xff ID(B) LEN(S) CONTENTS... ]
1380 ;; Warning: here seekpoint is measured by Emacs's point value
1381 ;; while yahtml-hex-vale requires file offset
1382 (setq seekpoint 3) ;where the first JPEG marker exists
1383 (catch 'exit
1384 (while (< seekpoint (- (buffer-size) 4))
1385 (cond
1386 ((not (eq (char-after seekpoint) ?\377))
1387 ;maybe corrupted, exit from loop
1388 (throw 'exit t))
1389 ((memq
1390 (char-after (1+ seekpoint))
1391 '(?\300 ?\301 ?\302 ?\303
1392 ?\305 ?\306 ?\307 ?\311 ?\312 ?\313 ?\315 ?\316 ?\317))
1393 ;;'(192 193 194 195 197 198 199 201 202 203 205 206 207
1394 ;;found!
1395 (setq height (yahtml-hex-value (+ seekpoint 4) 2)
1396 width (yahtml-hex-value (+ seekpoint 6) 2)
1397 depth (yahtml-hex-value (+ seekpoint 3) 1)))
1398 ((eq (char-after (1+ seekpoint)) ?\376) ;0xFE = comment
1399 ;; JPEG comment area
1400 (setq beg (+ seekpoint 2 2)
1401 end (+ seekpoint
1402 (yahtml-hex-value (1+ seekpoint) 2) 2))
1403 (setq comment (cons (buffer-substring beg end) comment)))
1404 (t ;other markers
1405 nil)) ;just skip it
1406 (setq seekpoint (+ seekpoint 2)
1407 seekpoint (+ seekpoint
1408 (yahtml-hex-value (1- seekpoint) 2))))))
1409 ((and (eq c1 ?\211) ;0x89
1410 (eq c2 ?P) (eq c3 ?N) (eq c4 ?G))
1411 ;;PNG Image data X=@0x10(L), Y=@0x14(L), D=@0x18(B)
1412 (setq width (yahtml-hex-value 16 4)
1413 height (yahtml-hex-value 20 4)
1414 depth (yahtml-hex-value 24 1)))
1415 ((looking-at "GIF8")
1416 ;;GIF Image data X=@0x6(leshort), Y=@0x8(leshort)
1417 (setq width (yahtml-hex-value 6 2 t)
1418 height (yahtml-hex-value 8 2 t)))
1419 ((looking-at "BM")
1420 ;;# OS/2, Windoze BMP files
1421 ;;@0x0e = 12 -> OS/2 1.x - X=@0x12(leshort), Y=@0x14(leshort)
1422 ;;@0x0e = 64 -> OS/2 2.x - X=@0x12(leshort), Y=@0x14(leshort)
1423 ;;@0x0e = 40 -> Windows 3.x - X=@0x12(lelong), Y=@0x16(lelong)
1424 (cond
1425 ((eq (yahtml-hex-value 14 2 t) 40)
1426 (setq width (yahtml-hex-value 18 4 t)
1427 height (yahtml-hex-value 22 4 t)))
1428 (t
1429 (setq width (yahtml-hex-value 18 2 t)
1430 height (yahtml-hex-value 20 2 t)))))))
1431 (message "")
1432 (kill-buffer tmpbuf))
1433 (list width height bytes depth (nreverse comment)))))
1435 (defun yahtml:form ()
1436 "Add-in function `form' input format"
1437 (concat
1438 " " (if yahtml-prefer-upcase-attributes "METHOD" "method") "=\""
1439 (completing-read-with-history "Method: " '(("POST") ("GET")) nil t)
1440 "\""
1441 (yahtml-make-optional-argument
1442 (if yahtml-prefer-upcase-attributes "ENCTYPE" "enctype")
1443 (completing-read-with-history
1444 "Enctype: "
1445 '(("application/x-www-form-urlencoded") ("multipart/form-data"))))
1446 " " (if yahtml-prefer-upcase-attributes "ACTION" "action") "=\""
1447 (read-string-with-history "Action: ") "\""))
1449 (defun yahtml:select ()
1450 "Add-in function for `select' input format"
1451 (setq yahtml-last-single-cmd "option" ;;<- it's old
1452 yahtml-last-typeface-cmd "option")
1453 (concat " " (if yahtml-prefer-upcase-attributes "NAME" "name") "=\""
1454 (read-string-with-history "name: ") "\""))
1455 (defun yahtml:label ()
1456 "Add-in function for `<label>'"
1457 (yahtml-make-optional-argument
1458 "for"
1459 (YaTeX-completing-read-or-skip "for=" (yahtml-collect-ids) nil t)))
1461 (defun yahtml:ol ()
1462 "Add-in function for <ol>"
1463 (setq yahtml-last-typeface-cmd "li")
1464 (let ((start (YaTeX-read-string-or-skip "start="))
1465 (type (YaTeX-completing-read-or-skip
1466 "type=" '(("1") ("a") ("A") ("i") ("I")) nil t)))
1467 (concat
1468 (yahtml-make-optional-argument "start" start)
1469 (yahtml-make-optional-argument "type" type))))
1470 (defun yahtml:ul ()
1471 (setq yahtml-last-typeface-cmd "li") "")
1472 (defun yahtml:dl ()
1473 (setq yahtml-last-typeface-cmd "dt") "")
1474 (defun yahtml:dt ()
1475 (setq yahtml-last-typeface-cmd "dd") "")
1477 (defun yahtml:p ()
1478 (if yahtml-html4-strict nil
1479 (let ((alg (yahtml-read-parameter "align")))
1480 (yahtml-make-optional-argument "align" alg))))
1482 (defvar yahtml-input-types
1483 '(("text") ("password") ("checkbox") ("radio") ("submit")
1484 ("reset") ("image") ("hidden") ("file")
1485 ("date") ("time") ("datetime-local") ("week") ("number") ("tel")
1486 ("range") ("color")))
1488 (defun yahtml:input ()
1489 "Add-in function for `input' form"
1490 (let ((size "") name type value id (maxlength "")
1491 (l yahtml-prefer-upcase-attributes))
1492 (setq name (read-string-with-history "name: ")
1493 type (YaTeX-completing-read-or-skip "type (default=text): "
1494 yahtml-input-types nil t)
1495 value (YaTeX-read-string-or-skip "value: "))
1496 (or (string-match "submit\\|reset" type)
1497 (setq id (YaTeX-read-string-or-skip "id: ")))
1498 (if (string-match "text\\|password\\|^$" type)
1499 (setq size (YaTeX-read-string-or-skip "size: ")
1500 maxlength (YaTeX-read-string-or-skip "maxlength: ")))
1501 (concat
1502 (if l "NAME" "name") "=\"" name "\""
1503 (yahtml-make-optional-argument "type" type)
1504 (yahtml-make-optional-argument "value" value)
1505 (yahtml-make-optional-argument "id" id)
1506 (yahtml-make-optional-argument "size" size)
1507 (if (string-match "range" type)
1508 (concat (yahtml-make-optional-argument
1509 "min" (YaTeX-read-string-or-skip "min: "))
1510 (yahtml-make-optional-argument
1511 "max" (YaTeX-read-string-or-skip "max: "))
1512 (yahtml-make-optional-argument
1513 "step" (YaTeX-read-string-or-skip "step: "))))
1514 (yahtml-make-optional-argument "maxlength" maxlength))))
1516 (defun yahtml:datalist ()
1517 "Add-in function for `datalist' form"
1518 (setq yahtml-last-typeface-cmd "option")
1519 (let ((ids (yahtml-collect-ids)))
1520 (yahtml-make-optional-argument
1521 "id" (YaTeX-completing-read-or-skip "id: " ids nil t))))
1523 (defun yahtml:textarea ()
1524 "Add-in function for `textarea'"
1525 (interactive)
1526 (let (name rows cols)
1527 (setq name (read-string-with-history "Name: ")
1528 cols (read-string-with-history "Columns: ")
1529 rows (read-string-with-history "Rows: "))
1530 (concat
1531 (concat (if yahtml-prefer-upcase-attributes "NAME=" "name=")
1532 "\"" name "\"")
1533 (yahtml-make-optional-argument "cols" cols)
1534 (yahtml-make-optional-argument "rows" rows))))
1536 (defun yahtml:table ()
1537 "Add-in function for `table'"
1538 (let ((b (read-string-with-history "border="))
1539 (a (if yahtml-html4-strict ""
1540 (yahtml-read-parameter
1541 "align" nil '(("align" ("right")("center")))))))
1542 (if yahtml-html4-strict
1543 (yahtml-make-optional-argument
1544 "style"
1545 (if (or (string< "" b) (string< "" a))
1546 (yahtml-make-style-parameter
1547 (append
1548 (if (string< "" b)
1549 (list
1550 (cons "border" (format "%dpx solid" (YaTeX-str2int b)))
1551 (cons "border-collapse" "collapse")))
1552 (if (string< "" a)
1553 (cond
1554 ((string-match "right" a)
1555 (list (cons "margin-left" "auto")
1556 (cons "margin-right" "0")))
1557 ((string-match "center" a)
1558 (list (cons "margin-left" "auto")
1559 (cons "margin-right" "auto")))))))))
1560 (concat
1561 (yahtml-make-optional-argument "border" b)
1562 (yahtml-make-optional-argument "align" a)))))
1564 ;(fset 'yahtml:caption 'yahtml:p)
1565 (defun yahtml:caption ()
1566 "Add-in function for `caption' in table tag"
1567 (let ((par (yahtml-read-parameter "align")))
1568 (if yahtml-html4-strict
1569 (yahtml-make-optional-argument
1570 "style" (if par (yahtml-make-style-parameter
1571 (list (cons "caption-side" par)))))
1572 (yahtml-make-optional-argument "align" par))))
1574 (defun yahtml:font ()
1575 "Add-in function for `font'"
1576 (concat
1577 (yahtml-make-optional-argument "color" (read-string-with-history "color="))
1578 (yahtml-make-optional-argument "size" (read-string-with-history "size="))))
1580 (defun yahtml:style ()
1581 "Add-in function for `style'"
1582 (yahtml-make-optional-argument
1583 "type" (read-string-with-history "type=" "text/css")))
1585 (defun yahtml:script ()
1586 "Add-in function for `script'"
1587 (concat
1588 (yahtml-make-optional-argument
1589 "type" (yahtml-read-parameter "type" "text/javascript"))
1590 (yahtml-make-optional-argument
1591 "src" (yahtml-read-parameter "src" ""))))
1593 (defun yahtml:tr ()
1594 "Add-in function for `tr'"
1595 (setq yahtml-last-typeface-cmd "td")
1596 "")
1598 (defun yahtml:link ()
1599 "Add-in function for `link' (まだちょっと良く分かってない)"
1600 (let (rel rev type href)
1601 (setq rel (yahtml-read-parameter "rel"))
1602 (cond
1603 ((equal rel "")
1604 (concat (yahtml-make-optional-argument
1605 "rev" (yahtml-read-parameter "rev"))
1606 (yahtml-make-optional-argument
1607 "href" (yahtml-read-parameter "href")
1608 ;;他に良く使うのって何?
1609 )))
1610 ((string-match "stylesheet" rel)
1611 (concat
1612 (yahtml-make-optional-argument "rel" rel)
1613 (yahtml-make-optional-argument
1614 "type" (yahtml-read-parameter "type" "text/css"))
1615 (progn
1616 (setq href
1617 (read-from-minibuffer-with-history
1618 "href: " "" yahtml-url-completion-map))
1619 (if (string< "" href)
1620 (progn
1621 (if (and (file-exists-p (yahtml-url-to-path href))
1622 (y-or-n-p "Load css symbols now? "))
1623 (setq yahtml-css-class-alist
1624 (yahtml-css-collect-classes-file
1625 (yahtml-url-to-path href) yahtml-css-class-alist)))
1626 (message "")
1627 (yahtml-make-optional-argument "href" href))))))
1628 (t
1629 (concat
1630 (yahtml-make-optional-argument "rel" rel)
1631 (yahtml-make-optional-argument
1632 "type" (yahtml-read-parameter "type"))
1633 (yahtml-make-optional-argument
1634 "href"
1635 (read-from-minibuffer-with-history
1636 "href: " "" yahtml-url-completion-map)))))))
1638 (defvar yahtml:meta-attrs
1639 '(("charset" value)
1640 ("name" content ("keywords")("author")("copyright")("date")("GENERATOR")
1641 ("viewport"))
1642 ("http-equiv" content)))
1644 (defun yahtml:meta ()
1645 (let ((attr (completing-read-with-history
1646 "Meta Attribute: " yahtml:meta-attrs))
1647 (case-fold-search t)
1648 (completion-ignore-case t)
1649 todonext name http-equiv content)
1650 (cond
1651 ((string= "" attr) nil)
1652 ((and (setq todonext (cdr-safe (assoc attr yahtml:meta-attrs)))
1653 (eq 'value (car todonext)))
1654 (yahtml-make-optional-argument attr (yahtml-read-parameter attr)))
1655 ((eq 'content (car todonext))
1656 (setq name (if (cdr todonext)
1657 (completing-read-with-history
1658 (format "%s: " attr) (cdr todonext))
1659 (yahtml-read-parameter attr)))
1660 (concat
1661 (yahtml-make-optional-argument attr name)
1662 (yahtml-make-optional-argument
1663 "content"
1664 (cond
1665 ((string-match "date" name)
1666 (read-string-with-history "Date: " (current-time-string)))
1667 ((string-match "author" name)
1668 (read-string-with-history "Author: "
1669 (if (and (user-full-name) (string< "" (user-full-name)))
1670 (user-full-name)
1671 (user-login-name))))
1672 ((string-match "GENERATOR" name)
1673 (setq content (read-string-with-history
1674 "Generator: " "User-agent: "))
1675 (if (string-match "yahtml" content)
1676 (message "Thank you!"))
1677 content)
1678 ((string-match "content-type" name)
1679 (if (string-match "http-equiv" attr )
1680 (error "Use <meta charset=\"...\" instead.. See docs/qanda.")
1681 (yahtml-make-optional-argument
1682 "content" (yahtml-read-parameter "content"))))
1683 ((string-match "viewport" name)
1684 ;; XXX: Very dirty static string
1685 "width=device-width, initial-scale=1")
1686 (t (read-string-with-history (concat name ": ")))))))
1687 (t (yahtml-make-optional-argument
1688 attr (yahtml-read-parameter attr))))))
1690 (defun yahtml:br ()
1691 (yahtml-make-optional-argument "clear" (yahtml-read-parameter "clear")))
1693 (defun yahtml:object ()
1694 (let ((codetype (yahtml-read-parameter "codetype" "application/java"))
1695 data classid)
1696 (cond
1697 ((string-match "java" codetype)
1698 (let ((completion-ignored-extensions
1699 ;;any extensions except ".class"
1700 '(".java" ".html" ".htm" ".gif" ".jpg" ".jpeg" ".png")))
1701 (setq classid (concat "java:"
1702 (yahtml-read-parameter "class file name"))))
1703 (concat
1704 (yahtml-make-optional-argument "codetype" codetype)
1705 (yahtml-make-optional-argument "classid" classid)
1706 (yahtml-make-optional-argument
1707 "width" (yahtml-read-parameter "width"))
1708 (yahtml-make-optional-argument
1709 "height" (yahtml-read-parameter "height"))))
1710 (t
1711 ""))))
1713 (defun yahtml:abbr ()
1714 "Add-in function for abbr."
1715 (yahtml-make-optional-argument "title" (yahtml-read-parameter "title")))
1717 (defun yahtml:button ()
1718 (concat
1719 (yahtml-make-optional-argument
1720 "name" (yahtml-read-parameter "name"))
1721 (yahtml-make-optional-argument
1722 "type" (yahtml-read-parameter
1723 "type" "button" '(("submit")("reset")("button"))))
1724 (yahtml-make-optional-argument
1725 "value" (yahtml-read-parameter "value"))))
1727 (defun yahtml::article ()
1728 (setq yahtml-last-typeface-cmd "h1" yahtml-last-begend "h1"))
1730 ;;; ---------- Simple tag ----------
1731 (defun yahtml-insert-tag (region-mode &optional tag)
1732 "Insert <TAG> </TAG> and put cursor inside of them."
1733 (interactive "P")
1734 (setq yahtml-current-completion-type 'inline
1735 region-mode (or region-mode (YaTeX-region-active-p)))
1736 (or tag
1737 (let ((completion-ignore-case t))
1738 (setq tag
1739 (YaTeX-cplread-with-learning
1740 (format "Tag %s(default %s): "
1741 (if region-mode "region: " "") yahtml-last-typeface-cmd)
1742 'yahtml-typeface-table 'yahtml-user-typeface-table
1743 'yahtml-tmp-typeface-table))))
1744 (if (string= "" tag) (setq tag yahtml-last-typeface-cmd))
1745 (setq tag (or (cdr (assoc tag yahtml-typeface-table)) tag))
1746 (setq yahtml-last-typeface-cmd tag
1747 tag (funcall (if yahtml-prefer-upcases 'upcase 'downcase) tag))
1748 (if region-mode
1749 (if (if (string< "19" emacs-version) (mark t) (mark))
1750 (save-excursion
1751 (if (> (point) (mark)) (exchange-point-and-mark))
1752 (insert (format "<%s%s>" tag (yahtml-addin tag)))
1753 (exchange-point-and-mark)
1754 (insert "</" tag ">"))
1755 (message "No mark set now"))
1756 (insert (format "<%s%s>" tag (yahtml-addin tag)))
1757 (save-excursion (insert (format "</%s>" tag)))))
1759 (defun yahtml-insert-tag-region (&optional tag)
1760 "Call yahtml-insert-tag with region mode."
1761 (interactive)
1762 (yahtml-insert-tag t tag))
1764 (defvar yahtml-need-single-closer nil) ;for test
1765 (defun yahtml-insert-single (cmd)
1766 "Insert <CMD>."
1767 (interactive
1768 (list
1769 (let ((completion-ignore-case t))
1770 (YaTeX-cplread-with-learning
1771 (format "Command%s: "
1772 (if yahtml-last-single-cmd
1773 (concat "(default " yahtml-last-single-cmd ")") ""))
1774 'yahtml-single-cmd-table 'yahtml-user-single-cmd-table
1775 'yahtml-tmp-single-cmd-table))))
1776 (if (string= "" cmd) (setq cmd yahtml-last-single-cmd))
1777 (setq yahtml-last-single-cmd
1778 (or (cdr (assoc cmd yahtml-single-cmd-table)) cmd))
1779 (setq cmd (funcall (if yahtml-prefer-upcases 'upcase 'downcase)
1780 yahtml-last-single-cmd))
1781 (insert (format "<%s%s%s>"
1782 cmd
1783 (yahtml-addin cmd)
1784 (if (and yahtml-need-single-closer
1785 (assoc cmd '(("br")("hr"))))
1786 " /" "")))
1787 (if (assoc cmd yahtml-env-table)
1788 (save-excursion (insert (format "</%s>" cmd)))))
1790 (defun yahtml-insert-p (&optional arg)
1791 "Convenient function to insert <p></p>"
1792 (interactive "P")
1793 (if (or yahtml-always-/p arg) (yahtml-insert-tag arg "p")
1794 (yahtml-insert-single "p")))
1796 (defun yahtml-insert-amps (arg)
1797 "Insert char-entity references via ampersand"
1798 ;; Thanks; http://www.tsc.co.jp/~asada/html/wdg40_f/entities/
1799 (interactive "P")
1800 (let*((mess "") c
1801 (list (append yahtml-entity-reference-chars-alist-default
1802 yahtml-entity-reference-chars-alist))
1803 (l list))
1804 (while l
1805 (setq mess (format "%s %c" mess (car (car l)) (cdr (car l)))
1806 l (cdr l)))
1807 (message "Char-entity reference: %s SPC=& RET=&; BS=%s Other=&#..;"
1808 mess (if YaTeX-japan "直前の文字" "Preceding-Char"))
1809 (setq c (read-char))
1810 (cond
1811 ((equal c (car-safe (assoc c list)))
1812 (insert (format "&%s;" (cdr (assoc c list)))))
1813 ((or (equal c ?\n) (equal c ?\r))
1814 (insert "&;")
1815 (forward-char -1))
1816 ((equal c ? )
1817 (insert ?&))
1818 ((and (memq c '(127 8))
1819 (setq c (preceding-char))
1820 (delete-backward-char 1)
1821 nil)) ;Fall through to the next 't block
1822 (t (insert (format "&#x%x;" c))))))
1824 (defun yahtml:!--\#include ()
1825 (let ((file (yahtml-read-parameter "file" "")))
1826 (format "%s=\"%s\"--" (if (string-match "/" file) "virtual" "file") file)))
1828 (defun yahtml:!--\#exec ()
1829 (format "cmd=\"%s\"--"
1830 (yahtml-read-parameter "cmd" "" '(("cmd" . command)))))
1832 (defun yahtml:media-read-options (&optional opts-alist)
1833 (let*((delim " ")
1834 (minibuffer-completion-table
1835 (or opts-alist '(("autoplay") ("controls") ("loop") ("preload"))))
1836 (quotekey (substitute-command-keys "\\[quoted-insert]")))
1837 (read-from-minibuffer-with-history
1838 (format "Media Opts(`%s SPC' for more options): " quotekey)
1839 "controls" YaTeX-minibuffer-completion-map)))
1841 (defun yahtml:audio ()
1842 ;preload autoplay loop controls: `src' be specified via `source'
1843 (yahtml:media-read-options))
1845 (defun yahtml:video ()
1846 ;`src' be specified via `source'
1847 (let ((poster (yahtml-make-optional-argument
1848 "poster"
1849 (yahtml-read-file-name-regexp
1850 "Poster: " "\\.\\(gif\\|png\\|jpg\\|w?bmp\\|pict\\|tif\\)"
1851 "")))
1852 (opts (yahtml:media-read-options)))
1853 (concat poster (if (string< "" opts) (concat " " opts)))))
1855 (defvar yahtml-media-file-regexp
1856 "\\.\\(mp[0-9]\\|wav\\|og[gv]\\|opus\\|aac\\)"
1857 "*Default filename regexp of media files.")
1859 (defun yahtml:source ()
1860 ;; source element must have src attribute
1861 (format "src=\"%s\"" (yahtml-read-file-name-regexp
1862 "source: " yahtml-media-file-regexp "" "" nil "")))
1864 (defun yahtml:figure ()
1865 (setq yahtml-last-typeface-cmd "figcaption"))
1867 (defun yahtml:iframe ()
1868 (let ((src (yahtml-read-url "src: ")))
1869 (concat
1870 (yahtml-make-optional-argument "src" src)
1871 (yahtml-make-optional-argument
1872 "width" (YaTeX-read-string-or-skip "width: "))
1873 (yahtml-make-optional-argument
1874 "height" (YaTeX-read-string-or-skip "height: ")))))
1876 ;;; ---------- Jump ----------
1877 (defun yahtml-on-href-p ()
1878 "Check if point is on href clause."
1879 (let ((p (point)) e cmd (case-fold-search t))
1880 (save-excursion
1881 (and ;;(string= (YaTeX-inner-environment t) "a") ;aでなくても許可にした
1882 (save-excursion
1883 ;;(search-forward "</a>" nil t) ;aでなくても許可にした
1884 (search-forward "[\" \t\n]" nil t)
1885 (setq e (point)))
1886 ;(goto-char (get 'YaTeX-inner-environment 'point))
1887 (re-search-backward "<\\(a\\|link\\)\\>" nil t)
1888 (search-forward "href" e t)
1889 (search-forward "=" e t)
1890 (progn
1891 (skip-chars-forward " \t\n")
1892 (looking-at "\"?\\([^\"> \t\n]+\\)\"?"))
1893 (< p (match-end 0))
1894 (yahtml-unescape-string (YaTeX-match-string 1))))))
1896 (defun yahtml-netscape-sentinel (proc mes)
1897 (cond
1898 ((null (buffer-name (process-buffer proc)))
1899 (set-process-buffer proc nil))
1900 ((eq (process-status proc) 'exit)
1901 (let ((cb (current-buffer)))
1902 (set-buffer (process-buffer proc))
1903 (goto-char (point-min))
1904 (if (search-forward "not running" nil t)
1905 (progn
1906 (message "Starting netscape...")
1907 (start-process
1908 "browser" (process-buffer proc)
1909 shell-file-name yahtml-shell-command-option
1910 (format "%s \"%s\"" yahtml-www-browser
1911 (get 'yahtml-netscape-sentinel 'url)))
1912 (message "Starting netscape...Done")))
1913 (set-buffer cb)))))
1915 (defvar yahtml-browser-process nil)
1917 (defun yahtml-browse-html (href)
1918 "Call WWW Browser to see HREF."
1919 (let ((pb "* WWW Browser *") (cb (current-buffer)))
1920 (cond
1921 ((string-match "^start\\>" yahtml-www-browser)
1922 (if (get-buffer pb)
1923 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
1924 (put 'yahtml-netscape-sentinel 'url href)
1925 (set-process-sentinel
1926 (setq yahtml-browser-process
1927 (start-process
1928 "browser" pb shell-file-name yahtml-shell-command-option
1929 (format "%s \"%s\"" yahtml-www-browser href)))
1930 'yahtml-netscape-sentinel))
1931 ((and (string-match
1932 "[Nn]etscape\\|[Ff]irefox\\|[Mm]ozilla" yahtml-www-browser)
1933 (not (eq system-type 'windows-nt)))
1934 (if (get-buffer pb)
1935 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
1936 (put 'yahtml-netscape-sentinel 'url href)
1937 (set-process-sentinel
1938 (setq yahtml-browser-process
1939 (start-process
1940 "browser" pb shell-file-name yahtml-shell-command-option ;"-c"
1941 (format "%s -remote \"openURL(%s)\"" yahtml-www-browser href)))
1942 'yahtml-netscape-sentinel))
1943 ((and (string= "w3" yahtml-www-browser) (fboundp 'w3-fetch))
1944 (w3-fetch href))
1945 ((stringp yahtml-www-browser)
1946 (if (and yahtml-browser-process
1947 (eq (process-status yahtml-browser-process) 'run))
1948 (message "%s is already running" yahtml-www-browser)
1949 (setq yahtml-browser-process
1950 (start-process
1951 "browser" "* WWW Browser *"
1952 shell-file-name yahtml-shell-command-option
1953 (format "%s \"%s\"" yahtml-www-browser href)))))
1954 (t
1955 (message "Sorry, jump across http is not supported.")))))
1957 (defun yahtml-goto-corresponding-href (&optional other)
1958 "Go to corresponding name."
1959 (let ((href (yahtml-on-href-p)) file name (parent buffer-file-name))
1960 (if href
1961 (cond
1962 ((string-match "^\\(ht\\|f\\)tps?:" href)
1963 (yahtml-browse-html href))
1964 (t (if (string-match "\&" href)
1965 (setq href (yahtml-untranslate-string href)))
1966 (setq file (substring href 0 (string-match "#" href)))
1967 (if (string-match "#" href)
1968 (setq name (substring href (1+ (string-match "#" href)))))
1969 (if (string< "" file)
1970 (progn
1971 (if (string-match "/$" file)
1972 (or (catch 'dirindex
1973 (mapcar
1974 (function
1975 (lambda (f)
1976 (if (file-exists-p (concat file f))
1977 (throw 'dirindex
1978 (setq file (concat file f))))))
1979 (yahtml-get-directory-index))
1980 nil)
1981 (setq file (concat file yahtml-directory-index))))
1982 (if (string-match "^/" file)
1983 (setq file (yahtml-url-to-path file)))
1984 (if other (YaTeX-switch-to-buffer-other-window file)
1985 (YaTeX-switch-to-buffer file))
1986 (or YaTeX-parent-file (setq YaTeX-parent-file parent))))
1987 (if name
1988 (progn (set-mark-command nil) (yahtml-jump-to-name name)))
1989 t)))))
1991 (defun yahtml-jump-to-name (name)
1992 "Jump to html's named tag."
1993 (setq name (format "\\(name\\|id\\)\\s *=\\s *\"?%s\\>\"?" name))
1994 (or (and (re-search-forward name nil t) (goto-char (match-beginning 0)))
1995 (and (re-search-backward name nil t) (goto-char (match-beginning 0)))
1996 (message "Named tag `%s' not found" (substring href 1))))
1998 (defun yahtml-on-begend-p (&optional p)
1999 "Check if point is on begend clause."
2000 (let ((p (or p (point))) cmd (case-fold-search t))
2001 (save-excursion
2002 (goto-char p)
2003 (if (equal (char-after (point)) ?<) (forward-char 1))
2004 (if (and (re-search-backward "<" nil t)
2005 (looking-at
2006 ;(concat "<\\(/?" yahtml-struct-name-regexp "\\)\\b")
2007 "<\\(/?[A-Z][A-Z0-9]*\\)\\b")
2008 (condition-case nil
2009 (forward-list 1)
2010 (error nil))
2011 (< p (point)))
2012 (YaTeX-match-string 1)))))
2014 (defun yahtml-goto-corresponding-begend (&optional noerr)
2015 "Go to corresponding opening/closing tag.
2016 Optional argument NOERR causes no error for unballanced tag."
2017 (let ((cmd (yahtml-on-begend-p)) m0
2018 (p (point)) (case-fold-search t) func str (nest 0))
2019 (cond
2020 (cmd
2021 (setq m0 (match-beginning 0))
2022 (if (= (aref cmd 0) ?/) ;on </cmd> line
2023 (setq cmd (substring cmd 1)
2024 str (format "\\(<%s\\)\\|\\(</%s\\)" cmd cmd)
2025 func 're-search-backward)
2026 (setq str (format "\\(</%s\\)\\|\\(<%s\\)" cmd cmd)
2027 func 're-search-forward))
2028 (while (and (>= nest 0) (funcall func str nil t))
2029 (if (equal m0 (match-beginning 0))
2030 nil
2031 (setq nest (+ nest (if (match-beginning 1) -1 1)))))
2032 (if (< nest 0)
2033 (goto-char (match-beginning 0))
2034 (funcall
2035 (if noerr 'message 'error)
2036 "Corresponding tag of `%s' not found." cmd)
2037 (goto-char p)
2038 nil))
2039 (t nil))))
2041 (defun yahtml-current-tag ()
2042 "Return the current tag name including #exec and #include."
2043 (save-excursion
2044 (let ((p (point)) b tag)
2045 (or (bobp)
2046 (looking-at "<")
2047 (progn (skip-chars-backward "^<") (forward-char -1)))
2048 (setq b (point))
2049 (skip-chars-forward "<")
2050 (setq tag (YaTeX-buffer-substring
2051 (point) (progn (skip-chars-forward "^ \t\n") (point))))
2052 (goto-char b)
2053 (forward-list 1)
2054 (and (< p (point)) tag))))
2056 (defun yahtml-get-attrvalue (attr)
2057 "Extract current tag's attribute value from buffer."
2058 (let (e (case-fold-search t))
2059 (save-excursion
2060 (or (looking-at "<")
2061 (progn (skip-chars-backward "^<") (backward-char 1)))
2062 (setq e (save-excursion (forward-list 1) (point)))
2063 (if (and
2064 (re-search-forward (concat "\\b" attr "\\b") e t)
2065 (progn (skip-chars-forward " \t\n=")
2066 (looking-at "\"?\\([^\"> \t\n]+\\)\"?")))
2067 (YaTeX-match-string 1)))))
2069 (defun yahtml-goto-corresponding-img ()
2070 "View image on point"
2071 (let ((tag (yahtml-current-tag)) image (p (point)) (case-fold-search t))
2072 (if (and tag
2073 (string-match "img" tag)
2074 (setq image
2075 (yahtml-unescape-string (yahtml-get-attrvalue "src"))))
2076 (progn
2077 (message "Invoking %s %s..." yahtml-image-viewer image)
2078 (start-process
2079 "Viewer" " * Image Viewer *"
2080 shell-file-name yahtml-shell-command-option ;"-c"
2081 (concat yahtml-image-viewer " " image))
2082 (message "Invoking %s %s...Done" yahtml-image-viewer image)))))
2084 (defun yahtml-goto-corresponding-source (&optional other)
2085 "Goto applet's or script's source."
2086 (let ((env (yahtml-current-tag)) s (p (point)))
2087 (cond
2088 ((string-match "applet" env)
2089 (if (setq s (yahtml-unescape-string (yahtml-get-attrvalue "code")))
2090 (progn
2091 (setq s (YaTeX-match-string 1)
2092 s (concat
2093 (substring s 0 (string-match "\\.[A-Za-z]+$" s))
2094 ".java"))
2095 (if other (YaTeX-switch-to-buffer-other-window s)
2096 (YaTeX-switch-to-buffer s))
2097 s) ;return source file name
2098 (message "No applet source specified")
2099 (sit-for 1)
2100 nil))
2101 ((string-match "script" env)
2102 (if (setq s (yahtml-get-attrvalue "src"))
2103 (progn
2104 (funcall (if other 'YaTeX-switch-to-buffer-other-window
2105 'YaTeX-switch-to-buffer)
2106 (yahtml-url-to-path s))
2107 s)))
2108 ((string-match "!--#include" env)
2109 (cond
2110 ((setq s (yahtml-get-attrvalue "file")) ;<!--#include file="foo"-->
2111 (if other (YaTeX-switch-to-buffer-other-window s)
2112 (YaTeX-switch-to-buffer s))
2113 s)
2114 ((setq s (yahtml-get-attrvalue "virtual"));<!--#include virtual="foo"-->
2115 (setq s (yahtml-url-to-path s))
2116 (if other (YaTeX-switch-to-buffer-other-window s)
2117 (YaTeX-switch-to-buffer s))
2118 s)))
2119 ((and (string-match "!--#exec" env)
2120 (setq s (yahtml-get-attrvalue "cmd")))
2121 (setq s (substring s 0 (string-match " \t\\?" s))) ;get argv0
2122 (let ((b " *yahtmltmp*")) ;peek a little
2123 (unwind-protect
2124 (progn
2125 (set-buffer (get-buffer-create b))
2126 (YaTeX-insert-file-contents s nil 0 100)
2127 (if (looking-at "#!")
2128 (if other (YaTeX-switch-to-buffer-other-window s)
2129 (YaTeX-switch-to-buffer s))))
2130 (kill-buffer (get-buffer b)))
2131 (get-file-buffer s))))))
2133 (defun yahtml-goto-corresponding-* (&optional other)
2134 "Go to corresponding object."
2135 (interactive "P")
2136 (cond
2137 ((yahtml-goto-corresponding-href other))
2138 ((yahtml-goto-corresponding-img))
2139 ((yahtml-goto-corresponding-source other))
2140 ((yahtml-goto-corresponding-begend))
2141 (t (message "I don't know where to go."))))
2143 (defun yahtml-goto-corresponding-*-other-window ()
2144 "Go to corresponding object."
2145 (interactive)
2146 (yahtml-goto-corresponding-* t))
2148 (defun yahtml-visit-main ()
2149 "Go to parent file from where you visit current file."
2150 (interactive)
2151 (if YaTeX-parent-file (YaTeX-switch-to-buffer YaTeX-parent-file)))
2153 ;;; ---------- killing ----------
2154 (defun yahtml-kill-begend (&optional whole)
2155 (let ((tag (yahtml-on-begend-p)) p q r bbolp)
2156 (if tag
2157 (save-excursion
2158 (or (looking-at "<")
2159 (progn (skip-chars-backward "^<") (forward-char -1)))
2160 (setq p (point))
2161 (yahtml-goto-corresponding-begend)
2162 (or (looking-at "<")
2163 (progn (skip-chars-backward "^<") (forward-char -1)))
2164 (if (< (point) p) ;if on the opening tag
2165 (progn (setq q p p (point))
2166 (goto-char q))
2167 (setq q (point))) ;now q has end-line's (point)
2168 (if (not whole)
2169 (kill-region
2170 (progn (skip-chars-backward " \t")
2171 (if (setq bbolp (bolp)) (point) q))
2172 (progn (forward-list 1)
2173 (setq r (point))
2174 (skip-chars-forward " \t")
2175 (if (and bbolp (eolp) (not (eobp))) (1+ (point)) r))))
2176 (goto-char p)
2177 (skip-chars-backward " \t")
2178 (if (not whole)
2179 (progn
2180 (kill-append
2181 (buffer-substring
2182 (setq p (if (setq bbolp (bolp)) (point) p))
2183 (setq q (progn
2184 (forward-list 1)
2185 (setq r (point))
2186 (skip-chars-forward " \t")
2187 (if (and bbolp (eolp) (not (eobp)))
2188 (1+ (point))
2189 r))))
2190 t)
2191 (delete-region p q))
2192 (kill-region
2193 (if (bolp) (point) p)
2194 (progn (goto-char q)
2195 (forward-list 1)
2196 (setq r (point))
2197 (skip-chars-forward " \t")
2198 (if (and (eolp) (not (eobp))) (1+ (point)) r))))
2199 tag))))
2201 (defun yahtml-kill-* (whole)
2202 "Kill current position's HTML tag (set)."
2203 (interactive "P")
2204 (cond
2205 ((yahtml-kill-begend whole))))
2208 ;;; ---------- changing ----------
2209 (defun yahtml-on-assignment-p ()
2210 "Return if current point is on parameter assignment.
2211 If so, return parameter name, otherwise nil.
2212 This function should be able to treat white spaces in value, but not yet."
2213 (let ((p (point)))
2214 (save-excursion
2215 (put 'yahtml-on-assignment-p 'region nil)
2216 (skip-chars-backward "^ \t\n")
2217 (and (looking-at "\\([A-Za-z0-9]+\\)\\s *=\\s *\"?\\([^ \t\"]+\\)\"?")
2218 (< p (match-end 0))
2219 (>= p (1- (match-beginning 2)))
2220 (put 'yahtml-on-assignment-p 'region
2221 (cons (match-beginning 2) (match-end 2)))
2222 (YaTeX-match-string 1)))))
2224 (defun yahtml-change-begend ()
2225 (let ((tag (yahtml-on-begend-p))
2226 (completion-ignore-case t)
2227 (case-fold-search t)
2228 (p (point)) (q (make-marker))
2229 (default (append yahtml-env-table yahtml-typeface-table))
2230 (user (append yahtml-user-env-table yahtml-user-typeface-table))
2231 (tmp (append yahtml-tmp-env-table yahtml-tmp-typeface-table))
2232 href b1 e1 attr new css)
2233 (cond
2234 (tag
2235 (cond
2236 ((and (string-match "^a$" tag)
2237 (save-excursion
2238 (and
2239 (re-search-backward "<a\\b" nil t)
2240 (progn
2241 (goto-char (match-end 0))
2242 (skip-chars-forward " \t\n")
2243 (setq b1 (point))
2244 (search-forward ">" nil t))
2245 (setq e1 (match-beginning 0))
2246 (goto-char b1)
2247 (re-search-forward "href\\s *=" e1 t)
2248 (>= p (point))
2249 (progn
2250 (goto-char (match-end 0))
2251 (skip-chars-forward " \t\n")
2252 (looking-at "\"?\\([^\"> \t\n]+\\)\"?"))
2253 (< p (match-end 0)))))
2254 (setq b1 (match-beginning 1) e1 (match-end 1)
2255 yahtml-completing-buffer (current-buffer)
2256 ;; yahtml-urls-local is buffer-local, so we must put
2257 ;; that into yahtml-urls here
2258 yahtml-urls (append yahtml-urls-private yahtml-urls-local)
2259 href (read-from-minibuffer
2260 "Change href to: " "" yahtml-url-completion-map))
2261 (if (string< "" href)
2262 (progn
2263 ;;(setq href ;??
2264 ;; (if yahtml-prefer-upcases (upcase href) (downcase href)))
2265 (delete-region b1 e1)
2266 (goto-char b1)
2267 (insert href))))
2268 ((setq attr (yahtml-on-assignment-p)) ;if on the assignment to attr
2269 (if (and (equal attr "class") ;treat "class" attribute specially
2270 (setq css (yahtml-css-get-element-completion-alist tag)))
2272 (setq new (yahtml-read-css css tag))
2273 ;;other than "class", read parameter normally
2274 (setq new (yahtml-read-parameter attr)))
2275 (goto-char (car (get 'yahtml-on-assignment-p 'region)))
2276 (delete-region (point) (cdr (get 'yahtml-on-assignment-p 'region)))
2277 (insert new))
2278 (t
2279 (save-excursion
2280 (if (= (aref tag 0) ?/) (setq tag (substring tag 1)))
2281 (or (= (char-after (point)) ?<) (skip-chars-backward "^<"))
2282 (skip-chars-forward "^A-Za-z")
2283 (set-marker q (point))
2284 (setq p (point))
2285 (yahtml-goto-corresponding-begend)
2286 (or (= (char-after (point)) ?<)
2287 (skip-chars-backward "^<"))
2288 (skip-chars-forward "^A-Za-z")
2289 (if (= (char-after (1- (point))) ?/)
2290 (progn
2291 (set-marker q (point))
2292 (goto-char p)))
2293 (setq tag (let ((completion-ignore-case t))
2294 (YaTeX-cplread-with-learning
2295 (format "Change `%s' to(default %s): "
2296 tag yahtml-last-begend)
2297 'default 'user 'tmp)))
2298 (delete-region (point) (progn (skip-chars-forward "^>") (point)))
2299 (if (string= "" tag) (setq tag yahtml-last-begend))
2300 (setq yahtml-last-begend
2301 (or (cdr (assoc tag yahtml-env-table)) tag)
2302 tag yahtml-last-begend)
2303 (setq tag (if yahtml-prefer-upcases (upcase tag) (downcase tag)))
2304 (insert (format "%s%s" tag (yahtml-addin tag)))
2305 (goto-char q)
2306 (set-marker q nil)
2307 (delete-region (point) (progn (skip-chars-forward "^>") (point)))
2308 (insert tag))))
2309 t))))
2311 (defun yahtml-change-command ()
2312 (let ((p (point)) (case-fold-search t) cmd par new
2313 (beg (make-marker)) (end (make-marker)))
2314 (skip-chars-backward "^<")
2315 (if (and
2316 (looking-at yahtml-command-regexp)
2317 (progn
2318 (set-marker beg (match-beginning 0))
2319 (set-marker end (match-end 0))
2320 t) ;for further work
2321 (progn
2322 (forward-char -1)
2323 (condition-case nil
2324 (forward-list 1)
2325 (error nil))
2326 (< p (point))))
2327 (progn
2328 (goto-char p)
2329 (if (setq par (yahtml-on-assignment-p))
2330 (progn
2331 (setq new (yahtml-read-parameter par))
2332 (set-marker beg (car (get 'yahtml-on-assignment-p 'region)))
2333 (set-marker end (cdr (get 'yahtml-on-assignment-p 'region))))
2334 (setq new
2335 (YaTeX-cplread-with-learning
2336 "Change form to: "
2337 'yahtml-form-table 'yahtml-user-form-table
2338 'yahtml-tmp-form-table)))
2339 (delete-region beg end)
2340 (goto-char beg)
2341 (set-marker beg nil)
2342 (set-marker end nil)
2343 (insert new)
2344 t)
2345 (goto-char p)
2346 nil)))
2348 (defun yahtml-change-* ()
2349 "Change current position's HTML tag (set)."
2350 (interactive)
2351 (cond
2352 ((yahtml-change-begend))
2353 ((yahtml-change-command))))
2355 ;;; ---------- commenting ----------
2357 (defun yahtml-comment-region (&optional uncom)
2358 "Comment out region or environment."
2359 (interactive)
2360 (let ((e (make-marker)) be beg p)
2361 (cond
2362 (;(marker-position (set-marker e (yahtml-on-begend-p)))
2363 (setq be (yahtml-on-begend-p))
2364 (save-excursion
2365 (setq p (point))
2366 (if (string-match "^/" be)
2367 (setq beg (progn (forward-line 1) (point)))
2368 (setq beg (progn (beginning-of-line) (point))))
2369 (goto-char p)
2370 (yahtml-goto-corresponding-begend)
2371 (if (string-match "^/" be)
2372 (beginning-of-line)
2373 (forward-line 1))
2374 (set-marker e (point))
2375 ;(comment-region beg (point) (if uncom (list 4)))))
2376 ))
2377 (t ;(comment-region (region-beginning) (region-end) (if uncom (list 4)))
2378 (setq beg (region-beginning))
2379 (set-marker e (region-end))))
2380 (if yahtml-translate-hyphens-when-comment-region
2381 (let ((yahtml-entity-reference-chars-alist-default nil)
2382 (yahtml-entity-reference-chars-alist '((?- . "#45")))
2383 yahtml-entity-reference-chars-regexp
2384 yahtml-entity-reference-chars-reverse-regexp)
2385 (yahtml-entity-reference-chars-setup)
2386 (funcall
2387 (if uncom 'yahtml-translate-reverse-region
2388 'yahtml-translate-region)
2389 beg e)))
2390 (comment-region beg e (if uncom (list 4)))
2391 (set-marker e nil)))
2393 (defun yahtml-uncomment-region ()
2394 (interactive)
2395 (yahtml-comment-region t))
2397 ;;; ---------- translate to entity references ----------
2398 (defvar yahtml-entity-reference-chars-alist-default
2399 ;'((?> . "gt") (?< . "lt") (?& . "amp") (?\" . "quot") (?' . "apos"))
2400 '((?> . "gt") (?< . "lt") (?& . "amp") (?\" . "quot"))
2401 "Default translation table from character to entity reference")
2402 (defvar yahtml-entity-reference-chars-alist nil
2403 "*Translation table from character to entity reference")
2404 (defvar yahtml-entity-reference-chars-regexp nil)
2405 (defvar yahtml-entity-reference-chars-reverse-regexp nil)
2407 (defun yahtml-entity-reference-chars-setup ()
2408 (let ((list (append yahtml-entity-reference-chars-alist-default
2409 yahtml-entity-reference-chars-alist)))
2410 (setq yahtml-entity-reference-chars-regexp "["
2411 yahtml-entity-reference-chars-reverse-regexp "&\\(")
2412 (while list
2413 (setq yahtml-entity-reference-chars-regexp
2414 (concat yahtml-entity-reference-chars-regexp
2415 (char-to-string (car (car list))))
2416 yahtml-entity-reference-chars-reverse-regexp
2417 (concat yahtml-entity-reference-chars-reverse-regexp
2418 (cdr (car list))
2419 (if (cdr list) "\\|")))
2420 (setq list (cdr list)))
2421 (setq yahtml-entity-reference-chars-regexp
2422 (concat yahtml-entity-reference-chars-regexp "]")
2423 yahtml-entity-reference-chars-reverse-regexp
2424 (concat yahtml-entity-reference-chars-reverse-regexp "\\);"))))
2426 (yahtml-entity-reference-chars-setup)
2428 (defun yahtml-translate-region (beg end)
2429 "Translate inhibited literals."
2430 (interactive "r")
2431 (save-excursion
2432 (save-restriction
2433 (narrow-to-region beg end)
2434 (let ((ct (append yahtml-entity-reference-chars-alist
2435 yahtml-entity-reference-chars-alist-default)))
2436 (goto-char beg)
2437 (while (re-search-forward yahtml-entity-reference-chars-regexp nil t)
2438 ;(setq c (preceding-char))
2439 (replace-match
2440 (concat "&" (cdr (assoc (preceding-char) ct)) ";")))))))
2442 (defun yahtml-translate-reverse-region (beg end)
2443 "Translate entity references to literals."
2444 (interactive "r")
2445 (save-excursion
2446 (save-restriction
2447 (narrow-to-region beg end)
2448 (let ((ct (append yahtml-entity-reference-chars-alist
2449 yahtml-entity-reference-chars-alist-default))
2450 ec)
2451 (goto-char beg)
2452 (while (re-search-forward
2453 yahtml-entity-reference-chars-reverse-regexp nil t)
2454 ;(setq c (preceding-char))
2455 (setq ec (YaTeX-match-string 1))
2456 (delete-region (match-end 0) (match-beginning 0))
2457 (insert (car (YaTeX-rassoc ec ct))))))))
2459 (defun yahtml-inner-environment-but (exclude &optional quick)
2460 "Return the inner environment but matches with EXCLUDE tag."
2461 (let (e (case-fold-search t))
2462 (save-excursion
2463 (while (and (setq e (YaTeX-inner-environment quick))
2464 (string-match exclude e))
2465 (goto-char (get 'YaTeX-inner-environment 'point))))
2466 e))
2468 (defun yahtml-untranslate-string (str)
2469 "Untranslate entity reference."
2470 (let ((md (match-data)) (left "") (right str) b0 ch
2471 (ct (append yahtml-entity-reference-chars-alist
2472 yahtml-entity-reference-chars-alist-default))
2473 (revrex yahtml-entity-reference-chars-reverse-regexp))
2474 (unwind-protect
2475 (progn
2476 (while (string< "" right)
2477 (cond
2478 ((string-match revrex right)
2479 (setq ch (YaTeX-rassoc
2480 (substring right (match-beginning 1) (match-end 1)))
2481 b0 (substring right 0 (match-beginning 0))
2482 right (substring right (match-end 0))
2483 left (concat left
2484 (substring right 0 (match-beginning 0))
2485 (char-to-string ch))))
2486 ((string-match "\\&#\\(x\\)?\\([0-9a-f]+\\);" right)
2487 (setq ch (substring right (match-beginning 2) (match-end 2))
2488 b0 (substring right 0 (match-beginning 0))
2489 right (substring right (match-end 0))
2490 left (concat left
2491 b0
2492 (char-to-string
2493 (if (match-beginning 1)
2494 (YaTeX-hex ch)
2495 (string-to-number ch))))))
2496 (t (setq left (concat left right)
2497 right ""))))
2498 left)
2499 (store-match-data md))))
2501 ;;; ---------- table-ize region ----------
2502 (defun yahtml-td-region (e delim beg end)
2503 "Enclose each item in a region with <td>..</td>.
2504 Interactive prefix argument consults enclosing element other than td."
2505 (interactive "P\nsDelimiter(s): \nr")
2506 (let ((e (cond
2507 ((null e) "td")
2508 ((stringp e) e)
2509 (t (read-string-with-history
2510 "Enclose with(`thd' means th td td..): " "th"))))
2511 (ws "[ \t]")
2512 elm p i)
2513 (if (string= delim "") (setq delim " \t\n"))
2514 (setq delim (concat "[" delim "]+")
2515 elm (if (string= "thd" e)
2516 (cons "th" "td")
2517 (cons e e)))
2518 (save-excursion
2519 (save-restriction
2520 (narrow-to-region beg end)
2521 (goto-char (setq p (point-min)))
2522 (setq i 0 e (car elm))
2523 (while (re-search-forward delim nil t)
2524 (setq e (if (= (setq i (1+ i)) 1) (car elm) (cdr elm)))
2525 (goto-char (match-beginning 0))
2526 (insert "</" e ">")
2527 (save-excursion
2528 (goto-char p)
2529 (insert "<" e ">"))
2530 (setq p (point))
2531 (while (and (not (eobp)) (looking-at ws))
2532 (delete-char 1))
2533 (if (looking-at delim) (delete-char 1)))
2534 (insert "<" e ">")
2535 (goto-char (point-max))
2536 (insert "</" e ">")))))
2538 (defun yahtml-tr-region (e delim beg end)
2539 "Enclose lines in a form tab-sv/csv with <tr><td>..</td></tr>."
2540 (interactive "P\nsDelimiter(s): \nr")
2541 (setq e (if (and e (listp e))
2542 (read-string-with-history
2543 "Enclose with(td or th, `thd' -> th td td td...: " "th")))
2544 (save-excursion
2545 (save-restriction
2546 (narrow-to-region (point) (mark))
2547 (goto-char (point-min))
2548 (while (not (eobp))
2549 (insert "<tr>")
2550 (yahtml-td-region e delim (point) (point-end-of-line))
2551 (end-of-line)
2552 (insert "</tr>")
2553 (forward-line 1)))))
2555 ;;; ---------- filling ----------
2556 (defvar yahtml-saved-move-to-column (symbol-function 'move-to-column))
2557 (defun yahtml-move-to-column (col &optional force)
2558 (beginning-of-line)
2559 (let ((ccol 0))
2560 (while (and (> col ccol) (not (eolp)))
2561 (if (eq (following-char) ?\<)
2562 (progn
2563 (while (and (not (eq (following-char) ?\>))
2564 (not (eolp)))
2565 (forward-char))
2566 (or (eolp) (forward-char)))
2567 (or (eolp) (forward-char))
2568 (if (eq (preceding-char) ?\t)
2569 (let ((wd (- 8 (% (+ ccol 8) 8))))
2570 (if (and force (< col (+ ccol wd)))
2571 (progn
2572 (backward-char 1)
2573 (insert-char ?\ (- col ccol))
2574 (setq ccol col))
2575 (setq ccol (+ ccol wd))))
2576 (setq ccol (1+ ccol)))
2577 (if (and YaTeX-japan
2578 (or
2579 (and (fboundp 'char-category)
2580 (string-match "[chj]" (char-category (preceding-char))))
2581 (and (fboundp 'char-charset)
2582 (not (eq (char-charset (preceding-char)) 'ascii)))))
2583 (setq ccol (1+ ccol)))))
2584 (if (and force (> col ccol))
2585 (progn
2586 (insert-char ?\ (- col ccol))
2587 col)
2588 ccol)))
2590 (defun yahtml-fill-paragraph (arg)
2591 (interactive "P")
2592 (let*((case-fold-search t) (p (point)) fill-prefix
2593 (e (or (yahtml-inner-environment-but "^\\(a\\|p\\)\\b" t) "html"))
2594 indent
2595 (startp (get 'YaTeX-inner-environment 'point))
2596 (prep (string-match "^pre$" e))
2597 (ps1 (if prep (default-value 'paragraph-start)
2598 paragraph-start))
2599 (ps2 (if prep (concat (default-value 'paragraph-start)
2600 "$\\|^\\s *</?pre>")
2601 paragraph-start)))
2602 (save-excursion
2603 (unwind-protect
2604 (progn
2605 (if prep
2606 (fset 'move-to-column 'yahtml-move-to-column))
2607 (save-excursion
2608 (beginning-of-line)
2609 (indent-to-column (yahtml-this-indent))
2610 (setq fill-prefix
2611 (buffer-substring (point) (point-beginning-of-line)))
2612 (delete-region (point) (point-beginning-of-line)))
2613 (fill-region-as-paragraph
2614 (progn (re-search-backward paragraph-start nil t)
2615 (or (save-excursion
2616 (goto-char (match-beginning 0))
2617 (if (looking-at "<")
2618 (forward-list)
2619 (goto-char (match-end 0))
2620 (skip-chars-forward " \t>"))
2621 (if (looking-at "[ \t]*$")
2622 (progn (forward-line 1) (point))))
2623 (point)))
2624 (progn (goto-char p)
2625 (re-search-forward ps2 nil t)
2626 (match-beginning 0))))
2627 (fset 'move-to-column yahtml-saved-move-to-column)))))
2629 ;;;
2630 ;;; ---------- move forward/backward field ----------
2631 ;;;
2632 (defun yahtml-element-path ()
2633 "Return the element path from <body> at point as a list"
2634 (let (path elm)
2635 (save-excursion
2636 (while (and (YaTeX-beginning-of-environment)
2637 (looking-at (concat "<\\(" yahtml-command-regexp "\\)\\>"))
2638 (not (string= (setq elm (downcase (YaTeX-match-string 1)))
2639 "body")))
2640 (setq path (cons elm path)
2641 elm nil))
2642 (and elm (setq path (cons elm path)))
2643 path)))
2645 (defun yahtml-forward-field (arg)
2646 "Move ARGth forward cell to table element.
2647 ENVINFO is a cons of target element name and its beginning point."
2648 (interactive "p")
2649 (let (inenv elm path sibs)
2650 (cond
2651 ((< arg 0) (yahtml-backward-field (- arg)))
2652 ((= arg 0) nil)
2653 ((and (setq path (nreverse (yahtml-element-path)))
2654 (catch 'sibling
2655 (while path
2656 (if (setq elm (car-safe
2657 (member (car path) '("td" "th" "li" "dt" "dd"))))
2658 (throw 'sibling elm))
2659 (setq path (cdr path)))))
2660 (setq inenv (YaTeX-in-environment-p elm)
2661 sibs (cdr (assoc elm '(("td" . "td\\|th")
2662 ("th" . "td\\|th")
2663 ("li" . "li")
2664 ("dt" . "dt\\|dd")
2665 ("dd" . "dt\\|dd")))))
2666 (goto-char (cdr inenv))
2667 (while (>= (setq arg (1- arg)) 0)
2668 (yahtml-goto-corresponding-begend)
2669 (if (looking-at "<") (forward-list 1))
2670 (skip-chars-forward "^<"))
2671 (while (looking-at "\\s \\|\\(</\\)")
2672 (if (match-beginning 1) (forward-list 1)
2673 (skip-chars-forward "\n\t ")))
2674 (forward-list 1) ;; step into environment
2675 (skip-chars-forward " \t\n")
2676 (if (looking-at (concat "<\\(" sibs "\\)\\>"))
2677 (forward-list 1))
2678 ))))
2681 ;;;
2682 ;;; ---------- indentation ----------
2683 ;;;
2684 (defun yahtml-indent-line-1 ()
2685 "Indent a line (faster wrapper)"
2686 (interactive)
2687 (let (indent)
2688 (if (and (save-excursion
2689 (beginning-of-line) (skip-chars-forward "\t ")
2690 (not (looking-at "<")))
2691 (save-excursion
2692 (forward-line -1)
2693 (while (and (not (bobp)) (looking-at "^\\s *$"))
2694 (forward-line -1))
2695 (skip-chars-forward "\t ")
2696 (setq indent (current-column))
2697 (not (looking-at "<"))))
2698 (progn
2699 (save-excursion
2700 (beginning-of-line)
2701 (skip-chars-forward " \t")
2702 (or (= (current-column) indent)
2703 (YaTeX-reindent indent)))
2704 (and (bolp) (skip-chars-forward " \t")))
2705 (yahtml-indent-line-real))))
2707 (defun yahtml-indent-line ()
2708 "Indent a line (Second level wrapper).
2709 See also yahtml-indent-line-1 and yahtml-indent-line-real."
2710 (interactive)
2711 (let ((cc (current-column)) (p (point)))
2712 (yahtml-indent-line-1)
2713 (and (= cc (current-column))
2714 (= p (point))
2715 (equal last-command 'yahtml-indent-line)
2716 (yahtml-forward-field 1))))
2719 (defun yahtml-this-indent ()
2720 (let ((envs "[uod]l\\|table\\|[ht][rhd0-6]\\|select\\|blockquote\\|center\\|menu\\|dir\\|d[td]\\|li")
2721 (itemizing-envs "^\\([uod]l\\|menu\\|dir\\|li\\|d[td]\\)$")
2722 (itms "<\\(dt\\|dd\\|li\\|t[rdh]\\|option\\)\\b")
2723 (excludes
2724 "\\b\\(a\\|p\\|span\\|code\\|tt\\|em\\|u\\|i\\|big\\|small\\|font\\)\\b")
2725 inenv p col peol (case-fold-search t))
2726 (save-excursion
2727 (beginning-of-line)
2728 (setq inenv (or (yahtml-inner-environment-but excludes t)
2729 "html")
2730 col (get 'YaTeX-inner-environment 'indent)
2731 p (get 'YaTeX-inner-environment 'point)
2732 op nil))
2733 (save-excursion
2734 (cond
2735 ((string-match (concat "^\\(" envs "\\)") inenv)
2736 (save-excursion
2737 (beginning-of-line)
2738 (skip-chars-forward " \t")
2739 (cond ;lookup current line's tag
2740 ((looking-at (concat "</\\(" envs "\\)>"))
2741 col)
2742 ((looking-at itms)
2743 (+ col yahtml-environment-indent))
2744 ((and yahtml-hate-too-deep-indentation
2745 (looking-at (concat "<\\(" envs "\\)")))
2746 (+ col (* 2 yahtml-environment-indent)))
2747 ((and (< p (point))
2748 (string-match itemizing-envs inenv)
2749 (save-excursion
2750 (and
2751 (setq op (point))
2752 (goto-char p)
2753 (re-search-forward itms op t)
2754 (progn
2755 (if yahtml-indent-listing-constant
2756 (setq col (+ (current-column)
2757 (if yahtml-faithful-to-htmllint 1 2)))
2758 (skip-chars-forward "^>")
2759 (skip-chars-forward ">")
2760 (skip-chars-forward " \t")
2761 (setq col (if (looking-at "$")
2762 (+ col yahtml-environment-indent)
2763 (current-column))))))))
2764 col)
2765 (t
2766 (+ col yahtml-environment-indent)))))
2767 (t col)))))
2769 (defun yahtml-indent-line-real ()
2770 "Indent current line."
2771 (interactive)
2772 (YaTeX-reindent (yahtml-this-indent))
2773 (if (bolp) (skip-chars-forward " \t"))
2774 (let (peol col inenv)
2775 (if (and (setq inenv (yahtml-on-begend-p))
2776 (string-match
2777 (concat "^\\<\\(" yahtml-struct-name-regexp "\\)") inenv))
2778 (save-excursion
2779 (setq peol (point-end-of-line))
2780 (or (= (char-after (point)) ?<)
2781 (progn (skip-chars-backward "^<") (forward-char -1)))
2782 (setq col (current-column))
2783 (if (and (yahtml-goto-corresponding-begend t)
2784 (> (point) peol)) ;if on the different line
2785 (YaTeX-reindent col))))))
2787 ;(defun yahtml-fill-item ()
2788 ; "Fill item HTML version"
2789 ; (interactive)
2790 ; (let (inenv p fill-prefix peol (case-fold-search t))
2791 ; (setq inenv (or (YaTeX-inner-environment) "html")
2792 ; p (get 'YaTeX-inner-environment 'point))
2793 ; (cond
2794 ; ((string-match "^[uod]l" inenv)
2795 ; (save-excursion
2796 ; (if (re-search-backward "<\\(d[td]\\|li\\)>[ \t\n]*" p t)
2797 ; (progn
2798 ; (goto-char (match-end 0))
2799 ; (setq col (current-column)))
2800 ; (error "No <li>, <dt>, <dd>")))
2801 ; (save-excursion
2802 ; (end-of-line)
2803 ; (setq peol (point))
2804 ; (newline)
2805 ; (indent-to-column col)
2806 ; (setq fill-prefix (buffer-substring (point) (1+ peol)))
2807 ; (delete-region (point) peol)
2808 ; (fill-region-as-paragraph
2809 ; (progn (re-search-backward paragraph-start nil t) (point))
2810 ; (progn (re-search-forward paragraph-start nil t 2)
2811 ; (match-beginning 0)))))
2812 ; (t nil))))
2814 ;;;
2815 ;;; ---------- Lint and Browsing ----------
2816 ;;;
2817 (defun yahtml-browse-menu ()
2818 "Browsing or other external process invokation menu."
2819 (interactive)
2820 (message "J)weblint p)Browse R)eload N)ewpage...")
2821 (let ((c (char-to-string (read-char))))
2822 (cond
2823 ((string-match "j" c)
2824 (yahtml-lint-buffer (current-buffer)))
2825 ((string-match "[bp]" c)
2826 (yahtml-browse-current-file))
2827 ((string-match "r" c)
2828 (yahtml-browse-reload))
2829 ((string-match "n" c)
2830 (call-interactively 'yahtml-newpage)))))
2832 (if (fboundp 'wrap-function-to-control-ime)
2833 (wrap-function-to-control-ime 'yahtml-browse-menu t nil))
2835 (defvar yahtml-lint-buffer "*weblint*")
2837 (defun yahtml-lint-buffer (buf)
2838 "Call lint on buffer BUF."
2839 (require 'yatexprc)
2840 (interactive "bCall lint on buffer: ")
2841 (setq buf (get-buffer buf))
2842 (YaTeX-save-buffers)
2843 (let ((bcmd (YaTeX-get-builtin "lint")))
2844 (and bcmd (setq bcmd (yahtml-untranslate-string bcmd)))
2845 (YaTeX-typeset
2846 (concat (or bcmd yahtml-lint-program)
2847 " " (file-name-nondirectory (buffer-file-name buf)))
2848 yahtml-lint-buffer "lint" "lint")))
2850 (defun yahtml-file-to-url (file)
2851 "Convert local unix file name to URL.
2852 If no matches found in yahtml-path-url-alist, return raw file name."
2853 (let ((list yahtml-path-url-alist) p url)
2854 (if (file-directory-p file)
2855 (setq file (expand-file-name yahtml-directory-index file))
2856 (setq file (expand-file-name file)))
2857 (if (string-match "^[A-Za-z]:/" file)
2858 (progn
2859 ;; (aset file 1 ?|) ;これは要らないらしい…
2860 (setq file (concat "///" file))))
2861 (while list
2862 (if (string-match (concat "^" (regexp-quote (car (car list)))) file)
2863 (setq url (cdr (car list))
2864 file (substring file (match-end 0))
2865 url (concat url file)
2866 list nil))
2867 (setq list (cdr list)))
2868 (or url (concat "file:" file))))
2870 (defun yahtml-url-to-path (file &optional basedir)
2871 "Convert local URL name to unix file name."
2872 (let ((list yahtml-path-url-alist) url realpath docroot
2873 (dirsufp (string-match "/$" file)))
2874 (setq basedir (or basedir
2875 (file-name-directory
2876 (expand-file-name default-directory))))
2877 (cond
2878 ((string-match "^/" file)
2879 (while list
2880 (if (file-directory-p (car (car list)))
2881 (progn
2882 (setq url (cdr (car list)))
2883 (if (string-match "\\(https?://[^/]*\\)/" url)
2884 (setq docroot (substring url (match-end 1)))
2885 (setq docroot url))
2886 (cond
2887 ((string-match (concat "^" (regexp-quote docroot)) file)
2888 (setq realpath
2889 (expand-file-name
2890 (substring
2891 file
2892 (if (= (aref file (1- (match-end 0))) ?/)
2893 (match-end 0) ; "/foo"
2894 (min (1+ (match-end 0)) (length file)))) ; "/~foo"
2895 (car (car list))))))
2896 (if realpath
2897 (progn (setq list nil)
2898 (if (and dirsufp (not (string-match "/$" realpath)))
2899 (setq realpath (concat realpath "/")))))))
2900 (setq list (cdr list)))
2901 realpath)
2902 (t file))))
2904 (defun yahtml-browse-current-file ()
2905 "Call WWW browser on current file."
2906 (interactive)
2907 (basic-save-buffer)
2908 (yahtml-browse-html (yahtml-file-to-url (buffer-file-name))))
2910 (defun yahtml-browse-reload ()
2911 "Send `reload' event to netscape."
2912 (let ((pb "* WWW Browser *") (cb (current-buffer)))
2913 (cond
2914 ((string-match "[Nn]etscape" yahtml-www-browser)
2915 (if (get-buffer pb)
2916 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
2917 ;;(or (get 'yahtml-netscape-sentinel 'url)
2918 ;; (error "Reload should be called after Browsing."))
2919 (put 'yahtml-netscape-sentinel 'url
2920 (yahtml-file-to-url (buffer-file-name)))
2921 (basic-save-buffer)
2922 (set-process-sentinel
2923 (setq yahtml-browser-process
2924 (start-process
2925 "browser" pb shell-file-name yahtml-shell-command-option ;"-c"
2926 (format "%s -remote 'reload'" yahtml-www-browser)))
2927 'yahtml-netscape-sentinel))
2928 (t
2929 (message "Sorry, RELOAD is supported only for Netscape.")))))
2931 ;;; ---------- Intelligent newline ----------
2932 (defun yahtml-intelligent-newline (arg)
2933 "Intelligent newline for HTML"
2934 (interactive "P")
2935 (let (env func)
2936 (end-of-line)
2937 (setq env (downcase (or (yahtml-inner-environment-but "^\\(a\\|p\\)\\b" t)
2938 "html")))
2939 (setq func (intern-soft (concat "yahtml-intelligent-newline-" env)))
2940 (newline)
2941 (if (and env func (fboundp func))
2942 ;; if intelligent line function is defined, call that
2943 (funcall func)
2944 ;; else do the default action
2945 (if (string-match yahtml-p-prefered-env-regexp env)
2946 (yahtml-insert-p)))))
2948 (defun yahtml-intelligent-newline-ul ()
2949 (interactive)
2950 (yahtml-insert-single "li")
2951 (or yahtml-always-/li yahtml-faithful-to-htmllint (insert " "))
2952 (yahtml-indent-line))
2954 (fset 'yahtml-intelligent-newline-ol 'yahtml-intelligent-newline-ul)
2956 (defun yahtml-intelligent-newline-datalist ()
2957 (interactive)
2958 (yahtml-insert-form "option")
2959 (save-excursion (yahtml-insert-form "/option")))
2961 (defun yahtml-intelligent-newline-dl ()
2962 (interactive)
2963 (let ((case-fold-search t))
2964 (if (save-excursion
2965 (re-search-backward "<\\(\\(dt\\)\\|\\(dd\\)\\)[ \t>]"
2966 (get 'YaTeX-inner-environment 'point) t))
2967 (cond
2968 ((match-beginning 2)
2969 (yahtml-insert-single "dd")
2970 (or yahtml-always-/dd yahtml-faithful-to-htmllint (insert " "))
2971 (setq yahtml-last-single-cmd "dt"))
2972 ((match-beginning 3)
2973 (yahtml-insert-single "dt")
2974 (or yahtml-always-/dt yahtml-faithful-to-htmllint (insert " "))
2975 (setq yahtml-last-single-cmd "dd")))
2976 (yahtml-insert-single "dt")
2977 (or yahtml-always-/li yahtml-faithful-to-htmllint (insert " "))
2978 (setq yahtml-last-single-cmd "dd"))
2979 (yahtml-indent-line)
2980 (and (string-match yahtml-p-prefered-env-regexp "dl")
2981 (string-equal yahtml-last-single-cmd "dt")
2982 (yahtml-insert-p nil))))
2984 (defun yahtml-intelligent-newline-select ()
2985 (interactive)
2986 (yahtml-insert-single (if yahtml-prefer-upcases "OPTION" "option"))
2987 (yahtml-indent-line))
2989 (defun yahtml-intelligent-newline-style ()
2990 (interactive)
2991 (if (save-excursion
2992 (and
2993 (re-search-backward "<style\\|<!-- " nil t)
2994 (looking-at "<style")))
2995 (let (c)
2996 (yahtml-indent-line)
2997 (setq c (current-column))
2998 (insert "<!--\n")
2999 (YaTeX-reindent c)
3000 (insert "-->")
3001 (beginning-of-line)
3002 (open-line 1)
3003 (YaTeX-reindent c))))
3005 (defun yahtml-intelligent-newline-head ()
3006 (let ((title (read-string-with-history "Document title: "))
3007 (b "<title>") (e "</title>") p)
3008 (yahtml-indent-line)
3009 (insert (format "%s" (if yahtml-prefer-upcases (upcase b) b)))
3010 (setq p (point))
3011 (insert (format "%s%s" title (if yahtml-prefer-upcases (upcase e) e)))
3012 (if (string= "" title) (goto-char p))
3013 (setq yahtml-last-begend "body")))
3015 (defun yahtml-intelligent-newline-script ()
3016 (let ((p (point)) b)
3017 (if (save-excursion
3018 (and
3019 (setq b (re-search-backward "<script\\>" nil t))
3020 (re-search-forward
3021 "\\(javascript\\)\\|\\(tcl\\)\\|\\(vbscript\\)" p t)))
3022 (let ((js (match-end 1)) (tcl (match-end 2)) (vb (match-end 3))
3023 c (srcp (re-search-backward "src=" b t)))
3024 (goto-char p)
3025 (yahtml-indent-line)
3026 (setq c (current-column))
3027 (if srcp
3028 nil
3029 (insert "<!--\n" (cond (js "//") (tcl "#") (vb "'")) " -->")
3030 (beginning-of-line)
3031 (open-line 1)
3032 (YaTeX-reindent c))))))
3034 (defun yahtml-intelligent-newline-table ()
3035 (let ((cp (point)) (p (point)) tb rb (cols 0) th line (i 0) fmt
3036 (ptn "\\(<t[dh]\\>\\)\\|<t\\(r\\|head\\|body\\)\\>"))
3037 (cond
3038 ((save-excursion (setq tb (YaTeX-beginning-of-environment "table")))
3039 (while (and (setq rb (re-search-backward ptn tb t))
3040 (match-beginning 1))
3041 (setq th (looking-at "<th")) ;Remember if first-child is tr or not
3042 (goto-char (match-end 0))
3043 (skip-chars-forward " \t\n")
3044 (if (and (search-forward "colspan\\s *=" p t)
3045 (progn
3046 (skip-chars-forward "\"' \t\n")
3047 (looking-at "[0-9]+")))
3048 (setq cols (+ (YaTeX-str2int (YaTeX-match-string 0)) cols))
3049 (setq cols (1+ cols)))
3050 (goto-char rb)
3051 (setq p (point)))
3052 (if (> cols 0)
3053 (message "%s columns found. %s"
3054 cols (if YaTeX-japan "新しいtr(N)? 前のtrの複写?(D)?: "
3055 "New tr?(N) or Duplicate")))
3056 (cond
3057 ((and (> cols 0)
3058 (memq (read-char) '(?d ?D))) ;Duplication mode
3059 (setq line (YaTeX-buffer-substring (point) (1- cp))))
3060 (t ;empty cells
3061 (setq line "<tr>" i 0)
3062 (if (> cols 0)
3063 (while (> cols i)
3064 (setq line (concat line (if (and (= i 0) th) "<th></th>"
3065 "<td></td>"))
3066 th nil i (1+ i)))
3067 (setq fmt (read-string-with-history
3068 "`th' or `td' format: " "th td td"))
3069 (while (string-match "t\\(h\\)\\|td" fmt i)
3070 (setq line (concat line (if (match-beginning 1) "<th></th>"
3071 "<td></td>"))
3072 i (match-end 0))))
3073 (setq line (concat line "</tr>"))))
3074 (goto-char cp)
3075 (if th
3076 (message
3077 "Type `%s' to change td from/to th."
3078 (key-description (car (where-is-internal 'yahtml-change-*)))))
3079 (if (string< "" line)
3080 (progn
3081 (insert line)
3082 (goto-char (+ 8 cp))
3083 (yahtml-indent-line)))))))
3085 (defun yahtml-intelligent-newline-audio ()
3086 (let (b e)
3087 (if (save-excursion
3088 (goto-char (setq b (get 'YaTeX-inner-environment 'point)))
3089 (forward-list 1)
3090 (setq e (point))
3091 (catch 'src
3092 (while (re-search-forward "\\s src\\>" e t)
3093 (skip-chars-forward " \t\n")
3094 (and (looking-at "=") (throw 'src t)))))
3095 ;; if src= attribute found, do nothing
3096 (setq yahtml-last-begend "p")
3097 (yahtml-insert-single "source")
3098 )))
3099 (fset 'yahtml-intelligent-newline-video 'yahtml-intelligent-newline-audio)
3101 (defun yahtml-intelligent-newline-iframe ()
3102 (insert "<p>Your browser does not support iframes.</p>"))
3104 ;;; ---------- Marking ----------
3105 (defun yahtml-mark-begend ()
3106 "Mark current tag"
3107 (interactive)
3108 (YaTeX-beginning-of-environment)
3109 (let ((p (point)))
3110 (save-excursion
3111 (skip-chars-backward " \t" (point-beginning-of-line))
3112 (if (bolp) (setq p (point))))
3113 (push-mark p t))
3114 (yahtml-goto-corresponding-begend)
3115 (forward-list 1)
3116 (if (eolp) (forward-char 1)))
3118 ;;; ---------- complete marks ----------
3119 (defun yahtml-char-entity-ref ()
3120 "Complete &gt;, &lt;, &amp;, and &quot;."
3121 (interactive)
3122 (message "1:< 2:> 3:& 4:\" 5:' 6:nbsp")
3123 (let ((c (read-char)) d)
3124 (setq d (if (or (< c ?0) (> c ?7))
3125 (string-match (regexp-quote (char-to-string c)) "<>&\"' ")
3126 (- c ?1)))
3127 (cond
3128 ((null d) (insert (format "&#x%x;" c)))
3129 ((and (>= d 0) (<= d 6))
3130 (insert (format "&%s;"
3131 (nth d '("lt" "gt" "amp" "quot" "apos" "nbsp"))))))))
3134 ;;; ---------- jump to error line ----------
3135 (defun yahtml-prev-error ()
3136 "Jump to previous error seeing lint buffer."
3137 (interactive)
3138 (or (get-buffer yahtml-lint-buffer)
3139 (error "No lint program ran."))
3140 (YaTeX-showup-buffer yahtml-lint-buffer nil t)
3141 (yahtml-jump-to-error-line t))
3143 (defun yahtml-jump-to-error-line (&optional sit)
3144 (interactive "P")
3145 (let ((p (point)) (e (point-end-of-line)))
3146 (end-of-line)
3147 (if (re-search-backward yahtml-error-line-regexp nil t)
3148 (let ((f (if (string= "" (YaTeX-match-string 1))
3149 YaTeX-current-file-name
3150 (YaTeX-match-string 1)))
3151 (l (YaTeX-str2int (or (YaTeX-match-string 2)
3152 (YaTeX-match-string 3)))))
3153 (if sit (sit-for 1))
3154 (forward-line -1)
3155 (YaTeX-showup-buffer (YaTeX-switch-to-buffer f t) nil t)
3156 (goto-line l))
3157 (message "No line number usage"))))
3159 ;;; ---------- Style Sheet Support ----------
3160 (defvar yahtml-css-class-alist nil
3161 "Alist of elements vs. their classes")
3163 (defun yahtml-css-collect-classes-region (beg end &optional initial)
3164 (save-excursion
3165 (save-restriction
3166 (narrow-to-region beg end)
3167 (goto-char (point-min))
3168 (let ((alist initial) b e element class a)
3169 (setq b (point))
3170 (while (re-search-forward "\\({\\)\\|\\(@import\\)" nil t)
3171 (if (match-beginning 2)
3172 (let ((f (YaTeX-buffer-substring
3173 (progn (skip-chars-forward "^\"")(1+ (point)))
3174 (progn (forward-char 1)
3175 (skip-chars-forward "^\"")(point)))))
3176 (if (file-exists-p f)
3177 (setq alist
3178 (append alist (yahtml-css-collect-classes-file
3179 f initial)))))
3180 (setq e (point))
3181 (goto-char b)
3182 (while (re-search-forward ;ちょといい加減なREGEXP
3183 "\\([a-z*][-a-z0-9]*\\)?\\.\\([-a-z0-9][-a-z0-9]*\\)\\>"
3184 e t)
3185 (setq element (YaTeX-match-string 1)
3186 class (YaTeX-match-string 2))
3187 ;;if starts with period (match-string 1 is nil),
3188 ;;this is global class
3189 (setq element (downcase (or element "*")))
3190 (if (setq a (assoc element alist))
3191 (or (assoc class (cdr a))
3192 (setcdr a (cons (list class) (cdr a))))
3193 (setq alist (cons (list element (list class)) alist))))
3194 (goto-char (1- e))
3195 (search-forward "}" nil 1) ;1=move to limit when not found.
3196 (setq b (point))))
3197 alist))))
3199 (defun yahtml-css-collect-classes-buffer (&optional initial)
3200 (interactive)
3201 (yahtml-css-collect-classes-region (point-min) (point-max) initial))
3203 (defun yahtml-css-collect-classes-file (file &optional initial)
3204 (let*((hilit-auto-highlight nil)
3205 (buf (get-buffer-create
3206 (format " *css-collection*%s" (file-name-nondirectory file))))
3207 (cb (current-buffer)))
3208 (unwind-protect
3209 (progn
3210 (set-buffer buf)
3211 (insert-file-contents file)
3212 (cd (or (file-name-directory file) "."))
3213 (yahtml-css-collect-classes-buffer initial))
3214 (if (eq buf cb)
3215 nil
3216 (kill-buffer buf)
3217 (set-buffer cb)))))
3219 (defun yahtml-css-scan-styles ()
3220 (save-excursion
3221 (goto-char (point-min))
3222 (set (make-local-variable 'yahtml-css-class-alist) nil)
3223 (let (b tag type e href alist)
3224 (while (re-search-forward "<\\(style\\|link\\)" nil t)
3225 (setq b (match-beginning 0)
3226 tag (YaTeX-match-string 1))
3227 (cond
3228 ((string-match "style" tag)
3229 (goto-char b)
3230 (save-excursion (forward-list 1) (setq e (point)))
3231 (cond
3232 ((search-forward "text/css" e 1) ;css definition starts
3233 (setq alist
3234 (yahtml-css-collect-classes-region
3235 (point) (progn (search-forward "</style>") (point))
3236 alist)))))
3237 ((and (string-match "link" tag)
3238 (stringp (setq type (yahtml-get-attrvalue "type")))
3239 (string-match "text/css" type)
3240 (setq href (yahtml-get-attrvalue "href"))
3241 (file-exists-p (yahtml-url-to-path href)))
3242 (setq alist
3243 (yahtml-css-collect-classes-file
3244 (yahtml-url-to-path href) alist))))
3245 (setq yahtml-css-class-alist alist)))))
3247 (defun yahtml-css-get-element-completion-alist (element)
3248 (let ((alist (cdr-safe (assoc (downcase element) yahtml-css-class-alist)))
3249 (global (cdr-safe (assoc "*" yahtml-css-class-alist))))
3250 (and (or alist global)
3251 (append alist global))))
3253 ;;; ---------- ----------
3255 ;;;
3256 ;;hilit19
3257 ;;;
3258 (defvar yahtml-default-face-table
3259 '(
3260 (form black/ivory white/hex-442233 italic)
3261 ))
3262 (defvar yahtml-hilit-patterns-alist
3263 '(
3264 'case-fold
3265 ;; comments
3266 ("<!--\\s " "-->" comment)
3267 ;; include&exec
3268 ("<!--#\\(include\\|exec\\|config\\|fsize\\|flastmod\\)" "-->" include)
3269 ;; string
3270 (hilit-string-find ?\\ string)
3271 (yahtml-hilit-region-tag "<\\(strong\\|b\\)\\>" bold)
3272 ("</?[uod]l>" 0 decl)
3273 ("<\\(di\\|dt\\|li\\|dd\\)>" 0 label)
3274 (yahtml-hilit-region-tag "<\\(em\\|i\\>\\)" italic)
3275 ;("<a\\s +href" "</a>" crossref) ;good for hilit19, but odd for font-lock..
3276 (yahtml-hilit-region-tag "<\\(a\\)\\s +href" crossref)
3277 (yahtml-hilit-region-tag-itself "</?\\sw+\\>" decl)
3278 ))
3280 (defun yahtml-hilit-region-tag (tag)
3281 "Return list of start/end point of <TAG> form."
3282 (if (re-search-forward tag nil t)
3283 (let ((m0 (match-beginning 0)) (e0 (match-end 0))
3284 (elm (YaTeX-match-string 1)))
3285 (skip-chars-forward "^>")
3286 (prog1
3287 (cons (1+ (point))
3288 (progn (re-search-forward (concat "</" elm ">") nil t)
3289 (match-beginning 0)))
3290 (goto-char e0)))))
3292 (defun yahtml-hilit-region-tag-itself (ptn)
3293 "Return list of start/end point of <tag options...> itself."
3294 (if (re-search-forward ptn nil t)
3295 (let ((m0 (match-beginning 0)) (e0 (match-end 0)))
3296 (skip-chars-forward "^<>")
3297 (if (eq (char-after (point)) ?<) nil
3298 (prog1
3299 (cons m0 (min (point-max) (1+ (point))))
3300 (goto-char e0))))))
3302 ;(setq hilit-patterns-alist (delq (assq 'yahtml-mode hilit-patterns-alist) hilit-patterns-alist))
3303 (and yahtml-use-hilit19
3304 (or (assq 'yahtml-mode hilit-patterns-alist)
3305 (setq hilit-patterns-alist
3306 (cons (cons 'yahtml-mode yahtml-hilit-patterns-alist)
3307 hilit-patterns-alist))))
3308 ;;;
3309 ;; for font-lock
3310 ;;;
3312 ; <<STATIC KEYWORDS BELOW NOT USED>>
3313 ;(defvar yahtml-font-lock-keywords
3314 ; '(
3315 ; ;; comments
3316 ; ("<!--\\s .* -->" . font-lock-comment-face)
3317 ; ;; include&exec
3318 ; ("<!--#\\(include\\|exec\\|config\\|fsize\\|flastmod\\).*-->"
3319 ; 0 font-lock-include-face keep)
3320 ; ;; string
3321 ; ;(hilit-string-find ?\\ string)
3322 ; ;(yahtml-hilit-region-tag "\\(em\\|strong\\)" bold)
3323 ; ("</?[uod]l>" 0 font-lock-keyword-face)
3324 ; ("<\\(di\\|dt\\|li\\|dd\\)>" 0 font-lock-label-face)
3325 ; ("<a\\s +href=.*</a>" (0 font-lock-crossref-face keep))
3326 ; ;(yahtml-hilit-region-tag-itself "</?\\sw+\\>" decl)
3327 ; ("</?\\sw+\\>" (yahtml-fontify-to-tagend nil nil))
3328 ; )
3329 ; "*Defualt font-lock-keywords for yahtml-mode.")
3330 (defvar yahtml-font-lock-keywords
3331 (YaTeX-convert-pattern-hilit2fontlock yahtml-hilit-patterns-alist)
3332 "Default fontifying patterns for yahtml-mode")
3334 (defun yahtml-font-lock-set-default-keywords ()
3335 (put 'yahtml-mode 'font-lock-defaults
3336 '(yahtml-font-lock-keywords nil t)))
3338 (if yahtml-use-font-lock
3339 (progn
3340 (if (and (boundp 'hilit-mode-enable-list) hilit-mode-enable-list)
3341 ;;for those who use both hilit19 and font-lock
3342 (if (eq (car hilit-mode-enable-list) 'not)
3343 (or (member 'yahtml-mode hilit-mode-enable-list)
3344 (nconc hilit-mode-enable-list (list 'yahtml-mode)))
3345 (setq hilit-mode-enable-list
3346 (delq 'yahtml-mode hilit-mode-enable-list))))
3347 (yahtml-font-lock-set-default-keywords)))
3349 (defun yahtml-font-lock-recenter (&optional arg)
3350 (interactive "P")
3351 (font-lock-mode -1) ;is stupid, but sure.
3352 (font-lock-mode 1))
3354 ;;;
3355 ;; Drag-n-Drop
3356 ;;;
3357 (defun yahtml-dnd-handler (uri action)
3358 "DnD handler for yahtml mode
3359 Convert image URI to img-src and others to a-href."
3360 (let*((file (dnd-get-local-file-name uri))
3361 (path (if file (file-relative-name file) uri))
3362 (case-fold-search t)
3363 (geom ""))
3364 (cond
3365 ((memq action '(copy link move private))
3366 (cond
3367 ((string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\|tiff?\\)$" path)
3368 (if file
3369 (setq geom (yahtml-get-image-info path)
3370 geom (if (car geom)
3371 (apply 'format " width=\"%s\" height=\"%s\"" geom)
3372 "")))
3373 (insert (format "<img src=\"%s\" alt=\"%s\"%s>"
3374 path (file-name-nondirectory path) geom)))
3376 (t (insert (format "<a href=\"%s\"></a>" path))
3377 (forward-char -4))))
3378 (t (message "No handler for action `%s'" action))))
3379 action)
3381 (run-hooks 'yahtml-load-hook)
3382 (provide 'yahtml)
3384 ; Local variables:
3385 ; fill-prefix: ";;; "
3386 ; paragraph-start: "^$\\| \\|;;;$"
3387 ; paragraph-separate: "^$\\| \\|;;;$"
3388 ; End: