yatex

annotate yahtml.el @ 475:d6952c7e35cc

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