Muse Mode の設定

始めに

2006 年 11 月に emacs-wiki からmuse-mode に移行しました. できる事が増えて, 設定が更に複雑になった感は否めませんが, emacs-wiki 同様に大変便利です.

install

etch の Debian package は 3.02.8-1 なのですが, 本家では 3.12 が公開されています. 3.02 はリストのネスティングができないので, 本家から 3.12 を取得して, testing のソースを使って Debian package を 野良ビルドしました. 野良ビルドは 野良ビルド置き場 から取得できます.

 $ wget http://www.mwolson.org/static/dist/muse-latest.tar.gz
 $ apt-get source muse-el -t testing
 $ cd muse-el-3.11
 $ uupdate ../muse-el-latest.tar.gz -v 3.12
 $ cd muse-el-3.12
 $ dch -i
 $ debiuld -rfakeroot -uc -us
 $ sudo dpkg -i muse-el_3.12-1.uwabami1_all.deb

設定

.emacs での設定

今の所 xhtml での出力しか考えていません(この文書です). latex での出力もできるみたいですが, あんまり使ってません - -;)

;; 読み込み
(require 'muse-mode)
(require 'muse-html)
(require 'muse-latex)
(require 'muse-project)
(require 'muse-wiki)
;; project の定義
(setq muse-project-alist
      '(("cc-env"
         ("~/work/muse/cc-env" :default "index")
         (:base "xhtml" :path "~/public_html/cc-env")
         )))
(add-to-list 'muse-project-alist
             '("lec_note"
               ("~/work/muse/lec_note" :default "index")
               (:base "latex" :path "~/work/tex/lec_note")))
;; 拡張子をつけない場合にはコメントを外す
;(setq muse-file-extension nil muse-mode-auto-p t)
;;文字コード設定
(setq muse-xhtml-charset-default "euc-jp")
(setq muse-html-encoding-default (quote euc-jp))
(setq muse-html-meta-content-encoding (quote euc-jp))
(setq muse-latexcjk-encoding-default
      (cdr (assoc 'euc-jp-unix muse-latexcjk-encoding-map)))
(setq muse-latex-header "~/.emacs.d/template/muse-header.tex")
;; footer の読み込み
(setq muse-xhtml-footer "~/.emacs.d/template/muse-footer.html")
;; header の読み込み.
(setq muse-xhtml-header "~/.emacs.d/template/muse-header.html")
;; CSS の読み込み
(setq muse-xhtml-style-sheet "<link rel=\"stylesheet\" type=\"text/css\" charset=\"euc-jp\" media=\"all\" href=\"../css/muse.css\" />")
;; 日付フォーマットの指定
(setq muse-footer-date-format "%Y-%m-%d")
;; \C-x n で project-find-file を起動
(define-key ctl-x-map "n" 'muse-project-find-file)
;; テンプレートの自動挿入
(setq auto-insert-alist
      (append
       '(
         ;; モードで選択
         (muse-mode . "muse-template.muse")
         ;; ファイル名で指定
         ("\\.muse" . "muse-template.muse")
         )
       auto-insert-alist))

xhtml 変換のヘッダ, フッタ, テンプレート

ヘッダはこんな感じ.

<?xml version="1.0" encoding="euc-jp"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
<head>
  <meta http-equiv="<lisp>muse-html-meta-http-equiv</lisp>" content="<lisp>muse-html-meta-content-type</lisp>" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="author" content="<lisp>user-full-name</lisp>" />
  <meta name="generator" content="Muse" />
  <link rev="made"  href="mailto:<lisp>user-mail-address</lisp>" />
  <link rel="start" href="./index.html" />
  <lisp>muse-xhtml-style-sheet </lisp>
  <title>
   <lisp>
   (let
      ((current-project
         (car (muse-project-of-file
               muse-publishing-current-file))))
      (concat
       (when current-project
         (concat current-project " - "))
       (muse-publishing-directive "title")))
   </lisp>
  </title>
</head>

<body>
<h1 id="top">
<lisp>
  (concat (muse-publishing-directive "title")
  (let ((author (muse-publishing-directive "author")))
  (if (not (string= author (user-full-name)))
  (concat " (by " author ")"))))
</lisp>
</h1>

<div class="navhead">
<table width="100%" border="0" summary="navigation header">
  <tr>
    <td align="left">
    </td>
    <td align="right">
      Lastupdated:
      <lisp>
      (if (muse-current-file)
      (format-time-string muse-footer-date-format
      (nth 5 (file-attributes (muse-current-file)))))
      </lisp>
    </td>
  </tr>
</table>
</div>

<!-- Page published by Emacs Muse begins here -->

フッタはこんな感じ

<!-- Page published by Emacs Muse ends here -->
<hr />
<div class="navfoot">
<table width="100%" border="0" summary="navifoot">
  <tr>
    <td align="left">
      [<a href="../index.html">Top</a>
       |
      <a href="./index.html">
      <lisp>
      (let
      ((current-project
      (car (muse-project-of-file
      muse-publishing-current-file))))
      (concat current-project))
      </lisp>
      </a>
      ]
    </td>
    <td align="right">
      <a href="../index.html">
      <lisp>user-full-name</lisp></a>
    </td>
  </tr>
</table>
</div>
</body>
</html>

テンプレートはこんな感じ. $Lastupdate:$($は半角の $) は, emacs で save-buffer 時に更新する設定をしてます.

#desc Top  ; -*- mode: Muse; coding: euc-japan-unix -*-
#title
<comment>
******
$Lastupdate: $
</comment>

画像のサムネイル出力

画像へリンクをはった際に, サムネイルへリンクするようにしてみた. ...と言っても, アップロードする際に変換しているだけで.

#!/usr/bin/ruby1.8

require 'RMagick'
require 'tempfile'

#--- image size setting
width = 320.0
height = 240.0

#--- error handring
if ARGV.size < 1
  puts "usage: muse-img-hook.rb [html_dir]"
  exit 1
end

#--- main
Dir.glob(ARGV[0] +"/*.html").each do |file|
  puts file
  temp = Tempfile::new(File.basename(file), "/tmp")
  File.open(file).each do |line|
    if line =~ /img src=\"\.\/img\/(.*\.png).*alt=\"(.*)\"/
      img_name =  "/img/" + $1
      thumb_name = "/img/thumb/" + $1
      unless $1 =~ /thumb/
        img = Magick::ImageList.new(File.dirname(file) + "/" + img_name)
        img.resize(width,height).write(File.dirname(file) + "/" + thumb_name)
        uri = "<a href=\".#{img_name}\">"
        imgtag = "<img src=\".#{thumb_name}\" alt=\"#{$2}\" />"
        link = uri + imgtag + "</a>"
        temp.puts( \
          line.gsub(/<img src=\"\.\/img\/(.*\.png).*alt=\"(.*)\".*\/>/,link))
      end
    else
      temp.puts(line.gsub(/font-style: normal/,"font-style: normal"))
    end
  end
  temp.close; temp.open
  File.open(file, "w").write(temp.read)
  temp.close(true)
end

なんて.


参考文献