yatex

annotate yahtml.el @ 411:a4a2635c5158

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