yatex

view yahtml.el @ 552:c3b9e81bd432

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