yatex
diff yahtml.el @ 73:f41b01fef5d6
Stable version(hope to be)
author | yuuji |
---|---|
date | Wed, 22 May 2002 04:57:42 +0000 |
parents | 0aaebd07dad0 |
children | 1b172d26b55e |
line diff
1.1 --- a/yahtml.el Mon Dec 25 10:19:28 2000 +0000 1.2 +++ b/yahtml.el Wed May 22 04:57:42 2002 +0000 1.3 @@ -1,9 +1,9 @@ 1.4 ;;; -*- Emacs-Lisp -*- 1.5 -;;; (c ) 1994-2000 by HIROSE Yuuji [yuuji@yatex.org] 1.6 -;;; Last modified Mon Dec 25 18:56:49 2000 on firestorm 1.7 +;;; (c ) 1994-2002 by HIROSE Yuuji [yuuji@yatex.org] 1.8 +;;; Last modified Wed May 22 13:55:01 2002 on firestorm 1.9 ;;; $Id$ 1.10 1.11 -(defconst yahtml-revision-number "1.69" 1.12 +(defconst yahtml-revision-number "1.70" 1.13 "Revision number of running yahtml.el") 1.14 1.15 ;;;[Installation] 1.16 @@ -246,6 +246,13 @@ 1.17 (not yahtml-use-font-lock)) 1.18 "*Non-nil means to Use hilit19 to highlight buffer") 1.19 1.20 +(defvar yahtml-mode-abbrev-table nil 1.21 + "*Abbrev table in use in yahtml-mode buffers.") 1.22 +(define-abbrev-table 'yahtml-mode-abbrev-table ()) 1.23 + 1.24 +(defvar yahtml-indentation-boundary "^\\s *<h[1-3]>" 1.25 + "*Boundary regexp for indentation calculation.") 1.26 + 1.27 ;;; --- customizable variable ends here --- 1.28 (defvar yahtml-prefix-map nil) 1.29 (defvar yahtml-mode-map nil "Keymap used in yahtml-mode.") 1.30 @@ -452,7 +459,10 @@ 1.31 (mapconcat 'car yahtml-env-table "\\|") 1.32 "\\)\\b") 1.33 "Regexp of any closable elemnts.") 1.34 - 1.35 + 1.36 +(defvar yahtml-indent-listing-constant t 1.37 + "*Nil means indentation for listing obeys the column of `>'. 1.38 +T for static indentation depth") 1.39 1.40 (or (assoc "p" yahtml-env-table) 1.41 (setq yahtml-env-table (cons '("p") yahtml-env-table))) 1.42 @@ -540,24 +550,27 @@ 1.43 (defvar yahtml-mode-old-mode nil) 1.44 (defun yahtml-mode () 1.45 (interactive) 1.46 - (kill-all-local-variables) 1.47 + (let ((old-mm major-mode)) ;Emacs21.0.95 resets major-mode 1.48 + (kill-all-local-variables) ;with kill-all-local-variables 1.49 + (if (not (eq 'yahtml-mode old-mm)) 1.50 + (set (make-local-variable 'yahtml-mode-old-mode) old-mm))) 1.51 (let ((coding (or (yahtml-dir-default-charset) yahtml-kanji-code))) 1.52 (cond 1.53 ((and YaTeX-emacs-20 (boundp 'buffer-file-coding-system)) 1.54 (setq buffer-file-coding-system 1.55 (or (and (fboundp 'set-auto-coding) buffer-file-name 1.56 - (save-excursion (set-auto-coding buffer-file-name 2000))) 1.57 + (save-excursion (set-auto-coding buffer-file-name (buffer-size)))) 1.58 coding))) 1.59 ((featurep 'mule) 1.60 (set-file-coding-system coding)) 1.61 ((boundp 'NEMACS) 1.62 (make-local-variable 'kanji-fileio-code) 1.63 (setq kanji-fileio-code coding)))) 1.64 - (if (not (eq 'yahtml-mode major-mode)) 1.65 - (set (make-local-variable 'yahtml-mode-old-mode) major-mode)) 1.66 (setq major-mode 'yahtml-mode 1.67 mode-name "yahtml" 1.68 - YaTeX-current-file-name (file-name-nondirectory (buffer-file-name))) 1.69 + YaTeX-current-file-name (file-name-nondirectory 1.70 + (or (buffer-file-name) "")) 1.71 + local-abbrev-table yahtml-mode-abbrev-table) 1.72 (mapcar 1.73 (function (lambda (x) 1.74 (make-local-variable (car x)) 1.75 @@ -833,14 +846,15 @@ 1.76 (not (equal last-command-char ?\C-j)) 1.77 (memq yahtml-current-completion-type '(multiline inline)) 1.78 (yahtml-make-optional-argument ;should be made generic? 1.79 - "class" (completing-read "class: " a))) 1.80 + "class" 1.81 + (let ((completion-ignore-case t)) 1.82 + (completing-read "class: " a)))) 1.83 (if (and (intern-soft addin) (fboundp (intern-soft addin)) 1.84 (stringp (setq s (funcall (intern addin)))) 1.85 (string< "" s)) 1.86 (if (eq (aref s 0) ? ) s (concat " " s)) 1.87 "")))) 1.88 1.89 - 1.90 (defvar yahtml-completing-buffer nil) 1.91 (defun yahtml-collect-labels (&optional file) 1.92 "Collect current buffers label (<?? name=...>). 1.93 @@ -881,14 +895,15 @@ 1.94 "Complete external URL from history or local file name." 1.95 (interactive) 1.96 (let ((p (point)) initial i2 cmpl path dir file listfunc beg labels 1.97 - (lim (YaTeX-minibuffer-begin))) 1.98 + (lim (YaTeX-minibuffer-begin)) 1.99 + (min (if (fboundp 'field-beginning) (field-beginning) (point-min)))) 1.100 (setq initial (YaTeX-minibuffer-string)) 1.101 (cond 1.102 ((string-match "^http:" initial) 1.103 (setq cmpl (try-completion initial yahtml-urls) 1.104 listfunc (list 'lambda nil 1.105 (list 'all-completions initial 'yahtml-urls)) 1.106 - beg (point-min))) 1.107 + beg min)) 1.108 ((setq beg (string-match "#" initial)) 1.109 (or (equal beg 0) ;begin with # 1.110 (progn 1.111 @@ -901,7 +916,7 @@ 1.112 listfunc (list 'lambda () 1.113 (list 'all-completions 1.114 initial (list 'quote labels))) 1.115 - beg (+ (point-min) beg))) 1.116 + beg (+ min beg))) 1.117 (t 1.118 (setq path (if (string-match "^/" initial) 1.119 (or (yahtml-url-to-path initial) initial) 1.120 @@ -1035,7 +1050,8 @@ 1.121 ("rev" . yahtml-link-types-alist) 1.122 ("rel" . yahtml-link-types-alist) 1.123 ("type" . yahtml-content-types-alist) 1.124 - ("codetype" . yahtml-content-types-alist))) 1.125 + ("codetype" . yahtml-content-types-alist) 1.126 + ("http-equiv" ("Refresh")))) 1.127 1.128 (defvar yahtml-link-types-alist 1.129 '(("alternate") ("stylesheet") ("start") ("next") ("prev") 1.130 @@ -1177,7 +1193,7 @@ 1.131 c3 (char-after 3) 1.132 c4 (char-after 4)) 1.133 (cond 1.134 - ((and (eq c1 255) (eq c2 216)) ; 0xff 0xd8 1.135 + ((and (eq c1 ?\377) (eq c2 ?\330)) ; 0xff 0xd8 1.136 ;;JPEG images need JPEG markers inspection 1.137 ;;JPEG markers consist of [ 0xff ID(B) LEN(S) CONTENTS... ] 1.138 ;; Warning: here seekpoint is measured by Emacs's point value 1.139 @@ -1186,16 +1202,19 @@ 1.140 (catch 'exit 1.141 (while (< seekpoint (- (buffer-size) 4)) 1.142 (cond 1.143 - ((not (eq (char-after seekpoint) 255)) 1.144 + ((not (eq (char-after seekpoint) ?\377)) 1.145 ;maybe corrupted, exit from loop 1.146 (throw 'exit t)) 1.147 - ((memq (char-after (1+ seekpoint)) 1.148 - '(192 193 194 195 197 198 199 201 202 203 205 206 207)) 1.149 + ((memq 1.150 + (char-after (1+ seekpoint)) 1.151 + '(?\300 ?\301 ?\302 ?\303 1.152 + ?\305 ?\306 ?\307 ?\311 ?\312 ?\313 ?\315 ?\316 ?\317)) 1.153 + ;;'(192 193 194 195 197 198 199 201 202 203 205 206 207 1.154 ;;found! 1.155 (setq height (yahtml-hex-value (+ seekpoint 4) 2) 1.156 width (yahtml-hex-value (+ seekpoint 6) 2) 1.157 depth (yahtml-hex-value (+ seekpoint 3) 1))) 1.158 - ((eq (char-after (1+ seekpoint)) 254) ;0xFE = comment 1.159 + ((eq (char-after (1+ seekpoint)) ?\376) ;0xFE = comment 1.160 ;; JPEG comment area 1.161 (setq beg (+ seekpoint 2 2) 1.162 end (+ seekpoint 1.163 @@ -1206,7 +1225,7 @@ 1.164 (setq seekpoint (+ seekpoint 2) 1.165 seekpoint (+ seekpoint 1.166 (yahtml-hex-value (1- seekpoint) 2)))))) 1.167 - ((and (eq c1 137) ;0x89 1.168 + ((and (eq c1 ?\211) ;0x89 1.169 (eq c2 ?P) (eq c3 ?N) (eq c4 ?G)) 1.170 ;;PNG Image data X=@0x10(L), Y=@0x14(L), D=@0x18(B) 1.171 (setq width (yahtml-hex-value 16 4) 1.172 @@ -1236,7 +1255,7 @@ 1.173 (defun yahtml:form () 1.174 "Add-in function `form' input format" 1.175 (concat 1.176 - " " (if yahtml-prefer-upcase-attributes "METHOD" "method=") 1.177 + " " (if yahtml-prefer-upcase-attributes "METHOD" "method") "=" 1.178 (completing-read "Method: " '(("POST") ("GET")) nil t) 1.179 " " (if yahtml-prefer-upcase-attributes "ACTION" "action") "=\"" 1.180 (read-string "Action: ") "\"" 1.181 @@ -1249,7 +1268,14 @@ 1.182 (read-string "name: ") "\"")) 1.183 1.184 (defun yahtml:ol () 1.185 - (setq yahtml-last-single-cmd "li") "") 1.186 + "Add-in function for <ol>" 1.187 + (setq yahtml-last-single-cmd "li") 1.188 + (let ((start (read-string "start=")) 1.189 + (type (completing-read 1.190 + "type=" '(("1") ("a") ("A") ("i") ("I")) nil t))) 1.191 + (concat 1.192 + (yahtml-make-optional-argument "start" start) 1.193 + (yahtml-make-optional-argument "type" type)))) 1.194 (defun yahtml:ul () 1.195 (setq yahtml-last-single-cmd "li") "") 1.196 (defun yahtml:dl () 1.197 @@ -1360,6 +1386,44 @@ 1.198 (t ;;?? 1.199 )))) 1.200 1.201 +(defvar yahtml:meta-names 1.202 + '(("name" ("keywords")("author")("copyright")("date")("GENERATOR")))) 1.203 + 1.204 +(defun yahtml:meta () 1.205 + (let ((name (yahtml-make-optional-argument 1.206 + "name" 1.207 + (yahtml-read-parameter "name" nil yahtml:meta-names))) 1.208 + http-equiv content) 1.209 + (if (string= "" name) 1.210 + (if (string-match 1.211 + "Content-type" 1.212 + (setq http-equiv (yahtml-make-optional-argument 1.213 + "http-equiv" 1.214 + (yahtml-read-parameter "http-equiv" nil)))) 1.215 + (error "It's very bad idea to set Content-type in META. %s" 1.216 + "See docs/qanda") 1.217 + (concat http-equiv 1.218 + (yahtml-make-optional-argument 1.219 + "content" (yahtml-read-parameter "content")))) 1.220 + (concat 1.221 + name 1.222 + (yahtml-make-optional-argument 1.223 + "content" 1.224 + (cond 1.225 + ((string-match "date" name) 1.226 + (read-string "Date: " (current-time-string))) 1.227 + ((string-match "author" name) 1.228 + (read-string "Author: " 1.229 + (if (and (user-full-name) (string< "" (user-full-name))) 1.230 + (user-full-name) 1.231 + (user-login-name)))) 1.232 + ((string-match "GENERATOR" name) 1.233 + (setq content (read-string "Generator: " "User-agent: ")) 1.234 + (if (string-match "yahtml" content) 1.235 + (message "Thank you!")) 1.236 + content) 1.237 + (t (read-string (concat name ": "))))))))) 1.238 + 1.239 (defun yahtml:br () 1.240 (yahtml-make-optional-argument "clear" (yahtml-read-parameter "clear"))) 1.241 1.242 @@ -1571,7 +1635,8 @@ 1.243 (if (file-exists-p (concat file f)) 1.244 (throw 'dirindex 1.245 (setq file (concat file f)))))) 1.246 - (yahtml-get-directory-index))) 1.247 + (yahtml-get-directory-index)) 1.248 + nil) 1.249 (setq file (concat file yahtml-directory-index)))) 1.250 (if (string-match "^/" file) 1.251 (setq file (yahtml-url-to-path file))) 1.252 @@ -2173,7 +2238,7 @@ 1.253 (itemizing-envs "^\\([uod]l\\|menu\\|dir\\)$") 1.254 (itms "<\\(dt\\|dd\\|li\\|t[rdh]\\|option\\)\\b") 1.255 (excludes 1.256 - "\\(a\\|p\\|span\\|tt\\|em\\|u\\|i\\|big\\|small\\|font\\)\\b") 1.257 + "\\(a\\|p\\|span\\|code\\|tt\\|em\\|u\\|i\\|big\\|small\\|font\\)\\b") 1.258 inenv p col peol (case-fold-search t)) 1.259 (save-excursion 1.260 (beginning-of-line) 1.261 @@ -2204,12 +2269,15 @@ 1.262 (goto-char p) 1.263 (re-search-forward itms op t) 1.264 (progn 1.265 - (skip-chars-forward "^>") 1.266 - (skip-chars-forward ">") 1.267 - (skip-chars-forward " \t") 1.268 - (setq col (if (looking-at "$") 1.269 - (+ col yahtml-environment-indent) 1.270 - (current-column))))))) 1.271 + (if yahtml-indent-listing-constant 1.272 + (setq col (+ (current-column) 1.273 + (if yahtml-faithful-to-htmllint 1 2))) 1.274 + (skip-chars-forward "^>") 1.275 + (skip-chars-forward ">") 1.276 + (skip-chars-forward " \t") 1.277 + (setq col (if (looking-at "$") 1.278 + (+ col yahtml-environment-indent) 1.279 + (current-column)))))))) 1.280 col) 1.281 (t 1.282 (+ col yahtml-environment-indent))))) 1.283 @@ -2402,7 +2470,7 @@ 1.284 (interactive) 1.285 (let ((case-fold-search t)) 1.286 (if (save-excursion 1.287 - (re-search-backward "<\\(\\(dt\\)\\|\\(dd\\)\\)>" 1.288 + (re-search-backward "<\\(\\(dt\\)\\|\\(dd\\)\\)[ \t>]" 1.289 (get 'YaTeX-inner-environment 'point) t)) 1.290 (cond 1.291 ((match-beginning 2) 1.292 @@ -2510,12 +2578,12 @@ 1.293 (setq e (point)) 1.294 (goto-char b) 1.295 (while (re-search-forward ;ちょといい加減なREGEXP 1.296 - "\\([a-z][a-z0-9]*\\)?\\.\\([a-z][a-z0-9]*\\)\\>" e t) 1.297 + "\\([a-z][-a-z0-9]*\\)?\\.\\([-a-z0-9][-a-z0-9]*\\)\\>" e t) 1.298 (setq element (YaTeX-match-string 1) 1.299 class (YaTeX-match-string 2)) 1.300 ;;if starts with period (match-string 1 is nil), 1.301 ;;this is global class 1.302 - (setq element (or element "global")) 1.303 + (setq element (downcase (or element "global"))) 1.304 (if (setq a (assoc element alist)) 1.305 (or (assoc class (cdr a)) 1.306 (setcdr a (cons (list class) (cdr a)))) 1.307 @@ -2568,7 +2636,7 @@ 1.308 (setq yahtml-css-class-alist alist))))) 1.309 1.310 (defun yahtml-css-get-element-completion-alist (element) 1.311 - (let ((alist (cdr-safe (assoc element yahtml-css-class-alist))) 1.312 + (let ((alist (cdr-safe (assoc (downcase element) yahtml-css-class-alist))) 1.313 (global (cdr-safe (assoc "global" yahtml-css-class-alist)))) 1.314 (and (or alist global) 1.315 (append alist global)))) 1.316 @@ -2615,9 +2683,12 @@ 1.317 (defun yahtml-hilit-region-tag-itself (ptn) 1.318 "Return list of start/end point of <tag options...> itself." 1.319 (if (re-search-forward ptn nil t) 1.320 - (let ((m0 (match-beginning 0))) 1.321 - (skip-chars-forward "^>") 1.322 - (cons m0 (1+ (point) ))))) 1.323 + (let ((m0 (match-beginning 0)) (e0 (match-end 0))) 1.324 + (skip-chars-forward "^<>") 1.325 + (if (eq (char-after (point)) ?<) nil 1.326 + (prog1 1.327 + (cons m0 (min (point-max) (1+ (point)))) 1.328 + (goto-char e0)))))) 1.329 1.330 ;(setq hilit-patterns-alist (delq (assq 'yahtml-mode hilit-patterns-alist) hilit-patterns-alist)) 1.331 (and yahtml-use-hilit19 1.332 @@ -2666,6 +2737,11 @@ 1.333 (delq 'yahtml-mode hilit-mode-enable-list)))) 1.334 (yahtml-font-lock-set-default-keywords))) 1.335 1.336 +(defun yahtml-font-lock-recenter (&optional arg) 1.337 + (interactive "P") 1.338 + (font-lock-mode -1) ;is stupid, but sure. 1.339 + (font-lock-mode 1)) 1.340 + 1.341 ;; (defun yahtml-fontify-to-tagend (lim) 1.342 ;; "*Fontify any tag including < and >. 1.343 ;; This is invalid use of font-lock function. Therefore