yatex

annotate yahtml.el @ 394:67fa6d791bc9

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