yatex
diff yahtml.el @ 64:36a48185b95a
Changes are listed in yatex.new.
Major one is supporing GNU Emacs20 and XEmacs.
author | yuuji |
---|---|
date | Tue, 16 Dec 1997 13:28:38 +0000 |
parents | b9f753846b6b |
children | 0eb6997bee16 |
line diff
1.1 --- a/yahtml.el Mon Apr 07 20:07:48 1997 +0000 1.2 +++ b/yahtml.el Tue Dec 16 13:28:38 1997 +0000 1.3 @@ -1,6 +1,6 @@ 1.4 ;;; -*- Emacs-Lisp -*- 1.5 ;;; (c ) 1994-1997 by HIROSE Yuuji [yuuji@ae.keio.ac.jp] 1.6 -;;; Last modified Mon Apr 7 16:58:32 1997 on crx 1.7 +;;; Last modified Tue Dec 16 21:10:05 1997 on crx 1.8 ;;; $Id$ 1.9 1.10 ;;;[Installation] 1.11 @@ -18,6 +18,22 @@ 1.12 ;;; ("/home/staff/yuuji/html" . "http://www.othernet/~yuuji"))) 1.13 ;;; ;Write correspondence alist from ABSOLUTE unix path name to URL path. 1.14 ;;; 1.15 +;;;[インストール方法] 1.16 +;;; 1.17 +;;; yahtml.el, yatexlib.el, yatexprc.el を load-path の通ったディレクト 1.18 +;;; リにインストールしてください。その後、以下を参考に ~/.emacs に設定を 1.19 +;;; 追加して下さい。 1.20 +;;; 1.21 +;;; (setq auto-mode-alist 1.22 +;;; (cons (cons "\\.html$" 'yahtml-mode) auto-mode-alist)) 1.23 +;;; (autoload 'yahtml-mode "yahtml" "Yet Another HTML mode" t) 1.24 +;;; (setq yahtml-www-browser "netscape") 1.25 +;;; ;お気に入りのブラウザを書いて下さい。netscapeが便利です。 1.26 +;;; (setq yahtml-path-url-alist 1.27 +;;; '(("/home/yuuji/public_html" . "http://www.mynet/~yuuji") 1.28 +;;; ("/home/staff/yuuji/html" . "http://www.othernet/~yuuji"))) 1.29 +;;; ;UNIXの絶対パスと対応するURLのリストを書いて下さい。 1.30 +;;; 1.31 ;;;[Commentary] 1.32 ;;; 1.33 ;;; It is assumed you are already familiar with YaTeX. The following 1.34 @@ -29,15 +45,16 @@ 1.35 ;;; this group 1.36 ;;; When input `href=...', you can complete file 1.37 ;;; name or label(href="#foo") by typing TAB. 1.38 -;;; * [prefix] s Complete declarative notations such as 1.39 -;;; `<img src="foo.gif">' 1.40 -;;; `<input name="var" ...>' 1.41 ;;; * [prefix] l Complete typeface-changing commands such as 1.42 ;;; `<i> ... </i>' or `<samp> ... </samp>' 1.43 ;;; This completion can be used to make in-line 1.44 ;;; tags which is normally completed with [prefix] b. 1.45 +;;; * [prefix] s Complete declarative notations such as 1.46 +;;; `<img src="foo.gif">' 1.47 +;;; `<input name="var" ...>' 1.48 ;;; * [prefix] m Complete single commands such as 1.49 ;;; `<br>' or `<hr> or <li>...' 1.50 +;;; * [prefix] p Insert <p></p> on the point 1.51 ;;; * M-RET Intelligent newline; if current TAG is one of 1.52 ;;; ul, ol, or dl. insert newline and <li> or 1.53 ;;; <dt> or <dd> suitable for current condition. 1.54 @@ -59,35 +76,116 @@ 1.55 ;;; * [prefix] a YaTeX's accent mark's equivalent of yahtml. 1.56 ;;; This function can input $lt, $gt or so. 1.57 ;;; 1.58 +;;;[キーの説明] 1.59 +;;; 1.60 +;;; 以下の説明において、特にカスタマイズをしていない限り、[prefix] は 1.61 +;;; C-c キーを意味します。 1.62 +;;; 1.63 +;;; * [prefix] b X `</H1>' といった終了タグが必要となる`H1'のよう 1.64 +;;; な環境を補完入力します。<a href=foo> ... </a> 1.65 +;;; もこのグループです。 1.66 +;;; `href=...' と入力した後、TABキーを押すことで、 1.67 +;;; ファイル名や (href="#foo") のようなラベルも補完 1.68 +;;; できます。 1.69 +;;; * [prefix] s 以下のような宣言の補完を行います。 1.70 +;;; `<img src="foo.gif">' 1.71 +;;; `<input name="var" ...>' 1.72 +;;; * [prefix] l `<i> ... </i>' や `<samp> ... </samp>' のよう 1.73 +;;; なテキストスタイル指定のタグを補完します。 1.74 +;;; この補完機能は通常 [prefix] b で補完できるものを 1.75 +;;; 一行内で書きたいときにも用いることが出来ます。 1.76 +;;; * [prefix] m `<br>' や `<hr> '、`<li>' 等の単体タグの補完 1.77 +;;; を行います。 1.78 +;;; * [prefix] p カーソル位置に<p></p>を挿入します。 1.79 +;;; * M-RET おまかせ改行; もしul、ol、dl等のタグ(リスト)を 1.80 +;;; 使っている場合に、環境に合わせて改行と <li>、 1.81 +;;; <dt>、<dd>を入力します。 1.82 +;;; * menu-bar yahtml 選択したアイテムをメニューより補完できます。 1.83 +;;; (私はメニューが嫌いなんですが、htmlに関してはメ 1.84 +;;; ニューは一番ありがたいかも) 1.85 +;;; * [prefix] g 対応するタグ、<dl> <-> </dl> や href="xxx" の 1.86 +;;; ような TAG にジャンプします。 1.87 +;;; <img src=...> の場合はイメージビューワを呼び出 1.88 +;;; します。href=hoge.html の場合はhoge.htmlに飛びま 1.89 +;;; す。 1.90 +;;; * [prefix] k ポイント上の HTML タグを消去します。 1.91 +;;; もし universal-argument を付けた場合(C-uを先に押 1.92 +;;; す)HTMLタグで囲まれた内容も同時に消去します。 1.93 +;;; * [prefix] c ポイント上のタグを変更します。 1.94 +;;; `href="xxx"'の上で [prefix] c を利用した場合は、 1.95 +;;; 参照しているリンクを補完機能を使いながら変更で 1.96 +;;; きます。 1.97 +;;; * [prefix] t j カレントファイルに対して jweblint を呼び出しま 1.98 +;;; す。 1.99 +;;; * [prefix] t p WWW ブラウザでカレントファイルを表示します。 1.100 +;;; (lisp変数 yahtml-www-browser の設定をお忘れな 1.101 +;;; く。お推めは "netscape" で、ねすけの場合既にねす 1.102 +;;; けが起動されていた場合そのねすけに Reload 命令を 1.103 +;;; 送るという芸当が出来ます。ただし今のところX版の 1.104 +;;; ねすけちゃんだけ) 1.105 +;;; * [prefix] a YaTeX のアクセント記号補完と同じです。 1.106 +;;; < > 等が入力できます。 1.107 +;;; 1.108 +;;; [謝辞] 1.109 +;;; 1.110 +;;; fj野鳥の会の皆さんには貴重な助言を頂きました。また、下に示す方々には 1.111 +;;; 特に大きな協力を頂きました。あわせてここに感謝申し上げます。 1.112 +;;; 1.113 +;;; * 横田和也さん(マツダ) 1.114 +;;; マニュアルの和訳をして頂きました。 1.115 +;;; * 吉田尚志さん(NTT Data) 1.116 +;;; Mule for Win32 での動作のさせ方を教えて頂きました。 1.117 +;;; (というかほとんどやってもらった ^^;) 1.118 +;;; 1.119 1.120 1.121 -(require 'yatex) 1.122 +;(require 'yatex) 1.123 +(require 'yatexlib) 1.124 ;;; --- customizable variable starts here --- 1.125 +(defvar yahtml-prefix "\C-c" 1.126 + "*Prefix key stroke of yahtml functions.") 1.127 (defvar yahtml-image-viewer "xv" "*Image viewer program") 1.128 (defvar yahtml-www-browser "netscape" 1.129 "*WWW Browser command") 1.130 (defvar yahtml-kanji-code 2 1.131 - "Kanji coding system of html file; 1=sjis, 2=jis, 3=euc") 1.132 + "*Kanji coding system number of html file; 1=sjis, 2=jis, 3=euc") 1.133 +(defvar yahtml-coding-system 1.134 + (cdr (assq yahtml-kanji-code YaTeX-kanji-code-alist)) 1.135 + "Kanji coding system") 1.136 +(defvar yahtml-fill-column 72 "*fill culumn used for yahtml-mode") 1.137 +(defvar yahtml-fill-prefix nil "*fill prefix for yahtml-mode") 1.138 + 1.139 ;;(defvar yahtml-www-server "www" "*Host name of your domain's WWW server") 1.140 (defvar yahtml-path-url-alist nil 1.141 "*Alist of unix path name vs. URL name of WWW server. 1.142 Ex. 1.143 '((\"/usr/home/yuuji/http\" . \"http://www.comp.ae.keio.ac.jp/~yuuji\") 1.144 - (\"/usr/home/yuuji/darts/http\" . \"http://inspire.comp.ae.keio.ac.jp/~darts\"))") 1.145 + (\"/usr/home/yuuji/darts/http\" . \"http://darts.comp.ae.keio.ac.jp/~darts\"))") 1.146 (defvar yahtml-directory-index "index.html" 1.147 "*Directory index file name; 1.148 Consult your site's WWW administrator.") 1.149 1.150 -(defvar yahtml-environment-indent YaTeX-environment-indent 1.151 +(defvar yahtml-environment-indent 1 1.152 "*Indentation depth of HTML's listing environment") 1.153 1.154 +(defvar YaTeX-japan (or (boundp 'NEMACS) (boundp 'MULE) YaTeX-emacs-20) 1.155 + "Whether yatex mode is running on Japanese environment or not.") 1.156 + 1.157 (defvar yahtml-lint-program (if YaTeX-japan "jweblint" "weblint") 1.158 "*Program name to lint HTML file") 1.159 (defvar yahtml-hate-too-deep-indentation nil 1.160 "*Non-nil for this variable suppress deep indentation in listing environments.") 1.161 1.162 +(defvar yahtml-always-/p nil 1.163 + "*Those who always use <p> with </p> set this to t.") 1.164 + 1.165 +(defvar yahtml-p-prefered-env-regexp "^\\(body\\|dl\\)" 1.166 + "*Regexp of envs where paragraphed sentences are prefered.") 1.167 + 1.168 +(defvar yahtml-template-file "~/http/template.html" 1.169 + "*Template HTML file. It'll be inserted to empty file.") 1.170 + 1.171 ;;; --- customizable variable ends here --- 1.172 - 1.173 (defvar yahtml-prefix-map nil) 1.174 (defvar yahtml-mode-map nil "Keymap used in yahtml-mode.") 1.175 (defvar yahtml-lint-buffer-map nil "Keymap used in lint buffer.") 1.176 @@ -121,7 +219,7 @@ 1.177 (if yahtml-mode-map nil 1.178 (setq yahtml-mode-map (make-sparse-keymap) 1.179 yahtml-prefix-map (make-sparse-keymap)) 1.180 - (define-key yahtml-mode-map YaTeX-prefix yahtml-prefix-map) 1.181 + (define-key yahtml-mode-map yahtml-prefix yahtml-prefix-map) 1.182 (define-key yahtml-mode-map "\M-\C-@" 'yahtml-mark-begend) 1.183 (if (and (boundp 'window-system) (eq window-system 'x) YaTeX-emacs-19) 1.184 (define-key yahtml-mode-map [?\M-\C- ] 'yahtml-mark-begend)) 1.185 @@ -129,7 +227,6 @@ 1.186 (define-key yahtml-mode-map "\M-\C-e" 'YaTeX-end-of-environment) 1.187 (define-key yahtml-mode-map "\M-\C-m" 'yahtml-intelligent-newline) 1.188 (define-key yahtml-mode-map "\C-i" 'yahtml-indent-line) 1.189 - (define-key yahtml-mode-map YaTeX-prefix yahtml-prefix-map) 1.190 (let ((map yahtml-prefix-map)) 1.191 (YaTeX-define-key "^" 'yahtml-visit-main map) 1.192 (YaTeX-define-key "4^" 'yahtml-visit-main-other-window map) 1.193 @@ -150,6 +247,7 @@ 1.194 (YaTeX-define-key "m" 'yahtml-insert-single map) 1.195 (YaTeX-define-key "n" '(lambda () (interactive) (insert (if yahtml-prefer-upcases "<BR>" "<br>"))) map) 1.196 (YaTeX-define-key "-" '(lambda () (interactive) (insert (if yahtml-prefer-upcases "<HR>" "<hr>") "\n")) map) 1.197 + (YaTeX-define-key "p" 'yahtml-insert-p map) 1.198 (if YaTeX-no-begend-shortcut 1.199 (progn 1.200 (YaTeX-define-key "B" 'yahtml-insert-begend-region map) 1.201 @@ -197,7 +295,7 @@ 1.202 "^$\\|<!--\\|^[ \t]*</?\\(h[1-6]\\|p\\|[bhtd][ldt]\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\|table\\|center\\|blockquote\\|!--\\)\\b") 1.203 "*Regexp of html paragraph separater") 1.204 (defvar yahtml-syntax-table nil 1.205 - "*Syntax table for typesetting buffer") 1.206 + "*Syntax table for yahtml-mode") 1.207 1.208 (if yahtml-syntax-table nil 1.209 (setq yahtml-syntax-table 1.210 @@ -214,6 +312,7 @@ 1.211 '(("img") ("input"))) 1.212 (defvar yahtml-user-form-table nil) 1.213 (defvar yahtml-tmp-form-table nil) 1.214 +(defvar yahtml-last-form "img") 1.215 1.216 (defvar yahtml-env-table 1.217 '(("html") ("head") ("title") ("body") ("dl") ("ul") ("ol") ("pre") 1.218 @@ -224,7 +323,8 @@ 1.219 ("Preformatted" . "pre") 1.220 ("table") ("tr") ("th") ("td") 1.221 ("h1") ("h2") ("h3") ("h4") ("h5") ("h6") 1.222 - ("p"))) 1.223 + ;; ("p") ;This makes indentation screwed up! 1.224 + )) 1.225 1.226 (defvar yahtml-itemizing-regexp 1.227 "\\(ul\\|ul\\|dl\\)" 1.228 @@ -234,15 +334,19 @@ 1.229 (defvar yahtml-tmp-env-table nil) 1.230 1.231 ;;; Completion tables for typeface designator 1.232 +(and yahtml-always-/p 1.233 + (or (assoc "p" yahtml-env-table) 1.234 + (setq yahtml-env-table (cons '("p") yahtml-env-table)))) 1.235 + 1.236 (defvar yahtml-typeface-table 1.237 (append 1.238 '(("dfn") ("em") ("cite") ("code") ("kbd") ("samp") 1.239 - ("strong") ("var") ("b") ("i") ("tt") ("u") ("address")) 1.240 + ("strong") ("var") ("b") ("i") ("tt") ("u") ("address") ("font")) 1.241 yahtml-env-table) 1.242 "Default completion table of typeface designator") 1.243 (defvar yahtml-user-typeface-table nil) 1.244 (defvar yahtml-tmp-typeface-table nil) 1.245 -(defvar yahtml-last-typeface-cmd "address") 1.246 +(defvar yahtml-last-typeface-cmd "a") 1.247 1.248 (defvar yahtml-single-cmd-table 1.249 '(("hr") ("br") ("option") ("p") 1.250 @@ -269,57 +373,80 @@ 1.251 (mapconcat (function (lambda (x) (car x))) yahtml-typeface-table "\\|") 1.252 "\\)\\b") 1.253 "Regexp of structure beginning.") 1.254 +(or (assoc "p" yahtml-env-table) 1.255 + (setq yahtml-env-table (cons '("p") yahtml-env-table))) 1.256 1.257 (defun yahtml-mode () 1.258 (interactive) 1.259 - (yatex-mode) 1.260 (cond 1.261 - ((boundp 'MULE) 1.262 - (set-file-coding-system 1.263 - (cdr (assq yahtml-kanji-code YaTeX-kanji-code-alist)))) 1.264 + ((and YaTeX-emacs-20 (fboundp 'coding-system-equal)) 1.265 + (if t (or (coding-system-equal 1.266 + yahtml-coding-system buffer-file-coding-system) 1.267 + (set-buffer-file-coding-system yahtml-coding-system)) 1.268 + ;;^v which is better? 1.269 + (let ((bmp (buffer-modified-p))) 1.270 + (set-buffer-file-coding-system yahtml-coding-system) 1.271 + (set-buffer-modified-p bmp)))) 1.272 + ((featurep 'mule) 1.273 + (set-file-coding-system yahtml-coding-system)) 1.274 ((boundp 'NEMACS) 1.275 (make-local-variable 'kanji-fileio-code) 1.276 (setq kanji-fileio-code yahtml-kanji-code))) 1.277 (setq major-mode 'yahtml-mode 1.278 mode-name "yahtml") 1.279 - (make-local-variable 'YaTeX-kanji-code) 1.280 - (make-local-variable 'YaTeX-ec) (setq YaTeX-ec "") 1.281 - (make-local-variable 'YaTeX-struct-begin) 1.282 - (setq YaTeX-struct-begin "<%1%2") 1.283 - (make-local-variable 'YaTeX-struct-end) (setq YaTeX-struct-end "</%1>") 1.284 - (make-local-variable 'YaTeX-struct-name-regexp) 1.285 - (setq YaTeX-struct-name-regexp yahtml-struct-name-regexp) 1.286 - (make-local-variable 'YaTeX-prefix-map) 1.287 - (make-local-variable 'YaTeX-command-token-regexp) 1.288 - (setq YaTeX-command-token-regexp yahtml-command-regexp) 1.289 - (make-local-variable 'YaTeX-comment-prefix) 1.290 - (setq YaTeX-comment-prefix "<!--") 1.291 - ;;(make-local-variable 'YaTeX-environment-indent) 1.292 - ;;(setq YaTeX-environment-indent 0) 1.293 - (make-local-variable 'fill-prefix) 1.294 - (setq fill-prefix nil) 1.295 - (make-local-variable 'paragraph-separate) 1.296 - (setq paragraph-start yahtml-paragraph-start 1.297 - paragraph-separate yahtml-paragraph-separate) 1.298 - (make-local-variable 'comment-start) 1.299 - (make-local-variable 'comment-end) 1.300 - (setq comment-start "<!-- " comment-end " -->") 1.301 - (make-local-variable 'indent-line-function) 1.302 - (setq indent-line-function 'yahtml-indent-line) 1.303 - (make-local-variable 'YaTeX-item-regexp) 1.304 - (setq YaTeX-item-regexp "<\\(li\\|d[td]\\)>") 1.305 - (make-local-variable 'YaTeX-typesetting-mode-map) 1.306 - (setq YaTeX-typesetting-mode-map yahtml-lint-buffer-map) 1.307 + (mapcar 1.308 + (function (lambda (x) 1.309 + (make-local-variable (car x)) 1.310 + (set (car x) (if (and (symbolp (cdr x)) 1.311 + (boundp (cdr x))) 1.312 + (symbol-value (cdr x)) 1.313 + (cdr x))))) 1.314 + '((YaTeX-ec . "") 1.315 + (YaTeX-struct-begin . "<%1%2") 1.316 + (YaTeX-struct-end . "</%1>") 1.317 + (YaTeX-struct-name-regexp . yahtml-struct-name-regexp) 1.318 + (YaTeX-comment-prefix . "<!--") 1.319 + (YaTeX-coding-system . yahtml-coding-system) 1.320 + (YaTeX-typesetting-mode-map . yahtml-lint-buffer-map) 1.321 + (fill-prefix . yahtml-fill-prefix) (fill-column . yahtml-fill-column) 1.322 + (paragraph-start . yahtml-paragraph-start) 1.323 + (paragraph-separate . yahtml-paragraph-separate) 1.324 + (comment-start . "<!-- ") (comment-end . " -->") 1.325 + (comment-start-skip . comment-start) 1.326 + (indent-line-function . yahtml-indent-line))) 1.327 + 1.328 (set-syntax-table yahtml-syntax-table) 1.329 (use-local-map yahtml-mode-map) 1.330 - (run-hooks 'yahtml-mode-hook)) 1.331 + (YaTeX-read-user-completion-table) 1.332 + (turn-on-auto-fill) ;Sorry, this is prerequisite 1.333 + (and (= 0 (buffer-size)) (file-exists-p yahtml-template-file) 1.334 + (y-or-n-p (format "Insert %s?" yahtml-template-file)) 1.335 + (insert-file-contents (expand-file-name yahtml-template-file))) 1.336 + (run-hooks 'text-mode-hook 'yahtml-mode-hook)) 1.337 1.338 (defun yahtml-define-menu (keymap bindlist) 1.339 - (mapcar 1.340 - (function 1.341 - (lambda (bind) 1.342 - (define-key keymap (vector (car bind)) (cdr bind)))) 1.343 - bindlist)) 1.344 + (cond 1.345 + ((featurep 'xemacs) 1.346 + (let ((name (keymap-name (symbol-value keymap)))) 1.347 + (set keymap nil) 1.348 + (mapcar 1.349 + (function 1.350 + (lambda (bind) 1.351 + (setq bind (cdr bind)) 1.352 + (if (eq (car (cdr bind)) 'lambda) 1.353 + (setcar (cdr bind) 'progn)) 1.354 + (if (stringp (car (cdr bind))) 1.355 + (set keymap (cons (cdr bind) (symbol-value keymap))) 1.356 + (set keymap (cons (vector (car bind) (cdr bind) t) 1.357 + (symbol-value keymap)))))) 1.358 + bindlist) 1.359 + (set keymap (cons name (symbol-value keymap))))) 1.360 + (t 1.361 + (mapcar 1.362 + (function 1.363 + (lambda (bind) 1.364 + (define-key (symbol-value keymap) (vector (car bind)) (cdr bind)))) 1.365 + bindlist)))) 1.366 1.367 (defvar yahtml-menu-map nil "Menu map of yahtml") 1.368 (defvar yahtml-menu-map-sectioning nil "Menu map of yahtml(sectioning)") 1.369 @@ -329,15 +456,15 @@ 1.370 1.371 ;;; Variables for mosaic url history 1.372 (defvar yahtml-urls nil "Alist of global history") 1.373 -(defvar yahtml-url-history-file "~/.mosaic-global-history" 1.374 - "File name of url history") 1.375 +(defvar yahtml-urls-private nil) 1.376 +(defvar yahtml-urls-local nil) 1.377 1.378 (cond 1.379 ((and YaTeX-emacs-19 (null yahtml-menu-map)) 1.380 - (setq yahtml-menu-map (make-sparse-keymap "yahtml menu")) 1.381 + (setq yahtml-menu-map (make-sparse-keymap "yahtml")) 1.382 (setq yahtml-menu-map-sectioning (make-sparse-keymap "sectioning menu")) 1.383 - (yahtml-define-menu 1.384 - yahtml-menu-map-sectioning 1.385 + (YaTeX-define-menu 1.386 + 'yahtml-menu-map-sectioning 1.387 (nreverse 1.388 '((1 "H1" . (lambda () (interactive) (yahtml-insert-begend nil "H1"))) 1.389 (2 "H2" . (lambda () (interactive) (yahtml-insert-begend nil "H2"))) 1.390 @@ -347,8 +474,8 @@ 1.391 (6 "H6" . (lambda () (interactive) (yahtml-insert-begend nil "H6"))) 1.392 ))) 1.393 (setq yahtml-menu-map-logical (make-sparse-keymap "logical tags")) 1.394 - (yahtml-define-menu 1.395 - yahtml-menu-map-logical 1.396 + (YaTeX-define-menu 1.397 + 'yahtml-menu-map-logical 1.398 (nreverse 1.399 '((em "Embolden" . 1.400 (lambda () (interactive) (yahtml-insert-tag nil "EM"))) 1.401 @@ -368,8 +495,8 @@ 1.402 (lambda () (interactive) (yahtml-insert-tag nil "VAR"))) 1.403 ))) 1.404 (setq yahtml-menu-map-typeface (make-sparse-keymap "typeface tags")) 1.405 - (yahtml-define-menu 1.406 - yahtml-menu-map-typeface 1.407 + (YaTeX-define-menu 1.408 + 'yahtml-menu-map-typeface 1.409 (nreverse 1.410 '((b "Bold" . 1.411 (lambda () (interactive) (yahtml-insert-tag nil "B"))) 1.412 @@ -381,8 +508,8 @@ 1.413 (lambda () (interactive) (yahtml-insert-tag nil "U"))) 1.414 ))) 1.415 (setq yahtml-menu-map-listing (make-sparse-keymap "listing")) 1.416 - (yahtml-define-menu 1.417 - yahtml-menu-map-listing 1.418 + (YaTeX-define-menu 1.419 + 'yahtml-menu-map-listing 1.420 (nreverse 1.421 '((ul "Unordered" . 1.422 (lambda () (interactive) (yahtml-insert-begend nil "UL"))) 1.423 @@ -392,8 +519,8 @@ 1.424 (lambda () (interactive) (yahtml-insert-begend nil "DL"))) 1.425 ))) 1.426 (setq yahtml-menu-map-item (make-sparse-keymap "item")) 1.427 - (yahtml-define-menu 1.428 - yahtml-menu-map-item 1.429 + (YaTeX-define-menu 1.430 + 'yahtml-menu-map-item 1.431 (nreverse 1.432 '((li "Simple item" . 1.433 (lambda () (interactive) (yahtml-insert-single "li"))) 1.434 @@ -408,8 +535,8 @@ 1.435 (while keys 1.436 (define-key yahtml-mode-map (car keys) 'yahtml-fill-paragraph) 1.437 (setq keys (cdr keys)))) 1.438 - (yahtml-define-menu 1.439 - yahtml-menu-map 1.440 + (YaTeX-define-menu 1.441 + 'yahtml-menu-map 1.442 (nreverse 1.443 (list 1.444 (cons (list 'sect "Sectioning") 1.445 @@ -423,26 +550,15 @@ 1.446 (cons (list 'type "Typeface tags") 1.447 (cons "typeface" yahtml-menu-map-typeface)) 1.448 ))) 1.449 + (if (featurep 'xemacs) 1.450 + (add-hook 'yahtml-mode-hook 1.451 + '(lambda () 1.452 + (or (assoc "yahtml" current-menubar) 1.453 + (progn 1.454 + (set-buffer-menubar (copy-sequence current-menubar)) 1.455 + (add-submenu nil yahtml-menu-map)))))) 1.456 )) 1.457 1.458 -(defun yahtml-collect-url-history () 1.459 - "Collect urls from global history file." 1.460 - (interactive) 1.461 - (save-excursion 1.462 - (set-buffer 1.463 - (find-file-noselect (expand-file-name yahtml-url-history-file))) 1.464 - (goto-char (point-min)) 1.465 - (setq yahtml-urls) 1.466 - (message "Collecting global history...") 1.467 - (while (re-search-forward "^[A-Za-z]+:" nil t) 1.468 - (setq yahtml-urls 1.469 - (cons (list 1.470 - (buffer-substring 1.471 - (progn (beginning-of-line) (point)) 1.472 - (progn (skip-chars-forward "^ ") (point)))) 1.473 - yahtml-urls))) 1.474 - (message "Collecting global history...Done"))) 1.475 - 1.476 ;;; ----------- Completion ---------- 1.477 (defvar yahtml-last-begend "html") 1.478 (defun yahtml-insert-begend (&optional region env) 1.479 @@ -476,7 +592,10 @@ 1.480 (insert "\n") 1.481 (indent-to-column cc) 1.482 (insert (format "</%s>" cmd))) 1.483 - (yahtml-intelligent-newline nil)))) 1.484 + (if (string-match "^a\\|p$" cmd) ;aとp決め打ちってのが美しくない… 1.485 + (newline) 1.486 + (yahtml-intelligent-newline nil)) 1.487 + (yahtml-indent-line)))) 1.488 1.489 (defun yahtml-insert-begend-region () 1.490 "Call yahtml-insert-begend in the region mode." 1.491 @@ -491,10 +610,12 @@ 1.492 (let ((completion-ignore-case t)) 1.493 (setq form 1.494 (YaTeX-cplread-with-learning 1.495 - "Form: " 1.496 + (format "Form(default %s): " yahtml-last-form) 1.497 'yahtml-form-table 'yahtml-user-form-table 1.498 'yahtml-tmp-form-table)))) 1.499 (let ((p (point)) q) 1.500 + (if (string= form "") (setq form yahtml-last-form)) 1.501 + (setq yahtml-last-form form) 1.502 (if yahtml-prefer-upcases (setq form (upcase form))) 1.503 (insert (format "<%s%s>" form (yahtml-addin form))) 1.504 ;;(indent-relative-maybe) 1.505 @@ -509,7 +630,7 @@ 1.506 (if (and (intern-soft addin) (fboundp (intern-soft addin)) 1.507 (stringp (setq s (funcall (intern addin)))) 1.508 (string< "" s)) 1.509 - (concat " " s) 1.510 + (if (eq (aref s 0) ? ) s (concat " " s)) 1.511 ""))) 1.512 1.513 1.514 @@ -528,9 +649,10 @@ 1.515 (setq bound (match-end 0)) 1.516 (search-forward ">" nil t) 1.517 (if (and (re-search-backward "\\(name\\|id\\)=" bound t) 1.518 - (goto-char (match-end 0)) 1.519 - (skip-chars-forward " \t\n") 1.520 - (looking-at "\"?#?\\([^\">]+\\)\"?\\b")) 1.521 + (progn 1.522 + (goto-char (match-end 0)) 1.523 + (skip-chars-forward " \t\n") 1.524 + (looking-at "\"?#?\\([^\">]+\\)\"?\\b"))) 1.525 (setq list (cons 1.526 (list (concat "#" (YaTeX-match-string 1))) 1.527 list)))) 1.528 @@ -548,7 +670,7 @@ 1.529 (defun yahtml-complete-url () 1.530 "Complete external URL from history or local file name." 1.531 (interactive) 1.532 - (let (initial i2 cmpl path dir file listfunc beg labels (p (point))) 1.533 + (let ((p (point)) initial i2 cmpl path dir file listfunc beg labels) 1.534 (setq initial (buffer-string)) 1.535 (cond 1.536 ((string-match "^http:" initial) 1.537 @@ -571,7 +693,7 @@ 1.538 beg (+ (point-min) beg))) 1.539 (t 1.540 (setq path (if (string-match "^/" initial) 1.541 - (yahtml-url-to-path initial) 1.542 + (or (yahtml-url-to-path initial) initial) 1.543 initial)) 1.544 (setq dir (or (file-name-directory path) ".") 1.545 file (file-name-nondirectory path) 1.546 @@ -602,20 +724,23 @@ 1.547 1.548 (defun yahtml:a () 1.549 "Add-in function for <a>" 1.550 - (let ((l yahtml-prefer-upcases)) 1.551 - (or yahtml-urls (yahtml-collect-url-history)) 1.552 - (setq yahtml-completing-buffer (current-buffer)) 1.553 -; (concat "href=\"" 1.554 -; (completing-read "href: " yahtml-urls) 1.555 -; "\"") 1.556 - (message "(H)ref (N)ame?") 1.557 - (cond 1.558 - ((string-match "[nN]" (char-to-string (read-char))) 1.559 - (concat (if l "NAME" "name") "=\"" (read-string "name: ") "\"")) 1.560 - (t 1.561 - (concat (if l "HREF" "href") "=\"" 1.562 - (read-from-minibuffer "href: " "" yahtml-url-completion-map) 1.563 - "\""))))) 1.564 + (let ((href "")) 1.565 + (setq yahtml-completing-buffer (current-buffer) 1.566 + href (read-from-minibuffer "href: " "" yahtml-url-completion-map) 1.567 + ;; yahtml-urls-local is buffer-local, so we must put 1.568 + ;; that into yahtml-urls here 1.569 + yahtml-urls (append yahtml-urls-private yahtml-urls-local)) 1.570 + (prog1 1.571 + (concat (yahtml-make-optional-argument 1.572 + "href" href) 1.573 + (yahtml-make-optional-argument 1.574 + "name" (read-string "name: "))) 1.575 + (if (and (string-match "^http://" href) 1.576 + (null (assoc href yahtml-urls))) 1.577 + (YaTeX-update-table 1.578 + (list href) 1.579 + 'yahtml-urls-private 'yahtml-urls-private 'yahtml-urls-local)) 1.580 + ))) 1.581 1.582 (defvar yahtml-parameters-completion-alist 1.583 '(("align" ("top") ("middle") ("bottom") ("left") ("right") ("center")) 1.584 @@ -635,19 +760,37 @@ 1.585 (t 1.586 (read-string prompt))))) 1.587 1.588 - 1.589 +(defun yahtml-make-optional-argument (opt arg) 1.590 + "Make optional argument string." 1.591 + (if (string= "" arg) 1.592 + "" 1.593 + (concat " " (if yahtml-prefer-upcases (upcase opt) (downcase opt)) 1.594 + "=\"" arg "\""))) 1.595 + 1.596 +(defun yahtml:body () 1.597 + "Add-in function for <body>" 1.598 + (let ((b (read-string "bgcolor=")) 1.599 + (x (read-string "text color=")) 1.600 + (l (read-string "link color=")) 1.601 + (v (read-string "vlink color="))) 1.602 + (concat 1.603 + (yahtml-make-optional-argument "bgcolor" b) 1.604 + (yahtml-make-optional-argument "text" x) 1.605 + (yahtml-make-optional-argument "link" l) 1.606 + (yahtml-make-optional-argument "vlink" v)))) 1.607 + 1.608 + 1.609 (defun yahtml:img () 1.610 "Add-in function for <img>" 1.611 - (or yahtml-urls (yahtml-collect-url-history)) 1.612 (let ((src (yahtml-read-parameter "src")) 1.613 (alg (yahtml-read-parameter "align")) 1.614 (alt (yahtml-read-parameter "alt")) 1.615 + (brd (read-string "border=")) 1.616 (l yahtml-prefer-upcases)) 1.617 (concat (if l "SRC" "src") "=\"" src "\"" 1.618 - (if (string< "" alg) 1.619 - (concat " " (if l "ALIGN" "align") "=\"" alg "\"")) 1.620 - (if (string< "" alt) 1.621 - (concat " " (if l "ALT" "alt") "=\"" alt "\""))))) 1.622 + (yahtml-make-optional-argument "align" alg) 1.623 + (yahtml-make-optional-argument "alt" alt) 1.624 + (yahtml-make-optional-argument "border" brd)))) 1.625 1.626 (defun yahtml:form () 1.627 "Add-in function `form' input format" 1.628 @@ -675,10 +818,8 @@ 1.629 1.630 (defun yahtml:p () 1.631 (let ((alg (yahtml-read-parameter "align"))) 1.632 - (if (string< "" alg) 1.633 - (setq alg (concat "align=" alg) 1.634 - alg (if yahtml-prefer-upcases (upcase alg) (downcase alg))) 1.635 - ""))) 1.636 + (yahtml-make-optional-argument "align" alg) 1.637 +)) 1.638 1.639 (defvar yahtml-input-types 1.640 '(("text") ("password") ("checkbox") ("radio") ("submit") 1.641 @@ -697,14 +838,10 @@ 1.642 maxlength (read-string "maxlength: "))) 1.643 (concat 1.644 (if l "NAME" "name") "=\"" name "\"" 1.645 - (if (string< "" type) 1.646 - (concat " " (if l "TYPE" "type") "=\"" type "\"")) 1.647 - (if (string< "" value) 1.648 - (concat " " (if l "VALUE" "value") "=\"" value "\"")) 1.649 - (if (string< "" size) 1.650 - (concat " " (if l "SIZE" "size") "=\"" size "\"")) 1.651 - (if (string< "" maxlength) 1.652 - (concat " " (if l "MAXLENGTH" "maxlength") "=\"" maxlength "\"")) 1.653 + (yahtml-make-optional-argument "type" type) 1.654 + (yahtml-make-optional-argument "value" value) 1.655 + (yahtml-make-optional-argument "size" size) 1.656 + (yahtml-make-optional-argument "maxlength" maxlength) 1.657 ))) 1.658 1.659 (defun yahtml:textarea () 1.660 @@ -717,11 +854,16 @@ 1.661 (concat 1.662 (concat (if yahtml-prefer-upcases "NAME=" "name=") 1.663 "\"" name "\"") 1.664 - (if (string< "" cols) 1.665 - (concat " " (if yahtml-prefer-upcases "COLS" "cols") "=" cols)) 1.666 - (if (string< "" rows) 1.667 - (concat " " (if yahtml-prefer-upcases "ROWS" "rows") "=" rows))))) 1.668 + (yahtml-make-optional-argument "cols" cols) 1.669 + (yahtml-make-optional-argument "rows" rows)))) 1.670 1.671 +(defun yahtml:table () 1.672 + "Add-in function for `table'" 1.673 + (yahtml-make-optional-argument "border" (read-string "border="))) 1.674 + 1.675 +(defun yahtml:font () 1.676 + "Add-in function for `font'" 1.677 + (yahtml-make-optional-argument "color" (read-string "color="))) 1.678 1.679 ;;; ---------- Simple tag ---------- 1.680 (defun yahtml-insert-tag (region-mode &optional tag) 1.681 @@ -731,7 +873,7 @@ 1.682 (let ((completion-ignore-case t)) 1.683 (setq tag 1.684 (YaTeX-cplread-with-learning 1.685 - (format "Tag %s(default %s): " 1.686 + (format "Tag %s(default %s): " 1.687 (if region-mode "region: " "") yahtml-last-typeface-cmd) 1.688 'yahtml-typeface-table 'yahtml-user-typeface-table 1.689 'yahtml-tmp-typeface-table)))) 1.690 @@ -755,6 +897,7 @@ 1.691 (interactive) 1.692 (yahtml-insert-tag t tag)) 1.693 1.694 + 1.695 (defun yahtml-insert-single (cmd) 1.696 "Insert <CMD>." 1.697 (interactive 1.698 @@ -773,6 +916,14 @@ 1.699 yahtml-last-single-cmd)) 1.700 (insert (format "<%s>" cmd))) 1.701 1.702 +(defun yahtml-insert-p (&optional arg) 1.703 + "Convenient function to insert <p></p>" 1.704 + (interactive "P") 1.705 + (if arg (yahtml-insert-tag nil "p") 1.706 + (insert "<p>") 1.707 + (save-excursion 1.708 + (insert "</p>")))) 1.709 + 1.710 ;;; ---------- Jump ---------- 1.711 (defun yahtml-on-href-p () 1.712 "Check if point is on href clause." 1.713 @@ -785,8 +936,9 @@ 1.714 (goto-char (get 'YaTeX-inner-environment 'point)) 1.715 (search-forward "href" e t) 1.716 (search-forward "=" e t) 1.717 - (skip-chars-forward " \t\n") 1.718 - (looking-at "\"?\\([^\"> \t\n]+\\)\"?") 1.719 + (progn 1.720 + (skip-chars-forward " \t\n") 1.721 + (looking-at "\"?\\([^\"> \t\n]+\\)\"?")) 1.722 (< p (match-end 0)) 1.723 (YaTeX-match-string 1) 1.724 )))) 1.725 @@ -816,6 +968,16 @@ 1.726 "Call WWW Browser to see HREF." 1.727 (let ((pb "* WWW Browser *") (cb (current-buffer))) 1.728 (cond 1.729 + ((string-match "^start\\>" yahtml-www-browser) 1.730 + (if (get-buffer pb) 1.731 + (progn (set-buffer pb) (erase-buffer) (set-buffer cb))) 1.732 + (put 'yahtml-netscape-sentinel 'url href) 1.733 + (set-process-sentinel 1.734 + (setq yahtml-browser-process 1.735 + (start-process 1.736 + "browser" pb shell-file-name yahtml-shell-command-option 1.737 + (format "%s \"%s\"" yahtml-www-browser href))) 1.738 + 'yahtml-netscape-sentinel)) 1.739 ((and (string-match "[Nn]etscape" yahtml-www-browser) 1.740 (not (eq system-type 'windows-nt))) 1.741 (if (get-buffer pb) 1.742 @@ -843,7 +1005,7 @@ 1.743 1.744 (defun yahtml-goto-corresponding-href (&optional other) 1.745 "Go to corresponding name." 1.746 - (let ((href (yahtml-on-href-p)) file name) 1.747 + (let ((href (yahtml-on-href-p)) file name (parent buffer-file-name)) 1.748 (if href 1.749 (cond 1.750 ((string-match "^\\(ht\\|f\\)tp:" href) 1.751 @@ -858,7 +1020,8 @@ 1.752 (if (string-match "^/" file) 1.753 (setq file (yahtml-url-to-path file))) 1.754 (if other (YaTeX-switch-to-buffer-other-window file) 1.755 - (YaTeX-switch-to-buffer file)))) 1.756 + (YaTeX-switch-to-buffer file)) 1.757 + (or YaTeX-parent-file (setq YaTeX-parent-file parent)))) 1.758 (if name 1.759 (progn (set-mark-command nil) (yahtml-jump-to-name name))) 1.760 t))))) 1.761 @@ -954,6 +1117,7 @@ 1.762 ((yahtml-goto-corresponding-href other)) 1.763 ((yahtml-goto-corresponding-img)) 1.764 ((yahtml-goto-corresponding-begend)) 1.765 + (t (message "I don't know where to go.")) 1.766 )) 1.767 1.768 (defun yahtml-goto-corresponding-*-other-window () 1.769 @@ -961,27 +1125,54 @@ 1.770 (interactive) 1.771 (yahtml-goto-corresponding-* t)) 1.772 1.773 +(defun yahtml-visit-main () 1.774 + "Go to parent file from where you visit current file." 1.775 + (interactive) 1.776 + (if YaTeX-parent-file (YaTeX-switch-to-buffer YaTeX-parent-file))) 1.777 + 1.778 ;;; ---------- killing ---------- 1.779 (defun yahtml-kill-begend (&optional whole) 1.780 - (let ((tag (yahtml-on-begend-p)) (p (make-marker)) (q (make-marker))) 1.781 + (let ((tag (yahtml-on-begend-p)) p q r) 1.782 (if tag 1.783 - (progn 1.784 + (save-excursion 1.785 (or (looking-at "<") 1.786 (progn (skip-chars-backward "^<") (forward-char -1))) 1.787 - (set-marker p (point)) 1.788 + (setq p (point)) 1.789 (yahtml-goto-corresponding-begend) 1.790 (or (looking-at "<") 1.791 (progn (skip-chars-backward "^<") (forward-char -1))) 1.792 - (delete-region (point) (progn (forward-list 1) (point))) 1.793 - (set-marker q (point)) 1.794 - (beginning-of-line) 1.795 - (if (looking-at "^\\s *$") 1.796 - (delete-region (point) (progn (forward-line 1) (point)))) 1.797 + (if (< (point) p) ;if on the opening tag 1.798 + (progn (setq q p p (point)) 1.799 + (goto-char q)) 1.800 + (setq q (point))) ;now q has end-line's (point) 1.801 + (if (not whole) 1.802 + (kill-region 1.803 + (progn (skip-chars-backward " \t") (if (bolp) (point) q)) 1.804 + (progn (forward-list 1) 1.805 + (setq r (point)) 1.806 + (skip-chars-forward " \t") 1.807 + (if (and (eolp) (not (eobp))) (1+ (point)) r)))) 1.808 (goto-char p) 1.809 - (delete-region (point) (progn (forward-list 1) (point))) 1.810 - (if (looking-at "^\\s *$") 1.811 - (delete-region (point) (progn (forward-line 1) (point)))) 1.812 - (if whole (delete-region p q)) 1.813 + (skip-chars-backward " \t") 1.814 + (if (not whole) 1.815 + (progn 1.816 + (kill-append 1.817 + (buffer-substring 1.818 + (setq p (if (bolp) (point) p)) 1.819 + (setq q (progn 1.820 + (forward-list 1) 1.821 + (setq r (point)) 1.822 + (skip-chars-forward " \t") 1.823 + (if (and (eolp) (not (eobp))) (1+ (point)) r)))) 1.824 + t) 1.825 + (delete-region p q)) 1.826 + (kill-region 1.827 + (if (bolp) (point) p) 1.828 + (progn (goto-char q) 1.829 + (forward-list 1) 1.830 + (setq r (point)) 1.831 + (skip-chars-forward " \t") 1.832 + (if (and (eolp) (not (eobp))) (1+ (point)) r)))) 1.833 tag)))) 1.834 1.835 (defun yahtml-kill-* (whole) 1.836 @@ -1024,20 +1215,25 @@ 1.837 (save-excursion 1.838 (and 1.839 (re-search-backward "<a\\b" nil t) 1.840 - (goto-char (match-end 0)) 1.841 - (skip-chars-forward " \t\n") 1.842 - (setq b1 (point)) 1.843 - (search-forward ">" nil t) 1.844 + (progn 1.845 + (goto-char (match-end 0)) 1.846 + (skip-chars-forward " \t\n") 1.847 + (setq b1 (point)) 1.848 + (search-forward ">" nil t)) 1.849 (setq e1 (match-beginning 0)) 1.850 (goto-char b1) 1.851 (re-search-forward "href\\s *=" e1 t) 1.852 (>= p (point)) 1.853 - (goto-char (match-end 0)) 1.854 - (skip-chars-forward " \t\n") 1.855 - (looking-at "\"?\\([^\"> \t\n]+\\)\"?") 1.856 + (progn 1.857 + (goto-char (match-end 0)) 1.858 + (skip-chars-forward " \t\n") 1.859 + (looking-at "\"?\\([^\"> \t\n]+\\)\"?")) 1.860 (< p (match-end 0))))) 1.861 (setq b1 (match-beginning 1) e1 (match-end 1) 1.862 yahtml-completing-buffer (current-buffer) 1.863 + ;; yahtml-urls-local is buffer-local, so we must put 1.864 + ;; that into yahtml-urls here 1.865 + yahtml-urls (append yahtml-urls-private yahtml-urls-local) 1.866 href (read-from-minibuffer 1.867 "Change href to: " "" yahtml-url-completion-map)) 1.868 (if (string< "" href) 1.869 @@ -1123,19 +1319,35 @@ 1.870 )) 1.871 1.872 ;;; ---------- commenting ---------- 1.873 -(defun yahtml-comment-region (beg end) 1.874 - (interactive "r") 1.875 - (comment-region beg end nil)) 1.876 +(defun yahtml-comment-region (&optional uncom) 1.877 + "Comment out region or environment." 1.878 + (interactive) 1.879 + (let (e beg p) 1.880 + (cond 1.881 + ((setq e (yahtml-on-begend-p)) 1.882 + (save-excursion 1.883 + (setq p (point)) 1.884 + (if (string-match "^/" e) 1.885 + (setq beg (progn (forward-line 1) (point))) 1.886 + (setq beg (progn (beginning-of-line) (point)))) 1.887 + (goto-char p) 1.888 + (yahtml-goto-corresponding-begend) 1.889 + (if (string-match "^/" e) 1.890 + (beginning-of-line) 1.891 + (forward-line 1)) 1.892 + (comment-region beg (point) (if uncom (list 4))))) 1.893 + (t (comment-region (region-beginning) (region-end) 1.894 + (if uncom (list 4))))))) 1.895 1.896 -(defun yahtml-uncomment-region (beg end) 1.897 - (interactive "r") 1.898 - (comment-region beg end '(4))) 1.899 +(defun yahtml-uncomment-region () 1.900 + (interactive) 1.901 + (yahtml-comment-region t)) 1.902 1.903 1.904 1.905 (defun yahtml-inner-environment-but (exclude &optional quick) 1.906 "Return the inner environment but matches with EXCLUDE tag." 1.907 - (let (e) 1.908 + (let (e (case-fold-search t)) 1.909 (save-excursion 1.910 (while (and (setq e (YaTeX-inner-environment quick)) 1.911 (string-match exclude e)) 1.912 @@ -1192,8 +1404,11 @@ 1.913 (fill-region-as-paragraph 1.914 (progn (re-search-backward paragraph-start nil t) 1.915 (or (save-excursion 1.916 - (goto-char (match-end 0)) 1.917 - (skip-chars-forward " \t>") 1.918 + (goto-char (match-beginning 0)) 1.919 + (if (looking-at "<") 1.920 + (forward-list) 1.921 + (goto-char (match-end 0)) 1.922 + (skip-chars-forward " \t>")) 1.923 (if (looking-at "[ \t]*$") 1.924 (progn (forward-line 1) (point)))) 1.925 (point))) 1.926 @@ -1213,8 +1428,32 @@ 1.927 ;;; ---------- indentation ---------- 1.928 ;;; 1.929 (defun yahtml-indent-line () 1.930 + "Indent a line (faster wrapper)" 1.931 (interactive) 1.932 - (let ((envs "[uod]l\\|table\\|t[rhd]\\|select\\|blockquote") 1.933 + (let (indent) 1.934 + (if (and (save-excursion 1.935 + (beginning-of-line) (skip-chars-forward "\t ") 1.936 + (not (looking-at "<"))) 1.937 + (save-excursion 1.938 + (forward-line -1) 1.939 + (while (and (not (bobp)) (looking-at "^\\s *$")) 1.940 + (forward-line -1)) 1.941 + (skip-chars-forward "\t ") 1.942 + (setq indent (current-column)) 1.943 + (not (looking-at "<")))) 1.944 + (progn 1.945 + (save-excursion 1.946 + (beginning-of-line) 1.947 + (skip-chars-forward " \t") 1.948 + (or (= (current-column) indent) 1.949 + (YaTeX-reindent indent))) 1.950 + (and (bolp) (skip-chars-forward " \t"))) 1.951 + (yahtml-indent-line-real)))) 1.952 + 1.953 +(defun yahtml-indent-line-real () 1.954 + (interactive) 1.955 + (let ((envs "[uod]l\\|table\\|[ht][rhd0-6]\\|select\\|blockquote\\|center\\|menu\\|dir") 1.956 + (itemizing-envs "^\\([uod]l\\|menu\\|dir\\)$") 1.957 (itms "<\\(dt\\|dd\\|li\\|t[rdh]\\|option\\)\\b") 1.958 inenv p col peol (case-fold-search t)) 1.959 (save-excursion 1.960 @@ -1223,38 +1462,43 @@ 1.961 "html") 1.962 col (get 'YaTeX-inner-environment 'indent) 1.963 p (get 'YaTeX-inner-environment 'point) 1.964 - op)) 1.965 + op nil)) 1.966 (save-excursion 1.967 (cond 1.968 ((string-match envs inenv) 1.969 (save-excursion 1.970 (beginning-of-line) 1.971 (skip-chars-forward " \t") 1.972 - (cond 1.973 + (cond ;lookup current line's tag 1.974 ((looking-at (concat "</\\(" envs "\\)>")) 1.975 (YaTeX-reindent col)) 1.976 - ((or (looking-at itms) 1.977 - (and yahtml-hate-too-deep-indentation 1.978 - (looking-at (concat "<" envs)))) 1.979 + ((looking-at itms) 1.980 (YaTeX-reindent (+ col yahtml-environment-indent))) 1.981 + ((and yahtml-hate-too-deep-indentation 1.982 + (looking-at (concat "<\\(" envs "\\)"))) 1.983 + (YaTeX-reindent (+ col (* 2 yahtml-environment-indent)))) 1.984 ((and (< p (point)) 1.985 + (string-match itemizing-envs inenv) 1.986 (save-excursion 1.987 (and 1.988 ;;(re-search-backward itms p t) 1.989 (setq op (point)) 1.990 (goto-char p) 1.991 (re-search-forward itms op t) 1.992 - ;(goto-char (match-end 0)) 1.993 - (skip-chars-forward "^>") 1.994 - (skip-chars-forward ">") 1.995 - (skip-chars-forward " \t") 1.996 - (setq col (current-column))))) 1.997 + (progn 1.998 + (skip-chars-forward "^>") 1.999 + (skip-chars-forward ">") 1.1000 + (skip-chars-forward " \t") 1.1001 + (setq col (if (looking-at "$") 1.1002 + (+ col yahtml-environment-indent) 1.1003 + (current-column))))))) 1.1004 (YaTeX-reindent col)) 1.1005 (t 1.1006 (YaTeX-reindent (+ col yahtml-environment-indent))))))) 1.1007 (and (bolp) (skip-chars-forward " \t")) 1.1008 (if (and (setq inenv (yahtml-on-begend-p)) 1.1009 - (string-match (concat "^\\(" envs "\\)") inenv)) 1.1010 + (string-match 1.1011 + (concat "^\\<\\(" yahtml-struct-name-regexp "\\)") inenv)) 1.1012 (save-excursion 1.1013 (setq peol (point-end-of-line)) 1.1014 (or (= (char-after (point)) ?<) 1.1015 @@ -1312,6 +1556,7 @@ 1.1016 1.1017 (defun yahtml-lint-buffer (buf) 1.1018 "Call lint on buffer BUF." 1.1019 + (require 'yatexprc) 1.1020 (interactive "bCall lint on buffer: ") 1.1021 (setq buf (get-buffer buf)) 1.1022 (YaTeX-save-buffers) 1.1023 @@ -1329,7 +1574,7 @@ 1.1024 (setq file (expand-file-name file))) 1.1025 (if (string-match "^[A-Za-z]:/" file) 1.1026 (progn 1.1027 - ;; (aset file 1 ?|) ;$B$3$l$OMW$i$J$$$i$7$$!D(B 1.1028 + ;; (aset file 1 ?|) ;これは要らないらしい… 1.1029 (setq file (concat "///" file)))) 1.1030 (while list 1.1031 (if (string-match (concat "^" (regexp-quote (car (car list)))) file) 1.1032 @@ -1356,15 +1601,16 @@ 1.1033 (if (string-match "\\(http://[^/]*\\)/" url) 1.1034 (setq docroot (substring url (match-end 1))) 1.1035 (setq docroot url)) 1.1036 - (if (string-match (concat "^" (regexp-quote docroot)) file) 1.1037 - (setq realpath 1.1038 - (expand-file-name 1.1039 - (substring 1.1040 - file 1.1041 - (if (= (aref file (1- (match-end 0))) ?/) 1.1042 - (match-end 0) ; "/foo" 1.1043 - (min (1+ (match-end 0)) (length file)))) ; "/~foo" 1.1044 - (car (car list))))) 1.1045 + (cond 1.1046 + ((string-match (concat "^" (regexp-quote docroot)) file) 1.1047 + (setq realpath 1.1048 + (expand-file-name 1.1049 + (substring 1.1050 + file 1.1051 + (if (= (aref file (1- (match-end 0))) ?/) 1.1052 + (match-end 0) ; "/foo" 1.1053 + (min (1+ (match-end 0)) (length file)))) ; "/~foo" 1.1054 + (car (car list)))))) 1.1055 (if realpath 1.1056 (progn (setq list nil) 1.1057 (if (and dirsufp (not (string-match "/$" realpath))) 1.1058 @@ -1406,15 +1652,22 @@ 1.1059 (interactive "P") 1.1060 (let (env func) 1.1061 (end-of-line) 1.1062 - (setq env (downcase (or (YaTeX-inner-environment) "html"))) 1.1063 + (setq env (downcase (or (yahtml-inner-environment-but "^\\(a\\|p\\)\\b" t) 1.1064 + "html"))) 1.1065 (setq func (intern-soft (concat "yahtml-intelligent-newline-" env))) 1.1066 (newline) 1.1067 (if (and env func (fboundp func)) 1.1068 - (funcall func)))) 1.1069 + ;; if intelligent line function is defined, call that 1.1070 + (funcall func) 1.1071 + ;; else do the default action 1.1072 + (if (string-match yahtml-p-prefered-env-regexp env) 1.1073 + (yahtml-insert-p))))) 1.1074 1.1075 +(defvar yahtml-faithful-to-htmllint nil) 1.1076 (defun yahtml-intelligent-newline-ul () 1.1077 (interactive) 1.1078 - (insert (if yahtml-prefer-upcases "<LI> " "<li> ")) 1.1079 + (yahtml-insert-single "li") 1.1080 + (or yahtml-faithful-to-htmllint (insert " ")) 1.1081 (yahtml-indent-line)) 1.1082 1.1083 (fset 'yahtml-intelligent-newline-ol 'yahtml-intelligent-newline-ul) 1.1084 @@ -1427,13 +1680,19 @@ 1.1085 (get 'YaTeX-inner-environment 'point) t)) 1.1086 (cond 1.1087 ((match-beginning 2) 1.1088 - (insert (if yahtml-prefer-upcases "<DD> " "<dd> ")) 1.1089 + (yahtml-insert-single "dd") 1.1090 + (or yahtml-faithful-to-htmllint (insert " ")) 1.1091 (setq yahtml-last-single-cmd "dt")) 1.1092 ((match-beginning 3) 1.1093 - (insert (if yahtml-prefer-upcases "<DT> " "<dt> ")) 1.1094 + (yahtml-insert-single "dt") 1.1095 + (or yahtml-faithful-to-htmllint (insert " ")) 1.1096 (setq yahtml-last-single-cmd "dd"))) 1.1097 - (insert (if yahtml-prefer-upcases "<DT> " "<dt> "))) 1.1098 - (yahtml-indent-line))) 1.1099 + (insert (if yahtml-prefer-upcases "<DT> " "<dt> ")) 1.1100 + (setq yahtml-last-single-cmd "dd")) 1.1101 + (yahtml-indent-line) 1.1102 + (and (string-match yahtml-p-prefered-env-regexp "dl") 1.1103 + (string-equal yahtml-last-single-cmd "dt") 1.1104 + (yahtml-insert-p nil)))) 1.1105 1.1106 (defun yahtml-intelligent-newline-select () 1.1107 (interactive) 1.1108 @@ -1478,17 +1737,18 @@ 1.1109 (or (get-buffer yahtml-lint-buffer) 1.1110 (error "No lint program ran.")) 1.1111 (YaTeX-showup-buffer yahtml-lint-buffer nil t) 1.1112 - (yahtml-jump-to-error-line)) 1.1113 + (yahtml-jump-to-error-line t)) 1.1114 1.1115 -(defun yahtml-jump-to-error-line () 1.1116 - (interactive) 1.1117 +(defun yahtml-jump-to-error-line (&optional sit) 1.1118 + (interactive "P") 1.1119 (let ((p (point)) (e (point-end-of-line))) 1.1120 (end-of-line) 1.1121 (if (re-search-backward yahtml-error-line-regexp nil t) 1.1122 (let ((f (YaTeX-match-string 1)) 1.1123 (l (string-to-int (YaTeX-match-string 2)))) 1.1124 + (if sit (sit-for 1)) 1.1125 (forward-line -1) 1.1126 - (YaTeX-showup-buffer f nil t) 1.1127 + (YaTeX-showup-buffer (YaTeX-switch-to-buffer f t) nil t) 1.1128 (goto-line l)) 1.1129 (message "No line number usage")))) 1.1130 1.1131 @@ -1513,8 +1773,7 @@ 1.1132 ("</?[uod]l>" 0 decl) 1.1133 ("<\\(di\\|dt\\|li\\|dd\\)>" 0 label) 1.1134 ("<a\\s +href" "</a>" crossref) 1.1135 - ("</?\\sw+>" 0 decl) 1.1136 - ("<form" "</form" form) 1.1137 + (yahtml-hilit-region-tag-itself "</?\\sw+\\>" decl) 1.1138 )) 1.1139 1.1140 (defun yahtml-hilit-region-tag (tag) 1.1141 @@ -1526,13 +1785,19 @@ 1.1142 (progn (re-search-forward (concat "</" tag ">") nil t) 1.1143 (match-beginning 0)))))) 1.1144 1.1145 +(defun yahtml-hilit-region-tag-itself (ptn) 1.1146 + "Return list of start/end point of <tag options...> itself." 1.1147 + (if (re-search-forward ptn nil t) 1.1148 + (let ((m0 (match-beginning 0))) 1.1149 + (skip-chars-forward "^>") 1.1150 + (cons m0 (1+ (point) ))))) 1.1151 + 1.1152 ;(setq hilit-patterns-alist (delq (assq 'yahtml-mode hilit-patterns-alist) hilit-patterns-alist)) 1.1153 -(cond 1.1154 - ((and (featurep 'hilit19) (featurep 'yatex19)) 1.1155 - (or (assq 'yahtml-mode hilit-patterns-alist) 1.1156 - (setq hilit-patterns-alist 1.1157 - (cons (cons 'yahtml-mode yahtml-hilit-patterns-alist) 1.1158 - hilit-patterns-alist))))) 1.1159 +(and (featurep 'hilit19) 1.1160 + (or (assq 'yahtml-mode hilit-patterns-alist) 1.1161 + (setq hilit-patterns-alist 1.1162 + (cons (cons 'yahtml-mode yahtml-hilit-patterns-alist) 1.1163 + hilit-patterns-alist)))) 1.1164 1.1165 (provide 'yahtml) 1.1166