yatex

view yahtml.el @ 584:907de32064c9

Add add-in for spacing environment from setspace package
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 04 Dec 2021 07:12:33 +0900
parents 9e07513fc2ef
children 722004cc4375
line source
1 ;;; yahtml.el --- Yet Another HTML mode -*- coding: sjis -*-
2 ;;; (c) 1994-2019 by HIROSE Yuuji [yuuji(@)yatex.org]
3 ;;; $Id$
5 (defconst yahtml-revision-number "1.80.1"
6 "Revision number of running yahtml.el")
8 ;;; Commentary:
10 ;;;[Installation]
11 ;;;
12 ;;; First, you have to install YaTeX and make sure it works fine. Then
13 ;;; put these expressions into your ~/.emacs
14 ;;;
15 ;;; (setq auto-mode-alist
16 ;;; (cons (cons "\\.html$" 'yahtml-mode) auto-mode-alist))
17 ;;; (autoload 'yahtml-mode "yahtml" "Yet Another HTML mode" t)
18 ;;; (setq yahtml-www-browser "firefox")
19 ;;; ;Write your favorite browser. But firefox is advantageous.
20 ;;; (setq yahtml-path-url-alist
21 ;;; '(("/home/yuuji/public_html" . "http://www.mynet/~yuuji")
22 ;;; ("/home/staff/yuuji/html" . "http://www.othernet/~yuuji")))
23 ;;; ;Write correspondence alist from ABSOLUTE unix path name to URL path.
24 ;;;
25 ;;;[インストール方法]
26 ;;;
27 ;;; yahtml.el, yatexlib.el, yatexprc.el を load-path の通ったディレクト
28 ;;; リにインストールしてください。その後、以下を参考に ~/.emacs に設定を
29 ;;; 追加して下さい。
30 ;;;
31 ;;; (setq auto-mode-alist
32 ;;; (cons (cons "\\.html$" 'yahtml-mode) auto-mode-alist))
33 ;;; (autoload 'yahtml-mode "yahtml" "Yet Another HTML mode" t)
34 ;;; (setq yahtml-www-browser "firefox")
35 ;;; ;お気に入りのブラウザを書いて下さい。firefoxが便利です。
36 ;;; (setq yahtml-path-url-alist
37 ;;; '(("/home/yuuji/public_html" . "http://www.mynet/~yuuji")
38 ;;; ("/home/staff/yuuji/html" . "http://www.othernet/~yuuji")))
39 ;;; ;UNIXの絶対パスと対応するURLのリストを書いて下さい。
40 ;;;
41 ;;; HTMLファイル漢字コードが正しく判別されるようにホームディレクトリに
42 ;;; .htaccess ファイルを作り以下のどれか1行を選んで書いて下さい。
43 ;;;
44 ;;; AddType "text/html; charset=Shift_JIS" .html (SJISの場合)
45 ;;; AddType "text/html; charset=iso2022-jp" .html (JISの場合)
46 ;;; AddType "text/html; charset=EUC-JP" .html (EUCの場合)
47 ;;; AddType "text/html; charset=utf-8" .html (UTF-8の場合)
48 ;;;
49 ;;; .htaccess が作れない場合は
50 ;;; (setq yahtml-kanji-code 2)
51 ;;; ;HTMLファイルの漢字コードを変更する場合は
52 ;;; ;1=SJIS、2=JIS、3=EUC 4=UTF-8
53 ;;; ;で設定して下さい。デフォルトは 4 です。
54 ;;;
55 ;;; を適切に書き換えて ~/.emacs に足して下さい。
56 ;;;
57 ;;;[Commentary]
58 ;;;
59 ;;; It is assumed you are already familiar with YaTeX. The following
60 ;;; completing featureas are available: ([prefix] means `C-c' by default)
61 ;;;
62 ;;; * [prefix] b X Complete environments such as `H1' which
63 ;;; normally requires closing tag `</H1>
64 ;;; <a href=foo> ... </a> is also classified into
65 ;;; this group
66 ;;; When input `href=...', you can complete file
67 ;;; name or label(href="#foo") by typing TAB.
68 ;;; * [prefix] l Complete typeface-changing commands such as
69 ;;; `<i> ... </i>' or `<samp> ... </samp>'
70 ;;; This completion can be used to make in-line
71 ;;; tags which is normally completed with [prefix] b.
72 ;;; * [prefix] s Complete declarative notations such as
73 ;;; `<img src="foo.gif">'
74 ;;; `<input name="var" ...>'
75 ;;; * [prefix] m Complete single commands such as
76 ;;; `<br>' or `<hr> or <li>...'
77 ;;; * [prefix] p Insert <p></p> on the point
78 ;;; * M-RET Intelligent newline; if current TAG is one of
79 ;;; ul, ol, or dl. insert newline and <li> or
80 ;;; <dt> or <dd> suitable for current condition.
81 ;;; * menu-bar yahtml Complete all by selecting a menu item (Though I
82 ;;; hate menu, this is most useful)
83 ;;; * [prefix] g Goto corresponding Tag or HREF such as
84 ;;; <dl> <-> </dl> or href="xxx".
85 ;;; Or invoke image viewer if point is on <img src=...>.
86 ;;; * [prefix] k Kill html tags on the point. If you provide
87 ;;; universal-argument, kill surrounded contents too.
88 ;;; * [prefix] c Change html tags on the point.
89 ;;; When typeing [prefix] c on `href="xxx"', you can
90 ;;; change the reference link with completion.
91 ;;; * [prefix] t j Call weblint on current file.
92 ;;; * [prefix] t p View current html with WWW browser
93 ;;; (To activate this, never fail to set the lisp
94 ;;; variable yahtml-www-browser. Recommended value
95 ;;; is "firefox")
96 ;;; * [prefix] a YaTeX's accent mark's equivalent of yahtml.
97 ;;; This function can input $lt, $gt or so.
98 ;;; * [prefix] ; Translate chars of `>', `<', `&', and `"' to
99 ;;; `&gt;', `&lt;', `&amp;', `&quot;' respectively
100 ;;; in the region.
101 ;;; * [prefix] : Do translation opposite to above, in the region.
102 ;;; * [prefix] # Translate unsafe-chars and unreserved-chars to
103 ;;; URLencoded string in the region.
104 ;;;
105 ;;;[キーの説明]
106 ;;;
107 ;;; 以下の説明において、特にカスタマイズをしていない限り、[prefix] は
108 ;;; C-c キーを意味します。
109 ;;;
110 ;;; * [prefix] b X `</H1>' といった終了タグが必要となる`H1'のよう
111 ;;; な環境を補完入力します。<a href=foo> ... </a>
112 ;;; もこのグループです。
113 ;;; `href=...' と入力した後、TABキーを押すことで、
114 ;;; ファイル名や (href="#foo") のようなラベルも補完
115 ;;; できます。
116 ;;; * [prefix] s 以下のような宣言の補完を行います。
117 ;;; `<img src="foo.gif">'
118 ;;; `<input name="var" ...>'
119 ;;; * [prefix] l `<i> ... </i>' や `<samp> ... </samp>' のよう
120 ;;; なテキストスタイル指定のタグを補完します。
121 ;;; この補完機能は通常 [prefix] b で補完できるものを
122 ;;; 一行内で書きたいときにも用いることが出来ます。
123 ;;; * [prefix] m `<br>' や `<hr> '、`<li>' 等の単体タグの補完
124 ;;; を行います。
125 ;;; * [prefix] p カーソル位置に<p></p>を挿入します。
126 ;;; * M-RET おまかせ改行; もしul、ol、dl等のタグ(リスト)を
127 ;;; 使っている場合に、環境に合わせて改行と <li>、
128 ;;; <dt>、<dd>を入力します。
129 ;;; * menu-bar yahtml 選択したアイテムをメニューより補完できます。
130 ;;; (私はメニューが嫌いなんですが、htmlに関してはメ
131 ;;; ニューは一番ありがたいかも)
132 ;;; * [prefix] g 対応するタグ、<dl> <-> </dl> や href="xxx" の
133 ;;; ような TAG にジャンプします。
134 ;;; <img src=...> の場合はイメージビューワを呼び出
135 ;;; します。href=hoge.html の場合はhoge.htmlに飛びま
136 ;;; す。
137 ;;; * [prefix] k ポイント上の HTML タグを消去します。
138 ;;; もし universal-argument を付けた場合(C-uを先に押
139 ;;; す)HTMLタグで囲まれた内容も同時に消去します。
140 ;;; * [prefix] c ポイント上のタグを変更します。
141 ;;; `href="xxx"'の上で [prefix] c を利用した場合は、
142 ;;; 参照しているリンクを補完機能を使いながら変更で
143 ;;; きます。
144 ;;; * [prefix] t j カレントファイルに対して jweblint を呼び出しま
145 ;;; す。ファイル先頭付近に
146 ;;; <!-- #lint コマンド -->
147 ;;; と書いておくとそのコマンドを呼びます。
148 ;;; * [prefix] t p WWW ブラウザでカレントファイルを表示します。
149 ;;; (lisp変数 yahtml-www-browser の設定をお忘れな
150 ;;; く。お推めは "firefox" です)
151 ;;; * [prefix] a YaTeX のアクセント記号補完と同じです。
152 ;;; &lt; &gt; 等が入力できます。
153 ;;; * [prefix] ; 指定したリジョン中の > < & " をそれぞれ
154 ;;; &gt; &lt; &amp; &quot; に変換します。
155 ;;; * [prefix] : 指定したリジョン中で上と逆の変換をします。
156 ;;; * [prefix] # 指定したリジョン中で%エンコードの必要な文字が
157 ;;; あればそれらをエンコードします。
158 ;;; * [prefix] } リジョン内の特定文字区切りのレコードを <td> 並びに
159 ;;; 変換します。C-u (universal-argument) 付きで起動
160 ;;; するとtd以外の任意要素で括ります。thdを指定する
161 ;;; と最初の1つだけth,残りすべてをtdで括ります。
162 ;;; * [prefix] ] リジョン内のすべての行をフィールドごとにtdで括り,
163 ;;; さらに各行をtrで括ります。universal-argument を
164 ;;; 付けるとフィールド括りをtd以外に指定できます。
165 ;;; * [prefix] ESC yahtml-mode を抜け yahtml-mode に入る前に動作し
166 ;;; ていたメジャーモードに戻ります。
167 ;;;
168 ;;; [謝辞]
169 ;;;
170 ;;; fj野鳥の会の皆さんには貴重な助言を頂きました。また、下に示す方々には
171 ;;; 特に大きな協力を頂きました。あわせてここに感謝申し上げます。
172 ;;;
173 ;;; * 横田和也さん(マツダ)
174 ;;; マニュアルの和訳をして頂きました。
175 ;;; * 吉田尚志さん(NTT Data)
176 ;;; Mule for Win32 での動作のさせ方を教えて頂きました。
177 ;;; (というかほとんどやってもらった ^^;)
178 ;;;
180 ;;; Code:
182 (require 'yatexlib)
183 ;;; --- customizable variable starts here ---
184 (defvar yahtml-prefix "\C-c"
185 "*Prefix key stroke of yahtml functions.")
186 (defvar yahtml-image-viewer "display" "*Image viewer program")
187 (defvar yahtml-www-browser "firefox" "*WWW Browser command")
188 (defvar yahtml-kanji-code 4
189 "*Kanji coding system number of html file; 1=sjis, 2=jis, 3=euc, 4=UTF-8")
190 ;;(defvar yahtml-coding-system
191 ;; (cdr (assq yahtml-kanji-code YaTeX-kanji-code-alist))
192 ;; "Kanji coding system")
193 (and (featurep 'mule)
194 (integerp yahtml-kanji-code)
195 (setq yahtml-kanji-code
196 (cdr (assq yahtml-kanji-code YaTeX-kanji-code-alist))))
198 (defvar yahtml-fill-column 72 "*fill culumn used for yahtml-mode")
199 (defvar yahtml-fill-prefix nil "*fill prefix for yahtml-mode")
201 ;;(defvar yahtml-www-server "www" "*Host name of your domain's WWW server")
202 (defvar yahtml-path-url-alist nil
203 "*Alist of unix path name vs. URL name of WWW server.
204 Ex.
205 '((\"/usr/home/yuuji/http\" . \"http://www.comp.ae.keio.ac.jp/~yuuji\")
206 (\"/home/yuuji/http\" . \"http://www.gentei.org/~yuuji\"))")
207 (defvar yahtml-directory-index "index.html"
208 "*Directory index file name;
209 Consult your site's WWW administrator.")
211 (defvar yahtml-environment-indent 1
212 "*Indentation depth of HTML's listing environment")
214 ;; YaTeX-japan is defined in yatexlib.el
215 (defvar yahtml-lint-program (if YaTeX-japan "jweblint" "weblint")
216 "*Program name to lint HTML file")
217 (defvar yahtml-hate-too-deep-indentation nil
218 "*Non-nil for this variable suppress deep indentation in listing environments.")
220 (defvar yahtml-always-/p t
221 "*Those who always use <p> with </p> set this to t.")
222 (defvar yahtml-always-/li nil
223 "*Those who always use <li> with </li> set this to t.")
224 (defvar yahtml-always-/dt nil
225 "*Those who always use <dt> with </dt> set this to t.")
226 (defvar yahtml-always-/dd nil
227 "*Those who always use <dd> with </dd> set this to t.")
229 (defvar yahtml-p-prefered-env-regexp "^\\(body\\|dl\\|blockquote\\)"
230 "*Regexp of envs where paragraphed sentences are prefered.")
232 (defvar yahtml-template-file "~/public_html/template.html"
233 "*Template HTML file. It'll be inserted to empty file.")
235 (defvar yahtml-prefer-upcases nil
236 "*Non-nil for preferring upcase TAGs")
238 (defvar yahtml-prefer-upcase-attributes nil
239 "*Non-nil for preferring upcase attributes")
241 (defvar yahtml-server-type 'apache "*WWW server program type")
243 (defvar yahtml-apache-access-file ".htaccess"
244 "*Server access file name for apache")
246 (defvar yahtml-use-css t "*Use stylesheet or not")
248 (defvar yahtml-image-inspection-bytes 500000
249 "*Number of bytes to inspect the image for geometry information")
250 (defvar yahtml:img-default-alt-format "%xx%y(%sbytes)"
251 "*Default format of img entity's ALT attributes.
252 %x: width, %y: height, %s: size in bytes, %c: first comment string,
253 %f: filename")
255 (defvar yahtml-faithful-to-htmllint yahtml-always-/li
256 "*Non-nil doesn't put space after opening tags.")
258 (defvar yahtml-error-line-regexp
259 "^\\(.*\\)(\\([0-9]+\\)):\\|^line \\([0-9]+\\)"
260 "*Regexp of error position which is produced by lint program.")
262 (defvar yahtml-translate-hyphens-when-comment-region t
263 "*Non-nil for translate hyphens to &#45; when comment-region")
264 (defvar yahtml-escape-chars 'ask
265 "*Escape reserved characters to URL-encoding or not.
266 Nil for never, t for everytime, and 'ask for inquiring
267 at each reserved chars.")
269 (defvar yahtml-use-font-lock (and (featurep 'font-lock)
270 (fboundp 'font-lock-fontify-region))
271 "*Non-nil means to use font-lock to fontify buffer.")
273 (defvar yahtml-use-hilit19 (and (featurep 'hilit19)
274 (not yahtml-use-font-lock))
275 "*Non-nil means to Use hilit19 to highlight buffer")
277 (defvar yahtml-mode-abbrev-table nil
278 "*Abbrev table in use in yahtml-mode buffers.")
279 (define-abbrev-table 'yahtml-mode-abbrev-table ())
281 (defvar yahtml-indentation-boundary "^\\s *<h[1-3]>"
282 "*Boundary regexp for indentation calculation.")
284 (defvar yahtml-html4-strict t
285 "*Non-nil means editing HTML 4.01 Strict.
286 Completing read for obsoleted attributes disabled.")
288 (defvar yahtml-electric-indent-mode -1
289 "*(Emacs 24.4+) Pass this value to electric-indent-local-mode.
290 -1 means `off'.")
292 ;;; --- customizable variable ends here ---
293 (defvar yahtml-prefix-map nil)
294 (defvar yahtml-mode-map nil "Keymap used in yahtml-mode.")
295 (defvar yahtml-lint-buffer-map nil "Keymap used in lint buffer.")
296 (defvar yahtml-shell-command-option
297 (or (and (boundp 'shell-command-option) shell-command-option)
298 (if (eq system-type 'ms-dos) "/c" "-c")))
299 (defvar yahtml-use-highlighting (or yahtml-use-font-lock yahtml-use-hilit19))
301 (defun yahtml-define-begend-key-normal (key env &optional map)
302 "Define short cut yahtml-insert-begend key."
303 (YaTeX-define-key
304 key
305 (list 'lambda '(arg) '(interactive "P")
306 (list 'yahtml-insert-begend 'arg env))
307 map))
309 (defun yahtml-define-begend-region-key (key env &optional map)
310 "Define short cut yahtml-insert-begend-region key."
311 (YaTeX-define-key key (list 'lambda nil '(interactive)
312 (list 'yahtml-insert-begend t env)) map))
314 (defun yahtml-define-begend-key (key env &optional map)
315 "Define short cut key for begin type completion both for
316 normal and region mode. To customize yahtml, user should use this function."
317 (yahtml-define-begend-key-normal key env map)
318 (if YaTeX-inhibit-prefix-letter nil
319 (yahtml-define-begend-region-key
320 (concat (upcase (substring key 0 1)) (substring key 1)) env map)))
322 (if yahtml-mode-map nil
323 (setq yahtml-mode-map (make-sparse-keymap)
324 yahtml-prefix-map (make-sparse-keymap))
325 (define-key yahtml-mode-map yahtml-prefix yahtml-prefix-map)
326 (define-key yahtml-mode-map "\M-\C-@" 'yahtml-mark-begend)
327 (if (and (boundp 'window-system) (eq window-system 'x) YaTeX-emacs-19)
328 (define-key yahtml-mode-map [?\M-\C- ] 'yahtml-mark-begend))
329 (define-key yahtml-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment)
330 (define-key yahtml-mode-map "\M-\C-e" 'YaTeX-end-of-environment)
331 (define-key yahtml-mode-map "\M-\C-m" 'yahtml-intelligent-newline)
332 (define-key yahtml-mode-map "\M-\C-j" 'yahtml-intelligent-newline)
333 (define-key yahtml-mode-map "\C-i" 'yahtml-indent-line)
334 (define-key yahtml-mode-map "&" 'yahtml-insert-amps)
335 (let ((map yahtml-prefix-map))
336 (YaTeX-define-key "^" 'yahtml-visit-main map)
337 (YaTeX-define-key "4^" 'yahtml-visit-main-other-window map)
338 (YaTeX-define-key "4g" 'yahtml-goto-corresponding-*-other-window map)
339 (YaTeX-define-key "44" 'YaTeX-switch-to-window map)
340 (and YaTeX-emacs-19 window-system
341 (progn
342 (YaTeX-define-key "5^" 'yahtml-visit-main-other-frame map)
343 (YaTeX-define-key "5g" 'yahtml-goto-corresponding-*-other-frame map)
344 (YaTeX-define-key "55" 'YaTeX-switch-to-window map)))
345 (YaTeX-define-key "v" 'yahtml-version map)
346 (YaTeX-define-key "s" 'yahtml-insert-form map)
347 (YaTeX-define-key "l" 'yahtml-insert-tag map)
348 (YaTeX-define-key "L" 'yahtml-insert-tag-region map)
349 (YaTeX-define-key "m" 'yahtml-insert-single map)
350 (YaTeX-define-key "n" (function(lambda () (interactive) (insert (if yahtml-prefer-upcases "<BR>" "<br>")))) map)
351 (YaTeX-define-key "-" (function(lambda () (interactive) (insert (if yahtml-prefer-upcases "<HR>" "<hr>") "\n"))) map)
352 (YaTeX-define-key "p" 'yahtml-insert-p map)
353 (if YaTeX-no-begend-shortcut
354 (progn
355 (YaTeX-define-key "B" 'yahtml-insert-begend-region map)
356 (YaTeX-define-key "b" 'yahtml-insert-begend map))
357 (yahtml-define-begend-key "bh" "html" map)
358 (yahtml-define-begend-key "bH" "head" map)
359 (yahtml-define-begend-key "bt" "title" map)
360 (yahtml-define-begend-key "bT" "table" map)
361 (yahtml-define-begend-key "bb" "body" map)
362 (yahtml-define-begend-key "bc" "center" map)
363 (yahtml-define-begend-key "bd" "dl" map)
364 (yahtml-define-begend-key "bD" "div" map)
365 (yahtml-define-begend-key "bu" "ul" map)
366 (yahtml-define-begend-key "bo" "ol" map)
367 (yahtml-define-begend-key "b1" "h1" map)
368 (yahtml-define-begend-key "b2" "h2" map)
369 (yahtml-define-begend-key "b3" "h3" map)
370 (yahtml-define-begend-key "ba" "a" map)
371 (yahtml-define-begend-key "bf" "form" map)
372 (yahtml-define-begend-key "bl" "label" map)
373 (yahtml-define-begend-key "bs" "select" map)
374 (yahtml-define-begend-key "bv" "div" map)
375 (yahtml-define-begend-key "bS" "span" map)
376 (yahtml-define-begend-key "bp" "pre" map)
377 (yahtml-define-begend-key "bq" "blockquote" map)
378 (YaTeX-define-key "b " 'yahtml-insert-begend map)
379 (YaTeX-define-key "B " 'yahtml-insert-begend-region map))
380 (YaTeX-define-key "e" 'YaTeX-end-environment map)
381 (YaTeX-define-key ">" 'yahtml-comment-region map)
382 (YaTeX-define-key "<" 'yahtml-uncomment-region map)
383 (YaTeX-define-key "g" 'yahtml-goto-corresponding-* map)
384 (YaTeX-define-key "k" 'yahtml-kill-* map)
385 (YaTeX-define-key "c" 'yahtml-change-* map)
386 (YaTeX-define-key "t" 'yahtml-browse-menu map)
387 (YaTeX-define-key "a" 'yahtml-char-entity-ref map)
388 (YaTeX-define-key "'" 'yahtml-prev-error map)
389 (YaTeX-define-key ";" 'yahtml-translate-region map)
390 (YaTeX-define-key ":" 'yahtml-translate-reverse-region map)
391 (YaTeX-define-key "#" 'yahtml-escape-chars-region map)
392 (YaTeX-define-key "}" 'yahtml-td-region map)
393 (YaTeX-define-key "]" 'yahtml-tr-region map)
394 ;;;;;(YaTeX-define-key "i" 'yahtml-fill-item map)
395 (YaTeX-define-key "\e" 'yahtml-quit map))
396 (substitute-all-key-definition
397 'fill-paragraph 'yahtml-fill-paragraph yahtml-mode-map)
398 (substitute-all-key-definition
399 'kill-buffer 'YaTeX-kill-buffer yahtml-mode-map))
401 (if yahtml-lint-buffer-map nil
402 (setq yahtml-lint-buffer-map (make-keymap))
403 (define-key yahtml-lint-buffer-map " " 'yahtml-jump-to-error-line))
406 (defvar yahtml-paragraph-start
407 (concat
408 "^$\\|<!--\\|^[ \t]*</?\\(h[1-6]\\|p\\|d[ldt]\\|[bhtd][rdh]\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\|table\\|center\\|blockquote\\)\\b")
409 "*Regexp of html paragraph separater")
410 (defvar yahtml-paragraph-separate
411 (concat
412 "^$\\|<!--\\|^[ \t]*</?\\(h[1-6]\\|p\\|[bhtd][ldt]\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\|table\\|center\\|blockquote\\|!--\\)\\b")
413 "*Regexp of html paragraph separater")
414 (defvar yahtml-syntax-table nil
415 "*Syntax table for yahtml-mode")
417 (if yahtml-syntax-table nil
418 (setq yahtml-syntax-table
419 (make-syntax-table (standard-syntax-table)))
420 (modify-syntax-entry ?\< "(>" yahtml-syntax-table)
421 (modify-syntax-entry ?\> ")<" yahtml-syntax-table)
422 (modify-syntax-entry ?\n " " yahtml-syntax-table))
424 (defvar yahtml-command-regexp "[A-Za-z0-9]+"
425 "Regexp of constituent of html commands.")
427 ;;; Completion tables for `form'
428 (defvar yahtml-form-table
429 '(("img") ("input") ("link") ("meta") ("label") ("source")))
430 (defvar yahtml-user-form-table nil)
431 (defvar yahtml-tmp-form-table nil)
432 (defvar yahtml-last-form "img")
434 (defvar yahtml-env-table
435 '(("html") ("head") ("title") ("body") ("dl") ("ul") ("ol") ("pre")
436 ("a") ("form") ("select") ("center") ("textarea") ("blockquote")
437 ("OrderedList" . "ol")
438 ("UnorderedList" . "ul")
439 ("DefinitionList" . "dl")
440 ("Preformatted" . "pre")
441 ("table") ("thead") ("tbody") ("tfoot") ("tr") ("th") ("td")
442 ("address") ("button")
443 ("h1") ("h2") ("h3") ("h4") ("h5") ("h6")
444 ;; ("p") ;This makes indentation screwed up!
445 ("style") ("script") ("noscript") ("div") ("object") ("ins") ("del")
446 ("option") ("datalist")
447 ;;HTML5
448 ("video") ("audio") ("figure") ("iframe")
449 ("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")))
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")))
1486 (defun yahtml:input ()
1487 "Add-in function for `input' form"
1488 (let ((size "") name type value id (maxlength "")
1489 (l yahtml-prefer-upcase-attributes))
1490 (setq name (read-string-with-history "name: ")
1491 type (YaTeX-completing-read-or-skip "type (default=text): "
1492 yahtml-input-types nil t)
1493 value (YaTeX-read-string-or-skip "value: "))
1494 (or (string-match "submit\\|reset" type)
1495 (setq id (YaTeX-read-string-or-skip "id: ")))
1496 (if (string-match "text\\|password\\|^$" type)
1497 (setq size (YaTeX-read-string-or-skip "size: ")
1498 maxlength (YaTeX-read-string-or-skip "maxlength: ")))
1499 (concat
1500 (if l "NAME" "name") "=\"" name "\""
1501 (yahtml-make-optional-argument "type" type)
1502 (yahtml-make-optional-argument "value" value)
1503 (yahtml-make-optional-argument "id" id)
1504 (yahtml-make-optional-argument "size" size)
1505 (yahtml-make-optional-argument "maxlength" maxlength))))
1507 (defun yahtml:datalist ()
1508 "Add-in function for `datalist' form"
1509 (setq yahtml-last-typeface-cmd "option")
1510 (let ((ids (yahtml-collect-ids)))
1511 (yahtml-make-optional-argument
1512 "id" (YaTeX-completing-read-or-skip "id: " ids nil t))))
1514 (defun yahtml:textarea ()
1515 "Add-in function for `textarea'"
1516 (interactive)
1517 (let (name rows cols)
1518 (setq name (read-string-with-history "Name: ")
1519 cols (read-string-with-history "Columns: ")
1520 rows (read-string-with-history "Rows: "))
1521 (concat
1522 (concat (if yahtml-prefer-upcase-attributes "NAME=" "name=")
1523 "\"" name "\"")
1524 (yahtml-make-optional-argument "cols" cols)
1525 (yahtml-make-optional-argument "rows" rows))))
1527 (defun yahtml:table ()
1528 "Add-in function for `table'"
1529 (let ((b (read-string-with-history "border="))
1530 (a (if yahtml-html4-strict ""
1531 (yahtml-read-parameter
1532 "align" nil '(("align" ("right")("center")))))))
1533 (if yahtml-html4-strict
1534 (yahtml-make-optional-argument
1535 "style"
1536 (if (or (string< "" b) (string< "" a))
1537 (yahtml-make-style-parameter
1538 (append
1539 (if (string< "" b)
1540 (list
1541 (cons "border" (format "%dpx solid" (YaTeX-str2int b)))
1542 (cons "border-collapse" "collapse")))
1543 (if (string< "" a)
1544 (cond
1545 ((string-match "right" a)
1546 (list (cons "margin-left" "auto")
1547 (cons "margin-right" "0")))
1548 ((string-match "center" a)
1549 (list (cons "margin-left" "auto")
1550 (cons "margin-right" "auto")))))))))
1551 (concat
1552 (yahtml-make-optional-argument "border" b)
1553 (yahtml-make-optional-argument "align" a)))))
1555 ;(fset 'yahtml:caption 'yahtml:p)
1556 (defun yahtml:caption ()
1557 "Add-in function for `caption' in table tag"
1558 (let ((par (yahtml-read-parameter "align")))
1559 (if yahtml-html4-strict
1560 (yahtml-make-optional-argument
1561 "style" (if par (yahtml-make-style-parameter
1562 (list (cons "caption-side" par)))))
1563 (yahtml-make-optional-argument "align" par))))
1565 (defun yahtml:font ()
1566 "Add-in function for `font'"
1567 (concat
1568 (yahtml-make-optional-argument "color" (read-string-with-history "color="))
1569 (yahtml-make-optional-argument "size" (read-string-with-history "size="))))
1571 (defun yahtml:style ()
1572 "Add-in function for `style'"
1573 (yahtml-make-optional-argument
1574 "type" (read-string-with-history "type=" "text/css")))
1576 (defun yahtml:script ()
1577 "Add-in function for `script'"
1578 (concat
1579 (yahtml-make-optional-argument
1580 "type" (yahtml-read-parameter "type" "text/javascript"))
1581 (yahtml-make-optional-argument
1582 "src" (yahtml-read-parameter "src" ""))))
1584 (defun yahtml:tr ()
1585 "Add-in function for `tr'"
1586 (setq yahtml-last-typeface-cmd "td")
1587 "")
1589 (defun yahtml:link ()
1590 "Add-in function for `link' (まだちょっと良く分かってない)"
1591 (let (rel rev type href)
1592 (setq rel (yahtml-read-parameter "rel"))
1593 (cond
1594 ((equal rel "")
1595 (concat (yahtml-make-optional-argument
1596 "rev" (yahtml-read-parameter "rev"))
1597 (yahtml-make-optional-argument
1598 "href" (yahtml-read-parameter "href")
1599 ;;他に良く使うのって何?
1600 )))
1601 ((string-match "stylesheet" rel)
1602 (concat
1603 (yahtml-make-optional-argument "rel" rel)
1604 (yahtml-make-optional-argument
1605 "type" (yahtml-read-parameter "type" "text/css"))
1606 (progn
1607 (setq href
1608 (read-from-minibuffer-with-history
1609 "href: " "" yahtml-url-completion-map))
1610 (if (string< "" href)
1611 (progn
1612 (if (and (file-exists-p (yahtml-url-to-path href))
1613 (y-or-n-p "Load css symbols now? "))
1614 (setq yahtml-css-class-alist
1615 (yahtml-css-collect-classes-file
1616 (yahtml-url-to-path href) yahtml-css-class-alist)))
1617 (message "")
1618 (yahtml-make-optional-argument "href" href))))))
1619 (t
1620 (concat
1621 (yahtml-make-optional-argument "rel" rel)
1622 (yahtml-make-optional-argument
1623 "type" (yahtml-read-parameter "type" "text/css"))
1624 (yahtml-make-optional-argument
1625 "href"
1626 (read-from-minibuffer-with-history
1627 "href: " "" yahtml-url-completion-map)))))))
1629 (defvar yahtml:meta-attrs
1630 '(("charset" value)
1631 ("name" content ("keywords")("author")("copyright")("date")("GENERATOR")
1632 ("viewport"))
1633 ("http-equiv" content)))
1635 (defun yahtml:meta ()
1636 (let ((attr (completing-read-with-history
1637 "Meta Attribute: " yahtml:meta-attrs))
1638 (case-fold-search t)
1639 (completion-ignore-case t)
1640 todonext name http-equiv content)
1641 (cond
1642 ((string= "" attr) nil)
1643 ((and (setq todonext (cdr-safe (assoc attr yahtml:meta-attrs)))
1644 (eq 'value (car todonext)))
1645 (yahtml-make-optional-argument attr (yahtml-read-parameter attr)))
1646 ((eq 'content (car todonext))
1647 (setq name (if (cdr todonext)
1648 (completing-read-with-history
1649 (format "%s: " attr) (cdr todonext))
1650 (yahtml-read-parameter attr)))
1651 (concat
1652 (yahtml-make-optional-argument attr name)
1653 (yahtml-make-optional-argument
1654 "content"
1655 (cond
1656 ((string-match "date" name)
1657 (read-string-with-history "Date: " (current-time-string)))
1658 ((string-match "author" name)
1659 (read-string-with-history "Author: "
1660 (if (and (user-full-name) (string< "" (user-full-name)))
1661 (user-full-name)
1662 (user-login-name))))
1663 ((string-match "GENERATOR" name)
1664 (setq content (read-string-with-history
1665 "Generator: " "User-agent: "))
1666 (if (string-match "yahtml" content)
1667 (message "Thank you!"))
1668 content)
1669 ((string-match "content-type" name)
1670 (if (string-match "http-equiv" attr )
1671 (error "Use <meta charset=\"...\" instead.. See docs/qanda.")
1672 (yahtml-make-optional-argument
1673 "content" (yahtml-read-parameter "content"))))
1674 ((string-match "viewport" name)
1675 ;; XXX: Very dirty static string
1676 "width=device-width, initial-scale=1")
1677 (t (read-string-with-history (concat name ": ")))))))
1678 (t (yahtml-make-optional-argument
1679 attr (yahtml-read-parameter attr))))))
1681 (defun yahtml:br ()
1682 (yahtml-make-optional-argument "clear" (yahtml-read-parameter "clear")))
1684 (defun yahtml:object ()
1685 (let ((codetype (yahtml-read-parameter "codetype" "application/java"))
1686 data classid)
1687 (cond
1688 ((string-match "java" codetype)
1689 (let ((completion-ignored-extensions
1690 ;;any extensions except ".class"
1691 '(".java" ".html" ".htm" ".gif" ".jpg" ".jpeg" ".png")))
1692 (setq classid (concat "java:"
1693 (yahtml-read-parameter "class file name"))))
1694 (concat
1695 (yahtml-make-optional-argument "codetype" codetype)
1696 (yahtml-make-optional-argument "classid" classid)
1697 (yahtml-make-optional-argument
1698 "width" (yahtml-read-parameter "width"))
1699 (yahtml-make-optional-argument
1700 "height" (yahtml-read-parameter "height"))))
1701 (t
1702 ""))))
1704 (defun yahtml:abbr ()
1705 "Add-in function for abbr."
1706 (yahtml-make-optional-argument "title" (yahtml-read-parameter "title")))
1708 (defun yahtml:button ()
1709 (concat
1710 (yahtml-make-optional-argument
1711 "name" (yahtml-read-parameter "name"))
1712 (yahtml-make-optional-argument
1713 "type" (yahtml-read-parameter
1714 "type" "button" '(("submit")("reset")("button"))))
1715 (yahtml-make-optional-argument
1716 "value" (yahtml-read-parameter "value"))))
1718 (defun yahtml::article ()
1719 (setq yahtml-last-typeface-cmd "h1" yahtml-last-begend "h1"))
1721 ;;; ---------- Simple tag ----------
1722 (defun yahtml-insert-tag (region-mode &optional tag)
1723 "Insert <TAG> </TAG> and put cursor inside of them."
1724 (interactive "P")
1725 (setq yahtml-current-completion-type 'inline
1726 region-mode (or region-mode (YaTeX-region-active-p)))
1727 (or tag
1728 (let ((completion-ignore-case t))
1729 (setq tag
1730 (YaTeX-cplread-with-learning
1731 (format "Tag %s(default %s): "
1732 (if region-mode "region: " "") yahtml-last-typeface-cmd)
1733 'yahtml-typeface-table 'yahtml-user-typeface-table
1734 'yahtml-tmp-typeface-table))))
1735 (if (string= "" tag) (setq tag yahtml-last-typeface-cmd))
1736 (setq tag (or (cdr (assoc tag yahtml-typeface-table)) tag))
1737 (setq yahtml-last-typeface-cmd tag
1738 tag (funcall (if yahtml-prefer-upcases 'upcase 'downcase) tag))
1739 (if region-mode
1740 (if (if (string< "19" emacs-version) (mark t) (mark))
1741 (save-excursion
1742 (if (> (point) (mark)) (exchange-point-and-mark))
1743 (insert (format "<%s%s>" tag (yahtml-addin tag)))
1744 (exchange-point-and-mark)
1745 (insert "</" tag ">"))
1746 (message "No mark set now"))
1747 (insert (format "<%s%s>" tag (yahtml-addin tag)))
1748 (save-excursion (insert (format "</%s>" tag)))))
1750 (defun yahtml-insert-tag-region (&optional tag)
1751 "Call yahtml-insert-tag with region mode."
1752 (interactive)
1753 (yahtml-insert-tag t tag))
1755 (defvar yahtml-need-single-closer nil) ;for test
1756 (defun yahtml-insert-single (cmd)
1757 "Insert <CMD>."
1758 (interactive
1759 (list
1760 (let ((completion-ignore-case t))
1761 (YaTeX-cplread-with-learning
1762 (format "Command%s: "
1763 (if yahtml-last-single-cmd
1764 (concat "(default " yahtml-last-single-cmd ")") ""))
1765 'yahtml-single-cmd-table 'yahtml-user-single-cmd-table
1766 'yahtml-tmp-single-cmd-table))))
1767 (if (string= "" cmd) (setq cmd yahtml-last-single-cmd))
1768 (setq yahtml-last-single-cmd
1769 (or (cdr (assoc cmd yahtml-single-cmd-table)) cmd))
1770 (setq cmd (funcall (if yahtml-prefer-upcases 'upcase 'downcase)
1771 yahtml-last-single-cmd))
1772 (insert (format "<%s%s%s>"
1773 cmd
1774 (yahtml-addin cmd)
1775 (if (and yahtml-need-single-closer
1776 (assoc cmd '(("br")("hr"))))
1777 " /" "")))
1778 (if (assoc cmd yahtml-env-table)
1779 (save-excursion (insert (format "</%s>" cmd)))))
1781 (defun yahtml-insert-p (&optional arg)
1782 "Convenient function to insert <p></p>"
1783 (interactive "P")
1784 (if (or yahtml-always-/p arg) (yahtml-insert-tag arg "p")
1785 (yahtml-insert-single "p")))
1787 (defun yahtml-insert-amps (arg)
1788 "Insert char-entity references via ampersand"
1789 ;; Thanks; http://www.tsc.co.jp/~asada/html/wdg40_f/entities/
1790 (interactive "P")
1791 (let*((mess "") c
1792 (list (append yahtml-entity-reference-chars-alist-default
1793 yahtml-entity-reference-chars-alist))
1794 (l list))
1795 (while l
1796 (setq mess (format "%s %c" mess (car (car l)) (cdr (car l)))
1797 l (cdr l)))
1798 (message "Char-entity reference: %s SPC=& RET=&; BS=%s Other=&#..;"
1799 mess (if YaTeX-japan "直前の文字" "Preceding-Char"))
1800 (setq c (read-char))
1801 (cond
1802 ((equal c (car-safe (assoc c list)))
1803 (insert (format "&%s;" (cdr (assoc c list)))))
1804 ((or (equal c ?\n) (equal c ?\r))
1805 (insert "&;")
1806 (forward-char -1))
1807 ((equal c ? )
1808 (insert ?&))
1809 ((and (memq c '(127 8))
1810 (setq c (preceding-char))
1811 (delete-backward-char 1)
1812 nil)) ;Fall through to the next 't block
1813 (t (insert (format "&#x%x;" c))))))
1815 (defun yahtml:!--\#include ()
1816 (let ((file (yahtml-read-parameter "file" "")))
1817 (format "%s=\"%s\"--" (if (string-match "/" file) "virtual" "file") file)))
1819 (defun yahtml:!--\#exec ()
1820 (format "cmd=\"%s\"--"
1821 (yahtml-read-parameter "cmd" "" '(("cmd" . command)))))
1823 (defun yahtml:media-read-options (&optional opts-alist)
1824 (let*((delim " ")
1825 (minibuffer-completion-table
1826 (or opts-alist '(("autoplay") ("controls") ("loop") ("preload"))))
1827 (quotekey (substitute-command-keys "\\[quoted-insert]")))
1828 (read-from-minibuffer-with-history
1829 (format "Media Opts(`%s SPC' for more options): " quotekey)
1830 "controls" YaTeX-minibuffer-completion-map)))
1832 (defun yahtml:audio ()
1833 ;preload autoplay loop controls: `src' be specified via `source'
1834 (yahtml:media-read-options))
1836 (defun yahtml:video ()
1837 ;`src' be specified via `source'
1838 (let ((poster (yahtml-make-optional-argument
1839 "poster"
1840 (yahtml-read-file-name-regexp
1841 "Poster: " "\\.\\(gif\\|png\\|jpg\\|w?bmp\\|pict\\|tif\\)"
1842 "")))
1843 (opts (yahtml:media-read-options)))
1844 (concat poster (if (string< "" opts) (concat " " opts)))))
1846 (defvar yahtml-media-file-regexp
1847 "\\.\\(mp[0-9]\\|wav\\|og[gv]\\|opus\\|aac\\)"
1848 "*Default filename regexp of media files.")
1850 (defun yahtml:source ()
1851 ;; source element must have src attribute
1852 (format "src=\"%s\"" (yahtml-read-file-name-regexp
1853 "source: " yahtml-media-file-regexp "" "" nil "")))
1855 (defun yahtml:figure ()
1856 (setq yahtml-last-typeface-cmd "figcaption"))
1858 (defun yahtml:iframe ()
1859 (let ((src (yahtml-read-url "src: ")))
1860 (concat
1861 (yahtml-make-optional-argument "src" src)
1862 (yahtml-make-optional-argument
1863 "width" (YaTeX-read-string-or-skip "width: "))
1864 (yahtml-make-optional-argument
1865 "height" (YaTeX-read-string-or-skip "height: ")))))
1867 ;;; ---------- Jump ----------
1868 (defun yahtml-on-href-p ()
1869 "Check if point is on href clause."
1870 (let ((p (point)) e cmd (case-fold-search t))
1871 (save-excursion
1872 (and ;;(string= (YaTeX-inner-environment t) "a") ;aでなくても許可にした
1873 (save-excursion
1874 ;;(search-forward "</a>" nil t) ;aでなくても許可にした
1875 (search-forward "[\" \t\n]" nil t)
1876 (setq e (point)))
1877 ;(goto-char (get 'YaTeX-inner-environment 'point))
1878 (re-search-backward "<\\(a\\|link\\)\\>" nil t)
1879 (search-forward "href" e t)
1880 (search-forward "=" e t)
1881 (progn
1882 (skip-chars-forward " \t\n")
1883 (looking-at "\"?\\([^\"> \t\n]+\\)\"?"))
1884 (< p (match-end 0))
1885 (yahtml-unescape-string (YaTeX-match-string 1))))))
1887 (defun yahtml-netscape-sentinel (proc mes)
1888 (cond
1889 ((null (buffer-name (process-buffer proc)))
1890 (set-process-buffer proc nil))
1891 ((eq (process-status proc) 'exit)
1892 (let ((cb (current-buffer)))
1893 (set-buffer (process-buffer proc))
1894 (goto-char (point-min))
1895 (if (search-forward "not running" nil t)
1896 (progn
1897 (message "Starting netscape...")
1898 (start-process
1899 "browser" (process-buffer proc)
1900 shell-file-name yahtml-shell-command-option
1901 (format "%s \"%s\"" yahtml-www-browser
1902 (get 'yahtml-netscape-sentinel 'url)))
1903 (message "Starting netscape...Done")))
1904 (set-buffer cb)))))
1906 (defvar yahtml-browser-process nil)
1908 (defun yahtml-browse-html (href)
1909 "Call WWW Browser to see HREF."
1910 (let ((pb "* WWW Browser *") (cb (current-buffer)))
1911 (cond
1912 ((string-match "^start\\>" yahtml-www-browser)
1913 (if (get-buffer pb)
1914 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
1915 (put 'yahtml-netscape-sentinel 'url href)
1916 (set-process-sentinel
1917 (setq yahtml-browser-process
1918 (start-process
1919 "browser" pb shell-file-name yahtml-shell-command-option
1920 (format "%s \"%s\"" yahtml-www-browser href)))
1921 'yahtml-netscape-sentinel))
1922 ((and (string-match
1923 "[Nn]etscape\\|[Ff]irefox\\|[Mm]ozilla" yahtml-www-browser)
1924 (not (eq system-type 'windows-nt)))
1925 (if (get-buffer pb)
1926 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
1927 (put 'yahtml-netscape-sentinel 'url href)
1928 (set-process-sentinel
1929 (setq yahtml-browser-process
1930 (start-process
1931 "browser" pb shell-file-name yahtml-shell-command-option ;"-c"
1932 (format "%s -remote \"openURL(%s)\"" yahtml-www-browser href)))
1933 'yahtml-netscape-sentinel))
1934 ((and (string= "w3" yahtml-www-browser) (fboundp 'w3-fetch))
1935 (w3-fetch href))
1936 ((stringp yahtml-www-browser)
1937 (if (and yahtml-browser-process
1938 (eq (process-status yahtml-browser-process) 'run))
1939 (message "%s is already running" yahtml-www-browser)
1940 (setq yahtml-browser-process
1941 (start-process
1942 "browser" "* WWW Browser *"
1943 shell-file-name yahtml-shell-command-option
1944 (format "%s \"%s\"" yahtml-www-browser href)))))
1945 (t
1946 (message "Sorry, jump across http is not supported.")))))
1948 (defun yahtml-goto-corresponding-href (&optional other)
1949 "Go to corresponding name."
1950 (let ((href (yahtml-on-href-p)) file name (parent buffer-file-name))
1951 (if href
1952 (cond
1953 ((string-match "^\\(ht\\|f\\)tps?:" href)
1954 (yahtml-browse-html href))
1955 (t (if (string-match "\&" href)
1956 (setq href (yahtml-untranslate-string href)))
1957 (setq file (substring href 0 (string-match "#" href)))
1958 (if (string-match "#" href)
1959 (setq name (substring href (1+ (string-match "#" href)))))
1960 (if (string< "" file)
1961 (progn
1962 (if (string-match "/$" file)
1963 (or (catch 'dirindex
1964 (mapcar
1965 (function
1966 (lambda (f)
1967 (if (file-exists-p (concat file f))
1968 (throw 'dirindex
1969 (setq file (concat file f))))))
1970 (yahtml-get-directory-index))
1971 nil)
1972 (setq file (concat file yahtml-directory-index))))
1973 (if (string-match "^/" file)
1974 (setq file (yahtml-url-to-path file)))
1975 (if other (YaTeX-switch-to-buffer-other-window file)
1976 (YaTeX-switch-to-buffer file))
1977 (or YaTeX-parent-file (setq YaTeX-parent-file parent))))
1978 (if name
1979 (progn (set-mark-command nil) (yahtml-jump-to-name name)))
1980 t)))))
1982 (defun yahtml-jump-to-name (name)
1983 "Jump to html's named tag."
1984 (setq name (format "\\(name\\|id\\)\\s *=\\s *\"?%s\\>\"?" name))
1985 (or (and (re-search-forward name nil t) (goto-char (match-beginning 0)))
1986 (and (re-search-backward name nil t) (goto-char (match-beginning 0)))
1987 (message "Named tag `%s' not found" (substring href 1))))
1989 (defun yahtml-on-begend-p (&optional p)
1990 "Check if point is on begend clause."
1991 (let ((p (or p (point))) cmd (case-fold-search t))
1992 (save-excursion
1993 (goto-char p)
1994 (if (equal (char-after (point)) ?<) (forward-char 1))
1995 (if (and (re-search-backward "<" nil t)
1996 (looking-at
1997 ;(concat "<\\(/?" yahtml-struct-name-regexp "\\)\\b")
1998 "<\\(/?[A-Z][A-Z0-9]*\\)\\b")
1999 (condition-case nil
2000 (forward-list 1)
2001 (error nil))
2002 (< p (point)))
2003 (YaTeX-match-string 1)))))
2005 (defun yahtml-goto-corresponding-begend (&optional noerr)
2006 "Go to corresponding opening/closing tag.
2007 Optional argument NOERR causes no error for unballanced tag."
2008 (let ((cmd (yahtml-on-begend-p)) m0
2009 (p (point)) (case-fold-search t) func str (nest 0))
2010 (cond
2011 (cmd
2012 (setq m0 (match-beginning 0))
2013 (if (= (aref cmd 0) ?/) ;on </cmd> line
2014 (setq cmd (substring cmd 1)
2015 str (format "\\(<%s\\)\\|\\(</%s\\)" cmd cmd)
2016 func 're-search-backward)
2017 (setq str (format "\\(</%s\\)\\|\\(<%s\\)" cmd cmd)
2018 func 're-search-forward))
2019 (while (and (>= nest 0) (funcall func str nil t))
2020 (if (equal m0 (match-beginning 0))
2021 nil
2022 (setq nest (+ nest (if (match-beginning 1) -1 1)))))
2023 (if (< nest 0)
2024 (goto-char (match-beginning 0))
2025 (funcall
2026 (if noerr 'message 'error)
2027 "Corresponding tag of `%s' not found." cmd)
2028 (goto-char p)
2029 nil))
2030 (t nil))))
2032 (defun yahtml-current-tag ()
2033 "Return the current tag name including #exec and #include."
2034 (save-excursion
2035 (let ((p (point)) b tag)
2036 (or (bobp)
2037 (looking-at "<")
2038 (progn (skip-chars-backward "^<") (forward-char -1)))
2039 (setq b (point))
2040 (skip-chars-forward "<")
2041 (setq tag (YaTeX-buffer-substring
2042 (point) (progn (skip-chars-forward "^ \t\n") (point))))
2043 (goto-char b)
2044 (forward-list 1)
2045 (and (< p (point)) tag))))
2047 (defun yahtml-get-attrvalue (attr)
2048 "Extract current tag's attribute value from buffer."
2049 (let (e (case-fold-search t))
2050 (save-excursion
2051 (or (looking-at "<")
2052 (progn (skip-chars-backward "^<") (backward-char 1)))
2053 (setq e (save-excursion (forward-list 1) (point)))
2054 (if (and
2055 (re-search-forward (concat "\\b" attr "\\b") e t)
2056 (progn (skip-chars-forward " \t\n=")
2057 (looking-at "\"?\\([^\"> \t\n]+\\)\"?")))
2058 (YaTeX-match-string 1)))))
2060 (defun yahtml-goto-corresponding-img ()
2061 "View image on point"
2062 (let ((tag (yahtml-current-tag)) image (p (point)) (case-fold-search t))
2063 (if (and tag
2064 (string-match "img" tag)
2065 (setq image
2066 (yahtml-unescape-string (yahtml-get-attrvalue "src"))))
2067 (progn
2068 (message "Invoking %s %s..." yahtml-image-viewer image)
2069 (start-process
2070 "Viewer" " * Image Viewer *"
2071 shell-file-name yahtml-shell-command-option ;"-c"
2072 (concat yahtml-image-viewer " " image))
2073 (message "Invoking %s %s...Done" yahtml-image-viewer image)))))
2075 (defun yahtml-goto-corresponding-source (&optional other)
2076 "Goto applet's or script's source."
2077 (let ((env (yahtml-current-tag)) s (p (point)))
2078 (cond
2079 ((string-match "applet" env)
2080 (if (setq s (yahtml-unescape-string (yahtml-get-attrvalue "code")))
2081 (progn
2082 (setq s (YaTeX-match-string 1)
2083 s (concat
2084 (substring s 0 (string-match "\\.[A-Za-z]+$" s))
2085 ".java"))
2086 (if other (YaTeX-switch-to-buffer-other-window s)
2087 (YaTeX-switch-to-buffer s))
2088 s) ;return source file name
2089 (message "No applet source specified")
2090 (sit-for 1)
2091 nil))
2092 ((string-match "script" env)
2093 (if (setq s (yahtml-get-attrvalue "src"))
2094 (progn
2095 (funcall (if other 'YaTeX-switch-to-buffer-other-window
2096 'YaTeX-switch-to-buffer)
2097 (yahtml-url-to-path s))
2098 s)))
2099 ((string-match "!--#include" env)
2100 (cond
2101 ((setq s (yahtml-get-attrvalue "file")) ;<!--#include file="foo"-->
2102 (if other (YaTeX-switch-to-buffer-other-window s)
2103 (YaTeX-switch-to-buffer s))
2104 s)
2105 ((setq s (yahtml-get-attrvalue "virtual"));<!--#include virtual="foo"-->
2106 (setq s (yahtml-url-to-path s))
2107 (if other (YaTeX-switch-to-buffer-other-window s)
2108 (YaTeX-switch-to-buffer s))
2109 s)))
2110 ((and (string-match "!--#exec" env)
2111 (setq s (yahtml-get-attrvalue "cmd")))
2112 (setq s (substring s 0 (string-match " \t\\?" s))) ;get argv0
2113 (let ((b " *yahtmltmp*")) ;peek a little
2114 (unwind-protect
2115 (progn
2116 (set-buffer (get-buffer-create b))
2117 (YaTeX-insert-file-contents s nil 0 100)
2118 (if (looking-at "#!")
2119 (if other (YaTeX-switch-to-buffer-other-window s)
2120 (YaTeX-switch-to-buffer s))))
2121 (kill-buffer (get-buffer b)))
2122 (get-file-buffer s))))))
2124 (defun yahtml-goto-corresponding-* (&optional other)
2125 "Go to corresponding object."
2126 (interactive "P")
2127 (cond
2128 ((yahtml-goto-corresponding-href other))
2129 ((yahtml-goto-corresponding-img))
2130 ((yahtml-goto-corresponding-source other))
2131 ((yahtml-goto-corresponding-begend))
2132 (t (message "I don't know where to go."))))
2134 (defun yahtml-goto-corresponding-*-other-window ()
2135 "Go to corresponding object."
2136 (interactive)
2137 (yahtml-goto-corresponding-* t))
2139 (defun yahtml-visit-main ()
2140 "Go to parent file from where you visit current file."
2141 (interactive)
2142 (if YaTeX-parent-file (YaTeX-switch-to-buffer YaTeX-parent-file)))
2144 ;;; ---------- killing ----------
2145 (defun yahtml-kill-begend (&optional whole)
2146 (let ((tag (yahtml-on-begend-p)) p q r bbolp)
2147 (if tag
2148 (save-excursion
2149 (or (looking-at "<")
2150 (progn (skip-chars-backward "^<") (forward-char -1)))
2151 (setq p (point))
2152 (yahtml-goto-corresponding-begend)
2153 (or (looking-at "<")
2154 (progn (skip-chars-backward "^<") (forward-char -1)))
2155 (if (< (point) p) ;if on the opening tag
2156 (progn (setq q p p (point))
2157 (goto-char q))
2158 (setq q (point))) ;now q has end-line's (point)
2159 (if (not whole)
2160 (kill-region
2161 (progn (skip-chars-backward " \t")
2162 (if (setq bbolp (bolp)) (point) q))
2163 (progn (forward-list 1)
2164 (setq r (point))
2165 (skip-chars-forward " \t")
2166 (if (and bbolp (eolp) (not (eobp))) (1+ (point)) r))))
2167 (goto-char p)
2168 (skip-chars-backward " \t")
2169 (if (not whole)
2170 (progn
2171 (kill-append
2172 (buffer-substring
2173 (setq p (if (setq bbolp (bolp)) (point) p))
2174 (setq q (progn
2175 (forward-list 1)
2176 (setq r (point))
2177 (skip-chars-forward " \t")
2178 (if (and bbolp (eolp) (not (eobp)))
2179 (1+ (point))
2180 r))))
2181 t)
2182 (delete-region p q))
2183 (kill-region
2184 (if (bolp) (point) p)
2185 (progn (goto-char q)
2186 (forward-list 1)
2187 (setq r (point))
2188 (skip-chars-forward " \t")
2189 (if (and (eolp) (not (eobp))) (1+ (point)) r))))
2190 tag))))
2192 (defun yahtml-kill-* (whole)
2193 "Kill current position's HTML tag (set)."
2194 (interactive "P")
2195 (cond
2196 ((yahtml-kill-begend whole))))
2199 ;;; ---------- changing ----------
2200 (defun yahtml-on-assignment-p ()
2201 "Return if current point is on parameter assignment.
2202 If so, return parameter name, otherwise nil.
2203 This function should be able to treat white spaces in value, but not yet."
2204 (let ((p (point)))
2205 (save-excursion
2206 (put 'yahtml-on-assignment-p 'region nil)
2207 (skip-chars-backward "^ \t\n")
2208 (and (looking-at "\\([A-Za-z0-9]+\\)\\s *=\\s *\"?\\([^ \t\"]+\\)\"?")
2209 (< p (match-end 0))
2210 (>= p (1- (match-beginning 2)))
2211 (put 'yahtml-on-assignment-p 'region
2212 (cons (match-beginning 2) (match-end 2)))
2213 (YaTeX-match-string 1)))))
2215 (defun yahtml-change-begend ()
2216 (let ((tag (yahtml-on-begend-p))
2217 (completion-ignore-case t)
2218 (case-fold-search t)
2219 (p (point)) (q (make-marker))
2220 (default (append yahtml-env-table yahtml-typeface-table))
2221 (user (append yahtml-user-env-table yahtml-user-typeface-table))
2222 (tmp (append yahtml-tmp-env-table yahtml-tmp-typeface-table))
2223 href b1 e1 attr new css)
2224 (cond
2225 (tag
2226 (cond
2227 ((and (string-match "^a$" tag)
2228 (save-excursion
2229 (and
2230 (re-search-backward "<a\\b" nil t)
2231 (progn
2232 (goto-char (match-end 0))
2233 (skip-chars-forward " \t\n")
2234 (setq b1 (point))
2235 (search-forward ">" nil t))
2236 (setq e1 (match-beginning 0))
2237 (goto-char b1)
2238 (re-search-forward "href\\s *=" e1 t)
2239 (>= p (point))
2240 (progn
2241 (goto-char (match-end 0))
2242 (skip-chars-forward " \t\n")
2243 (looking-at "\"?\\([^\"> \t\n]+\\)\"?"))
2244 (< p (match-end 0)))))
2245 (setq b1 (match-beginning 1) e1 (match-end 1)
2246 yahtml-completing-buffer (current-buffer)
2247 ;; yahtml-urls-local is buffer-local, so we must put
2248 ;; that into yahtml-urls here
2249 yahtml-urls (append yahtml-urls-private yahtml-urls-local)
2250 href (read-from-minibuffer
2251 "Change href to: " "" yahtml-url-completion-map))
2252 (if (string< "" href)
2253 (progn
2254 ;;(setq href ;??
2255 ;; (if yahtml-prefer-upcases (upcase href) (downcase href)))
2256 (delete-region b1 e1)
2257 (goto-char b1)
2258 (insert href))))
2259 ((setq attr (yahtml-on-assignment-p)) ;if on the assignment to attr
2260 (if (and (equal attr "class") ;treat "class" attribute specially
2261 (setq css (yahtml-css-get-element-completion-alist tag)))
2263 (setq new (yahtml-read-css css tag))
2264 ;;other than "class", read parameter normally
2265 (setq new (yahtml-read-parameter attr)))
2266 (goto-char (car (get 'yahtml-on-assignment-p 'region)))
2267 (delete-region (point) (cdr (get 'yahtml-on-assignment-p 'region)))
2268 (insert new))
2269 (t
2270 (save-excursion
2271 (if (= (aref tag 0) ?/) (setq tag (substring tag 1)))
2272 (or (= (char-after (point)) ?<) (skip-chars-backward "^<"))
2273 (skip-chars-forward "^A-Za-z")
2274 (set-marker q (point))
2275 (setq p (point))
2276 (yahtml-goto-corresponding-begend)
2277 (or (= (char-after (point)) ?<)
2278 (skip-chars-backward "^<"))
2279 (skip-chars-forward "^A-Za-z")
2280 (if (= (char-after (1- (point))) ?/)
2281 (progn
2282 (set-marker q (point))
2283 (goto-char p)))
2284 (setq tag (let ((completion-ignore-case t))
2285 (YaTeX-cplread-with-learning
2286 (format "Change `%s' to(default %s): "
2287 tag yahtml-last-begend)
2288 'default 'user 'tmp)))
2289 (delete-region (point) (progn (skip-chars-forward "^>") (point)))
2290 (if (string= "" tag) (setq tag yahtml-last-begend))
2291 (setq yahtml-last-begend
2292 (or (cdr (assoc tag yahtml-env-table)) tag)
2293 tag yahtml-last-begend)
2294 (setq tag (if yahtml-prefer-upcases (upcase tag) (downcase tag)))
2295 (insert (format "%s%s" tag (yahtml-addin tag)))
2296 (goto-char q)
2297 (set-marker q nil)
2298 (delete-region (point) (progn (skip-chars-forward "^>") (point)))
2299 (insert tag))))
2300 t))))
2302 (defun yahtml-change-command ()
2303 (let ((p (point)) (case-fold-search t) cmd par new
2304 (beg (make-marker)) (end (make-marker)))
2305 (skip-chars-backward "^<")
2306 (if (and
2307 (looking-at yahtml-command-regexp)
2308 (progn
2309 (set-marker beg (match-beginning 0))
2310 (set-marker end (match-end 0))
2311 t) ;for further work
2312 (progn
2313 (forward-char -1)
2314 (condition-case nil
2315 (forward-list 1)
2316 (error nil))
2317 (< p (point))))
2318 (progn
2319 (goto-char p)
2320 (if (setq par (yahtml-on-assignment-p))
2321 (progn
2322 (setq new (yahtml-read-parameter par))
2323 (set-marker beg (car (get 'yahtml-on-assignment-p 'region)))
2324 (set-marker end (cdr (get 'yahtml-on-assignment-p 'region))))
2325 (setq new
2326 (YaTeX-cplread-with-learning
2327 "Change form to: "
2328 'yahtml-form-table 'yahtml-user-form-table
2329 'yahtml-tmp-form-table)))
2330 (delete-region beg end)
2331 (goto-char beg)
2332 (set-marker beg nil)
2333 (set-marker end nil)
2334 (insert new)
2335 t)
2336 (goto-char p)
2337 nil)))
2339 (defun yahtml-change-* ()
2340 "Change current position's HTML tag (set)."
2341 (interactive)
2342 (cond
2343 ((yahtml-change-begend))
2344 ((yahtml-change-command))))
2346 ;;; ---------- commenting ----------
2348 (defun yahtml-comment-region (&optional uncom)
2349 "Comment out region or environment."
2350 (interactive)
2351 (let ((e (make-marker)) be beg p)
2352 (cond
2353 (;(marker-position (set-marker e (yahtml-on-begend-p)))
2354 (setq be (yahtml-on-begend-p))
2355 (save-excursion
2356 (setq p (point))
2357 (if (string-match "^/" be)
2358 (setq beg (progn (forward-line 1) (point)))
2359 (setq beg (progn (beginning-of-line) (point))))
2360 (goto-char p)
2361 (yahtml-goto-corresponding-begend)
2362 (if (string-match "^/" be)
2363 (beginning-of-line)
2364 (forward-line 1))
2365 (set-marker e (point))
2366 ;(comment-region beg (point) (if uncom (list 4)))))
2367 ))
2368 (t ;(comment-region (region-beginning) (region-end) (if uncom (list 4)))
2369 (setq beg (region-beginning))
2370 (set-marker e (region-end))))
2371 (if yahtml-translate-hyphens-when-comment-region
2372 (let ((yahtml-entity-reference-chars-alist-default nil)
2373 (yahtml-entity-reference-chars-alist '((?- . "#45")))
2374 yahtml-entity-reference-chars-regexp
2375 yahtml-entity-reference-chars-reverse-regexp)
2376 (yahtml-entity-reference-chars-setup)
2377 (funcall
2378 (if uncom 'yahtml-translate-reverse-region
2379 'yahtml-translate-region)
2380 beg e)))
2381 (comment-region beg e (if uncom (list 4)))
2382 (set-marker e nil)))
2384 (defun yahtml-uncomment-region ()
2385 (interactive)
2386 (yahtml-comment-region t))
2388 ;;; ---------- translate to entity references ----------
2389 (defvar yahtml-entity-reference-chars-alist-default
2390 ;'((?> . "gt") (?< . "lt") (?& . "amp") (?\" . "quot") (?' . "apos"))
2391 '((?> . "gt") (?< . "lt") (?& . "amp") (?\" . "quot"))
2392 "Default translation table from character to entity reference")
2393 (defvar yahtml-entity-reference-chars-alist nil
2394 "*Translation table from character to entity reference")
2395 (defvar yahtml-entity-reference-chars-regexp nil)
2396 (defvar yahtml-entity-reference-chars-reverse-regexp nil)
2398 (defun yahtml-entity-reference-chars-setup ()
2399 (let ((list (append yahtml-entity-reference-chars-alist-default
2400 yahtml-entity-reference-chars-alist)))
2401 (setq yahtml-entity-reference-chars-regexp "["
2402 yahtml-entity-reference-chars-reverse-regexp "&\\(")
2403 (while list
2404 (setq yahtml-entity-reference-chars-regexp
2405 (concat yahtml-entity-reference-chars-regexp
2406 (char-to-string (car (car list))))
2407 yahtml-entity-reference-chars-reverse-regexp
2408 (concat yahtml-entity-reference-chars-reverse-regexp
2409 (cdr (car list))
2410 (if (cdr list) "\\|")))
2411 (setq list (cdr list)))
2412 (setq yahtml-entity-reference-chars-regexp
2413 (concat yahtml-entity-reference-chars-regexp "]")
2414 yahtml-entity-reference-chars-reverse-regexp
2415 (concat yahtml-entity-reference-chars-reverse-regexp "\\);"))))
2417 (yahtml-entity-reference-chars-setup)
2419 (defun yahtml-translate-region (beg end)
2420 "Translate inhibited literals."
2421 (interactive "r")
2422 (save-excursion
2423 (save-restriction
2424 (narrow-to-region beg end)
2425 (let ((ct (append yahtml-entity-reference-chars-alist
2426 yahtml-entity-reference-chars-alist-default)))
2427 (goto-char beg)
2428 (while (re-search-forward yahtml-entity-reference-chars-regexp nil t)
2429 ;(setq c (preceding-char))
2430 (replace-match
2431 (concat "&" (cdr (assoc (preceding-char) ct)) ";")))))))
2433 (defun yahtml-translate-reverse-region (beg end)
2434 "Translate entity references to literals."
2435 (interactive "r")
2436 (save-excursion
2437 (save-restriction
2438 (narrow-to-region beg end)
2439 (let ((ct (append yahtml-entity-reference-chars-alist
2440 yahtml-entity-reference-chars-alist-default))
2441 ec)
2442 (goto-char beg)
2443 (while (re-search-forward
2444 yahtml-entity-reference-chars-reverse-regexp nil t)
2445 ;(setq c (preceding-char))
2446 (setq ec (YaTeX-match-string 1))
2447 (delete-region (match-end 0) (match-beginning 0))
2448 (insert (car (YaTeX-rassoc ec ct))))))))
2450 (defun yahtml-inner-environment-but (exclude &optional quick)
2451 "Return the inner environment but matches with EXCLUDE tag."
2452 (let (e (case-fold-search t))
2453 (save-excursion
2454 (while (and (setq e (YaTeX-inner-environment quick))
2455 (string-match exclude e))
2456 (goto-char (get 'YaTeX-inner-environment 'point))))
2457 e))
2459 (defun yahtml-untranslate-string (str)
2460 "Untranslate entity reference."
2461 (let ((md (match-data)) (left "") (right str) b0 ch
2462 (ct (append yahtml-entity-reference-chars-alist
2463 yahtml-entity-reference-chars-alist-default))
2464 (revrex yahtml-entity-reference-chars-reverse-regexp))
2465 (unwind-protect
2466 (progn
2467 (while (string< "" right)
2468 (cond
2469 ((string-match revrex right)
2470 (setq ch (YaTeX-rassoc
2471 (substring right (match-beginning 1) (match-end 1)))
2472 b0 (substring right 0 (match-beginning 0))
2473 right (substring right (match-end 0))
2474 left (concat left
2475 (substring right 0 (match-beginning 0))
2476 (char-to-string ch))))
2477 ((string-match "\\&#\\(x\\)?\\([0-9a-f]+\\);" right)
2478 (setq ch (substring right (match-beginning 2) (match-end 2))
2479 b0 (substring right 0 (match-beginning 0))
2480 right (substring right (match-end 0))
2481 left (concat left
2482 b0
2483 (char-to-string
2484 (if (match-beginning 1)
2485 (YaTeX-hex ch)
2486 (string-to-number ch))))))
2487 (t (setq left (concat left right)
2488 right ""))))
2489 left)
2490 (store-match-data md))))
2492 ;;; ---------- table-ize region ----------
2493 (defun yahtml-td-region (e delim beg end)
2494 "Enclose each item in a region with <td>..</td>.
2495 Interactive prefix argument consults enclosing element other than td."
2496 (interactive "P\nsDelimiter(s): \nr")
2497 (let ((e (cond
2498 ((null e) "td")
2499 ((stringp e) e)
2500 (t (read-string-with-history
2501 "Enclose with(`thd' means th td td..): " "th"))))
2502 (ws "[ \t]")
2503 elm p i)
2504 (if (string= delim "") (setq delim " \t\n"))
2505 (setq delim (concat "[" delim "]+")
2506 elm (if (string= "thd" e)
2507 (cons "th" "td")
2508 (cons e e)))
2509 (save-excursion
2510 (save-restriction
2511 (narrow-to-region beg end)
2512 (goto-char (setq p (point-min)))
2513 (setq i 0 e (car elm))
2514 (while (re-search-forward delim nil t)
2515 (setq e (if (= (setq i (1+ i)) 1) (car elm) (cdr elm)))
2516 (goto-char (match-beginning 0))
2517 (insert "</" e ">")
2518 (save-excursion
2519 (goto-char p)
2520 (insert "<" e ">"))
2521 (setq p (point))
2522 (while (and (not (eobp)) (looking-at ws))
2523 (delete-char 1))
2524 (if (looking-at delim) (delete-char 1)))
2525 (insert "<" e ">")
2526 (goto-char (point-max))
2527 (insert "</" e ">")))))
2529 (defun yahtml-tr-region (e delim beg end)
2530 "Enclose lines in a form tab-sv/csv with <tr><td>..</td></tr>."
2531 (interactive "P\nsDelimiter(s): \nr")
2532 (setq e (if (and e (listp e))
2533 (read-string-with-history
2534 "Enclose with(td or th, `thd' -> th td td td...: " "th")))
2535 (save-excursion
2536 (save-restriction
2537 (narrow-to-region (point) (mark))
2538 (goto-char (point-min))
2539 (while (not (eobp))
2540 (insert "<tr>")
2541 (yahtml-td-region e delim (point) (point-end-of-line))
2542 (end-of-line)
2543 (insert "</tr>")
2544 (forward-line 1)))))
2546 ;;; ---------- filling ----------
2547 (defvar yahtml-saved-move-to-column (symbol-function 'move-to-column))
2548 (defun yahtml-move-to-column (col &optional force)
2549 (beginning-of-line)
2550 (let ((ccol 0))
2551 (while (and (> col ccol) (not (eolp)))
2552 (if (eq (following-char) ?\<)
2553 (progn
2554 (while (and (not (eq (following-char) ?\>))
2555 (not (eolp)))
2556 (forward-char))
2557 (or (eolp) (forward-char)))
2558 (or (eolp) (forward-char))
2559 (if (eq (preceding-char) ?\t)
2560 (let ((wd (- 8 (% (+ ccol 8) 8))))
2561 (if (and force (< col (+ ccol wd)))
2562 (progn
2563 (backward-char 1)
2564 (insert-char ?\ (- col ccol))
2565 (setq ccol col))
2566 (setq ccol (+ ccol wd))))
2567 (setq ccol (1+ ccol)))
2568 (if (and YaTeX-japan
2569 (or
2570 (and (fboundp 'char-category)
2571 (string-match "[chj]" (char-category (preceding-char))))
2572 (and (fboundp 'char-charset)
2573 (not (eq (char-charset (preceding-char)) 'ascii)))))
2574 (setq ccol (1+ ccol)))))
2575 (if (and force (> col ccol))
2576 (progn
2577 (insert-char ?\ (- col ccol))
2578 col)
2579 ccol)))
2581 (defun yahtml-fill-paragraph (arg)
2582 (interactive "P")
2583 (let*((case-fold-search t) (p (point)) fill-prefix
2584 (e (or (yahtml-inner-environment-but "^\\(a\\|p\\)\\b" t) "html"))
2585 indent
2586 (startp (get 'YaTeX-inner-environment 'point))
2587 (prep (string-match "^pre$" e))
2588 (ps1 (if prep (default-value 'paragraph-start)
2589 paragraph-start))
2590 (ps2 (if prep (concat (default-value 'paragraph-start)
2591 "$\\|^\\s *</?pre>")
2592 paragraph-start)))
2593 (save-excursion
2594 (unwind-protect
2595 (progn
2596 (if prep
2597 (fset 'move-to-column 'yahtml-move-to-column))
2598 (save-excursion
2599 (beginning-of-line)
2600 (indent-to-column (yahtml-this-indent))
2601 (setq fill-prefix
2602 (buffer-substring (point) (point-beginning-of-line)))
2603 (delete-region (point) (point-beginning-of-line)))
2604 (fill-region-as-paragraph
2605 (progn (re-search-backward paragraph-start nil t)
2606 (or (save-excursion
2607 (goto-char (match-beginning 0))
2608 (if (looking-at "<")
2609 (forward-list)
2610 (goto-char (match-end 0))
2611 (skip-chars-forward " \t>"))
2612 (if (looking-at "[ \t]*$")
2613 (progn (forward-line 1) (point))))
2614 (point)))
2615 (progn (goto-char p)
2616 (re-search-forward ps2 nil t)
2617 (match-beginning 0))))
2618 (fset 'move-to-column yahtml-saved-move-to-column)))))
2620 ;;;
2621 ;;; ---------- move forward/backward field ----------
2622 ;;;
2623 (defun yahtml-element-path ()
2624 "Return the element path from <body> at point as a list"
2625 (let (path elm)
2626 (save-excursion
2627 (while (and (YaTeX-beginning-of-environment)
2628 (looking-at (concat "<\\(" yahtml-command-regexp "\\)\\>"))
2629 (not (string= (setq elm (downcase (YaTeX-match-string 1)))
2630 "body")))
2631 (setq path (cons elm path)
2632 elm nil))
2633 (and elm (setq path (cons elm path)))
2634 path)))
2636 (defun yahtml-forward-field (arg)
2637 "Move ARGth forward cell to table element.
2638 ENVINFO is a cons of target element name and its beginning point."
2639 (interactive "p")
2640 (let (inenv elm path sibs)
2641 (cond
2642 ((< arg 0) (yahtml-backward-field (- arg)))
2643 ((= arg 0) nil)
2644 ((and (setq path (nreverse (yahtml-element-path)))
2645 (catch 'sibling
2646 (while path
2647 (if (setq elm (car-safe
2648 (member (car path) '("td" "th" "li" "dt" "dd"))))
2649 (throw 'sibling elm))
2650 (setq path (cdr path)))))
2651 (setq inenv (YaTeX-in-environment-p elm)
2652 sibs (cdr (assoc elm '(("td" . "td\\|th")
2653 ("th" . "td\\|th")
2654 ("li" . "li")
2655 ("dt" . "dt\\|dd")
2656 ("dd" . "dt\\|dd")))))
2657 (goto-char (cdr inenv))
2658 (while (>= (setq arg (1- arg)) 0)
2659 (yahtml-goto-corresponding-begend)
2660 (if (looking-at "<") (forward-list 1))
2661 (skip-chars-forward "^<"))
2662 (while (looking-at "\\s \\|\\(</\\)")
2663 (if (match-beginning 1) (forward-list 1)
2664 (skip-chars-forward "\n\t ")))
2665 (forward-list 1) ;; step into environment
2666 (skip-chars-forward " \t\n")
2667 (if (looking-at (concat "<\\(" sibs "\\)\\>"))
2668 (forward-list 1))
2669 ))))
2672 ;;;
2673 ;;; ---------- indentation ----------
2674 ;;;
2675 (defun yahtml-indent-line-1 ()
2676 "Indent a line (faster wrapper)"
2677 (interactive)
2678 (let (indent)
2679 (if (and (save-excursion
2680 (beginning-of-line) (skip-chars-forward "\t ")
2681 (not (looking-at "<")))
2682 (save-excursion
2683 (forward-line -1)
2684 (while (and (not (bobp)) (looking-at "^\\s *$"))
2685 (forward-line -1))
2686 (skip-chars-forward "\t ")
2687 (setq indent (current-column))
2688 (not (looking-at "<"))))
2689 (progn
2690 (save-excursion
2691 (beginning-of-line)
2692 (skip-chars-forward " \t")
2693 (or (= (current-column) indent)
2694 (YaTeX-reindent indent)))
2695 (and (bolp) (skip-chars-forward " \t")))
2696 (yahtml-indent-line-real))))
2698 (defun yahtml-indent-line ()
2699 "Indent a line (Second level wrapper).
2700 See also yahtml-indent-line-1 and yahtml-indent-line-real."
2701 (interactive)
2702 (let ((cc (current-column)) (p (point)))
2703 (yahtml-indent-line-1)
2704 (and (= cc (current-column))
2705 (= p (point))
2706 (equal last-command 'yahtml-indent-line)
2707 (yahtml-forward-field 1))))
2710 (defun yahtml-this-indent ()
2711 (let ((envs "[uod]l\\|table\\|[ht][rhd0-6]\\|select\\|blockquote\\|center\\|menu\\|dir\\|d[td]\\|li")
2712 (itemizing-envs "^\\([uod]l\\|menu\\|dir\\|li\\|d[td]\\)$")
2713 (itms "<\\(dt\\|dd\\|li\\|t[rdh]\\|option\\)\\b")
2714 (excludes
2715 "\\b\\(a\\|p\\|span\\|code\\|tt\\|em\\|u\\|i\\|big\\|small\\|font\\)\\b")
2716 inenv p col peol (case-fold-search t))
2717 (save-excursion
2718 (beginning-of-line)
2719 (setq inenv (or (yahtml-inner-environment-but excludes t)
2720 "html")
2721 col (get 'YaTeX-inner-environment 'indent)
2722 p (get 'YaTeX-inner-environment 'point)
2723 op nil))
2724 (save-excursion
2725 (cond
2726 ((string-match (concat "^\\(" envs "\\)") inenv)
2727 (save-excursion
2728 (beginning-of-line)
2729 (skip-chars-forward " \t")
2730 (cond ;lookup current line's tag
2731 ((looking-at (concat "</\\(" envs "\\)>"))
2732 col)
2733 ((looking-at itms)
2734 (+ col yahtml-environment-indent))
2735 ((and yahtml-hate-too-deep-indentation
2736 (looking-at (concat "<\\(" envs "\\)")))
2737 (+ col (* 2 yahtml-environment-indent)))
2738 ((and (< p (point))
2739 (string-match itemizing-envs inenv)
2740 (save-excursion
2741 (and
2742 (setq op (point))
2743 (goto-char p)
2744 (re-search-forward itms op t)
2745 (progn
2746 (if yahtml-indent-listing-constant
2747 (setq col (+ (current-column)
2748 (if yahtml-faithful-to-htmllint 1 2)))
2749 (skip-chars-forward "^>")
2750 (skip-chars-forward ">")
2751 (skip-chars-forward " \t")
2752 (setq col (if (looking-at "$")
2753 (+ col yahtml-environment-indent)
2754 (current-column))))))))
2755 col)
2756 (t
2757 (+ col yahtml-environment-indent)))))
2758 (t col)))))
2760 (defun yahtml-indent-line-real ()
2761 "Indent current line."
2762 (interactive)
2763 (YaTeX-reindent (yahtml-this-indent))
2764 (if (bolp) (skip-chars-forward " \t"))
2765 (let (peol col inenv)
2766 (if (and (setq inenv (yahtml-on-begend-p))
2767 (string-match
2768 (concat "^\\<\\(" yahtml-struct-name-regexp "\\)") inenv))
2769 (save-excursion
2770 (setq peol (point-end-of-line))
2771 (or (= (char-after (point)) ?<)
2772 (progn (skip-chars-backward "^<") (forward-char -1)))
2773 (setq col (current-column))
2774 (if (and (yahtml-goto-corresponding-begend t)
2775 (> (point) peol)) ;if on the different line
2776 (YaTeX-reindent col))))))
2778 ;(defun yahtml-fill-item ()
2779 ; "Fill item HTML version"
2780 ; (interactive)
2781 ; (let (inenv p fill-prefix peol (case-fold-search t))
2782 ; (setq inenv (or (YaTeX-inner-environment) "html")
2783 ; p (get 'YaTeX-inner-environment 'point))
2784 ; (cond
2785 ; ((string-match "^[uod]l" inenv)
2786 ; (save-excursion
2787 ; (if (re-search-backward "<\\(d[td]\\|li\\)>[ \t\n]*" p t)
2788 ; (progn
2789 ; (goto-char (match-end 0))
2790 ; (setq col (current-column)))
2791 ; (error "No <li>, <dt>, <dd>")))
2792 ; (save-excursion
2793 ; (end-of-line)
2794 ; (setq peol (point))
2795 ; (newline)
2796 ; (indent-to-column col)
2797 ; (setq fill-prefix (buffer-substring (point) (1+ peol)))
2798 ; (delete-region (point) peol)
2799 ; (fill-region-as-paragraph
2800 ; (progn (re-search-backward paragraph-start nil t) (point))
2801 ; (progn (re-search-forward paragraph-start nil t 2)
2802 ; (match-beginning 0)))))
2803 ; (t nil))))
2805 ;;;
2806 ;;; ---------- Lint and Browsing ----------
2807 ;;;
2808 (defun yahtml-browse-menu ()
2809 "Browsing or other external process invokation menu."
2810 (interactive)
2811 (message "J)weblint p)Browse R)eload N)ewpage...")
2812 (let ((c (char-to-string (read-char))))
2813 (cond
2814 ((string-match "j" c)
2815 (yahtml-lint-buffer (current-buffer)))
2816 ((string-match "[bp]" c)
2817 (yahtml-browse-current-file))
2818 ((string-match "r" c)
2819 (yahtml-browse-reload))
2820 ((string-match "n" c)
2821 (call-interactively 'yahtml-newpage)))))
2823 (if (fboundp 'wrap-function-to-control-ime)
2824 (wrap-function-to-control-ime 'yahtml-browse-menu t nil))
2826 (defvar yahtml-lint-buffer "*weblint*")
2828 (defun yahtml-lint-buffer (buf)
2829 "Call lint on buffer BUF."
2830 (require 'yatexprc)
2831 (interactive "bCall lint on buffer: ")
2832 (setq buf (get-buffer buf))
2833 (YaTeX-save-buffers)
2834 (let ((bcmd (YaTeX-get-builtin "lint")))
2835 (and bcmd (setq bcmd (yahtml-untranslate-string bcmd)))
2836 (YaTeX-typeset
2837 (concat (or bcmd yahtml-lint-program)
2838 " " (file-name-nondirectory (buffer-file-name buf)))
2839 yahtml-lint-buffer "lint" "lint")))
2841 (defun yahtml-file-to-url (file)
2842 "Convert local unix file name to URL.
2843 If no matches found in yahtml-path-url-alist, return raw file name."
2844 (let ((list yahtml-path-url-alist) p url)
2845 (if (file-directory-p file)
2846 (setq file (expand-file-name yahtml-directory-index file))
2847 (setq file (expand-file-name file)))
2848 (if (string-match "^[A-Za-z]:/" file)
2849 (progn
2850 ;; (aset file 1 ?|) ;これは要らないらしい…
2851 (setq file (concat "///" file))))
2852 (while list
2853 (if (string-match (concat "^" (regexp-quote (car (car list)))) file)
2854 (setq url (cdr (car list))
2855 file (substring file (match-end 0))
2856 url (concat url file)
2857 list nil))
2858 (setq list (cdr list)))
2859 (or url (concat "file:" file))))
2861 (defun yahtml-url-to-path (file &optional basedir)
2862 "Convert local URL name to unix file name."
2863 (let ((list yahtml-path-url-alist) url realpath docroot
2864 (dirsufp (string-match "/$" file)))
2865 (setq basedir (or basedir
2866 (file-name-directory
2867 (expand-file-name default-directory))))
2868 (cond
2869 ((string-match "^/" file)
2870 (while list
2871 (if (file-directory-p (car (car list)))
2872 (progn
2873 (setq url (cdr (car list)))
2874 (if (string-match "\\(https?://[^/]*\\)/" url)
2875 (setq docroot (substring url (match-end 1)))
2876 (setq docroot url))
2877 (cond
2878 ((string-match (concat "^" (regexp-quote docroot)) file)
2879 (setq realpath
2880 (expand-file-name
2881 (substring
2882 file
2883 (if (= (aref file (1- (match-end 0))) ?/)
2884 (match-end 0) ; "/foo"
2885 (min (1+ (match-end 0)) (length file)))) ; "/~foo"
2886 (car (car list))))))
2887 (if realpath
2888 (progn (setq list nil)
2889 (if (and dirsufp (not (string-match "/$" realpath)))
2890 (setq realpath (concat realpath "/")))))))
2891 (setq list (cdr list)))
2892 realpath)
2893 (t file))))
2895 (defun yahtml-browse-current-file ()
2896 "Call WWW browser on current file."
2897 (interactive)
2898 (basic-save-buffer)
2899 (yahtml-browse-html (yahtml-file-to-url (buffer-file-name))))
2901 (defun yahtml-browse-reload ()
2902 "Send `reload' event to netscape."
2903 (let ((pb "* WWW Browser *") (cb (current-buffer)))
2904 (cond
2905 ((string-match "[Nn]etscape" yahtml-www-browser)
2906 (if (get-buffer pb)
2907 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
2908 ;;(or (get 'yahtml-netscape-sentinel 'url)
2909 ;; (error "Reload should be called after Browsing."))
2910 (put 'yahtml-netscape-sentinel 'url
2911 (yahtml-file-to-url (buffer-file-name)))
2912 (basic-save-buffer)
2913 (set-process-sentinel
2914 (setq yahtml-browser-process
2915 (start-process
2916 "browser" pb shell-file-name yahtml-shell-command-option ;"-c"
2917 (format "%s -remote 'reload'" yahtml-www-browser)))
2918 'yahtml-netscape-sentinel))
2919 (t
2920 (message "Sorry, RELOAD is supported only for Netscape.")))))
2922 ;;; ---------- Intelligent newline ----------
2923 (defun yahtml-intelligent-newline (arg)
2924 "Intelligent newline for HTML"
2925 (interactive "P")
2926 (let (env func)
2927 (end-of-line)
2928 (setq env (downcase (or (yahtml-inner-environment-but "^\\(a\\|p\\)\\b" t)
2929 "html")))
2930 (setq func (intern-soft (concat "yahtml-intelligent-newline-" env)))
2931 (newline)
2932 (if (and env func (fboundp func))
2933 ;; if intelligent line function is defined, call that
2934 (funcall func)
2935 ;; else do the default action
2936 (if (string-match yahtml-p-prefered-env-regexp env)
2937 (yahtml-insert-p)))))
2939 (defun yahtml-intelligent-newline-ul ()
2940 (interactive)
2941 (yahtml-insert-single "li")
2942 (or yahtml-always-/li yahtml-faithful-to-htmllint (insert " "))
2943 (yahtml-indent-line))
2945 (fset 'yahtml-intelligent-newline-ol 'yahtml-intelligent-newline-ul)
2947 (defun yahtml-intelligent-newline-datalist ()
2948 (interactive)
2949 (yahtml-insert-form "option")
2950 (save-excursion (yahtml-insert-form "/option")))
2952 (defun yahtml-intelligent-newline-dl ()
2953 (interactive)
2954 (let ((case-fold-search t))
2955 (if (save-excursion
2956 (re-search-backward "<\\(\\(dt\\)\\|\\(dd\\)\\)[ \t>]"
2957 (get 'YaTeX-inner-environment 'point) t))
2958 (cond
2959 ((match-beginning 2)
2960 (yahtml-insert-single "dd")
2961 (or yahtml-always-/dd yahtml-faithful-to-htmllint (insert " "))
2962 (setq yahtml-last-single-cmd "dt"))
2963 ((match-beginning 3)
2964 (yahtml-insert-single "dt")
2965 (or yahtml-always-/dt yahtml-faithful-to-htmllint (insert " "))
2966 (setq yahtml-last-single-cmd "dd")))
2967 (yahtml-insert-single "dt")
2968 (or yahtml-always-/li yahtml-faithful-to-htmllint (insert " "))
2969 (setq yahtml-last-single-cmd "dd"))
2970 (yahtml-indent-line)
2971 (and (string-match yahtml-p-prefered-env-regexp "dl")
2972 (string-equal yahtml-last-single-cmd "dt")
2973 (yahtml-insert-p nil))))
2975 (defun yahtml-intelligent-newline-select ()
2976 (interactive)
2977 (yahtml-insert-single (if yahtml-prefer-upcases "OPTION" "option"))
2978 (yahtml-indent-line))
2980 (defun yahtml-intelligent-newline-style ()
2981 (interactive)
2982 (if (save-excursion
2983 (and
2984 (re-search-backward "<style\\|<!-- " nil t)
2985 (looking-at "<style")))
2986 (let (c)
2987 (yahtml-indent-line)
2988 (setq c (current-column))
2989 (insert "<!--\n")
2990 (YaTeX-reindent c)
2991 (insert "-->")
2992 (beginning-of-line)
2993 (open-line 1)
2994 (YaTeX-reindent c))))
2996 (defun yahtml-intelligent-newline-head ()
2997 (let ((title (read-string-with-history "Document title: "))
2998 (b "<title>") (e "</title>") p)
2999 (yahtml-indent-line)
3000 (insert (format "%s" (if yahtml-prefer-upcases (upcase b) b)))
3001 (setq p (point))
3002 (insert (format "%s%s" title (if yahtml-prefer-upcases (upcase e) e)))
3003 (if (string= "" title) (goto-char p))
3004 (setq yahtml-last-begend "body")))
3006 (defun yahtml-intelligent-newline-script ()
3007 (let ((p (point)) b)
3008 (if (save-excursion
3009 (and
3010 (setq b (re-search-backward "<script\\>" nil t))
3011 (re-search-forward
3012 "\\(javascript\\)\\|\\(tcl\\)\\|\\(vbscript\\)" p t)))
3013 (let ((js (match-end 1)) (tcl (match-end 2)) (vb (match-end 3))
3014 c (srcp (re-search-backward "src=" b t)))
3015 (goto-char p)
3016 (yahtml-indent-line)
3017 (setq c (current-column))
3018 (if srcp
3019 nil
3020 (insert "<!--\n" (cond (js "//") (tcl "#") (vb "'")) " -->")
3021 (beginning-of-line)
3022 (open-line 1)
3023 (YaTeX-reindent c))))))
3025 (defun yahtml-intelligent-newline-table ()
3026 (let ((cp (point)) (p (point)) tb rb (cols 0) th line (i 0) fmt
3027 (ptn "\\(<t[dh]\\>\\)\\|<t\\(r\\|head\\|body\\)\\>"))
3028 (cond
3029 ((save-excursion (setq tb (YaTeX-beginning-of-environment "table")))
3030 (while (and (setq rb (re-search-backward ptn tb t))
3031 (match-beginning 1))
3032 (setq th (looking-at "<th")) ;Remember if first-child is tr or not
3033 (goto-char (match-end 0))
3034 (skip-chars-forward " \t\n")
3035 (if (and (search-forward "colspan\\s *=" p t)
3036 (progn
3037 (skip-chars-forward "\"' \t\n")
3038 (looking-at "[0-9]+")))
3039 (setq cols (+ (YaTeX-str2int (YaTeX-match-string 0)) cols))
3040 (setq cols (1+ cols)))
3041 (goto-char rb)
3042 (setq p (point)))
3043 (if (> cols 0)
3044 (message "%s columns found. %s"
3045 cols (if YaTeX-japan "新しいtr(N)? 前のtrの複写?(D)?: "
3046 "New tr?(N) or Duplicate")))
3047 (cond
3048 ((and (> cols 0)
3049 (memq (read-char) '(?d ?D))) ;Duplication mode
3050 (setq line (YaTeX-buffer-substring (point) (1- cp))))
3051 (t ;empty cells
3052 (setq line "<tr>" i 0)
3053 (if (> cols 0)
3054 (while (> cols i)
3055 (setq line (concat line (if (and (= i 0) th) "<th></th>"
3056 "<td></td>"))
3057 th nil i (1+ i)))
3058 (setq fmt (read-string-with-history
3059 "`th' or `td' format: " "th td td"))
3060 (while (string-match "t\\(h\\)\\|td" fmt i)
3061 (setq line (concat line (if (match-beginning 1) "<th></th>"
3062 "<td></td>"))
3063 i (match-end 0))))
3064 (setq line (concat line "</tr>"))))
3065 (goto-char cp)
3066 (if th
3067 (message
3068 "Type `%s' to change td from/to th."
3069 (key-description (car (where-is-internal 'yahtml-change-*)))))
3070 (if (string< "" line)
3071 (progn
3072 (insert line)
3073 (goto-char (+ 8 cp))
3074 (yahtml-indent-line)))))))
3076 (defun yahtml-intelligent-newline-audio ()
3077 (let (b e)
3078 (if (save-excursion
3079 (goto-char (setq b (get 'YaTeX-inner-environment 'point)))
3080 (forward-list 1)
3081 (setq e (point))
3082 (catch 'src
3083 (while (re-search-forward "\\s src\\>" e t)
3084 (skip-chars-forward " \t\n")
3085 (and (looking-at "=") (throw 'src t)))))
3086 ;; if src= attribute found, do nothing
3087 (setq yahtml-last-begend "p")
3088 (yahtml-insert-single "source")
3089 )))
3090 (fset 'yahtml-intelligent-newline-video 'yahtml-intelligent-newline-audio)
3092 (defun yahtml-intelligent-newline-iframe ()
3093 (insert "<p>Your browser does not support iframes.</p>"))
3095 ;;; ---------- Marking ----------
3096 (defun yahtml-mark-begend ()
3097 "Mark current tag"
3098 (interactive)
3099 (YaTeX-beginning-of-environment)
3100 (let ((p (point)))
3101 (save-excursion
3102 (skip-chars-backward " \t" (point-beginning-of-line))
3103 (if (bolp) (setq p (point))))
3104 (push-mark p t))
3105 (yahtml-goto-corresponding-begend)
3106 (forward-list 1)
3107 (if (eolp) (forward-char 1)))
3109 ;;; ---------- complete marks ----------
3110 (defun yahtml-char-entity-ref ()
3111 "Complete &gt;, &lt;, &amp;, and &quot;."
3112 (interactive)
3113 (message "1:< 2:> 3:& 4:\" 5:' 6:nbsp")
3114 (let ((c (read-char)) d)
3115 (setq d (if (or (< c ?0) (> c ?7))
3116 (string-match (regexp-quote (char-to-string c)) "<>&\"' ")
3117 (- c ?1)))
3118 (cond
3119 ((null d) (insert (format "&#x%x;" c)))
3120 ((and (>= d 0) (<= d 6))
3121 (insert (format "&%s;"
3122 (nth d '("lt" "gt" "amp" "quot" "apos" "nbsp"))))))))
3125 ;;; ---------- jump to error line ----------
3126 (defun yahtml-prev-error ()
3127 "Jump to previous error seeing lint buffer."
3128 (interactive)
3129 (or (get-buffer yahtml-lint-buffer)
3130 (error "No lint program ran."))
3131 (YaTeX-showup-buffer yahtml-lint-buffer nil t)
3132 (yahtml-jump-to-error-line t))
3134 (defun yahtml-jump-to-error-line (&optional sit)
3135 (interactive "P")
3136 (let ((p (point)) (e (point-end-of-line)))
3137 (end-of-line)
3138 (if (re-search-backward yahtml-error-line-regexp nil t)
3139 (let ((f (if (string= "" (YaTeX-match-string 1))
3140 YaTeX-current-file-name
3141 (YaTeX-match-string 1)))
3142 (l (YaTeX-str2int (or (YaTeX-match-string 2)
3143 (YaTeX-match-string 3)))))
3144 (if sit (sit-for 1))
3145 (forward-line -1)
3146 (YaTeX-showup-buffer (YaTeX-switch-to-buffer f t) nil t)
3147 (goto-line l))
3148 (message "No line number usage"))))
3150 ;;; ---------- Style Sheet Support ----------
3151 (defvar yahtml-css-class-alist nil
3152 "Alist of elements vs. their classes")
3154 (defun yahtml-css-collect-classes-region (beg end &optional initial)
3155 (save-excursion
3156 (save-restriction
3157 (narrow-to-region beg end)
3158 (goto-char (point-min))
3159 (let ((alist initial) b e element class a)
3160 (setq b (point))
3161 (while (re-search-forward "\\({\\)\\|\\(@import\\)" nil t)
3162 (if (match-beginning 2)
3163 (let ((f (YaTeX-buffer-substring
3164 (progn (skip-chars-forward "^\"")(1+ (point)))
3165 (progn (forward-char 1)
3166 (skip-chars-forward "^\"")(point)))))
3167 (if (file-exists-p f)
3168 (setq alist
3169 (append alist (yahtml-css-collect-classes-file
3170 f initial)))))
3171 (setq e (point))
3172 (goto-char b)
3173 (while (re-search-forward ;ちょといい加減なREGEXP
3174 "\\([a-z*][-a-z0-9]*\\)?\\.\\([-a-z0-9][-a-z0-9]*\\)\\>"
3175 e t)
3176 (setq element (YaTeX-match-string 1)
3177 class (YaTeX-match-string 2))
3178 ;;if starts with period (match-string 1 is nil),
3179 ;;this is global class
3180 (setq element (downcase (or element "*")))
3181 (if (setq a (assoc element alist))
3182 (or (assoc class (cdr a))
3183 (setcdr a (cons (list class) (cdr a))))
3184 (setq alist (cons (list element (list class)) alist))))
3185 (goto-char (1- e))
3186 (search-forward "}" nil 1) ;1=move to limit when not found.
3187 (setq b (point))))
3188 alist))))
3190 (defun yahtml-css-collect-classes-buffer (&optional initial)
3191 (interactive)
3192 (yahtml-css-collect-classes-region (point-min) (point-max) initial))
3194 (defun yahtml-css-collect-classes-file (file &optional initial)
3195 (let*((hilit-auto-highlight nil)
3196 (buf (get-buffer-create
3197 (format " *css-collection*%s" (file-name-nondirectory file))))
3198 (cb (current-buffer)))
3199 (unwind-protect
3200 (progn
3201 (set-buffer buf)
3202 (insert-file-contents file)
3203 (cd (or (file-name-directory file) "."))
3204 (yahtml-css-collect-classes-buffer initial))
3205 (if (eq buf cb)
3206 nil
3207 (kill-buffer buf)
3208 (set-buffer cb)))))
3210 (defun yahtml-css-scan-styles ()
3211 (save-excursion
3212 (goto-char (point-min))
3213 (set (make-local-variable 'yahtml-css-class-alist) nil)
3214 (let (b tag type e href alist)
3215 (while (re-search-forward "<\\(style\\|link\\)" nil t)
3216 (setq b (match-beginning 0)
3217 tag (YaTeX-match-string 1))
3218 (cond
3219 ((string-match "style" tag)
3220 (goto-char b)
3221 (save-excursion (forward-list 1) (setq e (point)))
3222 (cond
3223 ((search-forward "text/css" e 1) ;css definition starts
3224 (setq alist
3225 (yahtml-css-collect-classes-region
3226 (point) (progn (search-forward "</style>") (point))
3227 alist)))))
3228 ((and (string-match "link" tag)
3229 (stringp (setq type (yahtml-get-attrvalue "type")))
3230 (string-match "text/css" type)
3231 (setq href (yahtml-get-attrvalue "href"))
3232 (file-exists-p (yahtml-url-to-path href)))
3233 (setq alist
3234 (yahtml-css-collect-classes-file
3235 (yahtml-url-to-path href) alist))))
3236 (setq yahtml-css-class-alist alist)))))
3238 (defun yahtml-css-get-element-completion-alist (element)
3239 (let ((alist (cdr-safe (assoc (downcase element) yahtml-css-class-alist)))
3240 (global (cdr-safe (assoc "*" yahtml-css-class-alist))))
3241 (and (or alist global)
3242 (append alist global))))
3244 ;;; ---------- ----------
3246 ;;;
3247 ;;hilit19
3248 ;;;
3249 (defvar yahtml-default-face-table
3250 '(
3251 (form black/ivory white/hex-442233 italic)
3252 ))
3253 (defvar yahtml-hilit-patterns-alist
3254 '(
3255 'case-fold
3256 ;; comments
3257 ("<!--\\s " "-->" comment)
3258 ;; include&exec
3259 ("<!--#\\(include\\|exec\\|config\\|fsize\\|flastmod\\)" "-->" include)
3260 ;; string
3261 (hilit-string-find ?\\ string)
3262 (yahtml-hilit-region-tag "<\\(strong\\|b\\)\\>" bold)
3263 ("</?[uod]l>" 0 decl)
3264 ("<\\(di\\|dt\\|li\\|dd\\)>" 0 label)
3265 (yahtml-hilit-region-tag "<\\(em\\|i\\>\\)" italic)
3266 ;("<a\\s +href" "</a>" crossref) ;good for hilit19, but odd for font-lock..
3267 (yahtml-hilit-region-tag "<\\(a\\)\\s +href" crossref)
3268 (yahtml-hilit-region-tag-itself "</?\\sw+\\>" decl)
3269 ))
3271 (defun yahtml-hilit-region-tag (tag)
3272 "Return list of start/end point of <TAG> form."
3273 (if (re-search-forward tag nil t)
3274 (let ((m0 (match-beginning 0)) (e0 (match-end 0))
3275 (elm (YaTeX-match-string 1)))
3276 (skip-chars-forward "^>")
3277 (prog1
3278 (cons (1+ (point))
3279 (progn (re-search-forward (concat "</" elm ">") nil t)
3280 (match-beginning 0)))
3281 (goto-char e0)))))
3283 (defun yahtml-hilit-region-tag-itself (ptn)
3284 "Return list of start/end point of <tag options...> itself."
3285 (if (re-search-forward ptn nil t)
3286 (let ((m0 (match-beginning 0)) (e0 (match-end 0)))
3287 (skip-chars-forward "^<>")
3288 (if (eq (char-after (point)) ?<) nil
3289 (prog1
3290 (cons m0 (min (point-max) (1+ (point))))
3291 (goto-char e0))))))
3293 ;(setq hilit-patterns-alist (delq (assq 'yahtml-mode hilit-patterns-alist) hilit-patterns-alist))
3294 (and yahtml-use-hilit19
3295 (or (assq 'yahtml-mode hilit-patterns-alist)
3296 (setq hilit-patterns-alist
3297 (cons (cons 'yahtml-mode yahtml-hilit-patterns-alist)
3298 hilit-patterns-alist))))
3299 ;;;
3300 ;; for font-lock
3301 ;;;
3303 ; <<STATIC KEYWORDS BELOW NOT USED>>
3304 ;(defvar yahtml-font-lock-keywords
3305 ; '(
3306 ; ;; comments
3307 ; ("<!--\\s .* -->" . font-lock-comment-face)
3308 ; ;; include&exec
3309 ; ("<!--#\\(include\\|exec\\|config\\|fsize\\|flastmod\\).*-->"
3310 ; 0 font-lock-include-face keep)
3311 ; ;; string
3312 ; ;(hilit-string-find ?\\ string)
3313 ; ;(yahtml-hilit-region-tag "\\(em\\|strong\\)" bold)
3314 ; ("</?[uod]l>" 0 font-lock-keyword-face)
3315 ; ("<\\(di\\|dt\\|li\\|dd\\)>" 0 font-lock-label-face)
3316 ; ("<a\\s +href=.*</a>" (0 font-lock-crossref-face keep))
3317 ; ;(yahtml-hilit-region-tag-itself "</?\\sw+\\>" decl)
3318 ; ("</?\\sw+\\>" (yahtml-fontify-to-tagend nil nil))
3319 ; )
3320 ; "*Defualt font-lock-keywords for yahtml-mode.")
3321 (defvar yahtml-font-lock-keywords
3322 (YaTeX-convert-pattern-hilit2fontlock yahtml-hilit-patterns-alist)
3323 "Default fontifying patterns for yahtml-mode")
3325 (defun yahtml-font-lock-set-default-keywords ()
3326 (put 'yahtml-mode 'font-lock-defaults
3327 '(yahtml-font-lock-keywords nil t)))
3329 (if yahtml-use-font-lock
3330 (progn
3331 (if (and (boundp 'hilit-mode-enable-list) hilit-mode-enable-list)
3332 ;;for those who use both hilit19 and font-lock
3333 (if (eq (car hilit-mode-enable-list) 'not)
3334 (or (member 'yahtml-mode hilit-mode-enable-list)
3335 (nconc hilit-mode-enable-list (list 'yahtml-mode)))
3336 (setq hilit-mode-enable-list
3337 (delq 'yahtml-mode hilit-mode-enable-list))))
3338 (yahtml-font-lock-set-default-keywords)))
3340 (defun yahtml-font-lock-recenter (&optional arg)
3341 (interactive "P")
3342 (font-lock-mode -1) ;is stupid, but sure.
3343 (font-lock-mode 1))
3345 ;;;
3346 ;; Drag-n-Drop
3347 ;;;
3348 (defun yahtml-dnd-handler (uri action)
3349 "DnD handler for yahtml mode
3350 Convert image URI to img-src and others to a-href."
3351 (let*((file (dnd-get-local-file-name uri))
3352 (path (if file (file-relative-name file) uri))
3353 (case-fold-search t)
3354 (geom ""))
3355 (cond
3356 ((memq action '(copy link move private))
3357 (cond
3358 ((string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\|tiff?\\)$" path)
3359 (if file
3360 (setq geom (yahtml-get-image-info path)
3361 geom (if (car geom)
3362 (apply 'format " width=\"%s\" height=\"%s\"" geom)
3363 "")))
3364 (insert (format "<img src=\"%s\" alt=\"%s\"%s>"
3365 path (file-name-nondirectory path) geom)))
3367 (t (insert (format "<a href=\"%s\"></a>" path))
3368 (forward-char -4))))
3369 (t (message "No handler for action `%s'" action))))
3370 action)
3372 (run-hooks 'yahtml-load-hook)
3373 (provide 'yahtml)
3375 ; Local variables:
3376 ; fill-prefix: ";;; "
3377 ; paragraph-start: "^$\\| \\|;;;$"
3378 ; paragraph-separate: "^$\\| \\|;;;$"
3379 ; End: