yatex

view yahtml.el @ 529:b742adfa30e2

UTF-8 mnemonic for command line option changed as s/utf-8/utf8/
author HIROSE Yuuji <yuuji@gentei.org>
date Wed, 23 May 2018 08:02:11 +0900
parents 723f136edde5
children d97881f33e28
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 ("http-equiv" content)))
1629 (defun yahtml:meta ()
1630 (let ((attr (completing-read-with-history
1631 "Meta Attribute: " yahtml:meta-attrs))
1632 (case-fold-search t)
1633 (completion-ignore-case t)
1634 todonext name http-equiv content)
1635 (cond
1636 ((string= "" attr) nil)
1637 ((and (setq todonext (cdr-safe (assoc attr yahtml:meta-attrs)))
1638 (eq 'value (car todonext)))
1639 (yahtml-make-optional-argument attr (yahtml-read-parameter attr)))
1640 ((eq 'content (car todonext))
1641 (setq name (if (cdr todonext)
1642 (completing-read-with-history
1643 (format "%s: " attr) (cdr todonext))
1644 (yahtml-read-parameter attr)))
1645 (concat
1646 (yahtml-make-optional-argument attr name)
1647 (yahtml-make-optional-argument
1648 "content"
1649 (cond
1650 ((string-match "date" name)
1651 (read-string-with-history "Date: " (current-time-string)))
1652 ((string-match "author" name)
1653 (read-string-with-history "Author: "
1654 (if (and (user-full-name) (string< "" (user-full-name)))
1655 (user-full-name)
1656 (user-login-name))))
1657 ((string-match "GENERATOR" name)
1658 (setq content (read-string-with-history
1659 "Generator: " "User-agent: "))
1660 (if (string-match "yahtml" content)
1661 (message "Thank you!"))
1662 content)
1663 ((string-match "content-type" name)
1664 (if (string-match "http-equiv" attr )
1665 (error "Use <meta charset=\"...\" instead.. See docs/qanda.")
1666 (yahtml-make-optional-argument
1667 "content" (yahtml-read-parameter "content"))))
1668 (t (read-string-with-history (concat name ": ")))))))
1669 (t (yahtml-make-optional-argument
1670 attr (yahtml-read-parameter attr))))))
1672 (defun yahtml:br ()
1673 (yahtml-make-optional-argument "clear" (yahtml-read-parameter "clear")))
1675 (defun yahtml:object ()
1676 (let ((codetype (yahtml-read-parameter "codetype" "application/java"))
1677 data classid)
1678 (cond
1679 ((string-match "java" codetype)
1680 (let ((completion-ignored-extensions
1681 ;;any extensions except ".class"
1682 '(".java" ".html" ".htm" ".gif" ".jpg" ".jpeg" ".png")))
1683 (setq classid (concat "java:"
1684 (yahtml-read-parameter "class file name"))))
1685 (concat
1686 (yahtml-make-optional-argument "codetype" codetype)
1687 (yahtml-make-optional-argument "classid" classid)
1688 (yahtml-make-optional-argument
1689 "width" (yahtml-read-parameter "width"))
1690 (yahtml-make-optional-argument
1691 "height" (yahtml-read-parameter "height"))))
1692 (t
1693 ""))))
1695 (defun yahtml:abbr ()
1696 "Add-in function for abbr."
1697 (yahtml-make-optional-argument "title" (yahtml-read-parameter "title")))
1699 (defun yahtml:button ()
1700 (concat
1701 (yahtml-make-optional-argument
1702 "name" (yahtml-read-parameter "name"))
1703 (yahtml-make-optional-argument
1704 "type" (yahtml-read-parameter
1705 "type" "button" '(("submit")("reset")("button"))))
1706 (yahtml-make-optional-argument
1707 "value" (yahtml-read-parameter "value"))))
1709 ;;; ---------- Simple tag ----------
1710 (defun yahtml-insert-tag (region-mode &optional tag)
1711 "Insert <TAG> </TAG> and put cursor inside of them."
1712 (interactive "P")
1713 (setq yahtml-current-completion-type 'inline
1714 region-mode (or region-mode (YaTeX-region-active-p)))
1715 (or tag
1716 (let ((completion-ignore-case t))
1717 (setq tag
1718 (YaTeX-cplread-with-learning
1719 (format "Tag %s(default %s): "
1720 (if region-mode "region: " "") yahtml-last-typeface-cmd)
1721 'yahtml-typeface-table 'yahtml-user-typeface-table
1722 'yahtml-tmp-typeface-table))))
1723 (if (string= "" tag) (setq tag yahtml-last-typeface-cmd))
1724 (setq tag (or (cdr (assoc tag yahtml-typeface-table)) tag))
1725 (setq yahtml-last-typeface-cmd tag
1726 tag (funcall (if yahtml-prefer-upcases 'upcase 'downcase) tag))
1727 (if region-mode
1728 (if (if (string< "19" emacs-version) (mark t) (mark))
1729 (save-excursion
1730 (if (> (point) (mark)) (exchange-point-and-mark))
1731 (insert (format "<%s%s>" tag (yahtml-addin tag)))
1732 (exchange-point-and-mark)
1733 (insert "</" tag ">"))
1734 (message "No mark set now"))
1735 (insert (format "<%s%s>" tag (yahtml-addin tag)))
1736 (save-excursion (insert (format "</%s>" tag)))))
1738 (defun yahtml-insert-tag-region (&optional tag)
1739 "Call yahtml-insert-tag with region mode."
1740 (interactive)
1741 (yahtml-insert-tag t tag))
1743 (defvar yahtml-need-single-closer nil) ;for test
1744 (defun yahtml-insert-single (cmd)
1745 "Insert <CMD>."
1746 (interactive
1747 (list
1748 (let ((completion-ignore-case t))
1749 (YaTeX-cplread-with-learning
1750 (format "Command%s: "
1751 (if yahtml-last-single-cmd
1752 (concat "(default " yahtml-last-single-cmd ")") ""))
1753 'yahtml-single-cmd-table 'yahtml-user-single-cmd-table
1754 'yahtml-tmp-single-cmd-table))))
1755 (if (string= "" cmd) (setq cmd yahtml-last-single-cmd))
1756 (setq yahtml-last-single-cmd
1757 (or (cdr (assoc cmd yahtml-single-cmd-table)) cmd))
1758 (setq cmd (funcall (if yahtml-prefer-upcases 'upcase 'downcase)
1759 yahtml-last-single-cmd))
1760 (insert (format "<%s%s%s>"
1761 cmd
1762 (yahtml-addin cmd)
1763 (if (and yahtml-need-single-closer
1764 (assoc cmd '(("br")("hr"))))
1765 " /" "")))
1766 (if (assoc cmd yahtml-env-table)
1767 (save-excursion (insert (format "</%s>" cmd)))))
1769 (defun yahtml-insert-p (&optional arg)
1770 "Convenient function to insert <p></p>"
1771 (interactive "P")
1772 (if (or yahtml-always-/p arg) (yahtml-insert-tag arg "p")
1773 (yahtml-insert-single "p")))
1775 (defun yahtml-insert-amps (arg)
1776 "Insert char-entity references via ampersand"
1777 ;; Thanks; http://www.tsc.co.jp/~asada/html/wdg40_f/entities/
1778 (interactive "P")
1779 (let*((mess "") c
1780 (list (append yahtml-entity-reference-chars-alist-default
1781 yahtml-entity-reference-chars-alist))
1782 (l list))
1783 (while l
1784 (setq mess (format "%s %c" mess (car (car l)) (cdr (car l)))
1785 l (cdr l)))
1786 (message "Char-entity reference: %s SPC=& RET=&; BS=%s Other=&#..;"
1787 mess (if YaTeX-japan "直前の文字" "Preceding-Char"))
1788 (setq c (read-char))
1789 (cond
1790 ((equal c (car-safe (assoc c list)))
1791 (insert (format "&%s;" (cdr (assoc c list)))))
1792 ((or (equal c ?\n) (equal c ?\r))
1793 (insert "&;")
1794 (forward-char -1))
1795 ((equal c ? )
1796 (insert ?&))
1797 ((and (memq c '(127 8))
1798 (setq c (preceding-char))
1799 (delete-backward-char 1)
1800 nil)) ;Fall through to the next 't block
1801 (t (insert (format "&#x%x;" c))))))
1803 (defun yahtml:!--\#include ()
1804 (let ((file (yahtml-read-parameter "file" "")))
1805 (format "%s=\"%s\"--" (if (string-match "/" file) "virtual" "file") file)))
1807 (defun yahtml:!--\#exec ()
1808 (format "cmd=\"%s\"--"
1809 (yahtml-read-parameter "cmd" "" '(("cmd" . command)))))
1811 (defun yahtml:media-read-options (&optional opts-alist)
1812 (let*((delim " ")
1813 (minibuffer-completion-table
1814 (or opts-alist '(("autoplay") ("controls") ("loop") ("preload"))))
1815 (quotekey (substitute-command-keys "\\[quoted-insert]")))
1816 (read-from-minibuffer-with-history
1817 (format "Media Opts(`%s SPC' for more options): " quotekey)
1818 "controls" YaTeX-minibuffer-completion-map)))
1820 (defun yahtml:audio ()
1821 ;preload autoplay loop controls: `src' be specified via `source'
1822 (yahtml:media-read-options))
1824 (defun yahtml:video ()
1825 ;`src' be specified via `source'
1826 (let ((poster (yahtml-make-optional-argument
1827 "poster"
1828 (yahtml-read-file-name-regexp
1829 "Poster: " "\\.\\(gif\\|png\\|jpg\\|w?bmp\\|pict\\|tif\\)"
1830 "")))
1831 (opts (yahtml:media-read-options)))
1832 (concat poster (if (string< "" opts) (concat " " opts)))))
1834 (defvar yahtml-media-file-regexp
1835 "\\.\\(mp[0-9]\\|wav\\|og[gv]\\|opus\\|aac\\)"
1836 "*Default filename regexp of media files.")
1838 (defun yahtml:source ()
1839 ;; source element must have src attribute
1840 (format "src=\"%s\"" (yahtml-read-file-name-regexp
1841 "source: " yahtml-media-file-regexp "" "" nil "")))
1843 (defun yahtml:figure ()
1844 (setq yahtml-last-typeface-cmd "figcaption"))
1846 (defun yahtml:iframe ()
1847 (let ((src (yahtml-read-url "src: ")))
1848 (concat
1849 (yahtml-make-optional-argument "src" src)
1850 (yahtml-make-optional-argument
1851 "width" (YaTeX-read-string-or-skip "width: "))
1852 (yahtml-make-optional-argument
1853 "height" (YaTeX-read-string-or-skip "height: ")))))
1855 ;;; ---------- Jump ----------
1856 (defun yahtml-on-href-p ()
1857 "Check if point is on href clause."
1858 (let ((p (point)) e cmd (case-fold-search t))
1859 (save-excursion
1860 (and ;;(string= (YaTeX-inner-environment t) "a") ;aでなくても許可にした
1861 (save-excursion
1862 ;;(search-forward "</a>" nil t) ;aでなくても許可にした
1863 (search-forward "[\" \t\n]" nil t)
1864 (setq e (point)))
1865 ;(goto-char (get 'YaTeX-inner-environment 'point))
1866 (re-search-backward "<\\(a\\|link\\)\\>" nil t)
1867 (search-forward "href" e t)
1868 (search-forward "=" e t)
1869 (progn
1870 (skip-chars-forward " \t\n")
1871 (looking-at "\"?\\([^\"> \t\n]+\\)\"?"))
1872 (< p (match-end 0))
1873 (yahtml-unescape-string (YaTeX-match-string 1))))))
1875 (defun yahtml-netscape-sentinel (proc mes)
1876 (cond
1877 ((null (buffer-name (process-buffer proc)))
1878 (set-process-buffer proc nil))
1879 ((eq (process-status proc) 'exit)
1880 (let ((cb (current-buffer)))
1881 (set-buffer (process-buffer proc))
1882 (goto-char (point-min))
1883 (if (search-forward "not running" nil t)
1884 (progn
1885 (message "Starting netscape...")
1886 (start-process
1887 "browser" (process-buffer proc)
1888 shell-file-name yahtml-shell-command-option
1889 (format "%s \"%s\"" yahtml-www-browser
1890 (get 'yahtml-netscape-sentinel 'url)))
1891 (message "Starting netscape...Done")))
1892 (set-buffer cb)))))
1894 (defvar yahtml-browser-process nil)
1896 (defun yahtml-browse-html (href)
1897 "Call WWW Browser to see HREF."
1898 (let ((pb "* WWW Browser *") (cb (current-buffer)))
1899 (cond
1900 ((string-match "^start\\>" yahtml-www-browser)
1901 (if (get-buffer pb)
1902 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
1903 (put 'yahtml-netscape-sentinel 'url href)
1904 (set-process-sentinel
1905 (setq yahtml-browser-process
1906 (start-process
1907 "browser" pb shell-file-name yahtml-shell-command-option
1908 (format "%s \"%s\"" yahtml-www-browser href)))
1909 'yahtml-netscape-sentinel))
1910 ((and (string-match
1911 "[Nn]etscape\\|[Ff]irefox\\|[Mm]ozilla" yahtml-www-browser)
1912 (not (eq system-type 'windows-nt)))
1913 (if (get-buffer pb)
1914 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
1915 (put 'yahtml-netscape-sentinel 'url href)
1916 (set-process-sentinel
1917 (setq yahtml-browser-process
1918 (start-process
1919 "browser" pb shell-file-name yahtml-shell-command-option ;"-c"
1920 (format "%s -remote \"openURL(%s)\"" yahtml-www-browser href)))
1921 'yahtml-netscape-sentinel))
1922 ((and (string= "w3" yahtml-www-browser) (fboundp 'w3-fetch))
1923 (w3-fetch href))
1924 ((stringp yahtml-www-browser)
1925 (if (and yahtml-browser-process
1926 (eq (process-status yahtml-browser-process) 'run))
1927 (message "%s is already running" yahtml-www-browser)
1928 (setq yahtml-browser-process
1929 (start-process
1930 "browser" "* WWW Browser *"
1931 shell-file-name yahtml-shell-command-option
1932 (format "%s \"%s\"" yahtml-www-browser href)))))
1933 (t
1934 (message "Sorry, jump across http is not supported.")))))
1936 (defun yahtml-goto-corresponding-href (&optional other)
1937 "Go to corresponding name."
1938 (let ((href (yahtml-on-href-p)) file name (parent buffer-file-name))
1939 (if href
1940 (cond
1941 ((string-match "^\\(ht\\|f\\)tps?:" href)
1942 (yahtml-browse-html href))
1943 (t (if (string-match "\&" href)
1944 (setq href (yahtml-untranslate-string href)))
1945 (setq file (substring href 0 (string-match "#" href)))
1946 (if (string-match "#" href)
1947 (setq name (substring href (1+ (string-match "#" href)))))
1948 (if (string< "" file)
1949 (progn
1950 (if (string-match "/$" file)
1951 (or (catch 'dirindex
1952 (mapcar
1953 (function
1954 (lambda (f)
1955 (if (file-exists-p (concat file f))
1956 (throw 'dirindex
1957 (setq file (concat file f))))))
1958 (yahtml-get-directory-index))
1959 nil)
1960 (setq file (concat file yahtml-directory-index))))
1961 (if (string-match "^/" file)
1962 (setq file (yahtml-url-to-path file)))
1963 (if other (YaTeX-switch-to-buffer-other-window file)
1964 (YaTeX-switch-to-buffer file))
1965 (or YaTeX-parent-file (setq YaTeX-parent-file parent))))
1966 (if name
1967 (progn (set-mark-command nil) (yahtml-jump-to-name name)))
1968 t)))))
1970 (defun yahtml-jump-to-name (name)
1971 "Jump to html's named tag."
1972 (setq name (format "\\(name\\|id\\)\\s *=\\s *\"?%s\\>\"?" name))
1973 (or (and (re-search-forward name nil t) (goto-char (match-beginning 0)))
1974 (and (re-search-backward name nil t) (goto-char (match-beginning 0)))
1975 (message "Named tag `%s' not found" (substring href 1))))
1977 (defun yahtml-on-begend-p (&optional p)
1978 "Check if point is on begend clause."
1979 (let ((p (or p (point))) cmd (case-fold-search t))
1980 (save-excursion
1981 (goto-char p)
1982 (if (equal (char-after (point)) ?<) (forward-char 1))
1983 (if (and (re-search-backward "<" nil t)
1984 (looking-at
1985 ;(concat "<\\(/?" yahtml-struct-name-regexp "\\)\\b")
1986 "<\\(/?[A-Z][A-Z0-9]*\\)\\b")
1987 (condition-case nil
1988 (forward-list 1)
1989 (error nil))
1990 (< p (point)))
1991 (YaTeX-match-string 1)))))
1993 (defun yahtml-goto-corresponding-begend (&optional noerr)
1994 "Go to corresponding opening/closing tag.
1995 Optional argument NOERR causes no error for unballanced tag."
1996 (let ((cmd (yahtml-on-begend-p)) m0
1997 (p (point)) (case-fold-search t) func str (nest 0))
1998 (cond
1999 (cmd
2000 (setq m0 (match-beginning 0))
2001 (if (= (aref cmd 0) ?/) ;on </cmd> line
2002 (setq cmd (substring cmd 1)
2003 str (format "\\(<%s\\)\\|\\(</%s\\)" cmd cmd)
2004 func 're-search-backward)
2005 (setq str (format "\\(</%s\\)\\|\\(<%s\\)" cmd cmd)
2006 func 're-search-forward))
2007 (while (and (>= nest 0) (funcall func str nil t))
2008 (if (equal m0 (match-beginning 0))
2009 nil
2010 (setq nest (+ nest (if (match-beginning 1) -1 1)))))
2011 (if (< nest 0)
2012 (goto-char (match-beginning 0))
2013 (funcall
2014 (if noerr 'message 'error)
2015 "Corresponding tag of `%s' not found." cmd)
2016 (goto-char p)
2017 nil))
2018 (t nil))))
2020 (defun yahtml-current-tag ()
2021 "Return the current tag name including #exec and #include."
2022 (save-excursion
2023 (let ((p (point)) b tag)
2024 (or (bobp)
2025 (looking-at "<")
2026 (progn (skip-chars-backward "^<") (forward-char -1)))
2027 (setq b (point))
2028 (skip-chars-forward "<")
2029 (setq tag (YaTeX-buffer-substring
2030 (point) (progn (skip-chars-forward "^ \t\n") (point))))
2031 (goto-char b)
2032 (forward-list 1)
2033 (and (< p (point)) tag))))
2035 (defun yahtml-get-attrvalue (attr)
2036 "Extract current tag's attribute value from buffer."
2037 (let (e (case-fold-search t))
2038 (save-excursion
2039 (or (looking-at "<")
2040 (progn (skip-chars-backward "^<") (backward-char 1)))
2041 (setq e (save-excursion (forward-list 1) (point)))
2042 (if (and
2043 (re-search-forward (concat "\\b" attr "\\b") e t)
2044 (progn (skip-chars-forward " \t\n=")
2045 (looking-at "\"?\\([^\"> \t\n]+\\)\"?")))
2046 (YaTeX-match-string 1)))))
2048 (defun yahtml-goto-corresponding-img ()
2049 "View image on point"
2050 (let ((tag (yahtml-current-tag)) image (p (point)) (case-fold-search t))
2051 (if (and tag
2052 (string-match "img" tag)
2053 (setq image
2054 (yahtml-unescape-string (yahtml-get-attrvalue "src"))))
2055 (progn
2056 (message "Invoking %s %s..." yahtml-image-viewer image)
2057 (start-process
2058 "Viewer" " * Image Viewer *"
2059 shell-file-name yahtml-shell-command-option ;"-c"
2060 (concat yahtml-image-viewer " " image))
2061 (message "Invoking %s %s...Done" yahtml-image-viewer image)))))
2063 (defun yahtml-goto-corresponding-source (&optional other)
2064 "Goto applet's or script's source."
2065 (let ((env (yahtml-current-tag)) s (p (point)))
2066 (cond
2067 ((string-match "applet" env)
2068 (if (setq s (yahtml-unescape-string (yahtml-get-attrvalue "code")))
2069 (progn
2070 (setq s (YaTeX-match-string 1)
2071 s (concat
2072 (substring s 0 (string-match "\\.[A-Za-z]+$" s))
2073 ".java"))
2074 (if other (YaTeX-switch-to-buffer-other-window s)
2075 (YaTeX-switch-to-buffer s))
2076 s) ;return source file name
2077 (message "No applet source specified")
2078 (sit-for 1)
2079 nil))
2080 ((string-match "script" env)
2081 (if (setq s (yahtml-get-attrvalue "src"))
2082 (progn
2083 (funcall (if other 'YaTeX-switch-to-buffer-other-window
2084 'YaTeX-switch-to-buffer)
2085 (yahtml-url-to-path s))
2086 s)))
2087 ((string-match "!--#include" env)
2088 (cond
2089 ((setq s (yahtml-get-attrvalue "file")) ;<!--#include file="foo"-->
2090 (if other (YaTeX-switch-to-buffer-other-window s)
2091 (YaTeX-switch-to-buffer s))
2092 s)
2093 ((setq s (yahtml-get-attrvalue "virtual"));<!--#include virtual="foo"-->
2094 (setq s (yahtml-url-to-path s))
2095 (if other (YaTeX-switch-to-buffer-other-window s)
2096 (YaTeX-switch-to-buffer s))
2097 s)))
2098 ((and (string-match "!--#exec" env)
2099 (setq s (yahtml-get-attrvalue "cmd")))
2100 (setq s (substring s 0 (string-match " \t\\?" s))) ;get argv0
2101 (let ((b " *yahtmltmp*")) ;peek a little
2102 (unwind-protect
2103 (progn
2104 (set-buffer (get-buffer-create b))
2105 (YaTeX-insert-file-contents s nil 0 100)
2106 (if (looking-at "#!")
2107 (if other (YaTeX-switch-to-buffer-other-window s)
2108 (YaTeX-switch-to-buffer s))))
2109 (kill-buffer (get-buffer b)))
2110 (get-file-buffer s))))))
2112 (defun yahtml-goto-corresponding-* (&optional other)
2113 "Go to corresponding object."
2114 (interactive "P")
2115 (cond
2116 ((yahtml-goto-corresponding-href other))
2117 ((yahtml-goto-corresponding-img))
2118 ((yahtml-goto-corresponding-source other))
2119 ((yahtml-goto-corresponding-begend))
2120 (t (message "I don't know where to go."))))
2122 (defun yahtml-goto-corresponding-*-other-window ()
2123 "Go to corresponding object."
2124 (interactive)
2125 (yahtml-goto-corresponding-* t))
2127 (defun yahtml-visit-main ()
2128 "Go to parent file from where you visit current file."
2129 (interactive)
2130 (if YaTeX-parent-file (YaTeX-switch-to-buffer YaTeX-parent-file)))
2132 ;;; ---------- killing ----------
2133 (defun yahtml-kill-begend (&optional whole)
2134 (let ((tag (yahtml-on-begend-p)) p q r bbolp)
2135 (if tag
2136 (save-excursion
2137 (or (looking-at "<")
2138 (progn (skip-chars-backward "^<") (forward-char -1)))
2139 (setq p (point))
2140 (yahtml-goto-corresponding-begend)
2141 (or (looking-at "<")
2142 (progn (skip-chars-backward "^<") (forward-char -1)))
2143 (if (< (point) p) ;if on the opening tag
2144 (progn (setq q p p (point))
2145 (goto-char q))
2146 (setq q (point))) ;now q has end-line's (point)
2147 (if (not whole)
2148 (kill-region
2149 (progn (skip-chars-backward " \t")
2150 (if (setq bbolp (bolp)) (point) q))
2151 (progn (forward-list 1)
2152 (setq r (point))
2153 (skip-chars-forward " \t")
2154 (if (and bbolp (eolp) (not (eobp))) (1+ (point)) r))))
2155 (goto-char p)
2156 (skip-chars-backward " \t")
2157 (if (not whole)
2158 (progn
2159 (kill-append
2160 (buffer-substring
2161 (setq p (if (setq bbolp (bolp)) (point) p))
2162 (setq q (progn
2163 (forward-list 1)
2164 (setq r (point))
2165 (skip-chars-forward " \t")
2166 (if (and bbolp (eolp) (not (eobp)))
2167 (1+ (point))
2168 r))))
2169 t)
2170 (delete-region p q))
2171 (kill-region
2172 (if (bolp) (point) p)
2173 (progn (goto-char q)
2174 (forward-list 1)
2175 (setq r (point))
2176 (skip-chars-forward " \t")
2177 (if (and (eolp) (not (eobp))) (1+ (point)) r))))
2178 tag))))
2180 (defun yahtml-kill-* (whole)
2181 "Kill current position's HTML tag (set)."
2182 (interactive "P")
2183 (cond
2184 ((yahtml-kill-begend whole))))
2187 ;;; ---------- changing ----------
2188 (defun yahtml-on-assignment-p ()
2189 "Return if current point is on parameter assignment.
2190 If so, return parameter name, otherwise nil.
2191 This function should be able to treat white spaces in value, but not yet."
2192 (let ((p (point)))
2193 (save-excursion
2194 (put 'yahtml-on-assignment-p 'region nil)
2195 (skip-chars-backward "^ \t\n")
2196 (and (looking-at "\\([A-Za-z0-9]+\\)\\s *=\\s *\"?\\([^ \t\"]+\\)\"?")
2197 (< p (match-end 0))
2198 (>= p (1- (match-beginning 2)))
2199 (put 'yahtml-on-assignment-p 'region
2200 (cons (match-beginning 2) (match-end 2)))
2201 (YaTeX-match-string 1)))))
2203 (defun yahtml-change-begend ()
2204 (let ((tag (yahtml-on-begend-p))
2205 (completion-ignore-case t)
2206 (case-fold-search t)
2207 (p (point)) (q (make-marker))
2208 (default (append yahtml-env-table yahtml-typeface-table))
2209 (user (append yahtml-user-env-table yahtml-user-typeface-table))
2210 (tmp (append yahtml-tmp-env-table yahtml-tmp-typeface-table))
2211 href b1 e1 attr new css)
2212 (cond
2213 (tag
2214 (cond
2215 ((and (string-match "^a$" tag)
2216 (save-excursion
2217 (and
2218 (re-search-backward "<a\\b" nil t)
2219 (progn
2220 (goto-char (match-end 0))
2221 (skip-chars-forward " \t\n")
2222 (setq b1 (point))
2223 (search-forward ">" nil t))
2224 (setq e1 (match-beginning 0))
2225 (goto-char b1)
2226 (re-search-forward "href\\s *=" e1 t)
2227 (>= p (point))
2228 (progn
2229 (goto-char (match-end 0))
2230 (skip-chars-forward " \t\n")
2231 (looking-at "\"?\\([^\"> \t\n]+\\)\"?"))
2232 (< p (match-end 0)))))
2233 (setq b1 (match-beginning 1) e1 (match-end 1)
2234 yahtml-completing-buffer (current-buffer)
2235 ;; yahtml-urls-local is buffer-local, so we must put
2236 ;; that into yahtml-urls here
2237 yahtml-urls (append yahtml-urls-private yahtml-urls-local)
2238 href (read-from-minibuffer
2239 "Change href to: " "" yahtml-url-completion-map))
2240 (if (string< "" href)
2241 (progn
2242 ;;(setq href ;??
2243 ;; (if yahtml-prefer-upcases (upcase href) (downcase href)))
2244 (delete-region b1 e1)
2245 (goto-char b1)
2246 (insert href))))
2247 ((setq attr (yahtml-on-assignment-p)) ;if on the assignment to attr
2248 (if (and (equal attr "class") ;treat "class" attribute specially
2249 (setq css (yahtml-css-get-element-completion-alist tag)))
2251 (setq new (yahtml-read-css css tag))
2252 ;;other than "class", read parameter normally
2253 (setq new (yahtml-read-parameter attr)))
2254 (goto-char (car (get 'yahtml-on-assignment-p 'region)))
2255 (delete-region (point) (cdr (get 'yahtml-on-assignment-p 'region)))
2256 (insert new))
2257 (t
2258 (save-excursion
2259 (if (= (aref tag 0) ?/) (setq tag (substring tag 1)))
2260 (or (= (char-after (point)) ?<) (skip-chars-backward "^<"))
2261 (skip-chars-forward "^A-Za-z")
2262 (set-marker q (point))
2263 (setq p (point))
2264 (yahtml-goto-corresponding-begend)
2265 (or (= (char-after (point)) ?<)
2266 (skip-chars-backward "^<"))
2267 (skip-chars-forward "^A-Za-z")
2268 (if (= (char-after (1- (point))) ?/)
2269 (progn
2270 (set-marker q (point))
2271 (goto-char p)))
2272 (setq tag (let ((completion-ignore-case t))
2273 (YaTeX-cplread-with-learning
2274 (format "Change `%s' to(default %s): "
2275 tag yahtml-last-begend)
2276 'default 'user 'tmp)))
2277 (delete-region (point) (progn (skip-chars-forward "^>") (point)))
2278 (if (string= "" tag) (setq tag yahtml-last-begend))
2279 (setq yahtml-last-begend
2280 (or (cdr (assoc tag yahtml-env-table)) tag)
2281 tag yahtml-last-begend)
2282 (setq tag (if yahtml-prefer-upcases (upcase tag) (downcase tag)))
2283 (insert (format "%s%s" tag (yahtml-addin tag)))
2284 (goto-char q)
2285 (set-marker q nil)
2286 (delete-region (point) (progn (skip-chars-forward "^>") (point)))
2287 (insert tag))))
2288 t))))
2290 (defun yahtml-change-command ()
2291 (let ((p (point)) (case-fold-search t) cmd par new
2292 (beg (make-marker)) (end (make-marker)))
2293 (skip-chars-backward "^<")
2294 (if (and
2295 (looking-at yahtml-command-regexp)
2296 (progn
2297 (set-marker beg (match-beginning 0))
2298 (set-marker end (match-end 0))
2299 t) ;for further work
2300 (progn
2301 (forward-char -1)
2302 (condition-case nil
2303 (forward-list 1)
2304 (error nil))
2305 (< p (point))))
2306 (progn
2307 (goto-char p)
2308 (if (setq par (yahtml-on-assignment-p))
2309 (progn
2310 (setq new (yahtml-read-parameter par))
2311 (set-marker beg (car (get 'yahtml-on-assignment-p 'region)))
2312 (set-marker end (cdr (get 'yahtml-on-assignment-p 'region))))
2313 (setq new
2314 (YaTeX-cplread-with-learning
2315 "Change form to: "
2316 'yahtml-form-table 'yahtml-user-form-table
2317 'yahtml-tmp-form-table)))
2318 (delete-region beg end)
2319 (goto-char beg)
2320 (set-marker beg nil)
2321 (set-marker end nil)
2322 (insert new)
2323 t)
2324 (goto-char p)
2325 nil)))
2327 (defun yahtml-change-* ()
2328 "Change current position's HTML tag (set)."
2329 (interactive)
2330 (cond
2331 ((yahtml-change-begend))
2332 ((yahtml-change-command))))
2334 ;;; ---------- commenting ----------
2336 (defun yahtml-comment-region (&optional uncom)
2337 "Comment out region or environment."
2338 (interactive)
2339 (let ((e (make-marker)) be beg p)
2340 (cond
2341 (;(marker-position (set-marker e (yahtml-on-begend-p)))
2342 (setq be (yahtml-on-begend-p))
2343 (save-excursion
2344 (setq p (point))
2345 (if (string-match "^/" be)
2346 (setq beg (progn (forward-line 1) (point)))
2347 (setq beg (progn (beginning-of-line) (point))))
2348 (goto-char p)
2349 (yahtml-goto-corresponding-begend)
2350 (if (string-match "^/" be)
2351 (beginning-of-line)
2352 (forward-line 1))
2353 (set-marker e (point))
2354 ;(comment-region beg (point) (if uncom (list 4)))))
2355 ))
2356 (t ;(comment-region (region-beginning) (region-end) (if uncom (list 4)))
2357 (setq beg (region-beginning))
2358 (set-marker e (region-end))))
2359 (if yahtml-translate-hyphens-when-comment-region
2360 (let ((yahtml-entity-reference-chars-alist-default nil)
2361 (yahtml-entity-reference-chars-alist '((?- . "#45")))
2362 yahtml-entity-reference-chars-regexp
2363 yahtml-entity-reference-chars-reverse-regexp)
2364 (yahtml-entity-reference-chars-setup)
2365 (funcall
2366 (if uncom 'yahtml-translate-reverse-region
2367 'yahtml-translate-region)
2368 beg e)))
2369 (comment-region beg e (if uncom (list 4)))
2370 (set-marker e nil)))
2372 (defun yahtml-uncomment-region ()
2373 (interactive)
2374 (yahtml-comment-region t))
2376 ;;; ---------- translate to entity references ----------
2377 (defvar yahtml-entity-reference-chars-alist-default
2378 ;'((?> . "gt") (?< . "lt") (?& . "amp") (?\" . "quot") (?' . "apos"))
2379 '((?> . "gt") (?< . "lt") (?& . "amp") (?\" . "quot"))
2380 "Default translation table from character to entity reference")
2381 (defvar yahtml-entity-reference-chars-alist nil
2382 "*Translation table from character to entity reference")
2383 (defvar yahtml-entity-reference-chars-regexp nil)
2384 (defvar yahtml-entity-reference-chars-reverse-regexp nil)
2386 (defun yahtml-entity-reference-chars-setup ()
2387 (let ((list (append yahtml-entity-reference-chars-alist-default
2388 yahtml-entity-reference-chars-alist)))
2389 (setq yahtml-entity-reference-chars-regexp "["
2390 yahtml-entity-reference-chars-reverse-regexp "&\\(")
2391 (while list
2392 (setq yahtml-entity-reference-chars-regexp
2393 (concat yahtml-entity-reference-chars-regexp
2394 (char-to-string (car (car list))))
2395 yahtml-entity-reference-chars-reverse-regexp
2396 (concat yahtml-entity-reference-chars-reverse-regexp
2397 (cdr (car list))
2398 (if (cdr list) "\\|")))
2399 (setq list (cdr list)))
2400 (setq yahtml-entity-reference-chars-regexp
2401 (concat yahtml-entity-reference-chars-regexp "]")
2402 yahtml-entity-reference-chars-reverse-regexp
2403 (concat yahtml-entity-reference-chars-reverse-regexp "\\);"))))
2405 (yahtml-entity-reference-chars-setup)
2407 (defun yahtml-translate-region (beg end)
2408 "Translate inhibited literals."
2409 (interactive "r")
2410 (save-excursion
2411 (save-restriction
2412 (narrow-to-region beg end)
2413 (let ((ct (append yahtml-entity-reference-chars-alist
2414 yahtml-entity-reference-chars-alist-default)))
2415 (goto-char beg)
2416 (while (re-search-forward yahtml-entity-reference-chars-regexp nil t)
2417 ;(setq c (preceding-char))
2418 (replace-match
2419 (concat "&" (cdr (assoc (preceding-char) ct)) ";")))))))
2421 (defun yahtml-translate-reverse-region (beg end)
2422 "Translate entity references to literals."
2423 (interactive "r")
2424 (save-excursion
2425 (save-restriction
2426 (narrow-to-region beg end)
2427 (let ((ct (append yahtml-entity-reference-chars-alist
2428 yahtml-entity-reference-chars-alist-default))
2429 ec)
2430 (goto-char beg)
2431 (while (re-search-forward
2432 yahtml-entity-reference-chars-reverse-regexp nil t)
2433 ;(setq c (preceding-char))
2434 (setq ec (YaTeX-match-string 1))
2435 (delete-region (match-end 0) (match-beginning 0))
2436 (insert (car (YaTeX-rassoc ec ct))))))))
2438 (defun yahtml-inner-environment-but (exclude &optional quick)
2439 "Return the inner environment but matches with EXCLUDE tag."
2440 (let (e (case-fold-search t))
2441 (save-excursion
2442 (while (and (setq e (YaTeX-inner-environment quick))
2443 (string-match exclude e))
2444 (goto-char (get 'YaTeX-inner-environment 'point))))
2445 e))
2447 (defun yahtml-untranslate-string (str)
2448 "Untranslate entity reference."
2449 (let ((md (match-data)) (left "") (right str) b0 ch
2450 (ct (append yahtml-entity-reference-chars-alist
2451 yahtml-entity-reference-chars-alist-default))
2452 (revrex yahtml-entity-reference-chars-reverse-regexp))
2453 (unwind-protect
2454 (progn
2455 (while (string< "" right)
2456 (cond
2457 ((string-match revrex right)
2458 (setq ch (YaTeX-rassoc
2459 (substring right (match-beginning 1) (match-end 1)))
2460 b0 (substring right 0 (match-beginning 0))
2461 right (substring right (match-end 0))
2462 left (concat left
2463 (substring right 0 (match-beginning 0))
2464 (char-to-string ch))))
2465 ((string-match "\\&#\\(x\\)?\\([0-9a-f]+\\);" right)
2466 (setq ch (substring right (match-beginning 2) (match-end 2))
2467 b0 (substring right 0 (match-beginning 0))
2468 right (substring right (match-end 0))
2469 left (concat left
2470 b0
2471 (char-to-string
2472 (if (match-beginning 1)
2473 (YaTeX-hex ch)
2474 (string-to-number ch))))))
2475 (t (setq left (concat left right)
2476 right ""))))
2477 left)
2478 (store-match-data md))))
2480 ;;; ---------- table-ize region ----------
2481 (defun yahtml-td-region (e delim beg end)
2482 "Enclose each item in a region with <td>..</td>.
2483 Interactive prefix argument consults enclosing element other than td."
2484 (interactive "P\nsDelimiter(s): \nr")
2485 (let ((e (cond
2486 ((null e) "td")
2487 ((stringp e) e)
2488 (t (read-string-with-history
2489 "Enclose with(`thd' means th td td..): " "th"))))
2490 (ws "[ \t]")
2491 elm p i)
2492 (if (string= delim "") (setq delim " \t\n"))
2493 (setq delim (concat "[" delim "]+")
2494 elm (if (string= "thd" e)
2495 (cons "th" "td")
2496 (cons e e)))
2497 (save-excursion
2498 (save-restriction
2499 (narrow-to-region beg end)
2500 (goto-char (setq p (point-min)))
2501 (setq i 0 e (car elm))
2502 (while (re-search-forward delim nil t)
2503 (setq e (if (= (setq i (1+ i)) 1) (car elm) (cdr elm)))
2504 (goto-char (match-beginning 0))
2505 (insert "</" e ">")
2506 (save-excursion
2507 (goto-char p)
2508 (insert "<" e ">"))
2509 (setq p (point))
2510 (while (and (not (eobp)) (looking-at ws))
2511 (delete-char 1))
2512 (if (looking-at delim) (delete-char 1)))
2513 (insert "<" e ">")
2514 (goto-char (point-max))
2515 (insert "</" e ">")))))
2517 (defun yahtml-tr-region (e delim beg end)
2518 "Enclose lines in a form tab-sv/csv with <tr><td>..</td></tr>."
2519 (interactive "P\nsDelimiter(s): \nr")
2520 (setq e (if (and e (listp e))
2521 (read-string-with-history
2522 "Enclose with(td or th, `thd' -> th td td td...: " "th")))
2523 (save-excursion
2524 (save-restriction
2525 (narrow-to-region (point) (mark))
2526 (goto-char (point-min))
2527 (while (not (eobp))
2528 (insert "<tr>")
2529 (yahtml-td-region e delim (point) (point-end-of-line))
2530 (end-of-line)
2531 (insert "</tr>")
2532 (forward-line 1)))))
2534 ;;; ---------- filling ----------
2535 (defvar yahtml-saved-move-to-column (symbol-function 'move-to-column))
2536 (defun yahtml-move-to-column (col &optional force)
2537 (beginning-of-line)
2538 (let ((ccol 0))
2539 (while (and (> col ccol) (not (eolp)))
2540 (if (eq (following-char) ?\<)
2541 (progn
2542 (while (and (not (eq (following-char) ?\>))
2543 (not (eolp)))
2544 (forward-char))
2545 (or (eolp) (forward-char)))
2546 (or (eolp) (forward-char))
2547 (if (eq (preceding-char) ?\t)
2548 (let ((wd (- 8 (% (+ ccol 8) 8))))
2549 (if (and force (< col (+ ccol wd)))
2550 (progn
2551 (backward-char 1)
2552 (insert-char ?\ (- col ccol))
2553 (setq ccol col))
2554 (setq ccol (+ ccol wd))))
2555 (setq ccol (1+ ccol)))
2556 (if (and YaTeX-japan
2557 (or
2558 (and (fboundp 'char-category)
2559 (string-match "[chj]" (char-category (preceding-char))))
2560 (and (fboundp 'char-charset)
2561 (not (eq (char-charset (preceding-char)) 'ascii)))))
2562 (setq ccol (1+ ccol)))))
2563 (if (and force (> col ccol))
2564 (progn
2565 (insert-char ?\ (- col ccol))
2566 col)
2567 ccol)))
2569 (defun yahtml-fill-paragraph (arg)
2570 (interactive "P")
2571 (let*((case-fold-search t) (p (point)) fill-prefix
2572 (e (or (yahtml-inner-environment-but "^\\(a\\|p\\)\\b" t) "html"))
2573 indent
2574 (startp (get 'YaTeX-inner-environment 'point))
2575 (prep (string-match "^pre$" e))
2576 (ps1 (if prep (default-value 'paragraph-start)
2577 paragraph-start))
2578 (ps2 (if prep (concat (default-value 'paragraph-start)
2579 "$\\|^\\s *</?pre>")
2580 paragraph-start)))
2581 (save-excursion
2582 (unwind-protect
2583 (progn
2584 (if prep
2585 (fset 'move-to-column 'yahtml-move-to-column))
2586 (save-excursion
2587 (beginning-of-line)
2588 (indent-to-column (yahtml-this-indent))
2589 (setq fill-prefix
2590 (buffer-substring (point) (point-beginning-of-line)))
2591 (delete-region (point) (point-beginning-of-line)))
2592 (fill-region-as-paragraph
2593 (progn (re-search-backward paragraph-start nil t)
2594 (or (save-excursion
2595 (goto-char (match-beginning 0))
2596 (if (looking-at "<")
2597 (forward-list)
2598 (goto-char (match-end 0))
2599 (skip-chars-forward " \t>"))
2600 (if (looking-at "[ \t]*$")
2601 (progn (forward-line 1) (point))))
2602 (point)))
2603 (progn (goto-char p)
2604 (re-search-forward ps2 nil t)
2605 (match-beginning 0))))
2606 (fset 'move-to-column yahtml-saved-move-to-column)))))
2608 ;;;
2609 ;;; ---------- move forward/backward field ----------
2610 ;;;
2611 (defun yahtml-element-path ()
2612 "Return the element path from <body> at point as a list"
2613 (let (path elm)
2614 (save-excursion
2615 (while (and (YaTeX-beginning-of-environment)
2616 (looking-at (concat "<\\(" yahtml-command-regexp "\\)\\>"))
2617 (not (string= (setq elm (downcase (YaTeX-match-string 1)))
2618 "body")))
2619 (setq path (cons elm path)
2620 elm nil))
2621 (and elm (setq path (cons elm path)))
2622 path)))
2624 (defun yahtml-forward-field (arg)
2625 "Move ARGth forward cell to table element.
2626 ENVINFO is a cons of target element name and its beginning point."
2627 (interactive "p")
2628 (let (inenv elm path sibs)
2629 (cond
2630 ((< arg 0) (yahtml-backward-field (- arg)))
2631 ((= arg 0) nil)
2632 ((and (setq path (nreverse (yahtml-element-path)))
2633 (catch 'sibling
2634 (while path
2635 (if (setq elm (car-safe
2636 (member (car path) '("td" "th" "li" "dt" "dd"))))
2637 (throw 'sibling elm))
2638 (setq path (cdr path)))))
2639 (setq inenv (YaTeX-in-environment-p elm)
2640 sibs (cdr (assoc elm '(("td" . "td\\|th")
2641 ("th" . "td\\|th")
2642 ("li" . "li")
2643 ("dt" . "dt\\|dd")
2644 ("dd" . "dt\\|dd")))))
2645 (goto-char (cdr inenv))
2646 (while (>= (setq arg (1- arg)) 0)
2647 (yahtml-goto-corresponding-begend)
2648 (if (looking-at "<") (forward-list 1))
2649 (skip-chars-forward "^<"))
2650 (while (looking-at "\\s \\|\\(</\\)")
2651 (if (match-beginning 1) (forward-list 1)
2652 (skip-chars-forward "\n\t ")))
2653 (forward-list 1) ;; step into environment
2654 (skip-chars-forward " \t\n")
2655 (if (looking-at (concat "<\\(" sibs "\\)\\>"))
2656 (forward-list 1))
2657 ))))
2660 ;;;
2661 ;;; ---------- indentation ----------
2662 ;;;
2663 (defun yahtml-indent-line-1 ()
2664 "Indent a line (faster wrapper)"
2665 (interactive)
2666 (let (indent)
2667 (if (and (save-excursion
2668 (beginning-of-line) (skip-chars-forward "\t ")
2669 (not (looking-at "<")))
2670 (save-excursion
2671 (forward-line -1)
2672 (while (and (not (bobp)) (looking-at "^\\s *$"))
2673 (forward-line -1))
2674 (skip-chars-forward "\t ")
2675 (setq indent (current-column))
2676 (not (looking-at "<"))))
2677 (progn
2678 (save-excursion
2679 (beginning-of-line)
2680 (skip-chars-forward " \t")
2681 (or (= (current-column) indent)
2682 (YaTeX-reindent indent)))
2683 (and (bolp) (skip-chars-forward " \t")))
2684 (yahtml-indent-line-real))))
2686 (defun yahtml-indent-line ()
2687 "Indent a line (Second level wrapper).
2688 See also yahtml-indent-line-1 and yahtml-indent-line-real."
2689 (interactive)
2690 (let ((cc (current-column)) (p (point)))
2691 (yahtml-indent-line-1)
2692 (and (= cc (current-column))
2693 (= p (point))
2694 (equal last-command 'yahtml-indent-line)
2695 (yahtml-forward-field 1))))
2698 (defun yahtml-this-indent ()
2699 (let ((envs "[uod]l\\|table\\|[ht][rhd0-6]\\|select\\|blockquote\\|center\\|menu\\|dir\\|d[td]\\|li")
2700 (itemizing-envs "^\\([uod]l\\|menu\\|dir\\|li\\|d[td]\\)$")
2701 (itms "<\\(dt\\|dd\\|li\\|t[rdh]\\|option\\)\\b")
2702 (excludes
2703 "\\b\\(a\\|p\\|span\\|code\\|tt\\|em\\|u\\|i\\|big\\|small\\|font\\)\\b")
2704 inenv p col peol (case-fold-search t))
2705 (save-excursion
2706 (beginning-of-line)
2707 (setq inenv (or (yahtml-inner-environment-but excludes t)
2708 "html")
2709 col (get 'YaTeX-inner-environment 'indent)
2710 p (get 'YaTeX-inner-environment 'point)
2711 op nil))
2712 (save-excursion
2713 (cond
2714 ((string-match (concat "^\\(" envs "\\)") inenv)
2715 (save-excursion
2716 (beginning-of-line)
2717 (skip-chars-forward " \t")
2718 (cond ;lookup current line's tag
2719 ((looking-at (concat "</\\(" envs "\\)>"))
2720 col)
2721 ((looking-at itms)
2722 (+ col yahtml-environment-indent))
2723 ((and yahtml-hate-too-deep-indentation
2724 (looking-at (concat "<\\(" envs "\\)")))
2725 (+ col (* 2 yahtml-environment-indent)))
2726 ((and (< p (point))
2727 (string-match itemizing-envs inenv)
2728 (save-excursion
2729 (and
2730 (setq op (point))
2731 (goto-char p)
2732 (re-search-forward itms op t)
2733 (progn
2734 (if yahtml-indent-listing-constant
2735 (setq col (+ (current-column)
2736 (if yahtml-faithful-to-htmllint 1 2)))
2737 (skip-chars-forward "^>")
2738 (skip-chars-forward ">")
2739 (skip-chars-forward " \t")
2740 (setq col (if (looking-at "$")
2741 (+ col yahtml-environment-indent)
2742 (current-column))))))))
2743 col)
2744 (t
2745 (+ col yahtml-environment-indent)))))
2746 (t col)))))
2748 (defun yahtml-indent-line-real ()
2749 "Indent current line."
2750 (interactive)
2751 (YaTeX-reindent (yahtml-this-indent))
2752 (if (bolp) (skip-chars-forward " \t"))
2753 (let (peol col inenv)
2754 (if (and (setq inenv (yahtml-on-begend-p))
2755 (string-match
2756 (concat "^\\<\\(" yahtml-struct-name-regexp "\\)") inenv))
2757 (save-excursion
2758 (setq peol (point-end-of-line))
2759 (or (= (char-after (point)) ?<)
2760 (progn (skip-chars-backward "^<") (forward-char -1)))
2761 (setq col (current-column))
2762 (if (and (yahtml-goto-corresponding-begend t)
2763 (> (point) peol)) ;if on the different line
2764 (YaTeX-reindent col))))))
2766 ;(defun yahtml-fill-item ()
2767 ; "Fill item HTML version"
2768 ; (interactive)
2769 ; (let (inenv p fill-prefix peol (case-fold-search t))
2770 ; (setq inenv (or (YaTeX-inner-environment) "html")
2771 ; p (get 'YaTeX-inner-environment 'point))
2772 ; (cond
2773 ; ((string-match "^[uod]l" inenv)
2774 ; (save-excursion
2775 ; (if (re-search-backward "<\\(d[td]\\|li\\)>[ \t\n]*" p t)
2776 ; (progn
2777 ; (goto-char (match-end 0))
2778 ; (setq col (current-column)))
2779 ; (error "No <li>, <dt>, <dd>")))
2780 ; (save-excursion
2781 ; (end-of-line)
2782 ; (setq peol (point))
2783 ; (newline)
2784 ; (indent-to-column col)
2785 ; (setq fill-prefix (buffer-substring (point) (1+ peol)))
2786 ; (delete-region (point) peol)
2787 ; (fill-region-as-paragraph
2788 ; (progn (re-search-backward paragraph-start nil t) (point))
2789 ; (progn (re-search-forward paragraph-start nil t 2)
2790 ; (match-beginning 0)))))
2791 ; (t nil))))
2793 ;;;
2794 ;;; ---------- Lint and Browsing ----------
2795 ;;;
2796 (defun yahtml-browse-menu ()
2797 "Browsing or other external process invokation menu."
2798 (interactive)
2799 (message "J)weblint p)Browse R)eload N)ewpage...")
2800 (let ((c (char-to-string (read-char))))
2801 (cond
2802 ((string-match "j" c)
2803 (yahtml-lint-buffer (current-buffer)))
2804 ((string-match "[bp]" c)
2805 (yahtml-browse-current-file))
2806 ((string-match "r" c)
2807 (yahtml-browse-reload))
2808 ((string-match "n" c)
2809 (call-interactively 'yahtml-newpage)))))
2811 (if (fboundp 'wrap-function-to-control-ime)
2812 (wrap-function-to-control-ime 'yahtml-browse-menu t nil))
2814 (defvar yahtml-lint-buffer "*weblint*")
2816 (defun yahtml-lint-buffer (buf)
2817 "Call lint on buffer BUF."
2818 (require 'yatexprc)
2819 (interactive "bCall lint on buffer: ")
2820 (setq buf (get-buffer buf))
2821 (YaTeX-save-buffers)
2822 (let ((bcmd (YaTeX-get-builtin "lint")))
2823 (and bcmd (setq bcmd (yahtml-untranslate-string bcmd)))
2824 (YaTeX-typeset
2825 (concat (or bcmd yahtml-lint-program)
2826 " " (file-name-nondirectory (buffer-file-name buf)))
2827 yahtml-lint-buffer "lint" "lint")))
2829 (defun yahtml-file-to-url (file)
2830 "Convert local unix file name to URL.
2831 If no matches found in yahtml-path-url-alist, return raw file name."
2832 (let ((list yahtml-path-url-alist) p url)
2833 (if (file-directory-p file)
2834 (setq file (expand-file-name yahtml-directory-index file))
2835 (setq file (expand-file-name file)))
2836 (if (string-match "^[A-Za-z]:/" file)
2837 (progn
2838 ;; (aset file 1 ?|) ;これは要らないらしい…
2839 (setq file (concat "///" file))))
2840 (while list
2841 (if (string-match (concat "^" (regexp-quote (car (car list)))) file)
2842 (setq url (cdr (car list))
2843 file (substring file (match-end 0))
2844 url (concat url file)
2845 list nil))
2846 (setq list (cdr list)))
2847 (or url (concat "file:" file))))
2849 (defun yahtml-url-to-path (file &optional basedir)
2850 "Convert local URL name to unix file name."
2851 (let ((list yahtml-path-url-alist) url realpath docroot
2852 (dirsufp (string-match "/$" file)))
2853 (setq basedir (or basedir
2854 (file-name-directory
2855 (expand-file-name default-directory))))
2856 (cond
2857 ((string-match "^/" file)
2858 (while list
2859 (if (file-directory-p (car (car list)))
2860 (progn
2861 (setq url (cdr (car list)))
2862 (if (string-match "\\(https?://[^/]*\\)/" url)
2863 (setq docroot (substring url (match-end 1)))
2864 (setq docroot url))
2865 (cond
2866 ((string-match (concat "^" (regexp-quote docroot)) file)
2867 (setq realpath
2868 (expand-file-name
2869 (substring
2870 file
2871 (if (= (aref file (1- (match-end 0))) ?/)
2872 (match-end 0) ; "/foo"
2873 (min (1+ (match-end 0)) (length file)))) ; "/~foo"
2874 (car (car list))))))
2875 (if realpath
2876 (progn (setq list nil)
2877 (if (and dirsufp (not (string-match "/$" realpath)))
2878 (setq realpath (concat realpath "/")))))))
2879 (setq list (cdr list)))
2880 realpath)
2881 (t file))))
2883 (defun yahtml-browse-current-file ()
2884 "Call WWW browser on current file."
2885 (interactive)
2886 (basic-save-buffer)
2887 (yahtml-browse-html (yahtml-file-to-url (buffer-file-name))))
2889 (defun yahtml-browse-reload ()
2890 "Send `reload' event to netscape."
2891 (let ((pb "* WWW Browser *") (cb (current-buffer)))
2892 (cond
2893 ((string-match "[Nn]etscape" yahtml-www-browser)
2894 (if (get-buffer pb)
2895 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
2896 ;;(or (get 'yahtml-netscape-sentinel 'url)
2897 ;; (error "Reload should be called after Browsing."))
2898 (put 'yahtml-netscape-sentinel 'url
2899 (yahtml-file-to-url (buffer-file-name)))
2900 (basic-save-buffer)
2901 (set-process-sentinel
2902 (setq yahtml-browser-process
2903 (start-process
2904 "browser" pb shell-file-name yahtml-shell-command-option ;"-c"
2905 (format "%s -remote 'reload'" yahtml-www-browser)))
2906 'yahtml-netscape-sentinel))
2907 (t
2908 (message "Sorry, RELOAD is supported only for Netscape.")))))
2910 ;;; ---------- Intelligent newline ----------
2911 (defun yahtml-intelligent-newline (arg)
2912 "Intelligent newline for HTML"
2913 (interactive "P")
2914 (let (env func)
2915 (end-of-line)
2916 (setq env (downcase (or (yahtml-inner-environment-but "^\\(a\\|p\\)\\b" t)
2917 "html")))
2918 (setq func (intern-soft (concat "yahtml-intelligent-newline-" env)))
2919 (newline)
2920 (if (and env func (fboundp func))
2921 ;; if intelligent line function is defined, call that
2922 (funcall func)
2923 ;; else do the default action
2924 (if (string-match yahtml-p-prefered-env-regexp env)
2925 (yahtml-insert-p)))))
2927 (defun yahtml-intelligent-newline-ul ()
2928 (interactive)
2929 (yahtml-insert-single "li")
2930 (or yahtml-always-/li yahtml-faithful-to-htmllint (insert " "))
2931 (yahtml-indent-line))
2933 (fset 'yahtml-intelligent-newline-ol 'yahtml-intelligent-newline-ul)
2935 (defun yahtml-intelligent-newline-datalist ()
2936 (interactive)
2937 (yahtml-insert-form "option")
2938 (save-excursion (yahtml-insert-form "/option")))
2940 (defun yahtml-intelligent-newline-dl ()
2941 (interactive)
2942 (let ((case-fold-search t))
2943 (if (save-excursion
2944 (re-search-backward "<\\(\\(dt\\)\\|\\(dd\\)\\)[ \t>]"
2945 (get 'YaTeX-inner-environment 'point) t))
2946 (cond
2947 ((match-beginning 2)
2948 (yahtml-insert-single "dd")
2949 (or yahtml-always-/dd yahtml-faithful-to-htmllint (insert " "))
2950 (setq yahtml-last-single-cmd "dt"))
2951 ((match-beginning 3)
2952 (yahtml-insert-single "dt")
2953 (or yahtml-always-/dt yahtml-faithful-to-htmllint (insert " "))
2954 (setq yahtml-last-single-cmd "dd")))
2955 (yahtml-insert-single "dt")
2956 (or yahtml-always-/li yahtml-faithful-to-htmllint (insert " "))
2957 (setq yahtml-last-single-cmd "dd"))
2958 (yahtml-indent-line)
2959 (and (string-match yahtml-p-prefered-env-regexp "dl")
2960 (string-equal yahtml-last-single-cmd "dt")
2961 (yahtml-insert-p nil))))
2963 (defun yahtml-intelligent-newline-select ()
2964 (interactive)
2965 (yahtml-insert-single (if yahtml-prefer-upcases "OPTION" "option"))
2966 (yahtml-indent-line))
2968 (defun yahtml-intelligent-newline-style ()
2969 (interactive)
2970 (if (save-excursion
2971 (and
2972 (re-search-backward "<style\\|<!-- " nil t)
2973 (looking-at "<style")))
2974 (let (c)
2975 (yahtml-indent-line)
2976 (setq c (current-column))
2977 (insert "<!--\n")
2978 (YaTeX-reindent c)
2979 (insert "-->")
2980 (beginning-of-line)
2981 (open-line 1)
2982 (YaTeX-reindent c))))
2984 (defun yahtml-intelligent-newline-head ()
2985 (let ((title (read-string-with-history "Document title: "))
2986 (b "<title>") (e "</title>") p)
2987 (yahtml-indent-line)
2988 (insert (format "%s" (if yahtml-prefer-upcases (upcase b) b)))
2989 (setq p (point))
2990 (insert (format "%s%s" title (if yahtml-prefer-upcases (upcase e) e)))
2991 (if (string= "" title) (goto-char p))
2992 (setq yahtml-last-begend "body")))
2994 (defun yahtml-intelligent-newline-script ()
2995 (let ((p (point)) b)
2996 (if (save-excursion
2997 (and
2998 (setq b (re-search-backward "<script\\>" nil t))
2999 (re-search-forward
3000 "\\(javascript\\)\\|\\(tcl\\)\\|\\(vbscript\\)" p t)))
3001 (let ((js (match-end 1)) (tcl (match-end 2)) (vb (match-end 3))
3002 c (srcp (re-search-backward "src=" b t)))
3003 (goto-char p)
3004 (yahtml-indent-line)
3005 (setq c (current-column))
3006 (if srcp
3007 nil
3008 (insert "<!--\n" (cond (js "//") (tcl "#") (vb "'")) " -->")
3009 (beginning-of-line)
3010 (open-line 1)
3011 (YaTeX-reindent c))))))
3013 (defun yahtml-intelligent-newline-table ()
3014 (let ((cp (point)) (p (point)) tb rb (cols 0) th line (i 0) fmt
3015 (ptn "\\(<t[dh]\\>\\)\\|<t\\(r\\|head\\|body\\)\\>"))
3016 (cond
3017 ((save-excursion (setq tb (YaTeX-beginning-of-environment "table")))
3018 (while (and (setq rb (re-search-backward ptn tb t))
3019 (match-beginning 1))
3020 (setq th (looking-at "<th")) ;Remember if first-child is tr or not
3021 (goto-char (match-end 0))
3022 (skip-chars-forward " \t\n")
3023 (if (and (search-forward "colspan\\s *=" p t)
3024 (progn
3025 (skip-chars-forward "\"' \t\n")
3026 (looking-at "[0-9]+")))
3027 (setq cols (+ (YaTeX-str2int (YaTeX-match-string 0)) cols))
3028 (setq cols (1+ cols)))
3029 (goto-char rb)
3030 (setq p (point)))
3031 (if (> cols 0)
3032 (message "%s columns found. %s"
3033 cols (if YaTeX-japan "新しいtr(N)? 前のtrの複写?(D)?: "
3034 "New tr?(N) or Duplicate")))
3035 (cond
3036 ((and (> cols 0)
3037 (memq (read-char) '(?d ?D))) ;Duplication mode
3038 (setq line (YaTeX-buffer-substring (point) (1- cp))))
3039 (t ;empty cells
3040 (setq line "<tr>" i 0)
3041 (if (> cols 0)
3042 (while (> cols i)
3043 (setq line (concat line (if (and (= i 0) th) "<th></th>"
3044 "<td></td>"))
3045 th nil i (1+ i)))
3046 (setq fmt (read-string-with-history
3047 "`th' or `td' format: " "th td td"))
3048 (while (string-match "t\\(h\\)\\|td" fmt i)
3049 (setq line (concat line (if (match-beginning 1) "<th></th>"
3050 "<td></td>"))
3051 i (match-end 0))))
3052 (setq line (concat line "</tr>"))))
3053 (goto-char cp)
3054 (if th
3055 (message
3056 "Type `%s' to change td from/to th."
3057 (key-description (car (where-is-internal 'yahtml-change-*)))))
3058 (if (string< "" line)
3059 (progn
3060 (insert line)
3061 (goto-char (+ 8 cp))
3062 (yahtml-indent-line)))))))
3064 (defun yahtml-intelligent-newline-audio ()
3065 (let (b e)
3066 (if (save-excursion
3067 (goto-char (setq b (get 'YaTeX-inner-environment 'point)))
3068 (forward-list 1)
3069 (setq e (point))
3070 (catch 'src
3071 (while (re-search-forward "\\s src\\>" e t)
3072 (skip-chars-forward " \t\n")
3073 (and (looking-at "=") (throw 'src t)))))
3074 ;; if src= attribute found, do nothing
3075 (setq yahtml-last-begend "p")
3076 (yahtml-insert-single "source")
3077 )))
3078 (fset 'yahtml-intelligent-newline-video 'yahtml-intelligent-newline-audio)
3080 (defun yahtml-intelligent-newline-iframe ()
3081 (insert "<p>Your browser does not support iframes.</p>"))
3083 ;;; ---------- Marking ----------
3084 (defun yahtml-mark-begend ()
3085 "Mark current tag"
3086 (interactive)
3087 (YaTeX-beginning-of-environment)
3088 (let ((p (point)))
3089 (save-excursion
3090 (skip-chars-backward " \t" (point-beginning-of-line))
3091 (if (bolp) (setq p (point))))
3092 (push-mark p t))
3093 (yahtml-goto-corresponding-begend)
3094 (forward-list 1)
3095 (if (eolp) (forward-char 1)))
3097 ;;; ---------- complete marks ----------
3098 (defun yahtml-char-entity-ref ()
3099 "Complete &gt;, &lt;, &amp;, and &quot;."
3100 (interactive)
3101 (message "1:< 2:> 3:& 4:\" 5:' 6:nbsp")
3102 (let ((c (read-char)) d)
3103 (setq d (if (or (< c ?0) (> c ?7))
3104 (string-match (regexp-quote (char-to-string c)) "<>&\"' ")
3105 (- c ?1)))
3106 (cond
3107 ((null d) (insert (format "&#x%x;" c)))
3108 ((and (>= d 0) (<= d 6))
3109 (insert (format "&%s;"
3110 (nth d '("lt" "gt" "amp" "quot" "apos" "nbsp"))))))))
3113 ;;; ---------- jump to error line ----------
3114 (defun yahtml-prev-error ()
3115 "Jump to previous error seeing lint buffer."
3116 (interactive)
3117 (or (get-buffer yahtml-lint-buffer)
3118 (error "No lint program ran."))
3119 (YaTeX-showup-buffer yahtml-lint-buffer nil t)
3120 (yahtml-jump-to-error-line t))
3122 (defun yahtml-jump-to-error-line (&optional sit)
3123 (interactive "P")
3124 (let ((p (point)) (e (point-end-of-line)))
3125 (end-of-line)
3126 (if (re-search-backward yahtml-error-line-regexp nil t)
3127 (let ((f (if (string= "" (YaTeX-match-string 1))
3128 YaTeX-current-file-name
3129 (YaTeX-match-string 1)))
3130 (l (YaTeX-str2int (or (YaTeX-match-string 2)
3131 (YaTeX-match-string 3)))))
3132 (if sit (sit-for 1))
3133 (forward-line -1)
3134 (YaTeX-showup-buffer (YaTeX-switch-to-buffer f t) nil t)
3135 (goto-line l))
3136 (message "No line number usage"))))
3138 ;;; ---------- Style Sheet Support ----------
3139 (defvar yahtml-css-class-alist nil
3140 "Alist of elements vs. their classes")
3142 (defun yahtml-css-collect-classes-region (beg end &optional initial)
3143 (save-excursion
3144 (save-restriction
3145 (narrow-to-region beg end)
3146 (goto-char (point-min))
3147 (let ((alist initial) b e element class a)
3148 (setq b (point))
3149 (while (re-search-forward "\\({\\)\\|\\(@import\\)" nil t)
3150 (if (match-beginning 2)
3151 (let ((f (YaTeX-buffer-substring
3152 (progn (skip-chars-forward "^\"")(1+ (point)))
3153 (progn (forward-char 1)
3154 (skip-chars-forward "^\"")(point)))))
3155 (if (file-exists-p f)
3156 (setq alist
3157 (append alist (yahtml-css-collect-classes-file
3158 f initial)))))
3159 (setq e (point))
3160 (goto-char b)
3161 (while (re-search-forward ;ちょといい加減なREGEXP
3162 "\\([a-z*][-a-z0-9]*\\)?\\.\\([-a-z0-9][-a-z0-9]*\\)\\>"
3163 e t)
3164 (setq element (YaTeX-match-string 1)
3165 class (YaTeX-match-string 2))
3166 ;;if starts with period (match-string 1 is nil),
3167 ;;this is global class
3168 (setq element (downcase (or element "*")))
3169 (if (setq a (assoc element alist))
3170 (or (assoc class (cdr a))
3171 (setcdr a (cons (list class) (cdr a))))
3172 (setq alist (cons (list element (list class)) alist))))
3173 (goto-char (1- e))
3174 (search-forward "}" nil 1) ;1=move to limit when not found.
3175 (setq b (point))))
3176 alist))))
3178 (defun yahtml-css-collect-classes-buffer (&optional initial)
3179 (interactive)
3180 (yahtml-css-collect-classes-region (point-min) (point-max) initial))
3182 (defun yahtml-css-collect-classes-file (file &optional initial)
3183 (let*((hilit-auto-highlight nil)
3184 (buf (get-buffer-create
3185 (format " *css-collection*%s" (file-name-nondirectory file))))
3186 (cb (current-buffer)))
3187 (unwind-protect
3188 (progn
3189 (set-buffer buf)
3190 (insert-file-contents file)
3191 (cd (or (file-name-directory file) "."))
3192 (yahtml-css-collect-classes-buffer initial))
3193 (if (eq buf cb)
3194 nil
3195 (kill-buffer buf)
3196 (set-buffer cb)))))
3198 (defun yahtml-css-scan-styles ()
3199 (save-excursion
3200 (goto-char (point-min))
3201 (set (make-local-variable 'yahtml-css-class-alist) nil)
3202 (let (b tag type e href alist)
3203 (while (re-search-forward "<\\(style\\|link\\)" nil t)
3204 (setq b (match-beginning 0)
3205 tag (YaTeX-match-string 1))
3206 (cond
3207 ((string-match "style" tag)
3208 (goto-char b)
3209 (save-excursion (forward-list 1) (setq e (point)))
3210 (cond
3211 ((search-forward "text/css" e 1) ;css definition starts
3212 (setq alist
3213 (yahtml-css-collect-classes-region
3214 (point) (progn (search-forward "</style>") (point))
3215 alist)))))
3216 ((and (string-match "link" tag)
3217 (stringp (setq type (yahtml-get-attrvalue "type")))
3218 (string-match "text/css" type)
3219 (setq href (yahtml-get-attrvalue "href"))
3220 (file-exists-p (yahtml-url-to-path href)))
3221 (setq alist
3222 (yahtml-css-collect-classes-file
3223 (yahtml-url-to-path href) alist))))
3224 (setq yahtml-css-class-alist alist)))))
3226 (defun yahtml-css-get-element-completion-alist (element)
3227 (let ((alist (cdr-safe (assoc (downcase element) yahtml-css-class-alist)))
3228 (global (cdr-safe (assoc "*" yahtml-css-class-alist))))
3229 (and (or alist global)
3230 (append alist global))))
3232 ;;; ---------- ----------
3234 ;;;
3235 ;;hilit19
3236 ;;;
3237 (defvar yahtml-default-face-table
3238 '(
3239 (form black/ivory white/hex-442233 italic)
3240 ))
3241 (defvar yahtml-hilit-patterns-alist
3242 '(
3243 'case-fold
3244 ;; comments
3245 ("<!--\\s " "-->" comment)
3246 ;; include&exec
3247 ("<!--#\\(include\\|exec\\|config\\|fsize\\|flastmod\\)" "-->" include)
3248 ;; string
3249 (hilit-string-find ?\\ string)
3250 (yahtml-hilit-region-tag "<\\(strong\\|b\\)\\>" bold)
3251 ("</?[uod]l>" 0 decl)
3252 ("<\\(di\\|dt\\|li\\|dd\\)>" 0 label)
3253 (yahtml-hilit-region-tag "<\\(em\\|i\\>\\)" italic)
3254 ;("<a\\s +href" "</a>" crossref) ;good for hilit19, but odd for font-lock..
3255 (yahtml-hilit-region-tag "<\\(a\\)\\s +href" crossref)
3256 (yahtml-hilit-region-tag-itself "</?\\sw+\\>" decl)
3257 ))
3259 (defun yahtml-hilit-region-tag (tag)
3260 "Return list of start/end point of <TAG> form."
3261 (if (re-search-forward tag nil t)
3262 (let ((m0 (match-beginning 0)) (e0 (match-end 0))
3263 (elm (YaTeX-match-string 1)))
3264 (skip-chars-forward "^>")
3265 (prog1
3266 (cons (1+ (point))
3267 (progn (re-search-forward (concat "</" elm ">") nil t)
3268 (match-beginning 0)))
3269 (goto-char e0)))))
3271 (defun yahtml-hilit-region-tag-itself (ptn)
3272 "Return list of start/end point of <tag options...> itself."
3273 (if (re-search-forward ptn nil t)
3274 (let ((m0 (match-beginning 0)) (e0 (match-end 0)))
3275 (skip-chars-forward "^<>")
3276 (if (eq (char-after (point)) ?<) nil
3277 (prog1
3278 (cons m0 (min (point-max) (1+ (point))))
3279 (goto-char e0))))))
3281 ;(setq hilit-patterns-alist (delq (assq 'yahtml-mode hilit-patterns-alist) hilit-patterns-alist))
3282 (and yahtml-use-hilit19
3283 (or (assq 'yahtml-mode hilit-patterns-alist)
3284 (setq hilit-patterns-alist
3285 (cons (cons 'yahtml-mode yahtml-hilit-patterns-alist)
3286 hilit-patterns-alist))))
3287 ;;;
3288 ;; for font-lock
3289 ;;;
3291 ; <<STATIC KEYWORDS BELOW NOT USED>>
3292 ;(defvar yahtml-font-lock-keywords
3293 ; '(
3294 ; ;; comments
3295 ; ("<!--\\s .* -->" . font-lock-comment-face)
3296 ; ;; include&exec
3297 ; ("<!--#\\(include\\|exec\\|config\\|fsize\\|flastmod\\).*-->"
3298 ; 0 font-lock-include-face keep)
3299 ; ;; string
3300 ; ;(hilit-string-find ?\\ string)
3301 ; ;(yahtml-hilit-region-tag "\\(em\\|strong\\)" bold)
3302 ; ("</?[uod]l>" 0 font-lock-keyword-face)
3303 ; ("<\\(di\\|dt\\|li\\|dd\\)>" 0 font-lock-label-face)
3304 ; ("<a\\s +href=.*</a>" (0 font-lock-crossref-face keep))
3305 ; ;(yahtml-hilit-region-tag-itself "</?\\sw+\\>" decl)
3306 ; ("</?\\sw+\\>" (yahtml-fontify-to-tagend nil nil))
3307 ; )
3308 ; "*Defualt font-lock-keywords for yahtml-mode.")
3309 (defvar yahtml-font-lock-keywords
3310 (YaTeX-convert-pattern-hilit2fontlock yahtml-hilit-patterns-alist)
3311 "Default fontifying patterns for yahtml-mode")
3313 (defun yahtml-font-lock-set-default-keywords ()
3314 (put 'yahtml-mode 'font-lock-defaults
3315 '(yahtml-font-lock-keywords nil t)))
3317 (if yahtml-use-font-lock
3318 (progn
3319 (if (and (boundp 'hilit-mode-enable-list) hilit-mode-enable-list)
3320 ;;for those who use both hilit19 and font-lock
3321 (if (eq (car hilit-mode-enable-list) 'not)
3322 (or (member 'yahtml-mode hilit-mode-enable-list)
3323 (nconc hilit-mode-enable-list (list 'yahtml-mode)))
3324 (setq hilit-mode-enable-list
3325 (delq 'yahtml-mode hilit-mode-enable-list))))
3326 (yahtml-font-lock-set-default-keywords)))
3328 (defun yahtml-font-lock-recenter (&optional arg)
3329 (interactive "P")
3330 (font-lock-mode -1) ;is stupid, but sure.
3331 (font-lock-mode 1))
3333 ;;;
3334 ;; Drag-n-Drop
3335 ;;;
3336 (defun yahtml-dnd-handler (uri action)
3337 "DnD handler for yahtml mode
3338 Convert image URI to img-src and others to a-href."
3339 (let*((file (dnd-get-local-file-name uri))
3340 (path (if file (file-relative-name file) uri))
3341 (case-fold-search t)
3342 (geom ""))
3343 (cond
3344 ((memq action '(copy link move private))
3345 (cond
3346 ((string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\|tiff?\\)$" path)
3347 (if file
3348 (setq geom (yahtml-get-image-info path)
3349 geom (if (car geom)
3350 (apply 'format " width=\"%s\" height=\"%s\"" geom)
3351 "")))
3352 (insert (format "<img src=\"%s\" alt=\"%s\"%s>"
3353 path (file-name-nondirectory path) geom)))
3355 (t (insert (format "<a href=\"%s\"></a>" path))
3356 (forward-char -4))))
3357 (t (message "No handler for action `%s'" action))))
3358 action)
3360 (run-hooks 'yahtml-load-hook)
3361 (provide 'yahtml)
3363 ; Local variables:
3364 ; fill-prefix: ";;; "
3365 ; paragraph-start: "^$\\| \\|;;;$"
3366 ; paragraph-separate: "^$\\| \\|;;;$"
3367 ; End: