yatex
diff yahtml.el @ 68:0eb6997bee16
More adjustment for Emacs20 and XEmacs
[prefix] g for <applet> <!--#include> <!--#exec>
author | yuuji |
---|---|
date | Mon, 26 Oct 1998 12:05:32 +0000 |
parents | 36a48185b95a |
children | 807c1e7e68b7 |
line diff
1.1 --- a/yahtml.el Tue Dec 16 13:28:38 1997 +0000 1.2 +++ b/yahtml.el Mon Oct 26 12:05:32 1998 +0000 1.3 @@ -1,7 +1,9 @@ 1.4 ;;; -*- Emacs-Lisp -*- 1.5 ;;; (c ) 1994-1997 by HIROSE Yuuji [yuuji@ae.keio.ac.jp] 1.6 -;;; Last modified Tue Dec 16 21:10:05 1997 on crx 1.7 +;;; Last modified Mon Oct 26 19:57:36 1998 on firestorm 1.8 ;;; $Id$ 1.9 +(defconst yahtml-revision-number "1.65.5" 1.10 + "Revision number of running yatex.el") 1.11 1.12 ;;;[Installation] 1.13 ;;; 1.14 @@ -121,8 +123,7 @@ 1.15 ;;; (lisp変数 yahtml-www-browser の設定をお忘れな 1.16 ;;; く。お推めは "netscape" で、ねすけの場合既にねす 1.17 ;;; けが起動されていた場合そのねすけに Reload 命令を 1.18 -;;; 送るという芸当が出来ます。ただし今のところX版の 1.19 -;;; ねすけちゃんだけ) 1.20 +;;; 送るという芸当が出来ます) 1.21 ;;; * [prefix] a YaTeX のアクセント記号補完と同じです。 1.22 ;;; < > 等が入力できます。 1.23 ;;; 1.24 @@ -340,7 +341,7 @@ 1.25 1.26 (defvar yahtml-typeface-table 1.27 (append 1.28 - '(("dfn") ("em") ("cite") ("code") ("kbd") ("samp") 1.29 + '(("dfn") ("em") ("cite") ("code") ("kbd") ("samp") ("strike") 1.30 ("strong") ("var") ("b") ("i") ("tt") ("u") ("address") ("font")) 1.31 yahtml-env-table) 1.32 "Default completion table of typeface designator") 1.33 @@ -380,13 +381,14 @@ 1.34 (interactive) 1.35 (cond 1.36 ((and YaTeX-emacs-20 (fboundp 'coding-system-equal)) 1.37 - (if t (or (coding-system-equal 1.38 - yahtml-coding-system buffer-file-coding-system) 1.39 - (set-buffer-file-coding-system yahtml-coding-system)) 1.40 - ;;^v which is better? 1.41 - (let ((bmp (buffer-modified-p))) 1.42 + (let ((mp (buffer-modified-p)) 1.43 + (ud (memq buffer-file-coding-system 1.44 + '(undecided undecided-unix undecided-dos undecided-mac)))) 1.45 + (if (coding-system-equal 1.46 + yahtml-coding-system buffer-file-coding-system) 1.47 + nil ; if coding-system is the same, do nothing 1.48 (set-buffer-file-coding-system yahtml-coding-system) 1.49 - (set-buffer-modified-p bmp)))) 1.50 + (if ud (set-buffer-modified-p mp))))) 1.51 ((featurep 'mule) 1.52 (set-file-coding-system yahtml-coding-system)) 1.53 ((boundp 'NEMACS) 1.54 @@ -636,7 +638,7 @@ 1.55 1.56 (defvar yahtml-completing-buffer nil) 1.57 (defun yahtml-collect-labels (&optional file) 1.58 - "Collect current buffers label (<a name=...>). 1.59 + "Collect current buffers label (<?? name=...>). 1.60 If optional argument FILE is specified collect labels in FILE." 1.61 (let (list bound) 1.62 (save-excursion 1.63 @@ -645,10 +647,10 @@ 1.64 (set-buffer (find-file-noselect file)))) 1.65 (save-excursion 1.66 (goto-char (point-min)) 1.67 - (while (re-search-forward "<a\\b" nil t) 1.68 + (while (re-search-forward "<\\w+\\b" nil t) 1.69 (setq bound (match-end 0)) 1.70 (search-forward ">" nil t) 1.71 - (if (and (re-search-backward "\\(name\\|id\\)=" bound t) 1.72 + (if (and (re-search-backward "\\(name\\|id\\)\\s *=" bound t) 1.73 (progn 1.74 (goto-char (match-end 0)) 1.75 (skip-chars-forward " \t\n") 1.76 @@ -863,7 +865,9 @@ 1.77 1.78 (defun yahtml:font () 1.79 "Add-in function for `font'" 1.80 - (yahtml-make-optional-argument "color" (read-string "color="))) 1.81 + (concat 1.82 + (yahtml-make-optional-argument "color" (read-string "color=")) 1.83 + (yahtml-make-optional-argument "size" (read-string "size=")))) 1.84 1.85 ;;; ---------- Simple tag ---------- 1.86 (defun yahtml-insert-tag (region-mode &optional tag) 1.87 @@ -920,9 +924,9 @@ 1.88 "Convenient function to insert <p></p>" 1.89 (interactive "P") 1.90 (if arg (yahtml-insert-tag nil "p") 1.91 - (insert "<p>") 1.92 - (save-excursion 1.93 - (insert "</p>")))) 1.94 + (save-excursion ;insert "/p" first to memorize "p" 1.95 + (yahtml-insert-single "/p")) ;in the last-completion variable 1.96 + (yahtml-insert-single "p"))) 1.97 1.98 ;;; ---------- Jump ---------- 1.99 (defun yahtml-on-href-p () 1.100 @@ -1028,7 +1032,7 @@ 1.101 1.102 (defun yahtml-jump-to-name (name) 1.103 "Jump to html's named tag." 1.104 - (setq name (format "name\\s *=\\s *\"?%s\"?" name)) 1.105 + (setq name (format "\\(name\\|id\\)\\s *=\\s *\"?%s\"?" name)) 1.106 (or (and (re-search-forward name nil t) (goto-char (match-beginning 0))) 1.107 (and (re-search-backward name nil t) (goto-char (match-beginning 0))) 1.108 (message "Named tag `%s' not found" (substring href 1)))) 1.109 @@ -1110,6 +1114,61 @@ 1.110 (concat yahtml-image-viewer " " image)) 1.111 (message "Invoking %s %s...Done" yahtml-image-viewer image))))) 1.112 1.113 +(defun yahtml-get-attrvalue (attr) 1.114 + "Extract current tag's attribute value from buffer." 1.115 + (let (e (case-fold-search t)) 1.116 + (save-excursion 1.117 + (or (looking-at "<") 1.118 + (progn (skip-chars-backward "^<") (backward-char 1))) 1.119 + (setq e (save-excursion (forward-list 1) (point))) 1.120 + (if (and 1.121 + (re-search-forward (concat "\\b" attr "\\b") e t) 1.122 + (progn (skip-chars-forward " \t\n=") 1.123 + (looking-at "\"?\\([^\"> \t\n]+\\)\"?"))) 1.124 + (YaTeX-match-string 1))))) 1.125 + 1.126 +(defun yahtml-goto-corresponding-source (&optional other) 1.127 + "Goto applet's source." 1.128 + (let ((env (yahtml-current-tag)) s (p (point))) 1.129 + (cond 1.130 + ((string-match "applet" env) 1.131 + (if (setq s (yahtml-get-attrvalue "code")) 1.132 + (progn 1.133 + (setq s (YaTeX-match-string 1) 1.134 + s (concat 1.135 + (substring s 0 (string-match "\\.[A-Za-z]+$" s)) 1.136 + ".java")) 1.137 + (if other (YaTeX-switch-to-buffer-other-window s) 1.138 + (YaTeX-switch-to-buffer s)) 1.139 + s) ;return source file name 1.140 + (message "No applet source specified") 1.141 + (sit-for 1) 1.142 + nil)) 1.143 + ((string-match "!--#include" env) 1.144 + (cond 1.145 + ((setq s (yahtml-get-attrvalue "file")) ;<!--#include file="foo"--> 1.146 + (if other (YaTeX-switch-to-buffer-other-window s) 1.147 + (YaTeX-switch-to-buffer s)) 1.148 + s) 1.149 + ((setq s (yahtml-get-attrvalue "virtual"));<!--#include virtual="foo"--> 1.150 + (setq s (yahtml-url-to-path s)) 1.151 + (if other (YaTeX-switch-to-buffer-other-window s) 1.152 + (YaTeX-switch-to-buffer s)) 1.153 + s))) 1.154 + ((and (string-match "!--#exec" env) 1.155 + (setq s (yahtml-get-attrvalue "cmd"))) 1.156 + (setq s (substring s 0 (string-match " \t\\?" s))) ;get argv0 1.157 + (let ((b " *yahtmltmp*")) ;peek a little 1.158 + (unwind-protect 1.159 + (progn 1.160 + (set-buffer (get-buffer-create b)) 1.161 + (insert-file-contents s nil 0 100) 1.162 + (if (looking-at "#!") 1.163 + (if other (YaTeX-switch-to-buffer-other-window s) 1.164 + (YaTeX-switch-to-buffer s)))) 1.165 + (kill-buffer (get-buffer b))) 1.166 + (get-file-buffer s)))))) 1.167 + 1.168 (defun yahtml-goto-corresponding-* (&optional other) 1.169 "Go to corresponding object." 1.170 (interactive) 1.171 @@ -1117,6 +1176,7 @@ 1.172 ((yahtml-goto-corresponding-href other)) 1.173 ((yahtml-goto-corresponding-img)) 1.174 ((yahtml-goto-corresponding-begend)) 1.175 + ((yahtml-goto-corresponding-source other)) 1.176 (t (message "I don't know where to go.")) 1.177 )) 1.178 1.179 @@ -1132,7 +1192,7 @@ 1.180 1.181 ;;; ---------- killing ---------- 1.182 (defun yahtml-kill-begend (&optional whole) 1.183 - (let ((tag (yahtml-on-begend-p)) p q r) 1.184 + (let ((tag (yahtml-on-begend-p)) p q r bbolp) 1.185 (if tag 1.186 (save-excursion 1.187 (or (looking-at "<") 1.188 @@ -1147,23 +1207,26 @@ 1.189 (setq q (point))) ;now q has end-line's (point) 1.190 (if (not whole) 1.191 (kill-region 1.192 - (progn (skip-chars-backward " \t") (if (bolp) (point) q)) 1.193 + (progn (skip-chars-backward " \t") 1.194 + (if (setq bbolp (bolp)) (point) q)) 1.195 (progn (forward-list 1) 1.196 (setq r (point)) 1.197 (skip-chars-forward " \t") 1.198 - (if (and (eolp) (not (eobp))) (1+ (point)) r)))) 1.199 + (if (and bbolp (eolp) (not (eobp))) (1+ (point)) r)))) 1.200 (goto-char p) 1.201 (skip-chars-backward " \t") 1.202 (if (not whole) 1.203 (progn 1.204 (kill-append 1.205 (buffer-substring 1.206 - (setq p (if (bolp) (point) p)) 1.207 + (setq p (if (setq bbolp (bolp)) (point) p)) 1.208 (setq q (progn 1.209 (forward-list 1) 1.210 (setq r (point)) 1.211 (skip-chars-forward " \t") 1.212 - (if (and (eolp) (not (eobp))) (1+ (point)) r)))) 1.213 + (if (and bbolp (eolp) (not (eobp))) 1.214 + (1+ (point)) 1.215 + r)))) 1.216 t) 1.217 (delete-region p q)) 1.218 (kill-region 1.219 @@ -1271,6 +1334,7 @@ 1.220 (setq tag (if yahtml-prefer-upcases (upcase tag) (downcase tag))) 1.221 (insert (format "%s%s" tag (yahtml-addin tag))) 1.222 (goto-char q) 1.223 + (set-marker q nil) 1.224 (delete-region (point) (progn (skip-chars-forward "^>") (point))) 1.225 (insert tag)))) 1.226 t)))) 1.227 @@ -1305,6 +1369,8 @@ 1.228 'yahtml-tmp-form-table))) 1.229 (delete-region beg end) 1.230 (goto-char beg) 1.231 + (set-marker beg nil) 1.232 + (set-marker end nil) 1.233 (insert new) 1.234 t) 1.235 (goto-char p) 1.236 @@ -1388,8 +1454,10 @@ 1.237 1.238 (defun yahtml-fill-paragraph (arg) 1.239 (interactive "P") 1.240 - (let*((case-fold-search t) (p (point)) 1.241 + (let*((case-fold-search t) (p (point)) fill-prefix 1.242 (e (or (yahtml-inner-environment-but "^\\(a\\|p\\)\\b" t) "html")) 1.243 + indent 1.244 + (startp (get 'YaTeX-inner-environment 'point)) 1.245 (prep (string-match "^pre$" e)) 1.246 (ps1 (if prep (default-value 'paragraph-start) 1.247 paragraph-start)) 1.248 @@ -1401,6 +1469,12 @@ 1.249 (progn 1.250 (if prep 1.251 (fset 'move-to-column 'yahtml-move-to-column)) 1.252 + (save-excursion 1.253 + (beginning-of-line) 1.254 + (indent-to-column (yahtml-this-indent)) 1.255 + (setq fill-prefix 1.256 + (buffer-substring (point) (point-beginning-of-line))) 1.257 + (delete-region (point) (point-beginning-of-line))) 1.258 (fill-region-as-paragraph 1.259 (progn (re-search-backward paragraph-start nil t) 1.260 (or (save-excursion 1.261 @@ -1414,7 +1488,9 @@ 1.262 (point))) 1.263 (progn (goto-char p) 1.264 (re-search-forward ps2 nil t) 1.265 - (match-beginning 0)))) 1.266 + (match-beginning 0) 1.267 + 1.268 + ))) 1.269 (fset 'move-to-column yahtml-saved-move-to-column))))) 1.270 1.271 ;(defun yahtml-indent-new-commnet-line () 1.272 @@ -1450,9 +1526,8 @@ 1.273 (and (bolp) (skip-chars-forward " \t"))) 1.274 (yahtml-indent-line-real)))) 1.275 1.276 -(defun yahtml-indent-line-real () 1.277 - (interactive) 1.278 - (let ((envs "[uod]l\\|table\\|[ht][rhd0-6]\\|select\\|blockquote\\|center\\|menu\\|dir") 1.279 +(defun yahtml-this-indent () 1.280 + (let ((envs "[uod]l\\|table\\|[ht][rhd0-6]\\|select\\|blockquote\\|center\\|menu\\|dir\\|font") 1.281 (itemizing-envs "^\\([uod]l\\|menu\\|dir\\)$") 1.282 (itms "<\\(dt\\|dd\\|li\\|t[rdh]\\|option\\)\\b") 1.283 inenv p col peol (case-fold-search t)) 1.284 @@ -1471,17 +1546,16 @@ 1.285 (skip-chars-forward " \t") 1.286 (cond ;lookup current line's tag 1.287 ((looking-at (concat "</\\(" envs "\\)>")) 1.288 - (YaTeX-reindent col)) 1.289 + col) 1.290 ((looking-at itms) 1.291 - (YaTeX-reindent (+ col yahtml-environment-indent))) 1.292 + (+ col yahtml-environment-indent)) 1.293 ((and yahtml-hate-too-deep-indentation 1.294 (looking-at (concat "<\\(" envs "\\)"))) 1.295 - (YaTeX-reindent (+ col (* 2 yahtml-environment-indent)))) 1.296 + (+ col (* 2 yahtml-environment-indent))) 1.297 ((and (< p (point)) 1.298 (string-match itemizing-envs inenv) 1.299 (save-excursion 1.300 (and 1.301 - ;;(re-search-backward itms p t) 1.302 (setq op (point)) 1.303 (goto-char p) 1.304 (re-search-forward itms op t) 1.305 @@ -1492,22 +1566,28 @@ 1.306 (setq col (if (looking-at "$") 1.307 (+ col yahtml-environment-indent) 1.308 (current-column))))))) 1.309 - (YaTeX-reindent col)) 1.310 + col) 1.311 (t 1.312 - (YaTeX-reindent (+ col yahtml-environment-indent))))))) 1.313 - (and (bolp) (skip-chars-forward " \t")) 1.314 - (if (and (setq inenv (yahtml-on-begend-p)) 1.315 - (string-match 1.316 - (concat "^\\<\\(" yahtml-struct-name-regexp "\\)") inenv)) 1.317 - (save-excursion 1.318 - (setq peol (point-end-of-line)) 1.319 - (or (= (char-after (point)) ?<) 1.320 - (progn (skip-chars-backward "^<") (forward-char -1))) 1.321 - (setq col (current-column)) 1.322 - (if (and (yahtml-goto-corresponding-begend t) 1.323 - (> (point) peol)) ;if on the different line 1.324 - (YaTeX-reindent col))))) 1.325 - (and (bolp) (skip-chars-forward " \t")))) 1.326 + (+ col yahtml-environment-indent))))) 1.327 + (t col))))) 1.328 + 1.329 +(defun yahtml-indent-line-real () 1.330 + "Indent current line." 1.331 + (interactive) 1.332 + (YaTeX-reindent (yahtml-this-indent)) 1.333 + (if (bolp) (skip-chars-forward " \t")) 1.334 + (let (peol col) 1.335 + (if (and (setq inenv (yahtml-on-begend-p)) 1.336 + (string-match 1.337 + (concat "^\\<\\(" yahtml-struct-name-regexp "\\)") inenv)) 1.338 + (save-excursion 1.339 + (setq peol (point-end-of-line)) 1.340 + (or (= (char-after (point)) ?<) 1.341 + (progn (skip-chars-backward "^<") (forward-char -1))) 1.342 + (setq col (current-column)) 1.343 + (if (and (yahtml-goto-corresponding-begend t) 1.344 + (> (point) peol)) ;if on the different line 1.345 + (YaTeX-reindent col)))))) 1.346 1.347 ;(defun yahtml-fill-item () 1.348 ; "Fill item HTML version" 1.349 @@ -1768,7 +1848,7 @@ 1.350 ;; include&exec 1.351 ("<!--#\\(include\\|exec\\)" "-->" include) 1.352 ;; string 1.353 - (hilit-string-find 39 string) 1.354 + (hilit-string-find ?\\ string) 1.355 (yahtml-hilit-region-tag "\\(em\\|strong\\)" bold) 1.356 ("</?[uod]l>" 0 decl) 1.357 ("<\\(di\\|dt\\|li\\|dd\\)>" 0 label) 1.358 @@ -1799,6 +1879,7 @@ 1.359 (cons (cons 'yahtml-mode yahtml-hilit-patterns-alist) 1.360 hilit-patterns-alist)))) 1.361 1.362 +(run-hooks 'yahtml-load-hook) 1.363 (provide 'yahtml) 1.364 1.365 ; Local variables: