yatex

annotate yahtml.el @ 437:27f00e6e0150

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