yatex

annotate yahtml.el @ 103:f2f0d1eedd39

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