yatex

view yahtml.el @ 437:27f00e6e0150

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