yatex

annotate yahtml.el @ 60:9e08ed569d80

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