yatex

view yahtml.el @ 54:2d45e43fb35f

Full support of English documents
author yuuji
date Mon, 24 Apr 1995 14:42:53 +0000
parents cb9afa9c1213
children 18f4939986e6
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; (c ) 1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp, pcs39334@ascii-net.or.jp]
3 ;;; Last modified Mon Apr 24 22:52:17 1995 on pajero
4 ;;; This is PURELY tentative.
5 ;;; $Id$
7 ;;;[Commentary]
8 ;;;
9 ;;; It is assumed you are already familiar with YaTeX. The following
10 ;;; completing featureas are available: ([prefix] means `C-c' by default)
11 ;;;
12 ;;; * [prefix] b X Complete environments such as `H1' which
13 ;;; normally requires newline.
14 ;;; * [prefix] s Complete declarative notations such as
15 ;;; `<a href="foo.html"> .... </a>'
16 ;;; * [prefix] l Complete typeface-changing commands such as
17 ;;; `<i> ... </i>' or `<samp> ... </samp>'
18 ;;; * menu-bar yahtml Complete all by selecting a menu item (Though I
19 ;;; hate menu, this is most useful)
20 ;;;
21 ;;; NOTE! This program is truly tentative. If you find some bright
22 ;;; future with this, please send me a mail to drive me to maintain this :)
25 (require 'yatex)
26 (defvar yahtml-prefix-map (copy-keymap YaTeX-prefix-map))
27 (defvar yahtml-mode-map nil
28 "Keymap used in yahtml-mode.")
29 (if yahtml-mode-map nil
30 (setq yahtml-mode-map (make-sparse-keymap))
31 (define-key yahtml-mode-map YaTeX-prefix yahtml-prefix-map)
32 (define-key yahtml-mode-map "\M-\C-@" 'YaTeX-mark-environment)
33 (define-key yahtml-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment)
34 (define-key yahtml-mode-map "\M-\C-e" 'YaTeX-end-of-environment))
36 (defvar yahtml-syntax-table nil
37 "*Syntax table for typesetting buffer")
39 (if yahtml-syntax-table nil
40 (setq yahtml-syntax-table
41 (make-syntax-table (standard-syntax-table)))
42 (modify-syntax-entry ?\< "(" yahtml-syntax-table)
43 (modify-syntax-entry ?\> ")" yahtml-syntax-table)
44 )
45 (defvar yahtml-command-regexp "[A-Za-z0-9]+"
46 "Regexp of constituent of html commands.")
48 ;;; Completion tables for `form'
49 (defvar yahtml-form-table '(("a") ("form")))
50 (defvar yahtml-user-form-table nil)
51 (defvar yahtml-tmp-form-table nil)
53 (defvar yahtml-env-table
54 '(("html") ("head") ("title") ("body") ("dl")
55 ("h1") ("h2") ("h3") ("h4") ("h5") ("h6")))
57 ;;; Completion tables for typeface designator
58 (defvar yahtml-typeface-table
59 '(("defn") ("em") ("cite") ("code") ("kbd") ("samp")
60 ("strong") ("var") ("b") ("i") ("tt") ("u"))
61 "Default completion table of typeface designator")
62 (defvar yahtml-user-typeface-table nil)
63 (defvar yahtml-tmp-typeface-table nil)
65 (defvar yahtml-prefer-upcases nil)
66 (cond
67 (yahtml-prefer-upcases
68 (setq yahtml-form-table
69 (mapcar (function (lambda (list) (list (upcase (car list)))))
70 yahtml-form-table))
71 (setq yahtml-env-table
72 (mapcar (function (lambda (list) (list (upcase (car list)))))
73 yahtml-env-table))
74 (setq yahtml-typeface-table
75 (mapcar (function (lambda (list) (list (upcase (car list)))))
76 yahtml-typeface-table))))
78 (defun yahtml-mode ()
79 (interactive)
80 (yatex-mode)
81 (setq major-mode 'yahtml-mode
82 mode-name "yahtml")
83 (make-local-variable 'YaTeX-ec) (setq YaTeX-ec "")
84 (make-local-variable 'YaTeX-struct-begin) (setq YaTeX-struct-begin "<%1>")
85 (make-local-variable 'YaTeX-struct-end) (setq YaTeX-struct-end "</%1>")
86 (mapcar 'make-local-variable
87 '(env-table user-env-table tmp-env-table))
88 (setq env-table yahtml-env-table)
89 (mapcar 'make-local-variable
90 '(singlecmd-table user-singlecmd-table tmp-singlecmd-table))
91 (make-local-variable 'YaTeX-struct-name-regexp)
92 (setq YaTeX-struct-name-regexp "[^/]+")
93 (make-local-variable 'YaTeX-prefix-map)
94 (make-local-variable 'YaTeX-command-token-regexp)
95 (setq YaTeX-command-token-regexp yahtml-command-regexp)
96 (setq YaTeX-prefix-map yahtml-prefix-map)
97 (set-syntax-table yahtml-syntax-table)
98 (use-local-map yahtml-mode-map)
99 (YaTeX-define-key "s" 'yahtml-insert-form)
100 (YaTeX-define-key "l" 'yahtml-insert-tag)
101 (if YaTeX-no-begend-shortcut nil
102 (YaTeX-define-begend-key "bh" "HTML")
103 (YaTeX-define-begend-key "bH" "HEAD")
104 (YaTeX-define-begend-key "bt" "TITLE")
105 (YaTeX-define-begend-key "bb" "BODY")
106 (YaTeX-define-begend-key "bd" "DL")
107 (YaTeX-define-begend-key "b1" "H1")
108 (YaTeX-define-begend-key "b2" "H2")
109 (YaTeX-define-begend-key "b3" "H3"))
110 (run-hooks 'yahtml-mode-hook))
112 (defun yahtml-define-menu (keymap bindlist)
113 (mapcar
114 (function
115 (lambda (bind)
116 (define-key keymap (vector (car bind)) (cdr bind))))
117 bindlist))
119 (defvar yahtml-menu-map nil "Menu map of yahtml")
120 (defvar yahtml-menu-map-sectioning nil "Menu map of yahtml(sectioning)")
121 (defvar yahtml-menu-map-listing nil "Menu map of yahtml(listing)")
122 (defvar yahtml-menu-map-logical nil "Menu map of yahtml(logical tags)")
123 (defvar yahtml-menu-map-typeface nil "Menu map of yahtml(typeface tags)")
125 ;;; Variables for mosaic url history
126 (defvar yahtml-urls nil "Alist of global history")
127 (defvar yahtml-url-history-file "~/.mosaic-global-history"
128 "File name of url history")
130 (cond
131 ((and YaTeX-emacs-19 (null yahtml-menu-map))
132 (setq yahtml-menu-map (make-sparse-keymap "yahtml menu"))
133 (setq yahtml-menu-map-sectioning (make-sparse-keymap "sectioning menu"))
134 (yahtml-define-menu
135 yahtml-menu-map-sectioning
136 (nreverse
137 '((1 "H1" . (lambda () (interactive) (yahtml-insert-begin-end "H1" nil)))
138 (2 "H2" . (lambda () (interactive) (yahtml-insert-begin-end "H2" nil)))
139 (3 "H3" . (lambda () (interactive) (yahtml-insert-begin-end "H3" nil)))
140 (4 "H4" . (lambda () (interactive) (yahtml-insert-begin-end "H4" nil)))
141 (5 "H5" . (lambda () (interactive) (yahtml-insert-begin-end "H5" nil)))
142 (6 "H6" . (lambda () (interactive) (yahtml-insert-begin-end "H6" nil)))
143 )))
144 (setq yahtml-menu-map-logical (make-sparse-keymap "logical tags"))
145 (yahtml-define-menu
146 yahtml-menu-map-logical
147 (nreverse
148 '((em "Embolden" .
149 (lambda () (interactive) (yahtml-insert-tag "EM")))
150 (defn "Define a word" .
151 (lambda () (interactive) (yahtml-insert-tag "DEFN")))
152 (cite "Citation" .
153 (lambda () (interactive) (yahtml-insert-tag "CITE")))
154 (code "Code" .
155 (lambda () (interactive) (yahtml-insert-tag "CODE")))
156 (kbd "Keyboard" .
157 (lambda () (interactive) (yahtml-insert-tag "KBD")))
158 (samp "Sample display" .
159 (lambda () (interactive) (yahtml-insert-tag "SAMP")))
160 (strong "Strong" .
161 (lambda () (interactive) (yahtml-insert-tag "STRONG")))
162 (VAR "Variable notation" .
163 (lambda () (interactive) (yahtml-insert-tag "VAR")))
164 )))
165 (setq yahtml-menu-map-typeface (make-sparse-keymap "typeface tags"))
166 (yahtml-define-menu
167 yahtml-menu-map-typeface
168 (nreverse
169 '((b "Bold" .
170 (lambda () (interactive) (yahtml-insert-tag "B")))
171 (i "Italic" .
172 (lambda () (interactive) (yahtml-insert-tag "I")))
173 (tt "Typewriter" .
174 (lambda () (interactive) (yahtml-insert-tag "TT")))
175 (u "Underlined" .
176 (lambda () (interactive) (yahtml-insert-tag "U")))
177 )))
178 (setq yahtml-menu-map-listing (make-sparse-keymap "listing"))
179 (yahtml-define-menu
180 yahtml-menu-map-listing
181 (nreverse
182 '((ul "Unnumbered" .
183 (lambda () (interactive) (yahtml-insert-begin-end "UL" nil)))
184 (ol "Numbered" .
185 (lambda () (interactive) (yahtml-insert-begin-end "OL" nil)))
186 (dl "Description" .
187 (lambda () (interactive) (yahtml-insert-begin-end "DL" nil)))
188 )))
189 (define-key yahtml-mode-map [menu-bar yahtml]
190 (cons "yahtml" yahtml-menu-map))
191 (yahtml-define-menu
192 yahtml-menu-map
193 (nreverse
194 (list
195 (cons (list 'sect "Sectioning")
196 (cons "sectioning" yahtml-menu-map-sectioning))
197 (cons (list 'list "Listing")
198 (cons "Listing" yahtml-menu-map-listing))
199 (cons (list 'logi "Logical tags")
200 (cons "logical" yahtml-menu-map-logical))
201 (cons (list 'type "Typeface tags")
202 (cons "typeface" yahtml-menu-map-typeface))
203 )))
204 ))
206 (defun yahtml-collect-url-history ()
207 "Collect urls from global history file."
208 (interactive)
209 (save-excursion
210 (set-buffer
211 (find-file-noselect (expand-file-name yahtml-url-history-file)))
212 (goto-char (point-min))
213 (setq yahtml-urls)
214 (message "Collecting global history...")
215 (while (re-search-forward "^[A-Za-z]+:" nil t)
216 (setq yahtml-urls
217 (cons (list
218 (buffer-substring
219 (progn (beginning-of-line) (point))
220 (progn (skip-chars-forward "^ ") (point))))
221 yahtml-urls)))
222 (message "Collecting global history...Done")))
224 (defun yahtml-insert-form (&optional form)
225 "Insert <FORM option=\"argument\"> </FORM>."
226 (interactive)
227 (or form
228 (setq form
229 (YaTeX-cplread-with-learning
230 "Form: "
231 'yahtml-form-table 'yahtml-user-form-table
232 'yahtml-tmp-form-table)))
233 (let ((p (point)))
234 (insert (format "<%s%s>\n" form (yahtml-addin (downcase form))))
235 (indent-relative-maybe)
236 (save-excursion (insert (format "</%s>" form)))
237 (if (search-backward "\"\"" p t) (forward-char 1))))
239 (defun yahtml-addin (form)
240 "Check add-in function's existence and call it if exists."
241 (let ((addin (concat "yahtml::" form)))
242 (if (and (intern-soft addin) (fboundp (intern-soft addin)))
243 (concat " " (funcall (intern addin)))
244 "")))
246 (defun yahtml::a ()
247 "Add-in function for <a>"
248 (or yahtml-urls (yahtml-collect-url-history))
249 (concat "href=\""
250 (completing-read "href: " yahtml-urls)
251 "\""))
253 (defun yahtml-insert-begin-end (env &optional region-mode)
254 "Insert <ENV> \\n </ENV> by calling YaTeX-insert-begin-end."
255 (interactive "sEnv: ")
256 (setq env (funcall (if yahtml-prefer-upcases 'upcase 'downcase) env))
257 (YaTeX-insert-begin-end env region-mode))
259 (defun yahtml-insert-tag (&optional tag)
260 "Insert <TAG> </TAG> and put cursor inside of them."
261 (interactive)
262 (or tag
263 (setq tag
264 (YaTeX-cplread-with-learning
265 "Tag: "
266 'yahtml-typeface-table 'yahtml-user-typeface-table
267 'yahtml-tmp-typeface-table)))
268 (setq tag (funcall (if yahtml-prefer-upcases 'upcase 'downcase) tag))
269 (insert (format "<%s> " tag))
270 (save-excursion (insert (format "</%s>" tag))))
272 (provide 'yahtml)
274 ; Local variables:
275 ; fill-prefix: ";;; "
276 ; paragraph-start: "^$\\| \\|;;;$"
277 ; paragraph-separate: "^$\\| \\|;;;$"
278 ; End: