yatex

annotate yahtml.el @ 58:3a7c0c2bf16d

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