yatex

annotate yahtml.el @ 623:6a0fea36298f

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