URAMIRAIKAN

1020のなれの果て (since 2005.6.19)

MercurialとPygments

 Mercurialサーバを立ててスクリプトとか設定ファイルを管理していますが、Pygmentsというのを使用することで、WEBブラウザでアクセスしたときにSyntax Highlighterみたいにコードを色分けして見やすくできるようです。

 さっそく使ってみました。

 いろいろインストール方法はあると思いますが、自分の環境ではMercurialと同じく"easy_install"を使用します。

# easy_install pygments
Searching for pygments
Reading http://pypi.python.org/simple/pygments/
Best match: Pygments 1.6
Downloading
 ~ 以下省略 ~

 これだけでインストールは完了です。

 あとはhgwebの設定ファイルの[extensions]セクションに”hgext.highlight ="を、[web]セクションに"pygments_style = <スタイル名>"を追記します。

[web] encoding = UTF-8 style = gitweb allow_archive = gz,zip pygments_style = vim [extensions] hgext.highlight = [paths] repository_name = /path/to/repository

 上記では、ついでにMercurial自体のスタイルも"gitweb"にしました。
 "pygments_style"で指定できるスタイルは、今回のインストール方法だと"/usr/lib/python2.6/site-packages/Pygments-1.6-py2.6.egg/pygments/styles"以下にあります。
(ちなみにMercurialのスタイルは"/usr/lib/python2.6/site-packages/mercurial-2.9.1-py2.6-linux-i686.egg/mercurial/templates"内でした。)

# ls /usr/lib/python2.6/site-packages/Pygments-1.6-py2.6.egg/pygments/styles
__init__.py
__init__.pyc
autumn.py
autumn.pyc
borland.py
borland.pyc
bw.py
bw.pyc
colorful.py
colorful.pyc
default.py
default.pyc
emacs.py
emacs.pyc
friendly.py
friendly.pyc
fruity.py
fruity.pyc
manni.py
manni.pyc
monokai.py
monokai.pyc
murphy.py
murphy.pyc
native.py
native.pyc
pastie.py
pastie.pyc
perldoc.py
perldoc.pyc
rrt.py
rrt.pyc
tango.py
tango.pyc
trac.py
trac.pyc
vim.py
vim.pyc
vs.py
vs.pyc

 これでスクリプトの表示がずいぶん見やすくなりました。