[ホーム]-> [emacs]-> [活用法]-> [yahtml]

yahtml

1. yahtml とは

YaTeX の作者の広瀬さんが作られた html 編集用のモードです。yatex の配布にも含まれていますが、yahtml だけでも配布されています。

html ファイルを記述する際に使われるものには他に html-helper-mode というものがあります。 私は野鳥を使う感覚で使えるため、yahtml の方を使っています。 こちらの方がより賢い便宜を提供してくれるように思いますし。 このページも勿論これを使いながら書いてます。

2. 設定例

(autoload 'yahtml-mode "yahtml" "Yet Another HTML mode" t)
(setq auto-mode-alist (cons (cons "\\.html?$" 'yahtml-mode) auto-mode-alist))

;; 表示には w3m 
(defadvice yahtml-browse-html
  (around w3m-yahtml-browse-html activate compile)
  (w3-fetch (ad-get-arg 0))
;  (w3m-goto-url (ad-get-arg 0) t)
  )
(setq yahtml-lint-program "htmllint")
(setq yahtml-kanji-code 2) ; (1 sjis, 2 jis, 3 euc)
(setq yahtml-path-url-alist
      '(
        ("~/public_html" . "http://www.math.s.chiba-u.ac.jp/~matsu")
        ))
(add-hook
 'yahtml-mode-hook
 (function (lambda ()
             (progn
               (require 'yahtml-insert-index)
               (auto-fill-mode 0)
               (if (equal 'shift_jis-unix buffer-file-coding-system)
                   (progn
                     (set-buffer-file-coding-system 'shift_jis-dos)
                     (set-buffer-modified-p nil)))             
               ))))

(autoload 'yahtml-mode "yahtml" "Yet Another HTML mode" t)
;;; yahtml 用の設定
(setq yahtml-www-browser "mosaic"); yatex の html モードで起動するビューワ
(setq yahtml-path-url-alist ; ホームページの連想リスト
      '(("~/public_html/index-j.html" .
         "http://www.math.s.chiba-u.ac.jp/~matsu/public_html/index.html")))
;; html ファイルを編集する際の自動折り返し桁数
(add-hook 'yahtml-mode-hook '(lambda () (setq fill-column 78)))

3. 使い方

機能は、info に詳しく書かれていますが、主なキーバインドは次の通りです。 下の3つについては上の設定に書いたように外部コマンドを指定しておきます。

[prefix] bタグ挿入
[prefix] lタグ挿入(一行内)
[prefix] simg, imput など終了タグのないもの
[prefix] mbr とか p など
[prefix] aアクセント(<,>,& etc.)
[prefix] cタグ変更
[prefix] kタグ削除
[prefix] gタグジャンプ
[prefix] t jHTML 構文チェッカ
[prefix] t pブラウザ起動
[prefix] t r(ブラウザへの)再読み込み

個人的には [prefix] g でタグジャンプ出来るのが結構嬉しかったりします。 また、スタイルシートを指定している場合、その記述を勝手に読み取って、例えば class などを補完機能付きで入力できるのも魅力です。

4. 2種類の外部ブラウザを利用したい場合

私は w3 と w3m をブラウザとして使っているので、パッチを当てて [prefix] t p (または b)[prefix] t v で別々のブラウザを起動できるようにしています。 上のパッチを当てて、.emacs.el
(autoload 'w3-fetch "w3")
(defadvice yahtml-browse-html
  (around w3m-yahtml-browse-html activate compile)
  (w3-fetch (ad-get-arg 0)))
(autoload 'w3-fetch "w3")
(defadvice yahtml-browse-html-2
  (around w3m-yahtml-browse-html-2 activate compile)
  (w3-fetch (ad-get-arg 0)))
と書いておけばよいです。
[ホーム]-> [emacs]-> [活用法]-> [yahtml]