rev |
line source |
yuuji@13
|
1 ;;; -*- Emacs-Lisp -*-
|
yuuji@58
|
2 ;;; (c ) 1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp, pcs39334@asciinet.or.jp]
|
yuuji@59
|
3 ;;; Last modified Tue Apr 23 23:13:12 1996 on inspire
|
yuuji@58
|
4 ;;; This package is no longer tentative.
|
yuuji@54
|
5 ;;; $Id$
|
yuuji@54
|
6
|
yuuji@58
|
7 ;;;[Installation]
|
yuuji@58
|
8 ;;;
|
yuuji@58
|
9 ;;; First, you have to install YaTeX and make sure it works fine. Then
|
yuuji@58
|
10 ;;; put these expressions into your ~/.emacs
|
yuuji@58
|
11 ;;;
|
yuuji@58
|
12 ;;; (setq auto-mode-alist
|
yuuji@58
|
13 ;;; (cons (cons "\\.html$" 'yahtml-mode) auto-mode-alist))
|
yuuji@58
|
14 ;;; (autoload 'yahtml-mode "yahtml" "Yet Another HTML mode" t)
|
yuuji@58
|
15 ;;; (setq yahtml-www-browser "netscape")
|
yuuji@58
|
16 ;;; ;Write your favorite browser. But netscape is advantageous.
|
yuuji@58
|
17 ;;; (setq yahtml-path-url-alist
|
yuuji@58
|
18 ;;; '(("/home/yuuji/public_html" . "http://www.mynet/~yuuji")
|
yuuji@58
|
19 ;;; ("/home/staff/yuuji/html" . "http://www.othernet/~yuuji")))
|
yuuji@58
|
20 ;;; ;Write correspondence alist from ABSOLUTE unix path name to URL path.
|
yuuji@58
|
21 ;;;
|
yuuji@54
|
22 ;;;[Commentary]
|
yuuji@13
|
23 ;;;
|
yuuji@54
|
24 ;;; It is assumed you are already familiar with YaTeX. The following
|
yuuji@54
|
25 ;;; completing featureas are available: ([prefix] means `C-c' by default)
|
yuuji@54
|
26 ;;;
|
yuuji@54
|
27 ;;; * [prefix] b X Complete environments such as `H1' which
|
yuuji@57
|
28 ;;; normally requires closing tag `</H1>
|
yuuji@57
|
29 ;;; <a href=foo> ... </a> is also classified into
|
yuuji@57
|
30 ;;; this group
|
yuuji@59
|
31 ;;; When input `href=...', you can complete file
|
yuuji@59
|
32 ;;; name or label(href="#foo") by typing TAB.
|
yuuji@54
|
33 ;;; * [prefix] s Complete declarative notations such as
|
yuuji@57
|
34 ;;; `<img src="foo.gif">'
|
yuuji@57
|
35 ;;; `<input name="var" ...>'
|
yuuji@54
|
36 ;;; * [prefix] l Complete typeface-changing commands such as
|
yuuji@54
|
37 ;;; `<i> ... </i>' or `<samp> ... </samp>'
|
yuuji@57
|
38 ;;; * [prefix] m Complete single commands such as
|
yuuji@58
|
39 ;;; `<br>' or `<hr> or <li>...'
|
yuuji@59
|
40 ;;; * M-RET Intelligent newline; if current TAG is one of
|
yuuji@59
|
41 ;;; ul, ol, or dl. insert newline and <li> or
|
yuuji@59
|
42 ;;; <dt> or <dd> suitable for current condition.
|
yuuji@54
|
43 ;;; * menu-bar yahtml Complete all by selecting a menu item (Though I
|
yuuji@54
|
44 ;;; hate menu, this is most useful)
|
yuuji@58
|
45 ;;; * [prefix] g Goto corresponding Tag or HREF such as
|
yuuji@59
|
46 ;;; <dl> <-> </dl> or href="xxx".
|
yuuji@59
|
47 ;;; Or invoke image viewer if point is on <img src=...>.
|
yuuji@58
|
48 ;;; * [prefix] k Kill html tags on the point. If you provide
|
yuuji@58
|
49 ;;; universal-argument, kill surrounded contents too.
|
yuuji@58
|
50 ;;; * [prefix] c Change html tags on the point.
|
yuuji@59
|
51 ;;; When typeing [prefix] c on `href="xxx"', you can
|
yuuji@59
|
52 ;;; change the reference link with completion.
|
yuuji@58
|
53 ;;; * [prefix] t b View current html with WWW browser
|
yuuji@58
|
54 ;;; (To activate this, never fail to set the lisp
|
yuuji@58
|
55 ;;; variable yahtml-www-browser. Recommended value
|
yuuji@58
|
56 ;;; is "netscape")
|
yuuji@59
|
57 ;;; * [prefix] a YaTeX's accent mark's equivalent of yahtml.
|
yuuji@59
|
58 ;;; This function can input $lt, $gt or so.
|
yuuji@58
|
59 ;;;
|
yuuji@54
|
60
|
yuuji@13
|
61
|
yuuji@13
|
62 (require 'yatex)
|
yuuji@57
|
63 (defvar yahtml-prefix-map nil)
|
yuuji@57
|
64 (defvar yahtml-mode-map nil "Keymap used in yahtml-mode.")
|
yuuji@58
|
65 (defvar yahtml-image-viewer "xv" "*Image viewer program")
|
yuuji@58
|
66 (defvar yahtml-www-browser "netscape"
|
yuuji@58
|
67 "*WWW Browser command")
|
yuuji@58
|
68 (defvar yahtml-kanji-code 2
|
yuuji@58
|
69 "Kanji coding system of html file; 1=sjis, 2=jis, 3=euc")
|
yuuji@58
|
70 ;;(defvar yahtml-www-server "www" "*Host name of your domain's WWW server")
|
yuuji@58
|
71 (defvar yahtml-path-url-alist nil
|
yuuji@58
|
72 "*Alist of unix path name vs. URL name of WWW server.
|
yuuji@58
|
73 Ex.
|
yuuji@58
|
74 '((\"/usr/home/yuuji/http\" . \"http://www.comp.ae.keio.ac.jp/~yuuji\")
|
yuuji@58
|
75 (\"/usr/home/yuuji/darts/http\" . \"http://inspire.comp.ae.keio.ac.jp/~darts\"))")
|
yuuji@58
|
76 (defvar yahtml-directory-index "index.html"
|
yuuji@58
|
77 "*Directory index file name;
|
yuuji@58
|
78 Consult your site's WWW administrator.")
|
yuuji@57
|
79
|
yuuji@57
|
80 (defun yahtml-define-begend-key-normal (key env &optional map)
|
yuuji@57
|
81 "Define short cut yahtml-insert-begin-end key."
|
yuuji@57
|
82 (YaTeX-define-key
|
yuuji@57
|
83 key
|
yuuji@57
|
84 (list 'lambda '(arg) '(interactive "P")
|
yuuji@57
|
85 (list 'yahtml-insert-begin-end env 'arg))
|
yuuji@57
|
86 map))
|
yuuji@57
|
87
|
yuuji@57
|
88 (defun yahtml-define-begend-region-key (key env &optional map)
|
yuuji@57
|
89 "Define short cut yahtml-insert-begin-end-region key."
|
yuuji@57
|
90 (YaTeX-define-key key (list 'lambda nil '(interactive)
|
yuuji@57
|
91 (list 'yahtml-insert-begin-end env t)) map))
|
yuuji@57
|
92
|
yuuji@57
|
93 (defun yahtml-define-begend-key (key env &optional map)
|
yuuji@57
|
94 "Define short cut key for begin type completion both for
|
yuuji@57
|
95 normal and region mode. To customize yahtml, user should use this function."
|
yuuji@57
|
96 (yahtml-define-begend-key-normal key env map)
|
yuuji@57
|
97 (if YaTeX-inhibit-prefix-letter nil
|
yuuji@57
|
98 (yahtml-define-begend-region-key
|
yuuji@57
|
99 (concat (upcase (substring key 0 1)) (substring key 1)) env)))
|
yuuji@57
|
100
|
yuuji@57
|
101
|
yuuji@13
|
102 (if yahtml-mode-map nil
|
yuuji@57
|
103 (setq yahtml-mode-map (make-sparse-keymap)
|
yuuji@57
|
104 yahtml-prefix-map (make-sparse-keymap))
|
yuuji@54
|
105 (define-key yahtml-mode-map YaTeX-prefix yahtml-prefix-map)
|
yuuji@58
|
106 (define-key yahtml-mode-map "\M-\C-@" 'yahtml-mark-begend)
|
yuuji@58
|
107 (if (and (boundp 'window-system) (eq window-system 'x) YaTeX-emacs-19)
|
yuuji@58
|
108 (define-key yahtml-mode-map [?\M-\C- ] 'yahtml-mark-begend))
|
yuuji@54
|
109 (define-key yahtml-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment)
|
yuuji@57
|
110 (define-key yahtml-mode-map "\M-\C-e" 'YaTeX-end-of-environment)
|
yuuji@58
|
111 (define-key yahtml-mode-map "\M-\C-m" 'yahtml-intelligent-newline)
|
yuuji@58
|
112 (define-key yahtml-mode-map "\C-i" 'yahtml-indent-line)
|
yuuji@57
|
113 (define-key yahtml-mode-map YaTeX-prefix yahtml-prefix-map)
|
yuuji@57
|
114 (let ((map yahtml-prefix-map))
|
yuuji@57
|
115 (YaTeX-define-key "^" 'yahtml-visit-main map)
|
yuuji@57
|
116 (YaTeX-define-key "4^" 'yahtml-visit-main-other-window map)
|
yuuji@57
|
117 (YaTeX-define-key "4g" 'yahtml-goto-corresponding-*-other-window map)
|
yuuji@57
|
118 (YaTeX-define-key "44" 'YaTeX-switch-to-window map)
|
yuuji@57
|
119 (and YaTeX-emacs-19 window-system
|
yuuji@57
|
120 (progn
|
yuuji@57
|
121 (YaTeX-define-key "5^" 'yahtml-visit-main-other-frame map)
|
yuuji@57
|
122 (YaTeX-define-key "5g" 'yahtml-goto-corresponding-*-other-frame map)
|
yuuji@57
|
123 (YaTeX-define-key "55" 'YaTeX-switch-to-window map)))
|
yuuji@57
|
124 (YaTeX-define-key "v" 'YaTeX-version map)
|
yuuji@57
|
125 (YaTeX-define-key "}" 'YaTeX-insert-braces-region map)
|
yuuji@57
|
126 (YaTeX-define-key "]" 'YaTeX-insert-brackets-region map)
|
yuuji@57
|
127 (YaTeX-define-key ")" 'YaTeX-insert-parens-region map)
|
yuuji@57
|
128 (YaTeX-define-key "s" 'yahtml-insert-form map)
|
yuuji@57
|
129 (YaTeX-define-key "l" 'yahtml-insert-tag map)
|
yuuji@57
|
130 (YaTeX-define-key "m" 'yahtml-insert-single map)
|
yuuji@57
|
131 (YaTeX-define-key "n" '(lambda () (interactive) (insert "<br>\n")) map)
|
yuuji@57
|
132 (if YaTeX-no-begend-shortcut
|
yuuji@57
|
133 (progn
|
yuuji@57
|
134 (YaTeX-define-key "B" 'yahtml-insert-begend-region map)
|
yuuji@57
|
135 (YaTeX-define-key "b" 'yahtml-insert-begend map))
|
yuuji@57
|
136 (yahtml-define-begend-key "bh" "HTML" map)
|
yuuji@57
|
137 (yahtml-define-begend-key "bH" "HEAD" map)
|
yuuji@57
|
138 (yahtml-define-begend-key "bt" "TITLE" map)
|
yuuji@59
|
139 (yahtml-define-begend-key "bT" "table" map)
|
yuuji@57
|
140 (yahtml-define-begend-key "bb" "BODY" map)
|
yuuji@57
|
141 (yahtml-define-begend-key "bd" "DL" map)
|
yuuji@57
|
142 (yahtml-define-begend-key "b1" "H1" map)
|
yuuji@57
|
143 (yahtml-define-begend-key "b2" "H2" map)
|
yuuji@57
|
144 (yahtml-define-begend-key "b3" "H3" map)
|
yuuji@57
|
145 (yahtml-define-begend-key "ba" "a" map)
|
yuuji@57
|
146 (yahtml-define-begend-key "bf" "form" map)
|
yuuji@57
|
147 (yahtml-define-begend-key "bs" "select" map)
|
yuuji@57
|
148 (YaTeX-define-key "b " 'yahtml-insert-begend map)
|
yuuji@58
|
149 (YaTeX-define-key "B " 'yahtml-insert-begend-region map)
|
yuuji@57
|
150 )
|
yuuji@58
|
151 (YaTeX-define-key "e" 'YaTeX-end-environment map)
|
yuuji@57
|
152 (YaTeX-define-key ">" 'yahtml-comment-region map)
|
yuuji@57
|
153 (YaTeX-define-key "<" 'yahtml-uncomment-region map)
|
yuuji@57
|
154 (YaTeX-define-key "g" 'yahtml-goto-corresponding-* map)
|
yuuji@58
|
155 (YaTeX-define-key "k" 'yahtml-kill-* map)
|
yuuji@58
|
156 (YaTeX-define-key "c" 'yahtml-change-* map)
|
yuuji@58
|
157 (YaTeX-define-key "t" 'yahtml-browse-menu map)
|
yuuji@59
|
158 (YaTeX-define-key "a" 'yahtml-complete-mark map)
|
yuuji@58
|
159 ;;;;;(YaTeX-define-key "i" 'yahtml-fill-item map)
|
yuuji@57
|
160 )
|
yuuji@57
|
161 )
|
yuuji@54
|
162
|
yuuji@59
|
163 (defvar yahtml-paragraph-start
|
yuuji@59
|
164 (concat
|
yuuji@59
|
165 "^$\\|<[bh]r>\\|<p>\\|^[ \t]*</?\\(h[1-6]\\|p\\|d[ldt]\\|t[rdh]\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\)>")
|
yuuji@59
|
166 "*Regexp of html paragraph separater")
|
yuuji@57
|
167 (defvar yahtml-paragraph-separate
|
yuuji@57
|
168 (concat
|
yuuji@59
|
169 "^$\\|<[bh]r>\\|<p>\\|^[ \t]*</?\\(h[1-6]\\|p\\|d[ldt]\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\)>")
|
yuuji@57
|
170 "*Regexp of html paragraph separater")
|
yuuji@54
|
171 (defvar yahtml-syntax-table nil
|
yuuji@54
|
172 "*Syntax table for typesetting buffer")
|
yuuji@54
|
173
|
yuuji@54
|
174 (if yahtml-syntax-table nil
|
yuuji@54
|
175 (setq yahtml-syntax-table
|
yuuji@54
|
176 (make-syntax-table (standard-syntax-table)))
|
yuuji@54
|
177 (modify-syntax-entry ?\< "(" yahtml-syntax-table)
|
yuuji@54
|
178 (modify-syntax-entry ?\> ")" yahtml-syntax-table)
|
yuuji@59
|
179 (modify-syntax-entry ?\n " " yahtml-syntax-table)
|
yuuji@54
|
180 )
|
yuuji@54
|
181 (defvar yahtml-command-regexp "[A-Za-z0-9]+"
|
yuuji@54
|
182 "Regexp of constituent of html commands.")
|
yuuji@54
|
183
|
yuuji@54
|
184 ;;; Completion tables for `form'
|
yuuji@57
|
185 (defvar yahtml-form-table
|
yuuji@57
|
186 '(("img") ("input")))
|
yuuji@54
|
187 (defvar yahtml-user-form-table nil)
|
yuuji@54
|
188 (defvar yahtml-tmp-form-table nil)
|
yuuji@54
|
189
|
yuuji@54
|
190 (defvar yahtml-env-table
|
yuuji@57
|
191 '(("html") ("head") ("title") ("body") ("dl") ("a") ("form") ("select")
|
yuuji@59
|
192 ("textarea")
|
yuuji@58
|
193 ("OrderedList" . "ol")
|
yuuji@58
|
194 ("UnorderedList" . "ul")
|
yuuji@58
|
195 ("DefinitionList" . "dl")
|
yuuji@59
|
196 ("Preformatted" . "pre")
|
yuuji@59
|
197 ("table") ("tr") ("th") ("td")
|
yuuji@57
|
198 ("h1") ("h2") ("h3") ("h4") ("h5") ("h6") ("ul")))
|
yuuji@57
|
199
|
yuuji@58
|
200 (defvar yahtml-itemizing-regexp
|
yuuji@58
|
201 "\\(ul\\|ul\\|dl\\)"
|
yuuji@58
|
202 "Regexp of itemizing forms")
|
yuuji@58
|
203
|
yuuji@57
|
204 (defvar yahtml-user-env-table nil)
|
yuuji@57
|
205 (defvar yahtml-tmp-env-table nil)
|
yuuji@54
|
206
|
yuuji@54
|
207 ;;; Completion tables for typeface designator
|
yuuji@54
|
208 (defvar yahtml-typeface-table
|
yuuji@54
|
209 '(("defn") ("em") ("cite") ("code") ("kbd") ("samp")
|
yuuji@57
|
210 ("strong") ("var") ("b") ("i") ("tt") ("u") ("address"))
|
yuuji@54
|
211 "Default completion table of typeface designator")
|
yuuji@54
|
212 (defvar yahtml-user-typeface-table nil)
|
yuuji@54
|
213 (defvar yahtml-tmp-typeface-table nil)
|
yuuji@58
|
214 (defvar yahtml-last-typeface-cmd "address")
|
yuuji@54
|
215
|
yuuji@57
|
216 (defvar yahtml-single-cmd-table
|
yuuji@58
|
217 '(("hr") ("br") ("option") ("p")
|
yuuji@58
|
218 ("HorizontalLine" . "hr")
|
yuuji@58
|
219 ("BreakLine" . "br")
|
yuuji@58
|
220 ("Paragraph" . "p")
|
yuuji@58
|
221 ("Item" . "li")
|
yuuji@58
|
222 ("DefineTerm" . "dt")
|
yuuji@58
|
223 ("Description" . "dd")
|
yuuji@58
|
224 ("dd") ("dt") ("li")
|
yuuji@58
|
225 )
|
yuuji@57
|
226 "Default completion table of HTML single command.")
|
yuuji@57
|
227 (defvar yahtml-user-single-cmd-table nil)
|
yuuji@57
|
228 (defvar yahtml-tmp-single-cmd-table nil)
|
yuuji@57
|
229 (defvar yahtml-last-single-cmd nil)
|
yuuji@57
|
230
|
yuuji@54
|
231 (defvar yahtml-prefer-upcases nil)
|
yuuji@54
|
232 (cond
|
yuuji@54
|
233 (yahtml-prefer-upcases
|
yuuji@54
|
234 (setq yahtml-form-table
|
yuuji@54
|
235 (mapcar (function (lambda (list) (list (upcase (car list)))))
|
yuuji@54
|
236 yahtml-form-table))
|
yuuji@54
|
237 (setq yahtml-env-table
|
yuuji@54
|
238 (mapcar (function (lambda (list) (list (upcase (car list)))))
|
yuuji@54
|
239 yahtml-env-table))
|
yuuji@54
|
240 (setq yahtml-typeface-table
|
yuuji@54
|
241 (mapcar (function (lambda (list) (list (upcase (car list)))))
|
yuuji@54
|
242 yahtml-typeface-table))))
|
yuuji@13
|
243
|
yuuji@57
|
244 (defvar yahtml-struct-name-regexp
|
yuuji@59
|
245 "\\<\\(h[1-6]\\|[uod]l\\|body\\|title\\|head\\|table\\|t[rhd]\\|pre\\|a\\|form\\|select\\)\\b")
|
yuuji@57
|
246
|
yuuji@57
|
247
|
yuuji@13
|
248 (defun yahtml-mode ()
|
yuuji@13
|
249 (interactive)
|
yuuji@13
|
250 (yatex-mode)
|
yuuji@57
|
251 (cond
|
yuuji@57
|
252 ((boundp 'MULE)
|
yuuji@57
|
253 (set-file-coding-system
|
yuuji@57
|
254 (cdr (assq yahtml-kanji-code YaTeX-kanji-code-alist))))
|
yuuji@57
|
255 ((boundp 'NEMACS)
|
yuuji@57
|
256 (make-local-variable 'kanji-fileio-code)
|
yuuji@57
|
257 (setq kanji-fileio-code yahtml-kanji-code)))
|
yuuji@13
|
258 (setq major-mode 'yahtml-mode
|
yuuji@13
|
259 mode-name "yahtml")
|
yuuji@54
|
260 (make-local-variable 'YaTeX-ec) (setq YaTeX-ec "")
|
yuuji@59
|
261 (make-local-variable 'YaTeX-struct-begin)
|
yuuji@59
|
262 (setq YaTeX-struct-begin "<%1%2>")
|
yuuji@54
|
263 (make-local-variable 'YaTeX-struct-end) (setq YaTeX-struct-end "</%1>")
|
yuuji@54
|
264 (make-local-variable 'YaTeX-struct-name-regexp)
|
yuuji@57
|
265 (setq YaTeX-struct-name-regexp yahtml-struct-name-regexp)
|
yuuji@13
|
266 (make-local-variable 'YaTeX-prefix-map)
|
yuuji@54
|
267 (make-local-variable 'YaTeX-command-token-regexp)
|
yuuji@54
|
268 (setq YaTeX-command-token-regexp yahtml-command-regexp)
|
yuuji@59
|
269 (make-local-variable 'YaTeX-comment-prefix)
|
yuuji@59
|
270 (setq YaTeX-comment-prefix "<!--")
|
yuuji@58
|
271 ;;(make-local-variable 'YaTeX-environment-indent)
|
yuuji@58
|
272 ;;(setq YaTeX-environment-indent 0)
|
yuuji@57
|
273 (make-local-variable 'fill-prefix)
|
yuuji@57
|
274 (setq fill-prefix nil)
|
yuuji@57
|
275 (make-local-variable 'paragraph-separate)
|
yuuji@59
|
276 (setq paragraph-start yahtml-paragraph-start
|
yuuji@59
|
277 paragraph-separate yahtml-paragraph-separate)
|
yuuji@57
|
278 (make-local-variable 'comment-start)
|
yuuji@57
|
279 (make-local-variable 'comment-end)
|
yuuji@57
|
280 (setq comment-start "<!-- " comment-end " -->")
|
yuuji@58
|
281 (make-local-variable 'indent-line-function)
|
yuuji@58
|
282 (setq indent-line-function 'yahtml-indent-line)
|
yuuji@58
|
283 (make-local-variable 'YaTeX-item-regexp)
|
yuuji@58
|
284 (setq YaTeX-item-regexp "<\\(li\\|d[td]\\)>")
|
yuuji@54
|
285 (set-syntax-table yahtml-syntax-table)
|
yuuji@13
|
286 (use-local-map yahtml-mode-map)
|
yuuji@54
|
287 (run-hooks 'yahtml-mode-hook))
|
yuuji@54
|
288
|
yuuji@54
|
289 (defun yahtml-define-menu (keymap bindlist)
|
yuuji@54
|
290 (mapcar
|
yuuji@54
|
291 (function
|
yuuji@54
|
292 (lambda (bind)
|
yuuji@54
|
293 (define-key keymap (vector (car bind)) (cdr bind))))
|
yuuji@54
|
294 bindlist))
|
yuuji@54
|
295
|
yuuji@54
|
296 (defvar yahtml-menu-map nil "Menu map of yahtml")
|
yuuji@54
|
297 (defvar yahtml-menu-map-sectioning nil "Menu map of yahtml(sectioning)")
|
yuuji@54
|
298 (defvar yahtml-menu-map-listing nil "Menu map of yahtml(listing)")
|
yuuji@54
|
299 (defvar yahtml-menu-map-logical nil "Menu map of yahtml(logical tags)")
|
yuuji@54
|
300 (defvar yahtml-menu-map-typeface nil "Menu map of yahtml(typeface tags)")
|
yuuji@54
|
301
|
yuuji@54
|
302 ;;; Variables for mosaic url history
|
yuuji@54
|
303 (defvar yahtml-urls nil "Alist of global history")
|
yuuji@54
|
304 (defvar yahtml-url-history-file "~/.mosaic-global-history"
|
yuuji@54
|
305 "File name of url history")
|
yuuji@54
|
306
|
yuuji@54
|
307 (cond
|
yuuji@54
|
308 ((and YaTeX-emacs-19 (null yahtml-menu-map))
|
yuuji@54
|
309 (setq yahtml-menu-map (make-sparse-keymap "yahtml menu"))
|
yuuji@54
|
310 (setq yahtml-menu-map-sectioning (make-sparse-keymap "sectioning menu"))
|
yuuji@54
|
311 (yahtml-define-menu
|
yuuji@54
|
312 yahtml-menu-map-sectioning
|
yuuji@54
|
313 (nreverse
|
yuuji@58
|
314 '((1 "H1" . (lambda () (interactive) (yahtml-insert-begend nil "H1")))
|
yuuji@58
|
315 (2 "H2" . (lambda () (interactive) (yahtml-insert-begend nil "H2")))
|
yuuji@58
|
316 (3 "H3" . (lambda () (interactive) (yahtml-insert-begend nil "H3")))
|
yuuji@58
|
317 (4 "H4" . (lambda () (interactive) (yahtml-insert-begend nil "H4")))
|
yuuji@58
|
318 (5 "H5" . (lambda () (interactive) (yahtml-insert-begend nil "H5")))
|
yuuji@58
|
319 (6 "H6" . (lambda () (interactive) (yahtml-insert-begend nil "H6")))
|
yuuji@54
|
320 )))
|
yuuji@54
|
321 (setq yahtml-menu-map-logical (make-sparse-keymap "logical tags"))
|
yuuji@54
|
322 (yahtml-define-menu
|
yuuji@54
|
323 yahtml-menu-map-logical
|
yuuji@54
|
324 (nreverse
|
yuuji@54
|
325 '((em "Embolden" .
|
yuuji@58
|
326 (lambda () (interactive) (yahtml-insert-tag nil "EM")))
|
yuuji@54
|
327 (defn "Define a word" .
|
yuuji@58
|
328 (lambda () (interactive) (yahtml-insert-tag nil "DEFN")))
|
yuuji@54
|
329 (cite "Citation" .
|
yuuji@58
|
330 (lambda () (interactive) (yahtml-insert-tag nil "CITE")))
|
yuuji@54
|
331 (code "Code" .
|
yuuji@58
|
332 (lambda () (interactive) (yahtml-insert-tag nil "CODE")))
|
yuuji@54
|
333 (kbd "Keyboard" .
|
yuuji@58
|
334 (lambda () (interactive) (yahtml-insert-tag nil "KBD")))
|
yuuji@54
|
335 (samp "Sample display" .
|
yuuji@58
|
336 (lambda () (interactive) (yahtml-insert-tag nil "SAMP")))
|
yuuji@54
|
337 (strong "Strong" .
|
yuuji@58
|
338 (lambda () (interactive) (yahtml-insert-tag nil "STRONG")))
|
yuuji@54
|
339 (VAR "Variable notation" .
|
yuuji@58
|
340 (lambda () (interactive) (yahtml-insert-tag nil "VAR")))
|
yuuji@54
|
341 )))
|
yuuji@54
|
342 (setq yahtml-menu-map-typeface (make-sparse-keymap "typeface tags"))
|
yuuji@54
|
343 (yahtml-define-menu
|
yuuji@54
|
344 yahtml-menu-map-typeface
|
yuuji@54
|
345 (nreverse
|
yuuji@54
|
346 '((b "Bold" .
|
yuuji@58
|
347 (lambda () (interactive) (yahtml-insert-tag nil "B")))
|
yuuji@54
|
348 (i "Italic" .
|
yuuji@58
|
349 (lambda () (interactive) (yahtml-insert-tag nil "I")))
|
yuuji@54
|
350 (tt "Typewriter" .
|
yuuji@58
|
351 (lambda () (interactive) (yahtml-insert-tag nil "TT")))
|
yuuji@54
|
352 (u "Underlined" .
|
yuuji@58
|
353 (lambda () (interactive) (yahtml-insert-tag nil "U")))
|
yuuji@54
|
354 )))
|
yuuji@54
|
355 (setq yahtml-menu-map-listing (make-sparse-keymap "listing"))
|
yuuji@54
|
356 (yahtml-define-menu
|
yuuji@54
|
357 yahtml-menu-map-listing
|
yuuji@54
|
358 (nreverse
|
yuuji@58
|
359 '((ul "Unordered" .
|
yuuji@58
|
360 (lambda () (interactive) (yahtml-insert-begend nil "UL")))
|
yuuji@58
|
361 (ol "Ordered" .
|
yuuji@58
|
362 (lambda () (interactive) (yahtml-insert-begend nil "OL")))
|
yuuji@58
|
363 (dl "Definition" .
|
yuuji@58
|
364 (lambda () (interactive) (yahtml-insert-begend nil "DL")))
|
yuuji@54
|
365 )))
|
yuuji@57
|
366 (setq yahtml-menu-map-item (make-sparse-keymap "item"))
|
yuuji@57
|
367 (yahtml-define-menu
|
yuuji@57
|
368 yahtml-menu-map-item
|
yuuji@57
|
369 (nreverse
|
yuuji@57
|
370 '((li "Simple item" .
|
yuuji@57
|
371 (lambda () (interactive) (yahtml-insert-single "li")))
|
yuuji@57
|
372 (dt "Define term" .
|
yuuji@57
|
373 (lambda () (interactive) (yahtml-insert-single "dt")))
|
yuuji@57
|
374 (dd "Description of term" .
|
yuuji@57
|
375 (lambda () (interactive) (yahtml-insert-single "dd")))
|
yuuji@57
|
376 )))
|
yuuji@54
|
377 (define-key yahtml-mode-map [menu-bar yahtml]
|
yuuji@54
|
378 (cons "yahtml" yahtml-menu-map))
|
yuuji@58
|
379 (let ((keys (where-is-internal 'fill-paragraph global-map)))
|
yuuji@58
|
380 (while keys
|
yuuji@58
|
381 (define-key yahtml-mode-map (car keys) 'yahtml-fill-paragraph)
|
yuuji@58
|
382 (setq keys (cdr keys))))
|
yuuji@54
|
383 (yahtml-define-menu
|
yuuji@54
|
384 yahtml-menu-map
|
yuuji@54
|
385 (nreverse
|
yuuji@54
|
386 (list
|
yuuji@54
|
387 (cons (list 'sect "Sectioning")
|
yuuji@54
|
388 (cons "sectioning" yahtml-menu-map-sectioning))
|
yuuji@54
|
389 (cons (list 'list "Listing")
|
yuuji@54
|
390 (cons "Listing" yahtml-menu-map-listing))
|
yuuji@57
|
391 (cons (list 'item "Item")
|
yuuji@57
|
392 (cons "Itemizing" yahtml-menu-map-item));;;
|
yuuji@54
|
393 (cons (list 'logi "Logical tags")
|
yuuji@54
|
394 (cons "logical" yahtml-menu-map-logical))
|
yuuji@54
|
395 (cons (list 'type "Typeface tags")
|
yuuji@54
|
396 (cons "typeface" yahtml-menu-map-typeface))
|
yuuji@54
|
397 )))
|
yuuji@54
|
398 ))
|
yuuji@54
|
399
|
yuuji@54
|
400 (defun yahtml-collect-url-history ()
|
yuuji@54
|
401 "Collect urls from global history file."
|
yuuji@54
|
402 (interactive)
|
yuuji@54
|
403 (save-excursion
|
yuuji@54
|
404 (set-buffer
|
yuuji@54
|
405 (find-file-noselect (expand-file-name yahtml-url-history-file)))
|
yuuji@54
|
406 (goto-char (point-min))
|
yuuji@54
|
407 (setq yahtml-urls)
|
yuuji@54
|
408 (message "Collecting global history...")
|
yuuji@54
|
409 (while (re-search-forward "^[A-Za-z]+:" nil t)
|
yuuji@54
|
410 (setq yahtml-urls
|
yuuji@54
|
411 (cons (list
|
yuuji@54
|
412 (buffer-substring
|
yuuji@54
|
413 (progn (beginning-of-line) (point))
|
yuuji@54
|
414 (progn (skip-chars-forward "^ ") (point))))
|
yuuji@54
|
415 yahtml-urls)))
|
yuuji@54
|
416 (message "Collecting global history...Done")))
|
yuuji@54
|
417
|
yuuji@57
|
418 ;;; ----------- Completion ----------
|
yuuji@57
|
419 (defvar yahtml-last-begend "html")
|
yuuji@58
|
420 (defun yahtml-insert-begend (&optional region env)
|
yuuji@57
|
421 "Insert <cmd> ... </cmd>."
|
yuuji@57
|
422 (interactive "P")
|
yuuji@58
|
423 (let*((completion-ignore-case t)
|
yuuji@58
|
424 (cmd
|
yuuji@58
|
425 (or env
|
yuuji@58
|
426 (YaTeX-cplread-with-learning
|
yuuji@57
|
427 (format "Environment(default %s): " yahtml-last-begend)
|
yuuji@58
|
428 'yahtml-env-table 'yahtml-user-env-table 'yahtml-tmp-env-table)))
|
yuuji@58
|
429 (bolp (save-excursion
|
yuuji@58
|
430 (skip-chars-backward " \t" (point-beginning-of-line)) (bolp)))
|
yuuji@58
|
431 (cc (current-column)))
|
yuuji@57
|
432 (if (string< "" cmd) (setq yahtml-last-begend cmd))
|
yuuji@58
|
433 (setq yahtml-last-begend
|
yuuji@58
|
434 (or (cdr (assoc yahtml-last-begend yahtml-env-table))
|
yuuji@58
|
435 yahtml-last-begend))
|
yuuji@57
|
436 (setq cmd yahtml-last-begend)
|
yuuji@57
|
437 (if region
|
yuuji@57
|
438 (let ((beg (region-beginning))
|
yuuji@57
|
439 (end (region-end))
|
yuuji@57
|
440 (addin (yahtml-addin cmd)))
|
yuuji@57
|
441 (goto-char end)
|
yuuji@57
|
442 (insert (format "</%s>%s" cmd (if bolp "\n" "")))
|
yuuji@57
|
443 (goto-char beg)
|
yuuji@57
|
444 (insert (format "<%s%s>%s" cmd addin (if bolp "\n" ""))))
|
yuuji@58
|
445 (insert (format "<%s%s>" cmd (yahtml-addin cmd)))
|
yuuji@58
|
446 (save-excursion
|
yuuji@58
|
447 (if bolp (progn
|
yuuji@58
|
448 (insert "\n")
|
yuuji@58
|
449 (indent-to-column cc)
|
yuuji@58
|
450 (insert (format "</%s>" cmd)))
|
yuuji@58
|
451 (insert (format "</%s>" cmd))))
|
yuuji@58
|
452 (if bolp (yahtml-intelligent-newline nil)))))
|
yuuji@57
|
453
|
yuuji@57
|
454 (defun yahtml-insert-begend-region ()
|
yuuji@57
|
455 "Call yahtml-insert-begend in the region mode."
|
yuuji@57
|
456 (interactive)
|
yuuji@57
|
457 (yahtml-insert-begend t))
|
yuuji@57
|
458
|
yuuji@57
|
459
|
yuuji@54
|
460 (defun yahtml-insert-form (&optional form)
|
yuuji@57
|
461 "Insert <FORM option=\"argument\">."
|
yuuji@54
|
462 (interactive)
|
yuuji@54
|
463 (or form
|
yuuji@54
|
464 (setq form
|
yuuji@54
|
465 (YaTeX-cplread-with-learning
|
yuuji@54
|
466 "Form: "
|
yuuji@54
|
467 'yahtml-form-table 'yahtml-user-form-table
|
yuuji@54
|
468 'yahtml-tmp-form-table)))
|
yuuji@57
|
469 (let ((p (point)) q)
|
yuuji@58
|
470 (insert (format "<%s%s>" form (yahtml-addin form)))
|
yuuji@57
|
471 ;;(indent-relative-maybe)
|
yuuji@57
|
472 (if (cdr (assoc form yahtml-form-table))
|
yuuji@57
|
473 (save-excursion (insert (format "</%s>" form))))
|
yuuji@54
|
474 (if (search-backward "\"\"" p t) (forward-char 1))))
|
yuuji@54
|
475
|
yuuji@59
|
476 ;;; ---------- Add-in ----------
|
yuuji@54
|
477 (defun yahtml-addin (form)
|
yuuji@54
|
478 "Check add-in function's existence and call it if exists."
|
yuuji@58
|
479 (let ((addin (concat "yahtml:" (downcase form))) s)
|
yuuji@58
|
480 (if (and (intern-soft addin) (fboundp (intern-soft addin))
|
yuuji@58
|
481 (stringp (setq s (funcall (intern addin))))
|
yuuji@58
|
482 (string< "" s))
|
yuuji@58
|
483 (concat " " s)
|
yuuji@54
|
484 "")))
|
yuuji@54
|
485
|
yuuji@59
|
486
|
yuuji@59
|
487 (defvar yahtml-completing-buffer nil)
|
yuuji@59
|
488 (defun yahtml-collect-labels (&optional file)
|
yuuji@59
|
489 "Collect current buffers label (<a name=...>).
|
yuuji@59
|
490 If optional argument FILE is specified collect labels in FILE."
|
yuuji@59
|
491 (let (list)
|
yuuji@59
|
492 (save-excursion
|
yuuji@59
|
493 (set-buffer yahtml-completing-buffer)
|
yuuji@59
|
494 (if file (set-buffer (find-file-noselect file)))
|
yuuji@59
|
495 (save-excursion
|
yuuji@59
|
496 (goto-char (point-min))
|
yuuji@59
|
497 (while (re-search-forward "<a\\b" nil t)
|
yuuji@59
|
498 (skip-chars-forward " \t\n")
|
yuuji@59
|
499 (if (looking-at "name\\s *=\\s *\"?#?\\([^\">]+\\)\"?>")
|
yuuji@59
|
500 (setq list (cons
|
yuuji@59
|
501 (list (concat "#" (YaTeX-match-string 1)))
|
yuuji@59
|
502 list))))
|
yuuji@59
|
503 list)))
|
yuuji@59
|
504 )
|
yuuji@59
|
505
|
yuuji@58
|
506 (defvar yahtml-url-completion-map nil "Key map used in URL completion buffer")
|
yuuji@58
|
507 (if yahtml-url-completion-map nil
|
yuuji@58
|
508 (setq yahtml-url-completion-map
|
yuuji@58
|
509 (copy-keymap minibuffer-local-completion-map))
|
yuuji@58
|
510 (define-key yahtml-url-completion-map "\t" 'yahtml-complete-url)
|
yuuji@58
|
511 (define-key yahtml-url-completion-map " " 'yahtml-complete-url)
|
yuuji@58
|
512 )
|
yuuji@58
|
513
|
yuuji@58
|
514 (defun yahtml-complete-url ()
|
yuuji@58
|
515 "Complete external URL from history or local file name."
|
yuuji@58
|
516 (interactive)
|
yuuji@59
|
517 (let (initial i2 cmpl path dir file listfunc beg labels (p (point)))
|
yuuji@58
|
518 (setq initial (buffer-string))
|
yuuji@58
|
519 (cond
|
yuuji@58
|
520 ((string-match "^http:" initial)
|
yuuji@58
|
521 (setq cmpl (try-completion initial yahtml-urls)
|
yuuji@58
|
522 listfunc (list 'lambda nil
|
yuuji@58
|
523 (list 'all-completions initial 'yahtml-urls))
|
yuuji@58
|
524 beg (point-min)))
|
yuuji@59
|
525 ((setq beg (string-match "#" initial))
|
yuuji@59
|
526 (or (equal beg 0) ;begin with #
|
yuuji@59
|
527 (progn
|
yuuji@59
|
528 (setq path (substring initial 0 beg))
|
yuuji@59
|
529 (if (string-match "^/" path)
|
yuuji@59
|
530 (setq path (yahtml-url-to-path path)))))
|
yuuji@59
|
531 (setq initial (substring initial beg))
|
yuuji@59
|
532 (setq labels (yahtml-collect-labels path)
|
yuuji@59
|
533 cmpl (try-completion initial labels)
|
yuuji@59
|
534 listfunc (list 'lambda ()
|
yuuji@59
|
535 (list 'all-completions
|
yuuji@59
|
536 initial (list 'quote labels)))
|
yuuji@59
|
537 beg (+ (point-min) beg)))
|
yuuji@58
|
538 (t
|
yuuji@58
|
539 (setq path (if (string-match "^/" initial)
|
yuuji@58
|
540 (yahtml-url-to-path initial)
|
yuuji@58
|
541 initial))
|
yuuji@58
|
542 (setq dir (or (file-name-directory path) ".")
|
yuuji@58
|
543 file (file-name-nondirectory path)
|
yuuji@58
|
544 initial file
|
yuuji@58
|
545 cmpl (file-name-completion file dir)
|
yuuji@58
|
546 listfunc (list 'lambda nil
|
yuuji@58
|
547 (list 'file-name-all-completions
|
yuuji@58
|
548 file dir))
|
yuuji@58
|
549 beg (save-excursion (skip-chars-backward "^/") (point)))))
|
yuuji@58
|
550 (cond
|
yuuji@58
|
551 ((stringp cmpl)
|
yuuji@58
|
552 (if (string= initial cmpl)
|
yuuji@58
|
553 (with-output-to-temp-buffer "*Completions*"
|
yuuji@58
|
554 (princ "Possible completinos are:\n")
|
yuuji@58
|
555 (princ
|
yuuji@58
|
556 (mapconcat '(lambda (x) x) (funcall listfunc) "\n")))
|
yuuji@58
|
557 (delete-region (point) beg)
|
yuuji@58
|
558 (insert cmpl)))
|
yuuji@58
|
559 ((null cmpl)
|
yuuji@58
|
560 (ding))
|
yuuji@58
|
561 ((eq t cmpl)
|
yuuji@58
|
562 (save-excursion
|
yuuji@58
|
563 (unwind-protect
|
yuuji@58
|
564 (progn
|
yuuji@58
|
565 (goto-char p)
|
yuuji@58
|
566 (insert " [Sole completion]"))
|
yuuji@58
|
567 (delete-region p (point-max))))))))
|
yuuji@58
|
568
|
yuuji@57
|
569 (defun yahtml:a ()
|
yuuji@54
|
570 "Add-in function for <a>"
|
yuuji@58
|
571 (or yahtml-urls (yahtml-collect-url-history))
|
yuuji@59
|
572 (setq yahtml-completing-buffer (current-buffer))
|
yuuji@57
|
573 ; (concat "href=\""
|
yuuji@57
|
574 ; (completing-read "href: " yahtml-urls)
|
yuuji@57
|
575 ; "\"")
|
yuuji@58
|
576 (message "(H)ref (N)ame?")
|
yuuji@58
|
577 (cond
|
yuuji@59
|
578 ((string-match "[nN]" (char-to-string (read-char)))
|
yuuji@59
|
579 (concat "name=\"" (read-string "name: ") "\""))
|
yuuji@59
|
580 (t
|
yuuji@58
|
581 (concat "href=\""
|
yuuji@58
|
582 (read-from-minibuffer "href: " "" yahtml-url-completion-map)
|
yuuji@59
|
583 "\""))))
|
yuuji@57
|
584
|
yuuji@57
|
585 (defun yahtml:img ()
|
yuuji@57
|
586 "Add-in function for <img>"
|
yuuji@54
|
587 (or yahtml-urls (yahtml-collect-url-history))
|
yuuji@58
|
588 (let ((src (read-file-name "src: " "" nil nil ""))
|
yuuji@59
|
589 (alg (completing-read "align: " '(("top") ("middle") ("bottom"))))
|
yuuji@59
|
590 (alt (read-string "alt: ")))
|
yuuji@57
|
591 (concat "src=\"" src "\""
|
yuuji@59
|
592 (if (string< "" alg) (concat " align=\"" alg "\""))
|
yuuji@59
|
593 (if (string< "" alt) (concat " alt=\"" alt "\"")))))
|
yuuji@57
|
594
|
yuuji@57
|
595 (defun yahtml:form ()
|
yuuji@57
|
596 "Add-in function `form' input format"
|
yuuji@57
|
597 (concat
|
yuuji@57
|
598 " method=" (completing-read "Method: " '(("POST") ("GET")) nil t)
|
yuuji@57
|
599 " action=\"" (read-string "Action: ") "\""
|
yuuji@57
|
600 ))
|
yuuji@57
|
601
|
yuuji@57
|
602 (defun yahtml:select ()
|
yuuji@57
|
603 "Add-in function for `select' input format"
|
yuuji@57
|
604 (setq yahtml-last-single-cmd "option")
|
yuuji@57
|
605 (concat " name=\"" (read-string "name: ") "\""))
|
yuuji@57
|
606
|
yuuji@58
|
607 (defun yahtml:ol ()
|
yuuji@58
|
608 (setq yahtml-last-single-cmd "li") "")
|
yuuji@58
|
609 (defun yahtml:ul ()
|
yuuji@58
|
610 (setq yahtml-last-single-cmd "li") "")
|
yuuji@58
|
611 (defun yahtml:dl ()
|
yuuji@58
|
612 (setq yahtml-last-single-cmd "dt") "")
|
yuuji@58
|
613 (defun yahtml:dt ()
|
yuuji@58
|
614 (setq yahtml-last-single-cmd "dd") "")
|
yuuji@58
|
615
|
yuuji@58
|
616
|
yuuji@57
|
617 (defvar yahtml-input-types
|
yuuji@57
|
618 '(("text") ("password") ("checkbox") ("radio") ("submit")
|
yuuji@57
|
619 ("reset") ("image") ("hidden")))
|
yuuji@57
|
620
|
yuuji@57
|
621 (defun yahtml:input ()
|
yuuji@57
|
622 "Add-in function for `input' form"
|
yuuji@57
|
623 (let (name type value checked (size "") (maxlength ""))
|
yuuji@57
|
624 (setq name (read-string "name: ")
|
yuuji@57
|
625 type (completing-read "type (default=text): "
|
yuuji@57
|
626 yahtml-input-types nil t)
|
yuuji@57
|
627 value (read-string "value: "))
|
yuuji@57
|
628 (if (string-match "text\\|password\\|^$" type)
|
yuuji@57
|
629 (setq size (read-string "size: ")
|
yuuji@57
|
630 maxlength (read-string "maxlength: ")))
|
yuuji@57
|
631 (concat
|
yuuji@57
|
632 "name=\"" name "\""
|
yuuji@57
|
633 (if (string< "" type) (concat " type=\"" type "\""))
|
yuuji@57
|
634 (if (string< "" value) (concat " value=\"" value "\""))
|
yuuji@57
|
635 (if (string< "" size) (concat " size=\"" size "\""))
|
yuuji@57
|
636 (if (string< "" maxlength) (concat " maxlength=\"" maxlength "\""))
|
yuuji@57
|
637 )))
|
yuuji@59
|
638
|
yuuji@59
|
639 (defun yahtml:textarea ()
|
yuuji@59
|
640 "Add-in function for `textarea'"
|
yuuji@59
|
641 (interactive)
|
yuuji@59
|
642 (let (name rows cols)
|
yuuji@59
|
643 (setq name (read-string "Name: ")
|
yuuji@59
|
644 cols (read-string "Columns: "
|
yuuji@59
|
645 rows (read-string "Rows: ")))
|
yuuji@59
|
646 (concat
|
yuuji@59
|
647 (concat (if yahtml-prefer-upcases "NAME=" "name=")
|
yuuji@59
|
648 "\"" name "\"")
|
yuuji@59
|
649 (if (string< "" cols)
|
yuuji@59
|
650 (concat " " (if yahtml-prefer-upcases "COLS" "cols") "=" cols))
|
yuuji@59
|
651 (if (string< "" rows)
|
yuuji@59
|
652 (concat " " (if yahtml-prefer-upcases "ROWS" "rows") "=" rows)))))
|
yuuji@59
|
653
|
yuuji@59
|
654
|
yuuji@59
|
655 ;;; ---------- Simple tag ----------
|
yuuji@58
|
656 (defun yahtml-insert-tag (region-mode &optional tag)
|
yuuji@54
|
657 "Insert <TAG> </TAG> and put cursor inside of them."
|
yuuji@58
|
658 (interactive "P")
|
yuuji@58
|
659 (or tag
|
yuuji@58
|
660 (setq tag
|
yuuji@58
|
661 (YaTeX-cplread-with-learning
|
yuuji@58
|
662 (format "Tag %s(default %s): "
|
yuuji@58
|
663 (if region-mode "region: " "") yahtml-last-typeface-cmd)
|
yuuji@58
|
664 'yahtml-typeface-table 'yahtml-user-typeface-table
|
yuuji@58
|
665 'yahtml-tmp-typeface-table)))
|
yuuji@58
|
666 (if (string= "" tag) (setq tag yahtml-last-typeface-cmd))
|
yuuji@58
|
667 (setq tag (funcall (if yahtml-prefer-upcases 'upcase 'downcase) tag)
|
yuuji@58
|
668 yahtml-last-typeface-cmd tag)
|
yuuji@58
|
669 (if region-mode
|
yuuji@58
|
670 (if (if (string< "19" emacs-version) (mark t) (mark))
|
yuuji@58
|
671 (save-excursion
|
yuuji@58
|
672 (if (> (point) (mark)) (exchange-point-and-mark))
|
yuuji@58
|
673 (insert "<" tag ">")
|
yuuji@58
|
674 (exchange-point-and-mark)
|
yuuji@58
|
675 (insert "</" tag ">"))
|
yuuji@58
|
676 (message "No mark set now"))
|
yuuji@58
|
677 (insert (format "<%s> " tag))
|
yuuji@58
|
678 (save-excursion (insert (format "</%s>" tag)))))
|
yuuji@54
|
679
|
yuuji@57
|
680 (defun yahtml-insert-single (cmd)
|
yuuji@57
|
681 "Insert <CMD>."
|
yuuji@57
|
682 (interactive
|
yuuji@58
|
683 (list
|
yuuji@58
|
684 (let ((completion-ignore-case t))
|
yuuji@58
|
685 (YaTeX-cplread-with-learning
|
yuuji@58
|
686 (format "Command%s: "
|
yuuji@58
|
687 (if yahtml-last-single-cmd
|
yuuji@58
|
688 (concat "(default " yahtml-last-single-cmd ")") ""))
|
yuuji@58
|
689 'yahtml-single-cmd-table 'yahtml-user-single-cmd-table
|
yuuji@58
|
690 'yahtml-tmp-single-cmd-table))))
|
yuuji@58
|
691 (if (string< "" cmd) (setq yahtml-last-single-cmd cmd))
|
yuuji@57
|
692 (setq cmd (funcall (if yahtml-prefer-upcases 'upcase 'downcase) cmd))
|
yuuji@58
|
693 (setq yahtml-last-single-cmd
|
yuuji@58
|
694 (or (cdr (assoc yahtml-last-single-cmd yahtml-single-cmd-table))
|
yuuji@58
|
695 yahtml-last-single-cmd))
|
yuuji@57
|
696 (insert (format "<%s>" yahtml-last-single-cmd)))
|
yuuji@57
|
697
|
yuuji@57
|
698 ;;; ---------- Jump ----------
|
yuuji@57
|
699 (defun yahtml-on-href-p ()
|
yuuji@57
|
700 "Check if point is on href clause."
|
yuuji@57
|
701 (let ((p (point)) cmd)
|
yuuji@57
|
702 (save-excursion
|
yuuji@58
|
703 (or (bobp) (skip-chars-backward "^ \t\n"))
|
yuuji@58
|
704 (and (looking-at "href\\s *=\\s *\"?\\([^\"> \t\n]+\\)\"?")
|
yuuji@57
|
705 (< p (match-end 0))
|
yuuji@57
|
706 (YaTeX-match-string 1)))))
|
yuuji@57
|
707
|
yuuji@58
|
708 (defun yahtml-netscape-sentinel (proc mes)
|
yuuji@58
|
709 (cond
|
yuuji@58
|
710 ((null (buffer-name (process-buffer proc)))
|
yuuji@58
|
711 (set-process-buffer proc nil))
|
yuuji@58
|
712 ((eq (process-status proc) 'exit)
|
yuuji@58
|
713 (let ((cb (current-buffer)))
|
yuuji@58
|
714 (set-buffer (process-buffer proc))
|
yuuji@58
|
715 (goto-char (point-min))
|
yuuji@58
|
716 (if (search-forward "not running" nil t)
|
yuuji@58
|
717 (progn
|
yuuji@58
|
718 (message "Starting netscape...")
|
yuuji@58
|
719 (start-process
|
yuuji@58
|
720 "browser" (process-buffer proc) shell-file-name "-c"
|
yuuji@58
|
721 (format "%s %s" yahtml-www-browser
|
yuuji@58
|
722 (get 'yahtml-netscape-sentinel 'url)))
|
yuuji@58
|
723 (message "Starting netscape...Done")))
|
yuuji@58
|
724 (set-buffer cb)))))
|
yuuji@58
|
725
|
yuuji@58
|
726 (defvar yahtml-browser-process nil)
|
yuuji@58
|
727
|
yuuji@58
|
728 (defun yahtml-browse-html (href)
|
yuuji@58
|
729 "Call WWW Browser to see HREF."
|
yuuji@58
|
730 (let ((pb "* WWW Browser *") (cb (current-buffer)))
|
yuuji@58
|
731 (cond
|
yuuji@58
|
732 ((string-match "[Nn]etscape" yahtml-www-browser)
|
yuuji@58
|
733 (if (get-buffer pb)
|
yuuji@58
|
734 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
|
yuuji@58
|
735 (put 'yahtml-netscape-sentinel 'url href)
|
yuuji@58
|
736 (set-process-sentinel
|
yuuji@58
|
737 (setq yahtml-browser-process
|
yuuji@58
|
738 (start-process
|
yuuji@58
|
739 "browser" pb shell-file-name "-c"
|
yuuji@58
|
740 (format "%s -remote 'openURL(%s)'" yahtml-www-browser href)))
|
yuuji@58
|
741 'yahtml-netscape-sentinel))
|
yuuji@58
|
742 ((and (string= "w3" yahtml-www-browser) (fboundp 'w3-fetch))
|
yuuji@58
|
743 (w3-fetch href))
|
yuuji@58
|
744 ((stringp yahtml-www-browser)
|
yuuji@58
|
745 (if (eq (process-status yahtml-browser-process) 'run)
|
yuuji@58
|
746 (message "%s is already running" yahtml-www-browser)
|
yuuji@58
|
747 (setq yahtml-browser-process
|
yuuji@58
|
748 (start-process
|
yuuji@58
|
749 "browser" "* WWW Browser *" shell-file-name
|
yuuji@58
|
750 (format "%s %s" yahtml-www-browser href)))))
|
yuuji@58
|
751 (t
|
yuuji@58
|
752 (message "Sorry, jump across http is not supported.")))))
|
yuuji@58
|
753
|
yuuji@57
|
754 (defun yahtml-goto-corresponding-href (&optional other)
|
yuuji@57
|
755 "Go to corresponding name."
|
yuuji@57
|
756 (let ((href (yahtml-on-href-p)) file name)
|
yuuji@57
|
757 (if href
|
yuuji@57
|
758 (cond
|
yuuji@57
|
759 ((string-match "^http:" href)
|
yuuji@58
|
760 (yahtml-browse-html href))
|
yuuji@57
|
761 (t (setq file (substring href 0 (string-match "#" href)))
|
yuuji@57
|
762 (if (string-match "#" href)
|
yuuji@57
|
763 (setq name (substring href (1+ (string-match "#" href)))))
|
yuuji@57
|
764 (if (string< "" file)
|
yuuji@57
|
765 (progn
|
yuuji@57
|
766 (if (string-match "/$" file)
|
yuuji@58
|
767 (setq file (concat file yahtml-directory-index)))
|
yuuji@58
|
768 (if (string-match "^/" file)
|
yuuji@58
|
769 (setq file (yahtml-url-to-path file)))
|
yuuji@57
|
770 (if other (YaTeX-switch-to-buffer-other-window file)
|
yuuji@57
|
771 (YaTeX-switch-to-buffer file))))
|
yuuji@57
|
772 (if name
|
yuuji@57
|
773 (progn (set-mark-command nil) (yahtml-jump-to-name name)))
|
yuuji@57
|
774 t)))))
|
yuuji@57
|
775
|
yuuji@57
|
776 (defun yahtml-jump-to-name (name)
|
yuuji@57
|
777 "Jump to html's named tag."
|
yuuji@57
|
778 (setq name (format "name\\s *=\\s *\"?%s\"?" name))
|
yuuji@57
|
779 (or (and (re-search-forward name nil t) (goto-char (match-beginning 0)))
|
yuuji@57
|
780 (and (re-search-backward name nil t) (goto-char (match-beginning 0)))
|
yuuji@57
|
781 (message "Named tag `%s' not found" (substring href 1))))
|
yuuji@57
|
782
|
yuuji@57
|
783 (defun yahtml-on-begend-p (&optional p)
|
yuuji@57
|
784 "Check if point is on begend clause."
|
yuuji@58
|
785 (let ((p (point)) cmd (case-fold-search t))
|
yuuji@57
|
786 (save-excursion
|
yuuji@57
|
787 (if p (goto-char p))
|
yuuji@58
|
788 (if (equal (char-after (point)) ?<) (forward-char 1))
|
yuuji@57
|
789 (if (and (re-search-backward "<" nil t)
|
yuuji@57
|
790 (looking-at
|
yuuji@57
|
791 (concat "<\\(/?" yahtml-command-regexp "\\)\\b"))
|
yuuji@57
|
792 (condition-case nil
|
yuuji@58
|
793 (forward-list 1)
|
yuuji@58
|
794 (error nil))
|
yuuji@57
|
795 (< p (point)))
|
yuuji@57
|
796 (YaTeX-match-string 1)))))
|
yuuji@57
|
797
|
yuuji@58
|
798 (defun yahtml-goto-corresponding-begend (&optional noerr)
|
yuuji@58
|
799 "Go to corresponding opening/closing tag.
|
yuuji@58
|
800 Optional argument NOERR causes no error for unballanced tag."
|
yuuji@58
|
801 (let ((cmd (yahtml-on-begend-p)) m0
|
yuuji@58
|
802 (p (point)) (case-fold-search t) func str (nest 0))
|
yuuji@58
|
803 (cond
|
yuuji@58
|
804 (cmd
|
yuuji@58
|
805 (setq m0 (match-beginning 0))
|
yuuji@58
|
806 (if (= (aref cmd 0) ?/) ;on </cmd> line
|
yuuji@58
|
807 (setq cmd (substring cmd 1)
|
yuuji@58
|
808 str (format "\\(<%s\\)\\|\\(</%s\\)" cmd cmd)
|
yuuji@58
|
809 func 're-search-backward)
|
yuuji@58
|
810 (setq str (format "\\(</%s\\)\\|\\(<%s\\)" cmd cmd)
|
yuuji@58
|
811 func 're-search-forward))
|
yuuji@58
|
812 (while (and (>= nest 0) (funcall func str nil t))
|
yuuji@58
|
813 (if (equal m0 (match-beginning 0))
|
yuuji@58
|
814 nil
|
yuuji@58
|
815 (setq nest (+ nest (if (match-beginning 1) -1 1)))))
|
yuuji@58
|
816 (if (< nest 0)
|
yuuji@58
|
817 (goto-char (match-beginning 0))
|
yuuji@58
|
818 (funcall
|
yuuji@58
|
819 (if noerr 'message 'error)
|
yuuji@58
|
820 "Corresponding tag of `%s' not found." cmd)
|
yuuji@58
|
821 (goto-char p)
|
yuuji@58
|
822 nil))
|
yuuji@58
|
823 (t nil))))
|
yuuji@58
|
824
|
yuuji@58
|
825 (defun yahtml-current-tag ()
|
yuuji@58
|
826 "Return the current tag name."
|
yuuji@58
|
827 (save-excursion
|
yuuji@58
|
828 (let ((p (point)) b tag)
|
yuuji@58
|
829 (or (bobp)
|
yuuji@58
|
830 (looking-at "<")
|
yuuji@58
|
831 (progn (skip-chars-backward "^<") (forward-char -1)))
|
yuuji@58
|
832 (setq b (point))
|
yuuji@58
|
833 (skip-chars-forward "<")
|
yuuji@58
|
834 (setq tag (buffer-substring
|
yuuji@58
|
835 (point) (progn (skip-chars-forward "^ \t\n") (point))))
|
yuuji@58
|
836 (goto-char b)
|
yuuji@58
|
837 (forward-list 1)
|
yuuji@58
|
838 (and (< p (point)) tag))))
|
yuuji@58
|
839
|
yuuji@58
|
840
|
yuuji@58
|
841 (defun yahtml-goto-corresponding-img ()
|
yuuji@58
|
842 "View image on point"
|
yuuji@58
|
843 (let ((tag (yahtml-current-tag)) image (p (point)) (case-fold-search t))
|
yuuji@58
|
844 (if (and tag
|
yuuji@58
|
845 (string-match "img" tag)
|
yuuji@58
|
846 (save-excursion
|
yuuji@58
|
847 (re-search-backward "<\\s *img" nil t)
|
yuuji@59
|
848 (re-search-forward "src=\"?\\([^\"> ]+\\)\"?")
|
yuuji@58
|
849 (match-beginning 1)
|
yuuji@58
|
850 (setq image
|
yuuji@58
|
851 (buffer-substring (match-beginning 1) (match-end 1)))))
|
yuuji@58
|
852 (progn
|
yuuji@58
|
853 (message "Invoking %s %s..." yahtml-image-viewer image)
|
yuuji@58
|
854 (start-process
|
yuuji@58
|
855 "Viewer" " * Image Viewer *" shell-file-name "-c"
|
yuuji@58
|
856 (concat yahtml-image-viewer " " image))
|
yuuji@58
|
857 (message "Invoking %s %s...Done" yahtml-image-viewer image)))))
|
yuuji@57
|
858
|
yuuji@57
|
859 (defun yahtml-goto-corresponding-* (&optional other)
|
yuuji@57
|
860 "Go to corresponding object."
|
yuuji@57
|
861 (interactive)
|
yuuji@57
|
862 (cond
|
yuuji@57
|
863 ((yahtml-goto-corresponding-href other))
|
yuuji@58
|
864 ((yahtml-goto-corresponding-img))
|
yuuji@58
|
865 ((yahtml-goto-corresponding-begend))
|
yuuji@57
|
866 ))
|
yuuji@57
|
867
|
yuuji@57
|
868 (defun yahtml-goto-corresponding-*-other-window ()
|
yuuji@57
|
869 "Go to corresponding object."
|
yuuji@57
|
870 (interactive)
|
yuuji@57
|
871 (yahtml-goto-corresponding-* t))
|
yuuji@57
|
872
|
yuuji@58
|
873 ;;; ---------- killing ----------
|
yuuji@58
|
874 (defun yahtml-kill-begend (&optional whole)
|
yuuji@58
|
875 (let ((tag (yahtml-on-begend-p)) (p (make-marker)) (q (make-marker)))
|
yuuji@58
|
876 (if tag
|
yuuji@58
|
877 (progn
|
yuuji@58
|
878 (or (looking-at "<")
|
yuuji@58
|
879 (progn (skip-chars-backward "^<") (forward-char -1)))
|
yuuji@58
|
880 (set-marker p (point))
|
yuuji@58
|
881 (yahtml-goto-corresponding-begend)
|
yuuji@58
|
882 (or (looking-at "<")
|
yuuji@58
|
883 (progn (skip-chars-backward "^<") (forward-char -1)))
|
yuuji@58
|
884 (delete-region (point) (progn (forward-list 1) (point)))
|
yuuji@58
|
885 (set-marker q (point))
|
yuuji@58
|
886 (beginning-of-line)
|
yuuji@58
|
887 (if (looking-at "^\\s *$")
|
yuuji@58
|
888 (delete-region (point) (progn (forward-line 1) (point))))
|
yuuji@58
|
889 (goto-char p)
|
yuuji@58
|
890 (delete-region (point) (progn (forward-list 1) (point)))
|
yuuji@58
|
891 (if (looking-at "^\\s *$")
|
yuuji@58
|
892 (delete-region (point) (progn (forward-line 1) (point))))
|
yuuji@58
|
893 (if whole (delete-region p q))
|
yuuji@58
|
894 tag))))
|
yuuji@58
|
895
|
yuuji@58
|
896 (defun yahtml-kill-* (whole)
|
yuuji@58
|
897 "Kill current position's HTML tag (set)."
|
yuuji@58
|
898 (interactive "P")
|
yuuji@58
|
899 (cond
|
yuuji@58
|
900 ((yahtml-kill-begend whole))
|
yuuji@58
|
901 ))
|
yuuji@58
|
902
|
yuuji@58
|
903
|
yuuji@58
|
904 ;;; ---------- changing ----------
|
yuuji@58
|
905 (defun yahtml-change-begend ()
|
yuuji@58
|
906 (let ((tag (yahtml-on-begend-p))
|
yuuji@58
|
907 (completion-ignore-case t)
|
yuuji@58
|
908 (p (point)) (q (make-marker))
|
yuuji@58
|
909 (default (append yahtml-env-table yahtml-typeface-table))
|
yuuji@58
|
910 (user (append yahtml-user-env-table yahtml-user-typeface-table))
|
yuuji@58
|
911 (tmp (append yahtml-tmp-env-table yahtml-tmp-typeface-table))
|
yuuji@59
|
912 href b1 e1)
|
yuuji@59
|
913 (cond
|
yuuji@59
|
914 (tag
|
yuuji@59
|
915 (cond
|
yuuji@59
|
916 ((and (equal tag "a")
|
yuuji@59
|
917 (save-excursion
|
yuuji@59
|
918 (and
|
yuuji@59
|
919 (re-search-backward "<a" nil t)
|
yuuji@59
|
920 (goto-char (match-end 0))
|
yuuji@59
|
921 (skip-chars-forward " \t\n")
|
yuuji@59
|
922 (>= p (point))
|
yuuji@59
|
923 (looking-at "href\\s *=\\s *\"?\\([^\"> \t\n]+\\)\"?")
|
yuuji@59
|
924 (< p (match-end 0)))))
|
yuuji@59
|
925 (setq b1 (match-beginning 1) e1 (match-end 1)
|
yuuji@59
|
926 href (read-from-minibuffer
|
yuuji@59
|
927 "Change href to: " "" yahtml-url-completion-map))
|
yuuji@59
|
928 (if (string< "" href)
|
yuuji@59
|
929 (progn
|
yuuji@59
|
930 (delete-region b1 e1)
|
yuuji@59
|
931 (goto-char b1)
|
yuuji@59
|
932 (insert href))))
|
yuuji@59
|
933 (t
|
yuuji@58
|
934 (save-excursion
|
yuuji@58
|
935 (if (= (aref tag 0) ?/) (setq tag (substring tag 1)))
|
yuuji@58
|
936 (or (= (char-after (point)) ?<) (skip-chars-backward "^<"))
|
yuuji@58
|
937 (skip-chars-forward "^A-Za-z")
|
yuuji@58
|
938 (set-marker q (point))
|
yuuji@58
|
939 (setq p (point))
|
yuuji@58
|
940 (yahtml-goto-corresponding-begend)
|
yuuji@58
|
941 (or (= (char-after (point)) ?<)
|
yuuji@58
|
942 (skip-chars-backward "^<"))
|
yuuji@58
|
943 (skip-chars-forward "^A-Za-z")
|
yuuji@58
|
944 (if (= (char-after (1- (point))) ?/)
|
yuuji@58
|
945 (progn
|
yuuji@58
|
946 (set-marker q (point))
|
yuuji@58
|
947 (goto-char p)))
|
yuuji@58
|
948 (setq tag (YaTeX-cplread-with-learning
|
yuuji@58
|
949 (format "Change `%s' to(default %s): "
|
yuuji@58
|
950 tag yahtml-last-begend)
|
yuuji@58
|
951 'default 'user 'tmp))
|
yuuji@58
|
952 (delete-region (point) (progn (skip-chars-forward "^>") (point)))
|
yuuji@58
|
953 (if (string= "" tag) (setq tag yahtml-last-begend))
|
yuuji@58
|
954 (setq yahtml-last-begend
|
yuuji@58
|
955 (or (cdr (assoc tag yahtml-env-table)) tag)
|
yuuji@58
|
956 tag yahtml-last-begend)
|
yuuji@58
|
957 (insert (format "%s%s" tag (yahtml-addin tag)))
|
yuuji@58
|
958 (goto-char q)
|
yuuji@58
|
959 (delete-region (point) (progn (skip-chars-forward "^>") (point)))
|
yuuji@59
|
960 (insert tag))))))))
|
yuuji@58
|
961
|
yuuji@58
|
962 (defun yahtml-change-* ()
|
yuuji@58
|
963 "Change current position's HTML tag (set)."
|
yuuji@58
|
964 (interactive)
|
yuuji@58
|
965 (cond
|
yuuji@58
|
966 ((yahtml-change-begend))
|
yuuji@58
|
967 ))
|
yuuji@58
|
968
|
yuuji@57
|
969 ;;; ---------- commenting ----------
|
yuuji@57
|
970 (defun yahtml-comment-region (beg end)
|
yuuji@57
|
971 (interactive "r")
|
yuuji@57
|
972 (comment-region beg end nil))
|
yuuji@57
|
973
|
yuuji@57
|
974 (defun yahtml-uncomment-region (beg end)
|
yuuji@57
|
975 (interactive "r")
|
yuuji@57
|
976 (comment-region beg end '(4)))
|
yuuji@57
|
977
|
yuuji@57
|
978
|
yuuji@57
|
979
|
yuuji@58
|
980 ;;; ---------- filling ----------
|
yuuji@58
|
981 (defun yahtml-fill-paragraph (arg)
|
yuuji@58
|
982 (interactive "P")
|
yuuji@58
|
983 (let ((case-fold-search t) (p (point)))
|
yuuji@58
|
984 (save-excursion
|
yuuji@58
|
985 (fill-region-as-paragraph
|
yuuji@58
|
986 (progn (re-search-backward paragraph-start nil t)
|
yuuji@58
|
987 (or (save-excursion
|
yuuji@58
|
988 (goto-char (match-end 0))
|
yuuji@58
|
989 (if (looking-at "[ \t]*$")
|
yuuji@58
|
990 (progn (forward-line 1) (point))))
|
yuuji@58
|
991 (point)))
|
yuuji@58
|
992 (progn (goto-char p)
|
yuuji@58
|
993 (re-search-forward paragraph-start nil t)
|
yuuji@58
|
994 (match-beginning 0))))))
|
yuuji@58
|
995
|
yuuji@58
|
996 ;;;
|
yuuji@58
|
997 ;;; ---------- indentation ----------
|
yuuji@58
|
998 ;;;
|
yuuji@58
|
999 (defvar yahtml-hate-too-deep-indentation nil)
|
yuuji@58
|
1000 (defun yahtml-indent-line ()
|
yuuji@58
|
1001 (interactive)
|
yuuji@59
|
1002 (let ((envs "[uod]l\\|table\\|t[rhd]\\|select\\|a\\b")
|
yuuji@59
|
1003 (itms "<\\(dt\\|dd\\|li\\|t[rdh]\\|option\\)>")
|
yuuji@58
|
1004 inenv p col peol (case-fold-search t))
|
yuuji@58
|
1005 (save-excursion
|
yuuji@58
|
1006 (beginning-of-line)
|
yuuji@58
|
1007 (setq inenv (or (YaTeX-inner-environment) "html")
|
yuuji@58
|
1008 col (get 'YaTeX-inner-environment 'indent)
|
yuuji@58
|
1009 p (get 'YaTeX-inner-environment 'point)
|
yuuji@58
|
1010 op))
|
yuuji@58
|
1011 (save-excursion
|
yuuji@58
|
1012 (cond
|
yuuji@58
|
1013 ((string-match envs inenv)
|
yuuji@58
|
1014 (save-excursion
|
yuuji@58
|
1015 (beginning-of-line)
|
yuuji@58
|
1016 (skip-chars-forward " \t")
|
yuuji@58
|
1017 (cond
|
yuuji@58
|
1018 ((looking-at (concat "</\\(" envs "\\)>"))
|
yuuji@58
|
1019 (YaTeX-reindent col))
|
yuuji@58
|
1020 ((or (looking-at itms)
|
yuuji@58
|
1021 (and yahtml-hate-too-deep-indentation
|
yuuji@58
|
1022 (looking-at (concat "<" envs))))
|
yuuji@58
|
1023 (YaTeX-reindent (+ col YaTeX-environment-indent)))
|
yuuji@58
|
1024 ((and (< p (point))
|
yuuji@58
|
1025 (save-excursion
|
yuuji@58
|
1026 (and
|
yuuji@58
|
1027 ;;(re-search-backward itms p t)
|
yuuji@58
|
1028 (setq op (point))
|
yuuji@58
|
1029 (goto-char p)
|
yuuji@58
|
1030 (re-search-forward itms op t)
|
yuuji@58
|
1031 (goto-char (match-end 0))
|
yuuji@58
|
1032 (skip-chars-forward " \t")
|
yuuji@58
|
1033 (setq col (current-column)))))
|
yuuji@58
|
1034 (YaTeX-reindent col))
|
yuuji@58
|
1035 (t
|
yuuji@58
|
1036 (YaTeX-reindent (+ col YaTeX-environment-indent)))))))
|
yuuji@58
|
1037 (and (bolp) (skip-chars-forward " \t"))
|
yuuji@58
|
1038 (if (and (setq inenv (yahtml-on-begend-p))
|
yuuji@58
|
1039 (string-match (concat "^\\(" envs "\\)") inenv))
|
yuuji@58
|
1040 (save-excursion
|
yuuji@58
|
1041 (setq peol (point-end-of-line))
|
yuuji@58
|
1042 (or (= (char-after (point)) ?<)
|
yuuji@58
|
1043 (progn (skip-chars-backward "^<") (forward-char -1)))
|
yuuji@58
|
1044 (setq col (current-column))
|
yuuji@58
|
1045 (if (and (yahtml-goto-corresponding-begend t)
|
yuuji@58
|
1046 (> (point) peol)) ;if on the different line
|
yuuji@58
|
1047 (YaTeX-reindent col)))))
|
yuuji@58
|
1048 (and (bolp) (skip-chars-forward " \t"))))
|
yuuji@58
|
1049
|
yuuji@58
|
1050 ;(defun yahtml-fill-item ()
|
yuuji@58
|
1051 ; "Fill item HTML version"
|
yuuji@58
|
1052 ; (interactive)
|
yuuji@58
|
1053 ; (let (inenv p fill-prefix peol (case-fold-search t))
|
yuuji@58
|
1054 ; (setq inenv (or (YaTeX-inner-environment) "html")
|
yuuji@58
|
1055 ; p (get 'YaTeX-inner-environment 'point))
|
yuuji@58
|
1056 ; (cond
|
yuuji@58
|
1057 ; ((string-match "^[uod]l" inenv)
|
yuuji@58
|
1058 ; (save-excursion
|
yuuji@58
|
1059 ; (if (re-search-backward "<\\(d[td]\\|li\\)>[ \t\n]*" p t)
|
yuuji@58
|
1060 ; (progn
|
yuuji@58
|
1061 ; (goto-char (match-end 0))
|
yuuji@58
|
1062 ; (setq col (current-column)))
|
yuuji@58
|
1063 ; (error "No <li>, <dt>, <dd>")))
|
yuuji@58
|
1064 ; (save-excursion
|
yuuji@58
|
1065 ; (end-of-line)
|
yuuji@58
|
1066 ; (setq peol (point))
|
yuuji@58
|
1067 ; (newline)
|
yuuji@58
|
1068 ; (indent-to-column col)
|
yuuji@58
|
1069 ; (setq fill-prefix (buffer-substring (point) (1+ peol)))
|
yuuji@58
|
1070 ; (delete-region (point) peol)
|
yuuji@58
|
1071 ; (fill-region-as-paragraph
|
yuuji@58
|
1072 ; (progn (re-search-backward paragraph-start nil t) (point))
|
yuuji@58
|
1073 ; (progn (re-search-forward paragraph-start nil t 2)
|
yuuji@58
|
1074 ; (match-beginning 0)))))
|
yuuji@58
|
1075 ; (t nil))))
|
yuuji@58
|
1076
|
yuuji@58
|
1077 ;;;
|
yuuji@58
|
1078 ;;; ---------- Browsing ----------
|
yuuji@58
|
1079 ;;;
|
yuuji@58
|
1080 (defun yahtml-browse-menu ()
|
yuuji@58
|
1081 "Browsing menu"
|
yuuji@58
|
1082 (interactive)
|
yuuji@58
|
1083 (message "B)rowse R)eload...")
|
yuuji@58
|
1084 (let ((c (char-to-string (read-char))))
|
yuuji@58
|
1085 (cond
|
yuuji@58
|
1086 ((string-match "[bj]" c)
|
yuuji@58
|
1087 (yahtml-browse-current-file))
|
yuuji@58
|
1088 ((string-match "r" c)
|
yuuji@58
|
1089 (yahtml-browse-reload)))))
|
yuuji@58
|
1090
|
yuuji@58
|
1091 (defun yahtml-file-to-url (file)
|
yuuji@58
|
1092 "Convert local unix file name to URL.
|
yuuji@58
|
1093 If no matches found in yahtml-path-url-alist, return raw file name."
|
yuuji@58
|
1094 (let ((list yahtml-path-url-alist) p url)
|
yuuji@58
|
1095 (if (file-directory-p file)
|
yuuji@58
|
1096 (setq file (expand-file-name yahtml-directory-index file))
|
yuuji@58
|
1097 (setq file (expand-file-name file)))
|
yuuji@58
|
1098 (while list
|
yuuji@58
|
1099 (if (string-match (concat "^" (regexp-quote (car (car list)))) file)
|
yuuji@58
|
1100 (setq url (cdr (car list))
|
yuuji@58
|
1101 file (substring file (match-end 0))
|
yuuji@58
|
1102 url (concat url file)
|
yuuji@58
|
1103 list nil))
|
yuuji@58
|
1104 (setq list (cdr list)))
|
yuuji@58
|
1105 (or url (concat "file:" file))))
|
yuuji@58
|
1106
|
yuuji@58
|
1107 (defun yahtml-url-to-path (file &optional basedir)
|
yuuji@58
|
1108 "Convert local URL name to unix file name."
|
yuuji@58
|
1109 (let ((list yahtml-path-url-alist) url realpath docroot
|
yuuji@58
|
1110 (dirsufp (string-match "/$" file)))
|
yuuji@58
|
1111 (setq basedir (or basedir
|
yuuji@58
|
1112 (file-name-directory
|
yuuji@58
|
1113 (expand-file-name default-directory))))
|
yuuji@58
|
1114 (cond
|
yuuji@58
|
1115 ((string-match "^/" file)
|
yuuji@58
|
1116 (while list
|
yuuji@59
|
1117 (if (file-directory-p (car (car list)))
|
yuuji@58
|
1118 (progn
|
yuuji@58
|
1119 (setq url (cdr (car list)))
|
yuuji@58
|
1120 (if (string-match "\\(http://[^/]*\\)/" url)
|
yuuji@58
|
1121 (setq docroot (substring url (match-end 1)))
|
yuuji@58
|
1122 (setq docroot url))
|
yuuji@59
|
1123 (if (string-match (concat "^" (regexp-quote docroot)) file)
|
yuuji@58
|
1124 (setq realpath
|
yuuji@58
|
1125 (expand-file-name
|
yuuji@58
|
1126 (substring
|
yuuji@59
|
1127 file
|
yuuji@59
|
1128 (if (= (aref file (1- (match-end 0))) ?/)
|
yuuji@59
|
1129 (match-end 0) ; "/foo"
|
yuuji@59
|
1130 (min (1+ (match-end 0)) (length file)))) ; "/~foo"
|
yuuji@58
|
1131 (car (car list)))))
|
yuuji@58
|
1132 (if realpath
|
yuuji@58
|
1133 (progn (setq list nil)
|
yuuji@58
|
1134 (if (and dirsufp (not (string-match "/$" realpath)))
|
yuuji@58
|
1135 (setq realpath (concat realpath "/")))))))
|
yuuji@58
|
1136 (setq list (cdr list)))
|
yuuji@58
|
1137 realpath)
|
yuuji@58
|
1138 (t file))))
|
yuuji@58
|
1139
|
yuuji@58
|
1140 (defun yahtml-browse-current-file ()
|
yuuji@58
|
1141 "Call WWW browser on current file."
|
yuuji@58
|
1142 (interactive)
|
yuuji@58
|
1143 (basic-save-buffer)
|
yuuji@58
|
1144 (yahtml-browse-html (yahtml-file-to-url (buffer-file-name))))
|
yuuji@58
|
1145
|
yuuji@58
|
1146 (defun yahtml-browse-reload ()
|
yuuji@58
|
1147 "Send `reload' event to netzscape."
|
yuuji@58
|
1148 (let ((pb "* WWW Browser *") (cb (current-buffer)))
|
yuuji@58
|
1149 (cond
|
yuuji@58
|
1150 ((string-match "[Nn]etscape" yahtml-www-browser)
|
yuuji@58
|
1151 (if (get-buffer pb)
|
yuuji@58
|
1152 (progn (set-buffer pb) (erase-buffer) (set-buffer cb)))
|
yuuji@58
|
1153 ;;(or (get 'yahtml-netscape-sentinel 'url)
|
yuuji@58
|
1154 ;; (error "Reload should be called after Browsing."))
|
yuuji@58
|
1155 (put 'yahtml-netscape-sentinel 'url
|
yuuji@58
|
1156 (yahtml-file-to-url (buffer-file-name)))
|
yuuji@58
|
1157 (basic-save-buffer)
|
yuuji@58
|
1158 (set-process-sentinel
|
yuuji@58
|
1159 (setq yahtml-browser-process
|
yuuji@58
|
1160 (start-process
|
yuuji@58
|
1161 "browser" pb shell-file-name "-c"
|
yuuji@58
|
1162 (format "%s -remote 'reload'" yahtml-www-browser)))
|
yuuji@58
|
1163 'yahtml-netscape-sentinel))
|
yuuji@58
|
1164 (t
|
yuuji@58
|
1165 (message "Sorry, RELOAD is supported only for Netscape.")))))
|
yuuji@58
|
1166
|
yuuji@58
|
1167 ;;; ---------- Intelligent newline ----------
|
yuuji@58
|
1168 (defun yahtml-intelligent-newline (arg)
|
yuuji@58
|
1169 "Intelligent newline for HTML"
|
yuuji@58
|
1170 (interactive "P")
|
yuuji@58
|
1171 (let ((env (downcase (or (YaTeX-inner-environment) "html"))) func)
|
yuuji@58
|
1172 (setq func (intern-soft (concat "yahtml-intelligent-newline-" env)))
|
yuuji@58
|
1173 (end-of-line)
|
yuuji@58
|
1174 (newline)
|
yuuji@58
|
1175 (if (and env func (fboundp func))
|
yuuji@58
|
1176 (funcall func))))
|
yuuji@58
|
1177
|
yuuji@58
|
1178 (defun yahtml-intelligent-newline-ul ()
|
yuuji@58
|
1179 (interactive)
|
yuuji@58
|
1180 (insert (if yahtml-prefer-upcases "<LI> " "<li> "))
|
yuuji@58
|
1181 (yahtml-indent-line))
|
yuuji@58
|
1182
|
yuuji@58
|
1183 (fset 'yahtml-intelligent-newline-ol 'yahtml-intelligent-newline-ul)
|
yuuji@58
|
1184
|
yuuji@58
|
1185 (defun yahtml-intelligent-newline-dl ()
|
yuuji@58
|
1186 (interactive)
|
yuuji@58
|
1187 (let ((case-fold-search t))
|
yuuji@58
|
1188 (if (save-excursion
|
yuuji@58
|
1189 (re-search-backward "<\\(\\(dt\\)\\|\\(dd\\)\\)>"
|
yuuji@58
|
1190 (get 'YaTeX-inner-environment 'point) t))
|
yuuji@58
|
1191 (cond
|
yuuji@58
|
1192 ((match-beginning 2)
|
yuuji@58
|
1193 (insert (if yahtml-prefer-upcases "<DD> " "<dd> "))
|
yuuji@58
|
1194 (setq yahtml-last-single-cmd "dt"))
|
yuuji@58
|
1195 ((match-beginning 3)
|
yuuji@58
|
1196 (insert (if yahtml-prefer-upcases "<DT> " "<dt> "))
|
yuuji@58
|
1197 (setq yahtml-last-single-cmd "dd")))
|
yuuji@58
|
1198 (insert (if yahtml-prefer-upcases "<DT> " "<dt> ")))
|
yuuji@58
|
1199 (yahtml-indent-line)))
|
yuuji@58
|
1200
|
yuuji@59
|
1201 (defun yahtml-intelligent-newline-select ()
|
yuuji@59
|
1202 (interactive)
|
yuuji@59
|
1203 (insert "<" (if yahtml-prefer-upcases "OPTION" "option") "> ")
|
yuuji@59
|
1204 (yahtml-indent-line))
|
yuuji@59
|
1205
|
yuuji@58
|
1206 ;;; ---------- Marking ----------
|
yuuji@58
|
1207 (defun yahtml-mark-begend ()
|
yuuji@58
|
1208 "Mark current tag"
|
yuuji@58
|
1209 (interactive)
|
yuuji@58
|
1210 (YaTeX-beginning-of-environment)
|
yuuji@58
|
1211 (let ((p (point)))
|
yuuji@58
|
1212 (save-excursion
|
yuuji@58
|
1213 (skip-chars-backward " \t" (point-beginning-of-line))
|
yuuji@58
|
1214 (if (bolp) (setq p (point))))
|
yuuji@58
|
1215 (push-mark p t))
|
yuuji@58
|
1216 (yahtml-goto-corresponding-begend)
|
yuuji@58
|
1217 (forward-list 1)
|
yuuji@58
|
1218 (if (eolp) (forward-char 1)))
|
yuuji@58
|
1219
|
yuuji@59
|
1220 ;;; ---------- complete marks ----------
|
yuuji@59
|
1221 (defun yahtml-complete-mark ()
|
yuuji@59
|
1222 "Complete >, <, &asterisk, and "e."
|
yuuji@59
|
1223 (interactive)
|
yuuji@59
|
1224 (message "1:< 2:> 3:& 4:\"")
|
yuuji@59
|
1225 (let ((c (read-char)))
|
yuuji@59
|
1226 (setq c (if (or (< c ?0) (> c ?5))
|
yuuji@59
|
1227 (string-match (regexp-quote (char-to-string c)) "<>&\"")
|
yuuji@59
|
1228 (- c ?1)))
|
yuuji@59
|
1229 (if (or (< c 0) (> c 4))
|
yuuji@59
|
1230 nil
|
yuuji@59
|
1231 (insert (format "&%s;" (nth c '("lt" "gt" "amp" "quot")))))))
|
yuuji@59
|
1232
|
yuuji@59
|
1233
|
yuuji@57
|
1234 ;;; ---------- ----------
|
yuuji@57
|
1235 ;;; ---------- ----------
|
yuuji@57
|
1236
|
yuuji@57
|
1237 ;;;
|
yuuji@57
|
1238 ;;hilit19
|
yuuji@57
|
1239 ;;;
|
yuuji@57
|
1240 (defvar yahtml-default-face-table
|
yuuji@57
|
1241 '(
|
yuuji@57
|
1242 (form black/ivory white/hex-442233 italic)
|
yuuji@57
|
1243 ))
|
yuuji@57
|
1244 (defvar yahtml-hilit-patterns-alist
|
yuuji@57
|
1245 '(
|
yuuji@57
|
1246 ;; comments
|
yuuji@57
|
1247 ("<!--\\s " "-->" comment)
|
yuuji@57
|
1248 ;; include&exec
|
yuuji@57
|
1249 ("<!--#\\(include\\|exec\\)" "-->" include)
|
yuuji@57
|
1250 ;; string
|
yuuji@57
|
1251 (hilit-string-find 39 string)
|
yuuji@57
|
1252 (yahtml-hilit-region-tag "\\(em\\|strong\\)" bold)
|
yuuji@57
|
1253 ("</?[uod]l>" 0 decl)
|
yuuji@57
|
1254 ("<\\(di\\|dt\\|li\\|dd\\)>" 0 label)
|
yuuji@57
|
1255 ("<a\\s +href" "</a>" crossref)
|
yuuji@57
|
1256 ("</?\\sw+>" 0 decl)
|
yuuji@57
|
1257 ("<form" "</form" form)
|
yuuji@57
|
1258 ))
|
yuuji@57
|
1259
|
yuuji@57
|
1260 (defun yahtml-hilit-region-tag (tag)
|
yuuji@57
|
1261 "Return list of start/end point of <TAG> form."
|
yuuji@57
|
1262 (if (re-search-forward (concat "<" tag ">") nil t)
|
yuuji@57
|
1263 (let ((m0 (match-beginning 0)))
|
yuuji@57
|
1264 (skip-chars-forward " \t\n")
|
yuuji@57
|
1265 (cons (point)
|
yuuji@57
|
1266 (progn (re-search-forward (concat "</" tag ">") nil t)
|
yuuji@58
|
1267 (match-beginning 0))))))
|
yuuji@57
|
1268
|
yuuji@57
|
1269 ;(setq hilit-patterns-alist (delq (assq 'yahtml-mode hilit-patterns-alist) hilit-patterns-alist))
|
yuuji@57
|
1270 (cond
|
yuuji@57
|
1271 ((and (featurep 'hilit19) (featurep 'yatex19))
|
yuuji@57
|
1272 (or (assq 'yahtml-mode hilit-patterns-alist)
|
yuuji@57
|
1273 (setq hilit-patterns-alist
|
yuuji@57
|
1274 (cons (cons 'yahtml-mode yahtml-hilit-patterns-alist)
|
yuuji@57
|
1275 hilit-patterns-alist)))))
|
yuuji@57
|
1276
|
yuuji@54
|
1277 (provide 'yahtml)
|
yuuji@54
|
1278
|
yuuji@54
|
1279 ; Local variables:
|
yuuji@54
|
1280 ; fill-prefix: ";;; "
|
yuuji@54
|
1281 ; paragraph-start: "^$\\|\\|;;;$"
|
yuuji@54
|
1282 ; paragraph-separate: "^$\\|\\|;;;$"
|
yuuji@54
|
1283 ; End:
|