yatex

annotate yahtml.el @ 72:0aaebd07dad0

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