2007年10月22日星期一

用Emacs+Muse来记笔记--Muse的配置

用Emacs+Muse来记笔记--Muse的配置

论坛里很少有关于EmacsWiki或者EmacsMuse的帖子
我写了一份配置说明,供大家参考
好像论坛里不能直接看我做的网页
大家可以把附件下载下来然后用浏览器看
的确很漂亮哦:)


Contents

前记
感谢
安装

Debian/Ubuntu系统上的安装

配置使用

基本配置
Projects的管理

"并排"方式
"目录树"方式

自定义派生的style

"并排"方式的派生style设置
"目录树"方式派生style设置

Google的搜索栏
导航菜单

自定义的函数

ywb-muse-relative-path
ywb-muse-html-markup-table
ywb-muse-publish-math-tab
ywb-muse-publish-src-tag
ywb-muse-handle-file-link
使contents更漂亮
给每个标题加个top锚
ywb-muse-publish-project
ywb-muse-output-file
ywb-muse-publish-this-file
ywb-muse-generate-index
ywb-muse-preview-with-w3m
ywb-muse-preview-html
ywb-muse-preview-source

3.02.90 版中的一些问题

解决方法

环境变量设置
Planner抄来的配置
快捷键设置
相关链接

Muse相关
EmacsWiki相关

top前记
最早看到用Emacs写WiKi的人应该是王垠吧,后来感觉最流行和最好看的WiKi就应该是薛瑞尼的了。但是现在Emacs Wiki的作者Michael Olson已经不维护Emacs Wiki这个项目了,而是维护一个类似的但功能更强大的项目Muse。而Muse有一些功能还不是很完善,于是我在Google和 Emacs@newsmth之间游走,到处找人帮忙,终于弄出了一个感觉还不错的配置文件,虽然有一些地方还不完善,但是还是先写出来,来以飨大家,其实更重要的是抛砖引玉,使Muse的配置更完善。如果大家对配置或者其中有一些函数进行改进,请尽量保留原作者的信息。
top感谢
叶文彬—几乎所有自定义的函数和大多数配置都是他写的,我都有些不好意思而求他了:)所以下面配置文件里所有带ywb字样的函数请保留,以表示对他的感谢。

薛瑞尼—我的css文件基本上是改他的,的确很漂亮。他也提供了他的配置文件供我参考。

其他人—我参考的其他人用Muse写的网页或者用Emacs-WiKi写的网页。
top安装
可以到Michael Olson的主页上去下载最新版

http://www.mwolson.org/projects/EmacsMuse.html

你也可以到下面的地址去下载最新release的tar.gz格式或者zip格式的包。

http://www.mwolson.org/static/dist/muse/

topDebian/Ubuntu系统上的安装
如果你用Debian的话,在etch(testing)和sid(unstable)里 已经有3.02.6-2这个版本了,所以只要

apt-get install muse-el

就可以了。如果想要装最新的版本,请在你的/etc/apt/sources.list加入下面的源然后更新安装即可。

deb http://www.mwolson.org/debian/ ./

你也可以到下面的地址去下载最新release的deb包然后直接dpkg -i muse-el_***.deb安装即可。

http://mwolson.org/debian/

现在我装的版本是3.02.92.arch.193-1,刚刚看到Olson已经把Muse开发到3.03了,但是not yet released,呵呵,好像增加了好多新特性,如果你要看看有什么新东西的话看这里 NEWS-3.03,或者看我下载的这个NEWS-3.03

如果用是用Ubuntu,我没有测试过,不知道源里有没有,但是上面添加 Michael Olson所提供的源然后安装的方法一定是可以的。
top配置使用
配置使用可以去Emacs Wiki: Muse Mode看看。

http://www.emacswiki.org/cgi-bin/wiki/MuseMode

也可以参考别人的,我这里尽量把我所知道的都写出来。我的配置文件在这里:

muse-init.el
top基本配置

Muse之所以功能强大,最重要的是能输出很多种格式的文件,但是如果只写网页的话只要几样就行了。所以下面配置里前面注掉的都是你可以选择的,如果你要输出其它格式的文件的话,请参考Muse自的带的文档说明。

