yatex

annotate yahtml.el @ 69:807c1e7e68b7

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