yatex

view yahtml.el @ 570:2ed79846fd53

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