yatex

annotate yahtml.el @ 443:7a9d30752353

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