yatex

annotate yahtml.el @ 57:18f4939986e6

(j)LaTeX2e supported yatex19.el fixed a lot
author yuuji
date Sat, 02 Dec 1995 18:35:28 +0000
parents 2d45e43fb35f
children 3a7c0c2bf16d
rev   line source
yuuji@13 1 ;;; -*- Emacs-Lisp -*-
yuuji@16 2 ;;; (c ) 1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp, pcs39334@ascii-net.or.jp]
yuuji@57 3 ;;; Last modified Mon Nov 20 11:26:38 1995 on inspire
yuuji@54 4 ;;; This is PURELY tentative.
yuuji@54 5 ;;; $Id$
yuuji@54 6
yuuji@54 7 ;;;[Commentary]
yuuji@13 8 ;;;
yuuji@54 9 ;;; It is assumed you are already familiar with YaTeX. The following
yuuji@54 10 ;;; completing featureas are available: ([prefix] means `C-c' by default)
yuuji@54 11 ;;;
yuuji@54 12 ;;; * [prefix] b X Complete environments such as `H1' which
yuuji@57 13 ;;; normally requires closing tag `</H1>
yuuji@57 14 ;;; <a href=foo> ... </a> is also classified into
yuuji@57 15 ;;; this group
yuuji@54 16 ;;; * [prefix] s Complete declarative notations such as
yuuji@57 17 ;;; `<img src="foo.gif">'
yuuji@57 18 ;;; `<input name="var" ...>'
yuuji@54 19 ;;; * [prefix] l Complete typeface-changing commands such as
yuuji@54 20 ;;; `<i> ... </i>' or `<samp> ... </samp>'
yuuji@57 21 ;;; * [prefix] m Complete single commands such as
yuuji@57 22 ;;; `<br>' or `<hr>'
yuuji@54 23 ;;; * menu-bar yahtml Complete all by selecting a menu item (Though I
yuuji@54 24 ;;; hate menu, this is most useful)
yuuji@54 25 ;;;
yuuji@54 26 ;;; NOTE! This program is truly tentative. If you find some bright
yuuji@54 27 ;;; future with this, please send me a mail to drive me to maintain this :)
yuuji@54 28
yuuji@13 29
yuuji@13 30 (require 'yatex)
yuuji@57 31 (defvar yahtml-prefix-map nil)
yuuji@57 32 (defvar yahtml-mode-map nil "Keymap used in yahtml-mode.")
yuuji@57 33
yuuji@57 34 (defun yahtml-define-begend-key-normal (key env &optional map)
yuuji@57 35 "Define short cut yahtml-insert-begin-end key."
yuuji@57 36 (YaTeX-define-key
yuuji@57 37 key
yuuji@57 38 (list 'lambda '(arg) '(interactive "P")
yuuji@57 39 (list 'yahtml-insert-begin-end env 'arg))
yuuji@57 40 map))
yuuji@57 41
yuuji@57 42 (defun yahtml-define-begend-region-key (key env &optional map)
yuuji@57 43 "Define short cut yahtml-insert-begin-end-region key."
yuuji@57 44 (YaTeX-define-key key (list 'lambda nil '(interactive)
yuuji@57 45 (list 'yahtml-insert-begin-end env t)) map))
yuuji@57 46
yuuji@57 47 (defun yahtml-define-begend-key (key env &optional map)
yuuji@57 48 "Define short cut key for begin type completion both for
yuuji@57 49 normal and region mode. To customize yahtml, user should use this function."
yuuji@57 50 (yahtml-define-begend-key-normal key env map)
yuuji@57 51 (if YaTeX-inhibit-prefix-letter nil
yuuji@57 52 (yahtml-define-begend-region-key
yuuji@57 53 (concat (upcase (substring key 0 1)) (substring key 1)) env)))
yuuji@57 54
yuuji@57 55
yuuji@13 56 (if yahtml-mode-map nil
yuuji@57 57 (setq yahtml-mode-map (make-sparse-keymap)
yuuji@57 58 yahtml-prefix-map (make-sparse-keymap))
yuuji@54 59 (define-key yahtml-mode-map YaTeX-prefix yahtml-prefix-map)
yuuji@54 60 (define-key yahtml-mode-map "\M-\C-@" 'YaTeX-mark-environment)
yuuji@54 61 (define-key yahtml-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment)
yuuji@57 62 (define-key yahtml-mode-map "\M-\C-e" 'YaTeX-end-of-environment)
yuuji@57 63 (define-key yahtml-mode-map "\C-i" 'YaTeX-indent-line)
yuuji@57 64 (define-key yahtml-mode-map YaTeX-prefix yahtml-prefix-map)
yuuji@57 65 (let ((map yahtml-prefix-map))
yuuji@57 66 (YaTeX-define-key "^" 'yahtml-visit-main map)
yuuji@57 67 (YaTeX-define-key "4^" 'yahtml-visit-main-other-window map)
yuuji@57 68 (YaTeX-define-key "4g" 'yahtml-goto-corresponding-*-other-window map)
yuuji@57 69 (YaTeX-define-key "44" 'YaTeX-switch-to-window map)
yuuji@57 70 (and YaTeX-emacs-19 window-system
yuuji@57 71 (progn
yuuji@57 72 (YaTeX-define-key "5^" 'yahtml-visit-main-other-frame map)
yuuji@57 73 (YaTeX-define-key "5g" 'yahtml-goto-corresponding-*-other-frame map)
yuuji@57 74 (YaTeX-define-key "55" 'YaTeX-switch-to-window map)))
yuuji@57 75 (YaTeX-define-key "v" 'YaTeX-version map)
yuuji@57 76 (YaTeX-define-key "}" 'YaTeX-insert-braces-region map)
yuuji@57 77 (YaTeX-define-key "]" 'YaTeX-insert-brackets-region map)
yuuji@57 78 (YaTeX-define-key ")" 'YaTeX-insert-parens-region map)
yuuji@57 79 (YaTeX-define-key "s" 'yahtml-insert-form map)
yuuji@57 80 (YaTeX-define-key "l" 'yahtml-insert-tag map)
yuuji@57 81 (YaTeX-define-key "m" 'yahtml-insert-single map)
yuuji@57 82 (YaTeX-define-key "n" '(lambda () (interactive) (insert "<br>\n")) map)
yuuji@57 83 (if YaTeX-no-begend-shortcut
yuuji@57 84 (progn
yuuji@57 85 (YaTeX-define-key "B" 'yahtml-insert-begend-region map)
yuuji@57 86 (YaTeX-define-key "b" 'yahtml-insert-begend map))
yuuji@57 87 (yahtml-define-begend-key "bh" "HTML" map)
yuuji@57 88 (yahtml-define-begend-key "bH" "HEAD" map)
yuuji@57 89 (yahtml-define-begend-key "bt" "TITLE" map)
yuuji@57 90 (yahtml-define-begend-key "bb" "BODY" map)
yuuji@57 91 (yahtml-define-begend-key "bd" "DL" map)
yuuji@57 92 (yahtml-define-begend-key "b1" "H1" map)
yuuji@57 93 (yahtml-define-begend-key "b2" "H2" map)
yuuji@57 94 (yahtml-define-begend-key "b3" "H3" map)
yuuji@57 95 (yahtml-define-begend-key "ba" "a" map)
yuuji@57 96 (yahtml-define-begend-key "bf" "form" map)
yuuji@57 97 (yahtml-define-begend-key "bs" "select" map)
yuuji@57 98 (YaTeX-define-key "b " 'yahtml-insert-begend map)
yuuji@57 99 (YaTeX-define-key "B " 'yahtml-insert-begend map)
yuuji@57 100 )
yuuji@57 101 (YaTeX-define-key "e" 'yahtml-end-environment map)
yuuji@57 102 (YaTeX-define-key ">" 'yahtml-comment-region map)
yuuji@57 103 (YaTeX-define-key "<" 'yahtml-uncomment-region map)
yuuji@57 104 (YaTeX-define-key "g" 'yahtml-goto-corresponding-* map)
yuuji@57 105 )
yuuji@57 106 )
yuuji@54 107
yuuji@57 108 (defvar yahtml-paragraph-separate
yuuji@57 109 (concat
yuuji@57 110 "^$\\|<br>\\|<p>\\|^[ \t]*</?\\(h[1-6]\\|p\\|dl\\|dd\\|dt\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\)>")
yuuji@57 111 "*Regexp of html paragraph separater")
yuuji@54 112 (defvar yahtml-syntax-table nil
yuuji@54 113 "*Syntax table for typesetting buffer")
yuuji@54 114
yuuji@54 115 (if yahtml-syntax-table nil
yuuji@54 116 (setq yahtml-syntax-table
yuuji@54 117 (make-syntax-table (standard-syntax-table)))
yuuji@54 118 (modify-syntax-entry ?\< "(" yahtml-syntax-table)
yuuji@54 119 (modify-syntax-entry ?\> ")" yahtml-syntax-table)
yuuji@54 120 )
yuuji@54 121 (defvar yahtml-command-regexp "[A-Za-z0-9]+"
yuuji@54 122 "Regexp of constituent of html commands.")
yuuji@57 123 (defvar yahtml-kanji-code 2
yuuji@57 124 "Kanji coding system of html file; 1=sjis, 2=jis, 3=euc")
yuuji@54 125
yuuji@54 126 ;;; Completion tables for `form'
yuuji@57 127 (defvar yahtml-form-table
yuuji@57 128 '(("img") ("input")))
yuuji@54 129 (defvar yahtml-user-form-table nil)
yuuji@54 130 (defvar yahtml-tmp-form-table nil)
yuuji@54 131
yuuji@54 132 (defvar yahtml-env-table
yuuji@57 133 '(("html") ("head") ("title") ("body") ("dl") ("a") ("form") ("select")
yuuji@57 134 ("h1") ("h2") ("h3") ("h4") ("h5") ("h6") ("ul")))
yuuji@57 135
yuuji@57 136 (defvar yahtml-user-env-table nil)
yuuji@57 137 (defvar yahtml-tmp-env-table nil)
yuuji@54 138
yuuji@54 139 ;;; Completion tables for typeface designator
yuuji@54 140 (defvar yahtml-typeface-table
yuuji@54 141 '(("defn") ("em") ("cite") ("code") ("kbd") ("samp")
yuuji@57 142 ("strong") ("var") ("b") ("i") ("tt") ("u") ("address"))
yuuji@54 143 "Default completion table of typeface designator")
yuuji@54 144 (defvar yahtml-user-typeface-table nil)
yuuji@54 145 (defvar yahtml-tmp-typeface-table nil)
yuuji@54 146
yuuji@57 147 (defvar yahtml-single-cmd-table
yuuji@57 148 '(("hr") ("br") ("option") ("p"))
yuuji@57 149 "Default completion table of HTML single command.")
yuuji@57 150 (defvar yahtml-user-single-cmd-table nil)
yuuji@57 151 (defvar yahtml-tmp-single-cmd-table nil)
yuuji@57 152 (defvar yahtml-last-single-cmd nil)
yuuji@57 153
yuuji@54 154 (defvar yahtml-prefer-upcases nil)
yuuji@54 155 (cond
yuuji@54 156 (yahtml-prefer-upcases
yuuji@54 157 (setq yahtml-form-table
yuuji@54 158 (mapcar (function (lambda (list) (list (upcase (car list)))))
yuuji@54 159 yahtml-form-table))
yuuji@54 160 (setq yahtml-env-table
yuuji@54 161 (mapcar (function (lambda (list) (list (upcase (car list)))))
yuuji@54 162 yahtml-env-table))
yuuji@54 163 (setq yahtml-typeface-table
yuuji@54 164 (mapcar (function (lambda (list) (list (upcase (car list)))))
yuuji@54 165 yahtml-typeface-table))))
yuuji@13 166
yuuji@57 167 (defvar yahtml-struct-name-regexp
yuuji@57 168 "\\<\\(h[1-6]\\|[uod]l\\|body\\|title\\|head\\)")
yuuji@57 169
yuuji@57 170
yuuji@13 171 (defun yahtml-mode ()
yuuji@13 172 (interactive)
yuuji@13 173 (yatex-mode)
yuuji@57 174 (cond
yuuji@57 175 ((boundp 'MULE)
yuuji@57 176 (set-file-coding-system
yuuji@57 177 (cdr (assq yahtml-kanji-code YaTeX-kanji-code-alist))))
yuuji@57 178 ((boundp 'NEMACS)
yuuji@57 179 (make-local-variable 'kanji-fileio-code)
yuuji@57 180 (setq kanji-fileio-code yahtml-kanji-code)))
yuuji@13 181 (setq major-mode 'yahtml-mode
yuuji@13 182 mode-name "yahtml")
yuuji@54 183 (make-local-variable 'YaTeX-ec) (setq YaTeX-ec "")
yuuji@57 184 (make-local-variable 'YaTeX-struct-begin) (setq YaTeX-struct-begin "<%1%2>")
yuuji@54 185 (make-local-variable 'YaTeX-struct-end) (setq YaTeX-struct-end "</%1>")
yuuji@54 186 (make-local-variable 'YaTeX-struct-name-regexp)
yuuji@57 187 (setq YaTeX-struct-name-regexp yahtml-struct-name-regexp)
yuuji@13 188 (make-local-variable 'YaTeX-prefix-map)
yuuji@54 189 (make-local-variable 'YaTeX-command-token-regexp)
yuuji@54 190 (setq YaTeX-command-token-regexp yahtml-command-regexp)
yuuji@57 191 (make-local-variable 'YaTeX-environment-indent)
yuuji@57 192 (setq YaTeX-environment-indent 0)
yuuji@57 193 (make-local-variable 'fill-prefix)
yuuji@57 194 (setq fill-prefix nil)
yuuji@57 195 (make-local-variable 'paragraph-separate)
yuuji@57 196 (setq paragraph-separate yahtml-paragraph-separate
yuuji@57 197 paragraph-start yahtml-paragraph-separate)
yuuji@57 198 (make-local-variable 'comment-start)
yuuji@57 199 (make-local-variable 'comment-end)
yuuji@57 200 (setq comment-start "<!-- " comment-end " -->")
yuuji@54 201 (set-syntax-table yahtml-syntax-table)
yuuji@13 202 (use-local-map yahtml-mode-map)
yuuji@54 203 (run-hooks 'yahtml-mode-hook))
yuuji@54 204
yuuji@54 205 (defun yahtml-define-menu (keymap bindlist)
yuuji@54 206 (mapcar
yuuji@54 207 (function
yuuji@54 208 (lambda (bind)
yuuji@54 209 (define-key keymap (vector (car bind)) (cdr bind))))
yuuji@54 210 bindlist))
yuuji@54 211
yuuji@54 212 (defvar yahtml-menu-map nil "Menu map of yahtml")
yuuji@54 213 (defvar yahtml-menu-map-sectioning nil "Menu map of yahtml(sectioning)")
yuuji@54 214 (defvar yahtml-menu-map-listing nil "Menu map of yahtml(listing)")
yuuji@54 215 (defvar yahtml-menu-map-logical nil "Menu map of yahtml(logical tags)")
yuuji@54 216 (defvar yahtml-menu-map-typeface nil "Menu map of yahtml(typeface tags)")
yuuji@54 217
yuuji@54 218 ;;; Variables for mosaic url history
yuuji@54 219 (defvar yahtml-urls nil "Alist of global history")
yuuji@54 220 (defvar yahtml-url-history-file "~/.mosaic-global-history"
yuuji@54 221 "File name of url history")
yuuji@54 222
yuuji@54 223 (cond
yuuji@54 224 ((and YaTeX-emacs-19 (null yahtml-menu-map))
yuuji@54 225 (setq yahtml-menu-map (make-sparse-keymap "yahtml menu"))
yuuji@54 226 (setq yahtml-menu-map-sectioning (make-sparse-keymap "sectioning menu"))
yuuji@54 227 (yahtml-define-menu
yuuji@54 228 yahtml-menu-map-sectioning
yuuji@54 229 (nreverse
yuuji@54 230 '((1 "H1" . (lambda () (interactive) (yahtml-insert-begin-end "H1" nil)))
yuuji@54 231 (2 "H2" . (lambda () (interactive) (yahtml-insert-begin-end "H2" nil)))
yuuji@54 232 (3 "H3" . (lambda () (interactive) (yahtml-insert-begin-end "H3" nil)))
yuuji@54 233 (4 "H4" . (lambda () (interactive) (yahtml-insert-begin-end "H4" nil)))
yuuji@54 234 (5 "H5" . (lambda () (interactive) (yahtml-insert-begin-end "H5" nil)))
yuuji@54 235 (6 "H6" . (lambda () (interactive) (yahtml-insert-begin-end "H6" nil)))
yuuji@54 236 )))
yuuji@54 237 (setq yahtml-menu-map-logical (make-sparse-keymap "logical tags"))
yuuji@54 238 (yahtml-define-menu
yuuji@54 239 yahtml-menu-map-logical
yuuji@54 240 (nreverse
yuuji@54 241 '((em "Embolden" .
yuuji@54 242 (lambda () (interactive) (yahtml-insert-tag "EM")))
yuuji@54 243 (defn "Define a word" .
yuuji@54 244 (lambda () (interactive) (yahtml-insert-tag "DEFN")))
yuuji@54 245 (cite "Citation" .
yuuji@54 246 (lambda () (interactive) (yahtml-insert-tag "CITE")))
yuuji@54 247 (code "Code" .
yuuji@54 248 (lambda () (interactive) (yahtml-insert-tag "CODE")))
yuuji@54 249 (kbd "Keyboard" .
yuuji@54 250 (lambda () (interactive) (yahtml-insert-tag "KBD")))
yuuji@54 251 (samp "Sample display" .
yuuji@54 252 (lambda () (interactive) (yahtml-insert-tag "SAMP")))
yuuji@54 253 (strong "Strong" .
yuuji@54 254 (lambda () (interactive) (yahtml-insert-tag "STRONG")))
yuuji@54 255 (VAR "Variable notation" .
yuuji@54 256 (lambda () (interactive) (yahtml-insert-tag "VAR")))
yuuji@54 257 )))
yuuji@54 258 (setq yahtml-menu-map-typeface (make-sparse-keymap "typeface tags"))
yuuji@54 259 (yahtml-define-menu
yuuji@54 260 yahtml-menu-map-typeface
yuuji@54 261 (nreverse
yuuji@54 262 '((b "Bold" .
yuuji@54 263 (lambda () (interactive) (yahtml-insert-tag "B")))
yuuji@54 264 (i "Italic" .
yuuji@54 265 (lambda () (interactive) (yahtml-insert-tag "I")))
yuuji@54 266 (tt "Typewriter" .
yuuji@54 267 (lambda () (interactive) (yahtml-insert-tag "TT")))
yuuji@54 268 (u "Underlined" .
yuuji@54 269 (lambda () (interactive) (yahtml-insert-tag "U")))
yuuji@54 270 )))
yuuji@54 271 (setq yahtml-menu-map-listing (make-sparse-keymap "listing"))
yuuji@54 272 (yahtml-define-menu
yuuji@54 273 yahtml-menu-map-listing
yuuji@54 274 (nreverse
yuuji@54 275 '((ul "Unnumbered" .
yuuji@54 276 (lambda () (interactive) (yahtml-insert-begin-end "UL" nil)))
yuuji@54 277 (ol "Numbered" .
yuuji@54 278 (lambda () (interactive) (yahtml-insert-begin-end "OL" nil)))
yuuji@54 279 (dl "Description" .
yuuji@54 280 (lambda () (interactive) (yahtml-insert-begin-end "DL" nil)))
yuuji@54 281 )))
yuuji@57 282 (setq yahtml-menu-map-item (make-sparse-keymap "item"))
yuuji@57 283 (yahtml-define-menu
yuuji@57 284 yahtml-menu-map-item
yuuji@57 285 (nreverse
yuuji@57 286 '((li "Simple item" .
yuuji@57 287 (lambda () (interactive) (yahtml-insert-single "li")))
yuuji@57 288 (dt "Define term" .
yuuji@57 289 (lambda () (interactive) (yahtml-insert-single "dt")))
yuuji@57 290 (dd "Description of term" .
yuuji@57 291 (lambda () (interactive) (yahtml-insert-single "dd")))
yuuji@57 292 )))
yuuji@54 293 (define-key yahtml-mode-map [menu-bar yahtml]
yuuji@54 294 (cons "yahtml" yahtml-menu-map))
yuuji@54 295 (yahtml-define-menu
yuuji@54 296 yahtml-menu-map
yuuji@54 297 (nreverse
yuuji@54 298 (list
yuuji@54 299 (cons (list 'sect "Sectioning")
yuuji@54 300 (cons "sectioning" yahtml-menu-map-sectioning))
yuuji@54 301 (cons (list 'list "Listing")
yuuji@54 302 (cons "Listing" yahtml-menu-map-listing))
yuuji@57 303 (cons (list 'item "Item")
yuuji@57 304 (cons "Itemizing" yahtml-menu-map-item));;;
yuuji@54 305 (cons (list 'logi "Logical tags")
yuuji@54 306 (cons "logical" yahtml-menu-map-logical))
yuuji@54 307 (cons (list 'type "Typeface tags")
yuuji@54 308 (cons "typeface" yahtml-menu-map-typeface))
yuuji@54 309 )))
yuuji@54 310 ))
yuuji@54 311
yuuji@54 312 (defun yahtml-collect-url-history ()
yuuji@54 313 "Collect urls from global history file."
yuuji@54 314 (interactive)
yuuji@54 315 (save-excursion
yuuji@54 316 (set-buffer
yuuji@54 317 (find-file-noselect (expand-file-name yahtml-url-history-file)))
yuuji@54 318 (goto-char (point-min))
yuuji@54 319 (setq yahtml-urls)
yuuji@54 320 (message "Collecting global history...")
yuuji@54 321 (while (re-search-forward "^[A-Za-z]+:" nil t)
yuuji@54 322 (setq yahtml-urls
yuuji@54 323 (cons (list
yuuji@54 324 (buffer-substring
yuuji@54 325 (progn (beginning-of-line) (point))
yuuji@54 326 (progn (skip-chars-forward "^ ") (point))))
yuuji@54 327 yahtml-urls)))
yuuji@54 328 (message "Collecting global history...Done")))
yuuji@54 329
yuuji@57 330 ;;; ----------- Completion ----------
yuuji@57 331 (defvar yahtml-last-begend "html")
yuuji@57 332 (defun yahtml-insert-begend (&optional region)
yuuji@57 333 "Insert <cmd> ... </cmd>."
yuuji@57 334 (interactive "P")
yuuji@57 335 (let ((cmd (YaTeX-cplread-with-learning
yuuji@57 336 (format "Environment(default %s): " yahtml-last-begend)
yuuji@57 337 'yahtml-env-table 'yahtml-user-env-table 'yahtml-tmp-env-table))
yuuji@57 338 (bolp (bolp)))
yuuji@57 339 (if (string< "" cmd) (setq yahtml-last-begend cmd))
yuuji@57 340 (setq cmd yahtml-last-begend)
yuuji@57 341 (if region
yuuji@57 342 (let ((beg (region-beginning))
yuuji@57 343 (end (region-end))
yuuji@57 344 (addin (yahtml-addin cmd)))
yuuji@57 345 (goto-char end)
yuuji@57 346 (insert (format "</%s>%s" cmd (if bolp "\n" "")))
yuuji@57 347 (goto-char beg)
yuuji@57 348 (insert (format "<%s%s>%s" cmd addin (if bolp "\n" ""))))
yuuji@57 349 (insert (format "<%s%s" cmd (yahtml-addin cmd)))
yuuji@57 350 (if bolp (progn (insert (format ">\n</%s>\n" cmd cmd))
yuuji@57 351 (forward-line -1))
yuuji@57 352 (insert ">")
yuuji@57 353 (save-excursion (insert (format "</%s>" cmd)))))))
yuuji@57 354
yuuji@57 355 (defun yahtml-insert-begend-region ()
yuuji@57 356 "Call yahtml-insert-begend in the region mode."
yuuji@57 357 (interactive)
yuuji@57 358 (yahtml-insert-begend t))
yuuji@57 359
yuuji@57 360
yuuji@54 361 (defun yahtml-insert-form (&optional form)
yuuji@57 362 "Insert <FORM option=\"argument\">."
yuuji@54 363 (interactive)
yuuji@54 364 (or form
yuuji@54 365 (setq form
yuuji@54 366 (YaTeX-cplread-with-learning
yuuji@54 367 "Form: "
yuuji@54 368 'yahtml-form-table 'yahtml-user-form-table
yuuji@54 369 'yahtml-tmp-form-table)))
yuuji@57 370 (let ((p (point)) q)
yuuji@57 371 (insert (format "<%s%s>" form (yahtml-addin (downcase form))))
yuuji@57 372 ;;(indent-relative-maybe)
yuuji@57 373 (if (cdr (assoc form yahtml-form-table))
yuuji@57 374 (save-excursion (insert (format "</%s>" form))))
yuuji@54 375 (if (search-backward "\"\"" p t) (forward-char 1))))
yuuji@54 376
yuuji@54 377 (defun yahtml-addin (form)
yuuji@54 378 "Check add-in function's existence and call it if exists."
yuuji@57 379 (let ((addin (concat "yahtml:" form)))
yuuji@54 380 (if (and (intern-soft addin) (fboundp (intern-soft addin)))
yuuji@54 381 (concat " " (funcall (intern addin)))
yuuji@54 382 "")))
yuuji@54 383
yuuji@57 384 (defun yahtml:a ()
yuuji@54 385 "Add-in function for <a>"
yuuji@57 386 ; (or yahtml-urls (yahtml-collect-url-history))
yuuji@57 387 ; (concat "href=\""
yuuji@57 388 ; (completing-read "href: " yahtml-urls)
yuuji@57 389 ; "\"")
yuuji@57 390 (concat "href=\"" (read-file-name "href: " "" nil nil "") "\"")
yuuji@57 391 )
yuuji@57 392
yuuji@57 393 (defun yahtml:img ()
yuuji@57 394 "Add-in function for <img>"
yuuji@54 395 (or yahtml-urls (yahtml-collect-url-history))
yuuji@57 396 (let ((src (read-file-name "src: " "" nil t ""))
yuuji@57 397 (alg (completing-read "align: " '(("top") ("middle") ("bottom")))))
yuuji@57 398 (concat "src=\"" src "\""
yuuji@57 399 (if (string< "" alg) (concat " align=\"" alg "\"")))))
yuuji@57 400
yuuji@57 401 (defun yahtml:form ()
yuuji@57 402 "Add-in function `form' input format"
yuuji@57 403 (concat
yuuji@57 404 " method=" (completing-read "Method: " '(("POST") ("GET")) nil t)
yuuji@57 405 " action=\"" (read-string "Action: ") "\""
yuuji@57 406 ))
yuuji@57 407
yuuji@57 408 (defun yahtml:select ()
yuuji@57 409 "Add-in function for `select' input format"
yuuji@57 410 (setq yahtml-last-single-cmd "option")
yuuji@57 411 (concat " name=\"" (read-string "name: ") "\""))
yuuji@57 412
yuuji@57 413 (defvar yahtml-input-types
yuuji@57 414 '(("text") ("password") ("checkbox") ("radio") ("submit")
yuuji@57 415 ("reset") ("image") ("hidden")))
yuuji@57 416
yuuji@57 417 (defun yahtml:input ()
yuuji@57 418 "Add-in function for `input' form"
yuuji@57 419 (let (name type value checked (size "") (maxlength ""))
yuuji@57 420 (setq name (read-string "name: ")
yuuji@57 421 type (completing-read "type (default=text): "
yuuji@57 422 yahtml-input-types nil t)
yuuji@57 423 value (read-string "value: "))
yuuji@57 424 (if (string-match "text\\|password\\|^$" type)
yuuji@57 425 (setq size (read-string "size: ")
yuuji@57 426 maxlength (read-string "maxlength: ")))
yuuji@57 427 (concat
yuuji@57 428 "name=\"" name "\""
yuuji@57 429 (if (string< "" type) (concat " type=\"" type "\""))
yuuji@57 430 (if (string< "" value) (concat " value=\"" value "\""))
yuuji@57 431 (if (string< "" size) (concat " size=\"" size "\""))
yuuji@57 432 (if (string< "" maxlength) (concat " maxlength=\"" maxlength "\""))
yuuji@57 433 )))
yuuji@57 434
yuuji@54 435
yuuji@54 436 (defun yahtml-insert-begin-end (env &optional region-mode)
yuuji@54 437 "Insert <ENV> \\n </ENV> by calling YaTeX-insert-begin-end."
yuuji@54 438 (interactive "sEnv: ")
yuuji@54 439 (setq env (funcall (if yahtml-prefer-upcases 'upcase 'downcase) env))
yuuji@54 440 (YaTeX-insert-begin-end env region-mode))
yuuji@54 441
yuuji@57 442 (defun yahtml-insert-tag (tag)
yuuji@54 443 "Insert <TAG> </TAG> and put cursor inside of them."
yuuji@57 444 (interactive
yuuji@57 445 (list
yuuji@57 446 (YaTeX-cplread-with-learning
yuuji@57 447 "Tag: "
yuuji@57 448 'yahtml-typeface-table 'yahtml-user-typeface-table
yuuji@57 449 'yahtml-tmp-typeface-table)))
yuuji@54 450 (setq tag (funcall (if yahtml-prefer-upcases 'upcase 'downcase) tag))
yuuji@54 451 (insert (format "<%s> " tag))
yuuji@54 452 (save-excursion (insert (format "</%s>" tag))))
yuuji@54 453
yuuji@57 454 (defun yahtml-insert-single (cmd)
yuuji@57 455 "Insert <CMD>."
yuuji@57 456 (interactive
yuuji@57 457 (list (YaTeX-cplread-with-learning
yuuji@57 458 (format "Command%s: "
yuuji@57 459 (if yahtml-last-single-cmd
yuuji@57 460 (concat "(default " yahtml-last-single-cmd ")") ""))
yuuji@57 461 'yahtml-single-cmd-table 'yahtml-user-single-cmd-table
yuuji@57 462 'yahtml-tmp-single-cmd-table)))
yuuji@57 463 (setq cmd (funcall (if yahtml-prefer-upcases 'upcase 'downcase) cmd))
yuuji@57 464 (if (string< "" cmd) (setq yahtml-last-single-cmd cmd))
yuuji@57 465 (insert (format "<%s>" yahtml-last-single-cmd)))
yuuji@57 466
yuuji@57 467 ;;; ---------- Jump ----------
yuuji@57 468 (defun yahtml-on-href-p ()
yuuji@57 469 "Check if point is on href clause."
yuuji@57 470 (let ((p (point)) cmd)
yuuji@57 471 (save-excursion
yuuji@57 472 (or (bobp) (skip-chars-backward "^ \t"))
yuuji@57 473 (and (looking-at "href\\s *=\\s *\"?\\([^\"]+\\)\"?")
yuuji@57 474 (< p (match-end 0))
yuuji@57 475 (YaTeX-match-string 1)))))
yuuji@57 476
yuuji@57 477 (defun yahtml-goto-corresponding-href (&optional other)
yuuji@57 478 "Go to corresponding name."
yuuji@57 479 (let ((href (yahtml-on-href-p)) file name)
yuuji@57 480 (if href
yuuji@57 481 (cond
yuuji@57 482 ((string-match "^http:" href)
yuuji@57 483 (message "Sorry, jump across http is not supported."))
yuuji@57 484 (t (setq file (substring href 0 (string-match "#" href)))
yuuji@57 485 (if (string-match "#" href)
yuuji@57 486 (setq name (substring href (1+ (string-match "#" href)))))
yuuji@57 487 (if (string< "" file)
yuuji@57 488 (progn
yuuji@57 489 (if (string-match "/$" file)
yuuji@57 490 (setq file (concat file "index.html")))
yuuji@57 491 (if other (YaTeX-switch-to-buffer-other-window file)
yuuji@57 492 (YaTeX-switch-to-buffer file))))
yuuji@57 493 (if name
yuuji@57 494 (progn (set-mark-command nil) (yahtml-jump-to-name name)))
yuuji@57 495 t)))))
yuuji@57 496
yuuji@57 497 (defun yahtml-jump-to-name (name)
yuuji@57 498 "Jump to html's named tag."
yuuji@57 499 (setq name (format "name\\s *=\\s *\"?%s\"?" name))
yuuji@57 500 (or (and (re-search-forward name nil t) (goto-char (match-beginning 0)))
yuuji@57 501 (and (re-search-backward name nil t) (goto-char (match-beginning 0)))
yuuji@57 502 (message "Named tag `%s' not found" (substring href 1))))
yuuji@57 503
yuuji@57 504 (defun yahtml-on-begend-p (&optional p)
yuuji@57 505 "Check if point is on begend clause."
yuuji@57 506 (let ((p (point)) cmd)
yuuji@57 507 (save-excursion
yuuji@57 508 (if p (goto-char p))
yuuji@57 509 (if (= (char-after (point)) ?<) (forward-char 1))
yuuji@57 510 (if (and (re-search-backward "<" nil t)
yuuji@57 511 (looking-at
yuuji@57 512 (concat "<\\(/?" yahtml-command-regexp "\\)\\b"))
yuuji@57 513 (condition-case nil
yuuji@57 514 (forward-list 1))
yuuji@57 515 (< p (point)))
yuuji@57 516 (YaTeX-match-string 1)))))
yuuji@57 517
yuuji@57 518 (defun yahtml-goto-corresponding-begend ()
yuuji@57 519 (let ((cmd (yahtml-on-begend-p)))
yuuji@57 520 (if cmd
yuuji@57 521 (progn
yuuji@57 522 (if (= (aref cmd 0) ?/) ;on </cmd> line
yuuji@57 523 (re-search-backward (format "<%s" (substring cmd 1)))
yuuji@57 524 (re-search-forward (format "</%s" cmd)))
yuuji@57 525 (if (match-beginning 0) (goto-char (match-beginning 0)))))))
yuuji@57 526
yuuji@57 527 (defun yahtml-goto-corresponding-* (&optional other)
yuuji@57 528 "Go to corresponding object."
yuuji@57 529 (interactive)
yuuji@57 530 (cond
yuuji@57 531 ((yahtml-goto-corresponding-href other))
yuuji@57 532 ((yahtml-goto-corresponding-begend other))
yuuji@57 533 ))
yuuji@57 534
yuuji@57 535 (defun yahtml-goto-corresponding-*-other-window ()
yuuji@57 536 "Go to corresponding object."
yuuji@57 537 (interactive)
yuuji@57 538 (yahtml-goto-corresponding-* t))
yuuji@57 539
yuuji@57 540 ;;; ---------- commenting ----------
yuuji@57 541 (defun yahtml-comment-region (beg end)
yuuji@57 542 (interactive "r")
yuuji@57 543 (comment-region beg end nil))
yuuji@57 544
yuuji@57 545 (defun yahtml-uncomment-region (beg end)
yuuji@57 546 (interactive "r")
yuuji@57 547 (comment-region beg end '(4)))
yuuji@57 548
yuuji@57 549
yuuji@57 550
yuuji@57 551 ;;; ---------- ----------
yuuji@57 552 ;;; ---------- ----------
yuuji@57 553 ;;; ---------- ----------
yuuji@57 554
yuuji@57 555 ;;;
yuuji@57 556 ;;hilit19
yuuji@57 557 ;;;
yuuji@57 558 (defvar yahtml-default-face-table
yuuji@57 559 '(
yuuji@57 560 (form black/ivory white/hex-442233 italic)
yuuji@57 561 ))
yuuji@57 562 (defvar yahtml-hilit-patterns-alist
yuuji@57 563 '(
yuuji@57 564 ;; comments
yuuji@57 565 ("<!--\\s " "-->" comment)
yuuji@57 566 ;; include&exec
yuuji@57 567 ("<!--#\\(include\\|exec\\)" "-->" include)
yuuji@57 568 ;; string
yuuji@57 569 (hilit-string-find 39 string)
yuuji@57 570 (yahtml-hilit-region-tag "\\(em\\|strong\\)" bold)
yuuji@57 571 ("</?[uod]l>" 0 decl)
yuuji@57 572 ("<\\(di\\|dt\\|li\\|dd\\)>" 0 label)
yuuji@57 573 ("<a\\s +href" "</a>" crossref)
yuuji@57 574 ("</?\\sw+>" 0 decl)
yuuji@57 575 ("<form" "</form" form)
yuuji@57 576 ))
yuuji@57 577
yuuji@57 578 (defun yahtml-hilit-region-tag (tag)
yuuji@57 579 "Return list of start/end point of <TAG> form."
yuuji@57 580 (if (re-search-forward (concat "<" tag ">") nil t)
yuuji@57 581 (let ((m0 (match-beginning 0)))
yuuji@57 582 (skip-chars-forward " \t\n")
yuuji@57 583 (cons (point)
yuuji@57 584 (progn (re-search-forward (concat "</" tag ">") nil t)
yuuji@57 585 (1- (match-beginning 0)))))))
yuuji@57 586
yuuji@57 587 ;(setq hilit-patterns-alist (delq (assq 'yahtml-mode hilit-patterns-alist) hilit-patterns-alist))
yuuji@57 588 (cond
yuuji@57 589 ((and (featurep 'hilit19) (featurep 'yatex19))
yuuji@57 590 (or (assq 'yahtml-mode hilit-patterns-alist)
yuuji@57 591 (setq hilit-patterns-alist
yuuji@57 592 (cons (cons 'yahtml-mode yahtml-hilit-patterns-alist)
yuuji@57 593 hilit-patterns-alist)))))
yuuji@57 594
yuuji@54 595 (provide 'yahtml)
yuuji@54 596
yuuji@54 597 ; Local variables:
yuuji@54 598 ; fill-prefix: ";;; "
yuuji@54 599 ; paragraph-start: "^$\\| \\|;;;$"
yuuji@54 600 ; paragraph-separate: "^$\\| \\|;;;$"
yuuji@54 601 ; End: