yatex

view yahtml.el @ 438:1b9beabd3fd1

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