;;; muse-init.el --- Initialize muse-mode.
;;;; Add below to ~/.emacs config file
;(load-file "~/.emacs.d/conf/muse-init.el")
;(add-to-list 'load-path "/usr/share/emacs/site-lisp/muse-el/experimental")
;;;; xhtml footer and header (如果你沿用emacs-wiki那样定义多个项目而不用muse子目录发布功能,注掉它,这个在后面会说明)
(load-file "~/.emacs.d/conf/muse-footer-header.el")
(require 'muse) ; load generic module
(require 'muse-mode nil t) ; load authoring mode
(require 'muse-wiki nil t) ; load Wiki support
(require 'muse-html nil t) ; load (X)HTML publishing style
(require 'muse-colors nil t) ; load coloring/font-lock module
(require 'outline nil t)
(require 'sgml-mode)
(require 'tp-muse-highlight nil t)
;;;;(下面的可选,我没有用到)
;(require 'muse-blosxom) ; load blosxom module
;(require 'muse-docbook) ; load DocBook publishing style
;(require 'muse-latex) ; load LaTeX/PDF publishing styles
;(require 'muse-texinfo) ; load Info publishing style
;(require 'muse-xml) ; load XML support
;(require 'muse-journal) ; load journal module
;(require 'muse-message) ; load message support (experimental)
;(require 'muse-srctag) ; load srctag support

tp-muse-highlight.el
topProjects的管理
Muse在projects的定义和管理方面做得比Emacs Wiki好,可以省去很多麻烦。projects之间的引用也很方便。而且有一项新功能是从blosxom那里学来的,就是可以把一个源文件的目录树相应地发布成html文件,而发布的目录树的结构跟源文件目录树的结构相同。但是这样也存在一些问题,比如说css文件、图片或者其它的一些东西的相对路径不能自动处理。但是叶文彬写了一些函数可以来解决这个问题。所以projects的管理我分种方法来说明,一种是像Emacs Wiki那样的组织多个"并排"的projects,另一种是"目录树"结构。下面分别介绍:
top"并排"方式
这种方式最简单,其实也最实用,唯一不爽的就是你得把所有的projects的源文件和发布文件都并排地放到一起,没有层次感。不过也并不是每个人都像我一样喜欢用树状结构来分类吧:)

(setq muse-project-alist
`(
("Debian" ;项目名称
("~/muse/source/wiki/debian" ;源文件的位置
:default "index" ;默认的project的主页
:force-publish ("WikiIndex"));发布项目时同时发布project的索引文件
(:base "wiki-xhtml" :path "~/muse/publish/wiki/debian")) ;发布路径
("Emacs"
("~/muse/source/wiki/emacs"
:default "index"
:force-publish ("WikiIndex"))
(:base "wiki-xhtml" :path "~/muse/publish/wiki/emacs"))
("GNU"
("~/muse/source/wiki/gnu"
:default "index"
:force-publish ("WikiIndex"))
(:base "wiki-xhtml" :path "~/muse/publish/wiki/gnu"))
))

top"目录树"方式
如果你像我一样平时收集了一堆从网上弄来的Linux相关的Tips啦,文章啦,而看着这一堆的东西太乱了,于是分门别类地建了一堆目录来分类,而目录下可能还有子目录。那在组织 projects时也想这么干吧。Muse中有一个设置muse-project-alist-dirs可以来干这个,并且把这个你定义的project下的所有目录树结构记住,在发布成html文件时相应地按源文件的目录树结构来发布到指定的目录下。

(setq muse-project-alist
`( ;!注意这一行最左边的是一个"`",ESC键下面那个!
("Muse"
("~/muse/source/wiki/gnu/emacs/muse"
:default "MuseIndex"
:force-publish ("index"))
(:base "wiki-xhtml" :path "~/muse/publish/wiki/gnu/emacs/muse"))
("Debian"
("~/muse/source/wiki/gnu/debian"
:default "index"
:force-publish ("WikiIndex"))
(:base "wiki-xhtml" :path "~/muse/publish/wiki/gnu/debian"))
("Emacs"
("~/muse/source/wiki/gnu/emacs"
:default "index"
:force-publish ("WikiIndex"))
(:base "wiki-xhtml" :path "~/muse/publish/wiki/gnu/emacs"))
("GNU"
("~/muse/source/wiki/gnu"
:default "index"
:force-publish ("WikiIndex"))
(:base "wiki-xhtml" :path "~/muse/publish/wiki/gnu"))

("WiKi" (,@(muse-project-alist-dirs "~/muse/source/wiki");源文件路径
:default "index" ;默认项目主页
:force-publish ("WikiIndex")
)
,@(muse-project-alist-styles "~/muse/source/wiki" ;还是源文件路径
"~/muse/publish/wiki" ;发布路径
"wiki-xhtml"))
("Others"
("~/muse/source/others"
:default "index"
:force-publish ("WikiIndex"))
(:base "xhtml" :path "~/muse/publish/others"))

("Default" (,@(muse-project-alist-dirs "~/muse/source/default")
:default "index"
:force-publish ("WikiIndex"))
,@(muse-project-alist-styles "~/muse/source/default"
"~/muse/publish"
"default-xhtml"))

))

肯定有人会问,既然都用子目录结构了,为什么还定义那些子projects呢?因为目录树的这个功能很有限,他只会把相应文件发布并按目录树结构安装,而如果你还是想把Emacs、 Debian、GNU这些做为projects,方便项目之间的引用的话,还得在写上这些项目的定义。而且写法也得按一定的"规矩"来,这个"规矩"是:

* 1.源文件目录中最上层目录放到项目定义的最下面

配置中的WiKi就得安排在Muse、Debian、Emacs、GNU的下面,因为这些"子"项目所在的目录都在 WiKi的目录中,是它的子目录。

* 2.项目在配置文件里的设置是根据目录的层数的深度来确定位置,原则是层数深的不能在层数浅的上面

配置中Muse的目录比Debian和Emacs的深,所以在它们俩的上面,而相同深度的就随便谁在上谁在下都行。

* 3.如果两个项目没有目录树间的关系,可以随便写。

比如说Others就可以写在下面。

这个是我实验过很多次得出的最好的方法。因为在header和footer里有一些处理项目名称的函数,这样写不会出乱子。
top自定义派生的style
Muse之所以能生成多种格式的文件的原因之一我想可能就是这个功能了,在输出html格式方面,你可以自定义你的html文件的header和footer,这样使用起来很方便。其他输出文件格式请参考Muse文档。但是因为有了上面的Projects的管理的两种配置方法,这里也要相应地跟着变化。
top"并排"方式的派生style设置
这个也最简单,定义一个派生的style,把你想要的header.html和footer.html的路径写上可以了。而这两个文件是按照html的语法来写的,在发布时直接把其中的内容拷到发布的 html文件里。

(unless (assoc "my-blosxom" muse-publishing-styles)
(muse-derive-style "wiki-xhtml" "xhtml" ;定义一个派生的style为wiki-xhtml
:header "~/muse/common/templates/header.html"
:footer "~/muse/common/templates/footer.html"
)
(muse-derive-style "default-xhtml" "xhtml" ;定义另一个派生的style
:header "~/muse/common/templates/default- header.html"
:footer "~/muse/common/templates/default-footer.html"
))

如果要对其中一些可变的内容用lisp函数来处理理,可以在其中嵌入lisp函数,比如说我在 footer.html里要设定网页发布的时间,就可以加上这么变态的几句来处理:

最后更新:
<lisp>
(format-time-string "%4Y-%2m-%2d-%T"
(nth 5 (file-attributes
muse-publishing-current-file)))
</lisp>

然后效果就是:

最后更新: 2006-08-25-23:23:19

我的header.html和footer.html你可以参考一下。文件的内容可以看这里:

header.html

footer.html

下载在这里:

common/templates/header.html

common/templates/footer.html
top"目录树"方式派生style设置
因为要处理html文件里css和图片的相对路径的问题,所以按上面"并排"的方式设置派生 style是有些问题的。我实验过,css文件的路径处理可以在header.html里用 ywb-muse-relative-path函数来处理(这个函数在下面会介绍,不要急:),像这样:

<link rel="stylesheet" type="text/css" charset="utf-8" media="all"
href="<lisp>(ywb-muse-relative-path "common/stylesheets/core.css")</lisp>" />

但是对于图片链接就不行了比如说这个:

<a href="http://www.mwolson.org/projects/EmacsMuse.html">
<img style="border: 0em none ;"
src=" <lisp> (ywb-muse-relative-path "common/images/muse- powered-by.png")</lisp> " alt="Emacs Muse Logo"></a>

可能是因为elisp的或者是html对"""的处理问题吧。那现在怎么办呢?其实很简单,可以入到muse-init.el中,如果要写到emacs的配置文件里去在每一个"""前加一个"\"来转义就可以了。也可以单独写一份文件叫muse-header-footer.el ,在加载muse-init.el时同时加载它就行了。

;;; muse-init.el --- Initialize muse-mode.
;;;; Add below to ~/.emacs config file
;(load-file "~/.emacs.d/conf/muse-init.el")
;;;; xhtml footer and header (如果你沿用emacs-wiki那样定义多个项目而不用muse子目录发布功能,注掉它,这个在后面会说明)
(load-file "~/.emacs.d/conf/muse-footer-header.el")

文件的内容可以看这里:

muse-header-footer_el.html

下载在这里:

muse-header-footer.el
topGoogle的搜索栏
我是参考邢兆鹏的,只在要header里的<h1>title</h1>加上下面这段就行了。那个Google图片也是从他网站上拷下来的,希望他不介意:)

<h1>
<lisp>(muse-publishing-directive \"title\")</lisp>
<!-- Google Search -->
<div class=\"searchbar\">
<form id=\"searchbar\" method=\"get\" action=\" http://www.google.com/custom\" title=\"My Site Search\">
<div id=\"searchbar\">
<label for=\"q\" title=\"Search this site\">
<img src=\"<lisp> (ywb-muse-relative-path \"common/images/google.gif\")</lisp>\" ></label>
<input type=hidden name=domains value=\" http://www.yoursite.org/\">
<input type=hidden name=sitesearch value=\"http://www.yoursite.org/\">
<input type=\"text\" id=\"q\" name=\"q\" accesskey=\"s\" size=\"16\">
<input type=\"submit\" id=\"submit\" value=\"Go\">
</div>
</form>
</div>
<!-- Google Search -->
</h1>

如果要你用"并排"方式来设置projects,那么请把上面所有的"\"去掉,然后加到 header.html里。当然我已经给弄好了一份,可以看上面的两小节。
top导航菜单
跟Google搜索栏相似,在header.html里的最后加入下面的内容就行了。其实会lisp语言的话还可做的更灵活:)

<!-- menu start here -->
<div class=\"menu\">
<div class=\"menuitem\">
<a href=\" <lisp> (ywb-muse-relative-path \"index.html\")</lisp>\">Home</a>
</div>
<div class=\"menuitem\">
<a href=\" <lisp> (ywb-muse-relative-path \"wiki/index.html\")</lisp>\">WiKiNotes</a>
</div>
</div>
<!-- menu ends here -->

top自定义的函数
这些函数可以在叶文彬的Muse配置文件里找到:

http://learn.tsinghua.edu.cn:8080/20...csMusecof.html

他写的关于Muse的说明:

http://learn.tsinghua.edu.cn:8080/20...EmacsMuse.html
topywb-muse-relative-path
如果你想用Projects的管理方式中的"目录树"方式,这个函数可以说是写的极好,肯定必用!

(defun ywb-muse-relative-path (file)
(concat
(file-relative-name
my-muse-publish-directory
(file-name-directory muse-publishing-current-output-path))
file))

这个函数用于子目录发布,在发布的过程中推断出相对路径。有了这个函数,对于 css 或者图片名, 在muse-init.el或者muse-header-footer.el这样写就行了:

<lisp>(ywb-muse-relative-path \"css/core.css\")</lisp>

css/core.css 是相对于 my-muse-publish-directory 的路径。而my-muse-publish-directory是个变量,定义如下:

(defvar my-muse-publish-directory "~/muse/publish/")

* 说明:

这个变量和函数的作用,这个变量是跟定义了你的所有要发布文件要发布到哪个目录中去,而在你的这个目录中(~/muse/publish/)如果有一个文件夹为css,里面有个core.css 的文件,那么把这个函数放到xhtml的头文件的定义中去来代替里面的css文件的路径位置, 然后在发布过程中这个函数会把core.css这个文件相对于(~/muse/publish/)这个目录的相对路径输出到html文件里,所以对于放着我的这个html网页和其它文件的这个文件夹来说,只要目录里的文件和文件夹的相对位置不变,那么无论把这个文件夹放到谁的机器上还是放到服务器上,你用浏览器打开这个网页都能正常显示,因为css文件的路径是相对的,而底下的那一排图标的路径也是相对的。我问过Olson这个问题,他要我用绝对路径,他的网站上所有的css文件和图片的路径都是绝对路径。可是我还没有服务器上传,我只想在本机上看,用绝对路径在本地看肯定不行了。所以我觉得这个函数很棒,真是非常感谢叶文彬:)
topywb-muse-html-markup-table

;;;;_+ ywb-muse-html-markup-table
(defun ywb-muse-html-markup-table ()
(let ((str (match-string 1)))
(when (= (aref str 0) ?|)
(save-excursion
(save-match-data
(let ((endmarker (set-marker (make-marker) (match-end 0)))
(start (match-beginning 0))
(nextline (lambda () (forward-line 1) (point))))
(goto-char (1+ start))
(when (looking-at "|\\([-]+[|+]\\)+[ \t]*$")
(delete-region (point) (funcall nextline))
(perform-replace "[ \t]+|[ \t]+" " || " nil t nil nil nil
(point) (funcall nextline))
(delete-region (funcall nextline) (funcall nextline)))
(goto-char endmarker)
(forward-line -1)
(when (looking-at "|\\([-]+[|+]\\)+[ \t]*$")
(delete-region (point) (funcall nextline)))
(perform-replace "^|[ \t]*" "" nil t nil nil nil start endmarker)
(perform-replace "|[ \t]*$" "" nil t nil nil nil start endmarker)))))
(muse-html-markup-table)))

topywb-muse-publish-math-tab
org-mode 可以发布一些具有上标和下标的html代码。可以借来用一下。

;;;;_+ ywb-muse-publish-math-tab
(defun ywb-muse-publish-math-tab (beg end attrs)
(require 'org)
(let ((tag (or (cdr (assoc "tag" attrs)) "span")))
(insert (concat "<" tag " class=\"math\">"
(org-export-html-convert-sub-super
(delete-and-extract-region beg end))
"</" tag ">\n"))
(muse-publish-mark-read-only beg (point))))

topywb-muse-publish-src-tag
语法加亮。本网页中的emacs-lisp语法加亮都是用这个函数来实现的。

;;;;_+ ywb-muse-publish-src-tag
(defun ywb-muse-publish-src-tag (beg end attrs)
(let ((mode (cdr (assoc "type" attrs))))
(tp-muse-fontified-example-tag beg end nil
(intern-soft (concat mode "-mode")))))

topywb-muse-handle-file-link
处理文件链接的函数。

;;;;_+ ywb-muse-handle-file-link
(defun ywb-muse-handle-file-link (&optional string)
(or string
(setq string
(let ((end (save-excursion
(re-search-forward "]" nil t)
(1- (point)))))
(when end
(buffer-substring-no-properties (point) end)))))
(setq string
(expand-file-name
(concat (muse-get-keyword :path (nth 2 (muse-project)))
"/" string)))
(when (file-exists-p string)
string))

下面的这几句我看不太懂,但意思差不多明白,应该是把上面那些自定义的有增强功能的函数加到 Muse自带的相应函数里去。反正照写就是啦:)

;;;;_+
(add-to-list 'muse-html-markup-functions '(table . ywb-muse-html-markup-table))
(add-to-list 'muse-html-markup-tags '("math" t t ywb-muse-publish-math-tag))
(add-to-list 'muse-html-markup-tags '("src" t t ywb-muse-publish-src-tag))
(add-to-list 'muse-explicit-link-functions 'ywb-muse-handle-file-link)

top使contents更漂亮
因为薛瑞尼的css文件对contents做了一些设置,并用了一个好看的小图片(就是最上面 Contents中那一排金色的小圆圈),看了他的配置文件才知道,其实他是加了一层 contents,并且改用了sacha写的一个函数,我开始改写了这个函数,但是虽然Contents好看了,然后所有的标题里的内容都跑到外面去了,叶文彬指出了错误所以在(处理时多输出了一个回车),于是重新改写于下:

;;;_+ insert contents. contents should strip all the tags
(defun ywb/muse-publish-strip-tags (string)
(while (string-match "<.*?>" string)
(setq string (replace-match "" nil t string)))
string)
(defadvice muse-publish-contents-tag (around ywb activate)
(let* ((beg (ad-get-arg 0))
(end (ad-get-arg 1))
(attrs (ad-get-arg 2))
(max-depth (let ((depth (cdr (assoc "depth" attrs))))
(or (and depth (string-to-int depth)) 3)))
(index 1)
base contents l)
(save-excursion
(catch 'done
(while (re-search-forward "^\\(\\*+\\)\\s-+\\(.+\\)" nil t)
(setq l (length (match-string 1)))
(if (null base)
(setq base l)
(if (< l base)
(throw 'done t)))
(when (<= l max-depth)
(setq contents (cons (cons l (match-string-no-properties 2))
contents))
(goto-char (match-beginning 2))
(muse-html-insert-anchor (concat "sec" (int-to-string index)))
(delete-backward-char 1)
(setq index (1+ index))))))
(setq index 1 contents (reverse contents))
(let ((depth 1) (sub-open 0) (p (point)))
(insert "<div class=\"mulu\">
<h6 class=\"mulu\">Contents</h6>\n")
(insert "<dl class=\"contents\">\n")
(while contents
(insert "<dt class=\"contents\">\n")
(insert "<a href=\"#sec" (int-to-string index) "\">"
(ywb/muse-publish-strip-tags (cdar contents))
"</a>\n")
(setq index (1+ index))
(insert "</dt>\n")
(setq depth (caar contents)
contents (cdr contents))
(if contents
(cond
((< (caar contents) depth)
(let ((idx (caar contents)))
(while (< idx depth)
(insert "</dl>\n</dd>\n")
(setq sub-open (1- sub-open)
idx (1+ idx)))))
((> (caar contents) depth) ; can't jump more than one ahead
(insert "<dd>\n<dl class=\"contents\">\n")
(setq sub-open (1+ sub-open))))))
(while (> sub-open 0)
(insert "</dl>\n</dd>\n")
(setq sub-open (1- sub-open)))
(insert "</dl>\n")
(insert "</div>\n")
(put-text-property p (point) 'read-only t))))

但是好像不用这个函数也可以,因为可以在css文件中设置contents相应的属性,比如说像 flyzhy的网页中的Contents就感觉还不错。我写信问过他,他说是在css文件中设置的。

http://www.flyzhy.org/projects/WebsiteSettings.html

http://www.mwolson.org/projects/EmacsMuse.html

在Muse的NEWS-3.03(我下载的文件NEWS-3.03)中提到了:

Make the Table of Contents CSS easier to customize.
For an example, see examples/mwolson/stylesheets/screen.css.

如果真能实现像薛瑞尼那样的效果,那可真不错,起码省了一个函数。如果你弄明白了,一定要告诉我啊:)
top给每个标题加个top锚
薛瑞尼的网页中每个标题右边都有一个top的锚,如果一个网页很长,当你想回到页首看 contents的时候,这个锚就很有用了。但是薛瑞尼给我的sacha的函数已经不能用了,于是叶文彬就重写了一个,功能完全一样。

;;;_+ insert toplink in html files
(defun ywb/muse-publish-markup-heading ()
(let* ((len (length (match-string 1)))
(start (muse-markup-text
(cond ((= len 1) 'section)
((= len 2) 'subsection)
((= len 3) 'subsubsection)
(t 'section-other))
len))
(end (muse-markup-text
(cond ((= len 1) 'section-end)
((= len 2) 'subsection-end)
((= len 3) 'subsubsection-end)
(t 'section-other-end))
len)))
(delete-region (match-beginning 0) (match-end 0))
(muse-insert-markup start)
(insert
(propertize
"<span class=\"toplink\"><a href=\"#top\">top</a></span>"
'rear-nonsticky '(read-only) 'read-only t))
(end-of-line)
(when end
(muse-insert-markup end))
(muse-publish-section-close len)))
(defalias 'muse-publish-markup-heading 'ywb/muse-publish-markup-heading)

topywb-muse-publish-project
这个函数我没有用,因为我的配置好像不用它就能正常工作,而且项目组织用"目录树"方式,只要在最上层目录上按Cc Cp就能发布所有没有发布的文件,如果Cu Cc Cp的话,就是全部更新了:)叶文彬在这个函数中把源文件放到发布文件目录中的wikisource下的,我是分开的。而且改了改他的函数也没改对:)如果你看懂了,想改一下就试试吧。

;;;_+ publish functions
(defun ywb-muse-publish-project (&optional arg)
(interactive "P")
(let ((dir default-directory)
(published (muse-project-publish (muse-project) arg))
(muse-explicit-link-functions (remove
'ywb-muse-handle-file-link
muse-explicit-link-functions))
cmd)
(when (= (aref published 0) ?A)
(setq default-directory dir)
(setq cmd (concat "psync .*\\.muse$ "
(expand-file-name
(concat (muse-get-keyword :path (car (cddr
(muse-project))))
"/wikisource/"))))
(message cmd)
(shell-command cmd))
(message published)))

topywb-muse-output-file
这个函数在下面几个函数中用到了

* ywb-muse-publish-this-file
* ywb-muse-preview-with-w3m
* ywb-muse-preview-html
* ywb-muse-preview-source

(defun ywb-muse-output-file ()
"Get output file name"
(let ((styles (muse-project-applicable-styles buffer-file-name (cddr (muse-project))))
output-dir)
(while (and styles
(progn
(setq output-dir (muse-style-element :path (car styles)))
(not (file-exists-p output-dir))))
(setq styles (cdr styles)))
(when output-dir
(muse-publish-output-file
buffer-file-name
output-dir
"html"))))

topywb-muse-publish-this-file
Muse自带的muse-publish-this-file有个Bug,看stid的说明:

muse 中有一个比较不爽的地方,就是单独发布一个文件时,不会发布到指定的项目发布目录中,而用 C-c C-p 发布整个项目就没问题,这是一个 bug。
muse 的BugTracker系统上已经有人提过了,相信不久的将来会有改进。

叶文彬自己定义的发布正在编辑的文件的一个函数,有两个。

其实这不是Bug,只是作者写这个函数的意思被大家误解了吧。我现在用的这个Muse 版本1加上我的配置能自动处理了,不是修复了这个"Bug",而是换了一种方案。如果你装了我装的这个新版本,再按C-c C-h看看:)

C-c C-t muse-project-publish-this-file
C-c C-S-t muse-publish-this-file

如果你用的时候觉得这个"Bug"在你装的Muse的版本上还存在的话,可以试试这两个函数。

(defun ywb-muse-publish-this-file (&optional arg)
"Publish current file to html"
(interactive)
(save-buffer)
(let ((path (muse-get-keyword :path (nth 2 (muse-project)))))
(muse-publish-this-file "xhtml" path current-prefix-arg)))

(defun ywb-muse-publish-this-file (&optional arg)
"Publish current file to html"
(interactive)
(save-buffer)
(let* ((path (file-name-directory (ywb-muse-output-file)))
(muse-explicit-link-functions (remove 'ywb-muse-handle-file-link muse-explicit-link-functions))
(source-path (concat path "/wikisource/")))
(unless (file-exists-p source-path)
(message "Creating wiki source directory %s" source-path)
(make-directory source-path t))
(copy-file buffer-file-name source-path t)
(muse-project-publish-file buffer-file-name (cddr muse-current-project) current-prefix-arg)))

topywb-muse-generate-index
原来生成 index 的方法是在 Wiki Index.muse 里写上:

<lisp>(muse-index-as-string t t)</lisp>

叶文彬写了一个函数,可以使生成的 index 是网页的 title,只要在 Wiki Index.muse 中加上这一句:

<lisp>(ywb-muse-generate-index)</lisp>

也可以传递参数生成多个 project 的目录。例如:

<lisp>(ywb-muse-generate-index '("Debian" "Emacs" "Muse" "GNU"))</lisp>

;;;###autoload
(defun ywb-muse-generate-index (&optional project-list)
"Generate the index of all wikifile except the file in the\"website\" project"
(unless project-list
(setq project-list (list (car (muse-project)))))
(let (project-files title)
(muse-with-temp-buffer
(dolist (project project-list)
(setq project-files (muse-project-file-alist project))
(progn
(insert "* " project "\n"))
(dolist (file project-files)
(unless (or (equal (car file) "index")
(equal (car file) "WikiIndex"))
(insert " - [[" project "#" (car file) "]["
(save-excursion
(set-buffer (generate-new-buffer "*index*"))
(insert-file-contents (cdr file))
(goto-char (point-min))
(setq title
(if (re-search-forward "^#title" nil t)
(buffer-substring (point) (line-end-position))
(car file)))
(kill-buffer (current-buffer))
title)
"]]\n")))
(insert "\n"))
(buffer-string))))

topywb-muse-preview-with-w3m

;;;;_+ preview commands
(defun ywb-muse-preview-with-w3m ()
"Preview the html file"
(interactive)
; (ywb-muse-publish-this-file)
(muse-project-publish-this-file)
(let ((file (ywb-muse-output-file)))
(w3m-goto-url (if (string-match "^[a-zA-Z]:" file)
(ywb-convert-to-cygwin-path file)
(concat "file://" file)))))

topywb-muse-preview-html

(defun ywb-muse-preview-html ()
"Preview the html file"
(interactive)
; (ywb-muse-publish-this-file)
(muse-project-publish-this-file)
(browse-url (ywb-muse-output-file)))

topywb-muse-preview-source

(defun ywb-muse-preview-source ()
"Find the html file"
(interactive)
; (ywb-muse-publish-this-file)
(muse-project-publish-this-file)
(find-file (ywb-muse-output-file)))

top3.02.90 版中的一些问题
叶文彬对3.02.90版Muse中的一些问题的处理。我现在的版本没有测试过,不知道有没有这些问题,供你参考。

* 1. 图片可以自己定义处理路径的函数,但是 muse-colors-insert-image 函数中将 link 转换成绝对路径了,所以其它定义的函数仍然无效。其它文件链接仍然没有一个选项能将路径修改为发布的目录。
* 2. latex2png 中使用 (cd "/tmp"),但是不同平台下的 tmp 目录不同。

top解决方法

* 1. 将 muse-colors-insert-image 中的第一行注释:

;; (setq link (expand-file-name link))

我觉得最好不要一直显示图像,可以用命令 muse-colors-toggle-inline-images 来切换图像的显示。如果想文件的链接是相对于发布目录的路径,可以增加下面的函数:

(defun ywb-muse-handle-file-link (&optional string) ;见上面

* 2. 修改 latex2png 函数:

(defun latex2png (math prefix preamble)
"Convert the MATH code into a png with PREFIX."
(unless preamble
(setq preamble ""))
(let* ((tmppath (cond ((boundp 'temporary-file-directory)
temporary-file-directory)
((fboundp 'temp-directory)
(temp-directory))))
(texfile (expand-file-name
(concat prefix "_" (format "%d" (abs (sxhash math))))
tmppath))
(oldcddir default-directory))
(with-temp-file (concat texfile ".tex")
(insert (concat "\\documentclass{article}
\\usepackage{fullpage}
\\usepackage{amssymb}
\\usepackage[usenames]{color}
\\usepackage{amsmath}
\\usepackage{latexsym}
\\usepackage[mathscr]{eucal}\n" preamble
"\n\\pagestyle{empty}
\\begin{document}"
"{"
math
"}\n"
"\n\\end{document}\n\n")))
(cd tmppath)
(call-process "latex" nil nil nil texfile)
(if (file-exists-p (concat texfile ".dvi"))
(progn
(shell-command-to-string
(concat "dvipng " texfile ".dvi -E "
" -fg " latex2png-fg
" -bg " latex2png-bg " -T tight"
" -x " (format "%s" (* latex2png-scale-factor 1000))
" -y " (format "%s" (* latex2png-scale-factor 1000))
" -o " texfile ".png"))
(if (file-exists-p (concat texfile ".png"))
(progn
(delete-file (concat texfile ".dvi"))
(delete-file (concat texfile ".tex"))
(delete-file (concat texfile ".aux"))
(delete-file (concat texfile ".log"))
(cd oldcddir)
(concat texfile ".png"))
(message "Failed to create png file")))
(message (concat "Failed to create dvi file " texfile)))))

* 3. redefine muse-colors-toggle-inline-images

;;;;_+ redefine of function
(defun muse-colors-insert-image (link beg end invis-props)
"Create an image using create-image or make-glyph and insert it
in place of an image link defined by BEG and END."
;; (setq link (expand-file-name link))
(let ((image-file (cond
((eq muse-colors-inline-image-method 'default-directory)
link)
((functionp muse-colors-inline-image-method)
(funcall muse-colors-inline-image-method link))))
glyph)
(when (stringp image-file)
(if (fboundp 'create-image)
;; use create-image and display property
(add-text-properties beg end
(list 'display (create-image image-file)))
;; use make-glyph and invisible property
(and (setq glyph (muse-make-file-glyph image-file))
(progn
(add-text-properties beg end invis-props)
(add-text-properties beg end (list
'end-glyph glyph
'help-echo link))))))))

top环境变量设置

;;;;_+ variable setting
(add-to-list 'magic-mode-alist
'("#title " . muse-mode))
(when (featurep 'tp-muse-highlight)
(tp-muse-html-syntax-highlight-tag "sqlexample" 'sql-mode)
(tp-muse-html-syntax-highlight-tag "perlexample" 'cperl-mode)
(tp-muse-html-syntax-highlight-tag "javaexample" 'java-mode))

(custom-set-variables
;;;; If you don't want to use any extension at all,
;;;; and want Muse to autodetect project files based on their location,
;;;; then add the following to your Muse settings file.
'(muse-file-extension nil)
'(muse-mode-auto-p t)
;;;; If you don't want to use .muse, you can customize
;;;; the extension by setting the value of muse-file-extension.
'(muse-file-extension "muse")
;;;; The content type used for the HTML <meta> tag.
;;;; If you are striving for XHTML 1.1 compliance,
;;;; you may want to change this to "application/xhtml+xml".
; (setq muse-html-meta-content-type "text/html; charset=utf-8")
;;;; The charset to append to the HTML <meta> tag.
;;;; If set to the symbol 'detect, use muse-html-encoding-map
;;;; to try and determine the HTML charset from emacs's coding.
;;;; If set to a string, this string will be used to force a
;;;; particular charset.
'(muse-html-meta-content-encoding (quote utf-8))
;;;; The default HTML meta charset to use if no translation
;;;; is found in muse-html-encoding-map.
'(muse-html-charset-default "utf-8")

;;;; The default Emacs buffer encoding to use in published files.
;;;; This will be used if no special characters are found.
'(muse-html-encoding-default (quote utf-8))

;;;; An alist mapping emacs coding systems to appropriate HTML
;;;; charsets. Use the base name of the coding system
;;;; (i.e. without the -unix).
'(muse-html-encoding-map "utf8")
'(muse-colors-autogen-headings (quote outline))
'(muse-colors-inline-image-method (quote muse-colors-use-publishing-directory))
'(muse-html-meta-content-encoding (quote utf-8))

'(muse-html-meta-content-type "text/xhtml; charset=utf-8")
'(muse-mode-hook (quote (flyspell-mode footnote-mode)))
'(muse-publish-comments-p t)
'(muse-publish-desc-transforms (quote (muse-wiki-publish-pretty-title muse-wiki-publish-pretty-interwiki)))
'(muse-html-markup-functions (quote ((anchor . muse-html-markup-anchor) (table . muse-html-markup-table) (footnote . muse-html-markup-footnote))))
'(muse-table-line-regexp "^|?[[:blank:]]*\\(?:[^|\n]+\\||\\)[[:blank:]-]+\\([|+]+\\)\\(?:[[:blank:]-]+\\|$\\)[^|\n].*")
'(muse-mode-highlight-p t)
'(muse-wiki-ignore-bare-project-names t)
'(muse-colors-evaluate-lisp-tags nil)
;'(muse-html-style-sheet "<link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"all\" href=\"../common/stylesheets/core.css\" />")
;'(muse-xhtml-style-sheet "<link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"all\" href=\"../common/stylesheets/core.css\" />")
'(muse-wiki-publish-small-title-words (quote ("the" "and" "at" "on" "of" "for" "in" "an" "a" "page" "anime"))))

topPlanner抄来的配置

;;;_. planner
(require 'planner nil t)
(require 'planner-id nil t)
(when (featurep 'planner)
(global-set-key (kbd "<f9> t") 'planner-create-task-from-buffer)
(global-set-key (kbd "<f9> c") 'planner-create-task)
(global-set-key (kbd "<f9> <f9>") 'plan)
(require 'remember-planner nil t)
(when (featurep 'remember-planner)
(setq remember-annotation-functions planner-annotation-functions)
(setq remember-handler-functions '(remember-planner-append))))

(autoload 'remember "remember" nil t)
(autoload 'remember-region "remember" nil t)
(global-set-key (kbd "<f9> r") 'remember)
(global-set-key (kbd "<f9> s") 'remember-region)
(global-set-key (kbd "<f9> d") 'planner-diary-add-entry)

(require 'planner-diary nil t)
(when (featurep 'planner-diary)
(defun planner-diary-add-entry (date time text)
"Prompt for a diary entry to add to `diary-file'. Will run
planner-annotations to make hyper links"
(interactive (list (planner-read-date)
(read-string "Time: ")
(read-string "Diary entry: ")))
(save-excursion
(save-window-excursion
(make-diary-entry
(concat
(let ((cal-date (planner-filename-to-calendar-date date)))
(if european-calendar-style
(format "%d/%d/%d"
(elt cal-date 1)
(elt cal-date 0)
(elt cal-date 2))
(format "%d/%d/%d"
(elt cal-date 0)
(elt cal-date 1)
(elt cal-date 2))))
" " time " " text " "
(run-hook-with-args-until-success
'planner-annotation-functions))))))
(setq planner-diary-use-diary t)
(planner-insinuate-diary)
(planner-insinuate-calendar)
(setq planner-diary-number-of-days 7)
(setq planner-diary-number-of-diary-entries 7)
(setq planner-diary-file diary-file))

top快捷键设置

(setq muse-mode-hook
(lambda ()
(footnote-mode)
(auto-fill-mode 1)
(modify-syntax-entry ?> ")" muse-mode-syntax-table)
(modify-syntax-entry ?< "(" muse-mode-syntax-table)
(define-key muse-mode-map (kbd "C-c /") 'sgml-close-tag)
(define-key muse-mode-map (kbd "C-c t") 'sgml-tag)
; (define-key muse-mode-map (kbd "C-c C-t") 'ywb-muse-publish-this-file)
; (define-key muse-mode-map (kbd "C-c C-p") 'ywb-muse-publish-project)
(define-key muse-mode-map (kbd "C-c C-c") 'ywb-muse-preview-source)
(define-key muse-mode-map (kbd "C-c C-j") 'ywb-muse-preview-html)
(define-key muse-mode-map (kbd "C-c C-m") 'ywb-muse-preview-with-w3m)
(define-key muse-mode-map (kbd "<C-return>") 'ywb-html-insert-newline)
(define-key muse-mode-map (kbd "M-RET") 'ywb-insert-item)
))
;;Local variables:
;;allout-layout: (0 : -1 -1 0)
;;End:

top相关链接
topMuse相关
Muse-el BugTracker

http://blog.gmane.org/gmane.emacs.muse.general

Michael Olson—http://www.mwolson.org/projects/EmacsMuse.html

stid—http://learn.tsinghua.edu.cn:8080/98...macs-muse.html

flyzhy—http://www.flyzhy.org/projects/WebsiteSettings.html

ShiXin—http://www.xshi.org/notes/WebPage.html

Gunnar Wrobel—http://gunnarwrobel.de/wiki/EmacsMuseMode.html

Sun Yongke—http://cisd-ftp.swfc.edu.cn/~syk/WebWiki/muse.html

pluskid—http://blog.donews.com/pluskid/archi...06/858197.aspx 他写的用 stardict的sdcv版在emacs里查单词的插件很不错。

http://people.ku.edu/~yjli/dk/EmacsMuse.html

http://ryang.68ab.com/notes_tips.html#top

邢兆鹏—http://www.mysmu.edu/me2005/zhaopeng...g/journal.html 我网页上那个 Google是抄他的,嘿嘿:)
topEmacs Wiki相关

王垠—http://learn.tsinghua.edu.cn:8080/20...wiki/WiKi.html

LiYu—http://59.77.16.178/html/liyu/webpage/EmacsWikiZh.html LiYu的主页好像域名解析不了直接用ip吧:)

http://sacha.free.net.ph/notebook/wiki/AboutMe.php

http://grid.tsinghua.edu.cn/home/liu...lcomePage.html

http://staff.ustc.edu.cn/~yoyosu/Def...lcomePage.html

http://k.thec.cn/Corsair/WelcomePage.html

http://ann77.stu.cdut.edu.cn/EmacsWikiNote.html

http://wwwhomes.uni-bielefeld.de/tli...acs_using.html

http://www.iamstone.net/publish/note/Emacs.html

http://people.ku.edu/~yjli/dk/Emacswiki.html

--
一步一步教你从互联网赚钱 http://www.zqzn.com/index.asp?rid=key480769
投资理财 http://li-cai.blogspot.com/

没有评论: