yatex

annotate yahtml.el @ 77:1b172d26b55e

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