yatex
diff yahtml.el @ 84:73cba5ddd111
Converted from RCS of yatex
author | yuuji |
---|---|
date | Sun, 27 Sep 2009 13:04:14 +0000 |
parents | 0734be649cb8 |
children | f14ec50103d0 |
line diff
1.1 --- a/yahtml.el Thu Dec 25 04:10:32 2003 +0000 1.2 +++ b/yahtml.el Sun Sep 27 13:04:14 2009 +0000 1.3 @@ -1,9 +1,9 @@ 1.4 ;;; -*- Emacs-Lisp -*- 1.5 -;;; (c) 1994-2003 by HIROSE Yuuji [yuuji@yatex.org] 1.6 -;;; Last modified Mon Nov 17 18:28:50 2003 on firestorm 1.7 +;;; (c) 1994-2006 by HIROSE Yuuji [yuuji@yatex.org] 1.8 +;;; Last modified Sun Dec 24 15:12:35 2006 on firestorm 1.9 ;;; $Id$ 1.10 1.11 -(defconst yahtml-revision-number "1.70" 1.12 +(defconst yahtml-revision-number "1.72" 1.13 "Revision number of running yahtml.el") 1.14 1.15 ;;;[Installation] 1.16 @@ -173,9 +173,8 @@ 1.17 ;;; --- customizable variable starts here --- 1.18 (defvar yahtml-prefix "\C-c" 1.19 "*Prefix key stroke of yahtml functions.") 1.20 -(defvar yahtml-image-viewer "xv" "*Image viewer program") 1.21 -(defvar yahtml-www-browser "netscape" 1.22 - "*WWW Browser command") 1.23 +(defvar yahtml-image-viewer "display" "*Image viewer program") 1.24 +(defvar yahtml-www-browser "firefox" "*WWW Browser command") 1.25 (defvar yahtml-kanji-code 2 1.26 "*Kanji coding system number of html file; 1=sjis, 2=jis, 3=euc") 1.27 ;;(defvar yahtml-coding-system 1.28 @@ -208,13 +207,19 @@ 1.29 (defvar yahtml-hate-too-deep-indentation nil 1.30 "*Non-nil for this variable suppress deep indentation in listing environments.") 1.31 1.32 -(defvar yahtml-always-/p nil 1.33 +(defvar yahtml-always-/p t 1.34 "*Those who always use <p> with </p> set this to t.") 1.35 +(defvar yahtml-always-/li nil 1.36 + "*Those who always use <li> with </li> set this to t.") 1.37 +(defvar yahtml-always-/dt nil 1.38 + "*Those who always use <dt> with </dt> set this to t.") 1.39 +(defvar yahtml-always-/dd nil 1.40 + "*Those who always use <dd> with </dd> set this to t.") 1.41 1.42 (defvar yahtml-p-prefered-env-regexp "^\\(body\\|dl\\|blockquote\\)" 1.43 "*Regexp of envs where paragraphed sentences are prefered.") 1.44 1.45 -(defvar yahtml-template-file "~/http/template.html" 1.46 +(defvar yahtml-template-file "~/public_html/template.html" 1.47 "*Template HTML file. It'll be inserted to empty file.") 1.48 1.49 (defvar yahtml-prefer-upcases nil 1.50 @@ -223,8 +228,7 @@ 1.51 (defvar yahtml-prefer-upcase-attributes nil 1.52 "*Non-nil for preferring upcase attributes") 1.53 1.54 -(defvar yahtml-server-type 'apache 1.55 - "*WWW server program type") 1.56 +(defvar yahtml-server-type 'apache "*WWW server program type") 1.57 1.58 (defvar yahtml-apache-access-file ".htaccess" 1.59 "*Server access file name for apache") 1.60 @@ -265,6 +269,10 @@ 1.61 (defvar yahtml-indentation-boundary "^\\s *<h[1-3]>" 1.62 "*Boundary regexp for indentation calculation.") 1.63 1.64 +(defvar yahtml-html4-strict t 1.65 + "*Non-nil means editing HTML 4.01 Strict. 1.66 +Completing read for obsoleted attributes disabled.") 1.67 + 1.68 ;;; --- customizable variable ends here --- 1.69 (defvar yahtml-prefix-map nil) 1.70 (defvar yahtml-mode-map nil "Keymap used in yahtml-mode.") 1.71 @@ -305,6 +313,7 @@ 1.72 (define-key yahtml-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment) 1.73 (define-key yahtml-mode-map "\M-\C-e" 'YaTeX-end-of-environment) 1.74 (define-key yahtml-mode-map "\M-\C-m" 'yahtml-intelligent-newline) 1.75 + (define-key yahtml-mode-map "\M-\C-j" 'yahtml-intelligent-newline) 1.76 (define-key yahtml-mode-map "\C-i" 'yahtml-indent-line) 1.77 (define-key yahtml-mode-map "&" 'yahtml-insert-amps) 1.78 (let ((map yahtml-prefix-map)) 1.79 @@ -337,6 +346,7 @@ 1.80 (yahtml-define-begend-key "bc" "center" map) 1.81 (yahtml-define-begend-key "bd" "dl" map) 1.82 (yahtml-define-begend-key "bu" "ul" map) 1.83 + (yahtml-define-begend-key "bo" "ol" map) 1.84 (yahtml-define-begend-key "b1" "h1" map) 1.85 (yahtml-define-begend-key "b2" "h2" map) 1.86 (yahtml-define-begend-key "b3" "h3" map) 1.87 @@ -344,7 +354,7 @@ 1.88 (yahtml-define-begend-key "bf" "form" map) 1.89 (yahtml-define-begend-key "bs" "select" map) 1.90 (yahtml-define-begend-key "bv" "div" map) 1.91 - (yahtml-define-begend-key "bS" "div" map) 1.92 + (yahtml-define-begend-key "bS" "span" map) 1.93 (yahtml-define-begend-key "bp" "pre" map) 1.94 (YaTeX-define-key "b " 'yahtml-insert-begend map) 1.95 (YaTeX-define-key "B " 'yahtml-insert-begend-region map) 1.96 @@ -409,13 +419,17 @@ 1.97 ("UnorderedList" . "ul") 1.98 ("DefinitionList" . "dl") 1.99 ("Preformatted" . "pre") 1.100 - ("table") ("thead") ("tbody") ("tfoot") ("caption") ("tr") ("th") ("td") 1.101 + ("table") ("thead") ("tbody") ("tfoot") ("tr") ("th") ("td") 1.102 ("address") 1.103 ("h1") ("h2") ("h3") ("h4") ("h5") ("h6") 1.104 ;; ("p") ;This makes indentation screwed up! 1.105 - ("style") ("div") ("object") 1.106 + ("style") ("script") ("noscript") ("div") ("object") ("ins") ("del") 1.107 )) 1.108 1.109 +(if yahtml-html4-strict 1.110 + (setq yahtml-env-table 1.111 + (delete (assoc "center" yahtml-env-table) yahtml-env-table))) 1.112 + 1.113 ;(defvar yahtml-itemizing-regexp 1.114 ; "\\(ul\\|ol\\|dl\\)" 1.115 ; "Regexp of itemizing forms") 1.116 @@ -427,12 +441,23 @@ 1.117 (and yahtml-always-/p 1.118 (or (assoc "p" yahtml-env-table) 1.119 (setq yahtml-env-table (cons '("p") yahtml-env-table)))) 1.120 +(and yahtml-always-/li 1.121 + (or (assoc "li" yahtml-env-table) 1.122 + (setq yahtml-env-table (cons '("li") yahtml-env-table)))) 1.123 +(and yahtml-always-/dt 1.124 + (or (assoc "dt" yahtml-env-table) 1.125 + (setq yahtml-env-table (cons '("dt") yahtml-env-table)))) 1.126 +(and yahtml-always-/dd 1.127 + (or (assoc "dd" yahtml-env-table) 1.128 + (setq yahtml-env-table (cons '("dd") yahtml-env-table)))) 1.129 1.130 (defvar yahtml-typeface-table 1.131 (append 1.132 - '(("dfn") ("em") ("cite") ("code") ("kbd") ("samp") ("strike") ("s") 1.133 - ("strong") ("var") ("b") ("i") ("tt") ("u") ("big") ("small") ("font") 1.134 - ("sup") ("sub") ("span")) 1.135 + '(("dfn") ("em") ("cite") ("code") ("kbd") ("samp") ("caption") 1.136 + ("strong") ("var") ("b") ("i") ("tt") ("big") ("small") 1.137 + ("sup") ("sub") ("span") ("abbr")) 1.138 + (if (not yahtml-html4-strict) 1.139 + '(("strike") ("s") ("u") ("font"))) 1.140 yahtml-env-table) 1.141 "Default completion table of typeface designator") 1.142 (defvar yahtml-user-typeface-table nil) 1.143 @@ -440,14 +465,17 @@ 1.144 (defvar yahtml-last-typeface-cmd "a") 1.145 1.146 (defvar yahtml-single-cmd-table 1.147 - '(("hr") ("br") ("option") ("p") 1.148 - ("HorizontalLine" . "hr") 1.149 + '(("hr") ("br") ("option") 1.150 + ("HorizontalRule" . "hr") 1.151 ("BreakLine" . "br") 1.152 - ("Paragraph" . "p") 1.153 - ("Item" . "li") 1.154 - ("DefineTerm" . "dt") 1.155 - ("Description" . "dd") 1.156 - ("dd") ("dt") ("li") 1.157 + ("exec" . "!--#exec") 1.158 + ("!--#exec") 1.159 + ("include" . "!--#include") 1.160 + ("!--#include") 1.161 +;; ("Item" . "li") 1.162 +;; ("DefineTerm" . "dt") 1.163 +;; ("Description" . "dd") 1.164 +;; ("dd") ("dt") ("li") 1.165 ) 1.166 "Default completion table of HTML single command.") 1.167 (defvar yahtml-user-single-cmd-table nil) 1.168 @@ -537,6 +565,8 @@ 1.169 (setq charset 3)) 1.170 ((string-match "shift_jis" charset) 1.171 (setq charset 1)) 1.172 + ((string-match "utf-8" charset) 1.173 + (setq charset 4)) 1.174 (t (setq charset nil))) 1.175 (setq dir ""))) 1.176 (if (featurep 'mule) 1.177 @@ -576,7 +606,9 @@ 1.178 ((and YaTeX-emacs-20 (boundp 'buffer-file-coding-system)) 1.179 (setq buffer-file-coding-system 1.180 (or (and (fboundp 'set-auto-coding) buffer-file-name 1.181 - (save-excursion (set-auto-coding buffer-file-name (buffer-size)))) 1.182 + (save-excursion 1.183 + (goto-char (point-min)) 1.184 + (set-auto-coding buffer-file-name (buffer-size)))) 1.185 coding))) 1.186 ((featurep 'mule) 1.187 (set-file-coding-system coding)) 1.188 @@ -599,7 +631,7 @@ 1.189 (YaTeX-struct-begin . "<%1%2") 1.190 (YaTeX-struct-end . "</%1>") 1.191 (YaTeX-struct-name-regexp . yahtml-closable-regexp) 1.192 - (YaTeX-comment-prefix . "<!--") 1.193 + (YaTeX-comment-prefix . "<!--[^#]") 1.194 (YaTeX-coding-system . yahtml-kanji-code) ;necessary? 1.195 (YaTeX-typesetting-mode-map . yahtml-lint-buffer-map) 1.196 (fill-prefix . yahtml-fill-prefix) (fill-column . yahtml-fill-column) 1.197 @@ -854,6 +886,16 @@ 1.198 (save-excursion (insert (format "</%s>" form)))) 1.199 (if (search-backward "\"\"" p t) (forward-char 1)))) 1.200 1.201 +(defun yahtml-read-css (alist) 1.202 + (let ((completion-ignore-case t) (delim " ") 1.203 + (minibuffer-completion-table alist)) 1.204 + (read-from-minibuffer 1.205 + (substitute-command-keys 1.206 + (if YaTeX-japan 1.207 + "クラス(複数指定は\\[quoted-insert] SPCで区切る): " 1.208 + "class(or class list delimited by \\[quoted-insert] SPC): ")) 1.209 + nil YaTeX-minibuffer-completion-map nil))) 1.210 + 1.211 ;;; ---------- Add-in ---------- 1.212 (defun yahtml-addin (form) 1.213 "Check add-in function's existence and call it if exists." 1.214 @@ -863,9 +905,7 @@ 1.215 (not (equal last-command-char ?\C-j)) 1.216 (memq yahtml-current-completion-type '(multiline inline)) 1.217 (yahtml-make-optional-argument ;should be made generic? 1.218 - "class" 1.219 - (let ((completion-ignore-case t)) 1.220 - (completing-read "class: " a)))) 1.221 + "class" (yahtml-read-css a))) 1.222 (if (and (intern-soft addin) (fboundp (intern-soft addin)) 1.223 (stringp (setq s (funcall (intern addin)))) 1.224 (string< "" s)) 1.225 @@ -1060,7 +1100,8 @@ 1.226 (defvar yahtml-parameters-completion-alist 1.227 '(("align" ("top") ("middle") ("bottom") ("left") ("right") ("center")) 1.228 ("clear" ("left") ("right") ("center") ("all") ("none")) 1.229 - ("src" . file) 1.230 + ("lang" ("ja") ("en") ("kr") ("ch") ("fr")) 1.231 + ("src" . file) ("file" . file) 1.232 ("background" . file) 1.233 ("class file name" . file) ("data" . file) 1.234 ("method" ("POST") ("GET")) 1.235 @@ -1078,6 +1119,7 @@ 1.236 (defvar yahtml-content-types-alist 1.237 '(("text/css") ("text/html") ("text/plain") ("text/richtext") 1.238 ("text/sgml") ("text/xml") 1.239 + ("text/javascript") ("text/tcl") ("text/vbscript") 1.240 ("application/octet-stream") ("application/postscript") ("application/pdf") 1.241 ("application/java") 1.242 ("image/jpeg") ("image/gif") ("image/tiff") ("image/png") ("video/mpeg")) 1.243 @@ -1091,7 +1133,8 @@ 1.244 v) 1.245 (cond 1.246 ((eq alist 'file) 1.247 - (read-file-name prompt "" default nil "")) 1.248 + (let ((insert-default-directory)) 1.249 + (read-file-name prompt "" default nil ""))) 1.250 ((and alist (symbolp alist)) 1.251 (completing-read prompt (symbol-value alist) nil nil default)) 1.252 (alist 1.253 @@ -1101,25 +1144,47 @@ 1.254 1.255 (defun yahtml-make-optional-argument (opt arg) 1.256 "Make optional argument string." 1.257 - (if (string= "" arg) 1.258 + (if (or (null arg) (string= "" arg)) 1.259 "" 1.260 (concat " " 1.261 (if yahtml-prefer-upcase-attributes (upcase opt) (downcase opt)) 1.262 "=\"" arg "\""))) 1.263 1.264 +(defun yahtml:html () 1.265 + "Add-in for <html>" 1.266 + (setq yahtml-last-begend "head" yahtml-last-typeface-cmd "head") 1.267 + (yahtml-make-optional-argument 1.268 + "lang" (yahtml-read-parameter "lang" (if YaTeX-japan "ja")))) 1.269 + 1.270 +(defun yahtml:head () 1.271 + "Add-in for <head>" 1.272 + (setq yahtml-last-begend "title" yahtml-last-typeface-cmd "title") 1.273 + "") 1.274 + 1.275 (defun yahtml:body () 1.276 "Add-in function for <body>" 1.277 - (let ((b (read-string "bgcolor=")) 1.278 - (bg (yahtml-read-parameter "background" "")) 1.279 - (x (read-string "text color=")) 1.280 - (l (read-string "link color=")) 1.281 - (v (read-string "vlink color="))) 1.282 - (concat 1.283 - (yahtml-make-optional-argument "bgcolor" b) 1.284 - (yahtml-make-optional-argument "background" bg) 1.285 - (yahtml-make-optional-argument "text" x) 1.286 - (yahtml-make-optional-argument "link" l) 1.287 - (yahtml-make-optional-argument "vlink" v)))) 1.288 + (cond 1.289 + (yahtml-html4-strict nil) 1.290 + (t 1.291 + (let ((b (read-string "bgcolor=")) 1.292 + (bg (yahtml-read-parameter "background" "")) 1.293 + (x (read-string "text color=")) 1.294 + (l (read-string "link color=")) 1.295 + (v (read-string "vlink color="))) 1.296 + (concat 1.297 + (yahtml-make-optional-argument "bgcolor" b) 1.298 + (yahtml-make-optional-argument "background" bg) 1.299 + (yahtml-make-optional-argument "text" x) 1.300 + (yahtml-make-optional-argument "link" l) 1.301 + (yahtml-make-optional-argument "vlink" v)))))) 1.302 + 1.303 +(defun yahtml-make-style-parameter (proplist) 1.304 + "Make CSS property definitions in style attribute." 1.305 + (mapconcat 1.306 + '(lambda (x) (if (and (cdr x) (string< "" (cdr x))) 1.307 + (format "%s: %s;" (car x) (cdr x)))) 1.308 + (delq nil proplist) 1.309 + " ")) 1.310 1.311 (defun yahtml:img () 1.312 "Add-in function for <img>" 1.313 @@ -1150,11 +1215,23 @@ 1.314 (setq width (yahtml-read-parameter "width" width) 1.315 height (yahtml-read-parameter "height" height)) 1.316 (concat (if l "SRC" "src") "=\"" src "\"" 1.317 - (yahtml-make-optional-argument "align" alg) 1.318 (yahtml-make-optional-argument "alt" alt) 1.319 (yahtml-make-optional-argument "width" width) 1.320 (yahtml-make-optional-argument "height" height) 1.321 - (yahtml-make-optional-argument "border" brd)))) 1.322 + (if yahtml-html4-strict 1.323 + (yahtml-make-optional-argument 1.324 + "style" 1.325 + (if (or brd alg) 1.326 + (yahtml-make-style-parameter 1.327 + (list 1.328 + (if (string< "" alg) 1.329 + (cons "align" alg)) 1.330 + (if (string< "" brd) 1.331 + (cons "border" 1.332 + (format "%dpx" (string-to-int brd)))))))) 1.333 + (concat 1.334 + (yahtml-make-optional-argument "border" brd) 1.335 + (yahtml-make-optional-argument "align" alg)))))) 1.336 1.337 (defun yahtml-file-truename (file) 1.338 (cond 1.339 @@ -1301,9 +1378,9 @@ 1.340 (setq yahtml-last-single-cmd "dd") "") 1.341 1.342 (defun yahtml:p () 1.343 - (let ((alg (yahtml-read-parameter "align"))) 1.344 - (yahtml-make-optional-argument "align" alg) 1.345 -)) 1.346 + (if yahtml-html4-strict nil 1.347 + (let ((alg (yahtml-read-parameter "align"))) 1.348 + (yahtml-make-optional-argument "align" alg)))) 1.349 1.350 (defvar yahtml-input-types 1.351 '(("text") ("password") ("checkbox") ("radio") ("submit") 1.352 @@ -1344,15 +1421,39 @@ 1.353 (defun yahtml:table () 1.354 "Add-in function for `table'" 1.355 (let ((b (read-string "border=")) 1.356 - (a (yahtml-read-parameter "align"))) 1.357 - (concat 1.358 - (yahtml-make-optional-argument "border" b) 1.359 - (yahtml-make-optional-argument "align" a)))) 1.360 + (a (yahtml-read-parameter 1.361 + "align" nil '(("align" ("right")("center")))))) 1.362 + (if yahtml-html4-strict 1.363 + (yahtml-make-optional-argument 1.364 + "style" 1.365 + (if (or (string< "" b) (string< "" a)) 1.366 + (yahtml-make-style-parameter 1.367 + (append 1.368 + (if (string< "" b) 1.369 + (list 1.370 + (cons "border" (format "%dpx solid" (string-to-int b))) 1.371 + (cons "border-collapse" "collapse"))) 1.372 + (if (string< "" a) 1.373 + (cond 1.374 + ((string-match "right" a) 1.375 + (list (cons "margin-left" "auto") 1.376 + (cons "margin-right" "0"))) 1.377 + ((string-match "center" a) 1.378 + (list (cons "margin-left" "auto") 1.379 + (cons "margin-right" "auto"))))))))) 1.380 + (concat 1.381 + (yahtml-make-optional-argument "border" b) 1.382 + (yahtml-make-optional-argument "align" a))))) 1.383 + 1.384 ;(fset 'yahtml:caption 'yahtml:p) 1.385 (defun yahtml:caption () 1.386 "Add-in function for `caption' in table tag" 1.387 - (let ((yahtml-parameters-completion-alist '(("align" ("top") ("bottom"))))) 1.388 - (yahtml-make-optional-argument "align" (yahtml-read-parameter "align")))) 1.389 + (let ((par (yahtml-read-parameter "align"))) 1.390 + (if yahtml-html4-strict 1.391 + (yahtml-make-optional-argument 1.392 + "style" (if par (yahtml-make-style-parameter 1.393 + (list (cons "caption-side" par))))) 1.394 + (yahtml-make-optional-argument "align" par)))) 1.395 1.396 (defun yahtml:font () 1.397 "Add-in function for `font'" 1.398 @@ -1365,6 +1466,14 @@ 1.399 (yahtml-make-optional-argument 1.400 "type" (read-string "type=" "text/css"))) 1.401 1.402 +(defun yahtml:script () 1.403 + "Add-in function for `script'" 1.404 + (concat 1.405 + (yahtml-make-optional-argument 1.406 + "type" (yahtml-read-parameter "type" "text/javascript")) 1.407 + (yahtml-make-optional-argument 1.408 + "src" (yahtml-read-parameter "src" "")))) 1.409 + 1.410 (defun yahtml:tr () 1.411 "Add-in function for `tr'" 1.412 (setq ;yahtml-last-begend "td" ;; which do you prefer? 1.413 @@ -1400,8 +1509,14 @@ 1.414 (yahtml-url-to-path href) yahtml-css-class-alist))) 1.415 (message "") 1.416 (yahtml-make-optional-argument "href" href)))))) 1.417 - (t ;;?? 1.418 - )))) 1.419 + (t 1.420 + (concat 1.421 + (yahtml-make-optional-argument "rel" rel) 1.422 + (yahtml-make-optional-argument 1.423 + "type" (yahtml-read-parameter "type" "text/css")) 1.424 + (yahtml-make-optional-argument 1.425 + "href" (read-from-minibuffer "href: " "" yahtml-url-completion-map)) 1.426 + ))))) 1.427 1.428 (defvar yahtml:meta-names 1.429 '(("name" ("keywords")("author")("copyright")("date")("GENERATOR")))) 1.430 @@ -1468,6 +1583,10 @@ 1.431 "" 1.432 )))) 1.433 1.434 +(defun yahtml:abbr () 1.435 + "Add-in function for abbr." 1.436 + (yahtml-make-optional-argument "title" (yahtml-read-parameter "title"))) 1.437 + 1.438 ;;; ---------- Simple tag ---------- 1.439 (defun yahtml-insert-tag (region-mode &optional tag) 1.440 "Insert <TAG> </TAG> and put cursor inside of them." 1.441 @@ -1502,6 +1621,7 @@ 1.442 (yahtml-insert-tag t tag)) 1.443 1.444 1.445 +(defvar yahtml-need-single-closer nil) ;for test 1.446 (defun yahtml-insert-single (cmd) 1.447 "Insert <CMD>." 1.448 (interactive 1.449 @@ -1518,14 +1638,19 @@ 1.450 (or (cdr (assoc cmd yahtml-single-cmd-table)) cmd)) 1.451 (setq cmd (funcall (if yahtml-prefer-upcases 'upcase 'downcase) 1.452 yahtml-last-single-cmd)) 1.453 - (insert (format "<%s>" cmd))) 1.454 + (insert (format "<%s%s%s>" 1.455 + cmd 1.456 + (yahtml-addin cmd) 1.457 + (if (and yahtml-need-single-closer 1.458 + (assoc cmd '(("br")("hr")))) 1.459 + " /" ""))) 1.460 + (if (assoc cmd yahtml-env-table) 1.461 + (save-excursion (insert (format "</%s>" cmd))))) 1.462 1.463 (defun yahtml-insert-p (&optional arg) 1.464 "Convenient function to insert <p></p>" 1.465 (interactive "P") 1.466 - (if arg (yahtml-insert-tag arg "p") 1.467 - (save-excursion ;insert "/p" first to memorize "p" 1.468 - (yahtml-insert-single "/p")) ;in the last-completion variable 1.469 + (if (or yahtml-always-/p arg) (yahtml-insert-tag arg "p") 1.470 (yahtml-insert-single "p"))) 1.471 1.472 (defun yahtml-insert-amps (arg) 1.473 @@ -1551,6 +1676,13 @@ 1.474 (insert ?&)) 1.475 (t (insert (format "&#%d;" c)))))) 1.476 1.477 +(defun yahtml:!--\#include () 1.478 + (let ((file (yahtml-read-parameter "file" ""))) 1.479 + (format "%s=\"%s\"--" (if (string-match "/" file) "virtual" "file") file))) 1.480 + 1.481 +(defun yahtml:!--\#exec () 1.482 + (format "cmd=\"%s\"--" (yahtml-read-parameter "cmd" "" '(("cmd" . file))))) 1.483 + 1.484 ;;; ---------- Jump ---------- 1.485 (defun yahtml-on-href-p () 1.486 "Check if point is on href clause." 1.487 @@ -1637,7 +1769,7 @@ 1.488 (let ((href (yahtml-on-href-p)) file name (parent buffer-file-name)) 1.489 (if href 1.490 (cond 1.491 - ((string-match "^\\(ht\\|f\\)tp:" href) 1.492 + ((string-match "^\\(ht\\|f\\)tps?:" href) 1.493 (yahtml-browse-html href)) 1.494 (t (setq file (substring href 0 (string-match "#" href))) 1.495 (if (string-match "#" href) 1.496 @@ -1716,7 +1848,7 @@ 1.497 (t nil)))) 1.498 1.499 (defun yahtml-current-tag () 1.500 - "Return the current tag name." 1.501 + "Return the current tag name including #exec and #include." 1.502 (save-excursion 1.503 (let ((p (point)) b tag) 1.504 (or (bobp) 1.505 @@ -1724,32 +1856,12 @@ 1.506 (progn (skip-chars-backward "^<") (forward-char -1))) 1.507 (setq b (point)) 1.508 (skip-chars-forward "<") 1.509 - (setq tag (buffer-substring 1.510 + (setq tag (YaTeX-buffer-substring 1.511 (point) (progn (skip-chars-forward "^ \t\n") (point)))) 1.512 (goto-char b) 1.513 (forward-list 1) 1.514 (and (< p (point)) tag)))) 1.515 1.516 - 1.517 -(defun yahtml-goto-corresponding-img () 1.518 - "View image on point" 1.519 - (let ((tag (yahtml-current-tag)) image (p (point)) (case-fold-search t)) 1.520 - (if (and tag 1.521 - (string-match "img" tag) 1.522 - (save-excursion 1.523 - (re-search-backward "<\\s *img" nil t) 1.524 - (re-search-forward "src=\"?\\([^\"> ]+\\)\"?") 1.525 - (match-beginning 1) 1.526 - (setq image 1.527 - (buffer-substring (match-beginning 1) (match-end 1))))) 1.528 - (progn 1.529 - (message "Invoking %s %s..." yahtml-image-viewer image) 1.530 - (start-process 1.531 - "Viewer" " * Image Viewer *" 1.532 - shell-file-name yahtml-shell-command-option ;"-c" 1.533 - (concat yahtml-image-viewer " " image)) 1.534 - (message "Invoking %s %s...Done" yahtml-image-viewer image))))) 1.535 - 1.536 (defun yahtml-get-attrvalue (attr) 1.537 "Extract current tag's attribute value from buffer." 1.538 (let (e (case-fold-search t)) 1.539 @@ -1763,8 +1875,22 @@ 1.540 (looking-at "\"?\\([^\"> \t\n]+\\)\"?"))) 1.541 (YaTeX-match-string 1))))) 1.542 1.543 +(defun yahtml-goto-corresponding-img () 1.544 + "View image on point" 1.545 + (let ((tag (yahtml-current-tag)) image (p (point)) (case-fold-search t)) 1.546 + (if (and tag 1.547 + (string-match "img" tag) 1.548 + (setq image (yahtml-get-attrvalue "src"))) 1.549 + (progn 1.550 + (message "Invoking %s %s..." yahtml-image-viewer image) 1.551 + (start-process 1.552 + "Viewer" " * Image Viewer *" 1.553 + shell-file-name yahtml-shell-command-option ;"-c" 1.554 + (concat yahtml-image-viewer " " image)) 1.555 + (message "Invoking %s %s...Done" yahtml-image-viewer image))))) 1.556 + 1.557 (defun yahtml-goto-corresponding-source (&optional other) 1.558 - "Goto applet's source." 1.559 + "Goto applet's or script's source." 1.560 (let ((env (yahtml-current-tag)) s (p (point))) 1.561 (cond 1.562 ((string-match "applet" env) 1.563 @@ -1780,6 +1906,13 @@ 1.564 (message "No applet source specified") 1.565 (sit-for 1) 1.566 nil)) 1.567 + ((string-match "script" env) 1.568 + (if (setq s (yahtml-get-attrvalue "src")) 1.569 + (progn 1.570 + (funcall (if other 'YaTeX-switch-to-buffer-other-window 1.571 + 'YaTeX-switch-to-buffer) 1.572 + (yahtml-url-to-path s)) 1.573 + s))) 1.574 ((string-match "!--#include" env) 1.575 (cond 1.576 ((setq s (yahtml-get-attrvalue "file")) ;<!--#include file="foo"--> 1.577 @@ -1807,12 +1940,12 @@ 1.578 1.579 (defun yahtml-goto-corresponding-* (&optional other) 1.580 "Go to corresponding object." 1.581 - (interactive) 1.582 + (interactive "P") 1.583 (cond 1.584 ((yahtml-goto-corresponding-href other)) 1.585 ((yahtml-goto-corresponding-img)) 1.586 + ((yahtml-goto-corresponding-source other)) 1.587 ((yahtml-goto-corresponding-begend)) 1.588 - ((yahtml-goto-corresponding-source other)) 1.589 (t (message "I don't know where to go.")) 1.590 )) 1.591 1.592 @@ -1945,8 +2078,8 @@ 1.593 ((setq attr (yahtml-on-assignment-p)) ;if on the assignment to attr 1.594 (if (and (equal attr "class") ;treat "class" attribute specially 1.595 (setq css (yahtml-css-get-element-completion-alist tag))) 1.596 - (setq new (yahtml-read-parameter ;should be made generic? 1.597 - attr nil (list (cons "class" css)))) 1.598 + 1.599 + (setq new (yahtml-read-css css)) 1.600 ;;other than "class", read parameter normally 1.601 (setq new (yahtml-read-parameter attr))) 1.602 (goto-char (car (get 'yahtml-on-assignment-p 'region))) 1.603 @@ -2478,7 +2611,7 @@ 1.604 (defun yahtml-intelligent-newline-ul () 1.605 (interactive) 1.606 (yahtml-insert-single "li") 1.607 - (or yahtml-faithful-to-htmllint (insert " ")) 1.608 + (or yahtml-always-/li yahtml-faithful-to-htmllint (insert " ")) 1.609 (yahtml-indent-line)) 1.610 1.611 (fset 'yahtml-intelligent-newline-ol 'yahtml-intelligent-newline-ul) 1.612 @@ -2492,11 +2625,11 @@ 1.613 (cond 1.614 ((match-beginning 2) 1.615 (yahtml-insert-single "dd") 1.616 - (or yahtml-faithful-to-htmllint (insert " ")) 1.617 + (or yahtml-always-/dd yahtml-faithful-to-htmllint (insert " ")) 1.618 (setq yahtml-last-single-cmd "dt")) 1.619 ((match-beginning 3) 1.620 (yahtml-insert-single "dt") 1.621 - (or yahtml-faithful-to-htmllint (insert " ")) 1.622 + (or yahtml-always-/dt yahtml-faithful-to-htmllint (insert " ")) 1.623 (setq yahtml-last-single-cmd "dd"))) 1.624 (insert (if yahtml-prefer-upcases "<DT> " "<dt> ")) 1.625 (setq yahtml-last-single-cmd "dd")) 1.626 @@ -2526,6 +2659,35 @@ 1.627 (open-line 1) 1.628 (YaTeX-reindent c)))) 1.629 1.630 +(defun yahtml-intelligent-newline-head () 1.631 + (let ((title (read-string "Document title: ")) 1.632 + (b "<title>") (e "</title>") p) 1.633 + (yahtml-indent-line) 1.634 + (insert (format "%s" (if yahtml-prefer-upcases (upcase b) b))) 1.635 + (setq p (point)) 1.636 + (insert (format "%s%s" title (if yahtml-prefer-upcases (upcase e) e))) 1.637 + (if (string= "" title) (goto-char p)) 1.638 + (setq yahtml-last-begend "body"))) 1.639 + 1.640 +(defun yahtml-intelligent-newline-script () 1.641 + (let ((p (point)) b) 1.642 + (if (save-excursion 1.643 + (and 1.644 + (setq b (re-search-backward "<script\\>" nil t)) 1.645 + (re-search-forward 1.646 + "\\(javascript\\)\\|\\(tcl\\)\\|\\(vbscript\\)" p t))) 1.647 + (let ((js (match-end 1)) (tcl (match-end 2)) (vb (match-end 3)) 1.648 + c (srcp (re-search-backward "src=" b t))) 1.649 + (goto-char p) 1.650 + (yahtml-indent-line) 1.651 + (setq c (current-column)) 1.652 + (if srcp 1.653 + nil 1.654 + (insert "<!--\n" (cond (js "//") (tcl "#") (vb "'")) " -->") 1.655 + (beginning-of-line) 1.656 + (open-line 1) 1.657 + (YaTeX-reindent c)))))) 1.658 + 1.659 ;;; ---------- Marking ---------- 1.660 (defun yahtml-mark-begend () 1.661 "Mark current tag" 1.662 @@ -2591,23 +2753,32 @@ 1.663 (goto-char (point-min)) 1.664 (let ((alist initial) b e element class a) 1.665 (setq b (point)) 1.666 - (while (search-forward "{" nil t) 1.667 - (setq e (point)) 1.668 - (goto-char b) 1.669 - (while (re-search-forward ;ちょといい加減なREGEXP 1.670 - "\\([a-z][-a-z0-9]*\\)?\\.\\([-a-z0-9][-a-z0-9]*\\)\\>" e t) 1.671 - (setq element (YaTeX-match-string 1) 1.672 - class (YaTeX-match-string 2)) 1.673 - ;;if starts with period (match-string 1 is nil), 1.674 - ;;this is global class 1.675 - (setq element (downcase (or element "global"))) 1.676 - (if (setq a (assoc element alist)) 1.677 - (or (assoc class (cdr a)) 1.678 - (setcdr a (cons (list class) (cdr a)))) 1.679 - (setq alist (cons (list element (list class)) alist)))) 1.680 - (goto-char (1- e)) 1.681 - (search-forward "}" nil t) 1.682 - (setq b (point))) 1.683 + (while (re-search-forward "\\({\\)\\|\\(@import\\)" nil t) 1.684 + (if (match-beginning 2) 1.685 + (let ((f (YaTeX-buffer-substring 1.686 + (progn (skip-chars-forward "^\"")(1+ (point))) 1.687 + (progn (forward-char 1) 1.688 + (skip-chars-forward "^\"")(point))))) 1.689 + (if (file-exists-p f) 1.690 + (setq alist 1.691 + (append alist (yahtml-css-collect-classes-file f))))) 1.692 + (setq e (point)) 1.693 + (goto-char b) 1.694 + (while (re-search-forward ;ちょといい加減なREGEXP 1.695 + "\\([a-z][-a-z0-9]*\\)?\\.\\([-a-z0-9][-a-z0-9]*\\)\\>" 1.696 + e t) 1.697 + (setq element (YaTeX-match-string 1) 1.698 + class (YaTeX-match-string 2)) 1.699 + ;;if starts with period (match-string 1 is nil), 1.700 + ;;this is global class 1.701 + (setq element (downcase (or element "global"))) 1.702 + (if (setq a (assoc element alist)) 1.703 + (or (assoc class (cdr a)) 1.704 + (setcdr a (cons (list class) (cdr a)))) 1.705 + (setq alist (cons (list element (list class)) alist)))) 1.706 + (goto-char (1- e)) 1.707 + (search-forward "}" nil t) 1.708 + (setq b (point)))) 1.709 alist)))) 1.710 1.711 (defun yahtml-css-collect-classes-buffer (&optional initial) 1.712 @@ -2676,10 +2847,10 @@ 1.713 ("<!--#\\(include\\|exec\\|config\\|fsize\\|flastmod\\)" "-->" include) 1.714 ;; string 1.715 (hilit-string-find ?\\ string) 1.716 - (yahtml-hilit-region-tag "<\\(em\\|strong\\|b\\)\\>" bold) 1.717 + (yahtml-hilit-region-tag "<\\(strong\\|b\\)\\>" bold) 1.718 ("</?[uod]l>" 0 decl) 1.719 ("<\\(di\\|dt\\|li\\|dd\\)>" 0 label) 1.720 - (yahtml-hilit-region-tag "<\\(i\\>\\)" italic) 1.721 + (yahtml-hilit-region-tag "<\\(em\\|i\\>\\)" italic) 1.722 ;("<a\\s +href" "</a>" crossref) ;good for hilit19, but odd for font-lock.. 1.723 (yahtml-hilit-region-tag "<\\(a\\)\\s +href" crossref) 1.724 (yahtml-hilit-region-tag-itself "</?\\sw+\\>" decl) 1.725 @@ -2777,5 +2948,5 @@ 1.726 ; fill-prefix: ";;; " 1.727 ; paragraph-start: "^$\\|\\|;;;$" 1.728 ; paragraph-separate: "^$\\|\\|;;;$" 1.729 -; buffer-file-coding-system: sjis 1.730 +; coding: sjis 1.731 ; End: