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