yatex

annotate yahtml.el @ 153:207f0b4af9df

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