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