yatex
diff yahtml.el @ 70:44e3a5e1e883
Fix makefile for Windows
Brush up label completion
\cite completion
Support much more about LaTeX2e
---
[yahtml]
English Info (By Jun Ohya)
Automatic pixel size detection for <img src="...">
Aware global-class of css definition
& for char-entity reference
author | yuuji |
---|---|
date | Sun, 09 Apr 2000 03:37:47 +0000 |
parents | 807c1e7e68b7 |
children | 0aaebd07dad0 |
line diff
1.1 --- a/yahtml.el Thu Jul 15 04:58:26 1999 +0000 1.2 +++ b/yahtml.el Sun Apr 09 03:37:47 2000 +0000 1.3 @@ -1,6 +1,6 @@ 1.4 ;;; -*- Emacs-Lisp -*- 1.5 -;;; (c ) 1994-1999 by HIROSE Yuuji [yuuji@gentei.org] 1.6 -;;; Last modified Wed Jul 14 18:01:18 1999 on firestorm 1.7 +;;; (c ) 1994-2000 by HIROSE Yuuji [yuuji@yatex.org] 1.8 +;;; Last modified Wed Mar 1 23:28:22 2000 on firestorm 1.9 ;;; $Id$ 1.10 1.11 ;;;[Installation] 1.12 @@ -175,7 +175,7 @@ 1.13 "*Alist of unix path name vs. URL name of WWW server. 1.14 Ex. 1.15 '((\"/usr/home/yuuji/http\" . \"http://www.comp.ae.keio.ac.jp/~yuuji\") 1.16 - (\"/usr/home/yuuji/darts/http\" . \"http://darts.comp.ae.keio.ac.jp/~darts\"))") 1.17 + (\"/home/yuuji/http\" . \"http://www.gentei.org/~yuuji\"))") 1.18 (defvar yahtml-directory-index "index.html" 1.19 "*Directory index file name; 1.20 Consult your site's WWW administrator.") 1.21 @@ -194,7 +194,7 @@ 1.22 (defvar yahtml-always-/p nil 1.23 "*Those who always use <p> with </p> set this to t.") 1.24 1.25 -(defvar yahtml-p-prefered-env-regexp "^\\(body\\|dl\\)" 1.26 +(defvar yahtml-p-prefered-env-regexp "^\\(body\\|dl\\|blockquote\\)" 1.27 "*Regexp of envs where paragraphed sentences are prefered.") 1.28 1.29 (defvar yahtml-template-file "~/http/template.html" 1.30 @@ -214,6 +214,16 @@ 1.31 1.32 (defvar yahtml-use-css t "*Use stylesheet or not") 1.33 1.34 +(defvar yahtml-image-inspection-bytes 10000 ;256 1.35 + "*Number of bytes to inspect the image for geometry information") 1.36 +(defvar yahtml:img-default-alt-format "%xx%y(%sbytes)" 1.37 + "*Default format of img entity's ALT attributes. 1.38 +%x: width, %y: height, %s: size in bytes, %c: first comment string, 1.39 +%f: filename") 1.40 + 1.41 +(defvar yahtml-use-hilit19 (featurep 'hilit19) 1.42 + "*Use hilit19 to fontify buffer or not") 1.43 + 1.44 ;;; --- customizable variable ends here --- 1.45 (defvar yahtml-prefix-map nil) 1.46 (defvar yahtml-mode-map nil "Keymap used in yahtml-mode.") 1.47 @@ -255,6 +265,7 @@ 1.48 (define-key yahtml-mode-map "\M-\C-e" 'YaTeX-end-of-environment) 1.49 (define-key yahtml-mode-map "\M-\C-m" 'yahtml-intelligent-newline) 1.50 (define-key yahtml-mode-map "\C-i" 'yahtml-indent-line) 1.51 + (define-key yahtml-mode-map "&" 'yahtml-insert-amps) 1.52 (let ((map yahtml-prefix-map)) 1.53 (YaTeX-define-key "^" 'yahtml-visit-main map) 1.54 (YaTeX-define-key "4^" 'yahtml-visit-main-other-window map) 1.55 @@ -310,7 +321,11 @@ 1.56 (YaTeX-define-key ":" 'yahtml-translate-reverse-region map) 1.57 (YaTeX-define-key "#" 'yahtml-escape-chars-region map) 1.58 ;;;;;(YaTeX-define-key "i" 'yahtml-fill-item map) 1.59 - )) 1.60 + ) 1.61 + (let ((keys (where-is-internal 'fill-paragraph global-map))) 1.62 + (while keys 1.63 + (define-key yahtml-mode-map (car keys) 'yahtml-fill-paragraph) 1.64 + (setq keys (cdr keys))))) 1.65 1.66 (if yahtml-lint-buffer-map nil 1.67 (setq yahtml-lint-buffer-map (make-keymap)) 1.68 @@ -356,7 +371,7 @@ 1.69 ("address") 1.70 ("h1") ("h2") ("h3") ("h4") ("h5") ("h6") 1.71 ;; ("p") ;This makes indentation screwed up! 1.72 - ("style") ("div") 1.73 + ("style") ("div") ("object") 1.74 )) 1.75 1.76 ;(defvar yahtml-itemizing-regexp 1.77 @@ -373,7 +388,7 @@ 1.78 1.79 (defvar yahtml-typeface-table 1.80 (append 1.81 - '(("dfn") ("em") ("cite") ("code") ("kbd") ("samp") ("strike") 1.82 + '(("dfn") ("em") ("cite") ("code") ("kbd") ("samp") ("strike") ("s") 1.83 ("strong") ("var") ("b") ("i") ("tt") ("u") ("big") ("small") ("font") 1.84 ("sup") ("sub") ("span")) 1.85 yahtml-env-table) 1.86 @@ -397,27 +412,41 @@ 1.87 (defvar yahtml-tmp-single-cmd-table nil) 1.88 (defvar yahtml-last-single-cmd nil) 1.89 1.90 +(defvar yahtml-current-completion-type nil 1.91 + "Has current completion type. This may be used in yahtml addin functions.") 1.92 + 1.93 ;(defvar yahtml-struct-name-regexp 1.94 ; "\\<\\(h[1-6]\\|[uod]l\\|html\\|body\\|title\\|head\\|table\\|t[rhd]\\|pre\\|a\\|form\\|select\\|center\\|blockquote\\)\\b") 1.95 (defvar yahtml-struct-name-regexp 1.96 (concat 1.97 "\\<\\(" 1.98 - (mapconcat (function (lambda (x) (car x))) yahtml-typeface-table "\\|") 1.99 + ;(mapconcat 'car yahtml-typeface-table "\\|") 1.100 + (mapconcat 'car yahtml-env-table "\\|") 1.101 "\\)\\b") 1.102 "Regexp of structure beginning.") 1.103 + 1.104 +(defvar yahtml-closable-regexp 1.105 + (concat 1.106 + "\\<\\(" 1.107 + (mapconcat 'car yahtml-typeface-table "\\|") 1.108 + (mapconcat 'car yahtml-env-table "\\|") 1.109 + "\\)\\b") 1.110 + "Regexp of any closable elemnts.") 1.111 + 1.112 + 1.113 (or (assoc "p" yahtml-env-table) 1.114 (setq yahtml-env-table (cons '("p") yahtml-env-table))) 1.115 1.116 -(defun yahtml-dir-default-charset () 1.117 + 1.118 +(defun yahtml-get-user-httpconf-entry (regexp) 1.119 (cond 1.120 ((and (eq yahtml-server-type 'apache) ;;check .htaccess 1.121 buffer-file-name) 1.122 (let ((dir default-directory) 1.123 charset af ext (ldir "") 1.124 + line 1.125 (case-fold-search t) 1.126 (uid (car (cdr (cdr (file-attributes ".")))))) 1.127 - (setq ext (file-name-nondirectory buffer-file-name) 1.128 - ext (substring ext (string-match "\\.[a-z0-9]+$" ext))) 1.129 (if (string-match "^[A-Z]:" dir) 1.130 (setq dir (substring dir 2))) ;remove drive letter 1.131 (while (and dir 1.132 @@ -429,33 +458,65 @@ 1.133 (set-buffer (find-file-noselect af)) 1.134 (save-excursion 1.135 (goto-char (point-min)) 1.136 - (if (re-search-forward ;search the charset for same extension 1.137 - (format "^\\s *AddType.*charset=\\(.*\\)\\%s$" ext) 1.138 - nil t) 1.139 - (progn 1.140 - (setq charset 1.141 - (buffer-substring 1.142 - (match-beginning 1) (match-end 1))) 1.143 - (cond 1.144 - ((string-match "iso-2022-jp" charset) 1.145 - (setq charset 2)) 1.146 - ((string-match "euc-jp" charset) 1.147 - (setq charset 3)) 1.148 - ((string-match "shift_jis" charset) 1.149 - (setq charset 1)) 1.150 - (t (setq charset nil))) 1.151 - (setq dir "")))) 1.152 + (if (re-search-forward regexp nil t) 1.153 + (setq line (buffer-substring 1.154 + (point-beginning-of-line) 1.155 + (point-end-of-line)) 1.156 + dir nil))) 1.157 (kill-buffer (current-buffer)))) 1.158 - (setq ldir dir 1.159 - dir (substring dir 0 (string-match "/$" dir)) 1.160 - dir (file-name-directory dir))) 1.161 - (if (featurep 'mule) 1.162 - (setq charset (cdr (assq charset YaTeX-kanji-code-alist)))) 1.163 - charset 1.164 + (if dir 1.165 + (setq ldir dir 1.166 + dir (substring dir 0 (string-match "/$" dir)) 1.167 + dir (file-name-directory dir)))) 1.168 + line 1.169 )) 1.170 (t nil)) 1.171 ) 1.172 1.173 +(defun yahtml-dir-default-charset () 1.174 + (let*((fn (file-name-nondirectory (or buffer-file-name ""))) 1.175 + (ext (substring fn (or (string-match "\\.[a-z0-9]+$" fn) 0))) 1.176 + (ptn (format "^\\s *AddType.*charset=\\(.*\\)\\%s$" ext)) 1.177 + line 1.178 + charset) 1.179 + (if (setq line (yahtml-get-user-httpconf-entry ptn)) 1.180 + (progn 1.181 + (string-match ptn line) 1.182 + (setq charset 1.183 + (substring line (match-beginning 1) (match-end 1))) 1.184 + (cond 1.185 + ((string-match "iso-2022-jp" charset) 1.186 + (setq charset 2)) 1.187 + ((string-match "euc-jp" charset) 1.188 + (setq charset 3)) 1.189 + ((string-match "shift_jis" charset) 1.190 + (setq charset 1)) 1.191 + (t (setq charset nil))) 1.192 + (setq dir ""))) 1.193 + (if (featurep 'mule) 1.194 + (setq charset (cdr (assq charset YaTeX-kanji-code-alist)))) 1.195 + charset)) 1.196 + 1.197 +(defun yahtml-get-directory-index () 1.198 + (let ((line (yahtml-get-user-httpconf-entry "^\\s *DirectoryIndex")) 1.199 + x index-list) 1.200 + ;;s/\\s *$//; 1.201 + (if line 1.202 + (progn 1.203 + (if (string-match "DirectoryIndex\\s +\\(.*\\)\\s *$" line) 1.204 + (setq line (substring line (match-beginning 1) (match-end 1)))) 1.205 + (while (string< "" line) 1.206 + (if (setq x (string-match "\\(\\s +\\)" line)) 1.207 + (setq index-list (cons (substring line 0 x) index-list) 1.208 + line (substring line (match-end 1))) 1.209 + (setq index-list (cons line index-list) 1.210 + line "")) 1.211 + ) 1.212 + (or (nreverse index-list) 1.213 + (if (listp yahtml-directory-index) 1.214 + yahtml-directory-index 1.215 + (list yahtml-directory-index))))))) 1.216 + 1.217 (defun yahtml-mode () 1.218 (interactive) 1.219 (let ((coding (or (yahtml-dir-default-charset) yahtml-kanji-code))) 1.220 @@ -479,7 +540,7 @@ 1.221 '((YaTeX-ec . "") 1.222 (YaTeX-struct-begin . "<%1%2") 1.223 (YaTeX-struct-end . "</%1>") 1.224 - (YaTeX-struct-name-regexp . yahtml-struct-name-regexp) 1.225 + (YaTeX-struct-name-regexp . yahtml-closable-regexp) 1.226 (YaTeX-comment-prefix . "<!--") 1.227 (YaTeX-coding-system . yahtml-kanji-code) ;necessary? 1.228 (YaTeX-typesetting-mode-map . yahtml-lint-buffer-map) 1.229 @@ -607,10 +668,6 @@ 1.230 ))) 1.231 (define-key yahtml-mode-map [menu-bar yahtml] 1.232 (cons "yahtml" yahtml-menu-map)) 1.233 - (let ((keys (where-is-internal 'fill-paragraph global-map))) 1.234 - (while keys 1.235 - (define-key yahtml-mode-map (car keys) 'yahtml-fill-paragraph) 1.236 - (setq keys (cdr keys)))) 1.237 (YaTeX-define-menu 1.238 'yahtml-menu-map 1.239 (nreverse 1.240 @@ -640,6 +697,7 @@ 1.241 (defun yahtml-insert-begend (&optional region env) 1.242 "Insert <cmd> ... </cmd>." 1.243 (interactive "P") 1.244 + (setq yahtml-current-completion-type 'multiline) 1.245 (let*((completion-ignore-case t) 1.246 (cmd 1.247 (or env 1.248 @@ -685,6 +743,7 @@ 1.249 (defun yahtml-insert-form (&optional form) 1.250 "Insert <FORM option=\"argument\">." 1.251 (interactive) 1.252 + (setq yahtml-current-completion-type 'single) 1.253 (or form 1.254 (let ((completion-ignore-case t)) 1.255 (setq form 1.256 @@ -707,9 +766,11 @@ 1.257 "Check add-in function's existence and call it if exists." 1.258 (let ((addin (concat "yahtml:" (downcase form))) s a) 1.259 (concat 1.260 - (if (setq a (assoc form yahtml-css-class-alist)) 1.261 - (yahtml-make-optional-argument ;should be made generic? 1.262 - "class" (completing-read "class: " (cdr a)))) 1.263 + (and (setq a (yahtml-css-get-element-completion-alist form)) 1.264 + (not (equal last-command-char ?\C-j)) 1.265 + (memq yahtml-current-completion-type '(multiline inline)) 1.266 + (yahtml-make-optional-argument ;should be made generic? 1.267 + "class" (completing-read "class: " a))) 1.268 (if (and (intern-soft addin) (fboundp (intern-soft addin)) 1.269 (stringp (setq s (funcall (intern addin)))) 1.270 (string< "" s)) 1.271 @@ -907,11 +968,15 @@ 1.272 1.273 (defvar yahtml-parameters-completion-alist 1.274 '(("align" ("top") ("middle") ("bottom") ("left") ("right") ("center")) 1.275 + ("clear" ("left") ("right") ("center") ("all") ("none")) 1.276 ("src" . file) 1.277 + ("background" . file) 1.278 + ("class file name" . file) ("data" . file) 1.279 ("method" ("POST") ("GET")) 1.280 ("rev" . yahtml-link-types-alist) 1.281 ("rel" . yahtml-link-types-alist) 1.282 - ("type" . yahtml-content-types-alist))) 1.283 + ("type" . yahtml-content-types-alist) 1.284 + ("codetype" . yahtml-content-types-alist))) 1.285 1.286 (defvar yahtml-link-types-alist 1.287 '(("alternate") ("stylesheet") ("start") ("next") ("prev") 1.288 @@ -922,7 +987,8 @@ 1.289 '(("text/css") ("text/html") ("text/plain") ("text/richtext") 1.290 ("text/sgml") ("text/xml") 1.291 ("application/octet-stream") ("application/postscript") ("application/pdf") 1.292 - ("image/jpeg") ("image/gif") ("image/tiff") ("video/mpeg")) 1.293 + ("application/java") 1.294 + ("image/jpeg") ("image/gif") ("image/tiff") ("image/png") ("video/mpeg")) 1.295 "Alist of content-types") 1.296 1.297 (defun yahtml-read-parameter (par &optional default alist) 1.298 @@ -934,7 +1000,7 @@ 1.299 (cond 1.300 ((eq alist 'file) 1.301 (read-file-name prompt "" default nil "")) 1.302 - ((symbolp alist) 1.303 + ((and alist (symbolp alist)) 1.304 (completing-read prompt (symbol-value alist) nil nil default)) 1.305 (alist 1.306 (completing-read prompt alist nil nil default)) 1.307 @@ -952,28 +1018,161 @@ 1.308 (defun yahtml:body () 1.309 "Add-in function for <body>" 1.310 (let ((b (read-string "bgcolor=")) 1.311 + (bg (yahtml-read-parameter "background" "")) 1.312 (x (read-string "text color=")) 1.313 (l (read-string "link color=")) 1.314 (v (read-string "vlink color="))) 1.315 (concat 1.316 (yahtml-make-optional-argument "bgcolor" b) 1.317 + (yahtml-make-optional-argument "background" bg) 1.318 (yahtml-make-optional-argument "text" x) 1.319 (yahtml-make-optional-argument "link" l) 1.320 (yahtml-make-optional-argument "vlink" v)))) 1.321 1.322 - 1.323 (defun yahtml:img () 1.324 "Add-in function for <img>" 1.325 (let ((src (yahtml-read-parameter "src")) 1.326 (alg (yahtml-read-parameter "align")) 1.327 - (alt (yahtml-read-parameter "alt")) 1.328 + alt 1.329 (brd (read-string "border=")) 1.330 - (l yahtml-prefer-upcase-attributes)) 1.331 + (l yahtml-prefer-upcase-attributes) 1.332 + info width height bytes comments) 1.333 + (and (stringp src) (string< "" src) (file-exists-p src) 1.334 + (setq info (yahtml-get-image-info src)) 1.335 + (car info) 1.336 + (setq width (int-to-string (car info)) 1.337 + height (int-to-string (car (cdr info))) 1.338 + bytes (car (cdr (cdr info))) 1.339 + comments (nth 4 info))) 1.340 + (if info 1.341 + (setq alt 1.342 + (YaTeX-replace-formats 1.343 + yahtml:img-default-alt-format 1.344 + (list (cons "x" width) 1.345 + (cons "y" height) 1.346 + (cons "s" (int-to-string bytes)) 1.347 + (cons "f" (file-name-nondirectory src)) 1.348 + (cons "c" (car comments)))))) 1.349 + 1.350 + (setq alt (yahtml-read-parameter "alt" alt)) 1.351 + (setq width (yahtml-read-parameter "width" width) 1.352 + height (yahtml-read-parameter "height" height)) 1.353 (concat (if l "SRC" "src") "=\"" src "\"" 1.354 (yahtml-make-optional-argument "align" alg) 1.355 (yahtml-make-optional-argument "alt" alt) 1.356 + (yahtml-make-optional-argument "width" width) 1.357 + (yahtml-make-optional-argument "height" height) 1.358 (yahtml-make-optional-argument "border" brd)))) 1.359 1.360 +(defun yahtml-file-truename (file) 1.361 + (cond 1.362 + ((fboundp 'file-truename) (file-truename (expand-file-name file))) 1.363 + (t (let ((new file)) 1.364 + (while (and (stringp (setq new (nth 0 (file-attributes file)))) 1.365 + (not (equal new file))) 1.366 + (setq file new)) 1.367 + file)))) 1.368 + 1.369 +(defun yahtml-hex-value (point length &optional little-endian) 1.370 + "Return the hex value the POINT positions LENGTH byte stream represents. 1.371 +Optional third argument LITTLE-ENDIAN is self extplanatory." 1.372 + (setq point (1+ point)) ;translate file offset to Emacs's point value 1.373 + (let ((mlt 1) 1.374 + (pos (if little-endian point (+ point length -1))) 1.375 + (direc (if little-endian 1 -1)) 1.376 + (value 0)) 1.377 + (while (> length 0) 1.378 + (setq value (+ value (* mlt (char-after pos))) 1.379 + pos (+ pos direc) 1.380 + mlt (* mlt 256) 1.381 + length (1- length))) 1.382 + value)) 1.383 + 1.384 +(defun yahtml-get-image-info (file) 1.385 + "Return the information on the image file FILE. 1.386 +Returns list of '(WIDTH HEIGHT BYTES DEPTH COMMENTLIST)." 1.387 + (save-excursion 1.388 + (let*((tmpbuf (get-buffer-create " *imgheader*")) 1.389 + width height bytes depth comment 1.390 + (file-coding-system-alist (list (cons "." 'no-conversion))) ;20 1.391 + (file-coding-system-for-read (and (boundp '*noconv*) *noconv*)) ;19 1.392 + (seekpoint 1) 1.393 + c1 c2 c3 c4 beg end 1.394 + (case-fold-search nil)) 1.395 + (setq bytes (nth 7 (file-attributes (yahtml-file-truename file)))) 1.396 + (set-buffer tmpbuf) 1.397 + (if (boundp 'mc-flag) (set (make-local-variable 'mc-flag) nil)) 1.398 + (erase-buffer) 1.399 + (if (fboundp 'set-buffer-multibyte) (set-buffer-multibyte nil)) 1.400 + (unwind-protect 1.401 + (progn 1.402 + (message "Inspecting image information of %s..." file) 1.403 + ;; Read 4bytes-more than inspection-bytes in case that 1.404 + ;; JPEG marker delimiter (4bytes) is on the alignment. 1.405 + (YaTeX-insert-file-contents 1.406 + file nil 0 (+ yahtml-image-inspection-bytes 4)) 1.407 + (goto-char (point-min)) ;assertion 1.408 + (setq c1 (char-after 1) ;cache first 4 bytes 1.409 + c2 (char-after 2) 1.410 + c3 (char-after 3) 1.411 + c4 (char-after 4)) 1.412 + (cond 1.413 + ((and (eq c1 255) (eq c2 216)) ; 0xff 0xd8 1.414 + ;;JPEG images need JPEG markers inspection 1.415 + ;;JPEG markers consist of [ 0xff ID(B) LEN(S) CONTENTS... ] 1.416 + ;; Warning: here seekpoint is measured by Emacs's point value 1.417 + ;; while yahtml-hex-vale requires file offset 1.418 + (setq seekpoint 3) ;where the first JPEG marker exists 1.419 + (catch 'exit 1.420 + (while (< seekpoint (- (buffer-size) 4)) 1.421 + (cond 1.422 + ((not (eq (char-after seekpoint) 255)) 1.423 + ;maybe corrupted, exit from loop 1.424 + (throw 'exit t)) 1.425 + ((memq (char-after (1+ seekpoint)) 1.426 + '(192 193 194 195 197 198 199 201 202 203 205 206 207)) 1.427 + ;;found! 1.428 + (setq height (yahtml-hex-value (+ seekpoint 4) 2) 1.429 + width (yahtml-hex-value (+ seekpoint 6) 2) 1.430 + depth (yahtml-hex-value (+ seekpoint 3) 1))) 1.431 + ((eq (char-after (1+ seekpoint)) 254) ;0xFE = comment 1.432 + ;; JPEG comment area 1.433 + (setq beg (+ seekpoint 2 2) 1.434 + end (+ seekpoint 1.435 + (yahtml-hex-value (1+ seekpoint) 2) 2)) 1.436 + (setq comment (cons (buffer-substring beg end) comment))) 1.437 + (t ;other markers 1.438 + nil)) ;just skip it 1.439 + (setq seekpoint (+ seekpoint 2) 1.440 + seekpoint (+ seekpoint 1.441 + (yahtml-hex-value (1- seekpoint) 2)))))) 1.442 + ((and (eq c1 137) ;0x89 1.443 + (eq c2 ?P) (eq c3 ?N) (eq c4 ?G)) 1.444 + ;;PNG Image data X=@0x10(L), Y=@0x14(L), D=@0x18(B) 1.445 + (setq width (yahtml-hex-value 16 4) 1.446 + height (yahtml-hex-value 20 4) 1.447 + depth (yahtml-hex-value 24 1))) 1.448 + ((looking-at "GIF8") 1.449 + ;;GIF Image data X=@0x6(leshort), Y=@0x8(leshort) 1.450 + (setq width (yahtml-hex-value 6 2 t) 1.451 + height (yahtml-hex-value 8 2 t))) 1.452 + ((looking-at "BM") 1.453 + ;;# OS/2, Windoze BMP files 1.454 + ;;@0x0e = 12 -> OS/2 1.x - X=@0x12(leshort), Y=@0x14(leshort) 1.455 + ;;@0x0e = 64 -> OS/2 2.x - X=@0x12(leshort), Y=@0x14(leshort) 1.456 + ;;@0x0e = 40 -> Windows 3.x - X=@0x12(lelong), Y=@0x16(lelong) 1.457 + (cond 1.458 + ((eq (yahtml-hex-value 14 2 t) 40) 1.459 + (setq width (yahtml-hex-value 18 4 t) 1.460 + height (yahtml-hex-value 22 4 t))) 1.461 + (t 1.462 + (setq width (yahtml-hex-value 18 2 t) 1.463 + height (yahtml-hex-value 20 2 t))))) 1.464 + )) 1.465 + (message "") 1.466 + (kill-buffer tmpbuf)) 1.467 + (list width height bytes depth (nreverse comment))))) 1.468 + 1.469 (defun yahtml:form () 1.470 "Add-in function `form' input format" 1.471 (concat 1.472 @@ -1101,10 +1300,38 @@ 1.473 (t ;;?? 1.474 )))) 1.475 1.476 +(defun yahtml:br () 1.477 + (yahtml-make-optional-argument "clear" (yahtml-read-parameter "clear"))) 1.478 + 1.479 +(defun yahtml:object () 1.480 + (let ((codetype (yahtml-read-parameter "codetype" "application/java")) 1.481 + data classid) 1.482 + (cond 1.483 + ((string-match "java" codetype) 1.484 + (let ((completion-ignored-extensions 1.485 + ;;any extensions except ".class" 1.486 + '(".java" ".html" ".htm" ".gif" ".jpg" ".jpeg" ".png"))) 1.487 + (setq classid (concat "java:" 1.488 + (yahtml-read-parameter "class file name")))) 1.489 + (concat 1.490 + (yahtml-make-optional-argument "codetype" codetype) 1.491 + (yahtml-make-optional-argument "classid" classid) 1.492 + (yahtml-make-optional-argument 1.493 + "width" (yahtml-read-parameter "width")) 1.494 + (yahtml-make-optional-argument 1.495 + "height" (yahtml-read-parameter "height")) 1.496 + (yahtml-make-optional-argument 1.497 + "align" (yahtml-read-parameter "align")) 1.498 + )) 1.499 + (t 1.500 + "" 1.501 + )))) 1.502 + 1.503 ;;; ---------- Simple tag ---------- 1.504 (defun yahtml-insert-tag (region-mode &optional tag) 1.505 "Insert <TAG> </TAG> and put cursor inside of them." 1.506 (interactive "P") 1.507 + (setq yahtml-current-completion-type 'inline) 1.508 (or tag 1.509 (let ((completion-ignore-case t)) 1.510 (setq tag 1.511 @@ -1160,6 +1387,29 @@ 1.512 (yahtml-insert-single "/p")) ;in the last-completion variable 1.513 (yahtml-insert-single "p"))) 1.514 1.515 +(defun yahtml-insert-amps (arg) 1.516 + "Insert char-entity references via ampersand" 1.517 + ;; Thanks; http://www.tsc.co.jp/~asada/html/wdg40_f/entities/ 1.518 + (interactive "P") 1.519 + (let*((mess "") c 1.520 + (list (append yahtml-entity-reference-chars-alist-default 1.521 + yahtml-entity-reference-chars-alist)) 1.522 + (l list)) 1.523 + (while l 1.524 + (setq mess (format "%s %c" mess (car (car l)) (cdr (car l))) 1.525 + l (cdr l))) 1.526 + (message "Char-entity reference: %s SPC=& RET=&; Other=&#..;" mess) 1.527 + (setq c (read-char)) 1.528 + (cond 1.529 + ((equal c (car-safe (assoc c list))) 1.530 + (insert (format "&%s;" (cdr (assoc c list))))) 1.531 + ((or (equal c ?\n) (equal c ?\r)) 1.532 + (insert "&;") 1.533 + (forward-char -1)) 1.534 + ((equal c ? ) 1.535 + (insert ?&)) 1.536 + (t (insert (format "&#%d;" c)))))) 1.537 + 1.538 ;;; ---------- Jump ---------- 1.539 (defun yahtml-on-href-p () 1.540 "Check if point is on href clause." 1.541 @@ -1254,7 +1504,14 @@ 1.542 (if (string< "" file) 1.543 (progn 1.544 (if (string-match "/$" file) 1.545 - (setq file (concat file yahtml-directory-index))) 1.546 + (or (catch 'dirindex 1.547 + (mapcar 1.548 + (lambda (f) 1.549 + (if (file-exists-p (concat file f)) 1.550 + (throw 'dirindex 1.551 + (setq file (concat file f))))) 1.552 + (yahtml-get-directory-index))) 1.553 + (setq file (concat file yahtml-directory-index)))) 1.554 (if (string-match "^/" file) 1.555 (setq file (yahtml-url-to-path file))) 1.556 (if other (YaTeX-switch-to-buffer-other-window file) 1.557 @@ -1279,7 +1536,9 @@ 1.558 (if (equal (char-after (point)) ?<) (forward-char 1)) 1.559 (if (and (re-search-backward "<" nil t) 1.560 (looking-at 1.561 - (concat "<\\(/?" yahtml-struct-name-regexp "\\)\\b")) 1.562 + ;(concat "<\\(/?" yahtml-struct-name-regexp "\\)\\b") 1.563 + "<\\(/?[A-Z][A-Z0-9]*\\)\\b" 1.564 + ) 1.565 (condition-case nil 1.566 (forward-list 1) 1.567 (error nil)) 1.568 @@ -1396,7 +1655,7 @@ 1.569 (unwind-protect 1.570 (progn 1.571 (set-buffer (get-buffer-create b)) 1.572 - (insert-file-contents s nil 0 100) 1.573 + (YaTeX-insert-file-contents s nil 0 100) 1.574 (if (looking-at "#!") 1.575 (if other (YaTeX-switch-to-buffer-other-window s) 1.576 (YaTeX-switch-to-buffer s)))) 1.577 @@ -1488,7 +1747,7 @@ 1.578 (let ((p (point))) 1.579 (save-excursion 1.580 (put 'yahtml-on-assignment-p 'region nil) 1.581 - (skip-chars-backward "^ \t") 1.582 + (skip-chars-backward "^ \t\n") 1.583 (and (looking-at "\\([A-Za-z0-9]+\\)\\s *=\\s *\"?\\([^ \t\"]+\\)\"?") 1.584 (< p (match-end 0)) 1.585 (>= p (1- (match-beginning 2))) 1.586 @@ -1542,9 +1801,9 @@ 1.587 (insert href)))) 1.588 ((setq attr (yahtml-on-assignment-p)) ;if on the assignment to attr 1.589 (if (and (equal attr "class") ;treat "class" attribute specially 1.590 - (setq css (assoc tag yahtml-css-class-alist))) 1.591 + (setq css (yahtml-css-get-element-completion-alist tag))) 1.592 (setq new (yahtml-read-parameter ;should be made generic? 1.593 - attr nil (list (cons "class" (cdr css))))) 1.594 + attr nil (list (cons "class" css)))) 1.595 ;;other than "class", read parameter normally 1.596 (setq new (yahtml-read-parameter attr))) 1.597 (goto-char (car (get 'yahtml-on-assignment-p 'region))) 1.598 @@ -1853,17 +2112,19 @@ 1.599 (let ((envs "[uod]l\\|table\\|[ht][rhd0-6]\\|select\\|blockquote\\|center\\|menu\\|dir\\|font") 1.600 (itemizing-envs "^\\([uod]l\\|menu\\|dir\\)$") 1.601 (itms "<\\(dt\\|dd\\|li\\|t[rdh]\\|option\\)\\b") 1.602 + (excludes 1.603 + "\\(a\\|p\\|span\\|tt\\|em\\|u\\|i\\|big\\|small\\|font\\)\\b") 1.604 inenv p col peol (case-fold-search t)) 1.605 (save-excursion 1.606 (beginning-of-line) 1.607 - (setq inenv (or (yahtml-inner-environment-but "^\\(a\\|p\\)\\b" t) 1.608 + (setq inenv (or (yahtml-inner-environment-but excludes t) 1.609 "html") 1.610 col (get 'YaTeX-inner-environment 'indent) 1.611 p (get 'YaTeX-inner-environment 'point) 1.612 op nil)) 1.613 (save-excursion 1.614 (cond 1.615 - ((string-match envs inenv) 1.616 + ((string-match (concat "^\\(" envs "\\)") inenv) 1.617 (save-excursion 1.618 (beginning-of-line) 1.619 (skip-chars-forward " \t") 1.620 @@ -1899,7 +2160,7 @@ 1.621 (interactive) 1.622 (YaTeX-reindent (yahtml-this-indent)) 1.623 (if (bolp) (skip-chars-forward " \t")) 1.624 - (let (peol col) 1.625 + (let (peol col inenv) 1.626 (if (and (setq inenv (yahtml-on-begend-p)) 1.627 (string-match 1.628 (concat "^\\<\\(" yahtml-struct-name-regexp "\\)") inenv)) 1.629 @@ -2102,6 +2363,22 @@ 1.630 (insert "<" (if yahtml-prefer-upcases "OPTION" "option") "> ") 1.631 (yahtml-indent-line)) 1.632 1.633 +(defun yahtml-intelligent-newline-style () 1.634 + (interactive) 1.635 + (if (save-excursion 1.636 + (and 1.637 + (re-search-backward "<style\\|<!-- " nil t) 1.638 + (looking-at "<style"))) 1.639 + (let (c) 1.640 + (yahtml-indent-line) 1.641 + (setq c (current-column)) 1.642 + (insert "<!--\n") 1.643 + (YaTeX-reindent c) 1.644 + (insert "-->") 1.645 + (beginning-of-line) 1.646 + (open-line 1) 1.647 + (YaTeX-reindent c)))) 1.648 + 1.649 ;;; ---------- Marking ---------- 1.650 (defun yahtml-mark-begend () 1.651 "Mark current tag" 1.652 @@ -2161,45 +2438,43 @@ 1.653 "Alist of elements vs. their classes") 1.654 1.655 (defun yahtml-css-collect-classes-region (beg end &optional initial) 1.656 - (save-restriction 1.657 - (save-excursion 1.658 + (save-excursion 1.659 + (save-restriction 1.660 (narrow-to-region beg end) 1.661 (goto-char (point-min)) 1.662 - (let ((alist initial) b e element class a 1.663 - (s1 (aref (syntax-table) ?\{ )) 1.664 - (s2 (aref (syntax-table) ?\} ))) 1.665 - ;(modify-syntax-entry ?{ "(}") 1.666 - ;(modify-syntax-entry ?} "){") 1.667 + (let ((alist initial) b e element class a) 1.668 (setq b (point)) 1.669 - (unwind-protect 1.670 - (while (search-forward "{" nil t) 1.671 - (setq e (point)) 1.672 - (goto-char b) 1.673 - (while (re-search-forward ;ちょといい加減なREGEXP 1.674 - "\\([a-z][a-z0-9]*\\)\\.\\([a-z][a-z0-9]*\\)\\>" e t) 1.675 - (setq element (YaTeX-match-string 1) 1.676 - class (YaTeX-match-string 2)) 1.677 - (if (setq a (assoc element alist)) 1.678 - (or (assoc class (cdr a)) 1.679 - (setcdr a (cons (list class) (cdr a)))) 1.680 - (setq alist (cons (list element (list class)) alist)))) 1.681 - (goto-char (1- e)) 1.682 - ;(forward-list 1) 1.683 - (search-forward "}" nil t) 1.684 - (setq b (point))) 1.685 - (aset (syntax-table) ?\{ s1) 1.686 - (aset (syntax-table) ?} s2)) 1.687 - alist)))) 1.688 + (while (search-forward "{" nil t) 1.689 + (setq e (point)) 1.690 + (goto-char b) 1.691 + (while (re-search-forward ;ちょといい加減なREGEXP 1.692 + "\\([a-z][a-z0-9]*\\)?\\.\\([a-z][a-z0-9]*\\)\\>" e t) 1.693 + (setq element (YaTeX-match-string 1) 1.694 + class (YaTeX-match-string 2)) 1.695 + ;;if starts with period (match-string 1 is nil), 1.696 + ;;this is global class 1.697 + (setq element (or element "global")) 1.698 + (if (setq a (assoc element alist)) 1.699 + (or (assoc class (cdr a)) 1.700 + (setcdr a (cons (list class) (cdr a)))) 1.701 + (setq alist (cons (list element (list class)) alist)))) 1.702 + (goto-char (1- e)) 1.703 + (search-forward "}" nil t) 1.704 + (setq b (point))) 1.705 + alist)))) 1.706 1.707 (defun yahtml-css-collect-classes-buffer (&optional initial) 1.708 (interactive) 1.709 (yahtml-css-collect-classes-region (point-min) (point-max) initial)) 1.710 1.711 (defun yahtml-css-collect-classes-file (file &optional initial) 1.712 - (let ((hilit-auto-highlight nil) (cb (current-buffer))) 1.713 - (set-buffer (find-file-noselect file)) 1.714 + (let*((hilit-auto-highlight nil) 1.715 + (openedp (get-file-buffer file)) 1.716 + (cb (current-buffer)) 1.717 + (buf (set-buffer (find-file-noselect file)))) 1.718 (prog1 1.719 (yahtml-css-collect-classes-buffer initial) 1.720 + (or openedp (kill-buffer buf)) 1.721 (set-buffer cb)))) 1.722 1.723 (defun yahtml-css-scan-styles () 1.724 @@ -2226,6 +2501,12 @@ 1.725 (yahtml-url-to-path href) alist)))) 1.726 (setq yahtml-css-class-alist alist))))) 1.727 1.728 +(defun yahtml-css-get-element-completion-alist (element) 1.729 + (let ((alist (cdr-safe (assoc element yahtml-css-class-alist))) 1.730 + (global (cdr-safe (assoc "global" yahtml-css-class-alist)))) 1.731 + (and (or alist global) 1.732 + (append alist global)))) 1.733 + 1.734 ;;; ---------- ---------- 1.735 1.736 ;;; 1.737 @@ -2237,6 +2518,7 @@ 1.738 )) 1.739 (defvar yahtml-hilit-patterns-alist 1.740 '( 1.741 + 'case-fold 1.742 ;; comments 1.743 ("<!--\\s " "-->" comment) 1.744 ;; include&exec 1.745 @@ -2267,7 +2549,7 @@ 1.746 (cons m0 (1+ (point) ))))) 1.747 1.748 ;(setq hilit-patterns-alist (delq (assq 'yahtml-mode hilit-patterns-alist) hilit-patterns-alist)) 1.749 -(and (featurep 'hilit19) 1.750 +(and yahtml-use-hilit19 1.751 (or (assq 'yahtml-mode hilit-patterns-alist) 1.752 (setq hilit-patterns-alist 1.753 (cons (cons 'yahtml-mode yahtml-hilit-patterns-alist)