yatex

annotate yahtml.el @ 64:36a48185b95a

Changes are listed in yatex.new. Major one is supporing GNU Emacs20 and XEmacs.
author yuuji
date Tue, 16 Dec 1997 13:28:38 +0000
parents b9f753846b6b
children 0eb6997bee16
rev   line source
yuuji@13 1 ;;; -*- Emacs-Lisp -*-
yuuji@60 2 ;;; (c ) 1994-1997 by HIROSE Yuuji [yuuji@ae.keio.ac.jp]
yuuji@64 3 ;;; Last modified Tue Dec 16 21:10:05 1997 on crx
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@58 78 ;;;
yuuji@64 79 ;;;[キーの説明]
yuuji@64 80 ;;;
yuuji@64 81 ;;; 以下の説明において、特にカスタマイズをしていない限り、[prefix] は
yuuji@64 82 ;;; C-c キーを意味します。
yuuji@64 83 ;;;
yuuji@64 84 ;;; * [prefix] b X `</H1>' といった終了タグが必要となる`H1'のよう
yuuji@64 85 ;;; な環境を補完入力します。<a href=foo> ... </a>
yuuji@64 86 ;;; もこのグループです。
yuuji@64 87 ;;; `href=...' と入力した後、TABキーを押すことで、
yuuji@64 88 ;;; ファイル名や (href="#foo") のようなラベルも補完
yuuji@64 89 ;;; できます。
yuuji@64 90 ;;; * [prefix] s 以下のような宣言の補完を行います。
yuuji@64 91 ;;; `<img src="foo.gif">'
yuuji@64 92 ;;; `<input name="var" ...>'
yuuji@64 93 ;;; * [prefix] l `<i> ... </i>' や `<samp> ... </samp>' のよう
yuuji@64 94 ;;; なテキストスタイル指定のタグを補完します。
yuuji@64 95 ;;; この補完機能は通常 [prefix] b で補完できるものを
yuuji@64 96 ;;; 一行内で書きたいときにも用いることが出来ます。
yuuji@64 97 ;;; * [prefix] m `<br>' や `<hr> '、`<li>' 等の単体タグの補完
yuuji@64 98 ;;; を行います。
yuuji@64 99 ;;; * [prefix] p カーソル位置に<p></p>を挿入します。
yuuji@64 100 ;;; * M-RET おまかせ改行; もしul、ol、dl等のタグ(リスト)を
yuuji@64 101 ;;; 使っている場合に、環境に合わせて改行と <li>、
yuuji@64 102 ;;; <dt>、<dd>を入力します。
yuuji@64 103 ;;; * menu-bar yahtml 選択したアイテムをメニューより補完できます。
yuuji@64 104 ;;; (私はメニューが嫌いなんですが、htmlに関してはメ
yuuji@64 105 ;;; ニューは一番ありがたいかも)
yuuji@64 106 ;;; * [prefix] g 対応するタグ、<dl> <-> </dl> や href="xxx" の
yuuji@64 107 ;;; ような TAG にジャンプします。
yuuji@64 108 ;;; <img src=...> の場合はイメージビューワを呼び出
yuuji@64 109 ;;; します。href=hoge.html の場合はhoge.htmlに飛びま
yuuji@64 110 ;;; す。
yuuji@64 111 ;;; * [prefix] k ポイント上の HTML タグを消去します。
yuuji@64 112 ;;; もし universal-argument を付けた場合(C-uを先に押
yuuji@64 113 ;;; す)HTMLタグで囲まれた内容も同時に消去します。
yuuji@64 114 ;;; * [prefix] c ポイント上のタグを変更します。
yuuji@64 115 ;;; `href="xxx"'の上で [prefix] c を利用した場合は、
yuuji@64 116 ;;; 参照しているリンクを補完機能を使いながら変更で
yuuji@64 117 ;;; きます。
yuuji@64 118 ;;; * [prefix] t j カレントファイルに対して jweblint を呼び出しま
yuuji@64 119 ;;; す。
yuuji@64 120 ;;; * [prefix] t p WWW ブラウザでカレントファイルを表示します。
yuuji@64 121 ;;; (lisp変数 yahtml-www-browser の設定をお忘れな
yuuji@64 122 ;;; く。お推めは "netscape" で、ねすけの場合既にねす
yuuji@64 123 ;;; けが起動されていた場合そのねすけに Reload 命令を
yuuji@64 124 ;;; 送るという芸当が出来ます。ただし今のところX版の
yuuji@64 125 ;;; ねすけちゃんだけ)
yuuji@64 126 ;;; * [prefix] a YaTeX のアクセント記号補完と同じです。
yuuji@64 127 ;;; &lt; &gt; 等が入力できます。
yuuji@64 128 ;;;
yuuji@64 129 ;;; [謝辞]
yuuji@64 130 ;;;
yuuji@64 131 ;;; fj野鳥の会の皆さんには貴重な助言を頂きました。また、下に示す方々には
yuuji@64 132 ;;; 特に大きな協力を頂きました。あわせてここに感謝申し上げます。
yuuji@64 133 ;;;
yuuji@64 134 ;;; * 横田和也さん(マツダ)
yuuji@64 135 ;;; マニュアルの和訳をして頂きました。
yuuji@64 136 ;;; * 吉田尚志さん(NTT Data)
yuuji@64 137 ;;; Mule for Win32 での動作のさせ方を教えて頂きました。
yuuji@64 138 ;;; (というかほとんどやってもらった ^^;)
yuuji@64 139 ;;;
yuuji@54 140
yuuji@13 141
yuuji@64 142 ;(require 'yatex)
yuuji@64 143 (require 'yatexlib)
yuuji@60 144 ;;; --- customizable variable starts here ---
yuuji@64 145 (defvar yahtml-prefix "\C-c"
yuuji@64 146 "*Prefix key stroke of yahtml functions.")
yuuji@58 147 (defvar yahtml-image-viewer "xv" "*Image viewer program")
yuuji@58 148 (defvar yahtml-www-browser "netscape"
yuuji@58 149 "*WWW Browser command")
yuuji@58 150 (defvar yahtml-kanji-code 2
yuuji@64 151 "*Kanji coding system number of html file; 1=sjis, 2=jis, 3=euc")
yuuji@64 152 (defvar yahtml-coding-system
yuuji@64 153 (cdr (assq yahtml-kanji-code YaTeX-kanji-code-alist))
yuuji@64 154 "Kanji coding system")
yuuji@64 155 (defvar yahtml-fill-column 72 "*fill culumn used for yahtml-mode")
yuuji@64 156 (defvar yahtml-fill-prefix nil "*fill prefix for yahtml-mode")
yuuji@64 157
yuuji@58 158 ;;(defvar yahtml-www-server "www" "*Host name of your domain's WWW server")
yuuji@58 159 (defvar yahtml-path-url-alist nil
yuuji@58 160 "*Alist of unix path name vs. URL name of WWW server.
yuuji@58 161 Ex.
yuuji@58 162 '((\"/usr/home/yuuji/http\" . \"http://www.comp.ae.keio.ac.jp/~yuuji\")
yuuji@64 163 (\"/usr/home/yuuji/darts/http\" . \"http://darts.comp.ae.keio.ac.jp/~darts\"))")
yuuji@58 164 (defvar yahtml-directory-index "index.html"
yuuji@58 165 "*Directory index file name;
yuuji@58 166 Consult your site's WWW administrator.")
yuuji@57 167
yuuji@64 168 (defvar yahtml-environment-indent 1
yuuji@60 169 "*Indentation depth of HTML's listing environment")
yuuji@60 170
yuuji@64 171 (defvar YaTeX-japan (or (boundp 'NEMACS) (boundp 'MULE) YaTeX-emacs-20)
yuuji@64 172 "Whether yatex mode is running on Japanese environment or not.")
yuuji@64 173
yuuji@60 174 (defvar yahtml-lint-program (if YaTeX-japan "jweblint" "weblint")
yuuji@60 175 "*Program name to lint HTML file")
yuuji@60 176 (defvar yahtml-hate-too-deep-indentation nil
yuuji@60 177 "*Non-nil for this variable suppress deep indentation in listing environments.")
yuuji@60 178
yuuji@64 179 (defvar yahtml-always-/p nil
yuuji@64 180 "*Those who always use <p> with </p> set this to t.")
yuuji@64 181
yuuji@64 182 (defvar yahtml-p-prefered-env-regexp "^\\(body\\|dl\\)"
yuuji@64 183 "*Regexp of envs where paragraphed sentences are prefered.")
yuuji@64 184
yuuji@64 185 (defvar yahtml-template-file "~/http/template.html"
yuuji@64 186 "*Template HTML file. It'll be inserted to empty file.")
yuuji@64 187
yuuji@60 188 ;;; --- customizable variable ends here ---
yuuji@60 189 (defvar yahtml-prefix-map nil)
yuuji@60 190 (defvar yahtml-mode-map nil "Keymap used in yahtml-mode.")
yuuji@60 191 (defvar yahtml-lint-buffer-map nil "Keymap used in lint buffer.")
yuuji@60 192 (defvar yahtml-shell-command-option
yuuji@60 193 (or (and (boundp 'shell-command-option) shell-command-option)
yuuji@60 194 (if (eq system-type 'ms-dos) "/c" "-c")))
yuuji@60 195
yuuji@60 196
yuuji@57 197 (defun yahtml-define-begend-key-normal (key env &optional map)
yuuji@60 198 "Define short cut yahtml-insert-begend key."
yuuji@57 199 (YaTeX-define-key
yuuji@57 200 key
yuuji@57 201 (list 'lambda '(arg) '(interactive "P")
yuuji@60 202 (list 'yahtml-insert-begend 'arg env))
yuuji@57 203 map))
yuuji@57 204
yuuji@57 205 (defun yahtml-define-begend-region-key (key env &optional map)
yuuji@60 206 "Define short cut yahtml-insert-begend-region key."
yuuji@57 207 (YaTeX-define-key key (list 'lambda nil '(interactive)
yuuji@60 208 (list 'yahtml-insert-begend t env)) map))
yuuji@57 209
yuuji@57 210 (defun yahtml-define-begend-key (key env &optional map)
yuuji@57 211 "Define short cut key for begin type completion both for
yuuji@57 212 normal and region mode. To customize yahtml, user should use this function."
yuuji@57 213 (yahtml-define-begend-key-normal key env map)
yuuji@57 214 (if YaTeX-inhibit-prefix-letter nil
yuuji@57 215 (yahtml-define-begend-region-key
yuuji@61 216 (concat (upcase (substring key 0 1)) (substring key 1)) env map)))
yuuji@57 217
yuuji@57 218
yuuji@13 219 (if yahtml-mode-map nil
yuuji@57 220 (setq yahtml-mode-map (make-sparse-keymap)
yuuji@57 221 yahtml-prefix-map (make-sparse-keymap))
yuuji@64 222 (define-key yahtml-mode-map yahtml-prefix yahtml-prefix-map)
yuuji@58 223 (define-key yahtml-mode-map "\M-\C-@" 'yahtml-mark-begend)
yuuji@58 224 (if (and (boundp 'window-system) (eq window-system 'x) YaTeX-emacs-19)
yuuji@58 225 (define-key yahtml-mode-map [?\M-\C- ] 'yahtml-mark-begend))
yuuji@54 226 (define-key yahtml-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment)
yuuji@57 227 (define-key yahtml-mode-map "\M-\C-e" 'YaTeX-end-of-environment)
yuuji@58 228 (define-key yahtml-mode-map "\M-\C-m" 'yahtml-intelligent-newline)
yuuji@58 229 (define-key yahtml-mode-map "\C-i" 'yahtml-indent-line)
yuuji@57 230 (let ((map yahtml-prefix-map))
yuuji@57 231 (YaTeX-define-key "^" 'yahtml-visit-main map)
yuuji@57 232 (YaTeX-define-key "4^" 'yahtml-visit-main-other-window map)
yuuji@57 233 (YaTeX-define-key "4g" 'yahtml-goto-corresponding-*-other-window map)
yuuji@57 234 (YaTeX-define-key "44" 'YaTeX-switch-to-window map)
yuuji@57 235 (and YaTeX-emacs-19 window-system
yuuji@57 236 (progn
yuuji@57 237 (YaTeX-define-key "5^" 'yahtml-visit-main-other-frame map)
yuuji@57 238 (YaTeX-define-key "5g" 'yahtml-goto-corresponding-*-other-frame map)
yuuji@57 239 (YaTeX-define-key "55" 'YaTeX-switch-to-window map)))
yuuji@57 240 (YaTeX-define-key "v" 'YaTeX-version map)
yuuji@57 241 (YaTeX-define-key "}" 'YaTeX-insert-braces-region map)
yuuji@57 242 (YaTeX-define-key "]" 'YaTeX-insert-brackets-region map)
yuuji@57 243 (YaTeX-define-key ")" 'YaTeX-insert-parens-region map)
yuuji@57 244 (YaTeX-define-key "s" 'yahtml-insert-form map)
yuuji@57 245 (YaTeX-define-key "l" 'yahtml-insert-tag map)
yuuji@61 246 (YaTeX-define-key "L" 'yahtml-insert-tag-region map)
yuuji@57 247 (YaTeX-define-key "m" 'yahtml-insert-single map)
yuuji@61 248 (YaTeX-define-key "n" '(lambda () (interactive) (insert (if yahtml-prefer-upcases "<BR>" "<br>"))) map)
yuuji@61 249 (YaTeX-define-key "-" '(lambda () (interactive) (insert (if yahtml-prefer-upcases "<HR>" "<hr>") "\n")) map)
yuuji@64 250 (YaTeX-define-key "p" 'yahtml-insert-p map)
yuuji@57 251 (if YaTeX-no-begend-shortcut
yuuji@57 252 (progn
yuuji@57 253 (YaTeX-define-key "B" 'yahtml-insert-begend-region map)
yuuji@57 254 (YaTeX-define-key "b" 'yahtml-insert-begend map))
yuuji@60 255 (yahtml-define-begend-key "bh" "html" map)
yuuji@60 256 (yahtml-define-begend-key "bH" "head" map)
yuuji@60 257 (yahtml-define-begend-key "bt" "title" map)
yuuji@59 258 (yahtml-define-begend-key "bT" "table" map)
yuuji@60 259 (yahtml-define-begend-key "bb" "body" map)
yuuji@60 260 (yahtml-define-begend-key "bc" "center" map)
yuuji@60 261 (yahtml-define-begend-key "bd" "dl" map)
yuuji@60 262 (yahtml-define-begend-key "bu" "ul" map)
yuuji@60 263 (yahtml-define-begend-key "b1" "h1" map)
yuuji@60 264 (yahtml-define-begend-key "b2" "h2" map)
yuuji@60 265 (yahtml-define-begend-key "b3" "h3" map)
yuuji@57 266 (yahtml-define-begend-key "ba" "a" map)
yuuji@57 267 (yahtml-define-begend-key "bf" "form" map)
yuuji@57 268 (yahtml-define-begend-key "bs" "select" map)
yuuji@57 269 (YaTeX-define-key "b " 'yahtml-insert-begend map)
yuuji@58 270 (YaTeX-define-key "B " 'yahtml-insert-begend-region map)
yuuji@57 271 )
yuuji@58 272 (YaTeX-define-key "e" 'YaTeX-end-environment map)
yuuji@57 273 (YaTeX-define-key ">" 'yahtml-comment-region map)
yuuji@57 274 (YaTeX-define-key "<" 'yahtml-uncomment-region map)
yuuji@57 275 (YaTeX-define-key "g" 'yahtml-goto-corresponding-* map)
yuuji@58 276 (YaTeX-define-key "k" 'yahtml-kill-* map)
yuuji@58 277 (YaTeX-define-key "c" 'yahtml-change-* map)
yuuji@58 278 (YaTeX-define-key "t" 'yahtml-browse-menu map)
yuuji@59 279 (YaTeX-define-key "a" 'yahtml-complete-mark map)
yuuji@60 280 (YaTeX-define-key "'" 'yahtml-prev-error map)
yuuji@58 281 ;;;;;(YaTeX-define-key "i" 'yahtml-fill-item map)
yuuji@60 282 ))
yuuji@60 283
yuuji@60 284 (if yahtml-lint-buffer-map nil
yuuji@60 285 (setq yahtml-lint-buffer-map (make-keymap))
yuuji@60 286 (define-key yahtml-lint-buffer-map " " 'yahtml-jump-to-error-line))
yuuji@60 287
yuuji@54 288
yuuji@59 289 (defvar yahtml-paragraph-start
yuuji@59 290 (concat
yuuji@61 291 "^$\\|<!--\\|^[ \t]*</?\\(h[1-6]\\|p\\|d[ldt]\\|[bhtd][rdh]\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\|table\\|center\\|blockquote\\)\\b")
yuuji@59 292 "*Regexp of html paragraph separater")
yuuji@57 293 (defvar yahtml-paragraph-separate
yuuji@57 294 (concat
yuuji@61 295 "^$\\|<!--\\|^[ \t]*</?\\(h[1-6]\\|p\\|[bhtd][ldt]\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\|table\\|center\\|blockquote\\|!--\\)\\b")
yuuji@57 296 "*Regexp of html paragraph separater")
yuuji@54 297 (defvar yahtml-syntax-table nil
yuuji@64 298 "*Syntax table for yahtml-mode")
yuuji@54 299
yuuji@54 300 (if yahtml-syntax-table nil
yuuji@54 301 (setq yahtml-syntax-table
yuuji@54 302 (make-syntax-table (standard-syntax-table)))
yuuji@61 303 (modify-syntax-entry ?\< "(>" yahtml-syntax-table)
yuuji@61 304 (modify-syntax-entry ?\> ")<" yahtml-syntax-table)
yuuji@59 305 (modify-syntax-entry ?\n " " yahtml-syntax-table)
yuuji@54 306 )
yuuji@54 307 (defvar yahtml-command-regexp "[A-Za-z0-9]+"
yuuji@54 308 "Regexp of constituent of html commands.")
yuuji@54 309
yuuji@54 310 ;;; Completion tables for `form'
yuuji@57 311 (defvar yahtml-form-table
yuuji@57 312 '(("img") ("input")))
yuuji@54 313 (defvar yahtml-user-form-table nil)
yuuji@54 314 (defvar yahtml-tmp-form-table nil)
yuuji@64 315 (defvar yahtml-last-form "img")
yuuji@54 316
yuuji@54 317 (defvar yahtml-env-table
yuuji@60 318 '(("html") ("head") ("title") ("body") ("dl") ("ul") ("ol") ("pre")
yuuji@60 319 ("a") ("form") ("select") ("center") ("textarea") ("blockquote")
yuuji@58 320 ("OrderedList" . "ol")
yuuji@58 321 ("UnorderedList" . "ul")
yuuji@58 322 ("DefinitionList" . "dl")
yuuji@59 323 ("Preformatted" . "pre")
yuuji@59 324 ("table") ("tr") ("th") ("td")
yuuji@61 325 ("h1") ("h2") ("h3") ("h4") ("h5") ("h6")
yuuji@64 326 ;; ("p") ;This makes indentation screwed up!
yuuji@64 327 ))
yuuji@57 328
yuuji@58 329 (defvar yahtml-itemizing-regexp
yuuji@58 330 "\\(ul\\|ul\\|dl\\)"
yuuji@58 331 "Regexp of itemizing forms")
yuuji@58 332
yuuji@57 333 (defvar yahtml-user-env-table nil)
yuuji@57 334 (defvar yahtml-tmp-env-table nil)
yuuji@54 335
yuuji@54 336 ;;; Completion tables for typeface designator
yuuji@64 337 (and yahtml-always-/p
yuuji@64 338 (or (assoc "p" yahtml-env-table)
yuuji@64 339 (setq yahtml-env-table (cons '("p") yahtml-env-table))))
yuuji@64 340
yuuji@54 341 (defvar yahtml-typeface-table
yuuji@60 342 (append
yuuji@60 343 '(("dfn") ("em") ("cite") ("code") ("kbd") ("samp")
yuuji@64 344 ("strong") ("var") ("b") ("i") ("tt") ("u") ("address") ("font"))
yuuji@60 345 yahtml-env-table)
yuuji@54 346 "Default completion table of typeface designator")
yuuji@54 347 (defvar yahtml-user-typeface-table nil)
yuuji@54 348 (defvar yahtml-tmp-typeface-table nil)
yuuji@64 349 (defvar yahtml-last-typeface-cmd "a")
yuuji@54 350
yuuji@57 351 (defvar yahtml-single-cmd-table
yuuji@58 352 '(("hr") ("br") ("option") ("p")
yuuji@58 353 ("HorizontalLine" . "hr")
yuuji@58 354 ("BreakLine" . "br")
yuuji@58 355 ("Paragraph" . "p")
yuuji@58 356 ("Item" . "li")
yuuji@58 357 ("DefineTerm" . "dt")
yuuji@58 358 ("Description" . "dd")
yuuji@58 359 ("dd") ("dt") ("li")
yuuji@58 360 )
yuuji@57 361 "Default completion table of HTML single command.")
yuuji@57 362 (defvar yahtml-user-single-cmd-table nil)
yuuji@57 363 (defvar yahtml-tmp-single-cmd-table nil)
yuuji@57 364 (defvar yahtml-last-single-cmd nil)
yuuji@57 365
yuuji@54 366 (defvar yahtml-prefer-upcases nil)
yuuji@13 367
yuuji@61 368 ;(defvar yahtml-struct-name-regexp
yuuji@61 369 ; "\\<\\(h[1-6]\\|[uod]l\\|html\\|body\\|title\\|head\\|table\\|t[rhd]\\|pre\\|a\\|form\\|select\\|center\\|blockquote\\)\\b")
yuuji@57 370 (defvar yahtml-struct-name-regexp
yuuji@61 371 (concat
yuuji@61 372 "\\<\\("
yuuji@61 373 (mapconcat (function (lambda (x) (car x))) yahtml-typeface-table "\\|")
yuuji@61 374 "\\)\\b")
yuuji@61 375 "Regexp of structure beginning.")
yuuji@64 376 (or (assoc "p" yahtml-env-table)
yuuji@64 377 (setq yahtml-env-table (cons '("p") yahtml-env-table)))
yuuji@57 378
yuuji@13 379 (defun yahtml-mode ()
yuuji@13 380 (interactive)
yuuji@57 381 (cond
yuuji@64 382 ((and YaTeX-emacs-20 (fboundp 'coding-system-equal))
yuuji@64 383 (if t (or (coding-system-equal
yuuji@64 384 yahtml-coding-system buffer-file-coding-system)
yuuji@64 385 (set-buffer-file-coding-system yahtml-coding-system))
yuuji@64 386 ;;^v which is better?
yuuji@64 387 (let ((bmp (buffer-modified-p)))
yuuji@64 388 (set-buffer-file-coding-system yahtml-coding-system)
yuuji@64 389 (set-buffer-modified-p bmp))))
yuuji@64 390 ((featurep 'mule)
yuuji@64 391 (set-file-coding-system yahtml-coding-system))
yuuji@57 392 ((boundp 'NEMACS)
yuuji@57 393 (make-local-variable 'kanji-fileio-code)
yuuji@57 394 (setq kanji-fileio-code yahtml-kanji-code)))
yuuji@13 395 (setq major-mode 'yahtml-mode
yuuji@13 396 mode-name "yahtml")
yuuji@64 397 (mapcar
yuuji@64 398 (function (lambda (x)
yuuji@64 399 (make-local-variable (car x))
yuuji@64 400 (set (car x) (if (and (symbolp (cdr x))
yuuji@64 401 (boundp (cdr x)))
yuuji@64 402 (symbol-value (cdr x))
yuuji@64 403 (cdr x)))))
yuuji@64 404 '((YaTeX-ec . "")
yuuji@64 405 (YaTeX-struct-begin . "<%1%2")
yuuji@64 406 (YaTeX-struct-end . "</%1>")
yuuji@64 407 (YaTeX-struct-name-regexp . yahtml-struct-name-regexp)
yuuji@64 408 (YaTeX-comment-prefix . "<!--")
yuuji@64 409 (YaTeX-coding-system . yahtml-coding-system)
yuuji@64 410 (YaTeX-typesetting-mode-map . yahtml-lint-buffer-map)
yuuji@64 411 (fill-prefix . yahtml-fill-prefix) (fill-column . yahtml-fill-column)
yuuji@64 412 (paragraph-start . yahtml-paragraph-start)
yuuji@64 413 (paragraph-separate . yahtml-paragraph-separate)
yuuji@64 414 (comment-start . "<!-- ") (comment-end . " -->")
yuuji@64 415 (comment-start-skip . comment-start)
yuuji@64 416 (indent-line-function . yahtml-indent-line)))
yuuji@64 417
yuuji@54 418 (set-syntax-table yahtml-syntax-table)
yuuji@13 419 (use-local-map yahtml-mode-map)
yuuji@64 420 (YaTeX-read-user-completion-table)
yuuji@64 421 (turn-on-auto-fill) ;Sorry, this is prerequisite
yuuji@64 422 (and (= 0 (buffer-size)) (file-exists-p yahtml-template-file)
yuuji@64 423 (y-or-n-p (format "Insert %s?" yahtml-template-file))
yuuji@64 424 (insert-file-contents (expand-file-name yahtml-template-file)))
yuuji@64 425 (run-hooks 'text-mode-hook 'yahtml-mode-hook))
yuuji@54 426
yuuji@54 427 (defun yahtml-define-menu (keymap bindlist)
yuuji@64 428 (cond
yuuji@64 429 ((featurep 'xemacs)
yuuji@64 430 (let ((name (keymap-name (symbol-value keymap))))
yuuji@64 431 (set keymap nil)
yuuji@64 432 (mapcar
yuuji@64 433 (function
yuuji@64 434 (lambda (bind)
yuuji@64 435 (setq bind (cdr bind))
yuuji@64 436 (if (eq (car (cdr bind)) 'lambda)
yuuji@64 437 (setcar (cdr bind) 'progn))
yuuji@64 438 (if (stringp (car (cdr bind)))
yuuji@64 439 (set keymap (cons (cdr bind) (symbol-value keymap)))
yuuji@64 440 (set keymap (cons (vector (car bind) (cdr bind) t)
yuuji@64 441 (symbol-value keymap))))))
yuuji@64 442 bindlist)
yuuji@64 443 (set keymap (cons name (symbol-value keymap)))))
yuuji@64 444 (t
yuuji@64 445 (mapcar
yuuji@64 446 (function
yuuji@64 447 (lambda (bind)
yuuji@64 448 (define-key (symbol-value keymap) (vector (car bind)) (cdr bind))))
yuuji@64 449 bindlist))))
yuuji@54 450
yuuji@54 451 (defvar yahtml-menu-map nil "Menu map of yahtml")
yuuji@54 452 (defvar yahtml-menu-map-sectioning nil "Menu map of yahtml(sectioning)")
yuuji@54 453 (defvar yahtml-menu-map-listing nil "Menu map of yahtml(listing)")
yuuji@54 454 (defvar yahtml-menu-map-logical nil "Menu map of yahtml(logical tags)")
yuuji@54 455 (defvar yahtml-menu-map-typeface nil "Menu map of yahtml(typeface tags)")
yuuji@54 456
yuuji@54 457 ;;; Variables for mosaic url history
yuuji@54 458 (defvar yahtml-urls nil "Alist of global history")
yuuji@64 459 (defvar yahtml-urls-private nil)
yuuji@64 460 (defvar yahtml-urls-local nil)
yuuji@54 461
yuuji@54 462 (cond
yuuji@54 463 ((and YaTeX-emacs-19 (null yahtml-menu-map))
yuuji@64 464 (setq yahtml-menu-map (make-sparse-keymap "yahtml"))
yuuji@54 465 (setq yahtml-menu-map-sectioning (make-sparse-keymap "sectioning menu"))
yuuji@64 466 (YaTeX-define-menu
yuuji@64 467 'yahtml-menu-map-sectioning
yuuji@54 468 (nreverse
yuuji@58 469 '((1 "H1" . (lambda () (interactive) (yahtml-insert-begend nil "H1")))
yuuji@58 470 (2 "H2" . (lambda () (interactive) (yahtml-insert-begend nil "H2")))
yuuji@58 471 (3 "H3" . (lambda () (interactive) (yahtml-insert-begend nil "H3")))
yuuji@58 472 (4 "H4" . (lambda () (interactive) (yahtml-insert-begend nil "H4")))
yuuji@58 473 (5 "H5" . (lambda () (interactive) (yahtml-insert-begend nil "H5")))
yuuji@58 474 (6 "H6" . (lambda () (interactive) (yahtml-insert-begend nil "H6")))
yuuji@54 475 )))
yuuji@54 476 (setq yahtml-menu-map-logical (make-sparse-keymap "logical tags"))
yuuji@64 477 (YaTeX-define-menu
yuuji@64 478 'yahtml-menu-map-logical
yuuji@54 479 (nreverse
yuuji@54 480 '((em "Embolden" .
yuuji@58 481 (lambda () (interactive) (yahtml-insert-tag nil "EM")))
yuuji@60 482 (dfn "Define a word" .
yuuji@60 483 (lambda () (interactive) (yahtml-insert-tag nil "DFN")))
yuuji@54 484 (cite "Citation" .
yuuji@58 485 (lambda () (interactive) (yahtml-insert-tag nil "CITE")))
yuuji@54 486 (code "Code" .
yuuji@58 487 (lambda () (interactive) (yahtml-insert-tag nil "CODE")))
yuuji@54 488 (kbd "Keyboard" .
yuuji@58 489 (lambda () (interactive) (yahtml-insert-tag nil "KBD")))
yuuji@54 490 (samp "Sample display" .
yuuji@58 491 (lambda () (interactive) (yahtml-insert-tag nil "SAMP")))
yuuji@54 492 (strong "Strong" .
yuuji@58 493 (lambda () (interactive) (yahtml-insert-tag nil "STRONG")))
yuuji@54 494 (VAR "Variable notation" .
yuuji@58 495 (lambda () (interactive) (yahtml-insert-tag nil "VAR")))
yuuji@54 496 )))
yuuji@54 497 (setq yahtml-menu-map-typeface (make-sparse-keymap "typeface tags"))
yuuji@64 498 (YaTeX-define-menu
yuuji@64 499 'yahtml-menu-map-typeface
yuuji@54 500 (nreverse
yuuji@54 501 '((b "Bold" .
yuuji@58 502 (lambda () (interactive) (yahtml-insert-tag nil "B")))
yuuji@54 503 (i "Italic" .
yuuji@58 504 (lambda () (interactive) (yahtml-insert-tag nil "I")))
yuuji@54 505 (tt "Typewriter" .
yuuji@58 506 (lambda () (interactive) (yahtml-insert-tag nil "TT")))
yuuji@54 507 (u "Underlined" .
yuuji@58 508 (lambda () (interactive) (yahtml-insert-tag nil "U")))
yuuji@54 509 )))
yuuji@54 510 (setq yahtml-menu-map-listing (make-sparse-keymap "listing"))
yuuji@64 511 (YaTeX-define-menu
yuuji@64 512 'yahtml-menu-map-listing
yuuji@54 513 (nreverse
yuuji@58 514 '((ul "Unordered" .
yuuji@58 515 (lambda () (interactive) (yahtml-insert-begend nil "UL")))
yuuji@58 516 (ol "Ordered" .
yuuji@58 517 (lambda () (interactive) (yahtml-insert-begend nil "OL")))
yuuji@58 518 (dl "Definition" .
yuuji@58 519 (lambda () (interactive) (yahtml-insert-begend nil "DL")))
yuuji@54 520 )))
yuuji@57 521 (setq yahtml-menu-map-item (make-sparse-keymap "item"))
yuuji@64 522 (YaTeX-define-menu
yuuji@64 523 'yahtml-menu-map-item
yuuji@57 524 (nreverse
yuuji@57 525 '((li "Simple item" .
yuuji@57 526 (lambda () (interactive) (yahtml-insert-single "li")))
yuuji@57 527 (dt "Define term" .
yuuji@57 528 (lambda () (interactive) (yahtml-insert-single "dt")))
yuuji@57 529 (dd "Description of term" .
yuuji@57 530 (lambda () (interactive) (yahtml-insert-single "dd")))
yuuji@57 531 )))
yuuji@54 532 (define-key yahtml-mode-map [menu-bar yahtml]
yuuji@54 533 (cons "yahtml" yahtml-menu-map))
yuuji@58 534 (let ((keys (where-is-internal 'fill-paragraph global-map)))
yuuji@58 535 (while keys
yuuji@58 536 (define-key yahtml-mode-map (car keys) 'yahtml-fill-paragraph)
yuuji@58 537 (setq keys (cdr keys))))
yuuji@64 538 (YaTeX-define-menu
yuuji@64 539 'yahtml-menu-map
yuuji@54 540 (nreverse
yuuji@54 541 (list
yuuji@54 542 (cons (list 'sect "Sectioning")
yuuji@54 543 (cons "sectioning" yahtml-menu-map-sectioning))
yuuji@54 544 (cons (list 'list "Listing")
yuuji@54 545 (cons "Listing" yahtml-menu-map-listing))
yuuji@57 546 (cons (list 'item "Item")
yuuji@57 547 (cons "Itemizing" yahtml-menu-map-item));;;
yuuji@54 548 (cons (list 'logi "Logical tags")
yuuji@54 549 (cons "logical" yahtml-menu-map-logical))
yuuji@54 550 (cons (list 'type "Typeface tags")
yuuji@54 551 (cons "typeface" yahtml-menu-map-typeface))
yuuji@54 552 )))
yuuji@64 553 (if (featurep 'xemacs)
yuuji@64 554 (add-hook 'yahtml-mode-hook
yuuji@64 555 '(lambda ()
yuuji@64 556 (or (assoc "yahtml" current-menubar)
yuuji@64 557 (progn
yuuji@64 558 (set-buffer-menubar (copy-sequence current-menubar))
yuuji@64 559 (add-submenu nil yahtml-menu-map))))))
yuuji@54 560 ))
yuuji@54 561
yuuji@57 562 ;;; ----------- Completion ----------
yuuji@57 563 (defvar yahtml-last-begend "html")
yuuji@58 564 (defun yahtml-insert-begend (&optional region env)
yuuji@57 565 "Insert <cmd> ... </cmd>."
yuuji@57 566 (interactive "P")
yuuji@58 567 (let*((completion-ignore-case t)
yuuji@58 568 (cmd
yuuji@58 569 (or env
yuuji@58 570 (YaTeX-cplread-with-learning
yuuji@57 571 (format "Environment(default %s): " yahtml-last-begend)
yuuji@58 572 'yahtml-env-table 'yahtml-user-env-table 'yahtml-tmp-env-table)))
yuuji@58 573 (bolp (save-excursion
yuuji@58 574 (skip-chars-backward " \t" (point-beginning-of-line)) (bolp)))
yuuji@58 575 (cc (current-column)))
yuuji@57 576 (if (string< "" cmd) (setq yahtml-last-begend cmd))
yuuji@58 577 (setq yahtml-last-begend
yuuji@58 578 (or (cdr (assoc yahtml-last-begend yahtml-env-table))
yuuji@58 579 yahtml-last-begend))
yuuji@57 580 (setq cmd yahtml-last-begend)
yuuji@60 581 (if yahtml-prefer-upcases (setq cmd (upcase cmd)))
yuuji@57 582 (if region
yuuji@57 583 (let ((beg (region-beginning))
yuuji@57 584 (end (region-end))
yuuji@57 585 (addin (yahtml-addin cmd)))
yuuji@57 586 (goto-char end)
yuuji@57 587 (insert (format "</%s>%s" cmd (if bolp "\n" "")))
yuuji@57 588 (goto-char beg)
yuuji@57 589 (insert (format "<%s%s>%s" cmd addin (if bolp "\n" ""))))
yuuji@58 590 (insert (format "<%s%s>" cmd (yahtml-addin cmd)))
yuuji@58 591 (save-excursion
yuuji@60 592 (insert "\n")
yuuji@60 593 (indent-to-column cc)
yuuji@60 594 (insert (format "</%s>" cmd)))
yuuji@64 595 (if (string-match "^a\\|p$" cmd) ;aとp決め打ちってのが美しくない…
yuuji@64 596 (newline)
yuuji@64 597 (yahtml-intelligent-newline nil))
yuuji@64 598 (yahtml-indent-line))))
yuuji@57 599
yuuji@57 600 (defun yahtml-insert-begend-region ()
yuuji@57 601 "Call yahtml-insert-begend in the region mode."
yuuji@57 602 (interactive)
yuuji@57 603 (yahtml-insert-begend t))
yuuji@57 604
yuuji@57 605
yuuji@54 606 (defun yahtml-insert-form (&optional form)
yuuji@57 607 "Insert <FORM option=\"argument\">."
yuuji@54 608 (interactive)
yuuji@54 609 (or form
yuuji@60 610 (let ((completion-ignore-case t))
yuuji@60 611 (setq form
yuuji@60 612 (YaTeX-cplread-with-learning
yuuji@64 613 (format "Form(default %s): " yahtml-last-form)
yuuji@60 614 'yahtml-form-table 'yahtml-user-form-table
yuuji@60 615 'yahtml-tmp-form-table))))
yuuji@57 616 (let ((p (point)) q)
yuuji@64 617 (if (string= form "") (setq form yahtml-last-form))
yuuji@64 618 (setq yahtml-last-form form)
yuuji@60 619 (if yahtml-prefer-upcases (setq form (upcase form)))
yuuji@58 620 (insert (format "<%s%s>" form (yahtml-addin form)))
yuuji@57 621 ;;(indent-relative-maybe)
yuuji@57 622 (if (cdr (assoc form yahtml-form-table))
yuuji@57 623 (save-excursion (insert (format "</%s>" form))))
yuuji@54 624 (if (search-backward "\"\"" p t) (forward-char 1))))
yuuji@54 625
yuuji@59 626 ;;; ---------- Add-in ----------
yuuji@54 627 (defun yahtml-addin (form)
yuuji@54 628 "Check add-in function's existence and call it if exists."
yuuji@58 629 (let ((addin (concat "yahtml:" (downcase form))) s)
yuuji@58 630 (if (and (intern-soft addin) (fboundp (intern-soft addin))
yuuji@58 631 (stringp (setq s (funcall (intern addin))))
yuuji@58 632 (string< "" s))
yuuji@64 633 (if (eq (aref s 0) ? ) s (concat " " s))
yuuji@54 634 "")))
yuuji@54 635
yuuji@59 636
yuuji@59 637 (defvar yahtml-completing-buffer nil)
yuuji@59 638 (defun yahtml-collect-labels (&optional file)
yuuji@59 639 "Collect current buffers label (<a name=...>).
yuuji@59 640 If optional argument FILE is specified collect labels in FILE."
yuuji@60 641 (let (list bound)
yuuji@59 642 (save-excursion
yuuji@59 643 (set-buffer yahtml-completing-buffer)
yuuji@60 644 (if file (let (hilit-auto-highlight)
yuuji@60 645 (set-buffer (find-file-noselect file))))
yuuji@59 646 (save-excursion
yuuji@59 647 (goto-char (point-min))
yuuji@59 648 (while (re-search-forward "<a\\b" nil t)
yuuji@60 649 (setq bound (match-end 0))
yuuji@60 650 (search-forward ">" nil t)
yuuji@60 651 (if (and (re-search-backward "\\(name\\|id\\)=" bound t)
yuuji@64 652 (progn
yuuji@64 653 (goto-char (match-end 0))
yuuji@64 654 (skip-chars-forward " \t\n")
yuuji@64 655 (looking-at "\"?#?\\([^\">]+\\)\"?\\b")))
yuuji@59 656 (setq list (cons
yuuji@59 657 (list (concat "#" (YaTeX-match-string 1)))
yuuji@59 658 list))))
yuuji@59 659 list)))
yuuji@59 660 )
yuuji@59 661
yuuji@58 662 (defvar yahtml-url-completion-map nil "Key map used in URL completion buffer")
yuuji@58 663 (if yahtml-url-completion-map nil
yuuji@58 664 (setq yahtml-url-completion-map
yuuji@58 665 (copy-keymap minibuffer-local-completion-map))
yuuji@58 666 (define-key yahtml-url-completion-map "\t" 'yahtml-complete-url)
yuuji@58 667 (define-key yahtml-url-completion-map " " 'yahtml-complete-url)
yuuji@58 668 )
yuuji@58 669
yuuji@58 670 (defun yahtml-complete-url ()
yuuji@58 671 "Complete external URL from history or local file name."
yuuji@58 672 (interactive)
yuuji@64 673 (let ((p (point)) initial i2 cmpl path dir file listfunc beg labels)
yuuji@58 674 (setq initial (buffer-string))
yuuji@58 675 (cond
yuuji@58 676 ((string-match "^http:" initial)
yuuji@58 677 (setq cmpl (try-completion initial yahtml-urls)
yuuji@58 678 listfunc (list 'lambda nil
yuuji@58 679 (list 'all-completions initial 'yahtml-urls))
yuuji@58 680 beg (point-min)))
yuuji@59 681 ((setq beg (string-match "#" initial))
yuuji@59 682 (or (equal beg 0) ;begin with #
yuuji@59 683 (progn
yuuji@59 684 (setq path (substring initial 0 beg))
yuuji@59 685 (if (string-match "^/" path)
yuuji@59 686 (setq path (yahtml-url-to-path path)))))
yuuji@59 687 (setq initial (substring initial beg))
yuuji@59 688 (setq labels (yahtml-collect-labels path)
yuuji@59 689 cmpl (try-completion initial labels)
yuuji@59 690 listfunc (list 'lambda ()
yuuji@59 691 (list 'all-completions
yuuji@59 692 initial (list 'quote labels)))
yuuji@59 693 beg (+ (point-min) beg)))
yuuji@58 694 (t
yuuji@58 695 (setq path (if (string-match "^/" initial)
yuuji@64 696 (or (yahtml-url-to-path initial) initial)
yuuji@58 697 initial))
yuuji@58 698 (setq dir (or (file-name-directory path) ".")
yuuji@58 699 file (file-name-nondirectory path)
yuuji@58 700 initial file
yuuji@58 701 cmpl (file-name-completion file dir)
yuuji@58 702 listfunc (list 'lambda nil
yuuji@58 703 (list 'file-name-all-completions
yuuji@58 704 file dir))
yuuji@58 705 beg (save-excursion (skip-chars-backward "^/") (point)))))
yuuji@58 706 (cond
yuuji@58 707 ((stringp cmpl)
yuuji@58 708 (if (string= initial cmpl)
yuuji@58 709 (with-output-to-temp-buffer "*Completions*"
yuuji@58 710 (princ "Possible completinos are:\n")
yuuji@58 711 (princ
yuuji@58 712 (mapconcat '(lambda (x) x) (funcall listfunc) "\n")))
yuuji@58 713 (delete-region (point) beg)
yuuji@58 714 (insert cmpl)))
yuuji@58 715 ((null cmpl)
yuuji@58 716 (ding))
yuuji@58 717 ((eq t cmpl)
yuuji@58 718 (save-excursion
yuuji@58 719 (unwind-protect
yuuji@58 720 (progn
yuuji@58 721 (goto-char p)
yuuji@58 722 (insert " [Sole completion]"))
yuuji@58 723 (delete-region p (point-max))))))))
yuuji@58 724
yuuji@57 725 (defun yahtml:a ()
yuuji@54 726 "Add-in function for <a>"
yuuji@64 727 (let ((href ""))
yuuji@64 728 (setq yahtml-completing-buffer (current-buffer)
yuuji@64 729 href (read-from-minibuffer "href: " "" yahtml-url-completion-map)
yuuji@64 730 ;; yahtml-urls-local is buffer-local, so we must put
yuuji@64 731 ;; that into yahtml-urls here
yuuji@64 732 yahtml-urls (append yahtml-urls-private yahtml-urls-local))
yuuji@64 733 (prog1
yuuji@64 734 (concat (yahtml-make-optional-argument
yuuji@64 735 "href" href)
yuuji@64 736 (yahtml-make-optional-argument
yuuji@64 737 "name" (read-string "name: ")))
yuuji@64 738 (if (and (string-match "^http://" href)
yuuji@64 739 (null (assoc href yahtml-urls)))
yuuji@64 740 (YaTeX-update-table
yuuji@64 741 (list href)
yuuji@64 742 'yahtml-urls-private 'yahtml-urls-private 'yahtml-urls-local))
yuuji@64 743 )))
yuuji@57 744
yuuji@60 745 (defvar yahtml-parameters-completion-alist
yuuji@61 746 '(("align" ("top") ("middle") ("bottom") ("left") ("right") ("center"))
yuuji@60 747 ("src" . file)
yuuji@60 748 ("method" ("POST") ("GET"))))
yuuji@60 749
yuuji@60 750 (defun yahtml-read-parameter (par)
yuuji@60 751 (let* ((alist (cdr-safe (assoc (downcase par)
yuuji@60 752 yahtml-parameters-completion-alist)))
yuuji@60 753 (prompt (concat par ": "))
yuuji@60 754 v)
yuuji@60 755 (cond
yuuji@60 756 ((eq alist 'file)
yuuji@60 757 (read-file-name prompt "" nil nil ""))
yuuji@60 758 (alist
yuuji@60 759 (completing-read prompt alist))
yuuji@60 760 (t
yuuji@60 761 (read-string prompt)))))
yuuji@60 762
yuuji@64 763 (defun yahtml-make-optional-argument (opt arg)
yuuji@64 764 "Make optional argument string."
yuuji@64 765 (if (string= "" arg)
yuuji@64 766 ""
yuuji@64 767 (concat " " (if yahtml-prefer-upcases (upcase opt) (downcase opt))
yuuji@64 768 "=\"" arg "\"")))
yuuji@64 769
yuuji@64 770 (defun yahtml:body ()
yuuji@64 771 "Add-in function for <body>"
yuuji@64 772 (let ((b (read-string "bgcolor="))
yuuji@64 773 (x (read-string "text color="))
yuuji@64 774 (l (read-string "link color="))
yuuji@64 775 (v (read-string "vlink color=")))
yuuji@64 776 (concat
yuuji@64 777 (yahtml-make-optional-argument "bgcolor" b)
yuuji@64 778 (yahtml-make-optional-argument "text" x)
yuuji@64 779 (yahtml-make-optional-argument "link" l)
yuuji@64 780 (yahtml-make-optional-argument "vlink" v))))
yuuji@64 781
yuuji@64 782
yuuji@57 783 (defun yahtml:img ()
yuuji@57 784 "Add-in function for <img>"
yuuji@60 785 (let ((src (yahtml-read-parameter "src"))
yuuji@60 786 (alg (yahtml-read-parameter "align"))
yuuji@60 787 (alt (yahtml-read-parameter "alt"))
yuuji@64 788 (brd (read-string "border="))
yuuji@60 789 (l yahtml-prefer-upcases))
yuuji@60 790 (concat (if l "SRC" "src") "=\"" src "\""
yuuji@64 791 (yahtml-make-optional-argument "align" alg)
yuuji@64 792 (yahtml-make-optional-argument "alt" alt)
yuuji@64 793 (yahtml-make-optional-argument "border" brd))))
yuuji@57 794
yuuji@57 795 (defun yahtml:form ()
yuuji@57 796 "Add-in function `form' input format"
yuuji@57 797 (concat
yuuji@60 798 " " (if yahtml-prefer-upcases "METHOD" "method=")
yuuji@60 799 (completing-read "Method: " '(("POST") ("GET")) nil t)
yuuji@60 800 " " (if yahtml-prefer-upcases "ACTION" "action") "=\""
yuuji@60 801 (read-string "Action: ") "\""
yuuji@57 802 ))
yuuji@57 803
yuuji@57 804 (defun yahtml:select ()
yuuji@57 805 "Add-in function for `select' input format"
yuuji@57 806 (setq yahtml-last-single-cmd "option")
yuuji@60 807 (concat " " (if yahtml-prefer-upcases "NAME" "name") "=\""
yuuji@60 808 (read-string "name: ") "\""))
yuuji@57 809
yuuji@58 810 (defun yahtml:ol ()
yuuji@58 811 (setq yahtml-last-single-cmd "li") "")
yuuji@58 812 (defun yahtml:ul ()
yuuji@58 813 (setq yahtml-last-single-cmd "li") "")
yuuji@58 814 (defun yahtml:dl ()
yuuji@58 815 (setq yahtml-last-single-cmd "dt") "")
yuuji@58 816 (defun yahtml:dt ()
yuuji@58 817 (setq yahtml-last-single-cmd "dd") "")
yuuji@58 818
yuuji@61 819 (defun yahtml:p ()
yuuji@61 820 (let ((alg (yahtml-read-parameter "align")))
yuuji@64 821 (yahtml-make-optional-argument "align" alg)
yuuji@64 822 ))
yuuji@58 823
yuuji@57 824 (defvar yahtml-input-types
yuuji@57 825 '(("text") ("password") ("checkbox") ("radio") ("submit")
yuuji@60 826 ("reset") ("image") ("hidden") ("file")))
yuuji@57 827
yuuji@57 828 (defun yahtml:input ()
yuuji@57 829 "Add-in function for `input' form"
yuuji@60 830 (let ((size "") name type value checked (maxlength "")
yuuji@60 831 (l yahtml-prefer-upcases))
yuuji@57 832 (setq name (read-string "name: ")
yuuji@57 833 type (completing-read "type (default=text): "
yuuji@57 834 yahtml-input-types nil t)
yuuji@57 835 value (read-string "value: "))
yuuji@57 836 (if (string-match "text\\|password\\|^$" type)
yuuji@57 837 (setq size (read-string "size: ")
yuuji@57 838 maxlength (read-string "maxlength: ")))
yuuji@57 839 (concat
yuuji@60 840 (if l "NAME" "name") "=\"" name "\""
yuuji@64 841 (yahtml-make-optional-argument "type" type)
yuuji@64 842 (yahtml-make-optional-argument "value" value)
yuuji@64 843 (yahtml-make-optional-argument "size" size)
yuuji@64 844 (yahtml-make-optional-argument "maxlength" maxlength)
yuuji@57 845 )))
yuuji@59 846
yuuji@59 847 (defun yahtml:textarea ()
yuuji@59 848 "Add-in function for `textarea'"
yuuji@59 849 (interactive)
yuuji@59 850 (let (name rows cols)
yuuji@59 851 (setq name (read-string "Name: ")
yuuji@60 852 cols (read-string "Columns: ")
yuuji@60 853 rows (read-string "Rows: "))
yuuji@59 854 (concat
yuuji@59 855 (concat (if yahtml-prefer-upcases "NAME=" "name=")
yuuji@59 856 "\"" name "\"")
yuuji@64 857 (yahtml-make-optional-argument "cols" cols)
yuuji@64 858 (yahtml-make-optional-argument "rows" rows))))
yuuji@59 859
yuuji@64 860 (defun yahtml:table ()
yuuji@64 861 "Add-in function for `table'"
yuuji@64 862 (yahtml-make-optional-argument "border" (read-string "border=")))
yuuji@64 863
yuuji@64 864 (defun yahtml:font ()
yuuji@64 865 "Add-in function for `font'"
yuuji@64 866 (yahtml-make-optional-argument "color" (read-string "color=")))
yuuji@59 867
yuuji@59 868 ;;; ---------- Simple tag ----------
yuuji@58 869 (defun yahtml-insert-tag (region-mode &optional tag)
yuuji@54 870 "Insert <TAG> </TAG> and put cursor inside of them."
yuuji@58 871 (interactive "P")
yuuji@58 872 (or tag
yuuji@60 873 (let ((completion-ignore-case t))
yuuji@60 874 (setq tag
yuuji@60 875 (YaTeX-cplread-with-learning
yuuji@64 876 (format "Tag %s(default %s): "
yuuji@60 877 (if region-mode "region: " "") yahtml-last-typeface-cmd)
yuuji@60 878 'yahtml-typeface-table 'yahtml-user-typeface-table
yuuji@60 879 'yahtml-tmp-typeface-table))))
yuuji@58 880 (if (string= "" tag) (setq tag yahtml-last-typeface-cmd))
yuuji@60 881 (setq tag (or (cdr (assoc tag yahtml-typeface-table)) tag))
yuuji@60 882 (setq yahtml-last-typeface-cmd tag
yuuji@60 883 tag (funcall (if yahtml-prefer-upcases 'upcase 'downcase) tag))
yuuji@58 884 (if region-mode
yuuji@58 885 (if (if (string< "19" emacs-version) (mark t) (mark))
yuuji@58 886 (save-excursion
yuuji@58 887 (if (> (point) (mark)) (exchange-point-and-mark))
yuuji@60 888 (insert (format "<%s%s>" tag (yahtml-addin tag)))
yuuji@58 889 (exchange-point-and-mark)
yuuji@58 890 (insert "</" tag ">"))
yuuji@58 891 (message "No mark set now"))
yuuji@60 892 (insert (format "<%s%s>" tag (yahtml-addin tag)))
yuuji@58 893 (save-excursion (insert (format "</%s>" tag)))))
yuuji@54 894
yuuji@61 895 (defun yahtml-insert-tag-region (&optional tag)
yuuji@61 896 "Call yahtml-insert-tag with region mode."
yuuji@61 897 (interactive)
yuuji@61 898 (yahtml-insert-tag t tag))
yuuji@61 899
yuuji@64 900
yuuji@57 901 (defun yahtml-insert-single (cmd)
yuuji@57 902 "Insert <CMD>."
yuuji@57 903 (interactive
yuuji@58 904 (list
yuuji@58 905 (let ((completion-ignore-case t))
yuuji@58 906 (YaTeX-cplread-with-learning
yuuji@58 907 (format "Command%s: "
yuuji@58 908 (if yahtml-last-single-cmd
yuuji@58 909 (concat "(default " yahtml-last-single-cmd ")") ""))
yuuji@58 910 'yahtml-single-cmd-table 'yahtml-user-single-cmd-table
yuuji@58 911 'yahtml-tmp-single-cmd-table))))
yuuji@60 912 (if (string= "" cmd) (setq cmd yahtml-last-single-cmd))
yuuji@58 913 (setq yahtml-last-single-cmd
yuuji@60 914 (or (cdr (assoc cmd yahtml-single-cmd-table)) cmd))
yuuji@60 915 (setq cmd (funcall (if yahtml-prefer-upcases 'upcase 'downcase)
yuuji@60 916 yahtml-last-single-cmd))
yuuji@60 917 (insert (format "<%s>" cmd)))
yuuji@57 918
yuuji@64 919 (defun yahtml-insert-p (&optional arg)
yuuji@64 920 "Convenient function to insert <p></p>"
yuuji@64 921 (interactive "P")
yuuji@64 922 (if arg (yahtml-insert-tag nil "p")
yuuji@64 923 (insert "<p>")
yuuji@64 924 (save-excursion
yuuji@64 925 (insert "</p>"))))
yuuji@64 926
yuuji@57 927 ;;; ---------- Jump ----------
yuuji@57 928 (defun yahtml-on-href-p ()
yuuji@57 929 "Check if point is on href clause."
yuuji@60 930 (let ((p (point)) e cmd (case-fold-search t))
yuuji@57 931 (save-excursion
yuuji@60 932 (and (string= (YaTeX-inner-environment t) "a")
yuuji@60 933 (save-excursion
yuuji@60 934 (search-forward "</a>" nil t)
yuuji@60 935 (setq e (point)))
yuuji@60 936 (goto-char (get 'YaTeX-inner-environment 'point))
yuuji@60 937 (search-forward "href" e t)
yuuji@60 938 (search-forward "=" e t)
yuuji@64 939 (progn
yuuji@64 940 (skip-chars-forward " \t\n")
yuuji@64 941 (looking-at "\"?\\([^\"> \t\n]+\\)\"?"))
yuuji@57 942 (< p (match-end 0))
yuuji@60 943 (YaTeX-match-string 1)
yuuji@60 944 ))))
yuuji@57 945
yuuji@58 946 (defun yahtml-netscape-sentinel (proc mes)
yuuji@58 947 (cond
yuuji@58 948 ((null (buffer-name (process-buffer proc)))
yuuji@58 949 (set-process-buffer proc nil))
yuuji@58 950 ((eq (process-status proc) 'exit)
yuuji@58 951 (let ((cb (current-buffer)))
yuuji@58 952 (set-buffer (process-buffer proc))
yuuji@58 953 (goto-char (point-min))
yuuji@58 954 (if (search-forward "not running" nil t)
yuuji@58 955 (progn
yuuji@58 956 (message "Starting netscape...")
yuuji@58 957 (start-process
yuuji@60 958 "browser" (process-buffer proc)
yuuji@60 959 shell-file-name yahtml-shell-command-option
yuuji@60 960 (format "%s \"%s\"" yahtml-www-browser
yuuji@58 961 (get 'yahtml-netscape-sentinel 'url)))
yuuji@58 962 (message "Starting netscape...Done")))
yuuji@58 963 (set-buffer cb)))))
yuuji@58 964
yuuji@58 965 (defvar yahtml-browser-process nil)
yuuji@58 966
yuuji@58 967 (defun yahtml-browse-html (href)
yuuji@58 968 "Call WWW Browser to see HREF."
yuuji@58 969 (let ((pb "* WWW Browser *") (cb (current-buffer)))
yuuji@58 970 (cond
yuuji@64 971 ((string-match "^start\\>" yahtml-www-browser)
yuuji@64 972 (if (get-buffer pb)
yuuji@64 973 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
yuuji@64 974 (put 'yahtml-netscape-sentinel 'url href)
yuuji@64 975 (set-process-sentinel
yuuji@64 976 (setq yahtml-browser-process
yuuji@64 977 (start-process
yuuji@64 978 "browser" pb shell-file-name yahtml-shell-command-option
yuuji@64 979 (format "%s \"%s\"" yahtml-www-browser href)))
yuuji@64 980 'yahtml-netscape-sentinel))
yuuji@60 981 ((and (string-match "[Nn]etscape" yahtml-www-browser)
yuuji@60 982 (not (eq system-type 'windows-nt)))
yuuji@58 983 (if (get-buffer pb)
yuuji@58 984 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
yuuji@58 985 (put 'yahtml-netscape-sentinel 'url href)
yuuji@58 986 (set-process-sentinel
yuuji@58 987 (setq yahtml-browser-process
yuuji@58 988 (start-process
yuuji@60 989 "browser" pb shell-file-name yahtml-shell-command-option ;"-c"
yuuji@60 990 (format "%s -remote \"openURL(%s)\"" yahtml-www-browser href)))
yuuji@58 991 'yahtml-netscape-sentinel))
yuuji@58 992 ((and (string= "w3" yahtml-www-browser) (fboundp 'w3-fetch))
yuuji@58 993 (w3-fetch href))
yuuji@58 994 ((stringp yahtml-www-browser)
yuuji@60 995 (if (and yahtml-browser-process
yuuji@60 996 (eq (process-status yahtml-browser-process) 'run))
yuuji@58 997 (message "%s is already running" yahtml-www-browser)
yuuji@58 998 (setq yahtml-browser-process
yuuji@58 999 (start-process
yuuji@60 1000 "browser" "* WWW Browser *"
yuuji@60 1001 shell-file-name yahtml-shell-command-option
yuuji@60 1002 (format "%s \"%s\"" yahtml-www-browser href)))))
yuuji@58 1003 (t
yuuji@58 1004 (message "Sorry, jump across http is not supported.")))))
yuuji@58 1005
yuuji@57 1006 (defun yahtml-goto-corresponding-href (&optional other)
yuuji@57 1007 "Go to corresponding name."
yuuji@64 1008 (let ((href (yahtml-on-href-p)) file name (parent buffer-file-name))
yuuji@57 1009 (if href
yuuji@57 1010 (cond
yuuji@60 1011 ((string-match "^\\(ht\\|f\\)tp:" href)
yuuji@58 1012 (yahtml-browse-html href))
yuuji@57 1013 (t (setq file (substring href 0 (string-match "#" href)))
yuuji@57 1014 (if (string-match "#" href)
yuuji@57 1015 (setq name (substring href (1+ (string-match "#" href)))))
yuuji@57 1016 (if (string< "" file)
yuuji@57 1017 (progn
yuuji@57 1018 (if (string-match "/$" file)
yuuji@58 1019 (setq file (concat file yahtml-directory-index)))
yuuji@58 1020 (if (string-match "^/" file)
yuuji@58 1021 (setq file (yahtml-url-to-path file)))
yuuji@57 1022 (if other (YaTeX-switch-to-buffer-other-window file)
yuuji@64 1023 (YaTeX-switch-to-buffer file))
yuuji@64 1024 (or YaTeX-parent-file (setq YaTeX-parent-file parent))))
yuuji@57 1025 (if name
yuuji@57 1026 (progn (set-mark-command nil) (yahtml-jump-to-name name)))
yuuji@57 1027 t)))))
yuuji@57 1028
yuuji@57 1029 (defun yahtml-jump-to-name (name)
yuuji@57 1030 "Jump to html's named tag."
yuuji@57 1031 (setq name (format "name\\s *=\\s *\"?%s\"?" name))
yuuji@57 1032 (or (and (re-search-forward name nil t) (goto-char (match-beginning 0)))
yuuji@57 1033 (and (re-search-backward name nil t) (goto-char (match-beginning 0)))
yuuji@57 1034 (message "Named tag `%s' not found" (substring href 1))))
yuuji@57 1035
yuuji@57 1036 (defun yahtml-on-begend-p (&optional p)
yuuji@57 1037 "Check if point is on begend clause."
yuuji@60 1038 (let ((p (or p (point))) cmd (case-fold-search t))
yuuji@57 1039 (save-excursion
yuuji@60 1040 (goto-char p)
yuuji@58 1041 (if (equal (char-after (point)) ?<) (forward-char 1))
yuuji@57 1042 (if (and (re-search-backward "<" nil t)
yuuji@57 1043 (looking-at
yuuji@60 1044 (concat "<\\(/?" yahtml-struct-name-regexp "\\)\\b"))
yuuji@57 1045 (condition-case nil
yuuji@58 1046 (forward-list 1)
yuuji@58 1047 (error nil))
yuuji@57 1048 (< p (point)))
yuuji@57 1049 (YaTeX-match-string 1)))))
yuuji@57 1050
yuuji@58 1051 (defun yahtml-goto-corresponding-begend (&optional noerr)
yuuji@58 1052 "Go to corresponding opening/closing tag.
yuuji@58 1053 Optional argument NOERR causes no error for unballanced tag."
yuuji@58 1054 (let ((cmd (yahtml-on-begend-p)) m0
yuuji@58 1055 (p (point)) (case-fold-search t) func str (nest 0))
yuuji@58 1056 (cond
yuuji@58 1057 (cmd
yuuji@58 1058 (setq m0 (match-beginning 0))
yuuji@58 1059 (if (= (aref cmd 0) ?/) ;on </cmd> line
yuuji@58 1060 (setq cmd (substring cmd 1)
yuuji@58 1061 str (format "\\(<%s\\)\\|\\(</%s\\)" cmd cmd)
yuuji@58 1062 func 're-search-backward)
yuuji@58 1063 (setq str (format "\\(</%s\\)\\|\\(<%s\\)" cmd cmd)
yuuji@58 1064 func 're-search-forward))
yuuji@58 1065 (while (and (>= nest 0) (funcall func str nil t))
yuuji@58 1066 (if (equal m0 (match-beginning 0))
yuuji@58 1067 nil
yuuji@58 1068 (setq nest (+ nest (if (match-beginning 1) -1 1)))))
yuuji@58 1069 (if (< nest 0)
yuuji@58 1070 (goto-char (match-beginning 0))
yuuji@58 1071 (funcall
yuuji@58 1072 (if noerr 'message 'error)
yuuji@58 1073 "Corresponding tag of `%s' not found." cmd)
yuuji@58 1074 (goto-char p)
yuuji@58 1075 nil))
yuuji@58 1076 (t nil))))
yuuji@58 1077
yuuji@58 1078 (defun yahtml-current-tag ()
yuuji@58 1079 "Return the current tag name."
yuuji@58 1080 (save-excursion
yuuji@58 1081 (let ((p (point)) b tag)
yuuji@58 1082 (or (bobp)
yuuji@58 1083 (looking-at "<")
yuuji@58 1084 (progn (skip-chars-backward "^<") (forward-char -1)))
yuuji@58 1085 (setq b (point))
yuuji@58 1086 (skip-chars-forward "<")
yuuji@58 1087 (setq tag (buffer-substring
yuuji@58 1088 (point) (progn (skip-chars-forward "^ \t\n") (point))))
yuuji@58 1089 (goto-char b)
yuuji@58 1090 (forward-list 1)
yuuji@58 1091 (and (< p (point)) tag))))
yuuji@58 1092
yuuji@58 1093
yuuji@58 1094 (defun yahtml-goto-corresponding-img ()
yuuji@58 1095 "View image on point"
yuuji@58 1096 (let ((tag (yahtml-current-tag)) image (p (point)) (case-fold-search t))
yuuji@58 1097 (if (and tag
yuuji@58 1098 (string-match "img" tag)
yuuji@58 1099 (save-excursion
yuuji@58 1100 (re-search-backward "<\\s *img" nil t)
yuuji@59 1101 (re-search-forward "src=\"?\\([^\"> ]+\\)\"?")
yuuji@58 1102 (match-beginning 1)
yuuji@58 1103 (setq image
yuuji@58 1104 (buffer-substring (match-beginning 1) (match-end 1)))))
yuuji@58 1105 (progn
yuuji@58 1106 (message "Invoking %s %s..." yahtml-image-viewer image)
yuuji@58 1107 (start-process
yuuji@60 1108 "Viewer" " * Image Viewer *"
yuuji@60 1109 shell-file-name yahtml-shell-command-option ;"-c"
yuuji@58 1110 (concat yahtml-image-viewer " " image))
yuuji@58 1111 (message "Invoking %s %s...Done" yahtml-image-viewer image)))))
yuuji@57 1112
yuuji@57 1113 (defun yahtml-goto-corresponding-* (&optional other)
yuuji@57 1114 "Go to corresponding object."
yuuji@57 1115 (interactive)
yuuji@57 1116 (cond
yuuji@57 1117 ((yahtml-goto-corresponding-href other))
yuuji@58 1118 ((yahtml-goto-corresponding-img))
yuuji@58 1119 ((yahtml-goto-corresponding-begend))
yuuji@64 1120 (t (message "I don't know where to go."))
yuuji@57 1121 ))
yuuji@57 1122
yuuji@57 1123 (defun yahtml-goto-corresponding-*-other-window ()
yuuji@57 1124 "Go to corresponding object."
yuuji@57 1125 (interactive)
yuuji@57 1126 (yahtml-goto-corresponding-* t))
yuuji@57 1127
yuuji@64 1128 (defun yahtml-visit-main ()
yuuji@64 1129 "Go to parent file from where you visit current file."
yuuji@64 1130 (interactive)
yuuji@64 1131 (if YaTeX-parent-file (YaTeX-switch-to-buffer YaTeX-parent-file)))
yuuji@64 1132
yuuji@58 1133 ;;; ---------- killing ----------
yuuji@58 1134 (defun yahtml-kill-begend (&optional whole)
yuuji@64 1135 (let ((tag (yahtml-on-begend-p)) p q r)
yuuji@58 1136 (if tag
yuuji@64 1137 (save-excursion
yuuji@58 1138 (or (looking-at "<")
yuuji@58 1139 (progn (skip-chars-backward "^<") (forward-char -1)))
yuuji@64 1140 (setq p (point))
yuuji@58 1141 (yahtml-goto-corresponding-begend)
yuuji@58 1142 (or (looking-at "<")
yuuji@58 1143 (progn (skip-chars-backward "^<") (forward-char -1)))
yuuji@64 1144 (if (< (point) p) ;if on the opening tag
yuuji@64 1145 (progn (setq q p p (point))
yuuji@64 1146 (goto-char q))
yuuji@64 1147 (setq q (point))) ;now q has end-line's (point)
yuuji@64 1148 (if (not whole)
yuuji@64 1149 (kill-region
yuuji@64 1150 (progn (skip-chars-backward " \t") (if (bolp) (point) q))
yuuji@64 1151 (progn (forward-list 1)
yuuji@64 1152 (setq r (point))
yuuji@64 1153 (skip-chars-forward " \t")
yuuji@64 1154 (if (and (eolp) (not (eobp))) (1+ (point)) r))))
yuuji@58 1155 (goto-char p)
yuuji@64 1156 (skip-chars-backward " \t")
yuuji@64 1157 (if (not whole)
yuuji@64 1158 (progn
yuuji@64 1159 (kill-append
yuuji@64 1160 (buffer-substring
yuuji@64 1161 (setq p (if (bolp) (point) p))
yuuji@64 1162 (setq q (progn
yuuji@64 1163 (forward-list 1)
yuuji@64 1164 (setq r (point))
yuuji@64 1165 (skip-chars-forward " \t")
yuuji@64 1166 (if (and (eolp) (not (eobp))) (1+ (point)) r))))
yuuji@64 1167 t)
yuuji@64 1168 (delete-region p q))
yuuji@64 1169 (kill-region
yuuji@64 1170 (if (bolp) (point) p)
yuuji@64 1171 (progn (goto-char q)
yuuji@64 1172 (forward-list 1)
yuuji@64 1173 (setq r (point))
yuuji@64 1174 (skip-chars-forward " \t")
yuuji@64 1175 (if (and (eolp) (not (eobp))) (1+ (point)) r))))
yuuji@58 1176 tag))))
yuuji@58 1177
yuuji@58 1178 (defun yahtml-kill-* (whole)
yuuji@58 1179 "Kill current position's HTML tag (set)."
yuuji@58 1180 (interactive "P")
yuuji@58 1181 (cond
yuuji@58 1182 ((yahtml-kill-begend whole))
yuuji@58 1183 ))
yuuji@58 1184
yuuji@58 1185
yuuji@58 1186 ;;; ---------- changing ----------
yuuji@60 1187 (defun yahtml-on-assignment-p ()
yuuji@60 1188 "Return if current point is on parameter assignment.
yuuji@60 1189 If so, return parameter name, otherwise nil.
yuuji@60 1190 This function should be able to treat white spaces in value, but not yet."
yuuji@60 1191 (let ((p (point)))
yuuji@60 1192 (save-excursion
yuuji@60 1193 (put 'yahtml-on-assignment-p 'region nil)
yuuji@60 1194 (skip-chars-backward "^ \t")
yuuji@60 1195 (and (looking-at "\\([A-Za-z0-9]+\\)\\s *=\\s *\"?\\([^ \t\"]+\\)\"?")
yuuji@60 1196 (< p (match-end 0))
yuuji@60 1197 (>= p (1- (match-beginning 2)))
yuuji@60 1198 (put 'yahtml-on-assignment-p 'region
yuuji@60 1199 (cons (match-beginning 2) (match-end 2)))
yuuji@60 1200 (YaTeX-match-string 1)))))
yuuji@60 1201
yuuji@58 1202 (defun yahtml-change-begend ()
yuuji@58 1203 (let ((tag (yahtml-on-begend-p))
yuuji@58 1204 (completion-ignore-case t)
yuuji@60 1205 (case-fold-search t)
yuuji@58 1206 (p (point)) (q (make-marker))
yuuji@58 1207 (default (append yahtml-env-table yahtml-typeface-table))
yuuji@58 1208 (user (append yahtml-user-env-table yahtml-user-typeface-table))
yuuji@58 1209 (tmp (append yahtml-tmp-env-table yahtml-tmp-typeface-table))
yuuji@59 1210 href b1 e1)
yuuji@59 1211 (cond
yuuji@59 1212 (tag
yuuji@59 1213 (cond
yuuji@60 1214 ((and (string-match "^a$" tag)
yuuji@59 1215 (save-excursion
yuuji@59 1216 (and
yuuji@60 1217 (re-search-backward "<a\\b" nil t)
yuuji@64 1218 (progn
yuuji@64 1219 (goto-char (match-end 0))
yuuji@64 1220 (skip-chars-forward " \t\n")
yuuji@64 1221 (setq b1 (point))
yuuji@64 1222 (search-forward ">" nil t))
yuuji@60 1223 (setq e1 (match-beginning 0))
yuuji@60 1224 (goto-char b1)
yuuji@60 1225 (re-search-forward "href\\s *=" e1 t)
yuuji@59 1226 (>= p (point))
yuuji@64 1227 (progn
yuuji@64 1228 (goto-char (match-end 0))
yuuji@64 1229 (skip-chars-forward " \t\n")
yuuji@64 1230 (looking-at "\"?\\([^\"> \t\n]+\\)\"?"))
yuuji@59 1231 (< p (match-end 0)))))
yuuji@59 1232 (setq b1 (match-beginning 1) e1 (match-end 1)
yuuji@60 1233 yahtml-completing-buffer (current-buffer)
yuuji@64 1234 ;; yahtml-urls-local is buffer-local, so we must put
yuuji@64 1235 ;; that into yahtml-urls here
yuuji@64 1236 yahtml-urls (append yahtml-urls-private yahtml-urls-local)
yuuji@59 1237 href (read-from-minibuffer
yuuji@59 1238 "Change href to: " "" yahtml-url-completion-map))
yuuji@59 1239 (if (string< "" href)
yuuji@59 1240 (progn
yuuji@60 1241 ;;(setq href ;??
yuuji@60 1242 ;; (if yahtml-prefer-upcases (upcase href) (downcase href)))
yuuji@59 1243 (delete-region b1 e1)
yuuji@59 1244 (goto-char b1)
yuuji@59 1245 (insert href))))
yuuji@59 1246 (t
yuuji@58 1247 (save-excursion
yuuji@58 1248 (if (= (aref tag 0) ?/) (setq tag (substring tag 1)))
yuuji@58 1249 (or (= (char-after (point)) ?<) (skip-chars-backward "^<"))
yuuji@58 1250 (skip-chars-forward "^A-Za-z")
yuuji@58 1251 (set-marker q (point))
yuuji@58 1252 (setq p (point))
yuuji@58 1253 (yahtml-goto-corresponding-begend)
yuuji@58 1254 (or (= (char-after (point)) ?<)
yuuji@58 1255 (skip-chars-backward "^<"))
yuuji@58 1256 (skip-chars-forward "^A-Za-z")
yuuji@58 1257 (if (= (char-after (1- (point))) ?/)
yuuji@58 1258 (progn
yuuji@58 1259 (set-marker q (point))
yuuji@58 1260 (goto-char p)))
yuuji@60 1261 (setq tag (let ((completion-ignore-case t))
yuuji@60 1262 (YaTeX-cplread-with-learning
yuuji@60 1263 (format "Change `%s' to(default %s): "
yuuji@60 1264 tag yahtml-last-begend)
yuuji@60 1265 'default 'user 'tmp)))
yuuji@58 1266 (delete-region (point) (progn (skip-chars-forward "^>") (point)))
yuuji@58 1267 (if (string= "" tag) (setq tag yahtml-last-begend))
yuuji@58 1268 (setq yahtml-last-begend
yuuji@58 1269 (or (cdr (assoc tag yahtml-env-table)) tag)
yuuji@58 1270 tag yahtml-last-begend)
yuuji@60 1271 (setq tag (if yahtml-prefer-upcases (upcase tag) (downcase tag)))
yuuji@58 1272 (insert (format "%s%s" tag (yahtml-addin tag)))
yuuji@58 1273 (goto-char q)
yuuji@58 1274 (delete-region (point) (progn (skip-chars-forward "^>") (point)))
yuuji@60 1275 (insert tag))))
yuuji@60 1276 t))))
yuuji@60 1277
yuuji@60 1278 (defun yahtml-change-command ()
yuuji@60 1279 (let ((p (point)) (case-fold-search t) cmd par new
yuuji@60 1280 (beg (make-marker)) (end (make-marker)))
yuuji@60 1281 (skip-chars-backward "^<")
yuuji@60 1282 (if (and
yuuji@60 1283 (looking-at yahtml-command-regexp)
yuuji@60 1284 (progn
yuuji@60 1285 (set-marker beg (match-beginning 0))
yuuji@60 1286 (set-marker end (match-end 0))
yuuji@60 1287 t) ;for further work
yuuji@60 1288 (progn
yuuji@60 1289 (forward-char -1)
yuuji@60 1290 (condition-case nil
yuuji@60 1291 (forward-list 1)
yuuji@60 1292 (error nil))
yuuji@60 1293 (< p (point))))
yuuji@60 1294 (progn
yuuji@60 1295 (goto-char p)
yuuji@60 1296 (if (setq par (yahtml-on-assignment-p))
yuuji@60 1297 (progn
yuuji@60 1298 (setq new (yahtml-read-parameter par))
yuuji@60 1299 (set-marker beg (car (get 'yahtml-on-assignment-p 'region)))
yuuji@60 1300 (set-marker end (cdr (get 'yahtml-on-assignment-p 'region))))
yuuji@60 1301 (setq new
yuuji@60 1302 (YaTeX-cplread-with-learning
yuuji@60 1303 "Change form to: "
yuuji@60 1304 'yahtml-form-table 'yahtml-user-form-table
yuuji@60 1305 'yahtml-tmp-form-table)))
yuuji@60 1306 (delete-region beg end)
yuuji@60 1307 (goto-char beg)
yuuji@60 1308 (insert new)
yuuji@60 1309 t)
yuuji@60 1310 (goto-char p)
yuuji@60 1311 nil)))
yuuji@58 1312
yuuji@58 1313 (defun yahtml-change-* ()
yuuji@58 1314 "Change current position's HTML tag (set)."
yuuji@58 1315 (interactive)
yuuji@58 1316 (cond
yuuji@58 1317 ((yahtml-change-begend))
yuuji@60 1318 ((yahtml-change-command))
yuuji@58 1319 ))
yuuji@58 1320
yuuji@57 1321 ;;; ---------- commenting ----------
yuuji@64 1322 (defun yahtml-comment-region (&optional uncom)
yuuji@64 1323 "Comment out region or environment."
yuuji@64 1324 (interactive)
yuuji@64 1325 (let (e beg p)
yuuji@64 1326 (cond
yuuji@64 1327 ((setq e (yahtml-on-begend-p))
yuuji@64 1328 (save-excursion
yuuji@64 1329 (setq p (point))
yuuji@64 1330 (if (string-match "^/" e)
yuuji@64 1331 (setq beg (progn (forward-line 1) (point)))
yuuji@64 1332 (setq beg (progn (beginning-of-line) (point))))
yuuji@64 1333 (goto-char p)
yuuji@64 1334 (yahtml-goto-corresponding-begend)
yuuji@64 1335 (if (string-match "^/" e)
yuuji@64 1336 (beginning-of-line)
yuuji@64 1337 (forward-line 1))
yuuji@64 1338 (comment-region beg (point) (if uncom (list 4)))))
yuuji@64 1339 (t (comment-region (region-beginning) (region-end)
yuuji@64 1340 (if uncom (list 4)))))))
yuuji@57 1341
yuuji@64 1342 (defun yahtml-uncomment-region ()
yuuji@64 1343 (interactive)
yuuji@64 1344 (yahtml-comment-region t))
yuuji@57 1345
yuuji@57 1346
yuuji@57 1347
yuuji@60 1348 (defun yahtml-inner-environment-but (exclude &optional quick)
yuuji@60 1349 "Return the inner environment but matches with EXCLUDE tag."
yuuji@64 1350 (let (e (case-fold-search t))
yuuji@60 1351 (save-excursion
yuuji@60 1352 (while (and (setq e (YaTeX-inner-environment quick))
yuuji@60 1353 (string-match exclude e))
yuuji@60 1354 (goto-char (get 'YaTeX-inner-environment 'point))))
yuuji@60 1355 e))
yuuji@60 1356
yuuji@58 1357 ;;; ---------- filling ----------
yuuji@60 1358
yuuji@60 1359 (defvar yahtml-saved-move-to-column (symbol-function 'move-to-column))
yuuji@60 1360 (defun yahtml-move-to-column (col &optional force)
yuuji@60 1361 (beginning-of-line)
yuuji@60 1362 (let ((ccol 0))
yuuji@60 1363 (while (and (> col ccol) (not (eolp)))
yuuji@60 1364 (if (eq (following-char) ?\<)
yuuji@60 1365 (progn
yuuji@60 1366 (while (and (not (eq (following-char) ?\>))
yuuji@60 1367 (not (eolp)))
yuuji@60 1368 (forward-char))
yuuji@60 1369 (or (eolp) (forward-char)))
yuuji@60 1370 (or (eolp) (forward-char))
yuuji@60 1371 (if (eq (preceding-char) ?\t)
yuuji@60 1372 (let ((wd (- 8 (% (+ ccol 8) 8))))
yuuji@60 1373 (if (and force (< col (+ ccol wd)))
yuuji@60 1374 (progn
yuuji@60 1375 (backward-char 1)
yuuji@60 1376 (insert-char ?\ (- col ccol))
yuuji@60 1377 (setq ccol col))
yuuji@60 1378 (setq ccol (+ ccol wd))))
yuuji@60 1379 (setq ccol (1+ ccol)))
yuuji@60 1380 (if (and YaTeX-japan
yuuji@60 1381 (string-match "[chj]" (char-category (preceding-char))))
yuuji@60 1382 (setq ccol (1+ ccol)))))
yuuji@60 1383 (if (and force (> col ccol))
yuuji@60 1384 (progn
yuuji@60 1385 (insert-char ?\ (- col ccol))
yuuji@60 1386 col)
yuuji@60 1387 ccol)))
yuuji@60 1388
yuuji@58 1389 (defun yahtml-fill-paragraph (arg)
yuuji@58 1390 (interactive "P")
yuuji@60 1391 (let*((case-fold-search t) (p (point))
yuuji@61 1392 (e (or (yahtml-inner-environment-but "^\\(a\\|p\\)\\b" t) "html"))
yuuji@60 1393 (prep (string-match "^pre$" e))
yuuji@60 1394 (ps1 (if prep (default-value 'paragraph-start)
yuuji@60 1395 paragraph-start))
yuuji@60 1396 (ps2 (if prep (concat (default-value 'paragraph-start)
yuuji@60 1397 "\\|^\\s *</?pre>")
yuuji@60 1398 paragraph-start)))
yuuji@58 1399 (save-excursion
yuuji@60 1400 (unwind-protect
yuuji@60 1401 (progn
yuuji@60 1402 (if prep
yuuji@60 1403 (fset 'move-to-column 'yahtml-move-to-column))
yuuji@60 1404 (fill-region-as-paragraph
yuuji@60 1405 (progn (re-search-backward paragraph-start nil t)
yuuji@60 1406 (or (save-excursion
yuuji@64 1407 (goto-char (match-beginning 0))
yuuji@64 1408 (if (looking-at "<")
yuuji@64 1409 (forward-list)
yuuji@64 1410 (goto-char (match-end 0))
yuuji@64 1411 (skip-chars-forward " \t>"))
yuuji@60 1412 (if (looking-at "[ \t]*$")
yuuji@60 1413 (progn (forward-line 1) (point))))
yuuji@60 1414 (point)))
yuuji@60 1415 (progn (goto-char p)
yuuji@60 1416 (re-search-forward ps2 nil t)
yuuji@60 1417 (match-beginning 0))))
yuuji@60 1418 (fset 'move-to-column yahtml-saved-move-to-column)))))
yuuji@60 1419
yuuji@60 1420 ;(defun yahtml-indent-new-commnet-line ()
yuuji@60 1421 ; (unwind-protect
yuuji@60 1422 ; (progn
yuuji@60 1423 ; (fset 'move-to-column 'yahtml-move-to-column)
yuuji@60 1424 ; (apply 'YaTeX-saved-indent-new-comment-line (if soft (list soft))))
yuuji@60 1425 ; (fset 'move-to-column yahtml-saved-move-to-column)))
yuuji@58 1426
yuuji@58 1427 ;;;
yuuji@58 1428 ;;; ---------- indentation ----------
yuuji@58 1429 ;;;
yuuji@58 1430 (defun yahtml-indent-line ()
yuuji@64 1431 "Indent a line (faster wrapper)"
yuuji@58 1432 (interactive)
yuuji@64 1433 (let (indent)
yuuji@64 1434 (if (and (save-excursion
yuuji@64 1435 (beginning-of-line) (skip-chars-forward "\t ")
yuuji@64 1436 (not (looking-at "<")))
yuuji@64 1437 (save-excursion
yuuji@64 1438 (forward-line -1)
yuuji@64 1439 (while (and (not (bobp)) (looking-at "^\\s *$"))
yuuji@64 1440 (forward-line -1))
yuuji@64 1441 (skip-chars-forward "\t ")
yuuji@64 1442 (setq indent (current-column))
yuuji@64 1443 (not (looking-at "<"))))
yuuji@64 1444 (progn
yuuji@64 1445 (save-excursion
yuuji@64 1446 (beginning-of-line)
yuuji@64 1447 (skip-chars-forward " \t")
yuuji@64 1448 (or (= (current-column) indent)
yuuji@64 1449 (YaTeX-reindent indent)))
yuuji@64 1450 (and (bolp) (skip-chars-forward " \t")))
yuuji@64 1451 (yahtml-indent-line-real))))
yuuji@64 1452
yuuji@64 1453 (defun yahtml-indent-line-real ()
yuuji@64 1454 (interactive)
yuuji@64 1455 (let ((envs "[uod]l\\|table\\|[ht][rhd0-6]\\|select\\|blockquote\\|center\\|menu\\|dir")
yuuji@64 1456 (itemizing-envs "^\\([uod]l\\|menu\\|dir\\)$")
yuuji@61 1457 (itms "<\\(dt\\|dd\\|li\\|t[rdh]\\|option\\)\\b")
yuuji@58 1458 inenv p col peol (case-fold-search t))
yuuji@58 1459 (save-excursion
yuuji@58 1460 (beginning-of-line)
yuuji@61 1461 (setq inenv (or (yahtml-inner-environment-but "^\\(a\\|p\\)\\b" t)
yuuji@61 1462 "html")
yuuji@58 1463 col (get 'YaTeX-inner-environment 'indent)
yuuji@58 1464 p (get 'YaTeX-inner-environment 'point)
yuuji@64 1465 op nil))
yuuji@58 1466 (save-excursion
yuuji@58 1467 (cond
yuuji@58 1468 ((string-match envs inenv)
yuuji@58 1469 (save-excursion
yuuji@58 1470 (beginning-of-line)
yuuji@58 1471 (skip-chars-forward " \t")
yuuji@64 1472 (cond ;lookup current line's tag
yuuji@58 1473 ((looking-at (concat "</\\(" envs "\\)>"))
yuuji@58 1474 (YaTeX-reindent col))
yuuji@64 1475 ((looking-at itms)
yuuji@60 1476 (YaTeX-reindent (+ col yahtml-environment-indent)))
yuuji@64 1477 ((and yahtml-hate-too-deep-indentation
yuuji@64 1478 (looking-at (concat "<\\(" envs "\\)")))
yuuji@64 1479 (YaTeX-reindent (+ col (* 2 yahtml-environment-indent))))
yuuji@58 1480 ((and (< p (point))
yuuji@64 1481 (string-match itemizing-envs inenv)
yuuji@58 1482 (save-excursion
yuuji@58 1483 (and
yuuji@58 1484 ;;(re-search-backward itms p t)
yuuji@58 1485 (setq op (point))
yuuji@58 1486 (goto-char p)
yuuji@58 1487 (re-search-forward itms op t)
yuuji@64 1488 (progn
yuuji@64 1489 (skip-chars-forward "^>")
yuuji@64 1490 (skip-chars-forward ">")
yuuji@64 1491 (skip-chars-forward " \t")
yuuji@64 1492 (setq col (if (looking-at "$")
yuuji@64 1493 (+ col yahtml-environment-indent)
yuuji@64 1494 (current-column)))))))
yuuji@58 1495 (YaTeX-reindent col))
yuuji@58 1496 (t
yuuji@60 1497 (YaTeX-reindent (+ col yahtml-environment-indent)))))))
yuuji@58 1498 (and (bolp) (skip-chars-forward " \t"))
yuuji@58 1499 (if (and (setq inenv (yahtml-on-begend-p))
yuuji@64 1500 (string-match
yuuji@64 1501 (concat "^\\<\\(" yahtml-struct-name-regexp "\\)") inenv))
yuuji@58 1502 (save-excursion
yuuji@58 1503 (setq peol (point-end-of-line))
yuuji@58 1504 (or (= (char-after (point)) ?<)
yuuji@58 1505 (progn (skip-chars-backward "^<") (forward-char -1)))
yuuji@58 1506 (setq col (current-column))
yuuji@58 1507 (if (and (yahtml-goto-corresponding-begend t)
yuuji@58 1508 (> (point) peol)) ;if on the different line
yuuji@58 1509 (YaTeX-reindent col)))))
yuuji@58 1510 (and (bolp) (skip-chars-forward " \t"))))
yuuji@58 1511
yuuji@58 1512 ;(defun yahtml-fill-item ()
yuuji@58 1513 ; "Fill item HTML version"
yuuji@58 1514 ; (interactive)
yuuji@58 1515 ; (let (inenv p fill-prefix peol (case-fold-search t))
yuuji@58 1516 ; (setq inenv (or (YaTeX-inner-environment) "html")
yuuji@58 1517 ; p (get 'YaTeX-inner-environment 'point))
yuuji@58 1518 ; (cond
yuuji@58 1519 ; ((string-match "^[uod]l" inenv)
yuuji@58 1520 ; (save-excursion
yuuji@58 1521 ; (if (re-search-backward "<\\(d[td]\\|li\\)>[ \t\n]*" p t)
yuuji@58 1522 ; (progn
yuuji@58 1523 ; (goto-char (match-end 0))
yuuji@58 1524 ; (setq col (current-column)))
yuuji@58 1525 ; (error "No <li>, <dt>, <dd>")))
yuuji@58 1526 ; (save-excursion
yuuji@58 1527 ; (end-of-line)
yuuji@58 1528 ; (setq peol (point))
yuuji@58 1529 ; (newline)
yuuji@58 1530 ; (indent-to-column col)
yuuji@58 1531 ; (setq fill-prefix (buffer-substring (point) (1+ peol)))
yuuji@58 1532 ; (delete-region (point) peol)
yuuji@58 1533 ; (fill-region-as-paragraph
yuuji@58 1534 ; (progn (re-search-backward paragraph-start nil t) (point))
yuuji@58 1535 ; (progn (re-search-forward paragraph-start nil t 2)
yuuji@58 1536 ; (match-beginning 0)))))
yuuji@58 1537 ; (t nil))))
yuuji@58 1538
yuuji@58 1539 ;;;
yuuji@60 1540 ;;; ---------- Lint and Browsing ----------
yuuji@58 1541 ;;;
yuuji@58 1542 (defun yahtml-browse-menu ()
yuuji@58 1543 "Browsing menu"
yuuji@58 1544 (interactive)
yuuji@60 1545 (message "J)weblint p)Browse R)eload...")
yuuji@58 1546 (let ((c (char-to-string (read-char))))
yuuji@58 1547 (cond
yuuji@60 1548 ((string-match "j" c)
yuuji@60 1549 (yahtml-lint-buffer (current-buffer)))
yuuji@60 1550 ((string-match "[bp]" c)
yuuji@58 1551 (yahtml-browse-current-file))
yuuji@58 1552 ((string-match "r" c)
yuuji@58 1553 (yahtml-browse-reload)))))
yuuji@58 1554
yuuji@60 1555 (defvar yahtml-lint-buffer "*weblint*")
yuuji@60 1556
yuuji@60 1557 (defun yahtml-lint-buffer (buf)
yuuji@60 1558 "Call lint on buffer BUF."
yuuji@64 1559 (require 'yatexprc)
yuuji@60 1560 (interactive "bCall lint on buffer: ")
yuuji@60 1561 (setq buf (get-buffer buf))
yuuji@60 1562 (YaTeX-save-buffers)
yuuji@60 1563 (YaTeX-typeset
yuuji@60 1564 (concat yahtml-lint-program " "
yuuji@60 1565 (file-name-nondirectory (buffer-file-name buf)))
yuuji@60 1566 yahtml-lint-buffer "lint" "lint"))
yuuji@60 1567
yuuji@58 1568 (defun yahtml-file-to-url (file)
yuuji@58 1569 "Convert local unix file name to URL.
yuuji@58 1570 If no matches found in yahtml-path-url-alist, return raw file name."
yuuji@58 1571 (let ((list yahtml-path-url-alist) p url)
yuuji@58 1572 (if (file-directory-p file)
yuuji@58 1573 (setq file (expand-file-name yahtml-directory-index file))
yuuji@58 1574 (setq file (expand-file-name file)))
yuuji@60 1575 (if (string-match "^[A-Za-z]:/" file)
yuuji@60 1576 (progn
yuuji@64 1577 ;; (aset file 1 ?|) ;これは要らないらしい…
yuuji@60 1578 (setq file (concat "///" file))))
yuuji@58 1579 (while list
yuuji@58 1580 (if (string-match (concat "^" (regexp-quote (car (car list)))) file)
yuuji@58 1581 (setq url (cdr (car list))
yuuji@58 1582 file (substring file (match-end 0))
yuuji@58 1583 url (concat url file)
yuuji@58 1584 list nil))
yuuji@58 1585 (setq list (cdr list)))
yuuji@58 1586 (or url (concat "file:" file))))
yuuji@58 1587
yuuji@58 1588 (defun yahtml-url-to-path (file &optional basedir)
yuuji@58 1589 "Convert local URL name to unix file name."
yuuji@58 1590 (let ((list yahtml-path-url-alist) url realpath docroot
yuuji@58 1591 (dirsufp (string-match "/$" file)))
yuuji@58 1592 (setq basedir (or basedir
yuuji@58 1593 (file-name-directory
yuuji@58 1594 (expand-file-name default-directory))))
yuuji@58 1595 (cond
yuuji@58 1596 ((string-match "^/" file)
yuuji@58 1597 (while list
yuuji@59 1598 (if (file-directory-p (car (car list)))
yuuji@58 1599 (progn
yuuji@58 1600 (setq url (cdr (car list)))
yuuji@58 1601 (if (string-match "\\(http://[^/]*\\)/" url)
yuuji@58 1602 (setq docroot (substring url (match-end 1)))
yuuji@58 1603 (setq docroot url))
yuuji@64 1604 (cond
yuuji@64 1605 ((string-match (concat "^" (regexp-quote docroot)) file)
yuuji@64 1606 (setq realpath
yuuji@64 1607 (expand-file-name
yuuji@64 1608 (substring
yuuji@64 1609 file
yuuji@64 1610 (if (= (aref file (1- (match-end 0))) ?/)
yuuji@64 1611 (match-end 0) ; "/foo"
yuuji@64 1612 (min (1+ (match-end 0)) (length file)))) ; "/~foo"
yuuji@64 1613 (car (car list))))))
yuuji@58 1614 (if realpath
yuuji@58 1615 (progn (setq list nil)
yuuji@58 1616 (if (and dirsufp (not (string-match "/$" realpath)))
yuuji@58 1617 (setq realpath (concat realpath "/")))))))
yuuji@58 1618 (setq list (cdr list)))
yuuji@58 1619 realpath)
yuuji@58 1620 (t file))))
yuuji@58 1621
yuuji@58 1622 (defun yahtml-browse-current-file ()
yuuji@58 1623 "Call WWW browser on current file."
yuuji@58 1624 (interactive)
yuuji@58 1625 (basic-save-buffer)
yuuji@58 1626 (yahtml-browse-html (yahtml-file-to-url (buffer-file-name))))
yuuji@58 1627
yuuji@58 1628 (defun yahtml-browse-reload ()
yuuji@58 1629 "Send `reload' event to netzscape."
yuuji@58 1630 (let ((pb "* WWW Browser *") (cb (current-buffer)))
yuuji@58 1631 (cond
yuuji@58 1632 ((string-match "[Nn]etscape" yahtml-www-browser)
yuuji@58 1633 (if (get-buffer pb)
yuuji@58 1634 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
yuuji@58 1635 ;;(or (get 'yahtml-netscape-sentinel 'url)
yuuji@58 1636 ;; (error "Reload should be called after Browsing."))
yuuji@58 1637 (put 'yahtml-netscape-sentinel 'url
yuuji@58 1638 (yahtml-file-to-url (buffer-file-name)))
yuuji@58 1639 (basic-save-buffer)
yuuji@58 1640 (set-process-sentinel
yuuji@58 1641 (setq yahtml-browser-process
yuuji@58 1642 (start-process
yuuji@60 1643 "browser" pb shell-file-name yahtml-shell-command-option ;"-c"
yuuji@58 1644 (format "%s -remote 'reload'" yahtml-www-browser)))
yuuji@58 1645 'yahtml-netscape-sentinel))
yuuji@58 1646 (t
yuuji@58 1647 (message "Sorry, RELOAD is supported only for Netscape.")))))
yuuji@58 1648
yuuji@58 1649 ;;; ---------- Intelligent newline ----------
yuuji@58 1650 (defun yahtml-intelligent-newline (arg)
yuuji@58 1651 "Intelligent newline for HTML"
yuuji@58 1652 (interactive "P")
yuuji@60 1653 (let (env func)
yuuji@60 1654 (end-of-line)
yuuji@64 1655 (setq env (downcase (or (yahtml-inner-environment-but "^\\(a\\|p\\)\\b" t)
yuuji@64 1656 "html")))
yuuji@58 1657 (setq func (intern-soft (concat "yahtml-intelligent-newline-" env)))
yuuji@58 1658 (newline)
yuuji@58 1659 (if (and env func (fboundp func))
yuuji@64 1660 ;; if intelligent line function is defined, call that
yuuji@64 1661 (funcall func)
yuuji@64 1662 ;; else do the default action
yuuji@64 1663 (if (string-match yahtml-p-prefered-env-regexp env)
yuuji@64 1664 (yahtml-insert-p)))))
yuuji@58 1665
yuuji@64 1666 (defvar yahtml-faithful-to-htmllint nil)
yuuji@58 1667 (defun yahtml-intelligent-newline-ul ()
yuuji@58 1668 (interactive)
yuuji@64 1669 (yahtml-insert-single "li")
yuuji@64 1670 (or yahtml-faithful-to-htmllint (insert " "))
yuuji@58 1671 (yahtml-indent-line))
yuuji@58 1672
yuuji@58 1673 (fset 'yahtml-intelligent-newline-ol 'yahtml-intelligent-newline-ul)
yuuji@58 1674
yuuji@58 1675 (defun yahtml-intelligent-newline-dl ()
yuuji@58 1676 (interactive)
yuuji@58 1677 (let ((case-fold-search t))
yuuji@58 1678 (if (save-excursion
yuuji@58 1679 (re-search-backward "<\\(\\(dt\\)\\|\\(dd\\)\\)>"
yuuji@58 1680 (get 'YaTeX-inner-environment 'point) t))
yuuji@58 1681 (cond
yuuji@58 1682 ((match-beginning 2)
yuuji@64 1683 (yahtml-insert-single "dd")
yuuji@64 1684 (or yahtml-faithful-to-htmllint (insert " "))
yuuji@58 1685 (setq yahtml-last-single-cmd "dt"))
yuuji@58 1686 ((match-beginning 3)
yuuji@64 1687 (yahtml-insert-single "dt")
yuuji@64 1688 (or yahtml-faithful-to-htmllint (insert " "))
yuuji@58 1689 (setq yahtml-last-single-cmd "dd")))
yuuji@64 1690 (insert (if yahtml-prefer-upcases "<DT> " "<dt> "))
yuuji@64 1691 (setq yahtml-last-single-cmd "dd"))
yuuji@64 1692 (yahtml-indent-line)
yuuji@64 1693 (and (string-match yahtml-p-prefered-env-regexp "dl")
yuuji@64 1694 (string-equal yahtml-last-single-cmd "dt")
yuuji@64 1695 (yahtml-insert-p nil))))
yuuji@58 1696
yuuji@59 1697 (defun yahtml-intelligent-newline-select ()
yuuji@59 1698 (interactive)
yuuji@59 1699 (insert "<" (if yahtml-prefer-upcases "OPTION" "option") "> ")
yuuji@59 1700 (yahtml-indent-line))
yuuji@59 1701
yuuji@58 1702 ;;; ---------- Marking ----------
yuuji@58 1703 (defun yahtml-mark-begend ()
yuuji@58 1704 "Mark current tag"
yuuji@58 1705 (interactive)
yuuji@58 1706 (YaTeX-beginning-of-environment)
yuuji@58 1707 (let ((p (point)))
yuuji@58 1708 (save-excursion
yuuji@58 1709 (skip-chars-backward " \t" (point-beginning-of-line))
yuuji@58 1710 (if (bolp) (setq p (point))))
yuuji@58 1711 (push-mark p t))
yuuji@58 1712 (yahtml-goto-corresponding-begend)
yuuji@58 1713 (forward-list 1)
yuuji@58 1714 (if (eolp) (forward-char 1)))
yuuji@58 1715
yuuji@59 1716 ;;; ---------- complete marks ----------
yuuji@59 1717 (defun yahtml-complete-mark ()
yuuji@60 1718 "Complete &gt, &lt, &ampersand, and &quote."
yuuji@59 1719 (interactive)
yuuji@59 1720 (message "1:< 2:> 3:& 4:\"")
yuuji@59 1721 (let ((c (read-char)))
yuuji@59 1722 (setq c (if (or (< c ?0) (> c ?5))
yuuji@59 1723 (string-match (regexp-quote (char-to-string c)) "<>&\"")
yuuji@59 1724 (- c ?1)))
yuuji@59 1725 (if (or (< c 0) (> c 4))
yuuji@59 1726 nil
yuuji@59 1727 (insert (format "&%s;" (nth c '("lt" "gt" "amp" "quot")))))))
yuuji@59 1728
yuuji@59 1729
yuuji@60 1730 ;;; ---------- jump to error line ----------
yuuji@60 1731 (defvar yahtml-error-line-regexp
yuuji@60 1732 "^\\(.*\\)(\\([0-9]+\\)):"
yuuji@60 1733 "*Regexp of error position which is produced by lint program.")
yuuji@60 1734 (defun yahtml-prev-error ()
yuuji@60 1735 "Jump to previous error seeing lint buffer."
yuuji@60 1736 (interactive)
yuuji@60 1737 (or (get-buffer yahtml-lint-buffer)
yuuji@60 1738 (error "No lint program ran."))
yuuji@60 1739 (YaTeX-showup-buffer yahtml-lint-buffer nil t)
yuuji@64 1740 (yahtml-jump-to-error-line t))
yuuji@60 1741
yuuji@64 1742 (defun yahtml-jump-to-error-line (&optional sit)
yuuji@64 1743 (interactive "P")
yuuji@60 1744 (let ((p (point)) (e (point-end-of-line)))
yuuji@60 1745 (end-of-line)
yuuji@60 1746 (if (re-search-backward yahtml-error-line-regexp nil t)
yuuji@60 1747 (let ((f (YaTeX-match-string 1))
yuuji@60 1748 (l (string-to-int (YaTeX-match-string 2))))
yuuji@64 1749 (if sit (sit-for 1))
yuuji@60 1750 (forward-line -1)
yuuji@64 1751 (YaTeX-showup-buffer (YaTeX-switch-to-buffer f t) nil t)
yuuji@60 1752 (goto-line l))
yuuji@60 1753 (message "No line number usage"))))
yuuji@60 1754
yuuji@57 1755 ;;; ---------- ----------
yuuji@57 1756
yuuji@57 1757 ;;;
yuuji@57 1758 ;;hilit19
yuuji@57 1759 ;;;
yuuji@57 1760 (defvar yahtml-default-face-table
yuuji@57 1761 '(
yuuji@57 1762 (form black/ivory white/hex-442233 italic)
yuuji@57 1763 ))
yuuji@57 1764 (defvar yahtml-hilit-patterns-alist
yuuji@57 1765 '(
yuuji@57 1766 ;; comments
yuuji@57 1767 ("<!--\\s " "-->" comment)
yuuji@57 1768 ;; include&exec
yuuji@57 1769 ("<!--#\\(include\\|exec\\)" "-->" include)
yuuji@57 1770 ;; string
yuuji@57 1771 (hilit-string-find 39 string)
yuuji@57 1772 (yahtml-hilit-region-tag "\\(em\\|strong\\)" bold)
yuuji@57 1773 ("</?[uod]l>" 0 decl)
yuuji@57 1774 ("<\\(di\\|dt\\|li\\|dd\\)>" 0 label)
yuuji@57 1775 ("<a\\s +href" "</a>" crossref)
yuuji@64 1776 (yahtml-hilit-region-tag-itself "</?\\sw+\\>" decl)
yuuji@57 1777 ))
yuuji@57 1778
yuuji@57 1779 (defun yahtml-hilit-region-tag (tag)
yuuji@57 1780 "Return list of start/end point of <TAG> form."
yuuji@57 1781 (if (re-search-forward (concat "<" tag ">") nil t)
yuuji@57 1782 (let ((m0 (match-beginning 0)))
yuuji@57 1783 (skip-chars-forward " \t\n")
yuuji@57 1784 (cons (point)
yuuji@57 1785 (progn (re-search-forward (concat "</" tag ">") nil t)
yuuji@58 1786 (match-beginning 0))))))
yuuji@57 1787
yuuji@64 1788 (defun yahtml-hilit-region-tag-itself (ptn)
yuuji@64 1789 "Return list of start/end point of <tag options...> itself."
yuuji@64 1790 (if (re-search-forward ptn nil t)
yuuji@64 1791 (let ((m0 (match-beginning 0)))
yuuji@64 1792 (skip-chars-forward "^>")
yuuji@64 1793 (cons m0 (1+ (point) )))))
yuuji@64 1794
yuuji@57 1795 ;(setq hilit-patterns-alist (delq (assq 'yahtml-mode hilit-patterns-alist) hilit-patterns-alist))
yuuji@64 1796 (and (featurep 'hilit19)
yuuji@64 1797 (or (assq 'yahtml-mode hilit-patterns-alist)
yuuji@64 1798 (setq hilit-patterns-alist
yuuji@64 1799 (cons (cons 'yahtml-mode yahtml-hilit-patterns-alist)
yuuji@64 1800 hilit-patterns-alist))))
yuuji@57 1801
yuuji@54 1802 (provide 'yahtml)
yuuji@54 1803
yuuji@54 1804 ; Local variables:
yuuji@54 1805 ; fill-prefix: ";;; "
yuuji@54 1806 ; paragraph-start: "^$\\| \\|;;;$"
yuuji@54 1807 ; paragraph-separate: "^$\\| \\|;;;$"
yuuji@54 1808 ; End: