yatex
diff yahtml.el @ 58:3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
author | yuuji |
---|---|
date | Thu, 01 Feb 1996 18:55:47 +0000 |
parents | 18f4939986e6 |
children | 48ac97a6b6ce |
line diff
1.1 --- a/yahtml.el Sat Dec 02 18:35:28 1995 +0000 1.2 +++ b/yahtml.el Thu Feb 01 18:55:47 1996 +0000 1.3 @@ -1,9 +1,24 @@ 1.4 ;;; -*- Emacs-Lisp -*- 1.5 -;;; (c ) 1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp, pcs39334@ascii-net.or.jp] 1.6 -;;; Last modified Mon Nov 20 11:26:38 1995 on inspire 1.7 -;;; This is PURELY tentative. 1.8 +;;; (c ) 1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp, pcs39334@asciinet.or.jp] 1.9 +;;; Last modified Fri Feb 2 02:37:23 1996 on supra 1.10 +;;; This package is no longer tentative. 1.11 ;;; $Id$ 1.12 1.13 +;;;[Installation] 1.14 +;;; 1.15 +;;; First, you have to install YaTeX and make sure it works fine. Then 1.16 +;;; put these expressions into your ~/.emacs 1.17 +;;; 1.18 +;;; (setq auto-mode-alist 1.19 +;;; (cons (cons "\\.html$" 'yahtml-mode) auto-mode-alist)) 1.20 +;;; (autoload 'yahtml-mode "yahtml" "Yet Another HTML mode" t) 1.21 +;;; (setq yahtml-www-browser "netscape") 1.22 +;;; ;Write your favorite browser. But netscape is advantageous. 1.23 +;;; (setq yahtml-path-url-alist 1.24 +;;; '(("/home/yuuji/public_html" . "http://www.mynet/~yuuji") 1.25 +;;; ("/home/staff/yuuji/html" . "http://www.othernet/~yuuji"))) 1.26 +;;; ;Write correspondence alist from ABSOLUTE unix path name to URL path. 1.27 +;;; 1.28 ;;;[Commentary] 1.29 ;;; 1.30 ;;; It is assumed you are already familiar with YaTeX. The following 1.31 @@ -19,10 +34,19 @@ 1.32 ;;; * [prefix] l Complete typeface-changing commands such as 1.33 ;;; `<i> ... </i>' or `<samp> ... </samp>' 1.34 ;;; * [prefix] m Complete single commands such as 1.35 -;;; `<br>' or `<hr>' 1.36 +;;; `<br>' or `<hr> or <li>...' 1.37 ;;; * menu-bar yahtml Complete all by selecting a menu item (Though I 1.38 ;;; hate menu, this is most useful) 1.39 -;;; 1.40 +;;; * [prefix] g Goto corresponding Tag or HREF such as 1.41 +;;; <dl> <-> </dl> or href="xxx" 1.42 +;;; * [prefix] k Kill html tags on the point. If you provide 1.43 +;;; universal-argument, kill surrounded contents too. 1.44 +;;; * [prefix] c Change html tags on the point. 1.45 +;;; * [prefix] t b View current html with WWW browser 1.46 +;;; (To activate this, never fail to set the lisp 1.47 +;;; variable yahtml-www-browser. Recommended value 1.48 +;;; is "netscape") 1.49 +;;; 1.50 ;;; NOTE! This program is truly tentative. If you find some bright 1.51 ;;; future with this, please send me a mail to drive me to maintain this :) 1.52 1.53 @@ -30,6 +54,20 @@ 1.54 (require 'yatex) 1.55 (defvar yahtml-prefix-map nil) 1.56 (defvar yahtml-mode-map nil "Keymap used in yahtml-mode.") 1.57 +(defvar yahtml-image-viewer "xv" "*Image viewer program") 1.58 +(defvar yahtml-www-browser "netscape" 1.59 + "*WWW Browser command") 1.60 +(defvar yahtml-kanji-code 2 1.61 + "Kanji coding system of html file; 1=sjis, 2=jis, 3=euc") 1.62 +;;(defvar yahtml-www-server "www" "*Host name of your domain's WWW server") 1.63 +(defvar yahtml-path-url-alist nil 1.64 + "*Alist of unix path name vs. URL name of WWW server. 1.65 +Ex. 1.66 +'((\"/usr/home/yuuji/http\" . \"http://www.comp.ae.keio.ac.jp/~yuuji\") 1.67 + (\"/usr/home/yuuji/darts/http\" . \"http://inspire.comp.ae.keio.ac.jp/~darts\"))") 1.68 +(defvar yahtml-directory-index "index.html" 1.69 + "*Directory index file name; 1.70 +Consult your site's WWW administrator.") 1.71 1.72 (defun yahtml-define-begend-key-normal (key env &optional map) 1.73 "Define short cut yahtml-insert-begin-end key." 1.74 @@ -57,10 +95,13 @@ 1.75 (setq yahtml-mode-map (make-sparse-keymap) 1.76 yahtml-prefix-map (make-sparse-keymap)) 1.77 (define-key yahtml-mode-map YaTeX-prefix yahtml-prefix-map) 1.78 - (define-key yahtml-mode-map "\M-\C-@" 'YaTeX-mark-environment) 1.79 + (define-key yahtml-mode-map "\M-\C-@" 'yahtml-mark-begend) 1.80 + (if (and (boundp 'window-system) (eq window-system 'x) YaTeX-emacs-19) 1.81 + (define-key yahtml-mode-map [?\M-\C- ] 'yahtml-mark-begend)) 1.82 (define-key yahtml-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment) 1.83 (define-key yahtml-mode-map "\M-\C-e" 'YaTeX-end-of-environment) 1.84 - (define-key yahtml-mode-map "\C-i" 'YaTeX-indent-line) 1.85 + (define-key yahtml-mode-map "\M-\C-m" 'yahtml-intelligent-newline) 1.86 + (define-key yahtml-mode-map "\C-i" 'yahtml-indent-line) 1.87 (define-key yahtml-mode-map YaTeX-prefix yahtml-prefix-map) 1.88 (let ((map yahtml-prefix-map)) 1.89 (YaTeX-define-key "^" 'yahtml-visit-main map) 1.90 @@ -96,18 +137,22 @@ 1.91 (yahtml-define-begend-key "bf" "form" map) 1.92 (yahtml-define-begend-key "bs" "select" map) 1.93 (YaTeX-define-key "b " 'yahtml-insert-begend map) 1.94 - (YaTeX-define-key "B " 'yahtml-insert-begend map) 1.95 + (YaTeX-define-key "B " 'yahtml-insert-begend-region map) 1.96 ) 1.97 - (YaTeX-define-key "e" 'yahtml-end-environment map) 1.98 + (YaTeX-define-key "e" 'YaTeX-end-environment map) 1.99 (YaTeX-define-key ">" 'yahtml-comment-region map) 1.100 (YaTeX-define-key "<" 'yahtml-uncomment-region map) 1.101 (YaTeX-define-key "g" 'yahtml-goto-corresponding-* map) 1.102 + (YaTeX-define-key "k" 'yahtml-kill-* map) 1.103 + (YaTeX-define-key "c" 'yahtml-change-* map) 1.104 + (YaTeX-define-key "t" 'yahtml-browse-menu map) 1.105 + ;;;;;(YaTeX-define-key "i" 'yahtml-fill-item map) 1.106 ) 1.107 ) 1.108 1.109 (defvar yahtml-paragraph-separate 1.110 (concat 1.111 - "^$\\|<br>\\|<p>\\|^[ \t]*</?\\(h[1-6]\\|p\\|dl\\|dd\\|dt\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\)>") 1.112 + "^$\\|<[bh]r>\\|<p>\\|^[ \t]*</?\\(h[1-6]\\|p\\|dl\\|dd\\|dt\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\)>") 1.113 "*Regexp of html paragraph separater") 1.114 (defvar yahtml-syntax-table nil 1.115 "*Syntax table for typesetting buffer") 1.116 @@ -120,8 +165,6 @@ 1.117 ) 1.118 (defvar yahtml-command-regexp "[A-Za-z0-9]+" 1.119 "Regexp of constituent of html commands.") 1.120 -(defvar yahtml-kanji-code 2 1.121 - "Kanji coding system of html file; 1=sjis, 2=jis, 3=euc") 1.122 1.123 ;;; Completion tables for `form' 1.124 (defvar yahtml-form-table 1.125 @@ -131,8 +174,15 @@ 1.126 1.127 (defvar yahtml-env-table 1.128 '(("html") ("head") ("title") ("body") ("dl") ("a") ("form") ("select") 1.129 + ("OrderedList" . "ol") 1.130 + ("UnorderedList" . "ul") 1.131 + ("DefinitionList" . "dl") 1.132 ("h1") ("h2") ("h3") ("h4") ("h5") ("h6") ("ul"))) 1.133 1.134 +(defvar yahtml-itemizing-regexp 1.135 + "\\(ul\\|ul\\|dl\\)" 1.136 + "Regexp of itemizing forms") 1.137 + 1.138 (defvar yahtml-user-env-table nil) 1.139 (defvar yahtml-tmp-env-table nil) 1.140 1.141 @@ -143,9 +193,18 @@ 1.142 "Default completion table of typeface designator") 1.143 (defvar yahtml-user-typeface-table nil) 1.144 (defvar yahtml-tmp-typeface-table nil) 1.145 +(defvar yahtml-last-typeface-cmd "address") 1.146 1.147 (defvar yahtml-single-cmd-table 1.148 - '(("hr") ("br") ("option") ("p")) 1.149 + '(("hr") ("br") ("option") ("p") 1.150 + ("HorizontalLine" . "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 + ) 1.158 "Default completion table of HTML single command.") 1.159 (defvar yahtml-user-single-cmd-table nil) 1.160 (defvar yahtml-tmp-single-cmd-table nil) 1.161 @@ -165,7 +224,7 @@ 1.162 yahtml-typeface-table)))) 1.163 1.164 (defvar yahtml-struct-name-regexp 1.165 - "\\<\\(h[1-6]\\|[uod]l\\|body\\|title\\|head\\)") 1.166 + "\\<\\(h[1-6]\\|[uod]l\\|body\\|title\\|head\\|table\\|t[rhd]\\)") 1.167 1.168 1.169 (defun yahtml-mode () 1.170 @@ -188,8 +247,8 @@ 1.171 (make-local-variable 'YaTeX-prefix-map) 1.172 (make-local-variable 'YaTeX-command-token-regexp) 1.173 (setq YaTeX-command-token-regexp yahtml-command-regexp) 1.174 - (make-local-variable 'YaTeX-environment-indent) 1.175 - (setq YaTeX-environment-indent 0) 1.176 + ;;(make-local-variable 'YaTeX-environment-indent) 1.177 + ;;(setq YaTeX-environment-indent 0) 1.178 (make-local-variable 'fill-prefix) 1.179 (setq fill-prefix nil) 1.180 (make-local-variable 'paragraph-separate) 1.181 @@ -198,6 +257,10 @@ 1.182 (make-local-variable 'comment-start) 1.183 (make-local-variable 'comment-end) 1.184 (setq comment-start "<!-- " comment-end " -->") 1.185 + (make-local-variable 'indent-line-function) 1.186 + (setq indent-line-function 'yahtml-indent-line) 1.187 + (make-local-variable 'YaTeX-item-regexp) 1.188 + (setq YaTeX-item-regexp "<\\(li\\|d[td]\\)>") 1.189 (set-syntax-table yahtml-syntax-table) 1.190 (use-local-map yahtml-mode-map) 1.191 (run-hooks 'yahtml-mode-hook)) 1.192 @@ -227,57 +290,57 @@ 1.193 (yahtml-define-menu 1.194 yahtml-menu-map-sectioning 1.195 (nreverse 1.196 - '((1 "H1" . (lambda () (interactive) (yahtml-insert-begin-end "H1" nil))) 1.197 - (2 "H2" . (lambda () (interactive) (yahtml-insert-begin-end "H2" nil))) 1.198 - (3 "H3" . (lambda () (interactive) (yahtml-insert-begin-end "H3" nil))) 1.199 - (4 "H4" . (lambda () (interactive) (yahtml-insert-begin-end "H4" nil))) 1.200 - (5 "H5" . (lambda () (interactive) (yahtml-insert-begin-end "H5" nil))) 1.201 - (6 "H6" . (lambda () (interactive) (yahtml-insert-begin-end "H6" nil))) 1.202 + '((1 "H1" . (lambda () (interactive) (yahtml-insert-begend nil "H1"))) 1.203 + (2 "H2" . (lambda () (interactive) (yahtml-insert-begend nil "H2"))) 1.204 + (3 "H3" . (lambda () (interactive) (yahtml-insert-begend nil "H3"))) 1.205 + (4 "H4" . (lambda () (interactive) (yahtml-insert-begend nil "H4"))) 1.206 + (5 "H5" . (lambda () (interactive) (yahtml-insert-begend nil "H5"))) 1.207 + (6 "H6" . (lambda () (interactive) (yahtml-insert-begend nil "H6"))) 1.208 ))) 1.209 (setq yahtml-menu-map-logical (make-sparse-keymap "logical tags")) 1.210 (yahtml-define-menu 1.211 yahtml-menu-map-logical 1.212 (nreverse 1.213 '((em "Embolden" . 1.214 - (lambda () (interactive) (yahtml-insert-tag "EM"))) 1.215 + (lambda () (interactive) (yahtml-insert-tag nil "EM"))) 1.216 (defn "Define a word" . 1.217 - (lambda () (interactive) (yahtml-insert-tag "DEFN"))) 1.218 + (lambda () (interactive) (yahtml-insert-tag nil "DEFN"))) 1.219 (cite "Citation" . 1.220 - (lambda () (interactive) (yahtml-insert-tag "CITE"))) 1.221 + (lambda () (interactive) (yahtml-insert-tag nil "CITE"))) 1.222 (code "Code" . 1.223 - (lambda () (interactive) (yahtml-insert-tag "CODE"))) 1.224 + (lambda () (interactive) (yahtml-insert-tag nil "CODE"))) 1.225 (kbd "Keyboard" . 1.226 - (lambda () (interactive) (yahtml-insert-tag "KBD"))) 1.227 + (lambda () (interactive) (yahtml-insert-tag nil "KBD"))) 1.228 (samp "Sample display" . 1.229 - (lambda () (interactive) (yahtml-insert-tag "SAMP"))) 1.230 + (lambda () (interactive) (yahtml-insert-tag nil "SAMP"))) 1.231 (strong "Strong" . 1.232 - (lambda () (interactive) (yahtml-insert-tag "STRONG"))) 1.233 + (lambda () (interactive) (yahtml-insert-tag nil "STRONG"))) 1.234 (VAR "Variable notation" . 1.235 - (lambda () (interactive) (yahtml-insert-tag "VAR"))) 1.236 + (lambda () (interactive) (yahtml-insert-tag nil "VAR"))) 1.237 ))) 1.238 (setq yahtml-menu-map-typeface (make-sparse-keymap "typeface tags")) 1.239 (yahtml-define-menu 1.240 yahtml-menu-map-typeface 1.241 (nreverse 1.242 '((b "Bold" . 1.243 - (lambda () (interactive) (yahtml-insert-tag "B"))) 1.244 + (lambda () (interactive) (yahtml-insert-tag nil "B"))) 1.245 (i "Italic" . 1.246 - (lambda () (interactive) (yahtml-insert-tag "I"))) 1.247 + (lambda () (interactive) (yahtml-insert-tag nil "I"))) 1.248 (tt "Typewriter" . 1.249 - (lambda () (interactive) (yahtml-insert-tag "TT"))) 1.250 + (lambda () (interactive) (yahtml-insert-tag nil "TT"))) 1.251 (u "Underlined" . 1.252 - (lambda () (interactive) (yahtml-insert-tag "U"))) 1.253 + (lambda () (interactive) (yahtml-insert-tag nil "U"))) 1.254 ))) 1.255 (setq yahtml-menu-map-listing (make-sparse-keymap "listing")) 1.256 (yahtml-define-menu 1.257 yahtml-menu-map-listing 1.258 (nreverse 1.259 - '((ul "Unnumbered" . 1.260 - (lambda () (interactive) (yahtml-insert-begin-end "UL" nil))) 1.261 - (ol "Numbered" . 1.262 - (lambda () (interactive) (yahtml-insert-begin-end "OL" nil))) 1.263 - (dl "Description" . 1.264 - (lambda () (interactive) (yahtml-insert-begin-end "DL" nil))) 1.265 + '((ul "Unordered" . 1.266 + (lambda () (interactive) (yahtml-insert-begend nil "UL"))) 1.267 + (ol "Ordered" . 1.268 + (lambda () (interactive) (yahtml-insert-begend nil "OL"))) 1.269 + (dl "Definition" . 1.270 + (lambda () (interactive) (yahtml-insert-begend nil "DL"))) 1.271 ))) 1.272 (setq yahtml-menu-map-item (make-sparse-keymap "item")) 1.273 (yahtml-define-menu 1.274 @@ -292,6 +355,10 @@ 1.275 ))) 1.276 (define-key yahtml-mode-map [menu-bar yahtml] 1.277 (cons "yahtml" yahtml-menu-map)) 1.278 + (let ((keys (where-is-internal 'fill-paragraph global-map))) 1.279 + (while keys 1.280 + (define-key yahtml-mode-map (car keys) 'yahtml-fill-paragraph) 1.281 + (setq keys (cdr keys)))) 1.282 (yahtml-define-menu 1.283 yahtml-menu-map 1.284 (nreverse 1.285 @@ -329,14 +396,22 @@ 1.286 1.287 ;;; ----------- Completion ---------- 1.288 (defvar yahtml-last-begend "html") 1.289 -(defun yahtml-insert-begend (&optional region) 1.290 +(defun yahtml-insert-begend (&optional region env) 1.291 "Insert <cmd> ... </cmd>." 1.292 (interactive "P") 1.293 - (let ((cmd (YaTeX-cplread-with-learning 1.294 + (let*((completion-ignore-case t) 1.295 + (cmd 1.296 + (or env 1.297 + (YaTeX-cplread-with-learning 1.298 (format "Environment(default %s): " yahtml-last-begend) 1.299 - 'yahtml-env-table 'yahtml-user-env-table 'yahtml-tmp-env-table)) 1.300 - (bolp (bolp))) 1.301 + 'yahtml-env-table 'yahtml-user-env-table 'yahtml-tmp-env-table))) 1.302 + (bolp (save-excursion 1.303 + (skip-chars-backward " \t" (point-beginning-of-line)) (bolp))) 1.304 + (cc (current-column))) 1.305 (if (string< "" cmd) (setq yahtml-last-begend cmd)) 1.306 + (setq yahtml-last-begend 1.307 + (or (cdr (assoc yahtml-last-begend yahtml-env-table)) 1.308 + yahtml-last-begend)) 1.309 (setq cmd yahtml-last-begend) 1.310 (if region 1.311 (let ((beg (region-beginning)) 1.312 @@ -346,11 +421,14 @@ 1.313 (insert (format "</%s>%s" cmd (if bolp "\n" ""))) 1.314 (goto-char beg) 1.315 (insert (format "<%s%s>%s" cmd addin (if bolp "\n" "")))) 1.316 - (insert (format "<%s%s" cmd (yahtml-addin cmd))) 1.317 - (if bolp (progn (insert (format ">\n</%s>\n" cmd cmd)) 1.318 - (forward-line -1)) 1.319 - (insert ">") 1.320 - (save-excursion (insert (format "</%s>" cmd))))))) 1.321 + (insert (format "<%s%s>" cmd (yahtml-addin cmd))) 1.322 + (save-excursion 1.323 + (if bolp (progn 1.324 + (insert "\n") 1.325 + (indent-to-column cc) 1.326 + (insert (format "</%s>" cmd))) 1.327 + (insert (format "</%s>" cmd)))) 1.328 + (if bolp (yahtml-intelligent-newline nil))))) 1.329 1.330 (defun yahtml-insert-begend-region () 1.331 "Call yahtml-insert-begend in the region mode." 1.332 @@ -368,7 +446,7 @@ 1.333 'yahtml-form-table 'yahtml-user-form-table 1.334 'yahtml-tmp-form-table))) 1.335 (let ((p (point)) q) 1.336 - (insert (format "<%s%s>" form (yahtml-addin (downcase form)))) 1.337 + (insert (format "<%s%s>" form (yahtml-addin form))) 1.338 ;;(indent-relative-maybe) 1.339 (if (cdr (assoc form yahtml-form-table)) 1.340 (save-excursion (insert (format "</%s>" form)))) 1.341 @@ -376,24 +454,81 @@ 1.342 1.343 (defun yahtml-addin (form) 1.344 "Check add-in function's existence and call it if exists." 1.345 - (let ((addin (concat "yahtml:" form))) 1.346 - (if (and (intern-soft addin) (fboundp (intern-soft addin))) 1.347 - (concat " " (funcall (intern addin))) 1.348 + (let ((addin (concat "yahtml:" (downcase form))) s) 1.349 + (if (and (intern-soft addin) (fboundp (intern-soft addin)) 1.350 + (stringp (setq s (funcall (intern addin)))) 1.351 + (string< "" s)) 1.352 + (concat " " s) 1.353 ""))) 1.354 1.355 +(defvar yahtml-url-completion-map nil "Key map used in URL completion buffer") 1.356 +(if yahtml-url-completion-map nil 1.357 + (setq yahtml-url-completion-map 1.358 + (copy-keymap minibuffer-local-completion-map)) 1.359 + (define-key yahtml-url-completion-map "\t" 'yahtml-complete-url) 1.360 + (define-key yahtml-url-completion-map " " 'yahtml-complete-url) 1.361 +) 1.362 + 1.363 +(defun yahtml-complete-url () 1.364 + "Complete external URL from history or local file name." 1.365 + (interactive) 1.366 + (let (initial cmpl path dir file listfunc beg (p (point))) 1.367 + (setq initial (buffer-string)) 1.368 + (cond 1.369 + ((string-match "^http:" initial) 1.370 + (setq cmpl (try-completion initial yahtml-urls) 1.371 + listfunc (list 'lambda nil 1.372 + (list 'all-completions initial 'yahtml-urls)) 1.373 + beg (point-min))) 1.374 + (t 1.375 + (setq path (if (string-match "^/" initial) 1.376 + (yahtml-url-to-path initial) 1.377 + initial)) 1.378 + (setq dir (or (file-name-directory path) ".") 1.379 + file (file-name-nondirectory path) 1.380 + initial file 1.381 + cmpl (file-name-completion file dir) 1.382 + listfunc (list 'lambda nil 1.383 + (list 'file-name-all-completions 1.384 + file dir)) 1.385 + beg (save-excursion (skip-chars-backward "^/") (point))))) 1.386 + (cond 1.387 + ((stringp cmpl) 1.388 + (if (string= initial cmpl) 1.389 + (with-output-to-temp-buffer "*Completions*" 1.390 + (princ "Possible completinos are:\n") 1.391 + (princ 1.392 + (mapconcat '(lambda (x) x) (funcall listfunc) "\n"))) 1.393 + (delete-region (point) beg) 1.394 + (insert cmpl))) 1.395 + ((null cmpl) 1.396 + (ding)) 1.397 + ((eq t cmpl) 1.398 + (save-excursion 1.399 + (unwind-protect 1.400 + (progn 1.401 + (goto-char p) 1.402 + (insert " [Sole completion]")) 1.403 + (delete-region p (point-max)))))))) 1.404 + 1.405 (defun yahtml:a () 1.406 "Add-in function for <a>" 1.407 -; (or yahtml-urls (yahtml-collect-url-history)) 1.408 + (or yahtml-urls (yahtml-collect-url-history)) 1.409 ; (concat "href=\"" 1.410 ; (completing-read "href: " yahtml-urls) 1.411 ; "\"") 1.412 - (concat "href=\"" (read-file-name "href: " "" nil nil "") "\"") 1.413 -) 1.414 + (message "(H)ref (N)ame?") 1.415 + (cond 1.416 + ((string-match "[hH]" (char-to-string (read-char))) 1.417 + (concat "href=\"" 1.418 + (read-from-minibuffer "href: " "" yahtml-url-completion-map) 1.419 + "\"")) 1.420 + (t (concat "name=\"" (read-string "name: ") "\"")))) 1.421 1.422 (defun yahtml:img () 1.423 "Add-in function for <img>" 1.424 (or yahtml-urls (yahtml-collect-url-history)) 1.425 - (let ((src (read-file-name "src: " "" nil t "")) 1.426 + (let ((src (read-file-name "src: " "" nil nil "")) 1.427 (alg (completing-read "align: " '(("top") ("middle") ("bottom"))))) 1.428 (concat "src=\"" src "\"" 1.429 (if (string< "" alg) (concat " align=\"" alg "\""))))) 1.430 @@ -410,6 +545,16 @@ 1.431 (setq yahtml-last-single-cmd "option") 1.432 (concat " name=\"" (read-string "name: ") "\"")) 1.433 1.434 +(defun yahtml:ol () 1.435 + (setq yahtml-last-single-cmd "li") "") 1.436 +(defun yahtml:ul () 1.437 + (setq yahtml-last-single-cmd "li") "") 1.438 +(defun yahtml:dl () 1.439 + (setq yahtml-last-single-cmd "dt") "") 1.440 +(defun yahtml:dt () 1.441 + (setq yahtml-last-single-cmd "dd") "") 1.442 + 1.443 + 1.444 (defvar yahtml-input-types 1.445 '(("text") ("password") ("checkbox") ("radio") ("submit") 1.446 ("reset") ("image") ("hidden"))) 1.447 @@ -432,36 +577,46 @@ 1.448 (if (string< "" maxlength) (concat " maxlength=\"" maxlength "\"")) 1.449 ))) 1.450 1.451 - 1.452 -(defun yahtml-insert-begin-end (env &optional region-mode) 1.453 - "Insert <ENV> \\n </ENV> by calling YaTeX-insert-begin-end." 1.454 - (interactive "sEnv: ") 1.455 - (setq env (funcall (if yahtml-prefer-upcases 'upcase 'downcase) env)) 1.456 - (YaTeX-insert-begin-end env region-mode)) 1.457 - 1.458 -(defun yahtml-insert-tag (tag) 1.459 +(defun yahtml-insert-tag (region-mode &optional tag) 1.460 "Insert <TAG> </TAG> and put cursor inside of them." 1.461 - (interactive 1.462 - (list 1.463 - (YaTeX-cplread-with-learning 1.464 - "Tag: " 1.465 - 'yahtml-typeface-table 'yahtml-user-typeface-table 1.466 - 'yahtml-tmp-typeface-table))) 1.467 - (setq tag (funcall (if yahtml-prefer-upcases 'upcase 'downcase) tag)) 1.468 - (insert (format "<%s> " tag)) 1.469 - (save-excursion (insert (format "</%s>" tag)))) 1.470 + (interactive "P") 1.471 + (or tag 1.472 + (setq tag 1.473 + (YaTeX-cplread-with-learning 1.474 + (format "Tag %s(default %s): " 1.475 + (if region-mode "region: " "") yahtml-last-typeface-cmd) 1.476 + 'yahtml-typeface-table 'yahtml-user-typeface-table 1.477 + 'yahtml-tmp-typeface-table))) 1.478 + (if (string= "" tag) (setq tag yahtml-last-typeface-cmd)) 1.479 + (setq tag (funcall (if yahtml-prefer-upcases 'upcase 'downcase) tag) 1.480 + yahtml-last-typeface-cmd tag) 1.481 + (if region-mode 1.482 + (if (if (string< "19" emacs-version) (mark t) (mark)) 1.483 + (save-excursion 1.484 + (if (> (point) (mark)) (exchange-point-and-mark)) 1.485 + (insert "<" tag ">") 1.486 + (exchange-point-and-mark) 1.487 + (insert "</" tag ">")) 1.488 + (message "No mark set now")) 1.489 + (insert (format "<%s> " tag)) 1.490 + (save-excursion (insert (format "</%s>" tag))))) 1.491 1.492 (defun yahtml-insert-single (cmd) 1.493 "Insert <CMD>." 1.494 (interactive 1.495 - (list (YaTeX-cplread-with-learning 1.496 - (format "Command%s: " 1.497 - (if yahtml-last-single-cmd 1.498 - (concat "(default " yahtml-last-single-cmd ")") "")) 1.499 - 'yahtml-single-cmd-table 'yahtml-user-single-cmd-table 1.500 - 'yahtml-tmp-single-cmd-table))) 1.501 + (list 1.502 + (let ((completion-ignore-case t)) 1.503 + (YaTeX-cplread-with-learning 1.504 + (format "Command%s: " 1.505 + (if yahtml-last-single-cmd 1.506 + (concat "(default " yahtml-last-single-cmd ")") "")) 1.507 + 'yahtml-single-cmd-table 'yahtml-user-single-cmd-table 1.508 + 'yahtml-tmp-single-cmd-table)))) 1.509 + (if (string< "" cmd) (setq yahtml-last-single-cmd cmd)) 1.510 (setq cmd (funcall (if yahtml-prefer-upcases 'upcase 'downcase) cmd)) 1.511 - (if (string< "" cmd) (setq yahtml-last-single-cmd cmd)) 1.512 + (setq yahtml-last-single-cmd 1.513 + (or (cdr (assoc yahtml-last-single-cmd yahtml-single-cmd-table)) 1.514 + yahtml-last-single-cmd)) 1.515 (insert (format "<%s>" yahtml-last-single-cmd))) 1.516 1.517 ;;; ---------- Jump ---------- 1.518 @@ -469,25 +624,73 @@ 1.519 "Check if point is on href clause." 1.520 (let ((p (point)) cmd) 1.521 (save-excursion 1.522 - (or (bobp) (skip-chars-backward "^ \t")) 1.523 - (and (looking-at "href\\s *=\\s *\"?\\([^\"]+\\)\"?") 1.524 + (or (bobp) (skip-chars-backward "^ \t\n")) 1.525 + (and (looking-at "href\\s *=\\s *\"?\\([^\"> \t\n]+\\)\"?") 1.526 (< p (match-end 0)) 1.527 (YaTeX-match-string 1))))) 1.528 1.529 +(defun yahtml-netscape-sentinel (proc mes) 1.530 + (cond 1.531 + ((null (buffer-name (process-buffer proc))) 1.532 + (set-process-buffer proc nil)) 1.533 + ((eq (process-status proc) 'exit) 1.534 + (let ((cb (current-buffer))) 1.535 + (set-buffer (process-buffer proc)) 1.536 + (goto-char (point-min)) 1.537 + (if (search-forward "not running" nil t) 1.538 + (progn 1.539 + (message "Starting netscape...") 1.540 + (start-process 1.541 + "browser" (process-buffer proc) shell-file-name "-c" 1.542 + (format "%s %s" yahtml-www-browser 1.543 + (get 'yahtml-netscape-sentinel 'url))) 1.544 + (message "Starting netscape...Done"))) 1.545 + (set-buffer cb))))) 1.546 + 1.547 +(defvar yahtml-browser-process nil) 1.548 + 1.549 +(defun yahtml-browse-html (href) 1.550 + "Call WWW Browser to see HREF." 1.551 + (let ((pb "* WWW Browser *") (cb (current-buffer))) 1.552 + (cond 1.553 + ((string-match "[Nn]etscape" yahtml-www-browser) 1.554 + (if (get-buffer pb) 1.555 + (progn (set-buffer pb) (erase-buffer) (set-buffer cb))) 1.556 + (put 'yahtml-netscape-sentinel 'url href) 1.557 + (set-process-sentinel 1.558 + (setq yahtml-browser-process 1.559 + (start-process 1.560 + "browser" pb shell-file-name "-c" 1.561 + (format "%s -remote 'openURL(%s)'" yahtml-www-browser href))) 1.562 + 'yahtml-netscape-sentinel)) 1.563 + ((and (string= "w3" yahtml-www-browser) (fboundp 'w3-fetch)) 1.564 + (w3-fetch href)) 1.565 + ((stringp yahtml-www-browser) 1.566 + (if (eq (process-status yahtml-browser-process) 'run) 1.567 + (message "%s is already running" yahtml-www-browser) 1.568 + (setq yahtml-browser-process 1.569 + (start-process 1.570 + "browser" "* WWW Browser *" shell-file-name 1.571 + (format "%s %s" yahtml-www-browser href))))) 1.572 + (t 1.573 + (message "Sorry, jump across http is not supported."))))) 1.574 + 1.575 (defun yahtml-goto-corresponding-href (&optional other) 1.576 "Go to corresponding name." 1.577 (let ((href (yahtml-on-href-p)) file name) 1.578 (if href 1.579 (cond 1.580 ((string-match "^http:" href) 1.581 - (message "Sorry, jump across http is not supported.")) 1.582 + (yahtml-browse-html href)) 1.583 (t (setq file (substring href 0 (string-match "#" href))) 1.584 (if (string-match "#" href) 1.585 (setq name (substring href (1+ (string-match "#" href))))) 1.586 (if (string< "" file) 1.587 (progn 1.588 (if (string-match "/$" file) 1.589 - (setq file (concat file "index.html"))) 1.590 + (setq file (concat file yahtml-directory-index))) 1.591 + (if (string-match "^/" file) 1.592 + (setq file (yahtml-url-to-path file))) 1.593 (if other (YaTeX-switch-to-buffer-other-window file) 1.594 (YaTeX-switch-to-buffer file)))) 1.595 (if name 1.596 @@ -503,33 +706,87 @@ 1.597 1.598 (defun yahtml-on-begend-p (&optional p) 1.599 "Check if point is on begend clause." 1.600 - (let ((p (point)) cmd) 1.601 + (let ((p (point)) cmd (case-fold-search t)) 1.602 (save-excursion 1.603 (if p (goto-char p)) 1.604 - (if (= (char-after (point)) ?<) (forward-char 1)) 1.605 + (if (equal (char-after (point)) ?<) (forward-char 1)) 1.606 (if (and (re-search-backward "<" nil t) 1.607 (looking-at 1.608 (concat "<\\(/?" yahtml-command-regexp "\\)\\b")) 1.609 (condition-case nil 1.610 - (forward-list 1)) 1.611 + (forward-list 1) 1.612 + (error nil)) 1.613 (< p (point))) 1.614 (YaTeX-match-string 1))))) 1.615 1.616 -(defun yahtml-goto-corresponding-begend () 1.617 - (let ((cmd (yahtml-on-begend-p))) 1.618 - (if cmd 1.619 - (progn 1.620 - (if (= (aref cmd 0) ?/) ;on </cmd> line 1.621 - (re-search-backward (format "<%s" (substring cmd 1))) 1.622 - (re-search-forward (format "</%s" cmd))) 1.623 - (if (match-beginning 0) (goto-char (match-beginning 0))))))) 1.624 +(defun yahtml-goto-corresponding-begend (&optional noerr) 1.625 + "Go to corresponding opening/closing tag. 1.626 +Optional argument NOERR causes no error for unballanced tag." 1.627 + (let ((cmd (yahtml-on-begend-p)) m0 1.628 + (p (point)) (case-fold-search t) func str (nest 0)) 1.629 + (cond 1.630 + (cmd 1.631 + (setq m0 (match-beginning 0)) 1.632 + (if (= (aref cmd 0) ?/) ;on </cmd> line 1.633 + (setq cmd (substring cmd 1) 1.634 + str (format "\\(<%s\\)\\|\\(</%s\\)" cmd cmd) 1.635 + func 're-search-backward) 1.636 + (setq str (format "\\(</%s\\)\\|\\(<%s\\)" cmd cmd) 1.637 + func 're-search-forward)) 1.638 + (while (and (>= nest 0) (funcall func str nil t)) 1.639 + (if (equal m0 (match-beginning 0)) 1.640 + nil 1.641 + (setq nest (+ nest (if (match-beginning 1) -1 1))))) 1.642 + (if (< nest 0) 1.643 + (goto-char (match-beginning 0)) 1.644 + (funcall 1.645 + (if noerr 'message 'error) 1.646 + "Corresponding tag of `%s' not found." cmd) 1.647 + (goto-char p) 1.648 + nil)) 1.649 + (t nil)))) 1.650 + 1.651 +(defun yahtml-current-tag () 1.652 + "Return the current tag name." 1.653 + (save-excursion 1.654 + (let ((p (point)) b tag) 1.655 + (or (bobp) 1.656 + (looking-at "<") 1.657 + (progn (skip-chars-backward "^<") (forward-char -1))) 1.658 + (setq b (point)) 1.659 + (skip-chars-forward "<") 1.660 + (setq tag (buffer-substring 1.661 + (point) (progn (skip-chars-forward "^ \t\n") (point)))) 1.662 + (goto-char b) 1.663 + (forward-list 1) 1.664 + (and (< p (point)) tag)))) 1.665 + 1.666 + 1.667 +(defun yahtml-goto-corresponding-img () 1.668 + "View image on point" 1.669 + (let ((tag (yahtml-current-tag)) image (p (point)) (case-fold-search t)) 1.670 + (if (and tag 1.671 + (string-match "img" tag) 1.672 + (save-excursion 1.673 + (re-search-backward "<\\s *img" nil t) 1.674 + (re-search-forward "src=\"?\\([^\"> ]+\\)\"?>") 1.675 + (match-beginning 1) 1.676 + (setq image 1.677 + (buffer-substring (match-beginning 1) (match-end 1))))) 1.678 + (progn 1.679 + (message "Invoking %s %s..." yahtml-image-viewer image) 1.680 + (start-process 1.681 + "Viewer" " * Image Viewer *" shell-file-name "-c" 1.682 + (concat yahtml-image-viewer " " image)) 1.683 + (message "Invoking %s %s...Done" yahtml-image-viewer image))))) 1.684 1.685 (defun yahtml-goto-corresponding-* (&optional other) 1.686 "Go to corresponding object." 1.687 (interactive) 1.688 (cond 1.689 ((yahtml-goto-corresponding-href other)) 1.690 - ((yahtml-goto-corresponding-begend other)) 1.691 + ((yahtml-goto-corresponding-img)) 1.692 + ((yahtml-goto-corresponding-begend)) 1.693 )) 1.694 1.695 (defun yahtml-goto-corresponding-*-other-window () 1.696 @@ -537,6 +794,82 @@ 1.697 (interactive) 1.698 (yahtml-goto-corresponding-* t)) 1.699 1.700 +;;; ---------- killing ---------- 1.701 +(defun yahtml-kill-begend (&optional whole) 1.702 + (let ((tag (yahtml-on-begend-p)) (p (make-marker)) (q (make-marker))) 1.703 + (if tag 1.704 + (progn 1.705 + (or (looking-at "<") 1.706 + (progn (skip-chars-backward "^<") (forward-char -1))) 1.707 + (set-marker p (point)) 1.708 + (yahtml-goto-corresponding-begend) 1.709 + (or (looking-at "<") 1.710 + (progn (skip-chars-backward "^<") (forward-char -1))) 1.711 + (delete-region (point) (progn (forward-list 1) (point))) 1.712 + (set-marker q (point)) 1.713 + (beginning-of-line) 1.714 + (if (looking-at "^\\s *$") 1.715 + (delete-region (point) (progn (forward-line 1) (point)))) 1.716 + (goto-char p) 1.717 + (delete-region (point) (progn (forward-list 1) (point))) 1.718 + (if (looking-at "^\\s *$") 1.719 + (delete-region (point) (progn (forward-line 1) (point)))) 1.720 + (if whole (delete-region p q)) 1.721 + tag)))) 1.722 + 1.723 +(defun yahtml-kill-* (whole) 1.724 + "Kill current position's HTML tag (set)." 1.725 + (interactive "P") 1.726 + (cond 1.727 + ((yahtml-kill-begend whole)) 1.728 + )) 1.729 + 1.730 + 1.731 +;;; ---------- changing ---------- 1.732 +(defun yahtml-change-begend () 1.733 + (let ((tag (yahtml-on-begend-p)) 1.734 + (completion-ignore-case t) 1.735 + (p (point)) (q (make-marker)) 1.736 + (default (append yahtml-env-table yahtml-typeface-table)) 1.737 + (user (append yahtml-user-env-table yahtml-user-typeface-table)) 1.738 + (tmp (append yahtml-tmp-env-table yahtml-tmp-typeface-table)) 1.739 + ) 1.740 + (if tag 1.741 + (save-excursion 1.742 + (if (= (aref tag 0) ?/) (setq tag (substring tag 1))) 1.743 + (or (= (char-after (point)) ?<) (skip-chars-backward "^<")) 1.744 + (skip-chars-forward "^A-Za-z") 1.745 + (set-marker q (point)) 1.746 + (setq p (point)) 1.747 + (yahtml-goto-corresponding-begend) 1.748 + (or (= (char-after (point)) ?<) 1.749 + (skip-chars-backward "^<")) 1.750 + (skip-chars-forward "^A-Za-z") 1.751 + (if (= (char-after (1- (point))) ?/) 1.752 + (progn 1.753 + (set-marker q (point)) 1.754 + (goto-char p))) 1.755 + (setq tag (YaTeX-cplread-with-learning 1.756 + (format "Change `%s' to(default %s): " 1.757 + tag yahtml-last-begend) 1.758 + 'default 'user 'tmp)) 1.759 + (delete-region (point) (progn (skip-chars-forward "^>") (point))) 1.760 + (if (string= "" tag) (setq tag yahtml-last-begend)) 1.761 + (setq yahtml-last-begend 1.762 + (or (cdr (assoc tag yahtml-env-table)) tag) 1.763 + tag yahtml-last-begend) 1.764 + (insert (format "%s%s" tag (yahtml-addin tag))) 1.765 + (goto-char q) 1.766 + (delete-region (point) (progn (skip-chars-forward "^>") (point))) 1.767 + (insert tag))))) 1.768 + 1.769 +(defun yahtml-change-* () 1.770 + "Change current position's HTML tag (set)." 1.771 + (interactive) 1.772 + (cond 1.773 + ((yahtml-change-begend)) 1.774 + )) 1.775 + 1.776 ;;; ---------- commenting ---------- 1.777 (defun yahtml-comment-region (beg end) 1.778 (interactive "r") 1.779 @@ -548,6 +881,238 @@ 1.780 1.781 1.782 1.783 +;;; ---------- filling ---------- 1.784 +(defun yahtml-fill-paragraph (arg) 1.785 + (interactive "P") 1.786 + (let ((case-fold-search t) (p (point))) 1.787 + (save-excursion 1.788 + (fill-region-as-paragraph 1.789 + (progn (re-search-backward paragraph-start nil t) 1.790 + (or (save-excursion 1.791 + (goto-char (match-end 0)) 1.792 + (if (looking-at "[ \t]*$") 1.793 + (progn (forward-line 1) (point)))) 1.794 + (point))) 1.795 + (progn (goto-char p) 1.796 + (re-search-forward paragraph-start nil t) 1.797 + (match-beginning 0)))))) 1.798 + 1.799 +;;; 1.800 +;;; ---------- indentation ---------- 1.801 +;;; 1.802 +(defvar yahtml-hate-too-deep-indentation nil) 1.803 +(defun yahtml-indent-line () 1.804 + (interactive) 1.805 + (let ((envs "[uod]l\\|table\\|t[rhd]") 1.806 + (itms "<\\(dt\\|dd\\|li\\|t[rdh]\\)>") 1.807 + inenv p col peol (case-fold-search t)) 1.808 + (save-excursion 1.809 + (beginning-of-line) 1.810 + (setq inenv (or (YaTeX-inner-environment) "html") 1.811 + col (get 'YaTeX-inner-environment 'indent) 1.812 + p (get 'YaTeX-inner-environment 'point) 1.813 + op)) 1.814 + (save-excursion 1.815 + (cond 1.816 + ((string-match envs inenv) 1.817 + (save-excursion 1.818 + (beginning-of-line) 1.819 + (skip-chars-forward " \t") 1.820 + (cond 1.821 + ((looking-at (concat "</\\(" envs "\\)>")) 1.822 + (YaTeX-reindent col)) 1.823 + ((or (looking-at itms) 1.824 + (and yahtml-hate-too-deep-indentation 1.825 + (looking-at (concat "<" envs)))) 1.826 + (YaTeX-reindent (+ col YaTeX-environment-indent))) 1.827 + ((and (< p (point)) 1.828 + (save-excursion 1.829 + (and 1.830 + ;;(re-search-backward itms p t) 1.831 + (setq op (point)) 1.832 + (goto-char p) 1.833 + (re-search-forward itms op t) 1.834 + (goto-char (match-end 0)) 1.835 + (skip-chars-forward " \t") 1.836 + (setq col (current-column))))) 1.837 + (YaTeX-reindent col)) 1.838 + (t 1.839 + (YaTeX-reindent (+ col YaTeX-environment-indent))))))) 1.840 + (and (bolp) (skip-chars-forward " \t")) 1.841 + (if (and (setq inenv (yahtml-on-begend-p)) 1.842 + (string-match (concat "^\\(" envs "\\)") inenv)) 1.843 + (save-excursion 1.844 + (setq peol (point-end-of-line)) 1.845 + (or (= (char-after (point)) ?<) 1.846 + (progn (skip-chars-backward "^<") (forward-char -1))) 1.847 + (setq col (current-column)) 1.848 + (if (and (yahtml-goto-corresponding-begend t) 1.849 + (> (point) peol)) ;if on the different line 1.850 + (YaTeX-reindent col))))) 1.851 + (and (bolp) (skip-chars-forward " \t")))) 1.852 + 1.853 +;(defun yahtml-fill-item () 1.854 +; "Fill item HTML version" 1.855 +; (interactive) 1.856 +; (let (inenv p fill-prefix peol (case-fold-search t)) 1.857 +; (setq inenv (or (YaTeX-inner-environment) "html") 1.858 +; p (get 'YaTeX-inner-environment 'point)) 1.859 +; (cond 1.860 +; ((string-match "^[uod]l" inenv) 1.861 +; (save-excursion 1.862 +; (if (re-search-backward "<\\(d[td]\\|li\\)>[ \t\n]*" p t) 1.863 +; (progn 1.864 +; (goto-char (match-end 0)) 1.865 +; (setq col (current-column))) 1.866 +; (error "No <li>, <dt>, <dd>"))) 1.867 +; (save-excursion 1.868 +; (end-of-line) 1.869 +; (setq peol (point)) 1.870 +; (newline) 1.871 +; (indent-to-column col) 1.872 +; (setq fill-prefix (buffer-substring (point) (1+ peol))) 1.873 +; (delete-region (point) peol) 1.874 +; (fill-region-as-paragraph 1.875 +; (progn (re-search-backward paragraph-start nil t) (point)) 1.876 +; (progn (re-search-forward paragraph-start nil t 2) 1.877 +; (match-beginning 0))))) 1.878 +; (t nil)))) 1.879 + 1.880 +;;; 1.881 +;;; ---------- Browsing ---------- 1.882 +;;; 1.883 +(defun yahtml-browse-menu () 1.884 + "Browsing menu" 1.885 + (interactive) 1.886 + (message "B)rowse R)eload...") 1.887 + (let ((c (char-to-string (read-char)))) 1.888 + (cond 1.889 + ((string-match "[bj]" c) 1.890 + (yahtml-browse-current-file)) 1.891 + ((string-match "r" c) 1.892 + (yahtml-browse-reload))))) 1.893 + 1.894 +(defun yahtml-file-to-url (file) 1.895 + "Convert local unix file name to URL. 1.896 +If no matches found in yahtml-path-url-alist, return raw file name." 1.897 + (let ((list yahtml-path-url-alist) p url) 1.898 + (if (file-directory-p file) 1.899 + (setq file (expand-file-name yahtml-directory-index file)) 1.900 + (setq file (expand-file-name file))) 1.901 + (while list 1.902 + (if (string-match (concat "^" (regexp-quote (car (car list)))) file) 1.903 + (setq url (cdr (car list)) 1.904 + file (substring file (match-end 0)) 1.905 + url (concat url file) 1.906 + list nil)) 1.907 + (setq list (cdr list))) 1.908 + (or url (concat "file:" file)))) 1.909 + 1.910 +(defun yahtml-url-to-path (file &optional basedir) 1.911 + "Convert local URL name to unix file name." 1.912 + (let ((list yahtml-path-url-alist) url realpath docroot 1.913 + (dirsufp (string-match "/$" file))) 1.914 + (setq basedir (or basedir 1.915 + (file-name-directory 1.916 + (expand-file-name default-directory)))) 1.917 + (cond 1.918 + ((string-match "^/" file) 1.919 + (while list 1.920 + (if (string-match (concat "^" (regexp-quote (car (car list)))) basedir) 1.921 + (progn 1.922 + (setq url (cdr (car list))) 1.923 + (if (string-match "\\(http://[^/]*\\)/" url) 1.924 + (setq docroot (substring url (match-end 1))) 1.925 + (setq docroot url)) 1.926 + (if (string-match (regexp-quote docroot) file) 1.927 + (setq realpath 1.928 + (expand-file-name 1.929 + (substring 1.930 + file (min (1+ (match-end 0)) (length file))) 1.931 + (car (car list))))) 1.932 + (if realpath 1.933 + (progn (setq list nil) 1.934 + (if (and dirsufp (not (string-match "/$" realpath))) 1.935 + (setq realpath (concat realpath "/"))))))) 1.936 + (setq list (cdr list))) 1.937 + realpath) 1.938 + (t file)))) 1.939 + 1.940 +(defun yahtml-browse-current-file () 1.941 + "Call WWW browser on current file." 1.942 + (interactive) 1.943 + (basic-save-buffer) 1.944 + (yahtml-browse-html (yahtml-file-to-url (buffer-file-name)))) 1.945 + 1.946 +(defun yahtml-browse-reload () 1.947 + "Send `reload' event to netzscape." 1.948 + (let ((pb "* WWW Browser *") (cb (current-buffer))) 1.949 + (cond 1.950 + ((string-match "[Nn]etscape" yahtml-www-browser) 1.951 + (if (get-buffer pb) 1.952 + (progn (set-buffer pb) (erase-buffer) (set-buffer cb))) 1.953 + ;;(or (get 'yahtml-netscape-sentinel 'url) 1.954 + ;; (error "Reload should be called after Browsing.")) 1.955 + (put 'yahtml-netscape-sentinel 'url 1.956 + (yahtml-file-to-url (buffer-file-name))) 1.957 + (basic-save-buffer) 1.958 + (set-process-sentinel 1.959 + (setq yahtml-browser-process 1.960 + (start-process 1.961 + "browser" pb shell-file-name "-c" 1.962 + (format "%s -remote 'reload'" yahtml-www-browser))) 1.963 + 'yahtml-netscape-sentinel)) 1.964 + (t 1.965 + (message "Sorry, RELOAD is supported only for Netscape."))))) 1.966 + 1.967 +;;; ---------- Intelligent newline ---------- 1.968 +(defun yahtml-intelligent-newline (arg) 1.969 + "Intelligent newline for HTML" 1.970 + (interactive "P") 1.971 + (let ((env (downcase (or (YaTeX-inner-environment) "html"))) func) 1.972 + (setq func (intern-soft (concat "yahtml-intelligent-newline-" env))) 1.973 + (end-of-line) 1.974 + (newline) 1.975 + (if (and env func (fboundp func)) 1.976 + (funcall func)))) 1.977 + 1.978 +(defun yahtml-intelligent-newline-ul () 1.979 + (interactive) 1.980 + (insert (if yahtml-prefer-upcases "<LI> " "<li> ")) 1.981 + (yahtml-indent-line)) 1.982 + 1.983 +(fset 'yahtml-intelligent-newline-ol 'yahtml-intelligent-newline-ul) 1.984 + 1.985 +(defun yahtml-intelligent-newline-dl () 1.986 + (interactive) 1.987 + (let ((case-fold-search t)) 1.988 + (if (save-excursion 1.989 + (re-search-backward "<\\(\\(dt\\)\\|\\(dd\\)\\)>" 1.990 + (get 'YaTeX-inner-environment 'point) t)) 1.991 + (cond 1.992 + ((match-beginning 2) 1.993 + (insert (if yahtml-prefer-upcases "<DD> " "<dd> ")) 1.994 + (setq yahtml-last-single-cmd "dt")) 1.995 + ((match-beginning 3) 1.996 + (insert (if yahtml-prefer-upcases "<DT> " "<dt> ")) 1.997 + (setq yahtml-last-single-cmd "dd"))) 1.998 + (insert (if yahtml-prefer-upcases "<DT> " "<dt> "))) 1.999 + (yahtml-indent-line))) 1.1000 + 1.1001 +;;; ---------- Marking ---------- 1.1002 +(defun yahtml-mark-begend () 1.1003 + "Mark current tag" 1.1004 + (interactive) 1.1005 + (YaTeX-beginning-of-environment) 1.1006 + (let ((p (point))) 1.1007 + (save-excursion 1.1008 + (skip-chars-backward " \t" (point-beginning-of-line)) 1.1009 + (if (bolp) (setq p (point)))) 1.1010 + (push-mark p t)) 1.1011 + (yahtml-goto-corresponding-begend) 1.1012 + (forward-list 1) 1.1013 + (if (eolp) (forward-char 1))) 1.1014 + 1.1015 ;;; ---------- ---------- 1.1016 ;;; ---------- ---------- 1.1017 ;;; ---------- ---------- 1.1018 @@ -582,7 +1147,7 @@ 1.1019 (skip-chars-forward " \t\n") 1.1020 (cons (point) 1.1021 (progn (re-search-forward (concat "</" tag ">") nil t) 1.1022 - (1- (match-beginning 0))))))) 1.1023 + (match-beginning 0)))))) 1.1024 1.1025 ;(setq hilit-patterns-alist (delq (assq 'yahtml-mode hilit-patterns-alist) hilit-patterns-alist)) 1.1026 (cond