[HOME]: [Mac OS X]: [MacPython]: [Emacs]: [生存報告記]: [MacEmacs JP Project]: [NTEmacs JP Project]:

概要

nxml-mode もしくは nXML mode 。Emacs23 からは標準登載です。

新しいXML用モード。Emacs21以上でないと動作しない。Mule-UCSとは同時に利用できない。

http://www.xmlhack.com/read.php?item=2061

このメモ Emacs23 登載の nXML mode に追随させる予定です。

インストール

Emacs23 から標準登載なのでインストール作業は不要です。

Emacs22 以前は以下から取得してインストールしてください。

http://www.thaiopensource.com/download/

nxml-mode-yyyymmdd.tar.gzを取得します。

tar xvfz nxml-mode-yyyymmdd.tar.gz
cd nxml-mode-yyyymmdd
make

load-pathの通ったディレクトリに移動するか、load-pathを設定してください。

設定

READMEに記述があるので、そのままです。

(load "~/lib/lisp/nxml-mode-200YMMDD/rng-auto.el")
(setq auto-mode-alist
        (cons '("\\.\\(xml\\|xsl\\|rng\\|xhtml\\)\\'" . nxml-mode)
              auto-mode-alist))

M-x customize-group <RET> nxml <RET>

にて設定してください。

わたしは追加で以下の設定を追加しています。

(add-hook 'nxml-mode-hook
          (lambda ()
            (setq auto-fill-mode -1)
            (setq nxml-slash-auto-complete-flag t)
            (setq nxml-child-indent 2)
            (setq indent-tabs-mode t)
            (setq tab-width 2)))

色の設定がいろいろと可能です。

nxml-xml-declaration-delimiter-face (for the <? and ?>)
nxml-xml-declaration-xml-face (for the xml keyword)
nxml-xml-declaration-attribute-name-face (for encoding, version etc)
nxml-xml-declaration-attribute-value-delimiter-face (for the "")
nxml-xml-declaration-attribute-value-face (for the contents of "")

ちなみに以下の設定をするとXMLhackでの紹介画像とほぼ同じになります。

(custom-set-faces
  ;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
 '(mode-line ((((type x w32 mac) (class color)) (:background "navy" :foreground "yellow" :box (:line-width -1 :style released-button)))))
 '(nxml-comment-content-face ((t (:foreground "yellow4"))))
 '(nxml-comment-delimiter-face ((t (:foreground "yellow4"))))
 '(nxml-delimited-data-face ((t (:foreground "lime green"))))
 '(nxml-delimiter-face ((t (:foreground "grey"))))
 '(nxml-element-local-name-face ((t (:inherit nxml-name-face :foreground "medium turquoise"))))
 '(nxml-name-face ((t (:foreground "rosy brown"))))
 '(nxml-tag-slash-face ((t (:inherit nxml-name-face :foreground "grey")))))

利用方法

説明は

C-u M-x info RET nxml-mode.info RET

で読むのがよいです。

C-c s <RET> schemaname.rnc

にてschemaをロードする。

C-<RET>

にてどんどんタグ記述。

C-c i

で終了タグを記述。

C-c f

でタグ閉じる。

終了って感じです。

schemaの指定

その場のみなら

C-c s <RET> schemaname.rnc

でもよいですが、これは普通に使うには面倒です。

M-x customize-variable <RET> rng-auto-file-name-alist <RET>
もしくは
M-x customize-variable <RET> rng-auto-element-alist <RET>

でカスタマイズしていまうのが簡易です。

最新版では変更になっていて rng-schema-locating-files にて schemas.xml を指定する事で設定ができます。

rng-auto-file-name-alist

これはファイル名で指定します。

デフォルトでは

(".*\\.xsl\\'" . "${nxml-home}/schema/xslt.rnc")
(".*\\.x?html?\\'" . "${nxml-home}/schema/xhtml.rnc")
(".*\\.rng\\'" . "${nxml-home}/schema/relaxng.rnc")
(".*\\.rdf\\'" . "${nxml-home}/schema/rdfxml.rnc")

${nxml-home}はnxmlのディレクトリ

みたいな設定になっています。

こまかい事はrng-auto.elを見るとわかるかと思います。

手で追加するなら

(setq rng-auto-file-name-alist
      (append
       (list
        '(".*\\.xslt\\'" "~/lib/lisp/nxml-mode/schema/xslt.rnc")
        )
       rng-auto-file-name-alist-default)
      )

とかで可能です。

rng-auto-element-alist

これはエレメントの指定で設定します。

エラー対処

No schema loader available for file extension `rnc'

が出る場合がある?

参考サイト

RelaxNG

http://kimama.ddo.jp/programming/nxml-mode/

http://www.dpawson.co.uk/relaxng/nxml/

EmacsWiki: NxmlMode

Directory /Emacs/DL/elisp/


CategoryPrograming CategoryEmacs CategoryXml