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" 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 "" 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
    ." yuuji@54: (interactive) yuuji@70: (setq yahtml-current-completion-type 'single) yuuji@54: (or form yuuji@60: (let ((completion-ignore-case t)) yuuji@60: (setq form yuuji@60: (YaTeX-cplread-with-learning yuuji@64: (format "Form(default %s): " yahtml-last-form) yuuji@60: 'yahtml-form-table 'yahtml-user-form-table yuuji@60: 'yahtml-tmp-form-table)))) yuuji@57: (let ((p (point)) q) yuuji@64: (if (string= form "") (setq form yahtml-last-form)) yuuji@64: (setq yahtml-last-form form) yuuji@60: (if yahtml-prefer-upcases (setq form (upcase form))) yuuji@58: (insert (format "<%s%s>" form (yahtml-addin form))) yuuji@57: ;;(indent-relative-maybe) yuuji@57: (if (cdr (assoc form yahtml-form-table)) yuuji@57: (save-excursion (insert (format "" form)))) yuuji@54: (if (search-backward "\"\"" p t) (forward-char 1)))) yuuji@54: yuuji@80: (defun yahtml-read-css (alist) yuuji@80: (let ((completion-ignore-case t) (delim " ") yuuji@80: (minibuffer-completion-table alist)) yuuji@80: (read-from-minibuffer yuuji@80: (substitute-command-keys yuuji@80: (if YaTeX-japan yuuji@80: "クラス(複数指定は\\[quoted-insert] SPCで区切る): " yuuji@80: "class(or class list delimited by \\[quoted-insert] SPC): ")) yuuji@80: nil YaTeX-minibuffer-completion-map nil))) yuuji@80: yuuji@138: (defvar yahtml-newpage-command "newpage.rb" yuuji@138: "*Command name to create new HTML file referring to index.html. yuuji@138: This command should create new HTML file named argument 1 and yuuji@138: output string like `anchor tag'. yuuji@138: This program should take -o option to overwrite existing HTML file.") yuuji@138: (defun yahtml-newpage (file ov) yuuji@138: "Create newpage via newpage script" yuuji@138: (interactive yuuji@138: (list yuuji@138: (let (insert-default-directory) yuuji@138: (read-file-name "New webpage file name: " "")) yuuji@138: current-prefix-arg)) yuuji@138: (if (and (file-exists-p file) (not ov)) yuuji@138: (error "%s already exists. Call this with universal argument to force overwrite." file)) yuuji@138: (insert (substring yuuji@138: (YaTeX-command-to-string yuuji@138: (concat yahtml-newpage-command " " (if ov "-o ") file)) yuuji@138: 0 -1))) yuuji@138: yuuji@59: ;;; ---------- Add-in ---------- yuuji@54: (defun yahtml-addin (form) yuuji@54: "Check add-in function's existence and call it if exists." yuuji@69: (let ((addin (concat "yahtml:" (downcase form))) s a) yuuji@69: (concat yuuji@70: (and (setq a (yahtml-css-get-element-completion-alist form)) yuuji@70: (not (equal last-command-char ?\C-j)) yuuji@70: (memq yahtml-current-completion-type '(multiline inline)) yuuji@70: (yahtml-make-optional-argument ;should be made generic? yuuji@80: "class" (yahtml-read-css a))) yuuji@69: (if (and (intern-soft addin) (fboundp (intern-soft addin)) yuuji@69: (stringp (setq s (funcall (intern addin)))) yuuji@69: (string< "" s)) yuuji@69: (if (eq (aref s 0) ? ) s (concat " " s)) yuuji@69: "")))) yuuji@54: yuuji@59: (defvar yahtml-completing-buffer nil) yuuji@59: (defun yahtml-collect-labels (&optional file) yuuji@68: "Collect current buffers label (). yuuji@59: If optional argument FILE is specified collect labels in FILE." yuuji@69: (let (list end) yuuji@59: (save-excursion yuuji@59: (set-buffer yahtml-completing-buffer) yuuji@60: (if file (let (hilit-auto-highlight) yuuji@60: (set-buffer (find-file-noselect file)))) yuuji@59: (save-excursion yuuji@59: (goto-char (point-min)) yuuji@69: (while ;(re-search-forward "<\\w+\\b" nil t) yuuji@69: (re-search-forward "\\(name\\|id\\)\\s *=" nil t) yuuji@69: ;(setq bound (match-end 0)) yuuji@69: ;(search-forward ">" nil t) yuuji@69: (setq end (match-end 0)) yuuji@69: (if (and ;(re-search-backward "\\(name\\|id\\)\\s *=" bound t) yuuji@69: (yahtml-on-assignment-p) yuuji@69: (progn yuuji@69: (goto-char end) yuuji@69: (skip-chars-forward " \t\n") yuuji@69: (looking-at "\"?#?\\([^\">]+\\)\"?\\b"))) yuuji@59: (setq list (cons yuuji@59: (list (concat "#" (YaTeX-match-string 1))) yuuji@59: list)))) yuuji@102: list)))) yuuji@59: yuuji@58: (defvar yahtml-url-completion-map nil "Key map used in URL completion buffer") yuuji@58: (if yahtml-url-completion-map nil yuuji@58: (setq yahtml-url-completion-map yuuji@58: (copy-keymap minibuffer-local-completion-map)) yuuji@58: (define-key yahtml-url-completion-map "\t" 'yahtml-complete-url) yuuji@102: (define-key yahtml-url-completion-map " " 'yahtml-complete-url)) yuuji@58: yuuji@58: (defun yahtml-complete-url () yuuji@58: "Complete external URL from history or local file name." yuuji@58: (interactive) yuuji@72: (let ((p (point)) initial i2 cmpl path dir file listfunc beg labels yuuji@73: (lim (YaTeX-minibuffer-begin)) yuuji@73: (min (if (fboundp 'field-beginning) (field-beginning) (point-min)))) yuuji@72: (setq initial (YaTeX-minibuffer-string)) yuuji@58: (cond yuuji@58: ((string-match "^http:" initial) yuuji@58: (setq cmpl (try-completion initial yahtml-urls) yuuji@58: listfunc (list 'lambda nil yuuji@58: (list 'all-completions initial 'yahtml-urls)) yuuji@73: beg min)) yuuji@59: ((setq beg (string-match "#" initial)) yuuji@59: (or (equal beg 0) ;begin with # yuuji@59: (progn yuuji@59: (setq path (substring initial 0 beg)) yuuji@59: (if (string-match "^/" path) yuuji@59: (setq path (yahtml-url-to-path path))))) yuuji@59: (setq initial (substring initial beg)) yuuji@59: (setq labels (yahtml-collect-labels path) yuuji@59: cmpl (try-completion initial labels) yuuji@59: listfunc (list 'lambda () yuuji@59: (list 'all-completions yuuji@59: initial (list 'quote labels))) yuuji@73: beg (+ min beg))) yuuji@58: (t yuuji@58: (setq path (if (string-match "^/" initial) yuuji@64: (or (yahtml-url-to-path initial) initial) yuuji@58: initial)) yuuji@58: (setq dir (or (file-name-directory path) ".") yuuji@58: file (file-name-nondirectory path) yuuji@58: initial file yuuji@58: cmpl (file-name-completion file dir) yuuji@58: listfunc (list 'lambda nil yuuji@58: (list 'file-name-all-completions yuuji@58: file dir)) yuuji@72: beg (save-excursion (skip-chars-backward "^/" lim) (point))))) yuuji@58: (cond yuuji@58: ((stringp cmpl) yuuji@58: (if (string= initial cmpl) yuuji@58: (with-output-to-temp-buffer "*Completions*" yuuji@58: (princ "Possible completinos are:\n") yuuji@58: (princ yuuji@58: (mapconcat '(lambda (x) x) (funcall listfunc) "\n"))) yuuji@58: (delete-region (point) beg) yuuji@58: (insert cmpl))) yuuji@58: ((null cmpl) yuuji@58: (ding)) yuuji@58: ((eq t cmpl) yuuji@58: (save-excursion yuuji@58: (unwind-protect yuuji@58: (progn yuuji@58: (goto-char p) yuuji@58: (insert " [Sole completion]")) yuuji@58: (delete-region p (point-max)))))))) yuuji@69: yuuji@69: ; yuuji@69: ; Subject: [yatex:02849] Re: [yahtml] tilda in href tag yuuji@69: ; From: Masayasu Ishikawa yuuji@69: ; To: yatex@arcadia.jaist.ac.jp yuuji@69: ; Date: Mon, 31 May 1999 21:09:31 +0900 yuuji@69: ; RFC 2396 の "2.4.3. Excluded US-ASCII Characters" によると、以下の文字 yuuji@69: ; は必ずエスケープしないといけません。 yuuji@69: ; yuuji@69: ; control = yuuji@69: ; space = yuuji@69: ; delims = "<" | ">" | "#" | "%" | <"> yuuji@69: ; unwise = "{" | "}" | "|" | "\" | "^" | "[" | "]" | "`" yuuji@69: (defvar yahtml-unsafe-chars-regexp yuuji@69: "[][\x0- \x7f <>%\"{}|\\^`]" ;#は除去する yuuji@69: "Characters regexp which must be escaped in URI.") yuuji@69: ; yuuji@69: ; また、以下の文字は予約された用法以外に用いる場合にはエスケープしないと yuuji@69: ; いけないことになっています。 yuuji@69: ; yuuji@69: ; reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | yuuji@69: ; "$" | "," yuuji@69: (defvar yahtml-unreserved-chars-regexp yuuji@69: "[;/?:@&=+$,]" yuuji@69: "Characters regexp which should be escaped in URI on certain conditions. yuuji@69: Not used yet.") yuuji@69: yuuji@69: (defun yahtml-escape-chars-string (str) yuuji@69: "Translate reserved chars to URL encoded string." yuuji@69: (let ((p 0) (target "") yuuji@69: (ask (eq yahtml-escape-chars 'ask))) yuuji@69: (cond yuuji@69: ((null yahtml-escape-chars) str) yuuji@69: (t yuuji@69: (while (and (string< "" str) yuuji@69: (setq p (string-match yahtml-unsafe-chars-regexp str))) yuuji@69: (if (and ask (y-or-n-p (format "Escape char [%c] of `%s'" yuuji@69: (aref str p) (substring str 0 (1+ p))))) yuuji@69: (setq target (concat target yuuji@69: (substring str 0 p) yuuji@69: (format "%%%x" (aref str p)))) yuuji@69: (setq target (concat target (substring str 0 (1+ p))))) yuuji@69: (setq str (substring str (1+ p)))) yuuji@69: (concat target str))))) yuuji@69: yuuji@69: (defun yahtml-escape-chars-region (beg end) yuuji@69: "Translate reserved chars to encoded string in the region." yuuji@69: (interactive "r") yuuji@69: (save-excursion yuuji@69: (let ((e (set-marker (make-marker) end)) c m yes) yuuji@69: (goto-char beg) yuuji@69: (while (and (< (point) e) yuuji@69: (re-search-forward yuuji@69: (concat yahtml-unsafe-chars-regexp "\\|" yuuji@69: yahtml-unreserved-chars-regexp) e t)) yuuji@69: (sit-for 0) yuuji@69: ; (setq m (buffer-modified-p) yuuji@69: ; c (char-after (1- (point)))) yuuji@69: ; (save-excursion (backward-char 1) (insert " ==>")) yuuji@69: ; (unwind-protect yuuji@69: ; (setq yes (y-or-n-p (format "Replace: [%c]" c))) yuuji@69: ; (save-excursion yuuji@69: ; (backward-char 1) yuuji@69: ; (delete-backward-char 4)) yuuji@69: ; (set-buffer-modified-p m)) yuuji@69: (message "Replace: [%c] (y or n):" (setq c (char-after (1- (point))))) yuuji@69: (if (memq (read-char) '(?y ?Y)) yuuji@69: (progn yuuji@69: (delete-region (match-beginning 0) (match-end 0)) yuuji@69: (insert (format "%%%x" c))))) yuuji@69: (set-marker e nil)))) yuuji@69: ;; ab%defgls/.| yuuji@69: yuuji@57: (defun yahtml:a () yuuji@54: "Add-in function for " yuuji@64: (let ((href "")) yuuji@64: (setq yahtml-completing-buffer (current-buffer) yuuji@69: yahtml-urls (append yahtml-urls-private yahtml-urls-local) yuuji@69: href (yahtml-escape-chars-string yuuji@69: (read-from-minibuffer "href: " "" yahtml-url-completion-map))) yuuji@64: (prog1 yuuji@64: (concat (yahtml-make-optional-argument yuuji@64: "href" href) yuuji@64: (yahtml-make-optional-argument yuuji@64: "name" (read-string "name: "))) yuuji@64: (if (and (string-match "^http://" href) yuuji@69: (null (assoc href yahtml-urls-private)) yuuji@69: (null (assoc href yahtml-urls-local))) yuuji@64: (YaTeX-update-table yuuji@64: (list href) yuuji@102: 'yahtml-urls-private 'yahtml-urls-private 'yahtml-urls-local))))) yuuji@57: yuuji@60: (defvar yahtml-parameters-completion-alist yuuji@61: '(("align" ("top") ("middle") ("bottom") ("left") ("right") ("center")) yuuji@70: ("clear" ("left") ("right") ("center") ("all") ("none")) yuuji@80: ("lang" ("ja") ("en") ("kr") ("ch") ("fr")) yuuji@80: ("src" . file) ("file" . file) yuuji@70: ("background" . file) yuuji@70: ("class file name" . file) ("data" . file) yuuji@69: ("method" ("POST") ("GET")) yuuji@69: ("rev" . yahtml-link-types-alist) yuuji@69: ("rel" . yahtml-link-types-alist) yuuji@70: ("type" . yahtml-content-types-alist) yuuji@73: ("codetype" . yahtml-content-types-alist) yuuji@73: ("http-equiv" ("Refresh")))) yuuji@60: yuuji@69: (defvar yahtml-link-types-alist yuuji@69: '(("alternate") ("stylesheet") ("start") ("next") ("prev") yuuji@69: ("contents") ("index") ("glossary") ("chapter") ("section") yuuji@69: ("subsection") ("appendix") ("help") ("bookmark"))) yuuji@69: yuuji@69: (defvar yahtml-content-types-alist yuuji@69: '(("text/css") ("text/html") ("text/plain") ("text/richtext") yuuji@69: ("text/sgml") ("text/xml") yuuji@80: ("text/javascript") ("text/tcl") ("text/vbscript") yuuji@69: ("application/octet-stream") ("application/postscript") ("application/pdf") yuuji@70: ("application/java") yuuji@70: ("image/jpeg") ("image/gif") ("image/tiff") ("image/png") ("video/mpeg")) yuuji@69: "Alist of content-types") yuuji@69: yuuji@69: (defun yahtml-read-parameter (par &optional default alist) yuuji@69: (let* ((alist yuuji@69: (cdr-safe (assoc (downcase par) yuuji@69: (or alist yahtml-parameters-completion-alist)))) yuuji@60: (prompt (concat par ": ")) yuuji@60: v) yuuji@60: (cond yuuji@60: ((eq alist 'file) yuuji@80: (let ((insert-default-directory)) yuuji@80: (read-file-name prompt "" default nil ""))) yuuji@70: ((and alist (symbolp alist)) yuuji@69: (completing-read prompt (symbol-value alist) nil nil default)) yuuji@60: (alist yuuji@69: (completing-read prompt alist nil nil default)) yuuji@60: (t yuuji@69: (read-string prompt default))))) yuuji@60: yuuji@64: (defun yahtml-make-optional-argument (opt arg) yuuji@64: "Make optional argument string." yuuji@80: (if (or (null arg) (string= "" arg)) yuuji@64: "" yuuji@69: (concat " " yuuji@69: (if yahtml-prefer-upcase-attributes (upcase opt) (downcase opt)) yuuji@64: "=\"" arg "\""))) yuuji@64: yuuji@80: (defun yahtml:html () yuuji@80: "Add-in for " yuuji@80: (setq yahtml-last-begend "head" yahtml-last-typeface-cmd "head") yuuji@80: (yahtml-make-optional-argument yuuji@80: "lang" (yahtml-read-parameter "lang" (if YaTeX-japan "ja")))) yuuji@80: yuuji@80: (defun yahtml:head () yuuji@80: "Add-in for " yuuji@80: (setq yahtml-last-begend "title" yahtml-last-typeface-cmd "title") yuuji@80: "") yuuji@80: yuuji@64: (defun yahtml:body () yuuji@64: "Add-in function for " yuuji@80: (cond yuuji@80: (yahtml-html4-strict nil) yuuji@80: (t yuuji@80: (let ((b (read-string "bgcolor=")) yuuji@80: (bg (yahtml-read-parameter "background" "")) yuuji@80: (x (read-string "text color=")) yuuji@80: (l (read-string "link color=")) yuuji@80: (v (read-string "vlink color="))) yuuji@80: (concat yuuji@80: (yahtml-make-optional-argument "bgcolor" b) yuuji@80: (yahtml-make-optional-argument "background" bg) yuuji@80: (yahtml-make-optional-argument "text" x) yuuji@80: (yahtml-make-optional-argument "link" l) yuuji@80: (yahtml-make-optional-argument "vlink" v)))))) yuuji@80: yuuji@80: (defun yahtml-make-style-parameter (proplist) yuuji@80: "Make CSS property definitions in style attribute." yuuji@80: (mapconcat yuuji@80: '(lambda (x) (if (and (cdr x) (string< "" (cdr x))) yuuji@80: (format "%s: %s;" (car x) (cdr x)))) yuuji@80: (delq nil proplist) yuuji@80: " ")) yuuji@64: yuuji@57: (defun yahtml:img () yuuji@57: "Add-in function for " yuuji@60: (let ((src (yahtml-read-parameter "src")) yuuji@60: (alg (yahtml-read-parameter "align")) yuuji@70: alt yuuji@64: (brd (read-string "border=")) yuuji@70: (l yahtml-prefer-upcase-attributes) yuuji@70: info width height bytes comments) yuuji@70: (and (stringp src) (string< "" src) (file-exists-p src) yuuji@70: (setq info (yahtml-get-image-info src)) yuuji@70: (car info) yuuji@70: (setq width (int-to-string (car info)) yuuji@70: height (int-to-string (car (cdr info))) yuuji@70: bytes (car (cdr (cdr info))) yuuji@70: comments (nth 4 info))) yuuji@70: (if info yuuji@70: (setq alt yuuji@70: (YaTeX-replace-formats yuuji@70: yahtml:img-default-alt-format yuuji@70: (list (cons "x" width) yuuji@70: (cons "y" height) yuuji@70: (cons "s" (int-to-string bytes)) yuuji@70: (cons "f" (file-name-nondirectory src)) yuuji@70: (cons "c" (car comments)))))) yuuji@70: yuuji@70: (setq alt (yahtml-read-parameter "alt" alt)) yuuji@70: (setq width (yahtml-read-parameter "width" width) yuuji@70: height (yahtml-read-parameter "height" height)) yuuji@60: (concat (if l "SRC" "src") "=\"" src "\"" yuuji@64: (yahtml-make-optional-argument "alt" alt) yuuji@70: (yahtml-make-optional-argument "width" width) yuuji@70: (yahtml-make-optional-argument "height" height) yuuji@80: (if yahtml-html4-strict yuuji@80: (yahtml-make-optional-argument yuuji@80: "style" yuuji@80: (if (or brd alg) yuuji@80: (yahtml-make-style-parameter yuuji@80: (list yuuji@80: (if (string< "" alg) yuuji@80: (cons "align" alg)) yuuji@80: (if (string< "" brd) yuuji@80: (cons "border" yuuji@80: (format "%dpx" (string-to-int brd)))))))) yuuji@80: (concat yuuji@80: (yahtml-make-optional-argument "border" brd) yuuji@80: (yahtml-make-optional-argument "align" alg)))))) yuuji@57: yuuji@70: (defun yahtml-file-truename (file) yuuji@70: (cond yuuji@70: ((fboundp 'file-truename) (file-truename (expand-file-name file))) yuuji@70: (t (let ((new file)) yuuji@70: (while (and (stringp (setq new (nth 0 (file-attributes file)))) yuuji@70: (not (equal new file))) yuuji@70: (setq file new)) yuuji@70: file)))) yuuji@70: yuuji@70: (defun yahtml-hex-value (point length &optional little-endian) yuuji@70: "Return the hex value the POINT positions LENGTH byte stream represents. yuuji@70: Optional third argument LITTLE-ENDIAN is self extplanatory." yuuji@70: (setq point (1+ point)) ;translate file offset to Emacs's point value yuuji@70: (let ((mlt 1) yuuji@70: (pos (if little-endian point (+ point length -1))) yuuji@70: (direc (if little-endian 1 -1)) yuuji@70: (value 0)) yuuji@70: (while (> length 0) yuuji@70: (setq value (+ value (* mlt (char-after pos))) yuuji@70: pos (+ pos direc) yuuji@70: mlt (* mlt 256) yuuji@70: length (1- length))) yuuji@70: value)) yuuji@70: yuuji@70: (defun yahtml-get-image-info (file) yuuji@70: "Return the information on the image file FILE. yuuji@70: Returns list of '(WIDTH HEIGHT BYTES DEPTH COMMENTLIST)." yuuji@70: (save-excursion yuuji@70: (let*((tmpbuf (get-buffer-create " *imgheader*")) yuuji@70: width height bytes depth comment yuuji@70: (file-coding-system-alist (list (cons "." 'no-conversion))) ;20 yuuji@70: (file-coding-system-for-read (and (boundp '*noconv*) *noconv*)) ;19 yuuji@72: (coding-system-for-read 'no-conversion) yuuji@70: (seekpoint 1) yuuji@70: c1 c2 c3 c4 beg end yuuji@70: (case-fold-search nil)) yuuji@70: (setq bytes (nth 7 (file-attributes (yahtml-file-truename file)))) yuuji@70: (set-buffer tmpbuf) yuuji@70: (if (boundp 'mc-flag) (set (make-local-variable 'mc-flag) nil)) yuuji@70: (erase-buffer) yuuji@70: (if (fboundp 'set-buffer-multibyte) (set-buffer-multibyte nil)) yuuji@70: (unwind-protect yuuji@70: (progn yuuji@70: (message "Inspecting image information of %s..." file) yuuji@70: ;; Read 4bytes-more than inspection-bytes in case that yuuji@70: ;; JPEG marker delimiter (4bytes) is on the alignment. yuuji@70: (YaTeX-insert-file-contents yuuji@70: file nil 0 (+ yahtml-image-inspection-bytes 4)) yuuji@70: (goto-char (point-min)) ;assertion yuuji@70: (setq c1 (char-after 1) ;cache first 4 bytes yuuji@70: c2 (char-after 2) yuuji@70: c3 (char-after 3) yuuji@70: c4 (char-after 4)) yuuji@70: (cond yuuji@73: ((and (eq c1 ?\377) (eq c2 ?\330)) ; 0xff 0xd8 yuuji@70: ;;JPEG images need JPEG markers inspection yuuji@70: ;;JPEG markers consist of [ 0xff ID(B) LEN(S) CONTENTS... ] yuuji@70: ;; Warning: here seekpoint is measured by Emacs's point value yuuji@70: ;; while yahtml-hex-vale requires file offset yuuji@70: (setq seekpoint 3) ;where the first JPEG marker exists yuuji@70: (catch 'exit yuuji@70: (while (< seekpoint (- (buffer-size) 4)) yuuji@70: (cond yuuji@73: ((not (eq (char-after seekpoint) ?\377)) yuuji@70: ;maybe corrupted, exit from loop yuuji@70: (throw 'exit t)) yuuji@73: ((memq yuuji@73: (char-after (1+ seekpoint)) yuuji@73: '(?\300 ?\301 ?\302 ?\303 yuuji@73: ?\305 ?\306 ?\307 ?\311 ?\312 ?\313 ?\315 ?\316 ?\317)) yuuji@73: ;;'(192 193 194 195 197 198 199 201 202 203 205 206 207 yuuji@70: ;;found! yuuji@70: (setq height (yahtml-hex-value (+ seekpoint 4) 2) yuuji@70: width (yahtml-hex-value (+ seekpoint 6) 2) yuuji@70: depth (yahtml-hex-value (+ seekpoint 3) 1))) yuuji@73: ((eq (char-after (1+ seekpoint)) ?\376) ;0xFE = comment yuuji@70: ;; JPEG comment area yuuji@70: (setq beg (+ seekpoint 2 2) yuuji@70: end (+ seekpoint yuuji@70: (yahtml-hex-value (1+ seekpoint) 2) 2)) yuuji@70: (setq comment (cons (buffer-substring beg end) comment))) yuuji@70: (t ;other markers yuuji@70: nil)) ;just skip it yuuji@70: (setq seekpoint (+ seekpoint 2) yuuji@70: seekpoint (+ seekpoint yuuji@70: (yahtml-hex-value (1- seekpoint) 2)))))) yuuji@73: ((and (eq c1 ?\211) ;0x89 yuuji@70: (eq c2 ?P) (eq c3 ?N) (eq c4 ?G)) yuuji@70: ;;PNG Image data X=@0x10(L), Y=@0x14(L), D=@0x18(B) yuuji@70: (setq width (yahtml-hex-value 16 4) yuuji@70: height (yahtml-hex-value 20 4) yuuji@70: depth (yahtml-hex-value 24 1))) yuuji@70: ((looking-at "GIF8") yuuji@70: ;;GIF Image data X=@0x6(leshort), Y=@0x8(leshort) yuuji@70: (setq width (yahtml-hex-value 6 2 t) yuuji@70: height (yahtml-hex-value 8 2 t))) yuuji@70: ((looking-at "BM") yuuji@70: ;;# OS/2, Windoze BMP files yuuji@70: ;;@0x0e = 12 -> OS/2 1.x - X=@0x12(leshort), Y=@0x14(leshort) yuuji@70: ;;@0x0e = 64 -> OS/2 2.x - X=@0x12(leshort), Y=@0x14(leshort) yuuji@70: ;;@0x0e = 40 -> Windows 3.x - X=@0x12(lelong), Y=@0x16(lelong) yuuji@70: (cond yuuji@70: ((eq (yahtml-hex-value 14 2 t) 40) yuuji@70: (setq width (yahtml-hex-value 18 4 t) yuuji@70: height (yahtml-hex-value 22 4 t))) yuuji@70: (t yuuji@70: (setq width (yahtml-hex-value 18 2 t) yuuji@102: height (yahtml-hex-value 20 2 t))))))) yuuji@70: (message "") yuuji@70: (kill-buffer tmpbuf)) yuuji@70: (list width height bytes depth (nreverse comment))))) yuuji@70: yuuji@57: (defun yahtml:form () yuuji@57: "Add-in function `form' input format" yuuji@57: (concat yuuji@73: " " (if yahtml-prefer-upcase-attributes "METHOD" "method") "=" yuuji@60: (completing-read "Method: " '(("POST") ("GET")) nil t) yuuji@69: " " (if yahtml-prefer-upcase-attributes "ACTION" "action") "=\"" yuuji@102: (read-string "Action: ") "\"")) yuuji@57: yuuji@57: (defun yahtml:select () yuuji@57: "Add-in function for `select' input format" yuuji@57: (setq yahtml-last-single-cmd "option") yuuji@69: (concat " " (if yahtml-prefer-upcase-attributes "NAME" "name") "=\"" yuuji@60: (read-string "name: ") "\"")) yuuji@57: yuuji@58: (defun yahtml:ol () yuuji@73: "Add-in function for
      " yuuji@73: (setq yahtml-last-single-cmd "li") yuuji@73: (let ((start (read-string "start=")) yuuji@73: (type (completing-read yuuji@73: "type=" '(("1") ("a") ("A") ("i") ("I")) nil t))) yuuji@73: (concat yuuji@73: (yahtml-make-optional-argument "start" start) yuuji@73: (yahtml-make-optional-argument "type" type)))) yuuji@58: (defun yahtml:ul () yuuji@58: (setq yahtml-last-single-cmd "li") "") yuuji@58: (defun yahtml:dl () yuuji@58: (setq yahtml-last-single-cmd "dt") "") yuuji@58: (defun yahtml:dt () yuuji@58: (setq yahtml-last-single-cmd "dd") "") yuuji@58: yuuji@61: (defun yahtml:p () yuuji@80: (if yahtml-html4-strict nil yuuji@80: (let ((alg (yahtml-read-parameter "align"))) yuuji@80: (yahtml-make-optional-argument "align" alg)))) yuuji@58: yuuji@57: (defvar yahtml-input-types yuuji@57: '(("text") ("password") ("checkbox") ("radio") ("submit") yuuji@60: ("reset") ("image") ("hidden") ("file"))) yuuji@57: yuuji@57: (defun yahtml:input () yuuji@57: "Add-in function for `input' form" yuuji@60: (let ((size "") name type value checked (maxlength "") yuuji@69: (l yahtml-prefer-upcase-attributes)) yuuji@57: (setq name (read-string "name: ") yuuji@57: type (completing-read "type (default=text): " yuuji@57: yahtml-input-types nil t) yuuji@57: value (read-string "value: ")) yuuji@57: (if (string-match "text\\|password\\|^$" type) yuuji@57: (setq size (read-string "size: ") yuuji@57: maxlength (read-string "maxlength: "))) yuuji@57: (concat yuuji@60: (if l "NAME" "name") "=\"" name "\"" yuuji@64: (yahtml-make-optional-argument "type" type) yuuji@64: (yahtml-make-optional-argument "value" value) yuuji@64: (yahtml-make-optional-argument "size" size) yuuji@102: (yahtml-make-optional-argument "maxlength" maxlength)))) yuuji@59: yuuji@59: (defun yahtml:textarea () yuuji@59: "Add-in function for `textarea'" yuuji@59: (interactive) yuuji@59: (let (name rows cols) yuuji@59: (setq name (read-string "Name: ") yuuji@60: cols (read-string "Columns: ") yuuji@60: rows (read-string "Rows: ")) yuuji@59: (concat yuuji@69: (concat (if yahtml-prefer-upcase-attributes "NAME=" "name=") yuuji@59: "\"" name "\"") yuuji@64: (yahtml-make-optional-argument "cols" cols) yuuji@64: (yahtml-make-optional-argument "rows" rows)))) yuuji@59: yuuji@64: (defun yahtml:table () yuuji@64: "Add-in function for `table'" yuuji@69: (let ((b (read-string "border=")) yuuji@80: (a (yahtml-read-parameter yuuji@80: "align" nil '(("align" ("right")("center")))))) yuuji@80: (if yahtml-html4-strict yuuji@80: (yahtml-make-optional-argument yuuji@80: "style" yuuji@80: (if (or (string< "" b) (string< "" a)) yuuji@80: (yahtml-make-style-parameter yuuji@80: (append yuuji@80: (if (string< "" b) yuuji@80: (list yuuji@80: (cons "border" (format "%dpx solid" (string-to-int b))) yuuji@80: (cons "border-collapse" "collapse"))) yuuji@80: (if (string< "" a) yuuji@80: (cond yuuji@80: ((string-match "right" a) yuuji@80: (list (cons "margin-left" "auto") yuuji@80: (cons "margin-right" "0"))) yuuji@80: ((string-match "center" a) yuuji@80: (list (cons "margin-left" "auto") yuuji@80: (cons "margin-right" "auto"))))))))) yuuji@80: (concat yuuji@80: (yahtml-make-optional-argument "border" b) yuuji@80: (yahtml-make-optional-argument "align" a))))) yuuji@80: yuuji@69: ;(fset 'yahtml:caption 'yahtml:p) yuuji@69: (defun yahtml:caption () yuuji@69: "Add-in function for `caption' in table tag" yuuji@80: (let ((par (yahtml-read-parameter "align"))) yuuji@80: (if yahtml-html4-strict yuuji@80: (yahtml-make-optional-argument yuuji@80: "style" (if par (yahtml-make-style-parameter yuuji@80: (list (cons "caption-side" par))))) yuuji@80: (yahtml-make-optional-argument "align" par)))) yuuji@64: yuuji@64: (defun yahtml:font () yuuji@64: "Add-in function for `font'" yuuji@68: (concat yuuji@68: (yahtml-make-optional-argument "color" (read-string "color=")) yuuji@68: (yahtml-make-optional-argument "size" (read-string "size=")))) yuuji@59: yuuji@69: (defun yahtml:style () yuuji@69: "Add-in function for `style'" yuuji@69: (yahtml-make-optional-argument yuuji@69: "type" (read-string "type=" "text/css"))) yuuji@69: yuuji@80: (defun yahtml:script () yuuji@80: "Add-in function for `script'" yuuji@80: (concat yuuji@80: (yahtml-make-optional-argument yuuji@80: "type" (yahtml-read-parameter "type" "text/javascript")) yuuji@80: (yahtml-make-optional-argument yuuji@80: "src" (yahtml-read-parameter "src" "")))) yuuji@80: yuuji@69: (defun yahtml:tr () yuuji@69: "Add-in function for `tr'" yuuji@69: (setq ;yahtml-last-begend "td" ;; which do you prefer? yuuji@69: yahtml-last-typeface-cmd "td") yuuji@69: "") yuuji@69: yuuji@69: (defun yahtml:link () yuuji@69: "Add-in function for `link' (まだちょっと良く分かってない)" yuuji@69: (let (rel rev type href) yuuji@69: (setq rel (yahtml-read-parameter "rel")) yuuji@69: (cond yuuji@69: ((equal rel "") yuuji@69: (concat (yahtml-make-optional-argument yuuji@69: "rev" (yahtml-read-parameter "rev")) yuuji@69: (yahtml-make-optional-argument yuuji@69: "href" (yahtml-read-parameter "href") yuuji@69: ;;他に良く使うのって何? yuuji@69: ))) yuuji@69: ((string-match "stylesheet" rel) yuuji@69: (concat yuuji@69: (yahtml-make-optional-argument "rel" rel) yuuji@69: (yahtml-make-optional-argument yuuji@69: "type" (yahtml-read-parameter "type" "text/css")) yuuji@69: (progn yuuji@69: (setq href yuuji@69: (read-from-minibuffer "href: " "" yahtml-url-completion-map)) yuuji@69: (if (string< "" href) yuuji@69: (progn yuuji@69: (if (and (file-exists-p (yahtml-url-to-path href)) yuuji@69: (y-or-n-p "Load css symbols now? ")) yuuji@69: (setq yahtml-css-class-alist yuuji@69: (yahtml-css-collect-classes-file yuuji@69: (yahtml-url-to-path href) yahtml-css-class-alist))) yuuji@69: (message "") yuuji@69: (yahtml-make-optional-argument "href" href)))))) yuuji@80: (t yuuji@80: (concat yuuji@80: (yahtml-make-optional-argument "rel" rel) yuuji@80: (yahtml-make-optional-argument yuuji@80: "type" (yahtml-read-parameter "type" "text/css")) yuuji@80: (yahtml-make-optional-argument yuuji@102: "href" yuuji@102: (read-from-minibuffer "href: " "" yahtml-url-completion-map))))))) yuuji@69: yuuji@73: (defvar yahtml:meta-names yuuji@73: '(("name" ("keywords")("author")("copyright")("date")("GENERATOR")))) yuuji@73: yuuji@73: (defun yahtml:meta () yuuji@73: (let ((name (yahtml-make-optional-argument yuuji@73: "name" yuuji@73: (yahtml-read-parameter "name" nil yahtml:meta-names))) yuuji@73: http-equiv content) yuuji@73: (if (string= "" name) yuuji@73: (if (string-match yuuji@73: "Content-type" yuuji@73: (setq http-equiv (yahtml-make-optional-argument yuuji@73: "http-equiv" yuuji@73: (yahtml-read-parameter "http-equiv" nil)))) yuuji@73: (error "It's very bad idea to set Content-type in META. %s" yuuji@73: "See docs/qanda") yuuji@73: (concat http-equiv yuuji@73: (yahtml-make-optional-argument yuuji@73: "content" (yahtml-read-parameter "content")))) yuuji@73: (concat yuuji@73: name yuuji@73: (yahtml-make-optional-argument yuuji@73: "content" yuuji@73: (cond yuuji@73: ((string-match "date" name) yuuji@73: (read-string "Date: " (current-time-string))) yuuji@73: ((string-match "author" name) yuuji@73: (read-string "Author: " yuuji@73: (if (and (user-full-name) (string< "" (user-full-name))) yuuji@73: (user-full-name) yuuji@73: (user-login-name)))) yuuji@73: ((string-match "GENERATOR" name) yuuji@73: (setq content (read-string "Generator: " "User-agent: ")) yuuji@73: (if (string-match "yahtml" content) yuuji@73: (message "Thank you!")) yuuji@73: content) yuuji@73: (t (read-string (concat name ": "))))))))) yuuji@73: yuuji@70: (defun yahtml:br () yuuji@70: (yahtml-make-optional-argument "clear" (yahtml-read-parameter "clear"))) yuuji@70: yuuji@70: (defun yahtml:object () yuuji@70: (let ((codetype (yahtml-read-parameter "codetype" "application/java")) yuuji@70: data classid) yuuji@70: (cond yuuji@70: ((string-match "java" codetype) yuuji@70: (let ((completion-ignored-extensions yuuji@70: ;;any extensions except ".class" yuuji@70: '(".java" ".html" ".htm" ".gif" ".jpg" ".jpeg" ".png"))) yuuji@70: (setq classid (concat "java:" yuuji@70: (yahtml-read-parameter "class file name")))) yuuji@70: (concat yuuji@70: (yahtml-make-optional-argument "codetype" codetype) yuuji@70: (yahtml-make-optional-argument "classid" classid) yuuji@70: (yahtml-make-optional-argument yuuji@70: "width" (yahtml-read-parameter "width")) yuuji@70: (yahtml-make-optional-argument yuuji@70: "height" (yahtml-read-parameter "height")) yuuji@70: (yahtml-make-optional-argument yuuji@102: "align" (yahtml-read-parameter "align")))) yuuji@70: (t yuuji@102: "")))) yuuji@70: yuuji@80: (defun yahtml:abbr () yuuji@80: "Add-in function for abbr." yuuji@80: (yahtml-make-optional-argument "title" (yahtml-read-parameter "title"))) yuuji@80: yuuji@136: (defun yahtml:button () yuuji@136: (concat yuuji@136: (yahtml-make-optional-argument yuuji@136: "name" (yahtml-read-parameter "name")) yuuji@136: (yahtml-make-optional-argument yuuji@136: "type" (yahtml-read-parameter yuuji@137: "type" "button" '(("submit")("reset")("button")))) yuuji@137: (yahtml-make-optional-argument yuuji@137: "value" (yahtml-read-parameter "value")))) yuuji@136: yuuji@59: ;;; ---------- Simple tag ---------- yuuji@58: (defun yahtml-insert-tag (region-mode &optional tag) yuuji@54: "Insert and put cursor inside of them." yuuji@58: (interactive "P") yuuji@70: (setq yahtml-current-completion-type 'inline) yuuji@58: (or tag yuuji@60: (let ((completion-ignore-case t)) yuuji@60: (setq tag yuuji@60: (YaTeX-cplread-with-learning yuuji@64: (format "Tag %s(default %s): " yuuji@60: (if region-mode "region: " "") yahtml-last-typeface-cmd) yuuji@60: 'yahtml-typeface-table 'yahtml-user-typeface-table yuuji@60: 'yahtml-tmp-typeface-table)))) yuuji@58: (if (string= "" tag) (setq tag yahtml-last-typeface-cmd)) yuuji@60: (setq tag (or (cdr (assoc tag yahtml-typeface-table)) tag)) yuuji@60: (setq yahtml-last-typeface-cmd tag yuuji@60: tag (funcall (if yahtml-prefer-upcases 'upcase 'downcase) tag)) yuuji@58: (if region-mode yuuji@58: (if (if (string< "19" emacs-version) (mark t) (mark)) yuuji@58: (save-excursion yuuji@58: (if (> (point) (mark)) (exchange-point-and-mark)) yuuji@60: (insert (format "<%s%s>" tag (yahtml-addin tag))) yuuji@58: (exchange-point-and-mark) yuuji@58: (insert "")) yuuji@58: (message "No mark set now")) yuuji@60: (insert (format "<%s%s>" tag (yahtml-addin tag))) yuuji@58: (save-excursion (insert (format "" tag))))) yuuji@54: yuuji@61: (defun yahtml-insert-tag-region (&optional tag) yuuji@61: "Call yahtml-insert-tag with region mode." yuuji@61: (interactive) yuuji@61: (yahtml-insert-tag t tag)) yuuji@61: yuuji@80: (defvar yahtml-need-single-closer nil) ;for test yuuji@57: (defun yahtml-insert-single (cmd) yuuji@57: "Insert ." yuuji@57: (interactive yuuji@58: (list yuuji@58: (let ((completion-ignore-case t)) yuuji@58: (YaTeX-cplread-with-learning yuuji@58: (format "Command%s: " yuuji@58: (if yahtml-last-single-cmd yuuji@58: (concat "(default " yahtml-last-single-cmd ")") "")) yuuji@58: 'yahtml-single-cmd-table 'yahtml-user-single-cmd-table yuuji@58: 'yahtml-tmp-single-cmd-table)))) yuuji@60: (if (string= "" cmd) (setq cmd yahtml-last-single-cmd)) yuuji@58: (setq yahtml-last-single-cmd yuuji@60: (or (cdr (assoc cmd yahtml-single-cmd-table)) cmd)) yuuji@60: (setq cmd (funcall (if yahtml-prefer-upcases 'upcase 'downcase) yuuji@60: yahtml-last-single-cmd)) yuuji@80: (insert (format "<%s%s%s>" yuuji@80: cmd yuuji@80: (yahtml-addin cmd) yuuji@80: (if (and yahtml-need-single-closer yuuji@80: (assoc cmd '(("br")("hr")))) yuuji@80: " /" ""))) yuuji@80: (if (assoc cmd yahtml-env-table) yuuji@80: (save-excursion (insert (format "" cmd))))) yuuji@57: yuuji@64: (defun yahtml-insert-p (&optional arg) yuuji@64: "Convenient function to insert

      " yuuji@64: (interactive "P") yuuji@80: (if (or yahtml-always-/p arg) (yahtml-insert-tag arg "p") yuuji@68: (yahtml-insert-single "p"))) yuuji@64: yuuji@70: (defun yahtml-insert-amps (arg) yuuji@70: "Insert char-entity references via ampersand" yuuji@70: ;; Thanks; http://www.tsc.co.jp/~asada/html/wdg40_f/entities/ yuuji@70: (interactive "P") yuuji@70: (let*((mess "") c yuuji@70: (list (append yahtml-entity-reference-chars-alist-default yuuji@70: yahtml-entity-reference-chars-alist)) yuuji@70: (l list)) yuuji@70: (while l yuuji@70: (setq mess (format "%s %c" mess (car (car l)) (cdr (car l))) yuuji@70: l (cdr l))) yuuji@70: (message "Char-entity reference: %s SPC=& RET=&; Other=&#..;" mess) yuuji@70: (setq c (read-char)) yuuji@70: (cond yuuji@70: ((equal c (car-safe (assoc c list))) yuuji@70: (insert (format "&%s;" (cdr (assoc c list))))) yuuji@70: ((or (equal c ?\n) (equal c ?\r)) yuuji@70: (insert "&;") yuuji@70: (forward-char -1)) yuuji@70: ((equal c ? ) yuuji@70: (insert ?&)) yuuji@70: (t (insert (format "&#%d;" c)))))) yuuji@70: yuuji@80: (defun yahtml:!--\#include () yuuji@80: (let ((file (yahtml-read-parameter "file" ""))) yuuji@80: (format "%s=\"%s\"--" (if (string-match "/" file) "virtual" "file") file))) yuuji@80: yuuji@80: (defun yahtml:!--\#exec () yuuji@80: (format "cmd=\"%s\"--" (yahtml-read-parameter "cmd" "" '(("cmd" . file))))) yuuji@80: yuuji@57: ;;; ---------- Jump ---------- yuuji@57: (defun yahtml-on-href-p () yuuji@57: "Check if point is on href clause." yuuji@60: (let ((p (point)) e cmd (case-fold-search t)) yuuji@57: (save-excursion yuuji@69: (and ;;(string= (YaTeX-inner-environment t) "a") ;aでなくても許可にした yuuji@60: (save-excursion yuuji@69: ;;(search-forward "
      " nil t) ;aでなくても許可にした yuuji@69: (search-forward "[\" \t\n]" nil t) yuuji@60: (setq e (point))) yuuji@69: ;(goto-char (get 'YaTeX-inner-environment 'point)) yuuji@69: (re-search-backward "<\\(a\\|link\\)\\>" nil t) yuuji@60: (search-forward "href" e t) yuuji@60: (search-forward "=" e t) yuuji@64: (progn yuuji@64: (skip-chars-forward " \t\n") yuuji@64: (looking-at "\"?\\([^\"> \t\n]+\\)\"?")) yuuji@57: (< p (match-end 0)) yuuji@102: (YaTeX-match-string 1))))) yuuji@57: yuuji@58: (defun yahtml-netscape-sentinel (proc mes) yuuji@58: (cond yuuji@58: ((null (buffer-name (process-buffer proc))) yuuji@58: (set-process-buffer proc nil)) yuuji@58: ((eq (process-status proc) 'exit) yuuji@58: (let ((cb (current-buffer))) yuuji@58: (set-buffer (process-buffer proc)) yuuji@58: (goto-char (point-min)) yuuji@58: (if (search-forward "not running" nil t) yuuji@58: (progn yuuji@58: (message "Starting netscape...") yuuji@58: (start-process yuuji@60: "browser" (process-buffer proc) yuuji@60: shell-file-name yahtml-shell-command-option yuuji@60: (format "%s \"%s\"" yahtml-www-browser yuuji@58: (get 'yahtml-netscape-sentinel 'url))) yuuji@58: (message "Starting netscape...Done"))) yuuji@58: (set-buffer cb))))) yuuji@58: yuuji@58: (defvar yahtml-browser-process nil) yuuji@58: yuuji@58: (defun yahtml-browse-html (href) yuuji@58: "Call WWW Browser to see HREF." yuuji@58: (let ((pb "* WWW Browser *") (cb (current-buffer))) yuuji@58: (cond yuuji@64: ((string-match "^start\\>" yahtml-www-browser) yuuji@64: (if (get-buffer pb) yuuji@64: (progn (set-buffer pb) (erase-buffer) (set-buffer cb))) yuuji@64: (put 'yahtml-netscape-sentinel 'url href) yuuji@64: (set-process-sentinel yuuji@64: (setq yahtml-browser-process yuuji@64: (start-process yuuji@64: "browser" pb shell-file-name yahtml-shell-command-option yuuji@64: (format "%s \"%s\"" yahtml-www-browser href))) yuuji@64: 'yahtml-netscape-sentinel)) yuuji@86: ((and (string-match yuuji@86: "[Nn]etscape\\|[Ff]irefox\\|[Mm]ozilla" yahtml-www-browser) yuuji@60: (not (eq system-type 'windows-nt))) yuuji@58: (if (get-buffer pb) yuuji@58: (progn (set-buffer pb) (erase-buffer) (set-buffer cb))) yuuji@58: (put 'yahtml-netscape-sentinel 'url href) yuuji@58: (set-process-sentinel yuuji@58: (setq yahtml-browser-process yuuji@58: (start-process yuuji@60: "browser" pb shell-file-name yahtml-shell-command-option ;"-c" yuuji@60: (format "%s -remote \"openURL(%s)\"" yahtml-www-browser href))) yuuji@58: 'yahtml-netscape-sentinel)) yuuji@58: ((and (string= "w3" yahtml-www-browser) (fboundp 'w3-fetch)) yuuji@58: (w3-fetch href)) yuuji@58: ((stringp yahtml-www-browser) yuuji@60: (if (and yahtml-browser-process yuuji@60: (eq (process-status yahtml-browser-process) 'run)) yuuji@58: (message "%s is already running" yahtml-www-browser) yuuji@58: (setq yahtml-browser-process yuuji@58: (start-process yuuji@60: "browser" "* WWW Browser *" yuuji@60: shell-file-name yahtml-shell-command-option yuuji@60: (format "%s \"%s\"" yahtml-www-browser href))))) yuuji@58: (t yuuji@58: (message "Sorry, jump across http is not supported."))))) yuuji@58: yuuji@57: (defun yahtml-goto-corresponding-href (&optional other) yuuji@57: "Go to corresponding name." yuuji@64: (let ((href (yahtml-on-href-p)) file name (parent buffer-file-name)) yuuji@57: (if href yuuji@57: (cond yuuji@80: ((string-match "^\\(ht\\|f\\)tps?:" href) yuuji@58: (yahtml-browse-html href)) yuuji@57: (t (setq file (substring href 0 (string-match "#" href))) yuuji@57: (if (string-match "#" href) yuuji@57: (setq name (substring href (1+ (string-match "#" href))))) yuuji@57: (if (string< "" file) yuuji@57: (progn yuuji@57: (if (string-match "/$" file) yuuji@70: (or (catch 'dirindex yuuji@70: (mapcar yuuji@72: (function yuuji@72: (lambda (f) yuuji@72: (if (file-exists-p (concat file f)) yuuji@72: (throw 'dirindex yuuji@72: (setq file (concat file f)))))) yuuji@73: (yahtml-get-directory-index)) yuuji@73: nil) yuuji@70: (setq file (concat file yahtml-directory-index)))) yuuji@58: (if (string-match "^/" file) yuuji@58: (setq file (yahtml-url-to-path file))) yuuji@57: (if other (YaTeX-switch-to-buffer-other-window file) yuuji@64: (YaTeX-switch-to-buffer file)) yuuji@64: (or YaTeX-parent-file (setq YaTeX-parent-file parent)))) yuuji@57: (if name yuuji@57: (progn (set-mark-command nil) (yahtml-jump-to-name name))) yuuji@57: t))))) yuuji@57: yuuji@57: (defun yahtml-jump-to-name (name) yuuji@57: "Jump to html's named tag." yuuji@69: (setq name (format "\\(name\\|id\\)\\s *=\\s *\"?%s\\>\"?" name)) yuuji@57: (or (and (re-search-forward name nil t) (goto-char (match-beginning 0))) yuuji@57: (and (re-search-backward name nil t) (goto-char (match-beginning 0))) yuuji@57: (message "Named tag `%s' not found" (substring href 1)))) yuuji@57: yuuji@57: (defun yahtml-on-begend-p (&optional p) yuuji@57: "Check if point is on begend clause." yuuji@60: (let ((p (or p (point))) cmd (case-fold-search t)) yuuji@57: (save-excursion yuuji@60: (goto-char p) yuuji@58: (if (equal (char-after (point)) ?<) (forward-char 1)) yuuji@57: (if (and (re-search-backward "<" nil t) yuuji@57: (looking-at yuuji@70: ;(concat "<\\(/?" yahtml-struct-name-regexp "\\)\\b") yuuji@102: "<\\(/?[A-Z][A-Z0-9]*\\)\\b") yuuji@57: (condition-case nil yuuji@58: (forward-list 1) yuuji@58: (error nil)) yuuji@57: (< p (point))) yuuji@57: (YaTeX-match-string 1))))) yuuji@57: yuuji@58: (defun yahtml-goto-corresponding-begend (&optional noerr) yuuji@58: "Go to corresponding opening/closing tag. yuuji@58: Optional argument NOERR causes no error for unballanced tag." yuuji@58: (let ((cmd (yahtml-on-begend-p)) m0 yuuji@58: (p (point)) (case-fold-search t) func str (nest 0)) yuuji@58: (cond yuuji@58: (cmd yuuji@58: (setq m0 (match-beginning 0)) yuuji@58: (if (= (aref cmd 0) ?/) ;on line yuuji@58: (setq cmd (substring cmd 1) yuuji@58: str (format "\\(<%s\\)\\|\\(= nest 0) (funcall func str nil t)) yuuji@58: (if (equal m0 (match-beginning 0)) yuuji@58: nil yuuji@58: (setq nest (+ nest (if (match-beginning 1) -1 1))))) yuuji@58: (if (< nest 0) yuuji@58: (goto-char (match-beginning 0)) yuuji@58: (funcall yuuji@58: (if noerr 'message 'error) yuuji@58: "Corresponding tag of `%s' not found." cmd) yuuji@58: (goto-char p) yuuji@58: nil)) yuuji@58: (t nil)))) yuuji@58: yuuji@58: (defun yahtml-current-tag () yuuji@80: "Return the current tag name including #exec and #include." yuuji@58: (save-excursion yuuji@58: (let ((p (point)) b tag) yuuji@58: (or (bobp) yuuji@58: (looking-at "<") yuuji@58: (progn (skip-chars-backward "^<") (forward-char -1))) yuuji@58: (setq b (point)) yuuji@58: (skip-chars-forward "<") yuuji@80: (setq tag (YaTeX-buffer-substring yuuji@58: (point) (progn (skip-chars-forward "^ \t\n") (point)))) yuuji@58: (goto-char b) yuuji@58: (forward-list 1) yuuji@58: (and (< p (point)) tag)))) yuuji@58: yuuji@68: (defun yahtml-get-attrvalue (attr) yuuji@68: "Extract current tag's attribute value from buffer." yuuji@68: (let (e (case-fold-search t)) yuuji@68: (save-excursion yuuji@68: (or (looking-at "<") yuuji@68: (progn (skip-chars-backward "^<") (backward-char 1))) yuuji@68: (setq e (save-excursion (forward-list 1) (point))) yuuji@68: (if (and yuuji@68: (re-search-forward (concat "\\b" attr "\\b") e t) yuuji@68: (progn (skip-chars-forward " \t\n=") yuuji@68: (looking-at "\"?\\([^\"> \t\n]+\\)\"?"))) yuuji@68: (YaTeX-match-string 1))))) yuuji@68: yuuji@80: (defun yahtml-goto-corresponding-img () yuuji@80: "View image on point" yuuji@80: (let ((tag (yahtml-current-tag)) image (p (point)) (case-fold-search t)) yuuji@80: (if (and tag yuuji@80: (string-match "img" tag) yuuji@80: (setq image (yahtml-get-attrvalue "src"))) yuuji@80: (progn yuuji@80: (message "Invoking %s %s..." yahtml-image-viewer image) yuuji@80: (start-process yuuji@80: "Viewer" " * Image Viewer *" yuuji@80: shell-file-name yahtml-shell-command-option ;"-c" yuuji@80: (concat yahtml-image-viewer " " image)) yuuji@80: (message "Invoking %s %s...Done" yahtml-image-viewer image))))) yuuji@80: yuuji@68: (defun yahtml-goto-corresponding-source (&optional other) yuuji@80: "Goto applet's or script's source." yuuji@68: (let ((env (yahtml-current-tag)) s (p (point))) yuuji@68: (cond yuuji@68: ((string-match "applet" env) yuuji@68: (if (setq s (yahtml-get-attrvalue "code")) yuuji@68: (progn yuuji@68: (setq s (YaTeX-match-string 1) yuuji@68: s (concat yuuji@68: (substring s 0 (string-match "\\.[A-Za-z]+$" s)) yuuji@68: ".java")) yuuji@68: (if other (YaTeX-switch-to-buffer-other-window s) yuuji@68: (YaTeX-switch-to-buffer s)) yuuji@68: s) ;return source file name yuuji@68: (message "No applet source specified") yuuji@68: (sit-for 1) yuuji@68: nil)) yuuji@80: ((string-match "script" env) yuuji@80: (if (setq s (yahtml-get-attrvalue "src")) yuuji@80: (progn yuuji@80: (funcall (if other 'YaTeX-switch-to-buffer-other-window yuuji@80: 'YaTeX-switch-to-buffer) yuuji@80: (yahtml-url-to-path s)) yuuji@80: s))) yuuji@68: ((string-match "!--#include" env) yuuji@68: (cond yuuji@68: ((setq s (yahtml-get-attrvalue "file")) ; yuuji@68: (if other (YaTeX-switch-to-buffer-other-window s) yuuji@68: (YaTeX-switch-to-buffer s)) yuuji@68: s) yuuji@68: ((setq s (yahtml-get-attrvalue "virtual")); yuuji@68: (setq s (yahtml-url-to-path s)) yuuji@68: (if other (YaTeX-switch-to-buffer-other-window s) yuuji@68: (YaTeX-switch-to-buffer s)) yuuji@68: s))) yuuji@68: ((and (string-match "!--#exec" env) yuuji@68: (setq s (yahtml-get-attrvalue "cmd"))) yuuji@68: (setq s (substring s 0 (string-match " \t\\?" s))) ;get argv0 yuuji@68: (let ((b " *yahtmltmp*")) ;peek a little yuuji@68: (unwind-protect yuuji@68: (progn yuuji@68: (set-buffer (get-buffer-create b)) yuuji@70: (YaTeX-insert-file-contents s nil 0 100) yuuji@68: (if (looking-at "#!") yuuji@68: (if other (YaTeX-switch-to-buffer-other-window s) yuuji@68: (YaTeX-switch-to-buffer s)))) yuuji@68: (kill-buffer (get-buffer b))) yuuji@68: (get-file-buffer s)))))) yuuji@68: yuuji@57: (defun yahtml-goto-corresponding-* (&optional other) yuuji@57: "Go to corresponding object." yuuji@80: (interactive "P") yuuji@57: (cond yuuji@57: ((yahtml-goto-corresponding-href other)) yuuji@58: ((yahtml-goto-corresponding-img)) yuuji@80: ((yahtml-goto-corresponding-source other)) yuuji@58: ((yahtml-goto-corresponding-begend)) yuuji@102: (t (message "I don't know where to go.")))) yuuji@57: yuuji@57: (defun yahtml-goto-corresponding-*-other-window () yuuji@57: "Go to corresponding object." yuuji@57: (interactive) yuuji@57: (yahtml-goto-corresponding-* t)) yuuji@57: yuuji@64: (defun yahtml-visit-main () yuuji@64: "Go to parent file from where you visit current file." yuuji@64: (interactive) yuuji@64: (if YaTeX-parent-file (YaTeX-switch-to-buffer YaTeX-parent-file))) yuuji@64: yuuji@58: ;;; ---------- killing ---------- yuuji@58: (defun yahtml-kill-begend (&optional whole) yuuji@68: (let ((tag (yahtml-on-begend-p)) p q r bbolp) yuuji@58: (if tag yuuji@64: (save-excursion yuuji@58: (or (looking-at "<") yuuji@58: (progn (skip-chars-backward "^<") (forward-char -1))) yuuji@64: (setq p (point)) yuuji@58: (yahtml-goto-corresponding-begend) yuuji@58: (or (looking-at "<") yuuji@58: (progn (skip-chars-backward "^<") (forward-char -1))) yuuji@64: (if (< (point) p) ;if on the opening tag yuuji@64: (progn (setq q p p (point)) yuuji@64: (goto-char q)) yuuji@64: (setq q (point))) ;now q has end-line's (point) yuuji@64: (if (not whole) yuuji@64: (kill-region yuuji@68: (progn (skip-chars-backward " \t") yuuji@68: (if (setq bbolp (bolp)) (point) q)) yuuji@64: (progn (forward-list 1) yuuji@64: (setq r (point)) yuuji@64: (skip-chars-forward " \t") yuuji@68: (if (and bbolp (eolp) (not (eobp))) (1+ (point)) r)))) yuuji@58: (goto-char p) yuuji@64: (skip-chars-backward " \t") yuuji@64: (if (not whole) yuuji@64: (progn yuuji@64: (kill-append yuuji@64: (buffer-substring yuuji@68: (setq p (if (setq bbolp (bolp)) (point) p)) yuuji@64: (setq q (progn yuuji@64: (forward-list 1) yuuji@64: (setq r (point)) yuuji@64: (skip-chars-forward " \t") yuuji@68: (if (and bbolp (eolp) (not (eobp))) yuuji@68: (1+ (point)) yuuji@68: r)))) yuuji@64: t) yuuji@64: (delete-region p q)) yuuji@64: (kill-region yuuji@64: (if (bolp) (point) p) yuuji@64: (progn (goto-char q) yuuji@64: (forward-list 1) yuuji@64: (setq r (point)) yuuji@64: (skip-chars-forward " \t") yuuji@64: (if (and (eolp) (not (eobp))) (1+ (point)) r)))) yuuji@58: tag)))) yuuji@58: yuuji@58: (defun yahtml-kill-* (whole) yuuji@58: "Kill current position's HTML tag (set)." yuuji@58: (interactive "P") yuuji@58: (cond yuuji@102: ((yahtml-kill-begend whole)))) yuuji@58: yuuji@58: yuuji@58: ;;; ---------- changing ---------- yuuji@60: (defun yahtml-on-assignment-p () yuuji@60: "Return if current point is on parameter assignment. yuuji@60: If so, return parameter name, otherwise nil. yuuji@60: This function should be able to treat white spaces in value, but not yet." yuuji@60: (let ((p (point))) yuuji@60: (save-excursion yuuji@60: (put 'yahtml-on-assignment-p 'region nil) yuuji@70: (skip-chars-backward "^ \t\n") yuuji@60: (and (looking-at "\\([A-Za-z0-9]+\\)\\s *=\\s *\"?\\([^ \t\"]+\\)\"?") yuuji@60: (< p (match-end 0)) yuuji@60: (>= p (1- (match-beginning 2))) yuuji@60: (put 'yahtml-on-assignment-p 'region yuuji@60: (cons (match-beginning 2) (match-end 2))) yuuji@60: (YaTeX-match-string 1))))) yuuji@60: yuuji@58: (defun yahtml-change-begend () yuuji@58: (let ((tag (yahtml-on-begend-p)) yuuji@58: (completion-ignore-case t) yuuji@60: (case-fold-search t) yuuji@58: (p (point)) (q (make-marker)) yuuji@58: (default (append yahtml-env-table yahtml-typeface-table)) yuuji@58: (user (append yahtml-user-env-table yahtml-user-typeface-table)) yuuji@58: (tmp (append yahtml-tmp-env-table yahtml-tmp-typeface-table)) yuuji@69: href b1 e1 attr new css) yuuji@59: (cond yuuji@59: (tag yuuji@59: (cond yuuji@60: ((and (string-match "^a$" tag) yuuji@59: (save-excursion yuuji@59: (and yuuji@60: (re-search-backward "" nil t)) yuuji@60: (setq e1 (match-beginning 0)) yuuji@60: (goto-char b1) yuuji@60: (re-search-forward "href\\s *=" e1 t) yuuji@59: (>= p (point)) yuuji@64: (progn yuuji@64: (goto-char (match-end 0)) yuuji@64: (skip-chars-forward " \t\n") yuuji@64: (looking-at "\"?\\([^\"> \t\n]+\\)\"?")) yuuji@59: (< p (match-end 0))))) yuuji@59: (setq b1 (match-beginning 1) e1 (match-end 1) yuuji@60: yahtml-completing-buffer (current-buffer) yuuji@64: ;; yahtml-urls-local is buffer-local, so we must put yuuji@64: ;; that into yahtml-urls here yuuji@64: yahtml-urls (append yahtml-urls-private yahtml-urls-local) yuuji@59: href (read-from-minibuffer yuuji@59: "Change href to: " "" yahtml-url-completion-map)) yuuji@59: (if (string< "" href) yuuji@59: (progn yuuji@60: ;;(setq href ;?? yuuji@60: ;; (if yahtml-prefer-upcases (upcase href) (downcase href))) yuuji@59: (delete-region b1 e1) yuuji@59: (goto-char b1) yuuji@59: (insert href)))) yuuji@69: ((setq attr (yahtml-on-assignment-p)) ;if on the assignment to attr yuuji@69: (if (and (equal attr "class") ;treat "class" attribute specially yuuji@70: (setq css (yahtml-css-get-element-completion-alist tag))) yuuji@80: yuuji@80: (setq new (yahtml-read-css css)) yuuji@69: ;;other than "class", read parameter normally yuuji@69: (setq new (yahtml-read-parameter attr))) yuuji@69: (goto-char (car (get 'yahtml-on-assignment-p 'region))) yuuji@69: (delete-region (point) (cdr (get 'yahtml-on-assignment-p 'region))) yuuji@69: (insert new)) yuuji@59: (t yuuji@58: (save-excursion yuuji@58: (if (= (aref tag 0) ?/) (setq tag (substring tag 1))) yuuji@58: (or (= (char-after (point)) ?<) (skip-chars-backward "^<")) yuuji@58: (skip-chars-forward "^A-Za-z") yuuji@58: (set-marker q (point)) yuuji@58: (setq p (point)) yuuji@58: (yahtml-goto-corresponding-begend) yuuji@58: (or (= (char-after (point)) ?<) yuuji@58: (skip-chars-backward "^<")) yuuji@58: (skip-chars-forward "^A-Za-z") yuuji@58: (if (= (char-after (1- (point))) ?/) yuuji@58: (progn yuuji@58: (set-marker q (point)) yuuji@58: (goto-char p))) yuuji@60: (setq tag (let ((completion-ignore-case t)) yuuji@60: (YaTeX-cplread-with-learning yuuji@60: (format "Change `%s' to(default %s): " yuuji@60: tag yahtml-last-begend) yuuji@60: 'default 'user 'tmp))) yuuji@58: (delete-region (point) (progn (skip-chars-forward "^>") (point))) yuuji@58: (if (string= "" tag) (setq tag yahtml-last-begend)) yuuji@58: (setq yahtml-last-begend yuuji@58: (or (cdr (assoc tag yahtml-env-table)) tag) yuuji@58: tag yahtml-last-begend) yuuji@60: (setq tag (if yahtml-prefer-upcases (upcase tag) (downcase tag))) yuuji@58: (insert (format "%s%s" tag (yahtml-addin tag))) yuuji@58: (goto-char q) yuuji@68: (set-marker q nil) yuuji@58: (delete-region (point) (progn (skip-chars-forward "^>") (point))) yuuji@60: (insert tag)))) yuuji@60: t)))) yuuji@60: yuuji@60: (defun yahtml-change-command () yuuji@60: (let ((p (point)) (case-fold-search t) cmd par new yuuji@60: (beg (make-marker)) (end (make-marker))) yuuji@60: (skip-chars-backward "^<") yuuji@60: (if (and yuuji@60: (looking-at yahtml-command-regexp) yuuji@60: (progn yuuji@60: (set-marker beg (match-beginning 0)) yuuji@60: (set-marker end (match-end 0)) yuuji@60: t) ;for further work yuuji@60: (progn yuuji@60: (forward-char -1) yuuji@60: (condition-case nil yuuji@60: (forward-list 1) yuuji@60: (error nil)) yuuji@60: (< p (point)))) yuuji@60: (progn yuuji@60: (goto-char p) yuuji@60: (if (setq par (yahtml-on-assignment-p)) yuuji@60: (progn yuuji@60: (setq new (yahtml-read-parameter par)) yuuji@60: (set-marker beg (car (get 'yahtml-on-assignment-p 'region))) yuuji@60: (set-marker end (cdr (get 'yahtml-on-assignment-p 'region)))) yuuji@60: (setq new yuuji@60: (YaTeX-cplread-with-learning yuuji@60: "Change form to: " yuuji@60: 'yahtml-form-table 'yahtml-user-form-table yuuji@60: 'yahtml-tmp-form-table))) yuuji@60: (delete-region beg end) yuuji@60: (goto-char beg) yuuji@68: (set-marker beg nil) yuuji@68: (set-marker end nil) yuuji@60: (insert new) yuuji@60: t) yuuji@60: (goto-char p) yuuji@60: nil))) yuuji@58: yuuji@58: (defun yahtml-change-* () yuuji@58: "Change current position's HTML tag (set)." yuuji@58: (interactive) yuuji@58: (cond yuuji@58: ((yahtml-change-begend)) yuuji@102: ((yahtml-change-command)))) yuuji@58: yuuji@57: ;;; ---------- commenting ---------- yuuji@69: yuuji@64: (defun yahtml-comment-region (&optional uncom) yuuji@64: "Comment out region or environment." yuuji@64: (interactive) yuuji@72: (let ((e (make-marker)) be beg p) yuuji@64: (cond yuuji@72: (;(marker-position (set-marker e (yahtml-on-begend-p))) yuuji@72: (setq be (yahtml-on-begend-p)) yuuji@64: (save-excursion yuuji@64: (setq p (point)) yuuji@72: (if (string-match "^/" be) yuuji@64: (setq beg (progn (forward-line 1) (point))) yuuji@64: (setq beg (progn (beginning-of-line) (point)))) yuuji@64: (goto-char p) yuuji@64: (yahtml-goto-corresponding-begend) yuuji@72: (if (string-match "^/" be) yuuji@64: (beginning-of-line) yuuji@64: (forward-line 1)) yuuji@69: (set-marker e (point)) yuuji@102: ;(comment-region beg (point) (if uncom (list 4))))) yuuji@103: )) yuuji@69: (t ;(comment-region (region-beginning) (region-end) (if uncom (list 4))) yuuji@69: (setq beg (region-beginning)) yuuji@69: (set-marker e (region-end)))) yuuji@69: (if yahtml-translate-hyphens-when-comment-region yuuji@69: (let ((yahtml-entity-reference-chars-alist-default nil) yuuji@69: (yahtml-entity-reference-chars-alist '((?- . "#45"))) yuuji@69: yahtml-entity-reference-chars-regexp yuuji@69: yahtml-entity-reference-chars-reverse-regexp) yuuji@69: (yahtml-entity-reference-chars-setup) yuuji@69: (funcall yuuji@69: (if uncom 'yahtml-translate-reverse-region yuuji@69: 'yahtml-translate-region) yuuji@69: beg e))) yuuji@69: (comment-region beg e (if uncom (list 4))) yuuji@69: (set-marker e nil))) yuuji@57: yuuji@64: (defun yahtml-uncomment-region () yuuji@64: (interactive) yuuji@64: (yahtml-comment-region t)) yuuji@57: yuuji@69: ;;; ---------- translate to entity references ---------- yuuji@69: (defvar yahtml-entity-reference-chars-alist-default yuuji@69: ;'((?> . "gt") (?< . "lt") (?& . "amp") (?\" . "quot") (?' . "apos")) yuuji@69: '((?> . "gt") (?< . "lt") (?& . "amp") (?\" . "quot")) yuuji@69: "Default translation table from character to entity reference") yuuji@69: (defvar yahtml-entity-reference-chars-alist nil yuuji@69: "*Translation table from character to entity reference") yuuji@69: (defvar yahtml-entity-reference-chars-regexp nil) yuuji@69: (defvar yahtml-entity-reference-chars-reverse-regexp nil) yuuji@57: yuuji@69: (defun yahtml-entity-reference-chars-setup () yuuji@69: (let ((list (append yahtml-entity-reference-chars-alist-default yuuji@69: yahtml-entity-reference-chars-alist))) yuuji@69: (setq yahtml-entity-reference-chars-regexp "[" yuuji@69: yahtml-entity-reference-chars-reverse-regexp "&\\(") yuuji@69: (while list yuuji@69: (setq yahtml-entity-reference-chars-regexp yuuji@69: (concat yahtml-entity-reference-chars-regexp yuuji@69: (char-to-string (car (car list)))) yuuji@69: yahtml-entity-reference-chars-reverse-regexp yuuji@69: (concat yahtml-entity-reference-chars-reverse-regexp yuuji@69: (cdr (car list)) yuuji@69: (if (cdr list) "\\|"))) yuuji@69: (setq list (cdr list))) yuuji@69: (setq yahtml-entity-reference-chars-regexp yuuji@69: (concat yahtml-entity-reference-chars-regexp "]") yuuji@69: yahtml-entity-reference-chars-reverse-regexp yuuji@69: (concat yahtml-entity-reference-chars-reverse-regexp "\\);")))) yuuji@69: yuuji@69: (yahtml-entity-reference-chars-setup) yuuji@69: yuuji@69: (defun yahtml-translate-region (beg end) yuuji@69: "Translate inhibited literals." yuuji@69: (interactive "r") yuuji@69: (save-excursion yuuji@69: (save-restriction yuuji@69: (narrow-to-region beg end) yuuji@69: (let ((ct (append yahtml-entity-reference-chars-alist yuuji@69: yahtml-entity-reference-chars-alist-default))) yuuji@69: (goto-char beg) yuuji@69: (while (re-search-forward yahtml-entity-reference-chars-regexp nil t) yuuji@69: ;(setq c (preceding-char)) yuuji@69: (replace-match yuuji@69: (concat "&" (cdr (assoc (preceding-char) ct)) ";"))))))) yuuji@69: yuuji@69: (defun yahtml-translate-reverse-region (beg end) yuuji@69: "Translate entity references to literals." yuuji@69: (interactive "r") yuuji@69: (save-excursion yuuji@69: (save-restriction yuuji@69: (narrow-to-region beg end) yuuji@69: (let ((ct (append yahtml-entity-reference-chars-alist yuuji@69: yahtml-entity-reference-chars-alist-default)) yuuji@69: ec) yuuji@69: (goto-char beg) yuuji@69: (while (re-search-forward yuuji@69: yahtml-entity-reference-chars-reverse-regexp nil t) yuuji@69: ;(setq c (preceding-char)) yuuji@69: (setq ec (YaTeX-match-string 1)) yuuji@69: (delete-region (match-end 0) (match-beginning 0)) yuuji@69: (insert (car (YaTeX-rassoc ec ct)))))))) yuuji@57: yuuji@60: (defun yahtml-inner-environment-but (exclude &optional quick) yuuji@60: "Return the inner environment but matches with EXCLUDE tag." yuuji@64: (let (e (case-fold-search t)) yuuji@60: (save-excursion yuuji@60: (while (and (setq e (YaTeX-inner-environment quick)) yuuji@60: (string-match exclude e)) yuuji@60: (goto-char (get 'YaTeX-inner-environment 'point)))) yuuji@60: e)) yuuji@60: yuuji@58: ;;; ---------- filling ---------- yuuji@60: (defvar yahtml-saved-move-to-column (symbol-function 'move-to-column)) yuuji@60: (defun yahtml-move-to-column (col &optional force) yuuji@60: (beginning-of-line) yuuji@60: (let ((ccol 0)) yuuji@60: (while (and (> col ccol) (not (eolp))) yuuji@60: (if (eq (following-char) ?\<) yuuji@60: (progn yuuji@60: (while (and (not (eq (following-char) ?\>)) yuuji@60: (not (eolp))) yuuji@60: (forward-char)) yuuji@60: (or (eolp) (forward-char))) yuuji@60: (or (eolp) (forward-char)) yuuji@60: (if (eq (preceding-char) ?\t) yuuji@60: (let ((wd (- 8 (% (+ ccol 8) 8)))) yuuji@60: (if (and force (< col (+ ccol wd))) yuuji@60: (progn yuuji@60: (backward-char 1) yuuji@60: (insert-char ?\ (- col ccol)) yuuji@60: (setq ccol col)) yuuji@60: (setq ccol (+ ccol wd)))) yuuji@60: (setq ccol (1+ ccol))) yuuji@60: (if (and YaTeX-japan yuuji@69: (or yuuji@69: (and (fboundp 'char-category) yuuji@69: (string-match "[chj]" (char-category (preceding-char)))) yuuji@69: (and (fboundp 'char-charset) yuuji@69: (not (eq (char-charset (preceding-char)) 'ascii))))) yuuji@60: (setq ccol (1+ ccol))))) yuuji@60: (if (and force (> col ccol)) yuuji@60: (progn yuuji@60: (insert-char ?\ (- col ccol)) yuuji@60: col) yuuji@60: ccol))) yuuji@60: yuuji@58: (defun yahtml-fill-paragraph (arg) yuuji@58: (interactive "P") yuuji@68: (let*((case-fold-search t) (p (point)) fill-prefix yuuji@61: (e (or (yahtml-inner-environment-but "^\\(a\\|p\\)\\b" t) "html")) yuuji@68: indent yuuji@68: (startp (get 'YaTeX-inner-environment 'point)) yuuji@60: (prep (string-match "^pre$" e)) yuuji@60: (ps1 (if prep (default-value 'paragraph-start) yuuji@60: paragraph-start)) yuuji@60: (ps2 (if prep (concat (default-value 'paragraph-start) yuuji@69: "$\\|^\\s *") yuuji@60: paragraph-start))) yuuji@58: (save-excursion yuuji@60: (unwind-protect yuuji@60: (progn yuuji@60: (if prep yuuji@60: (fset 'move-to-column 'yahtml-move-to-column)) yuuji@68: (save-excursion yuuji@68: (beginning-of-line) yuuji@68: (indent-to-column (yahtml-this-indent)) yuuji@68: (setq fill-prefix yuuji@68: (buffer-substring (point) (point-beginning-of-line))) yuuji@68: (delete-region (point) (point-beginning-of-line))) yuuji@60: (fill-region-as-paragraph yuuji@60: (progn (re-search-backward paragraph-start nil t) yuuji@60: (or (save-excursion yuuji@64: (goto-char (match-beginning 0)) yuuji@64: (if (looking-at "<") yuuji@64: (forward-list) yuuji@64: (goto-char (match-end 0)) yuuji@64: (skip-chars-forward " \t>")) yuuji@60: (if (looking-at "[ \t]*$") yuuji@60: (progn (forward-line 1) (point)))) yuuji@60: (point))) yuuji@60: (progn (goto-char p) yuuji@60: (re-search-forward ps2 nil t) yuuji@69: (match-beginning 0)))) yuuji@60: (fset 'move-to-column yahtml-saved-move-to-column))))) yuuji@60: yuuji@60: ;(defun yahtml-indent-new-commnet-line () yuuji@60: ; (unwind-protect yuuji@60: ; (progn yuuji@60: ; (fset 'move-to-column 'yahtml-move-to-column) yuuji@60: ; (apply 'YaTeX-saved-indent-new-comment-line (if soft (list soft)))) yuuji@60: ; (fset 'move-to-column yahtml-saved-move-to-column))) yuuji@58: yuuji@58: ;;; yuuji@58: ;;; ---------- indentation ---------- yuuji@58: ;;; yuuji@58: (defun yahtml-indent-line () yuuji@64: "Indent a line (faster wrapper)" yuuji@58: (interactive) yuuji@64: (let (indent) yuuji@64: (if (and (save-excursion yuuji@64: (beginning-of-line) (skip-chars-forward "\t ") yuuji@64: (not (looking-at "<"))) yuuji@64: (save-excursion yuuji@64: (forward-line -1) yuuji@64: (while (and (not (bobp)) (looking-at "^\\s *$")) yuuji@64: (forward-line -1)) yuuji@64: (skip-chars-forward "\t ") yuuji@64: (setq indent (current-column)) yuuji@64: (not (looking-at "<")))) yuuji@64: (progn yuuji@64: (save-excursion yuuji@64: (beginning-of-line) yuuji@64: (skip-chars-forward " \t") yuuji@64: (or (= (current-column) indent) yuuji@64: (YaTeX-reindent indent))) yuuji@64: (and (bolp) (skip-chars-forward " \t"))) yuuji@64: (yahtml-indent-line-real)))) yuuji@64: yuuji@68: (defun yahtml-this-indent () yuuji@68: (let ((envs "[uod]l\\|table\\|[ht][rhd0-6]\\|select\\|blockquote\\|center\\|menu\\|dir\\|font") yuuji@64: (itemizing-envs "^\\([uod]l\\|menu\\|dir\\)$") yuuji@61: (itms "<\\(dt\\|dd\\|li\\|t[rdh]\\|option\\)\\b") yuuji@70: (excludes yuuji@73: "\\(a\\|p\\|span\\|code\\|tt\\|em\\|u\\|i\\|big\\|small\\|font\\)\\b") yuuji@58: inenv p col peol (case-fold-search t)) yuuji@58: (save-excursion yuuji@58: (beginning-of-line) yuuji@70: (setq inenv (or (yahtml-inner-environment-but excludes t) yuuji@61: "html") yuuji@58: col (get 'YaTeX-inner-environment 'indent) yuuji@58: p (get 'YaTeX-inner-environment 'point) yuuji@64: op nil)) yuuji@58: (save-excursion yuuji@58: (cond yuuji@70: ((string-match (concat "^\\(" envs "\\)") inenv) yuuji@58: (save-excursion yuuji@58: (beginning-of-line) yuuji@58: (skip-chars-forward " \t") yuuji@64: (cond ;lookup current line's tag yuuji@58: ((looking-at (concat "")) yuuji@68: col) yuuji@64: ((looking-at itms) yuuji@68: (+ col yahtml-environment-indent)) yuuji@64: ((and yahtml-hate-too-deep-indentation yuuji@64: (looking-at (concat "<\\(" envs "\\)"))) yuuji@68: (+ col (* 2 yahtml-environment-indent))) yuuji@58: ((and (< p (point)) yuuji@64: (string-match itemizing-envs inenv) yuuji@58: (save-excursion yuuji@58: (and yuuji@58: (setq op (point)) yuuji@58: (goto-char p) yuuji@58: (re-search-forward itms op t) yuuji@64: (progn yuuji@73: (if yahtml-indent-listing-constant yuuji@73: (setq col (+ (current-column) yuuji@73: (if yahtml-faithful-to-htmllint 1 2))) yuuji@73: (skip-chars-forward "^>") yuuji@73: (skip-chars-forward ">") yuuji@73: (skip-chars-forward " \t") yuuji@73: (setq col (if (looking-at "$") yuuji@73: (+ col yahtml-environment-indent) yuuji@73: (current-column)))))))) yuuji@68: col) yuuji@58: (t yuuji@68: (+ col yahtml-environment-indent))))) yuuji@68: (t col))))) yuuji@68: yuuji@68: (defun yahtml-indent-line-real () yuuji@68: "Indent current line." yuuji@68: (interactive) yuuji@68: (YaTeX-reindent (yahtml-this-indent)) yuuji@68: (if (bolp) (skip-chars-forward " \t")) yuuji@70: (let (peol col inenv) yuuji@68: (if (and (setq inenv (yahtml-on-begend-p)) yuuji@68: (string-match yuuji@68: (concat "^\\<\\(" yahtml-struct-name-regexp "\\)") inenv)) yuuji@68: (save-excursion yuuji@68: (setq peol (point-end-of-line)) yuuji@68: (or (= (char-after (point)) ?<) yuuji@68: (progn (skip-chars-backward "^<") (forward-char -1))) yuuji@68: (setq col (current-column)) yuuji@68: (if (and (yahtml-goto-corresponding-begend t) yuuji@68: (> (point) peol)) ;if on the different line yuuji@68: (YaTeX-reindent col)))))) yuuji@58: yuuji@58: ;(defun yahtml-fill-item () yuuji@58: ; "Fill item HTML version" yuuji@58: ; (interactive) yuuji@58: ; (let (inenv p fill-prefix peol (case-fold-search t)) yuuji@58: ; (setq inenv (or (YaTeX-inner-environment) "html") yuuji@58: ; p (get 'YaTeX-inner-environment 'point)) yuuji@58: ; (cond yuuji@58: ; ((string-match "^[uod]l" inenv) yuuji@58: ; (save-excursion yuuji@58: ; (if (re-search-backward "<\\(d[td]\\|li\\)>[ \t\n]*" p t) yuuji@58: ; (progn yuuji@58: ; (goto-char (match-end 0)) yuuji@58: ; (setq col (current-column))) yuuji@58: ; (error "No
    1. ,
      ,
      "))) yuuji@58: ; (save-excursion yuuji@58: ; (end-of-line) yuuji@58: ; (setq peol (point)) yuuji@58: ; (newline) yuuji@58: ; (indent-to-column col) yuuji@58: ; (setq fill-prefix (buffer-substring (point) (1+ peol))) yuuji@58: ; (delete-region (point) peol) yuuji@58: ; (fill-region-as-paragraph yuuji@58: ; (progn (re-search-backward paragraph-start nil t) (point)) yuuji@58: ; (progn (re-search-forward paragraph-start nil t 2) yuuji@58: ; (match-beginning 0))))) yuuji@58: ; (t nil)))) yuuji@58: yuuji@58: ;;; yuuji@60: ;;; ---------- Lint and Browsing ---------- yuuji@58: ;;; yuuji@58: (defun yahtml-browse-menu () yuuji@138: "Browsing or other external process invokation menu." yuuji@58: (interactive) yuuji@138: (message "J)weblint p)Browse R)eload N)ewpage...") yuuji@58: (let ((c (char-to-string (read-char)))) yuuji@58: (cond yuuji@60: ((string-match "j" c) yuuji@60: (yahtml-lint-buffer (current-buffer))) yuuji@60: ((string-match "[bp]" c) yuuji@58: (yahtml-browse-current-file)) yuuji@58: ((string-match "r" c) yuuji@138: (yahtml-browse-reload)) yuuji@138: ((string-match "n" c) yuuji@138: (call-interactively 'yahtml-newpage))))) yuuji@58: yuuji@72: (if (fboundp 'wrap-function-to-control-ime) yuuji@72: (wrap-function-to-control-ime 'yahtml-browse-menu t nil)) yuuji@72: yuuji@60: (defvar yahtml-lint-buffer "*weblint*") yuuji@60: yuuji@60: (defun yahtml-lint-buffer (buf) yuuji@60: "Call lint on buffer BUF." yuuji@64: (require 'yatexprc) yuuji@60: (interactive "bCall lint on buffer: ") yuuji@60: (setq buf (get-buffer buf)) yuuji@60: (YaTeX-save-buffers) yuuji@60: (YaTeX-typeset yuuji@60: (concat yahtml-lint-program " " yuuji@60: (file-name-nondirectory (buffer-file-name buf))) yuuji@60: yahtml-lint-buffer "lint" "lint")) yuuji@60: yuuji@58: (defun yahtml-file-to-url (file) yuuji@58: "Convert local unix file name to URL. yuuji@58: If no matches found in yahtml-path-url-alist, return raw file name." yuuji@58: (let ((list yahtml-path-url-alist) p url) yuuji@58: (if (file-directory-p file) yuuji@58: (setq file (expand-file-name yahtml-directory-index file)) yuuji@58: (setq file (expand-file-name file))) yuuji@60: (if (string-match "^[A-Za-z]:/" file) yuuji@60: (progn yuuji@64: ;; (aset file 1 ?|) ;これは要らないらしい… yuuji@60: (setq file (concat "///" file)))) yuuji@58: (while list yuuji@58: (if (string-match (concat "^" (regexp-quote (car (car list)))) file) yuuji@58: (setq url (cdr (car list)) yuuji@58: file (substring file (match-end 0)) yuuji@58: url (concat url file) yuuji@58: list nil)) yuuji@58: (setq list (cdr list))) yuuji@58: (or url (concat "file:" file)))) yuuji@58: yuuji@58: (defun yahtml-url-to-path (file &optional basedir) yuuji@58: "Convert local URL name to unix file name." yuuji@58: (let ((list yahtml-path-url-alist) url realpath docroot yuuji@58: (dirsufp (string-match "/$" file))) yuuji@58: (setq basedir (or basedir yuuji@58: (file-name-directory yuuji@58: (expand-file-name default-directory)))) yuuji@58: (cond yuuji@58: ((string-match "^/" file) yuuji@58: (while list yuuji@59: (if (file-directory-p (car (car list))) yuuji@58: (progn yuuji@58: (setq url (cdr (car list))) yuuji@58: (if (string-match "\\(http://[^/]*\\)/" url) yuuji@58: (setq docroot (substring url (match-end 1))) yuuji@58: (setq docroot url)) yuuji@64: (cond yuuji@64: ((string-match (concat "^" (regexp-quote docroot)) file) yuuji@64: (setq realpath yuuji@64: (expand-file-name yuuji@64: (substring yuuji@64: file yuuji@64: (if (= (aref file (1- (match-end 0))) ?/) yuuji@64: (match-end 0) ; "/foo" yuuji@64: (min (1+ (match-end 0)) (length file)))) ; "/~foo" yuuji@64: (car (car list)))))) yuuji@58: (if realpath yuuji@58: (progn (setq list nil) yuuji@58: (if (and dirsufp (not (string-match "/$" realpath))) yuuji@58: (setq realpath (concat realpath "/"))))))) yuuji@58: (setq list (cdr list))) yuuji@58: realpath) yuuji@58: (t file)))) yuuji@58: yuuji@58: (defun yahtml-browse-current-file () yuuji@58: "Call WWW browser on current file." yuuji@58: (interactive) yuuji@58: (basic-save-buffer) yuuji@58: (yahtml-browse-html (yahtml-file-to-url (buffer-file-name)))) yuuji@58: yuuji@58: (defun yahtml-browse-reload () yuuji@115: "Send `reload' event to netscape." yuuji@58: (let ((pb "* WWW Browser *") (cb (current-buffer))) yuuji@58: (cond yuuji@58: ((string-match "[Nn]etscape" yahtml-www-browser) yuuji@58: (if (get-buffer pb) yuuji@58: (progn (set-buffer pb) (erase-buffer) (set-buffer cb))) yuuji@58: ;;(or (get 'yahtml-netscape-sentinel 'url) yuuji@58: ;; (error "Reload should be called after Browsing.")) yuuji@58: (put 'yahtml-netscape-sentinel 'url yuuji@58: (yahtml-file-to-url (buffer-file-name))) yuuji@58: (basic-save-buffer) yuuji@58: (set-process-sentinel yuuji@58: (setq yahtml-browser-process yuuji@58: (start-process yuuji@60: "browser" pb shell-file-name yahtml-shell-command-option ;"-c" yuuji@58: (format "%s -remote 'reload'" yahtml-www-browser))) yuuji@58: 'yahtml-netscape-sentinel)) yuuji@58: (t yuuji@58: (message "Sorry, RELOAD is supported only for Netscape."))))) yuuji@58: yuuji@58: ;;; ---------- Intelligent newline ---------- yuuji@58: (defun yahtml-intelligent-newline (arg) yuuji@58: "Intelligent newline for HTML" yuuji@58: (interactive "P") yuuji@60: (let (env func) yuuji@60: (end-of-line) yuuji@64: (setq env (downcase (or (yahtml-inner-environment-but "^\\(a\\|p\\)\\b" t) yuuji@64: "html"))) yuuji@58: (setq func (intern-soft (concat "yahtml-intelligent-newline-" env))) yuuji@58: (newline) yuuji@58: (if (and env func (fboundp func)) yuuji@64: ;; if intelligent line function is defined, call that yuuji@64: (funcall func) yuuji@64: ;; else do the default action yuuji@64: (if (string-match yahtml-p-prefered-env-regexp env) yuuji@64: (yahtml-insert-p))))) yuuji@58: yuuji@58: (defun yahtml-intelligent-newline-ul () yuuji@58: (interactive) yuuji@64: (yahtml-insert-single "li") yuuji@80: (or yahtml-always-/li yahtml-faithful-to-htmllint (insert " ")) yuuji@58: (yahtml-indent-line)) yuuji@58: yuuji@58: (fset 'yahtml-intelligent-newline-ol 'yahtml-intelligent-newline-ul) yuuji@58: yuuji@58: (defun yahtml-intelligent-newline-dl () yuuji@58: (interactive) yuuji@58: (let ((case-fold-search t)) yuuji@58: (if (save-excursion yuuji@73: (re-search-backward "<\\(\\(dt\\)\\|\\(dd\\)\\)[ \t>]" yuuji@58: (get 'YaTeX-inner-environment 'point) t)) yuuji@58: (cond yuuji@58: ((match-beginning 2) yuuji@64: (yahtml-insert-single "dd") yuuji@80: (or yahtml-always-/dd yahtml-faithful-to-htmllint (insert " ")) yuuji@58: (setq yahtml-last-single-cmd "dt")) yuuji@58: ((match-beginning 3) yuuji@64: (yahtml-insert-single "dt") yuuji@80: (or yahtml-always-/dt yahtml-faithful-to-htmllint (insert " ")) yuuji@58: (setq yahtml-last-single-cmd "dd"))) yuuji@121: (yahtml-insert-single "dt") yuuji@121: (or yahtml-always-/li yahtml-faithful-to-htmllint (insert " ")) yuuji@64: (setq yahtml-last-single-cmd "dd")) yuuji@64: (yahtml-indent-line) yuuji@64: (and (string-match yahtml-p-prefered-env-regexp "dl") yuuji@64: (string-equal yahtml-last-single-cmd "dt") yuuji@64: (yahtml-insert-p nil)))) yuuji@58: yuuji@59: (defun yahtml-intelligent-newline-select () yuuji@59: (interactive) yuuji@59: (insert "<" (if yahtml-prefer-upcases "OPTION" "option") "> ") yuuji@59: (yahtml-indent-line)) yuuji@59: yuuji@70: (defun yahtml-intelligent-newline-style () yuuji@70: (interactive) yuuji@70: (if (save-excursion yuuji@70: (and yuuji@70: (re-search-backward "") yuuji@70: (beginning-of-line) yuuji@70: (open-line 1) yuuji@70: (YaTeX-reindent c)))) yuuji@70: yuuji@80: (defun yahtml-intelligent-newline-head () yuuji@80: (let ((title (read-string "Document title: ")) yuuji@80: (b "") (e "") p) yuuji@80: (yahtml-indent-line) yuuji@80: (insert (format "%s" (if yahtml-prefer-upcases (upcase b) b))) yuuji@80: (setq p (point)) yuuji@80: (insert (format "%s%s" title (if yahtml-prefer-upcases (upcase e) e))) yuuji@80: (if (string= "" title) (goto-char p)) yuuji@80: (setq yahtml-last-begend "body"))) yuuji@80: yuuji@80: (defun yahtml-intelligent-newline-script () yuuji@80: (let ((p (point)) b) yuuji@80: (if (save-excursion yuuji@80: (and yuuji@80: (setq b (re-search-backward "" nil t)) yuuji@80: (re-search-forward yuuji@80: "\\(javascript\\)\\|\\(tcl\\)\\|\\(vbscript\\)" p t))) yuuji@80: (let ((js (match-end 1)) (tcl (match-end 2)) (vb (match-end 3)) yuuji@80: c (srcp (re-search-backward "src=" b t))) yuuji@80: (goto-char p) yuuji@80: (yahtml-indent-line) yuuji@80: (setq c (current-column)) yuuji@80: (if srcp yuuji@80: nil yuuji@80: (insert "") yuuji@80: (beginning-of-line) yuuji@80: (open-line 1) yuuji@80: (YaTeX-reindent c)))))) yuuji@80: yuuji@86: (defun yahtml-intelligent-newline-table () yuuji@86: (let ((cp (point)) (p (point)) tb rb (cols 0) th line (i 0) fmt yuuji@86: (ptn "\\(\\)\\|")) yuuji@86: (cond yuuji@86: ((save-excursion (setq tb (YaTeX-beginning-of-environment "table"))) yuuji@86: (while (and (setq rb (re-search-backward ptn tb t)) yuuji@86: (match-beginning 1)) yuuji@86: (setq th (looking-at " cols 0) yuuji@86: (message "%s columns found. %s" yuuji@86: cols (if YaTeX-japan "新しいtr(N)? 前のtrの複写?(D)?: " yuuji@86: "New tr?(N) or Duplicate"))) yuuji@86: (cond yuuji@86: ((and (> cols 0) yuuji@86: (memq (read-char) '(?d ?D))) ;Duplication mode yuuji@135: (setq line (YaTeX-buffer-substring (point) (1- cp)))) yuuji@86: (t ;empty cells yuuji@86: (setq line "" i 0) yuuji@86: (if (> cols 0) yuuji@86: (while (> cols i) yuuji@86: (setq line (concat line (if (and (= i 0) th) "" yuuji@86: "")) yuuji@86: th nil i (1+ i))) yuuji@86: (setq fmt (read-string "`th' or `td' format: " "th td td")) yuuji@86: (while (string-match "t\\(h\\)\\|td" fmt i) yuuji@86: (setq line (concat line (if (match-beginning 1) "" yuuji@86: "")) yuuji@86: i (match-end 0)))) yuuji@86: (setq line (concat line "")))) yuuji@86: (goto-char cp) yuuji@86: (if th yuuji@86: (message yuuji@86: "Type `%s' to change td from/to th." yuuji@86: (key-description (car (where-is-internal 'yahtml-change-*))))) yuuji@86: (if (string< "" line) yuuji@86: (progn yuuji@86: (insert line) yuuji@86: (goto-char (+ 8 cp)) yuuji@86: (yahtml-indent-line))))))) yuuji@86: yuuji@58: ;;; ---------- Marking ---------- yuuji@58: (defun yahtml-mark-begend () yuuji@58: "Mark current tag" yuuji@58: (interactive) yuuji@58: (YaTeX-beginning-of-environment) yuuji@58: (let ((p (point))) yuuji@58: (save-excursion yuuji@58: (skip-chars-backward " \t" (point-beginning-of-line)) yuuji@58: (if (bolp) (setq p (point)))) yuuji@58: (push-mark p t)) yuuji@58: (yahtml-goto-corresponding-begend) yuuji@58: (forward-list 1) yuuji@58: (if (eolp) (forward-char 1))) yuuji@58: yuuji@59: ;;; ---------- complete marks ---------- yuuji@59: (defun yahtml-complete-mark () yuuji@60: "Complete >, <, &ersand, and "e." yuuji@59: (interactive) yuuji@69: (message "1:< 2:> 3:& 4:\" 5:' 6:nbsp") yuuji@59: (let ((c (read-char))) yuuji@69: (setq c (if (or (< c ?0) (> c ?7)) yuuji@59: (string-match (regexp-quote (char-to-string c)) "<>&\"") yuuji@59: (- c ?1))) yuuji@69: (if (or (< c 0) (> c 6)) yuuji@59: nil yuuji@69: (insert (format "&%s;" yuuji@69: (nth c '("lt" "gt" "amp" "quot" "apos" "nbsp"))))))) yuuji@59: yuuji@59: yuuji@60: ;;; ---------- jump to error line ---------- yuuji@60: (defun yahtml-prev-error () yuuji@60: "Jump to previous error seeing lint buffer." yuuji@60: (interactive) yuuji@60: (or (get-buffer yahtml-lint-buffer) yuuji@60: (error "No lint program ran.")) yuuji@60: (YaTeX-showup-buffer yahtml-lint-buffer nil t) yuuji@64: (yahtml-jump-to-error-line t)) yuuji@60: yuuji@64: (defun yahtml-jump-to-error-line (&optional sit) yuuji@64: (interactive "P") yuuji@60: (let ((p (point)) (e (point-end-of-line))) yuuji@60: (end-of-line) yuuji@60: (if (re-search-backward yahtml-error-line-regexp nil t) yuuji@72: (let ((f (if (string= "" (YaTeX-match-string 1)) yuuji@72: YaTeX-current-file-name yuuji@72: (YaTeX-match-string 1))) yuuji@72: (l (string-to-int (or (YaTeX-match-string 2) yuuji@72: (YaTeX-match-string 3))))) yuuji@64: (if sit (sit-for 1)) yuuji@60: (forward-line -1) yuuji@64: (YaTeX-showup-buffer (YaTeX-switch-to-buffer f t) nil t) yuuji@60: (goto-line l)) yuuji@60: (message "No line number usage")))) yuuji@69: yuuji@69: ;;; ---------- Style Sheet Support ---------- yuuji@69: (defvar yahtml-css-class-alist nil yuuji@69: "Alist of elements vs. their classes") yuuji@69: yuuji@69: (defun yahtml-css-collect-classes-region (beg end &optional initial) yuuji@70: (save-excursion yuuji@70: (save-restriction yuuji@69: (narrow-to-region beg end) yuuji@69: (goto-char (point-min)) yuuji@70: (let ((alist initial) b e element class a) yuuji@69: (setq b (point)) yuuji@80: (while (re-search-forward "\\({\\)\\|\\(@import\\)" nil t) yuuji@80: (if (match-beginning 2) yuuji@80: (let ((f (YaTeX-buffer-substring yuuji@80: (progn (skip-chars-forward "^\"")(1+ (point))) yuuji@80: (progn (forward-char 1) yuuji@80: (skip-chars-forward "^\"")(point))))) yuuji@80: (if (file-exists-p f) yuuji@80: (setq alist yuuji@80: (append alist (yahtml-css-collect-classes-file f))))) yuuji@80: (setq e (point)) yuuji@80: (goto-char b) yuuji@80: (while (re-search-forward ;ちょといい加減なREGEXP yuuji@86: "\\([a-z*][-a-z0-9]*\\)?\\.\\([-a-z0-9][-a-z0-9]*\\)\\>" yuuji@80: e t) yuuji@80: (setq element (YaTeX-match-string 1) yuuji@80: class (YaTeX-match-string 2)) yuuji@80: ;;if starts with period (match-string 1 is nil), yuuji@80: ;;this is global class yuuji@86: (setq element (downcase (or element "*"))) yuuji@80: (if (setq a (assoc element alist)) yuuji@80: (or (assoc class (cdr a)) yuuji@80: (setcdr a (cons (list class) (cdr a)))) yuuji@80: (setq alist (cons (list element (list class)) alist)))) yuuji@80: (goto-char (1- e)) yuuji@80: (search-forward "}" nil t) yuuji@80: (setq b (point)))) yuuji@70: alist)))) yuuji@69: yuuji@69: (defun yahtml-css-collect-classes-buffer (&optional initial) yuuji@69: (interactive) yuuji@69: (yahtml-css-collect-classes-region (point-min) (point-max) initial)) yuuji@69: yuuji@69: (defun yahtml-css-collect-classes-file (file &optional initial) yuuji@70: (let*((hilit-auto-highlight nil) yuuji@86: (buf (get-buffer-create yuuji@86: (format " *css-collection*%s" (file-name-nondirectory file)))) yuuji@86: (cb (current-buffer))) yuuji@86: (unwind-protect yuuji@86: (progn yuuji@86: (set-buffer buf) yuuji@86: (insert-file-contents file) yuuji@86: (cd (or (file-name-directory file) ".")) yuuji@86: (yahtml-css-collect-classes-buffer initial)) yuuji@86: (if (eq buf cb) yuuji@86: nil yuuji@86: (kill-buffer buf) yuuji@86: (set-buffer cb))))) yuuji@69: yuuji@69: (defun yahtml-css-scan-styles () yuuji@69: (save-excursion yuuji@69: (goto-char (point-min)) yuuji@69: (set (make-local-variable 'yahtml-css-class-alist) nil) yuuji@72: (let (b tag type e href alist) yuuji@72: (while (re-search-forward "<\\(style\\|link\\)" nil t) yuuji@72: (setq b (match-beginning 0) yuuji@72: tag (YaTeX-match-string 1)) yuuji@69: (cond yuuji@69: ((string-match "style" tag) yuuji@69: (goto-char b) yuuji@69: (save-excursion (forward-list 1) (setq e (point))) yuuji@69: (cond yuuji@69: ((search-forward "text/css" e 1) ;css definition starts yuuji@69: (setq alist yuuji@69: (yahtml-css-collect-classes-region yuuji@69: (point) (progn (search-forward "") (point)) yuuji@69: alist))))) yuuji@69: ((and (string-match "link" tag) yuuji@72: (stringp (setq type (yahtml-get-attrvalue "type"))) yuuji@72: (string-match "text/css" type) yuuji@69: (setq href (yahtml-get-attrvalue "href")) yuuji@69: (file-exists-p (yahtml-url-to-path href))) yuuji@69: (setq alist yuuji@69: (yahtml-css-collect-classes-file yuuji@69: (yahtml-url-to-path href) alist)))) yuuji@69: (setq yahtml-css-class-alist alist))))) yuuji@69: yuuji@70: (defun yahtml-css-get-element-completion-alist (element) yuuji@73: (let ((alist (cdr-safe (assoc (downcase element) yahtml-css-class-alist))) yuuji@86: (global (cdr-safe (assoc "*" yahtml-css-class-alist)))) yuuji@70: (and (or alist global) yuuji@70: (append alist global)))) yuuji@70: yuuji@57: ;;; ---------- ---------- yuuji@57: yuuji@57: ;;; yuuji@57: ;;hilit19 yuuji@57: ;;; yuuji@57: (defvar yahtml-default-face-table yuuji@57: '( yuuji@57: (form black/ivory white/hex-442233 italic) yuuji@57: )) yuuji@57: (defvar yahtml-hilit-patterns-alist yuuji@57: '( yuuji@70: 'case-fold yuuji@57: ;; comments yuuji@57: ("" comment) yuuji@57: ;; include&exec yuuji@69: ("" include) yuuji@57: ;; string yuuji@68: (hilit-string-find ?\\ string) yuuji@80: (yahtml-hilit-region-tag "<\\(strong\\|b\\)\\>" bold) yuuji@57: ("" 0 decl) yuuji@57: ("<\\(di\\|dt\\|li\\|dd\\)>" 0 label) yuuji@80: (yahtml-hilit-region-tag "<\\(em\\|i\\>\\)" italic) yuuji@72: ;("" crossref) ;good for hilit19, but odd for font-lock.. yuuji@72: (yahtml-hilit-region-tag "<\\(a\\)\\s +href" crossref) yuuji@64: (yahtml-hilit-region-tag-itself "" decl) yuuji@57: )) yuuji@57: yuuji@57: (defun yahtml-hilit-region-tag (tag) yuuji@57: "Return list of start/end point of form." yuuji@72: (if (re-search-forward tag nil t) yuuji@72: (let ((m0 (match-beginning 0)) (e0 (match-end 0)) yuuji@72: (elm (YaTeX-match-string 1))) yuuji@72: (skip-chars-forward "^>") yuuji@72: (prog1 yuuji@72: (cons (1+ (point)) yuuji@72: (progn (re-search-forward (concat "") nil t) yuuji@72: (match-beginning 0))) yuuji@72: (goto-char e0))))) yuuji@57: yuuji@64: (defun yahtml-hilit-region-tag-itself (ptn) yuuji@64: "Return list of start/end point of itself." yuuji@64: (if (re-search-forward ptn nil t) yuuji@73: (let ((m0 (match-beginning 0)) (e0 (match-end 0))) yuuji@73: (skip-chars-forward "^<>") yuuji@73: (if (eq (char-after (point)) ?<) nil yuuji@73: (prog1 yuuji@73: (cons m0 (min (point-max) (1+ (point)))) yuuji@73: (goto-char e0)))))) yuuji@64: yuuji@57: ;(setq hilit-patterns-alist (delq (assq 'yahtml-mode hilit-patterns-alist) hilit-patterns-alist)) yuuji@70: (and yahtml-use-hilit19 yuuji@64: (or (assq 'yahtml-mode hilit-patterns-alist) yuuji@64: (setq hilit-patterns-alist yuuji@64: (cons (cons 'yahtml-mode yahtml-hilit-patterns-alist) yuuji@64: hilit-patterns-alist)))) yuuji@72: ;;; yuuji@72: ;; for font-lock yuuji@72: ;;; yuuji@72: yuuji@72: ; <> yuuji@72: ;(defvar yahtml-font-lock-keywords yuuji@72: ; '( yuuji@72: ; ;; comments yuuji@72: ; ("" . font-lock-comment-face) yuuji@72: ; ;; include&exec yuuji@72: ; ("" yuuji@72: ; 0 font-lock-include-face keep) yuuji@72: ; ;; string yuuji@72: ; ;(hilit-string-find ?\\ string) yuuji@72: ; ;(yahtml-hilit-region-tag "\\(em\\|strong\\)" bold) yuuji@72: ; ("" 0 font-lock-keyword-face) yuuji@72: ; ("<\\(di\\|dt\\|li\\|dd\\)>" 0 font-lock-label-face) yuuji@72: ; ("" (0 font-lock-crossref-face keep)) yuuji@72: ; ;(yahtml-hilit-region-tag-itself "" decl) yuuji@72: ; ("" (yahtml-fontify-to-tagend nil nil)) yuuji@72: ; ) yuuji@72: ; "*Defualt font-lock-keywords for yahtml-mode.") yuuji@72: (defvar yahtml-font-lock-keywords yuuji@72: (YaTeX-convert-pattern-hilit2fontlock yahtml-hilit-patterns-alist) yuuji@72: "Default fontifying patterns for yahtml-mode") yuuji@72: yuuji@72: (defun yahtml-font-lock-set-default-keywords () yuuji@72: (put 'yahtml-mode 'font-lock-defaults yuuji@72: '(yahtml-font-lock-keywords nil t))) yuuji@72: yuuji@72: (if yahtml-use-font-lock yuuji@72: (progn yuuji@72: (if (and (boundp 'hilit-mode-enable-list) hilit-mode-enable-list) yuuji@72: ;;for those who use both hilit19 and font-lock yuuji@72: (if (eq (car hilit-mode-enable-list) 'not) yuuji@72: (or (member 'yahtml-mode hilit-mode-enable-list) yuuji@72: (nconc hilit-mode-enable-list (list 'yahtml-mode))) yuuji@72: (setq hilit-mode-enable-list yuuji@72: (delq 'yahtml-mode hilit-mode-enable-list)))) yuuji@72: (yahtml-font-lock-set-default-keywords))) yuuji@72: yuuji@73: (defun yahtml-font-lock-recenter (&optional arg) yuuji@73: (interactive "P") yuuji@73: (font-lock-mode -1) ;is stupid, but sure. yuuji@73: (font-lock-mode 1)) yuuji@73: yuuji@68: (run-hooks 'yahtml-load-hook) yuuji@54: (provide 'yahtml) yuuji@54: yuuji@54: ; Local variables: yuuji@54: ; fill-prefix: ";;; " yuuji@54: ; paragraph-start: "^$\\| \\|;;;$" yuuji@54: ; paragraph-separate: "^$\\| \\|;;;$" yuuji@80: ; coding: sjis yuuji@54: ; End: