yatex
diff 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 diff
1.1 --- a/yahtml.el Fri May 06 21:14:11 1994 +0000 1.2 +++ b/yahtml.el Mon Apr 24 14:42:53 1995 +0000 1.3 @@ -1,10 +1,26 @@ 1.4 ;;; -*- Emacs-Lisp -*- 1.5 ;;; (c ) 1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp, pcs39334@ascii-net.or.jp] 1.6 -;;; Last modified Wed May 4 05:31:29 1994 on 98fa 1.7 -;;; This is sample hack definition for HTML. 1.8 +;;; Last modified Mon Apr 24 22:52:17 1995 on pajero 1.9 +;;; This is PURELY tentative. 1.10 +;;; $Id$ 1.11 + 1.12 +;;;[Commentary] 1.13 ;;; 1.14 -;;; [Purely tentative version] 1.15 -;;; $Id$ 1.16 +;;; It is assumed you are already familiar with YaTeX. The following 1.17 +;;; completing featureas are available: ([prefix] means `C-c' by default) 1.18 +;;; 1.19 +;;; * [prefix] b X Complete environments such as `H1' which 1.20 +;;; normally requires newline. 1.21 +;;; * [prefix] s Complete declarative notations such as 1.22 +;;; `<a href="foo.html"> .... </a>' 1.23 +;;; * [prefix] l Complete typeface-changing commands such as 1.24 +;;; `<i> ... </i>' or `<samp> ... </samp>' 1.25 +;;; * menu-bar yahtml Complete all by selecting a menu item (Though I 1.26 +;;; hate menu, this is most useful) 1.27 +;;; 1.28 +;;; NOTE! This program is truly tentative. If you find some bright 1.29 +;;; future with this, please send me a mail to drive me to maintain this :) 1.30 + 1.31 1.32 (require 'yatex) 1.33 (defvar yahtml-prefix-map (copy-keymap YaTeX-prefix-map)) 1.34 @@ -12,31 +28,251 @@ 1.35 "Keymap used in yahtml-mode.") 1.36 (if yahtml-mode-map nil 1.37 (setq yahtml-mode-map (make-sparse-keymap)) 1.38 - (define-key yahtml-mode-map YaTeX-prefix yahtml-prefix-map)) 1.39 + (define-key yahtml-mode-map YaTeX-prefix yahtml-prefix-map) 1.40 + (define-key yahtml-mode-map "\M-\C-@" 'YaTeX-mark-environment) 1.41 + (define-key yahtml-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment) 1.42 + (define-key yahtml-mode-map "\M-\C-e" 'YaTeX-end-of-environment)) 1.43 + 1.44 +(defvar yahtml-syntax-table nil 1.45 + "*Syntax table for typesetting buffer") 1.46 + 1.47 +(if yahtml-syntax-table nil 1.48 + (setq yahtml-syntax-table 1.49 + (make-syntax-table (standard-syntax-table))) 1.50 + (modify-syntax-entry ?\< "(" yahtml-syntax-table) 1.51 + (modify-syntax-entry ?\> ")" yahtml-syntax-table) 1.52 +) 1.53 +(defvar yahtml-command-regexp "[A-Za-z0-9]+" 1.54 + "Regexp of constituent of html commands.") 1.55 + 1.56 +;;; Completion tables for `form' 1.57 +(defvar yahtml-form-table '(("a") ("form"))) 1.58 +(defvar yahtml-user-form-table nil) 1.59 +(defvar yahtml-tmp-form-table nil) 1.60 + 1.61 +(defvar yahtml-env-table 1.62 + '(("html") ("head") ("title") ("body") ("dl") 1.63 + ("h1") ("h2") ("h3") ("h4") ("h5") ("h6"))) 1.64 + 1.65 +;;; Completion tables for typeface designator 1.66 +(defvar yahtml-typeface-table 1.67 + '(("defn") ("em") ("cite") ("code") ("kbd") ("samp") 1.68 + ("strong") ("var") ("b") ("i") ("tt") ("u")) 1.69 + "Default completion table of typeface designator") 1.70 +(defvar yahtml-user-typeface-table nil) 1.71 +(defvar yahtml-tmp-typeface-table nil) 1.72 + 1.73 +(defvar yahtml-prefer-upcases nil) 1.74 +(cond 1.75 + (yahtml-prefer-upcases 1.76 + (setq yahtml-form-table 1.77 + (mapcar (function (lambda (list) (list (upcase (car list))))) 1.78 + yahtml-form-table)) 1.79 + (setq yahtml-env-table 1.80 + (mapcar (function (lambda (list) (list (upcase (car list))))) 1.81 + yahtml-env-table)) 1.82 + (setq yahtml-typeface-table 1.83 + (mapcar (function (lambda (list) (list (upcase (car list))))) 1.84 + yahtml-typeface-table)))) 1.85 1.86 (defun yahtml-mode () 1.87 (interactive) 1.88 (yatex-mode) 1.89 (setq major-mode 'yahtml-mode 1.90 mode-name "yahtml") 1.91 - (make-local-variable 'YaTeX-ec) 1.92 - (setq YaTeX-ec "") 1.93 - (make-local-variable 'YaTeX-struct-begin) 1.94 - (setq YaTeX-struct-begin "<%1>") 1.95 - (make-local-variable 'YaTeX-struct-end) 1.96 - (setq YaTeX-struct-end "</%1>") 1.97 - (make-local-variable 'env-table) 1.98 - (setq env-table 1.99 - '(("HTML") ("HEAD") ("TITLE") ("BODY") ("H1") ("H2") ("H3") ("DL"))) 1.100 + (make-local-variable 'YaTeX-ec) (setq YaTeX-ec "") 1.101 + (make-local-variable 'YaTeX-struct-begin) (setq YaTeX-struct-begin "<%1>") 1.102 + (make-local-variable 'YaTeX-struct-end) (setq YaTeX-struct-end "</%1>") 1.103 + (mapcar 'make-local-variable 1.104 + '(env-table user-env-table tmp-env-table)) 1.105 + (setq env-table yahtml-env-table) 1.106 + (mapcar 'make-local-variable 1.107 + '(singlecmd-table user-singlecmd-table tmp-singlecmd-table)) 1.108 + (make-local-variable 'YaTeX-struct-name-regexp) 1.109 + (setq YaTeX-struct-name-regexp "[^/]+") 1.110 (make-local-variable 'YaTeX-prefix-map) 1.111 + (make-local-variable 'YaTeX-command-token-regexp) 1.112 + (setq YaTeX-command-token-regexp yahtml-command-regexp) 1.113 (setq YaTeX-prefix-map yahtml-prefix-map) 1.114 + (set-syntax-table yahtml-syntax-table) 1.115 (use-local-map yahtml-mode-map) 1.116 - (YaTeX-define-begend-key "bh" "HTML") 1.117 - (YaTeX-define-begend-key "bH" "HEAD") 1.118 - (YaTeX-define-begend-key "bt" "TITLE") 1.119 - (YaTeX-define-begend-key "bb" "BODY") 1.120 - (YaTeX-define-begend-key "bd" "DL") 1.121 - (YaTeX-define-begend-key "b1" "H1") 1.122 - (YaTeX-define-begend-key "b2" "H2") 1.123 - (YaTeX-define-begend-key "b3" "H3") 1.124 -) 1.125 + (YaTeX-define-key "s" 'yahtml-insert-form) 1.126 + (YaTeX-define-key "l" 'yahtml-insert-tag) 1.127 + (if YaTeX-no-begend-shortcut nil 1.128 + (YaTeX-define-begend-key "bh" "HTML") 1.129 + (YaTeX-define-begend-key "bH" "HEAD") 1.130 + (YaTeX-define-begend-key "bt" "TITLE") 1.131 + (YaTeX-define-begend-key "bb" "BODY") 1.132 + (YaTeX-define-begend-key "bd" "DL") 1.133 + (YaTeX-define-begend-key "b1" "H1") 1.134 + (YaTeX-define-begend-key "b2" "H2") 1.135 + (YaTeX-define-begend-key "b3" "H3")) 1.136 + (run-hooks 'yahtml-mode-hook)) 1.137 + 1.138 +(defun yahtml-define-menu (keymap bindlist) 1.139 + (mapcar 1.140 + (function 1.141 + (lambda (bind) 1.142 + (define-key keymap (vector (car bind)) (cdr bind)))) 1.143 + bindlist)) 1.144 + 1.145 +(defvar yahtml-menu-map nil "Menu map of yahtml") 1.146 +(defvar yahtml-menu-map-sectioning nil "Menu map of yahtml(sectioning)") 1.147 +(defvar yahtml-menu-map-listing nil "Menu map of yahtml(listing)") 1.148 +(defvar yahtml-menu-map-logical nil "Menu map of yahtml(logical tags)") 1.149 +(defvar yahtml-menu-map-typeface nil "Menu map of yahtml(typeface tags)") 1.150 + 1.151 +;;; Variables for mosaic url history 1.152 +(defvar yahtml-urls nil "Alist of global history") 1.153 +(defvar yahtml-url-history-file "~/.mosaic-global-history" 1.154 + "File name of url history") 1.155 + 1.156 +(cond 1.157 + ((and YaTeX-emacs-19 (null yahtml-menu-map)) 1.158 + (setq yahtml-menu-map (make-sparse-keymap "yahtml menu")) 1.159 + (setq yahtml-menu-map-sectioning (make-sparse-keymap "sectioning menu")) 1.160 + (yahtml-define-menu 1.161 + yahtml-menu-map-sectioning 1.162 + (nreverse 1.163 + '((1 "H1" . (lambda () (interactive) (yahtml-insert-begin-end "H1" nil))) 1.164 + (2 "H2" . (lambda () (interactive) (yahtml-insert-begin-end "H2" nil))) 1.165 + (3 "H3" . (lambda () (interactive) (yahtml-insert-begin-end "H3" nil))) 1.166 + (4 "H4" . (lambda () (interactive) (yahtml-insert-begin-end "H4" nil))) 1.167 + (5 "H5" . (lambda () (interactive) (yahtml-insert-begin-end "H5" nil))) 1.168 + (6 "H6" . (lambda () (interactive) (yahtml-insert-begin-end "H6" nil))) 1.169 + ))) 1.170 + (setq yahtml-menu-map-logical (make-sparse-keymap "logical tags")) 1.171 + (yahtml-define-menu 1.172 + yahtml-menu-map-logical 1.173 + (nreverse 1.174 + '((em "Embolden" . 1.175 + (lambda () (interactive) (yahtml-insert-tag "EM"))) 1.176 + (defn "Define a word" . 1.177 + (lambda () (interactive) (yahtml-insert-tag "DEFN"))) 1.178 + (cite "Citation" . 1.179 + (lambda () (interactive) (yahtml-insert-tag "CITE"))) 1.180 + (code "Code" . 1.181 + (lambda () (interactive) (yahtml-insert-tag "CODE"))) 1.182 + (kbd "Keyboard" . 1.183 + (lambda () (interactive) (yahtml-insert-tag "KBD"))) 1.184 + (samp "Sample display" . 1.185 + (lambda () (interactive) (yahtml-insert-tag "SAMP"))) 1.186 + (strong "Strong" . 1.187 + (lambda () (interactive) (yahtml-insert-tag "STRONG"))) 1.188 + (VAR "Variable notation" . 1.189 + (lambda () (interactive) (yahtml-insert-tag "VAR"))) 1.190 + ))) 1.191 + (setq yahtml-menu-map-typeface (make-sparse-keymap "typeface tags")) 1.192 + (yahtml-define-menu 1.193 + yahtml-menu-map-typeface 1.194 + (nreverse 1.195 + '((b "Bold" . 1.196 + (lambda () (interactive) (yahtml-insert-tag "B"))) 1.197 + (i "Italic" . 1.198 + (lambda () (interactive) (yahtml-insert-tag "I"))) 1.199 + (tt "Typewriter" . 1.200 + (lambda () (interactive) (yahtml-insert-tag "TT"))) 1.201 + (u "Underlined" . 1.202 + (lambda () (interactive) (yahtml-insert-tag "U"))) 1.203 + ))) 1.204 + (setq yahtml-menu-map-listing (make-sparse-keymap "listing")) 1.205 + (yahtml-define-menu 1.206 + yahtml-menu-map-listing 1.207 + (nreverse 1.208 + '((ul "Unnumbered" . 1.209 + (lambda () (interactive) (yahtml-insert-begin-end "UL" nil))) 1.210 + (ol "Numbered" . 1.211 + (lambda () (interactive) (yahtml-insert-begin-end "OL" nil))) 1.212 + (dl "Description" . 1.213 + (lambda () (interactive) (yahtml-insert-begin-end "DL" nil))) 1.214 + ))) 1.215 + (define-key yahtml-mode-map [menu-bar yahtml] 1.216 + (cons "yahtml" yahtml-menu-map)) 1.217 + (yahtml-define-menu 1.218 + yahtml-menu-map 1.219 + (nreverse 1.220 + (list 1.221 + (cons (list 'sect "Sectioning") 1.222 + (cons "sectioning" yahtml-menu-map-sectioning)) 1.223 + (cons (list 'list "Listing") 1.224 + (cons "Listing" yahtml-menu-map-listing)) 1.225 + (cons (list 'logi "Logical tags") 1.226 + (cons "logical" yahtml-menu-map-logical)) 1.227 + (cons (list 'type "Typeface tags") 1.228 + (cons "typeface" yahtml-menu-map-typeface)) 1.229 + ))) 1.230 + )) 1.231 + 1.232 +(defun yahtml-collect-url-history () 1.233 + "Collect urls from global history file." 1.234 + (interactive) 1.235 + (save-excursion 1.236 + (set-buffer 1.237 + (find-file-noselect (expand-file-name yahtml-url-history-file))) 1.238 + (goto-char (point-min)) 1.239 + (setq yahtml-urls) 1.240 + (message "Collecting global history...") 1.241 + (while (re-search-forward "^[A-Za-z]+:" nil t) 1.242 + (setq yahtml-urls 1.243 + (cons (list 1.244 + (buffer-substring 1.245 + (progn (beginning-of-line) (point)) 1.246 + (progn (skip-chars-forward "^ ") (point)))) 1.247 + yahtml-urls))) 1.248 + (message "Collecting global history...Done"))) 1.249 + 1.250 +(defun yahtml-insert-form (&optional form) 1.251 + "Insert <FORM option=\"argument\"> </FORM>." 1.252 + (interactive) 1.253 + (or form 1.254 + (setq form 1.255 + (YaTeX-cplread-with-learning 1.256 + "Form: " 1.257 + 'yahtml-form-table 'yahtml-user-form-table 1.258 + 'yahtml-tmp-form-table))) 1.259 + (let ((p (point))) 1.260 + (insert (format "<%s%s>\n" form (yahtml-addin (downcase form)))) 1.261 + (indent-relative-maybe) 1.262 + (save-excursion (insert (format "</%s>" form))) 1.263 + (if (search-backward "\"\"" p t) (forward-char 1)))) 1.264 + 1.265 +(defun yahtml-addin (form) 1.266 + "Check add-in function's existence and call it if exists." 1.267 + (let ((addin (concat "yahtml::" form))) 1.268 + (if (and (intern-soft addin) (fboundp (intern-soft addin))) 1.269 + (concat " " (funcall (intern addin))) 1.270 + ""))) 1.271 + 1.272 +(defun yahtml::a () 1.273 + "Add-in function for <a>" 1.274 + (or yahtml-urls (yahtml-collect-url-history)) 1.275 + (concat "href=\"" 1.276 + (completing-read "href: " yahtml-urls) 1.277 + "\"")) 1.278 + 1.279 +(defun yahtml-insert-begin-end (env &optional region-mode) 1.280 + "Insert <ENV> \\n </ENV> by calling YaTeX-insert-begin-end." 1.281 + (interactive "sEnv: ") 1.282 + (setq env (funcall (if yahtml-prefer-upcases 'upcase 'downcase) env)) 1.283 + (YaTeX-insert-begin-end env region-mode)) 1.284 + 1.285 +(defun yahtml-insert-tag (&optional tag) 1.286 + "Insert <TAG> </TAG> and put cursor inside of them." 1.287 + (interactive) 1.288 + (or tag 1.289 + (setq tag 1.290 + (YaTeX-cplread-with-learning 1.291 + "Tag: " 1.292 + 'yahtml-typeface-table 'yahtml-user-typeface-table 1.293 + 'yahtml-tmp-typeface-table))) 1.294 + (setq tag (funcall (if yahtml-prefer-upcases 'upcase 'downcase) tag)) 1.295 + (insert (format "<%s> " tag)) 1.296 + (save-excursion (insert (format "</%s>" tag)))) 1.297 + 1.298 +(provide 'yahtml) 1.299 + 1.300 +; Local variables: 1.301 +; fill-prefix: ";;; " 1.302 +; paragraph-start: "^$\\|\\|;;;$" 1.303 +; paragraph-separate: "^$\\|\\|;;;$" 1.304 +; End: