yuuji@13: ;;; -*- Emacs-Lisp -*-
yuuji@121: ;;; (c) 1994-2010 by HIROSE Yuuji [yuuji(@)yatex.org]
yuuji@138: ;;; Last modified Wed Jul 7 22:12:55 2010 on firestorm
yuuji@121: ;;; $Id$
yuuji@54:
yuuji@121: (defconst yahtml-revision-number "1.74.2"
yuuji@72: "Revision number of running yahtml.el")
yuuji@72:
yuuji@58: ;;;[Installation]
yuuji@58: ;;;
yuuji@58: ;;; First, you have to install YaTeX and make sure it works fine. Then
yuuji@58: ;;; put these expressions into your ~/.emacs
yuuji@58: ;;;
yuuji@58: ;;; (setq auto-mode-alist
yuuji@58: ;;; (cons (cons "\\.html$" 'yahtml-mode) auto-mode-alist))
yuuji@58: ;;; (autoload 'yahtml-mode "yahtml" "Yet Another HTML mode" t)
yuuji@115: ;;; (setq yahtml-www-browser "firefox")
yuuji@115: ;;; ;Write your favorite browser. But firefox is advantageous.
yuuji@58: ;;; (setq yahtml-path-url-alist
yuuji@58: ;;; '(("/home/yuuji/public_html" . "http://www.mynet/~yuuji")
yuuji@58: ;;; ("/home/staff/yuuji/html" . "http://www.othernet/~yuuji")))
yuuji@58: ;;; ;Write correspondence alist from ABSOLUTE unix path name to URL path.
yuuji@58: ;;;
yuuji@64: ;;;[インストール方法]
yuuji@64: ;;;
yuuji@64: ;;; yahtml.el, yatexlib.el, yatexprc.el を load-path の通ったディレクト
yuuji@64: ;;; リにインストールしてください。その後、以下を参考に ~/.emacs に設定を
yuuji@64: ;;; 追加して下さい。
yuuji@64: ;;;
yuuji@64: ;;; (setq auto-mode-alist
yuuji@64: ;;; (cons (cons "\\.html$" 'yahtml-mode) auto-mode-alist))
yuuji@64: ;;; (autoload 'yahtml-mode "yahtml" "Yet Another HTML mode" t)
yuuji@115: ;;; (setq yahtml-www-browser "firefox")
yuuji@115: ;;; ;お気に入りのブラウザを書いて下さい。firefoxが便利です。
yuuji@64: ;;; (setq yahtml-path-url-alist
yuuji@64: ;;; '(("/home/yuuji/public_html" . "http://www.mynet/~yuuji")
yuuji@64: ;;; ("/home/staff/yuuji/html" . "http://www.othernet/~yuuji")))
yuuji@64: ;;; ;UNIXの絶対パスと対応するURLのリストを書いて下さい。
yuuji@64: ;;;
yuuji@77: ;;; HTMLファイル漢字コードが正しく判別されるようにホームディレクトリに
yuuji@77: ;;; .htaccess ファイルを作り以下のどれか1行を選んで書いて下さい。
yuuji@77: ;;;
yuuji@77: ;;; AddType "text/html; charset=Shift_JIS" .html (SJISの場合)
yuuji@77: ;;; AddType "text/html; charset=iso2022-jp" .html (JISの場合)
yuuji@77: ;;; AddType "text/html; charset=EUC-JP" .html (EUCの場合)
yuuji@102: ;;; AddType "text/html; charset=utf-8" .html (UTF-8の場合)
yuuji@77: ;;;
yuuji@77: ;;; .htaccess が作れない場合は
yuuji@77: ;;; (setq yahtml-kanji-code 2)
yuuji@102: ;;; ;HTMLファイルの漢字コードを変更する場合は
yuuji@102: ;;; ;1=SJIS、2=JIS、3=EUC 4=UTF-8
yuuji@77: ;;; ;で設定して下さい。デフォルトは 2 です。
yuuji@77: ;;;
yuuji@77: ;;; を適切に書き換えて ~/.emacs に足して下さい。
yuuji@77: ;;;
yuuji@54: ;;;[Commentary]
yuuji@13: ;;;
yuuji@54: ;;; It is assumed you are already familiar with YaTeX. The following
yuuji@54: ;;; completing featureas are available: ([prefix] means `C-c' by default)
yuuji@54: ;;;
yuuji@54: ;;; * [prefix] b X Complete environments such as `H1' which
yuuji@57: ;;; normally requires closing tag `
yuuji@57: ;;; ... is also classified into
yuuji@57: ;;; this group
yuuji@59: ;;; When input `href=...', you can complete file
yuuji@59: ;;; name or label(href="#foo") by typing TAB.
yuuji@54: ;;; * [prefix] l Complete typeface-changing commands such as
yuuji@54: ;;; ` ... ' or ` ... '
yuuji@60: ;;; This completion can be used to make in-line
yuuji@60: ;;; tags which is normally completed with [prefix] b.
yuuji@64: ;;; * [prefix] s Complete declarative notations such as
yuuji@64: ;;; ` '
yuuji@64: ;;; ` '
yuuji@57: ;;; * [prefix] m Complete single commands such as
yuuji@58: ;;; ` ' or `
or ...'
yuuji@64: ;;; * [prefix] p Insert
on the point
yuuji@59: ;;; * M-RET Intelligent newline; if current TAG is one of
yuuji@59: ;;; ul, ol, or dl. insert newline and or
yuuji@59: ;;; or suitable for current condition.
yuuji@54: ;;; * menu-bar yahtml Complete all by selecting a menu item (Though I
yuuji@54: ;;; hate menu, this is most useful)
yuuji@58: ;;; * [prefix] g Goto corresponding Tag or HREF such as
yuuji@59: ;;; <-> or href="xxx".
yuuji@59: ;;; Or invoke image viewer if point is on .
yuuji@58: ;;; * [prefix] k Kill html tags on the point. If you provide
yuuji@58: ;;; universal-argument, kill surrounded contents too.
yuuji@58: ;;; * [prefix] c Change html tags on the point.
yuuji@59: ;;; When typeing [prefix] c on `href="xxx"', you can
yuuji@59: ;;; change the reference link with completion.
yuuji@60: ;;; * [prefix] t j Call weblint on current file.
yuuji@60: ;;; * [prefix] t p View current html with WWW browser
yuuji@58: ;;; (To activate this, never fail to set the lisp
yuuji@58: ;;; variable yahtml-www-browser. Recommended value
yuuji@115: ;;; is "firefox")
yuuji@59: ;;; * [prefix] a YaTeX's accent mark's equivalent of yahtml.
yuuji@59: ;;; This function can input $lt, $gt or so.
yuuji@69: ;;; * [prefix] ; Translate chars of `>', `<', `&', and `"' to
yuuji@69: ;;; `>', `<', `&', `"' respectively
yuuji@69: ;;; in the region.
yuuji@69: ;;; * [prefix] : Do translation opposite to above, in the region.
yuuji@69: ;;; * [prefix] # Translate unsafe-chars and unreserved-chars to
yuuji@69: ;;; URLencoded string in the region.
yuuji@58: ;;;
yuuji@64: ;;;[キーの説明]
yuuji@64: ;;;
yuuji@64: ;;; 以下の説明において、特にカスタマイズをしていない限り、[prefix] は
yuuji@64: ;;; C-c キーを意味します。
yuuji@64: ;;;
yuuji@64: ;;; * [prefix] b X `' といった終了タグが必要となる`H1'のよう
yuuji@64: ;;; な環境を補完入力します。 ...
yuuji@64: ;;; もこのグループです。
yuuji@64: ;;; `href=...' と入力した後、TABキーを押すことで、
yuuji@64: ;;; ファイル名や (href="#foo") のようなラベルも補完
yuuji@64: ;;; できます。
yuuji@64: ;;; * [prefix] s 以下のような宣言の補完を行います。
yuuji@64: ;;; ` '
yuuji@64: ;;; ` '
yuuji@64: ;;; * [prefix] l ` ... ' や ` ... ' のよう
yuuji@64: ;;; なテキストスタイル指定のタグを補完します。
yuuji@64: ;;; この補完機能は通常 [prefix] b で補完できるものを
yuuji@64: ;;; 一行内で書きたいときにも用いることが出来ます。
yuuji@64: ;;; * [prefix] m ` ' や ` '、`' 等の単体タグの補完
yuuji@64: ;;; を行います。
yuuji@64: ;;; * [prefix] p カーソル位置に
を挿入します。
yuuji@64: ;;; * M-RET おまかせ改行; もしul、ol、dl等のタグ(リスト)を
yuuji@64: ;;; 使っている場合に、環境に合わせて改行と 、
yuuji@64: ;;; 、 を入力します。
yuuji@64: ;;; * menu-bar yahtml 選択したアイテムをメニューより補完できます。
yuuji@64: ;;; (私はメニューが嫌いなんですが、htmlに関してはメ
yuuji@64: ;;; ニューは一番ありがたいかも)
yuuji@64: ;;; * [prefix] g 対応するタグ、 <-> や href="xxx" の
yuuji@64: ;;; ような TAG にジャンプします。
yuuji@64: ;;; の場合はイメージビューワを呼び出
yuuji@64: ;;; します。href=hoge.html の場合はhoge.htmlに飛びま
yuuji@64: ;;; す。
yuuji@64: ;;; * [prefix] k ポイント上の HTML タグを消去します。
yuuji@64: ;;; もし universal-argument を付けた場合(C-uを先に押
yuuji@64: ;;; す)HTMLタグで囲まれた内容も同時に消去します。
yuuji@64: ;;; * [prefix] c ポイント上のタグを変更します。
yuuji@64: ;;; `href="xxx"'の上で [prefix] c を利用した場合は、
yuuji@64: ;;; 参照しているリンクを補完機能を使いながら変更で
yuuji@64: ;;; きます。
yuuji@64: ;;; * [prefix] t j カレントファイルに対して jweblint を呼び出しま
yuuji@64: ;;; す。
yuuji@64: ;;; * [prefix] t p WWW ブラウザでカレントファイルを表示します。
yuuji@64: ;;; (lisp変数 yahtml-www-browser の設定をお忘れな
yuuji@115: ;;; く。お推めは "firefox" です)
yuuji@64: ;;; * [prefix] a YaTeX のアクセント記号補完と同じです。
yuuji@64: ;;; < > 等が入力できます。
yuuji@69: ;;; * [prefix] ; 指定したリジョン中の > < & " をそれぞれ
yuuji@69: ;;; > < & " に変換します。
yuuji@69: ;;; * [prefix] : 指定したリジョン中で上と逆の変換をします。
yuuji@69: ;;; * [prefix] # 指定したリジョン中で%エンコードの必要な文字が
yuuji@69: ;;; あればそれらをエンコードします。
yuuji@72: ;;; * [prefix] ESC yahtml-mode を抜け yahtml-mode に入る前に動作し
yuuji@72: ;;; ていたメジャーモードに戻ります。
yuuji@64: ;;;
yuuji@64: ;;; [謝辞]
yuuji@64: ;;;
yuuji@64: ;;; fj野鳥の会の皆さんには貴重な助言を頂きました。また、下に示す方々には
yuuji@64: ;;; 特に大きな協力を頂きました。あわせてここに感謝申し上げます。
yuuji@64: ;;;
yuuji@64: ;;; * 横田和也さん(マツダ)
yuuji@64: ;;; マニュアルの和訳をして頂きました。
yuuji@64: ;;; * 吉田尚志さん(NTT Data)
yuuji@64: ;;; Mule for Win32 での動作のさせ方を教えて頂きました。
yuuji@64: ;;; (というかほとんどやってもらった ^^;)
yuuji@64: ;;;
yuuji@54:
yuuji@13:
yuuji@64: (require 'yatexlib)
yuuji@60: ;;; --- customizable variable starts here ---
yuuji@64: (defvar yahtml-prefix "\C-c"
yuuji@64: "*Prefix key stroke of yahtml functions.")
yuuji@80: (defvar yahtml-image-viewer "display" "*Image viewer program")
yuuji@80: (defvar yahtml-www-browser "firefox" "*WWW Browser command")
yuuji@58: (defvar yahtml-kanji-code 2
yuuji@88: "*Kanji coding system number of html file; 1=sjis, 2=jis, 3=euc, 4=UTF-8")
yuuji@69: ;;(defvar yahtml-coding-system
yuuji@69: ;; (cdr (assq yahtml-kanji-code YaTeX-kanji-code-alist))
yuuji@69: ;; "Kanji coding system")
yuuji@69: (and (featurep 'mule)
yuuji@69: (integerp yahtml-kanji-code)
yuuji@69: (setq yahtml-kanji-code
yuuji@69: (cdr (assq yahtml-kanji-code YaTeX-kanji-code-alist))))
yuuji@69:
yuuji@64: (defvar yahtml-fill-column 72 "*fill culumn used for yahtml-mode")
yuuji@64: (defvar yahtml-fill-prefix nil "*fill prefix for yahtml-mode")
yuuji@64:
yuuji@58: ;;(defvar yahtml-www-server "www" "*Host name of your domain's WWW server")
yuuji@58: (defvar yahtml-path-url-alist nil
yuuji@58: "*Alist of unix path name vs. URL name of WWW server.
yuuji@58: Ex.
yuuji@58: '((\"/usr/home/yuuji/http\" . \"http://www.comp.ae.keio.ac.jp/~yuuji\")
yuuji@70: (\"/home/yuuji/http\" . \"http://www.gentei.org/~yuuji\"))")
yuuji@58: (defvar yahtml-directory-index "index.html"
yuuji@58: "*Directory index file name;
yuuji@58: Consult your site's WWW administrator.")
yuuji@57:
yuuji@64: (defvar yahtml-environment-indent 1
yuuji@60: "*Indentation depth of HTML's listing environment")
yuuji@60:
yuuji@79: ;; YaTeX-japan is defined in yatexlib.el
yuuji@60: (defvar yahtml-lint-program (if YaTeX-japan "jweblint" "weblint")
yuuji@60: "*Program name to lint HTML file")
yuuji@60: (defvar yahtml-hate-too-deep-indentation nil
yuuji@60: "*Non-nil for this variable suppress deep indentation in listing environments.")
yuuji@60:
yuuji@80: (defvar yahtml-always-/p t
yuuji@64: "*Those who always use with
set this to t.")
yuuji@80: (defvar yahtml-always-/li nil
yuuji@80: "*Those who always use with set this to t.")
yuuji@80: (defvar yahtml-always-/dt nil
yuuji@80: "*Those who always use with set this to t.")
yuuji@80: (defvar yahtml-always-/dd nil
yuuji@80: "*Those who always use with set this to t.")
yuuji@64:
yuuji@70: (defvar yahtml-p-prefered-env-regexp "^\\(body\\|dl\\|blockquote\\)"
yuuji@64: "*Regexp of envs where paragraphed sentences are prefered.")
yuuji@64:
yuuji@80: (defvar yahtml-template-file "~/public_html/template.html"
yuuji@64: "*Template HTML file. It'll be inserted to empty file.")
yuuji@64:
yuuji@69: (defvar yahtml-prefer-upcases nil
yuuji@69: "*Non-nil for preferring upcase TAGs")
yuuji@69:
yuuji@69: (defvar yahtml-prefer-upcase-attributes nil
yuuji@69: "*Non-nil for preferring upcase attributes")
yuuji@69:
yuuji@80: (defvar yahtml-server-type 'apache "*WWW server program type")
yuuji@69:
yuuji@69: (defvar yahtml-apache-access-file ".htaccess"
yuuji@69: "*Server access file name for apache")
yuuji@69:
yuuji@69: (defvar yahtml-use-css t "*Use stylesheet or not")
yuuji@69:
yuuji@102: (defvar yahtml-image-inspection-bytes 50000
yuuji@70: "*Number of bytes to inspect the image for geometry information")
yuuji@70: (defvar yahtml:img-default-alt-format "%xx%y(%sbytes)"
yuuji@70: "*Default format of img entity's ALT attributes.
yuuji@70: %x: width, %y: height, %s: size in bytes, %c: first comment string,
yuuji@70: %f: filename")
yuuji@70:
yuuji@72: (defvar yahtml-faithful-to-htmllint nil)
yuuji@72: (defvar yahtml-error-line-regexp
yuuji@72: "^\\(.*\\)(\\([0-9]+\\)):\\|^line \\([0-9]+\\)"
yuuji@72: "*Regexp of error position which is produced by lint program.")
yuuji@72:
yuuji@72: (defvar yahtml-translate-hyphens-when-comment-region t
yuuji@72: "*Non-nil for translate hyphens to - when comment-region")
yuuji@72: (defvar yahtml-escape-chars 'ask
yuuji@72: "*Escape reserved characters to URL-encoding or not.
yuuji@72: Nil for never, t for everytime, and 'ask for inquiring
yuuji@72: at each reserved chars.")
yuuji@72:
yuuji@72: (defvar yahtml-use-font-lock (and (featurep 'font-lock)
yuuji@72: (fboundp 'font-lock-fontify-region))
yuuji@72: "*Non-nil means to use font-lock to fontify buffer.")
yuuji@72:
yuuji@72: (defvar yahtml-use-hilit19 (and (featurep 'hilit19)
yuuji@72: (not yahtml-use-font-lock))
yuuji@72: "*Non-nil means to Use hilit19 to highlight buffer")
yuuji@70:
yuuji@73: (defvar yahtml-mode-abbrev-table nil
yuuji@73: "*Abbrev table in use in yahtml-mode buffers.")
yuuji@73: (define-abbrev-table 'yahtml-mode-abbrev-table ())
yuuji@73:
yuuji@73: (defvar yahtml-indentation-boundary "^\\s *"
yuuji@73: "*Boundary regexp for indentation calculation.")
yuuji@73:
yuuji@80: (defvar yahtml-html4-strict t
yuuji@80: "*Non-nil means editing HTML 4.01 Strict.
yuuji@80: Completing read for obsoleted attributes disabled.")
yuuji@80:
yuuji@60: ;;; --- customizable variable ends here ---
yuuji@60: (defvar yahtml-prefix-map nil)
yuuji@60: (defvar yahtml-mode-map nil "Keymap used in yahtml-mode.")
yuuji@60: (defvar yahtml-lint-buffer-map nil "Keymap used in lint buffer.")
yuuji@60: (defvar yahtml-shell-command-option
yuuji@60: (or (and (boundp 'shell-command-option) shell-command-option)
yuuji@60: (if (eq system-type 'ms-dos) "/c" "-c")))
yuuji@72: (defvar yahtml-use-highlighting (or yahtml-use-font-lock yahtml-use-hilit19))
yuuji@60:
yuuji@57: (defun yahtml-define-begend-key-normal (key env &optional map)
yuuji@60: "Define short cut yahtml-insert-begend key."
yuuji@57: (YaTeX-define-key
yuuji@57: key
yuuji@57: (list 'lambda '(arg) '(interactive "P")
yuuji@60: (list 'yahtml-insert-begend 'arg env))
yuuji@57: map))
yuuji@57:
yuuji@57: (defun yahtml-define-begend-region-key (key env &optional map)
yuuji@60: "Define short cut yahtml-insert-begend-region key."
yuuji@57: (YaTeX-define-key key (list 'lambda nil '(interactive)
yuuji@60: (list 'yahtml-insert-begend t env)) map))
yuuji@57:
yuuji@57: (defun yahtml-define-begend-key (key env &optional map)
yuuji@57: "Define short cut key for begin type completion both for
yuuji@57: normal and region mode. To customize yahtml, user should use this function."
yuuji@57: (yahtml-define-begend-key-normal key env map)
yuuji@57: (if YaTeX-inhibit-prefix-letter nil
yuuji@57: (yahtml-define-begend-region-key
yuuji@61: (concat (upcase (substring key 0 1)) (substring key 1)) env map)))
yuuji@57:
yuuji@13: (if yahtml-mode-map nil
yuuji@57: (setq yahtml-mode-map (make-sparse-keymap)
yuuji@57: yahtml-prefix-map (make-sparse-keymap))
yuuji@64: (define-key yahtml-mode-map yahtml-prefix yahtml-prefix-map)
yuuji@58: (define-key yahtml-mode-map "\M-\C-@" 'yahtml-mark-begend)
yuuji@58: (if (and (boundp 'window-system) (eq window-system 'x) YaTeX-emacs-19)
yuuji@58: (define-key yahtml-mode-map [?\M-\C- ] 'yahtml-mark-begend))
yuuji@54: (define-key yahtml-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment)
yuuji@57: (define-key yahtml-mode-map "\M-\C-e" 'YaTeX-end-of-environment)
yuuji@58: (define-key yahtml-mode-map "\M-\C-m" 'yahtml-intelligent-newline)
yuuji@80: (define-key yahtml-mode-map "\M-\C-j" 'yahtml-intelligent-newline)
yuuji@58: (define-key yahtml-mode-map "\C-i" 'yahtml-indent-line)
yuuji@70: (define-key yahtml-mode-map "&" 'yahtml-insert-amps)
yuuji@57: (let ((map yahtml-prefix-map))
yuuji@57: (YaTeX-define-key "^" 'yahtml-visit-main map)
yuuji@57: (YaTeX-define-key "4^" 'yahtml-visit-main-other-window map)
yuuji@57: (YaTeX-define-key "4g" 'yahtml-goto-corresponding-*-other-window map)
yuuji@57: (YaTeX-define-key "44" 'YaTeX-switch-to-window map)
yuuji@57: (and YaTeX-emacs-19 window-system
yuuji@57: (progn
yuuji@57: (YaTeX-define-key "5^" 'yahtml-visit-main-other-frame map)
yuuji@57: (YaTeX-define-key "5g" 'yahtml-goto-corresponding-*-other-frame map)
yuuji@57: (YaTeX-define-key "55" 'YaTeX-switch-to-window map)))
yuuji@72: (YaTeX-define-key "v" 'yahtml-version map)
yuuji@57: (YaTeX-define-key "s" 'yahtml-insert-form map)
yuuji@57: (YaTeX-define-key "l" 'yahtml-insert-tag map)
yuuji@61: (YaTeX-define-key "L" 'yahtml-insert-tag-region map)
yuuji@57: (YaTeX-define-key "m" 'yahtml-insert-single map)
yuuji@61: (YaTeX-define-key "n" '(lambda () (interactive) (insert (if yahtml-prefer-upcases " " " "))) map)
yuuji@61: (YaTeX-define-key "-" '(lambda () (interactive) (insert (if yahtml-prefer-upcases " " " ") "\n")) map)
yuuji@64: (YaTeX-define-key "p" 'yahtml-insert-p map)
yuuji@57: (if YaTeX-no-begend-shortcut
yuuji@57: (progn
yuuji@57: (YaTeX-define-key "B" 'yahtml-insert-begend-region map)
yuuji@57: (YaTeX-define-key "b" 'yahtml-insert-begend map))
yuuji@60: (yahtml-define-begend-key "bh" "html" map)
yuuji@60: (yahtml-define-begend-key "bH" "head" map)
yuuji@60: (yahtml-define-begend-key "bt" "title" map)
yuuji@59: (yahtml-define-begend-key "bT" "table" map)
yuuji@60: (yahtml-define-begend-key "bb" "body" map)
yuuji@60: (yahtml-define-begend-key "bc" "center" map)
yuuji@60: (yahtml-define-begend-key "bd" "dl" map)
yuuji@60: (yahtml-define-begend-key "bu" "ul" map)
yuuji@80: (yahtml-define-begend-key "bo" "ol" map)
yuuji@60: (yahtml-define-begend-key "b1" "h1" map)
yuuji@60: (yahtml-define-begend-key "b2" "h2" map)
yuuji@60: (yahtml-define-begend-key "b3" "h3" map)
yuuji@57: (yahtml-define-begend-key "ba" "a" map)
yuuji@57: (yahtml-define-begend-key "bf" "form" map)
yuuji@57: (yahtml-define-begend-key "bs" "select" map)
yuuji@79: (yahtml-define-begend-key "bv" "div" map)
yuuji@80: (yahtml-define-begend-key "bS" "span" map)
yuuji@79: (yahtml-define-begend-key "bp" "pre" map)
yuuji@57: (YaTeX-define-key "b " 'yahtml-insert-begend map)
yuuji@102: (YaTeX-define-key "B " 'yahtml-insert-begend-region map))
yuuji@58: (YaTeX-define-key "e" 'YaTeX-end-environment map)
yuuji@57: (YaTeX-define-key ">" 'yahtml-comment-region map)
yuuji@57: (YaTeX-define-key "<" 'yahtml-uncomment-region map)
yuuji@57: (YaTeX-define-key "g" 'yahtml-goto-corresponding-* map)
yuuji@58: (YaTeX-define-key "k" 'yahtml-kill-* map)
yuuji@58: (YaTeX-define-key "c" 'yahtml-change-* map)
yuuji@58: (YaTeX-define-key "t" 'yahtml-browse-menu map)
yuuji@59: (YaTeX-define-key "a" 'yahtml-complete-mark map)
yuuji@60: (YaTeX-define-key "'" 'yahtml-prev-error map)
yuuji@69: (YaTeX-define-key ";" 'yahtml-translate-region map)
yuuji@69: (YaTeX-define-key ":" 'yahtml-translate-reverse-region map)
yuuji@69: (YaTeX-define-key "#" 'yahtml-escape-chars-region map)
yuuji@58: ;;;;;(YaTeX-define-key "i" 'yahtml-fill-item map)
yuuji@102: (YaTeX-define-key "\e" 'yahtml-quit map))
yuuji@72: (substitute-all-key-definition
yuuji@72: 'fill-paragraph 'yahtml-fill-paragraph yahtml-mode-map)
yuuji@72: (substitute-all-key-definition
yuuji@72: 'kill-buffer 'YaTeX-kill-buffer yahtml-mode-map))
yuuji@60:
yuuji@60: (if yahtml-lint-buffer-map nil
yuuji@60: (setq yahtml-lint-buffer-map (make-keymap))
yuuji@60: (define-key yahtml-lint-buffer-map " " 'yahtml-jump-to-error-line))
yuuji@60:
yuuji@54:
yuuji@59: (defvar yahtml-paragraph-start
yuuji@59: (concat
yuuji@61: "^$\\|")
yuuji@64: (comment-start-skip . comment-start)
yuuji@64: (indent-line-function . yahtml-indent-line)))
yuuji@64:
yuuji@72: (if yahtml-use-font-lock
yuuji@72: (progn
yuuji@72: (yahtml-font-lock-set-default-keywords)
yuuji@72: (or (featurep 'xemacs)
yuuji@72: (progn
yuuji@72: (set (make-local-variable 'font-lock-defaults)
yuuji@72: '(yahtml-font-lock-keywords nil t))
yuuji@72: ;;(font-lock-mode -1)
yuuji@72: (font-lock-mode 1) ;;Why should I fontify again???
yuuji@72: ;; in yatex-mode, there's no need to refontify...
yuuji@102: (font-lock-fontify-buffer)))))
yuuji@54: (set-syntax-table yahtml-syntax-table)
yuuji@13: (use-local-map yahtml-mode-map)
yuuji@64: (YaTeX-read-user-completion-table)
yuuji@69: (yahtml-css-scan-styles)
yuuji@64: (turn-on-auto-fill) ;Sorry, this is prerequisite
yuuji@64: (and (= 0 (buffer-size)) (file-exists-p yahtml-template-file)
yuuji@64: (y-or-n-p (format "Insert %s?" yahtml-template-file))
yuuji@64: (insert-file-contents (expand-file-name yahtml-template-file)))
yuuji@72: (run-hooks 'text-mode-hook 'yahtml-mode-hook)
yuuji@72:
yuuji@72: ;; This warning should be removed after a while(2000/12/2)
yuuji@72: (let ((fld (or (and (local-variable-p 'font-lock-defaults (current-buffer))
yuuji@72: font-lock-defaults)
yuuji@72: (get 'yahtml-mode 'font-lock-defaults))))
yuuji@72: (and fld (not (memq 'yahtml-font-lock-keywords fld))
yuuji@72: (YaTeX-warning-font-lock "yahtml"))))
yuuji@72:
yuuji@72: (defun yahtml-version ()
yuuji@72: "Return string of the version of running yahtml."
yuuji@72: (interactive)
yuuji@72: (message
yuuji@72: (concat "Yet Another HTML-mode "
yuuji@72: (if YaTeX-japan "「HTML屋」" "`yahtml'")
yuuji@72: " Revision "
yuuji@72: yahtml-revision-number)))
yuuji@72:
yuuji@72: (defun yahtml-quit ()
yuuji@72: (interactive)
yuuji@72: (and yahtml-mode-old-mode
yuuji@72: (fboundp yahtml-mode-old-mode)
yuuji@72: (funcall yahtml-mode-old-mode)))
yuuji@54:
yuuji@54: (defun yahtml-define-menu (keymap bindlist)
yuuji@64: (cond
yuuji@64: ((featurep 'xemacs)
yuuji@64: (let ((name (keymap-name (symbol-value keymap))))
yuuji@64: (set keymap nil)
yuuji@64: (mapcar
yuuji@64: (function
yuuji@64: (lambda (bind)
yuuji@64: (setq bind (cdr bind))
yuuji@64: (if (eq (car (cdr bind)) 'lambda)
yuuji@64: (setcar (cdr bind) 'progn))
yuuji@64: (if (stringp (car (cdr bind)))
yuuji@64: (set keymap (cons (cdr bind) (symbol-value keymap)))
yuuji@64: (set keymap (cons (vector (car bind) (cdr bind) t)
yuuji@64: (symbol-value keymap))))))
yuuji@64: bindlist)
yuuji@64: (set keymap (cons name (symbol-value keymap)))))
yuuji@64: (t
yuuji@64: (mapcar
yuuji@64: (function
yuuji@64: (lambda (bind)
yuuji@64: (define-key (symbol-value keymap) (vector (car bind)) (cdr bind))))
yuuji@64: bindlist))))
yuuji@54:
yuuji@54: (defvar yahtml-menu-map nil "Menu map of yahtml")
yuuji@54: (defvar yahtml-menu-map-sectioning nil "Menu map of yahtml(sectioning)")
yuuji@54: (defvar yahtml-menu-map-listing nil "Menu map of yahtml(listing)")
yuuji@54: (defvar yahtml-menu-map-logical nil "Menu map of yahtml(logical tags)")
yuuji@54: (defvar yahtml-menu-map-typeface nil "Menu map of yahtml(typeface tags)")
yuuji@54:
yuuji@54: ;;; Variables for mosaic url history
yuuji@54: (defvar yahtml-urls nil "Alist of global history")
yuuji@64: (defvar yahtml-urls-private nil)
yuuji@64: (defvar yahtml-urls-local nil)
yuuji@54:
yuuji@54: (cond
yuuji@54: ((and YaTeX-emacs-19 (null yahtml-menu-map))
yuuji@64: (setq yahtml-menu-map (make-sparse-keymap "yahtml"))
yuuji@54: (setq yahtml-menu-map-sectioning (make-sparse-keymap "sectioning menu"))
yuuji@64: (YaTeX-define-menu
yuuji@64: 'yahtml-menu-map-sectioning
yuuji@54: (nreverse
yuuji@58: '((1 "H1" . (lambda () (interactive) (yahtml-insert-begend nil "H1")))
yuuji@58: (2 "H2" . (lambda () (interactive) (yahtml-insert-begend nil "H2")))
yuuji@58: (3 "H3" . (lambda () (interactive) (yahtml-insert-begend nil "H3")))
yuuji@58: (4 "H4" . (lambda () (interactive) (yahtml-insert-begend nil "H4")))
yuuji@58: (5 "H5" . (lambda () (interactive) (yahtml-insert-begend nil "H5")))
yuuji@58: (6 "H6" . (lambda () (interactive) (yahtml-insert-begend nil "H6")))
yuuji@54: )))
yuuji@54: (setq yahtml-menu-map-logical (make-sparse-keymap "logical tags"))
yuuji@64: (YaTeX-define-menu
yuuji@64: 'yahtml-menu-map-logical
yuuji@54: (nreverse
yuuji@54: '((em "Embolden" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "EM")))
yuuji@60: (dfn "Define a word" .
yuuji@60: (lambda () (interactive) (yahtml-insert-tag nil "DFN")))
yuuji@54: (cite "Citation" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "CITE")))
yuuji@54: (code "Code" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "CODE")))
yuuji@54: (kbd "Keyboard" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "KBD")))
yuuji@54: (samp "Sample display" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "SAMP")))
yuuji@54: (strong "Strong" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "STRONG")))
yuuji@54: (VAR "Variable notation" .
yuuji@102: (lambda () (interactive) (yahtml-insert-tag nil "VAR"))))))
yuuji@54: (setq yahtml-menu-map-typeface (make-sparse-keymap "typeface tags"))
yuuji@64: (YaTeX-define-menu
yuuji@64: 'yahtml-menu-map-typeface
yuuji@54: (nreverse
yuuji@54: '((b "Bold" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "B")))
yuuji@54: (i "Italic" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "I")))
yuuji@54: (tt "Typewriter" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "TT")))
yuuji@54: (u "Underlined" .
yuuji@102: (lambda () (interactive) (yahtml-insert-tag nil "U"))))))
yuuji@54: (setq yahtml-menu-map-listing (make-sparse-keymap "listing"))
yuuji@64: (YaTeX-define-menu
yuuji@64: 'yahtml-menu-map-listing
yuuji@54: (nreverse
yuuji@58: '((ul "Unordered" .
yuuji@58: (lambda () (interactive) (yahtml-insert-begend nil "UL")))
yuuji@58: (ol "Ordered" .
yuuji@58: (lambda () (interactive) (yahtml-insert-begend nil "OL")))
yuuji@58: (dl "Definition" .
yuuji@102: (lambda () (interactive) (yahtml-insert-begend nil "DL"))))))
yuuji@57: (setq yahtml-menu-map-item (make-sparse-keymap "item"))
yuuji@64: (YaTeX-define-menu
yuuji@64: 'yahtml-menu-map-item
yuuji@57: (nreverse
yuuji@57: '((li "Simple item" .
yuuji@57: (lambda () (interactive) (yahtml-insert-single "li")))
yuuji@57: (dt "Define term" .
yuuji@57: (lambda () (interactive) (yahtml-insert-single "dt")))
yuuji@57: (dd "Description of term" .
yuuji@102: (lambda () (interactive) (yahtml-insert-single "dd"))))))
yuuji@54: (define-key yahtml-mode-map [menu-bar yahtml]
yuuji@54: (cons "yahtml" yahtml-menu-map))
yuuji@64: (YaTeX-define-menu
yuuji@64: 'yahtml-menu-map
yuuji@54: (nreverse
yuuji@54: (list
yuuji@54: (cons (list 'sect "Sectioning")
yuuji@54: (cons "sectioning" yahtml-menu-map-sectioning))
yuuji@54: (cons (list 'list "Listing")
yuuji@54: (cons "Listing" yahtml-menu-map-listing))
yuuji@57: (cons (list 'item "Item")
yuuji@57: (cons "Itemizing" yahtml-menu-map-item));;;
yuuji@54: (cons (list 'logi "Logical tags")
yuuji@54: (cons "logical" yahtml-menu-map-logical))
yuuji@54: (cons (list 'type "Typeface tags")
yuuji@102: (cons "typeface" yahtml-menu-map-typeface)))))
yuuji@64: (if (featurep 'xemacs)
yuuji@64: (add-hook 'yahtml-mode-hook
yuuji@64: '(lambda ()
yuuji@64: (or (assoc "yahtml" current-menubar)
yuuji@64: (progn
yuuji@64: (set-buffer-menubar (copy-sequence current-menubar))
yuuji@102: (add-submenu nil yahtml-menu-map))))))))
yuuji@54:
yuuji@57: ;;; ----------- Completion ----------
yuuji@57: (defvar yahtml-last-begend "html")
yuuji@58: (defun yahtml-insert-begend (&optional region env)
yuuji@57: "Insert ... ."
yuuji@57: (interactive "P")
yuuji@70: (setq yahtml-current-completion-type 'multiline)
yuuji@58: (let*((completion-ignore-case t)
yuuji@58: (cmd
yuuji@58: (or env
yuuji@58: (YaTeX-cplread-with-learning
yuuji@57: (format "Environment(default %s): " yahtml-last-begend)
yuuji@58: 'yahtml-env-table 'yahtml-user-env-table 'yahtml-tmp-env-table)))
yuuji@58: (bolp (save-excursion
yuuji@58: (skip-chars-backward " \t" (point-beginning-of-line)) (bolp)))
yuuji@58: (cc (current-column)))
yuuji@57: (if (string< "" cmd) (setq yahtml-last-begend cmd))
yuuji@58: (setq yahtml-last-begend
yuuji@58: (or (cdr (assoc yahtml-last-begend yahtml-env-table))
yuuji@58: yahtml-last-begend))
yuuji@57: (setq cmd yahtml-last-begend)
yuuji@60: (if yahtml-prefer-upcases (setq cmd (upcase cmd)))
yuuji@57: (if region
yuuji@69: ;; We want to keep region effective for new tagged environment
yuuji@69: ;; to enable continuous regioning by another environment
yuuji@57: (let ((beg (region-beginning))
yuuji@57: (end (region-end))
yuuji@57: (addin (yahtml-addin cmd)))
yuuji@69: (save-excursion
yuuji@69: (goto-char end)
yuuji@69: (insert-before-markers (format "%s>%s" cmd (if bolp "\n" "")))
yuuji@69: (goto-char beg)
yuuji@69: (insert (format "<%s%s>%s" cmd addin (if bolp "\n" "")))))
yuuji@58: (insert (format "<%s%s>" cmd (yahtml-addin cmd)))
yuuji@58: (save-excursion
yuuji@60: (insert "\n")
yuuji@60: (indent-to-column cc)
yuuji@60: (insert (format "%s>" cmd)))
yuuji@64: (if (string-match "^a\\|p$" cmd) ;aとp決め打ちってのが美しくない…
yuuji@64: (newline)
yuuji@64: (yahtml-intelligent-newline nil))
yuuji@64: (yahtml-indent-line))))
yuuji@57:
yuuji@57: (defun yahtml-insert-begend-region ()
yuuji@57: "Call yahtml-insert-begend in the region mode."
yuuji@57: (interactive)
yuuji@57: (yahtml-insert-begend t))
yuuji@57:
yuuji@57:
yuuji@54: (defun yahtml-insert-form (&optional form)
yuuji@57: "Insert