yatex

annotate yahtml.el @ 61:b9f753846b6b

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