yatex

annotate yahtml.el @ 86:f14ec50103d0

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