Thursday, July 24, 2008

Apt和dpkg快速参考

Debian官方文档: http://www.debian.org/doc/user-manuals

Debian官方APT中文文档: http://www.debian.org/doc/manuals/apt-howto/index.zh-cn.html

apt-cache search # ------(package 搜索包)
apt-cache show #------(package 获取包的相关信息,如说明、大小、版本等)
apt-get install # ------(package 安装包)
apt-get install # -----(package --reinstall 重新安装包)
apt-get -f install # -----(强制安装, "-f = --fix-missing"当是修复安装吧...)
apt-get remove #-----(package 删除包)
apt-get remove --purge # ------(package 删除包,包括删除配置文件等)
apt-get autoremove --purge # ----(package 删除包及其依赖的软件包+配置文件等(只对6.10有效,强烈推荐))
apt-get update #------更新源
apt-get upgrade #------更新已安装的包
apt-get dist-upgrade # ---------升级系统
apt-get dselect-upgrade #------使用 dselect 升级
apt-cache depends #-------(package 了解使用依赖)
apt-cache rdepends # ------(package 了解某个具体的依赖,当是查看该包被哪些包依赖吧...)
apt-get build-dep # ------(package 安装相关的编译环境)
apt-get source #------(package 下载该包的源代码)
apt-get clean && apt-get autoclean # --------清理下载文件的存档 && 只清理过时的包
apt-get check #-------检查是否有损坏的依赖
dpkg -S filename -----查找filename属于哪个软件包
apt-file search filename -----查找filename属于哪个软件包
apt-file list packagename -----列出软件包的内容 
apt-file update --更新apt-file的数据库

dpkg --info "软件包名" --列出软件包解包后的包名称.
dpkg -l --列出当前系统中所有的包.可以和参数less一起使用在分屏查看. (类似于rpm -qa)
dpkg -l |grep -i "软件包名" --查看系统中与"软件包名"相关联的包.
dpkg -s 查询已安装的包的详细信息.
dpkg -L 查询系统中已安装的软件包所安装的位置. (类似于rpm -ql)
dpkg -S 查询系统中某个文件属于哪个软件包. (类似于rpm -qf)
dpkg -I 查询deb包的详细信息,在一个软件包下载到本地之后看看用不用安装(看一下呗).
dpkg -i 手动安装软件包(这个命令并不能解决软件包之前的依赖性问题),如果在安装某一个软件包的时候遇到了软件依赖的问题,可以用apt-get -f install在解决信赖性这个问题.
dpkg -r 卸载软件包.不是完全的卸载,它的配置文件还存在.
dpkg -P 全部卸载(但是还是不能解决软件包的依赖性的问题)
dpkg-reconfigure 重新配置



apt-get install
下载软件包,以及所有依赖的包,同时进行包的安装或升级。如果某个包被设置了 hold (停止标志,就会被搁在一边(即不会被升级)。更多 hold 细节请看下面。
apt-get remove [--purge]
移除 以及任何依赖这个包的其它包。
--purge 指明这个包应该被完全清除 (purged) ,更多信息请看 dpkg -P。

apt-get update
升级来自 Debian 镜像的包列表,如果你想安装当天的任何软件,至少每天运行一次,而且每次修改了
/etc/apt/sources.list 後,必须执行。

apt-get upgrade [-u]
升级所有已经安装的包为最新可用版本。不会安装新的或移除老的包。如果一个包改变了依赖关系而需要安装一个新的包,那么它将不会被升级,而是标志为 hold。apt-get update 不会升级被标志为 hold 的包 (这个也就是 hold 的意思)。请看下文如何手动设置包为 hold。我建议同时使用 '-u' 选项,因为这样你就能看到哪些包将会被升级。

apt-get dist-upgrade [-u]
和 apt-get upgrade 类似,除了 dist-upgrade 会安装和移除包来满足依赖关系。因此具有一定的危险性。

apt-cache search
在软件包名称和描述中,搜索包含xxx的软件包。

apt-cache show
显示某个软件包的完整的描述。

apt-cache showpkg
显示软件包更多细节,以及和其它包的关系。

dselect
console-apt
aptitude
gnome-apt
APT 的几个图形前端(其中一些在使用前得先安装)。这里 dselect 无疑是最强大的,也是最古老,最难驾驭。

普通 Dpkg 用法
dpkg -i
安装一个 Debian 包文件,如你手动下载的文件。

dpkg -c
列出 的内容。

dpkg -I
从 中提取包信息。

dpkg -r
移除一个已安装的包。

dpkg -P
完全清除一个已安装的包。和 remove 不同的是,remove 只是删掉数据和可执行文件,purge 另外还删除所有的配制文件。

dpkg -L
列出 安装的所有文件清单。同时请看 dpkg -c 来检查一个 .deb 文件的内容。

dpkg -s
显示已安装包的信息。同时请看 apt-cache 显示 Debian 存档中的包信息,以及 dpkg -I 来显示从一个 .deb 文件中提取的包信息。

dpkg-reconfigure
重新配制一个已经安装的包,如果它使用的是 debconf (debconf 为包安装提供了一个统一的配制界面)。你能够重新配制 debconf 它本身,如你想改变它的前端或提问的优先权。例如,重新配制 debconf,使用一个 dialog 前端,简单运行:

dpkg-reconfigure --frontend=dialog debconf (如果你安装时选错了,这里可以改回来哟:)

echo " hold" | dpkg --set-selections
设置 的状态为 hlod (命令行方式)

dpkg --get-selections ""
取的 的当前状态 (命令行方式)

支持通配符,如:
Debian:~# dpkg --get-selections *wine*
libwine hold
libwine-alsa hold
libwine-arts hold
libwine-dev hold
libwine-nas hold
libwine-print hold
libwine-twain hold
wine hold
wine+ hold
wine-doc hold
wine-utils hold

例如:
大家现在用的都是 gaim-0.58 + QQ-plugin,为了防止 gaim 被升级,我们可以采用如下方法:

方法一:
Debian:~# echo "gaim hold" | dpkg --set-selections
然後用下面命令检查一下:
Debian:~# dpkg --get-selections "gaim"
gaim hold
现在的状态标志是 hold,就不能被升级了。

如果想恢复怎么办呢?
Debian:~# echo "gaim install" | dpkg --set-selections
Debian:~# dpkg --get-selections "gaim"
gaim install
这时状态标志又被重置为 install,可以继续升级了。

同志们会问,哪个这些状态标志都写在哪个文件中呢?
在 /var/lib/dpkg/status 里,你也可以通过修改这个文件实现 hold。

有时你会发现有的软件状态标志是 purge,不要奇怪。
如:事先已经安装了 amsn,然後把它卸了。
apt-get remove --purge amsn
那么状态标志就从 install 变成 purge。

方法二:
在/etc/apt 下手动建一个 preferences 文件
内容:
Package: gaim
Pin: version 0.58*
保存

dpkg -S
在包数据库中查找 ,并告诉你哪个包包含了这个文件。(注:查找的是事先已经安装的包)

--------------------------------------------
Debian的软件包管理工具命令不完全列表
--------------------------------------------
Debian系统中所有的包信息都在/var/lib/dpkg下.其中/var/lib/dpkg/info目录中保存了各个软件包的信息及管理文件.每个文件的作用如下:
 以 ".conffiles" 结尾的文件记录软件包的配置列表.
 以 ".list" 结尾的文件记录了软件包的文件列表,用户可在文件当中找到软件包文件的具体安装位置.
 以 ".md5sums" 结尾的文件记录了md5信息,用来进行包的验证的.
 以 ".config" 结尾的文件是软件包的安装配置角本.
 以 ".postinst" 角本是完成Debian包解开之后的配置工作,通常用来执行所安装软件包相关的命令和服务的重新启动.
 以 ".preinst" 角本在Debain解包之前运行,主要作用是是停止作用于即将升级的软件包服务直到软件包安装或和升级完成.
 以 ".prerm" 脚本负责停止与软件包关联的daemon服务,在删除软件包关联文件之前执行.
 以 ".postrm" 脚本负责修改软件包链接或文件关联,或删除由它创建的文件.
 
 /var/lib/dpkg/available是软件包的描述信息.
 包括当前系统中所有使用的Debian安装源中所有的软件包,还包括当前系统中已经安装和未安装的软件包.
   
1.dpkg包管理工具
  dpkg --info "软件包名" --列出软件包解包后的包名称.
  dpkg -l --列出当前系统中所有的包.可以和参数less一起使用在分屏查看.
  dpkg -l |grep -i "软件包名" --查看系统中与"软件包名"相关联的包.
  dpkg -s 查询已安装的包的详细信息.
  dpkg -L 查询系统中已安装的软件包所安装的位置.
  dpkg -S 查询系统中某个文件属于哪个软件包.
  dpkg -I 查询deb包的详细信息,在一个软件包下载到本地之后看看用不用安装(看一下呗).
  dpkg -i 手动安装软件包(这个命令并不能解决软件包之前的依赖性问题),如果在安装某一个软件包的时候遇到了软件依赖的问题,可以用apt-get -f install在解决信赖性这个问题.
  dpkg -r 卸载软件包.不是完全的卸载,它的配置文件还存在.
  dpkg -P 全部卸载(但是还是不能解决软件包的依赖性的问题)
  dpkg -reconfigure 重新配置
2. apt高级包管理工具
  (1)GTK图形的"synaptic",这是APT的前端工具.
  (2)"aptitude",这也是APT的前端工具.
  用APT管理工具进行包的管理,可以有以下几种方法做源:
  (1)拿安装盘做源,方法如下:
  apt-cdrom ident 扫描光盘的信息
  apt-cdrom add 添加光盘源
  (2)这也是最常用的方法就是把源添加到/etc/apt/source.list中,之后更新列apt-get update
  APT管理工具常用命令
  apt-cache 加上不同的子命令和参数的使用可以实现查找,显示软件,包信息及包信赖关系等功能.
  apt-cache stats 显示当前系统所有使用的Debain数据源的统计信息.
  apt-cache search +"包名",可以查找相关的软件包.
  apt-cache show +"包名",可以显示指定软件包的详细信息.
  apt-cache depends +"包名",可以查找软件包的依赖关系.
  apt-get upgrade 更新系统中所有的包到最新版
  apt-get install 安装软件包
  apt-get --reindtall install 重新安装软件包
  apt-get remove 卸载软件包
  apt-get --purge remove 完全卸载软件包
  apt-get clean 清除无用的软件包
  在用命令apt-get install之前,是先将软件包下载到/var/cache/apt/archives中,之后再进行安装的.所以我们可以用apt-get clean清除/var/cache/apt/archives目录中的软件包.
  源码包安装
  apt-cache showsrc 查找看源码包的文件信息(在下载之前)
  apt-get source 下载源码包.
  apt-get build-dep +"包名" 构建源码包的编译环境.

Tuesday, July 22, 2008

tor + privoxy 实现代理上网

 tor + privoxy 

1. 概念 * tor 是一个用来匿名上网,隐藏自己踪迹的工具,实际上就是通过数量众多的代理服务器来让你上网,代理服务器有tor来收集,你只需要配置好tor就OK,不用自己手动去找代理。

* tor只提供了socks4的服务,要想让firefox通过tor上网,还必须配置privoxy,一个代理,将http的请求转发到tor的socks服务。 

2. 安装 * 基于Debian良好的软件包管理特性,只需要一条命令:

$ sudo apt-get install tor privoxy tor tsocks 

tor配置 /etc/tsocks.conf,

只需要三行即可:

server = 127.0.0.1

server_type = 5 

server_port = 9050 
privoxy 的配置文件(/etc/privoxy/config)里头加一句:
forward-socks4a / localhost:9050 . 
别漏掉了点。 
* 重新启动一下tor,privoxy: $ sudo /etc/init.d/privoxy restart 
/etc/init.d/tor restart

4. 设置firefox * 打开firefox,在连接属性里面改为手动设置代理:

host:localhost port:8118 * 就这样,firefox就可以上那些被屏蔽的网站了。

5.设置opera *打开opera,在工具-->首选项-->高级-->网络-->代理服务器 设置 

使用自动代理服务器配置 /home/jerry/.opera/proxy.pac

proxy.pac脚本内容为

function FindProxyForURL(url, host)
{
url = url.toLowerCase();
host = host.toLowerCase();//小写
proxyTor="PROXY localhost:8118" //定义代理,取决于你的代理方式

if(shExpMatch(host, "*my.opera.com*")) return proxyTor; //通配符*
else if(shExpMatch(host, "*.wikipedia.org*")) return proxyTor;
else if(shExpMatch(host, "*.blogspot.com*")) return proxyTor;
else if(shExpMatch(host, "*.technorati.com*")) return proxyTor;
else if(shExpMatch(host, "*.googlepages.com*")) return proxyTor;

else return "DIRECT"; //其它网站不用代理
}


加速OpenOffice


If you're an OpenOffice user, you've undoubtedly encountered the open source office suite's painstaking slow load up and the occasional freeze-up/stall. The Zolved weblog recommends making changes to the default settings in the "Memory" portion of OpenOffice's options dialog to speed things up. The tutorial at Zolved is written for Ubuntu Linux, however, you can apply similar tweaks to OpenOffice on Mac and Windows, too.

原文在这里 http://lifehacker.com/software/optimization/speed-up-openoffice-270775.php

1). 打开 OpenOffice Writer,在菜单中选择:工具->选项->内存: 

2). 修改:撤销命令->步数:20 
3). 修改:图形缓冲区->用于openoffice:128m,每个对象的内存:20m 
4). 激活:系统栏快速启动 
5). 取消 Java 选项页中的‘使用 Java 运行环境’ 设置input method 

debian/ubuntu网络pppoe安装以及加速

安装很简单

apt-get install pppoe pppoeconf dnsmasq

配置使用pppoeconf,其中一个选项很重要,不要选择覆盖DNS解析的文件/etc/resolv.conf,因为我们要选择dnsmasq来本地解析

也许是debian sid的bug,当我的adsl的拨号delay超过120秒的话,他就切断联结,搞的我装好sid以后网络老是不稳定

解决办法就是:

a--在终端输入 
sudo vim  /etc/ppp/options sudo vim /etc/ppp/peers/dsl-provider

将弹出的文档中的 lcp-echo-failure 4 改为 lcp-echo-failure 40 这是因为 debian si默认 
的设置有个很明显的缺陷,lcp-echo-failure 次数被设为 4,而 lcp-echo-interval 设为 30秒。也就是说,如果 120 秒钟之内,ADSL 服务器没有给回 echo-reply 信号,debian sid 便会认为网络已经出了问题,马上中断重联,搞得人非常不爽。 

提高ADSL(pppoe)上网速度
通过减少浏览器解释域名的时间提高上网速度1、安装dnsmasq
debian系统的用户使用
sudo apt-get install dnsmasq
archlinux系统的用户使用
sudo pacman -S dnsmasq

2、编辑dnsmasq的配置文件
sudo gedit /etc/dnsmasq.conf

找到下面这一项
#resolv-file=

用下面的一条语句替换
resolv-file=/etc/resolv_dnsmasq.conf

3、将原dns配置复制至resolv.dnsmasq.conf
确保你没有更改过/etc/resolv.conf文件,如果改过,恢复原状
sudo cp /etc/resolv.conf /etc/resolv_dnsmasq.conf(如果resolv.conf不是链接的情况下)
如果是链接请删除/resolv.conf,及
sudo rm /etc/resolv.conf
sudo cp /etc/ppp/resolv.conf /etc/resolv.conf
sudo cp /etc/ppp/resolv.conf /etc/resolv_dnsmasq.conf

4、编辑resolv.conf
sudo gedit /etc/resolv.conf

将其中的域名服务器全部去掉,加入以下这行
nameserver 127.0.0.1

保存,退出

5、编辑adsl链接配置文件,防止pppoe自动连接网络后resolv.conf的设置被覆盖
sudo gedit /etc/ppp/peers/dsl-provider(老版本的pppoe设置文件)
较新的.文件地址发生了改变。
sudo gedit /etc/ppp/pppoe.conf
在 usepeerdns (老版本),前面增加 # ,也就是把这条语句覆盖掉。
新版本的叫PEERDNS.

6、启动服务
debian系统的用户使用sysv-rc-conf工具来打开dnsmasq的默认开始状态和启用他。
或者直接sudo /etc/init.d/dnsmasq start.
archlinux用户,sudo gedit /etc/rc.conf 然后在daemon 段加入dnsmasq.
sudo /etc/rc.d/dnsmasq start,启用它。

现在感受dnsmasq的速度吧 。。


我的source.list存档

# deb cdrom:[Debian GNU/Linux testing _Lenny_ - Official Beta i386 CD Binary-1 20080630-10:20]/ lenny main

# deb cdrom:[Debian GNU/Linux testing _Lenny_ - Official Beta i386 CD Binary-1 20080630-10:20]/ lenny main

# Line commented out by installer because it failed to verify:
# deb http://security.debian.org/ lenny/updates main
# Line commented out by installer because it failed to verify:
# deb-src http://security.debian.org/ lenny/updates main


# sources.list generated by apt-spy v3.1

# CHINA 上午,晚上
# deb ftp://www.anheng.com.cn/debian/ sid main contrib non-free
# deb-src ftp://www.anheng.com.cn/debian/ sid main contrib non-free
# CHINA TW 下午
deb http://ftp.tw.debian.org/debian/ sid main contrib non-free
deb-src http://ftp.tw.debian.org/debian/ sid main contrib non-free
# deb http://security.debian.org/ lenny main contrib non-free

# debian multimedia
# do following command in a terminal as root (not sudo)
# wget http://debian-multimedia.org/gpgkey.pub -O - | apt-key add - && apt-get install debian-multimedia-keyring
deb http://ftp.tw.debian.org/debian-multimedia/ sid main
deb-src http://ftp.tw.debian.org/debian-multimedia/ sid main

# Emacs snapshot 23
# do following command in a terminal as root (not sudo)
# wget http://orebokech.com/Romain_Francoise.pgp -O - | apt-key add -
deb http://emacs.orebokech.com/ sid main
# deb-src http://emacs.orebokech.com/ sid main

# Google
# do following command in a terminal as root (not sudo)
# wget -q -O - http://dl.google.com/linux/linux_signing_key.pub | apt-key add -
deb http://dl.google.com/linux/deb/ stable non-free

# Compiz-fonsion
# do following command in a terminal as root (not sudo)
# wget http://download.tuxfamily.org/shames/A42A6CF5.gpg -O- | apt-key add -
deb http://download.tuxfamily.org/shames/debian-sid/desktopfx/unstable/ ./

## Opera
#KeyFetch: http http://deb.opera.com/archive.key
# deb http://deb.opera.com/opera/ stable non-free
# deb http://deb.opera.com/opera/ testing non-free
deb http://deb.opera.com/opera/ unstable non-free

## VirtualBox
#wget -q http://download.virtualbox.org/virtualbox/debian/sun_vbox.asc -O- | sudo apt-key add -
deb http://download.virtualbox.org/virtualbox/debian/ lenny non-free

Tuesday, July 15, 2008

现在的终端screen+urxvt

screen的配置文件

~/.screenrc.html
 1 #
 2 # This is an example for the global screenrc file.
 3 # You may want to install this file as /usr/local/etc/screenrc.
 4 # Check config.h for the exact location.
 5 #
 6 # Flaws of termcap and standard settings are done here.
 7 #Wed 21 Sep 2011 12:20:15 AM CST
 8 
 9 #startup_message off
10 
11 #defflow on # will force screen to process ^S/^Q
12 
13 deflogin on
14 #autodetach off
15 
16 vbell on
17 vbell_msg "   Wuff  ----  Wuff!!  "
18 
19 # all termcap entries are now duplicated as terminfo entries.
20 # only difference should be the slightly modified syntax, and check for
21 # terminfo entries, that are already corected in the database.
22 # 
23 # G0    we have a SEMI-GRAPHICS-CHARACTER-MODE
24 # WS    this sequence resizes our window.
25 # cs    this sequence changes the scrollregion
26 # hs@   we have no hardware statusline. screen will only believe that
27 #       there is a hardware status line if hs,ts,fs,ds are all set.
28 # ts    to statusline
29 # fs    from statusline
30 # ds    delete statusline
31 # al    add one line
32 # AL    add multiple lines
33 # dl    delete one line
34 # DL    delete multiple lines
35 # ic    insert one char (space)
36 # IC    insert multiple chars
37 # nx    terminal uses xon/xoff
38 
39 # 256color
40 terminfo rxvt-unicode 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
41 
42 # 这是配置那个tab bar
43 hardstatus alwayslastline
44 hardstatus string "%{=b}%{b}%-w%{.BW}%10>[%n %t]%{-}%+w%< %=%{G}%C%A, %Y-%m-%d"
45 #caption always "%{=u kC} %= %-w%L>%{=b G}[:%n %t:]%{-}%52<%+w %L=" termcapinfo xterm|rxvt ti@:te@
46 # screen里面的所有进程退出,screen就自动退出
47 autodetach on # default: on
48 # 退出vim/nano之后自动刷新屏幕
49 altscreen on
50 # 启动等待,显示版本
51 msgwait 2 version
52 # 启动信息
53 startup_message off # default: on
54 # 启用beep报错
55 #vbell off
56 # 默认的shell,不设置的话就是bash
57 # shell zsh
58 ## Keybindings ##
59 # C-a改为C-l
60 #escape ^L^L
61 # F10改标题
62 bindkey -k k; title
63 # F11左边的tab
64 bindkey -k F1 prev
65 # F12右边的tab
66 bindkey -k F2 next
67 
68 #remove some stupid / dangerous key bindings
69 bind ^k
70 #bind L
71 bind ^\
72 #make them better
73 bind \\ quit
74 bind K kill
75 bind I login on
76 bind O login off
77 bind } history
78 

urxvt配置

~/.Xdefaults.html
 1 ! vim: fdm=marker
 2 ! 修改了这个文件,必须$xrdb .Xdefaults让配置生效
 3 
 4 !! RXVT setting /*{{{*/
 5 !! Color
 6 !URxvt.background:black
 7 URxvt.background: [0]#000000
 8 !URxvt.foreground:gray60
 9 !URxvt.foreground:white
10 URxvt.foreground: #ffffff
11 !URxvt.geometry: 85x30+180+200
12 URxvt.colorBD:yellow
13 URxvt.colorUL:green
14 URxvt.cursorColor:red3
15 URxvt.color0:black
16 URxvt.color1:red3
17 URxvt.color2:springgreen
18 URxvt.color3:wheat3
19 URxvt.color4:navy
20 URxvt.color5:magenta4
21 URxvt.color6:steelblue1
22 URxvt.color7:gray85
23 URxvt.color8:gray10
24 URxvt.color9:orangered2
25 URxvt.color10:chartreuse3
26 URxvt.color11:lightgoldenrod2
27 URxvt.color12:skyblue1
28 URxvt.color13:pink1
29 URxvt.color14:lightblue1
30 URxvt.underlineColor: yellow
31 !urxvt typical
32 URxvt.cutchars: "`\"()';@?=,*<>[]{|}"
33 !Scroll
34 URxvt.scrollBar: true
35 URxvt.scrollBar_right: true
36 URxvt.scrollBar_floating: true
37 URxvt.scrollstyle: plain
38 URxvt.saveLines: 8192
39 !滚屏设置
40 URxvt.mouseWheelScrollPage:true
41 URxvt.scrollTtyoutput: False
42 URxvt.scrollWithBuffer: true
43 URxvt.scrollTtyKeypress: true
44 !cursor blink
45 URxvt.cursorBlink:true
46 !边框
47 URxvt.borderLess: false
48 !fonts
49 URxvt.font: \
50     xft:DejaVu Sans Mono:size=8, \
51     xft:WenQuanYi MicroHei Mono:pixelsize=12
52 URxvt.boldfont: \
53     xft:DejaVu Sans Mono:size=8, \
54     xft:WenQuanYi MicroHei Mono:pixelsize=12
55 !Xft.dpi:96
56 !URxvt.font:xft:WenQuanYi Micro Hei Mono:size=10:style=Regular:antialias=true,xft:WenQuanYi Micro Hei Mono:size=9:style=Regular:antialias=true
57 !URxvt.boldfont:xft:WenQuanYi Micro Hei Mono:size=10:style=BOld:antialias=true,xft:WenQuanYi Micro Hei Mono:size=9:style=Bold:antialias=true
58 !URxvt.font:xft:Dejavu Sans Mono-10,xft:WenQuanYi Bitmap Song-10
59 !URxvt.boldFont:xft:Dejavu Sans Mono-10:Bold,xft:WenQuanYi Bitmap Song-10:Bold
60 
61 !italicFont and boldItalicFont undefined
62 !URxvt.font: xft:Luxi Mono:regular:antialias=True:pixelsize=15,
63 !URxvt.font: xft:Monaco:medium:autohint=True:size=10, \
64 !                xft:DejaVu Sans Mono:book:autohint=True:size=10, \
65 !                xft:wenquanyi bitmap song:medium:pixelsize=15:antialias=True
66 !URxvt.boldFont: xft:Luxi Mono:bold:antialias=True:pixelsize=15,
67 !URxvt.boldFont: xft:Monaco:bold:autohint=True:size=10, \
68 !                xft:DejaVu Sans Mono:bold:autohint=True:size=10, \
69 !                xft:wenquanyi bitmap song:bold:pixelsize=15:antialias=True
70 
71 
72 !Input Method
73 URxvt.inputMethod: ibus
74 !URxvt.preeditType: OverTheSpot
75 !URxvt.imFont: WenQuanYi Bitmap Song
76 !Open URLs in firefox tabbar
77 !!支持tab
78 ! tab切换:shift+left/shift+right
79 ! 移动tab:ctrl+left/ctrl+right
80 ! 新建tab:shift+down
81 URxvt.perl-ext-common:  default,matcher,tabbed
82 URxvt.urlLauncher:      /usr/bin/firefox
83 URxvt.matcher.button:   1
84 
85 /*}}}*/

jerry-key-bindings.el

;;; jerry-key-bindings.el --- 全局键盘绑定设置

;;; Code:

;;统一设置键帮定,并尽量放在配置文件的最后,以免被绑定的键不小心被后面
;;的配置文件覆盖
;;常用习惯,F1打开帮助,常用帮助有info和woman(就是在emacs中看man)
(global-set-key [f1] 'info)
;;显示man在一个buffer里面,常用
(global-set-key [(control f1)] 'woman)
;;恢复,常用键
(global-set-key [f2] 'undo)
;;打开sawfish的配置文件
(global-set-key [(control f3)] 'my-open-dot-sawfishrc)
;;打开.emacs的快捷方式
(global-set-key [(control f2)] 'my-open-dot-emacs)
;;打开fvwm的.fvwm2rc和config的快速方式,我现在使用fvwm,常用
;(global-set-key [(control f3)] 'my-open-fvwmconfig)
;;反恢复,不是很常用,但是绑定了还是方便些
(global-set-key [f3] 'redo)
;;F4,kill键,习惯设置,关闭当前buffer
(global-set-key [f4] 'kill-this-buffer)
;(global-set-key [f5] 'speedbar)
;;文件管理器,常用
(global-set-key [f6] 'dired-jump)
;;打开一个终端,根据你的爱好可以绑定为:eshell,shell,terminal-emulator
(global-set-key [f5] 'eshell)
;(global-set-key [f5] 'ansi-term)
;;同clear相识,具体功能在jerry-functions.el讲过
(global-set-key [f7] 'my-line-to-top-of-window)
;;本人正在学scheme,常用
;(global-set-key [f8] 'run-scheme)
;;;F9:列举我的书签
(global-set-key [f8] 'list-bookmarks)
;;;F9:添加当前页到书签中
;;(global-set-key [f9] 'bookmark-set)
;;看新闻组,常用的很,不过更多时间现在sir里
(global-set-key [f9] 'gnus)
;;习惯设置,打开/关闭菜单
(global-set-key [f10] 'menu-bar-mode)
;;编译等,暂时还不常用
(global-set-key [f11] 'compile)
;(global-set-key [f12] 'todo-show)
(global-set-key [f12] 'gdb)

;;习惯设置,Home键设定光标到文件开头
(global-set-key [(home)] 'beginning-of-buffer)
;;习惯设置,End键设定光标到文件结尾
(global-set-key [(end)] 'end-of-buffer)

;; Meta
(global-set-key "\M- " 'set-mark-command)
(global-set-key "\M-\C-h" 'backward-kill-word)
(global-set-key "\M-\C-r" 'query-replace)
(global-set-key "\M-r" 'replace-string)
;(global-set-key "\M-g" 'goto-line)
(global-set-key "\M-h" 'help-command)
;;Alt+s : 让speedbar获得焦点
(global-set-key (kbd "M-s") 'speedbar-get-focus)

;;meta在常用PC键上就是Alt键
;;这三个绑定主要是光标移动的
(global-set-key [(meta down)] 'goto-line)
(global-set-key [(meta left)] 'backward-sexp)
(global-set-key [(meta right)] 'forward-sexp)
;;NB:这下面的几个快捷键还没有熟练使用
;;注释region
;;比较常用,来回改的麻烦,还是这个方便
(global-set-key [(meta m)] 'comment-region)
(global-set-key [(meta u)] 'uncomment-region)
;; 常用补全命令
(global-set-key (kbd "M-/") 'hippie-expand)

;; ;;小键盘的bindings
;; (global-set-key [up] "\C-p")
;; (global-set-key [down] "\C-n")
;; (global-set-key [left] "\C-b")
;; (global-set-key [right] "\C-f")
;; ;(global-set-key [home] "\C-a")
;; ;(global-set-key [end] "\C-e")
;; (global-set-key [prior] "\M-v"); prior就是上翻页pg up
;; (global-set-key [next] "\C-v"); AKA pg dn
;; (global-set-key [C-up] "\M-\C-b")
;; (global-set-key [C-down] "\M-\C-f")
;; (global-set-key [C-left] "\M-b")
;; (global-set-key [C-right] "\M-f")
;; (global-set-key [C-home] "\M-<")
;; (global-set-key [C-end] "\M->")
;; ;(global-set-key [C-prior] "\M-<"); AKA pg up
;; ;(global-set-key [C-next] "\M->") ; AKA pg dn

;;快速切换buffer,prior就是上翻页pg up,next就是pg dn键盘
(global-set-key [C-prior] 'swbuff-switch-to-previous-buffer)
(global-set-key [C-next] 'swbuff-switch-to-next-buffer)
;;Win更换tabbar不错吧,前两个是在不同的分组切换,后面的是在同组
;;切换
(global-set-key [s-up] 'tabbar-backward-group)
(global-set-key [s-down] 'tabbar-backward-group)
;(global-set-key (kbd "M-]") 'tabbar-forward-group)
(global-set-key [s-left] 'tabbar-backward-tab)
(global-set-key [s-right] 'tabbar-forward-tab)
;;括号配对
(global-set-key "%" 'my-match-paren)
;;类似vi的f命令,使用方法为C-c a "x",x为任意字符,找第几个字符
(define-key global-map (kbd "C-c a") 'my-go-to-char)
;;hide region
(global-set-key (kbd "C-c r") 'hide-region-hide)
(global-set-key (kbd "C-c R") 'hide-region-unhide)
;;hide lines
(global-set-key (kbd "C-c l") 'hide-lines)
(global-set-key (kbd "C-c L") 'show-all-invisible)
;; 因为C-c m不是已有的前缀,所以要先定义一下
(define-prefix-command 'ctl-cm-map)
(global-set-key (kbd "C-c m") 'ctl-cm-map)
;; msf-abbrev的几个快捷键
(global-set-key (kbd "C-c ml") 'msf-abbrev-goto-root)
(global-set-key (kbd "C-c ma") 'msf-abbrev-define-new-abbrev-this-mode)
;;todo的几个快捷键
(global-set-key "\C-ct" 'todo-show) ;; switch to TODO buffer
(global-set-key "\C-ci" 'todo-insert-item) ;; insert new item
;;使用的ibuffer
(global-set-key (kbd "C-x C-b") 'ibuffer)
;; (global-set-key (kbd "C-x C-b") 'ibuffer-other-window)
;;remember的快捷键
(define-key global-map (kbd "C-c C-r") 'remember)
;(define-key global-map [f9] 'remember-region)
;;C-x C-r ,TAP列出最近打开的文件列表
(global-set-key "\C-x\C-r" 'recentf-open-files-compl)
;;让当前buffer生效的快捷方式
(add-hook 'emacs-lisp-mode-hook
  (lambda ()
  (local-set-key "\C-c\C-c" 'eval-buffer)
  ))
;;为什么我就不能使用这个键呢,原来和fcitx输入法冲突了
(global-set-key [C-k] 'kill-line)


;;打开org的记事本,纪念,网络链接等
(define-key global-map "\C-cs" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
;(define-key global-map "\C-cr" 'org-remember)
;;用Emacs时常用多个窗口,窗口之间的移动很常见
;; 默认的打开文件太差劲,使用通用的操作方式吧
;(global-set-key [(control o)] 'ido-find-file)
(global-set-key [(meta o)] 'other-window)
;;这就是我的切换buffer的设置,同windows操作相识
;;没法,windows用了两年多,有些习惯还真不好改
;;不过emacs的配置就是好配,随你配
(global-set-key [(control tab)] 'tabbar-forward)
;;这个设置是改变outline的快捷键前缀
;;outline主要用于编程等,目前用的不多
(setq outline-minor-mode-prefix (kbd "C-o"))
(mapc (lambda (bind)
  (define-key outline-minor-mode-map
  (car bind)
  (cdr bind)))
  `((,(kbd "C-o q") . hide-sublevels)
  (,(kbd "C-o a") . show-all)
  (,(kbd "C-o t") . hide-body)
  (,(kbd "C-o c") . hide-entry)
  (,(kbd "C-o e") . show-entry)
  (,(kbd "C-o l") . hide-leaves)
  (,(kbd "C-o k") . show-branches)
  (,(kbd "C-o d") . hide-subtree)))

;;自定义自动补齐命令,这部分是抄hhuu的,如果在单词中间就补齐,否则
;; 就是tab。
;(global-set-key [(control tab)] 'my-indent-or-complete)
;; 直观地把矩形显示出来
;; 作为和绑定到 C-x C-x 的 exchange-point-and-mark 对应起来
(global-set-key (kbd "C-x r C-x") 'rm-exchange-point-and-mark)
;;快速跳转到当前buffer所对应的目录
;(define-key global-map (kbd "C-x C-j") 'dired-jump)
(define-key global-map (kbd "C-x 4 C-j") 'dired-jump-other-window)


;;默认的Ctrl-z是什么来着,关闭emacs吧,好像还是强行关闭,不好,用
;;C-x c就好了
;;我就将Ctrl-z作为我的键的绑定
(define-prefix-command 'ctl-z-map)
(global-set-key (kbd "C-z") 'ctl-z-map)
;;启动picture (artist)模式
(global-set-key (kbd "C-z a") 'artist-mode)
;;编译当前emacs-lisp源码为elc
(global-set-key (kbd "C-z b") 'emacs-lisp-byte-compile)
;;打开我得日历
(global-set-key (kbd "C-z c") 'calendar)
;;字典功能,就是查单词
(global-set-key (kbd "C-z d d") 'dictionary-lookup-definition)
;;与上面类似
(global-set-key (kbd "C-z d s") 'dictionary-search)
;;查询当前单词的匹配的单词,用于补全单词
(global-set-key (kbd "C-z d m") 'dictionary-match-words)
;;字典提示模式,同字典的自动取词功能相似
;;查stardict字典
(global-set-key (kbd "C-z d t") 'sdcv-search)
;(global-set-key (kbd "C-z d t") 'kid-sdcv-to-buffer)
;(global-set-key (kbd "C-z d m") 'kid-star-dict)
;(global-set-key (kbd "C-z d t") 'dictionary-tooltip-mode)
;;编辑环境变量,很好用的功能
(global-set-key (kbd "C-z e e") 'edit-env)
;;启动我的IRC客户端,到sir去
(global-set-key (kbd "C-z e s") 'erc-irc)
;;到fans聊天去
(global-set-key (kbd "C-z e f") 'erc-fans)
;;启动拼写检查模式,只检查打开后输入的单词
(global-set-key (kbd "C-z f m") 'flyspell-mode)
;;对整个buffer进行拼写检查
(global-set-key (kbd "C-z f b") 'flyspell-buffer)
;;打开gnus
(global-set-key (kbd "C-z g") 'gnus)
;;数数本文件有多少文字
(global-set-key (kbd "C-z h c") 'my-count-words-region)
;;同Clear键
(global-set-key (kbd "C-z h l") 'my-line-to-top-of-window)
;;使用hyperspec查询common lisp的symbol定义
(global-set-key (kbd "C-z h s") 'hyperspec-lookup)
;;把高亮显示当前buffer输出为html格式的文件
(global-set-key (kbd "C-z h z") 'htmlize-buffer)
;;拼写检查
(global-set-key (kbd "C-z i") 'ispell-minor-mode)
;;debug
(global-set-key (kbd "C-z j") 'jdb)
;;查看前面删除的内容记录
(global-set-key (kbd "C-z k") 'browse-kill-ring)
;;关闭没有用的buffer
(global-set-key (kbd "C-c k") 'my-clean-buffers)
;;打印当前buffer
;(global-set-key (kbd "C-z l") 'lpr-buffer)
(global-set-key (kbd "C-z l") 'my-longest-line)
;;启动我得maxima,漂亮模式
;(global-set-key (kbd "C-z m m") 'imaxima)
;;看看我的键绑定
(global-set-key (kbd "C-z m k") 'my-keytable)
;;emms相关的快捷键
;; global key-map
(global-set-key (kbd "H-b") 'emms-playlist-mode-go)

(global-set-key (kbd "C-c e t") 'emms-play-directory-tree)
(global-set-key (kbd "C-c e x") 'emms-start)
(global-set-key (kbd "C-c e v") 'emms-stop)
(global-set-key (kbd "C-c e n") 'emms-next)
(global-set-key (kbd "C-c e p") 'emms-previous)
(global-set-key (kbd "C-c e o") 'emms-show)
(global-set-key (kbd "C-c e h") 'emms-shuffle)
(global-set-key (kbd "C-c e e") 'emms-play-file)
(global-set-key (kbd "C-c e f") 'emms-play-playlist)
(global-set-key (kbd "C-c e SPC") 'emms-pause)
(global-set-key (kbd "C-c e a") 'emms-add-directory-tree)

(global-set-key (kbd "C-c e r") 'emms-toggle-repeat-track)
(global-set-key (kbd "C-c e R") 'emms-toggle-repeat-playlist)

(global-set-key (kbd "C-c e s u") 'emms-score-up-playing)
(global-set-key (kbd "C-c e s d") 'emms-score-down-playing)
(global-set-key (kbd "C-c e s o") 'emms-score-show-playing)
;; playlist-mode-map
(define-key emms-playlist-mode-map (kbd "SPC") 'emms-pause)
(define-key emms-playlist-mode-map (kbd "+") 'emms-volume-raise)
(define-key emms-playlist-mode-map (kbd "-") 'emms-volume-lower)
(define-key emms-playlist-mode-map (kbd "")
  (lambda () (interactive) (emms-seek-forward)));;+10)))
(define-key emms-playlist-mode-map (kbd "")
  (lambda () (interactive) (emms-seek-backward)));;-10)))
;; (define-key emms-playlist-mode-map (kbd "")
;; (lambda () (interactive) (emms-seek +60)))
;; ;(define-key emms-playlist-mode-map (kbd (""))
;; ; (lambda () (interactive) (emms-seek -60)))
(define-key emms-playlist-mode-map (kbd "S u") 'emms-score-up-file-on-line)
(define-key emms-playlist-mode-map (kbd "S d") 'emms-score-down-file-on-line)
(define-key emms-playlist-mode-map (kbd "S o") 'emms-score-show-file-on-line)
(define-key emms-playlist-mode-map (kbd "S l") 'emms-score-less-tolerant)
(define-key emms-playlist-mode-map (kbd "S m") 'emms-score-more-tolerant)
(define-key emms-playlist-mode-map (kbd "S t") 'emms-score-set-tolerance)
(define-key emms-playlist-mode-map (kbd "S s") 'emms-score-show-playing)

;;发送邮件
(global-set-key (kbd "C-z m s") 'mew-send)
;;接收邮件
(global-set-key (kbd "C-z m r") 'mew)

;;绑定两个narrow功能
(global-set-key (kbd "C-z n n") 'narrow-to-region)
(global-set-key (kbd "C-z n w") 'widen)
;;occur使用正则查找,列出一个buffer
(global-set-key (kbd "C-z o") 'occur)

;;几个小游戏
(global-set-key (kbd "C-z p g") 'gomoku)
(global-set-key (kbd "C-z p t") 'tetris)
;;训练绑定键盘的
(global-set-key (kbd "C-z p k") 'keywiz)
;;由于在html-helper-mode模式中F4键失效,用这个绑定来关闭buffer
(global-set-key (kbd "C-z q") 'kill-this-buffer)
;;带正则表达式的搜索
(global-set-key (kbd "C-z r") 'query-replace-regexp)
;;我得scheme也是可以在emacs中运行的
;(global-set-key (kbd "C-z s") 'run-scheme)
;;打开行号显示,和vi一样的
(global-set-key (kbd "C-z s s") 'setnu-mode)
;;把speedbar集成到emacs的frame里
;(global-set-key (kbd "C-z s b") 'reset-window-config)
;;我的终端
(global-set-key (kbd "C-z t") 'term)
;;我的文件管理器
(global-set-key (kbd "C-z u d") 'dired-jump)
;; ;;FIXME 还是使用dired-single吧
;; (global-set-key (kbd "C-z u d")
;; 'joc-dired-magic-buffer)
;; (global-set-key (kbd "C-z 4 d")
;; (lambda (directory)
;; (interactive "D")
;; (let ((win-list (window-list)))
;; (when (null (cdr win-list)) ; only one window
;; (split-window-vertically))
;; (other-window 1)
;; (joc-dired-magic-buffer directory))))
(global-set-key (kbd "C-z u f") 'folding-mode)
(global-set-key (kbd "C-z u o") 'outline-minor-mode)
;;查询service,见jerry-other-elisp.el
(global-set-key (kbd "C-z u s") 'services-lookup)
;;可以在emacs编辑文件使用vim习惯,常用的是vi-mode和viper-mode
(global-set-key (kbd "C-z v") 'vi-mode)
;;wiki中的绑定设置,还用的不多
(global-set-key (kbd "C-z w c") 'emacs-wiki-change-project)
(global-set-key (kbd "C-z w f") 'emacs-wiki-find-file)
(global-set-key (kbd "C-z w h") 'emacs-wiki-preview-html)
(global-set-key (kbd "C-z w i") 'emacs-wiki-index)
(global-set-key (kbd "C-z w p") 'emacs-wiki-publish)
(global-set-key (kbd "C-z w s") 'emacs-wiki-search)
;;我的浏览器
(global-set-key (kbd "C-z w w") 'w3m)
;;同C-z b有点不同,在编译后并加载
(global-set-key (kbd "C-z x") 'emacs-lisp-byte-compile-and-load)
;;同yank有点不一样,但具体怎样忘了,感觉这个比yank好点
(global-set-key (kbd "C-z y") 'clipboard-yank)
;;修改后的设定mark的绑定,由于经常忘了放住control键,就给这个功能两个绑
;;定了
(global-set-key (kbd "C-z z") 'set-mark-command)
(global-set-key (kbd "C-z C-z") 'set-mark-command)


;;there are severl other key-map below in other files
;;ctrl-f-folding-mode-prefix
;;ido key-map
;;severl self define functions related key-bindings.

(provide 'jerry-key-bindings)

;;; jerry-key-bindings.el ends here

jerry-other-elisp.el

;;; jerry-other-elisp.el ---

;; ASCII码表
(autoload 'ascii "ascii-table" "ASCII TABLE" t)
;; 保存状态
(require 'session)
(add-hook 'after-init-hook
  'session-initialize)
;;use both desktop and session
;(setq desktop-globals-to-save '(desktop-missing-file-warning))

;; redo
(require 'redo)

;; Add "Open Recent" menu to the Files menu.
;; Must be set before require, else not passed on initial call to
;; package it seems. Not sure why.
(setq recentf-save-file (expand-file-name "recentf" "~/.emacs.d/")
  recentf-max-saved-items 100
  recentf-max-menu-items 20
  ;recentf-exclude '("/VM/" "/Gnus/" "/bbdb" "\\`/[a-zA-Z0-9@]+:")
  )
;; 一个使用recentf可以打开最近打开文件列表的功能
(defun recentf-open-files-compl ()
  (interactive)
  (let* ((all-files recentf-list)
  (tocpl (mapcar (function
  (lambda (x) (cons (file-name-nondirectory x) x))) all-files))
  (prompt (append '("最近打开的文件: ") tocpl))
  ;;(prompt (append '("File name: ") tocpl))
  (fname (completing-read (car prompt) (cdr prompt) nil nil)))
  (find-file (cdr (assoc-string fname tocpl)))))

(require 'recentf)
(recentf-mode 1)

;;firefox风格的tabbar
(require 'tabbar)
(tabbar-mode)

;;快速切换buffer
(require 'swbuff)
(setq swbuff-exclude-buffer-regexps
  '("^ " "\\*.*\\*"))
(setq swbuff-status-window-layout 'scroll)
(setq swbuff-clear-delay 1)
(setq swbuff-separator "|")
(setq swbuff-window-min-text-height 1)

;;制作图表的
;(require 'table)
(autoload 'table-insert "table" "WYGIWYS table editor")
(add-hook 'text-mode-hook 'table-recognize)

;; 观看kill-ring
(require 'browse-kill-ring)
(browse-kill-ring-default-keybindings)

(autoload 'sawfish-mode "sawfish" "sawfish-mode" t)

(autoload 'maxima "maxima" "Maxima interaction" t)
(autoload 'maxima-mode "maxima" "Maxima mode" t)
(autoload 'emaxima-mode "emaxima" "Emaxima" t)
(add-hook 'emaxmia-mode-hook 'emaxima-mark-file-as-emaxima)

(autoload 'imaxima "imaxima" "Image support for Maxima." t)

;;2种编辑html的好模式
(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
(autoload 'css-mode "css-mode" "Mode for editing CSS files" t)

;;查看端口
(autoload 'services-lookup "services" "Perform a service lookup" t)
(autoload 'services-clear-cache "services" "Clear the service cache" t)

;;查看C的type
(require 'ctypes)
(ctypes-auto-parse-mode 1)
;;使用xcscope
(require 'xcscope)

;;emacs的grep
;(require 'igrep)
(autoload 'igrep "igrep"
  "*Run `grep` PROGRAM to match EXPRESSION in FILES..." t)
(autoload 'igrep-find "igrep"
  "*Run `grep` via `find`..." t)
(autoload 'igrep-visited-files "igrep"
  "*Run `grep` ... on all visited files." t)
(autoload 'dired-do-igrep "igrep"
  "*Run `grep` on the marked (or next prefix ARG) files." t)
(autoload 'dired-do-igrep-find "igrep"
  "*Run `grep` via `find` on the marked (or next prefix ARG) directories." t)
(autoload 'Buffer-menu-igrep "igrep"
  "*Run `grep` on the files visited in buffers marked with '>'." t)
(autoload 'igrep-insinuate "igrep"
  "Define `grep' aliases for the corresponding `igrep' commands." t)
(autoload 'igrep-find-query-replace "igrep-find-query-replace" "" t)
(put 'igrep-files-default 'c++-mode
  (lambda () "*.h *.cpp *.c"))
(put 'igrep-files-default 'c-mode
  (lambda () "*.[ch]"))

;;fvwm的高亮显示
;(require 'fvwm-mode)
(autoload 'fvwm-mode "fvwm-mode" "Mode for editing for fvwm files" t)

;;cscope的前端
;(require 'xcscope)


;; hide region
(require 'hide-region)

;; hide lines
(require 'hide-lines)

;; sdcv mode使用sdcv查字典
(require 'sdcv-mode)

;; windzoom平滑分割窗口
;(require 'windzoom)

;; emms 配置
;;; setup emms
;;(add-to-list 'load-path
;; (expand-file-name "~/emacs/packages/emms"))

(require 'emms-source-file)
(require 'emms-source-playlist)
(require 'emms-player-simple)
(require 'emms-player-mplayer)
(require 'emms-playlist-mode)
(require 'emms-info)
(require 'emms-cache)
(require 'emms-mode-line)
(require 'emms-playing-time)
(require 'emms-score)
(require 'emms-volume)

(setq emms-playlist-default-major-mode 'emms-playlist-mode)
(add-to-list 'emms-track-initialize-functions 'emms-info-initialize-track)
(add-to-list 'emms-info-functions 'kid-emms-info-simple)
(setq emms-track-description-function 'kid-emms-info-track-description)
(when (fboundp 'emms-cache)
  (emms-cache 1))

(setq emms-player-list
  '(emms-player-mpg321
  emms-player-ogg123
  emms-player-mplayer))

(setq emms-info-asynchronously nil)
(setq emms-playlist-buffer-name "*Music*")
; use faster finding facility if you have GNU find
(setq emms-source-file-directory-tree-function 'emms-source-file-directory-tree-find)
; My musics
(setq emms-source-file-default-directory "/media/hda6/舞曲")
(add-hook 'emms-player-started-hook 'emms-show)
; mode line format
(setq emms-mode-line-format "[ %s "
  emms-playing-time-display-format "%s ]")
(setq global-mode-string
  '("" emms-mode-line-string " " emms-playing-time-string))
;
(defun kid-emms-info-simple (track)
  "Get info from the filename.
mp3 标签的乱码问题总是很严重,幸好我系统里面的音乐文件
都放得比较有规律,所以我决定直接从文件名获取标签信息。"
  (when (eq 'file (emms-track-type track))
  (let ((regexp "/\\([^/]+\\)/\\([^/]+\\)\\.[^.]+$")
  (name (emms-track-name track)))
  (if (string-match regexp name)
  (progn
  (emms-track-set track 'info-artist (match-string 1 name))
  (emms-track-set track 'info-title (match-string 2 name)))
  (emms-track-set track
  'info-title
  (file-name-nondirectory name))))))

(defun kid-emms-info-track-description (track)
  "Return a description of the current track."
  (let ((artist (emms-track-get track 'info-artist))
  (title (emms-track-get track 'info-title)))
  (format "%-10s +| %s"
  (or artist
  "")
  title)))

;; show the line number
(require 'setnu)
(autoload 'setnu-plus "setnu-plus" t)

;; 把高亮显示的文本输出为html
;(require 'htmlize)
(setq htmlize-html-charset "gb2312")
(autoload 'htmlize-buffer "htmlize" "" t)

;; 高亮过于长的行
(require 'highlight-beyond-fill-column)

;;CJK Table
(if window-system
  (autoload 'keisen-mode "keisen-mouse" "MULE table" t)
  (autoload 'keisen-mode "keisen-mule" "MULE table" t))

;;图像化的矩形操作
(require 'rect-mark)

;; Auto rename the重名buffer
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)

;; svn的客户端
(require 'psvn)

;;;;;"Remember" is a mode for remembering data.
(autoload 'remember "remember" nil t)
(autoload 'remember-region "remember" nil t)

;; 多主模式的使用
(autoload 'mmm-mode "mmm-mode" "Multiple Major Modes" t)
(autoload 'mmm-parse-buffer "mmm-mode" "Automatic MMM-ification" t)
;(set-face-background 'mmm-default-submode-face nil)

;;使用ibuffer,把菜单里的也换掉
(require 'ibuffer)
(setq ibuffer-delete-window-on-quit t)
(defadvice ibuffer-quit (after kill-ibuffer activate)
  "Kill the ibuffer buffer on exit."
  (kill-buffer "*Ibuffer*"))
;; NB unusual way to modify menu entry. Found by C-h v menu-bar- [TAB].
(setq menu-bar-buffers-menu-command-entries
  ;;'(list-all-buffers menu-item "List All Buffers" ibuffer
  ;; (nil)
  ;; :help "Pop up a window listing all Emacs buffer"))
  '((command-separator "--")
 ;;(next-buffer menu-item "Next Buffer" next-buffer
 (next-buffer menu-item "下一个Buffer" next-buffer
  ([24 C-right]
  . " (C-x )")
  :help "在一个循环里切换到 \"next\" buffer")
  ;;:help "Switch to the \"next\" buffer in a cyclic order")
 ;;(previous-buffer menu-item "Previous Buffer" previous-buffer
 (previous-buffer menu-item "前一个Buffer" previous-buffer
  ([24 C-left]
  . " (C-x )")
  :help "在一个循环里切换到 \"previous\" buffer")
  ;;:help "Switch to the \"previous\" buffer in a cyclic order")
 ;;(select-named-buffer menu-item "Select Named Buffer..." switch-to-buffer
 (select-named-buffer menu-item "从Buffer的名字里选择..." switch-to-buffer
  ([24 98]
  . " (C-x b)")
  :help "提示buffer的名字,并把选中的buffer显示在当前的窗口")
  ;;:help "Prompt for a buffer name, and select that buffer in the current window")
 ;;(list-all-buffers menu-item "List All Buffers" ibuffer ;;就是这样
 (list-all-buffers menu-item "列出所有的buffers" ibuffer ;;就是这样
  ([24 98]
  . " (C-x C-b)")
  ;;(nil)
  :help "弹出一个窗口列出所有打开的buffer")))
  ;;:help "Pop up a window listing all Emacs buffers")))
;; Ibuffer的彩色效果
(setq ibuffer-formats '((mark modified read-only " " (name 16 16) " "
  (size 6 -1 :right) " " (mode 16 16 :center)
  " " (process 8 -1) " " filename)
  (mark " " (name 16 -1) " " filename))
  ibuffer-elide-long-columns t
  ibuffer-eliding-string "&")

;; edit-env 编辑环境变量
(require 'edit-env)

;; keywiz游戏- 训练你的键绑定-crazy game
(require 'keywiz)

;; todo mode
(autoload 'todo-mode "todo-mode"
  "Major mode for editing TODO lists." t)
(autoload 'todo-show "todo-mode"
  "Show TODO items." t)
(autoload 'todo-insert-item "todo-mode"
  "Add TODO item." t)
(setq todo-file-do "~/.emacs.d/todo-do")
(setq todo-file-done "~/.emacs.d/todo-done")
(setq todo-file-top "~/.emacs.d/todo-top")

;; slime
(add-to-list 'load-path "~/lib/emacs-lisp/slime-2.0/") ; your SLIME directory
;;(setq inferior-lisp-program "/opt/sbcl/bin/sbcl") ; your Lisp system
(require 'slime)
(slime-setup)
;;如果安装了 Emacs-w3m 的话,直接在 Emacs-w3m 里面打开 HyperSpec 就更方便了:
(require 'hyperspec)
(setq common-lisp-hyperspec-root "file:/usr/share/doc/hyperspec/")
;; (setq browse-url-browser-function
;; '(("/usr/share/doc/hyperspec/" . w3m-browse-url)
;; ("." . browse-url-default-browser)))

(provide 'jerry-other-elisp)

;;; jerry-other-elisp.el ends here

jerry-mew.el

;;; jerry-mew.el --- mew的配置
;;;;;;;;;;;;;;;;;;;;;
;;启动和初始化mew的设置
;;将emacs收发邮件的默认设置为gnus改为mew
;;;;;;;;;;;;;;;;;;;;;
(autoload 'mew "mew" nil t)
(autoload 'mew-send "mew" nil t)
;;设定图表所在文件夹,这个和w3m类似,如果不正确,mew无法启动
;(setq mew-icon-directory "/usr/share/mew")
(if (boundp 'read-mail-command)
  (setq read-mail-command 'mew))
(autoload 'mew-user-agent-compose "mew" nil t)
(if (boundp 'mail-user-agent)
  (setq mail-user-agent 'mew-user-agent))
(if (fboundp 'define-mail-user-agent)
  (define-mail-user-agent
  'mew-user-agent
  'mew-user-agent-compose
  'mew-draft-send-message
  'mew-draft-kill
  'mew-send-hook))


;;;;;;;;;;;;;;;;;;;;;;
;;信件引用设置
;;;;;;;;;;;;;;;;;;;;;;
(setq mew-cite-fields '("From:" "Subject:" "Date:" "Message-ID:"))
(setq mew-cite-format "From: %s\nSubject: %s\nDate: %s\nMessage-ID: %s\n\n")
(setq mew-cite-prefix-function 'mew-cite-prefix-username)


;;;;;;;;;;;;;;;;;;;;;
;;用w3m来读html格式邮件
;;w3m的使用将在以后讲到
;;;;;;;;;;;;;;;;;;;;;
(setq mew-mime-multipart-alternative-list '("Text/Html" "Text/Plain" "*."))
(condition-case nil
  (require 'mew-w3m)
  (file-error nil))


;;;;;;;;;;;;;;;;;
;;一些其他设置,未归类
;;;;;;;;;;;;;;;;;
(setq mew-pop-size 0)
(setq toolbar-mail-reader 'Mew)
(set-default 'mew-decode-quoted 't)
;;设定公共钥匙所用程序,下面采用的是GnuPG
(setq mew-prog-pgp "gpg")


;;;;;;;;;;;;
;;设定用户信息
;;;;;;;;;;;;
(setq mew-name "Jarod Lau")
(setq mew-user "jerry")


;;;;;;;;;;;;
;;设定smtp服务器
;;个人原因,这里不列出我的正确Email
;;;;;;;;;;;;
(setq mew-smtp-user "jarodlau@163.com")
(setq mew-mail-domain "163.com")
(setq mew-smtp-server "smtp.163.com")
;;smtp服务器认证设定
(setq mew-smtp-auth-list (quote ("CRAM-MD5" "LOGIN" "PLAIN")))
;;smtp服务器不用认证采用下面设定
;(setq mew-smtp-auth-list nil)


;;;;;;;;;;;
;;设定pop3服务器
;;个人原因,这里不列出我的正确Email
;;;;;;;;;;;
(setq mew-pop-server "pop.163.com")
(setq mew-pop-user "jarodlau@163.com")
(setq mew-pop-auth 'pass) ;;认证方式
(setq mew-pop-delete nil) ;;将邮件留在服务器上

;;;;;;;;;;;;
;;设定将密码保存一段时间,默认20分钟
;;;;;;;;;;;;
(setq mew-use-cached-passwd t)
;;gnus可以将密码放在配置文件里,收邮件的时候就不用输入密码了
;;我找了一下,发现下面这个变量应该有类似功能,但没有搞掂,高人帮忙!
(setq mew-passwd-alist '(ilyjerry))

;;;;;;;;;;;;;;;;;;;;;
;;语言设置
;;这个不知道有用没,好像在下一版emacs对unicode支持好了就可以了
;;当然这个试用emacs-cvs
;;;;;;;;;;;;;;;;;;;;;
(when (boundp 'utf-translate-cjk)
  (setq utf-translate-cjk t)
  (custom-set-variables
  '(utf-translate-cjk t)))
(if (fboundp 'utf-translate-cjk-mode)
  (utf-translate-cjk-mode 1))

(provide 'jerry-mew)

;;; jerry-mew.el ends here

jerry-mode.el

;;; jerry-mode.el --- 编程模式mode的配置

(add-hook 'text-mode-hook 'turn-on-auto-fill)

;;{{{ Menu ;;;;

(if (boundp 'vc-menu-map)
  (add-to-list 'minor-mode-map-alist
  `(vc-mode keymap
  (menu-bar keymap
  (VC menu-item "VC" ,vc-menu-map)))))

(define-key-after menu-bar-tools-menu [server-start]
  '("(重新)启动server" . server-start) t)
  ;;'("(Re)start Server" . server-start) t)


(defun my-menu-bar-find-file (file doc help)
  "Make a menu-item to visit a file read-only.
FILE is the file to visit, relative to `data-directory'.
DOC is the text to use the menu entry.
HELP is the text to use for the tooltip."
  `(menu-item ,doc
  (lambda () (interactive)
  (find-file-read-only
  (expand-file-name ,file data-directory)))
  :help ,help))

(let ((last 'emacs-problems) ; start point in menu
  file doc this)
  (mapcar (lambda (elem)
  (setq file (car elem)
  doc (cdr elem)
  ;; NB how make symbol on the fly. Not `make-symbol'.
  this (intern (concat "emacs-" (downcase file))))
  (define-key-after menu-bar-help-menu `[,this]
  (my-menu-bar-find-file file doc doc)
  last)
  (setq last this))
  '(("TODO" . "Emacs的TODO")
  ("DEBUG" . "Emacs调试信息")
  ("JOKES" . "Emacs笑话")
  ("future-bug" . "Emacs未来的bug"))))
  ;; '(("TODO" . "Emacs TODO List")
  ;; ("DEBUG" . "Emacs Debugging Information")
  ;; ("JOKES" . "Emacs Jokes")
  ;; ("future-bug" . "Emacs Future Bug"))))


;; cf menu-bar-make-mm-toggle.
(defmacro my-menu-bar-make-local-mm-toggle (fname doc help &optional props)
  "Make a menu-item for a local minor mode toggle.
FNAME is the minor mode's name (variable and function).
DOC is the text to use the menu entry.
HELP is the text to use for the tooltip.
PROPS are additional properties."
  `'(menu-item ,doc ,fname
  ,@(if props props)
  :help ,help
  :button (:toggle . (and (boundp ',fname)
  ,fname))))

(or (fboundp 'menu-bar-make-mm-toggle) ; for 21.3
  (defmacro menu-bar-make-mm-toggle (fname doc help &optional props) ""
  `'(menu-item ,doc ,fname
  ,@(if props props)
  :help ,help
  :button (:toggle . (and (default-boundp ',fname)
  (default-value ',fname))))))


(when (boundp 'menu-bar-options-menu)

  ;; Note that an error in a definition of this kind caused Emacs to exit
  ;; after "loading tooltip" portion of startup.
  (define-key-after menu-bar-options-menu [show-trailing-whitespace]
  (my-menu-bar-make-local-mm-toggle
  show-trailing-whitespace
  "高亮句子结尾的空格"
  "高亮句子结尾的空格(显示结尾的空白)")
  ;;"Trailing Whitespace Highlighting"
  ;;"Highlight whitespace at line ends (Show Trailing Whitespace)")
  'highlight-paren-mode)

  (define-key-after menu-bar-options-menu [toggle-auto-image]
  (menu-bar-make-mm-toggle auto-image-file-mode
  "自动显示图片文件"
  "以查看图片的方式显示图片")
  ;; "Automatic Display of Image Files"
  ;; "Visit image files as images")
  'toggle-auto-compression)

  (define-key-after menu-bar-options-menu [debug-on-signal]
  (menu-bar-make-toggle
  toggle-debug-on-signal debug-on-signal
  "以信号的方式进入Debugger" "在 %s 信号上调试"
  "不管条件处理模式,进入Lisp的调试模式")
  ;; "Enter Debugger on Signal" "Debug on Signal %s"
  ;; "Enter Lisp debugger regardless of condition handlers")
  'debug-on-error)

  (if (boundp 'menu-bar-showhide-menu)
  (define-key menu-bar-showhide-menu [ruler]
  (my-menu-bar-make-local-mm-toggle ruler-mode
  "Ruler" "ruler显示/不显示"))
  ;;"Ruler" "Turn ruler on/off"))

  (define-key-after menu-bar-options-menu [tool-bar-separator]
  '("--") 'debug-on-quit)

  (define-key-after menu-bar-options-menu [tool-bar]
  (menu-bar-make-mm-toggle tool-bar-mode "收起工具条"
  "切换工具条的显示")
  ;;"Toggle Tool Bar"
  ;;"Toggle display of the tool-bar")
  'tool-bar-separator)

  (define-key-after menu-bar-options-menu [display-time]
  (menu-bar-make-mm-toggle
  display-time-mode "切换显示 时间/邮件"
  "切换显示 时间/邮件 的指示器"))))
  ;;"Toggle Display Time/Mail"
  ;;"Toggle display of the time and mail indicator"))))

;;}}} Menu ;;;;

;;{{{ Font-lock ;;;;
;;;
;;启动语法高亮模式
(global-font-lock-mode t)
;;使用gdb的图形模式
(setq gdb-many-windows t)
(global-font-lock-mode 1)
;;一些具体的设置,从别的地方拷过来的,目前编程较少,所以也没具体改了,感觉目前配置还是非常不错的
;;如果你是一个程序员,这块你可以仔细改改
(setq font-lock-maximum-decoration t
  ;; Removed text-mode from this exclusion list for 21.
  ;; Otherwise yanking preserves font-lock attributes of kill buffer,
  ;; which is annoying. Still need hook to actually enable
  ;; font-lock mode for text-mode - see below.
  ;; Then put back in as it messes up latex mode as well.
  font-lock-global-modes '(not shell-mode text-mode)
  font-lock-verbose t
  font-lock-maximum-size '((t . 1048576) (vm-mode . 5250000)))

;; Extra highlighting.
(mapcar '(lambda (element)
  (let ((mode (car element))
  (comment (cdr element)))
  (font-lock-add-keywords
  mode
  '((,comment ("\\<\\(GM\\|NB\\|TODO\\|FIXME\\)\\>" nil nil
  (0 'font-lock-warning-face t)))
  (,comment ("[* ]\\*\\([a-zA-Z].*\\)\\*" nil nil
  (1 'font-lock-warning-face t)))
  (,comment ("`\\([^`']+\\)'" nil nil
  (1 'font-lock-constant-face t)))))))
 '((awk-mode . "#")
  (sh-mode . "#")
  (fortran-mode . "^C")
  (f90-mode . "!")
  (makefile-mode . "#")))

;; Support mode.
;; jit-lock doesn't seem to work for MIME messages in VM.
(setq font-lock-support-mode
  (if (boundp 'jit-lock-mode)
  '((vm-mode . fast-lock-mode) (t . jit-lock-mode))
  'fast-lock-mode))

;; Jit-lock.
(setq jit-lock-stealth-verbose nil
  jit-lock-stealth-time 2
  ;; If system load rises above this value, pause stealth fontification.
  jit-lock-stealth-load 90
  ;; Seconds to pause between chunks of stealth fontification.
  jit-lock-stealth-nice 0.5
  ;; If nil, deferred fontification only on lines directly modified.
  ;; If t, on those line plus any following.
  ;; Any other value, only if syntactic fontification for that buffer.
  jit-lock-defer-contextually 'syntax-driven)

;; Fast-lock. Caches font-lock information to speed up loads.
(setq fast-lock-minimum-size 50000 ; but not for small files
  fast-lock-verbose 50000 ; so keep quiet
  ;; Or kill-buffer, kill-emacs. If did not save, do not care.
  fast-lock-save-events '(save-buffer)
  fast-lock-save-others nil ; no font-caching for others' files
  ;; Prefer all information to be in one place rather than ./
  fast-lock-cache-directories `(,(expand-file-name "flc" "~/.emacs.d/")))

(mapcar '(lambda (element)
  (let ((dir (if (listp element) (cdr element) element)))
  (or (file-directory-p dir) (make-directory element))))
 fast-lock-cache-directories)
;;;
;;}}} Font-lock ;;;;

;;{{{ 缩写词abbrev mode
;; ensure abbrev mode is always on
(setq-default abbrev-mode t)
;; do not bug me about saving my abbreviations
(setq save-abbrevs nil)
;; load up msf-abbrevs for these modes
(require 'msf-abbrev)
(setq msf-abbrev-verbose t) ;; optional
(setq msf-abbrev-root "~/.emacs.d/mode-abbrevs")
;; (global-set-key (kbd "C-c ml") 'msf-abbrev-goto-root)
;; (global-set-key (kbd "C-c ma") 'msf-abbrev-define-new-abbrev-this-mode)
(msf-abbrev-load)
;;}}}

;;{{{ c-mode 的配置,专门为kernel的编程风格做一个模块

;; face
(font-lock-add-keywords
 'c-mode
 `(("/\\*" ("\\<\\(GM\\|NB\\|FIXME\\|TODO\\)\\>"
  nil nil (0 'font-lock-warning-face t)))
  ;; More complex than usual to avoid comments commented by coment-region.
  ("/\\*" ("\\*\\([^ ][^*]*[^ ]*\\)\\*[^//]"
  nil nil (1 'font-lock-warning-face t)))
  ("/\\*" ("`\\([^`']+\\)'" nil nil (1 'font-lock-constant-face t)))
  (,(regexp-opt '("&&" "||" "<=" ">=" "==" "!=" ; overkill?
  "++" "--" "+=" "-=" "*=" "/=") t) .
  font-lock-constant-face)))
;; This will define the M-x my-linux-c-mode command. When hacking on a
;; module, if you put the string -*- linux-c -*- somewhere on the first
;; two lines, this mode will be automatically invoked. Also, you may want
;; to add
;; (add-hook 'c-mode-hook
;; '(lambda () (hs-minor-mode 1)
;; (or (file-expand-wildcards "[Mm]akefile")
;; (set (make-local-variable 'compile-command)
;; (format "gcc %s" buffer-file-name)))))

;; (setq auto-mode-alist (cons '("/usr/src/linux.*/.*\\.[ch]$" . my-linux-c-mode)
;; auto-mode-alist))
;; (setq auto-mode-alist (cons '("/home/jerry/linux.*/.*\\.[ch]$" . my-linux-c-mode)
;; auto-mode-alist))

;; 我的linux的kernel的编辑策略

(defun my-linux-c-mode ()
  "C mode with adjusted defaults for use with the Linux kernel."
  (interactive)
  (c-mode)
  (c-set-style "k&r")
  (setq tab-width 8)
  (setq indent-tabs-mode t)
  (setq c-basic-offset 8))

;; FIXME 我的C/C++语言编辑策略

(defun my-c-mode-common-hook()
  (c-set-style "k&r")
  (setq tab-width 4 indent-tabs-mode t)
;;;(setq tab-width 4 indent-tabs-mode nil)
;;; hungry-delete and auto-newline
  (c-toggle-auto-hungry-state 1)
  (hs-minor-mode 1)
  (setq abbrev-mode 1)
  ;;按键定义
  (define-key c-mode-base-map [(control \`)] 'hs-toggle-hiding)
  (define-key c-mode-base-map [(return)] 'newline-and-indent)
  (define-key c-mode-base-map [(f7)] 'compile)
  (define-key c-mode-base-map [(f8)] 'ff-get-other-file)
  (define-key c-mode-base-map [(meta \`)] 'c-indent-command)
  ;; (define-key c-mode-base-map [(tab)] 'hippie-expand)
  (define-key c-mode-base-map [(tab)] 'my-indent-or-complete)
  (define-key c-mode-base-map [(meta ?/)] 'semantic-ia-complete-symbol-menu)
  ;;预处理设置
  (setq c-macro-shrink-window-flag t)
  (setq c-macro-preprocessor "cpp")
  (setq c-macro-cppflags " ")
  (setq c-macro-prompt-flag t)
  ;; (require 'xcscope)
  ;; ;;显示C的typedef
  ;; (require 'ctypes)
  ;; (ctypes-auto-parse-mode 1)
  )
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

(add-hook 'c-mode-hook 'imenu-add-menubar-index)

;; (defun my-ctypes-load-hook ()
;; (ctypes-read-file "~/.ctypes_std_c" nil t t))
;; (add-hook 'ctypes-load-hook 'my-ctypes-load-hook)

;;打开c mode的时候打开cscope,和type define

;;;;我的C++语言编辑策略
(defun my-c++-mode-hook()
  (setq tab-width 4 indent-tabs-mode nil)
  ;; (require 'xcscope)
  ;; ;;显示C的typedef
  ;; (require 'ctypes)
  ;; (ctypes-auto-parse-mode 1)
  (c-set-style "stroustrup")
  ;; (define-key c++-mode-map [f3] 'replace-regexp)
  )

(add-hook 'c++-mode-hook 'my-c++-mode-hook)

;;;;C/C++语言启动时自动加载semantic对/usr/include的索引数据库
(setq semanticdb-search-system-databases t)
(add-hook 'c-mode-common-hook
  (lambda ()
  (setq semanticdb-project-system-databases
  (list (semanticdb-create-database
  semanticdb-new-database-class
  "/usr/include")))))
;;}}} c mode

;;{{{ 我的Java语言编辑策略
(defun my-java-mode-hook()
  (setq tab-width 4 indent-tabs-mode nil)
  )

(add-hook 'java-mode-hook 'my-java-mode-hook)
;;}}}

;;{{{ Python Mode设置
;; (add-to-list 'load-path "/home/jerry/lib/emacs-lisp/python-mode-1.0")
;; (require 'python-mode)
;; ;;(require 'pycomplete)
;; (require 'doctest-mode)
;;}}}

;;{{{ 注释配置
;; (load-file "/home/jerry/lib/emacs-lisp/gnome-doc.el")
;;}}}


;;{{{ makefile-mode ;;;;
(add-hook 'makefile-mode-hook 'imenu-add-menubar-index)
;;}}} makefile-mode ;;;;

;;{{{ Lisp-mode ;;;;

;; 增加一些常用的高亮颜色
(font-lock-add-keywords
 'emacs-lisp-mode
 '((";" ("\\<\\(GM\\|NB\\|TODO\\|FIXME\\)\\>" nil nil
  (0 'font-lock-warning-face t)))
  (";" ("[* ]\\*[ \t]*\\(\\w.*\\)\\*" nil nil
  (1 'font-lock-warning-face t)))))


;; (mapcar (function (lambda (elem)
;; (add-hook 'emacs-lisp-mode-hook elem)))
;; '(imenu-add-menubar-index turn-on-eldoc-mode))
;; ;; checkdoc-minor-mode))

;; lisp 开发用的
(defun my-emacs-lisp-mode-hook-fn ()
  "Function added to `emacs-lisp-mode-hook'."
  (local-set-key "\C-cd" 'my-jump-to-defun)
  ;;(hs-minor-mode 1)
  ;; A little shorter than "Emacs-Lisp".
  ;; Avoid lisp-interaction and other derived modes.
  (if (eq major-mode 'emacs-lisp-mode)
  (setq mode-name "Elisp"))
  (when (boundp 'comment-auto-fill-only-comments)
  (setq comment-auto-fill-only-comments t)
  (kill-local-variable 'normal-auto-fill-function)))

(add-hook 'emacs-lisp-mode-hook 'my-emacs-lisp-mode-hook-fn)

(defun my-lisp-interaction-mode-hook-fn ()
  "Function added to `lisp-interaction-mode-hook'."
  (setq mode-name "Lisp Int"))
(add-hook 'lisp-interaction-mode-hook 'my-lisp-interaction-mode-hook-fn)

(setq eval-expression-print-level 10
  eval-expression-print-length 100)

;;}}} Lisp-mode ;;;;

;;{{{ WoMan ;;;;
(setq
 woman-cache-filename (expand-file-name "woman.cache" "~/.emacs.d/")
 woman-bold-headings nil
 woman-imenu-title "WoMan-imenu"
 woman-imenu t
 woman-use-own-frame nil ;不使用单独的frame
 woman-use-topic-at-point nil
 woman-fill-frame nil
 woman-show-log nil)

;;配置一下woman的颜色设置
(defun my-woman-pre-format-fn ()
  "."
  (face-spec-set 'woman-bold-face '((t (:foreground "white" :weight normal))))
  (face-spec-set 'woman-italic-face '((t (:foreground "yellow"))))
  (face-spec-set 'woman-addition-face '((t (:foreground "orange"))))
  (face-spec-set 'woman-unknown-face '((t (:foreground "cyan"))))
  ;; TODO can a function know its name?
  (remove-hook 'woman-pre-format-hook 'my-woman-pre-format-fn))

(add-hook 'woman-pre-format-hook 'my-woman-pre-format-fn)

;; So that each instance will pop up a new frame.
;; Maybe `special-display-regexps' would be better?
(add-hook 'woman-post-format-hook (lambda () (setq woman-frame nil)))
;;}}} WoMan ;;;;

;;{{{ eshell ;;;;

(defface my-eshell-code-face
  '((t (:foreground "Green")))
  "Eshell face for code (.c, .f90 etc) files.")

(defface my-eshell-img-face
  '((t (:foreground "magenta" :weight bold)))
  "Eshell face for image (.jpg etc) files.")

(defface my-eshell-movie-face
  '((t (:foreground "white" :weight bold)))
  "Eshell face for movie (.mpg etc) files.")

(defface my-eshell-music-face
  '((t (:foreground "magenta")))
  "Eshell face for music (.mp3 etc) files.")

(defface my-eshell-ps-face
  '((t (:foreground "cyan")))
  "Eshell face for PostScript (.ps, .pdf etc) files.")

(setq my-eshell-code-list '("f90" "f" "c" "bash" "sh" "csh" "awk" "el")
  my-eshell-img-list
  '("jpg" "jpeg" "png" "gif" "bmp" "ppm" "tga" "xbm" "xpm" "tif" "fli")
  my-eshell-movie-list '("mpg" "avi" "gl" "dl")
  my-eshell-music-list '("mp3" "ogg")
  my-eshell-ps-list '("ps" "eps" "cps" "pdf")
  eshell-ls-highlight-alist nil)

(let (list face)
  (mapcar (lambda (elem)
  (setq list (car elem)
  face (cdr elem))
  (add-to-list 'eshell-ls-highlight-alist
  (cons `(lambda (file attr)
  (string-match
  (concat "\\." (regexp-opt ,list t) "$")
  file))
  face)))
  '((my-eshell-code-list . my-eshell-code-face)
  (my-eshell-img-list . my-eshell-img-face)
  (my-eshell-movie-list . my-eshell-movie-face)
  (my-eshell-music-list . my-eshell-music-face)
  (my-eshell-ps-list . my-eshell-ps-face))))

(defun my-tidy-pwd (string)
  "Replace leading ~ by $HOME in output of pwd.
Argument STRING pwd."
  (replace-regexp-in-string "^~" (getenv "HOME") string))

(defun my-eshell-prompt-function ()
  "Return the prompt for eshell."
  (format "[%s@%s %s]%s "
  (eshell-user-name)
  (replace-regexp-in-string "\\..*" "" (system-name))
  (eshell/basename (eshell/pwd))
  (if (zerop (user-uid)) "#" "$")))

(defun my-eshell-line-discard ()
  "Eshell implementation of C-u."
  (interactive)
  (eshell-bol)
  (kill-line))


(defun my-eshell-clear-buffer ()
  "Eshell clear buffer."
  (interactive)
  (let ((eshell-buffer-maximum-lines 0))
  (eshell-truncate-buffer)))

(defalias 'eshell/clear 'my-eshell-clear-buffer)


(setq eshell-directory-name (expand-file-name "eshell" "~/.emacs.d/")
  eshell-pwd-convert-function 'my-tidy-pwd
  eshell-prompt-function 'my-eshell-prompt-function
  eshell-prompt-regexp "^\\[.*\\][#$] "
  eshell-ask-to-save-history 'always
  eshell-banner-message `(format-time-string
  "Eshell startup: %T, %A %d %B %Y\n\n"))


(defun my-eshell-first-time-mode-hook-fn ()
  "Function added to `eshell-first-time-mode-hook'."
  (face-spec-set 'eshell-ls-backup-face '((t(:foreground "Goldenrod"))))
  (face-spec-set 'eshell-ls-archive-face '((t(:foreground "red" :weight bold))))
  (face-spec-set 'eshell-ls-missing-face '((t(:foreground "orchid"))))
  (define-key eshell-mode-map "\C-ca" 'eshell-bol)
  (define-key eshell-mode-map "\C-c\C-u" 'my-eshell-line-discard)
  (mapcar (lambda (elem)
  (add-to-list 'eshell-visual-commands elem))
  '("pico" "nano")))

(add-hook 'eshell-first-time-mode-hook 'my-eshell-first-time-mode-hook-fn)

;;}}} eshell ;;;;


;;{{{ Shell-mode ;;;;
;;; Prefer terminal-mode really. Eshell even better.
(setq explicit-shell-file-name "bash"
;;; shell-file-name "/bin/bash"
  ;; Auto-generated variable name.
  explicit-bash-args '("--login")
  comint-scroll-to-bottom-on-input t
  comint-scroll-show-maximum-output t
  comint-scroll-to-bottom-on-output 'all
  comint-input-ignoredups t ; 1 copy only of identical input
  comint-completion-autolist t
  comint-completion-addsuffix t
  comint-buffer-maximum-size 200 ; lines
  comint-highlight-input nil ; highlight previous input
  comint-highlight-prompt nil)

(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)

(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)


(defun my-shell-mode-hook-fn ()
  "Function added to `shell-mode-hook'."
  ;; M-p by default.
  (define-key shell-mode-map [up] 'comint-previous-input)
  ;; M-n by default.
  (define-key shell-mode-map [down] 'comint-next-input)
  (define-key shell-mode-map [backspace] 'my-shell-backspace))

(add-hook 'shell-mode-hook 'my-shell-mode-hook-fn)


;; Passing with lambda expression not liked.
(add-hook 'comint-output-filter-functions 'comint-watch-for-password-prompt)
(add-hook 'comint-output-filter-functions 'comint-strip-ctrl-m)
(add-hook 'comint-output-filter-functions 'comint-truncate-buffer)

;;}}} Shell-mode ;;;;

;;{{{ 对相应的文件设定相应的模式,以便正确的语法显亮
;;文件名用正则表达式表示,注意不要后面覆盖了前面的而引起的误会
;;修改这个之前先C-h v auto-mode-alist查查已有的设置
;;一个简单的办法设置 auto-mode-alist, 免得写很多 add-to-list
(mapcar
 (function (lambda (setting)
  (setq auto-mode-alist
  (cons setting auto-mode-alist))))
 '(
  ("\\.\\(xml\\|rdf\\)\\'" . sgml-mode)
  ("\\.\\([ps]?html?\\|cfm\\|asp\\)\\'" . html-helper-mode)
  ("\\.html$" . html-helper-mode)
  ("\\.css\\'" . css-mode)
  ("\\.\\(emacs\\|session\\|gnus\\)\\'" . emacs-lisp-mode)
  ("\\.wiki\\'" . emacs-wiki-mode)
  ("\\.\\(jl\\|sawfishrc\\)\\'" . sawfish-mode)
  ("\\.scm\\'" . scheme-mode)
  ("\\.py\\'" . python-mode)
  ("\\.\\(ba\\)?sh\\'" . sh-mode)
  ("\\.l\\'" . c-mode)
  ("\\.max\\'" . maxima-mode)
  ;;("\\config" . fvwm-mode)
  ("\\.fvwm2rc$" . fvwm-mode)
  ("\\.fvwmrc$" . fvwm-mode)
  ("\\.strokes$" . fvwm-mode)
  ("\\.conkyrc$" . fvwm-mode)
  ))

;;}}}auto-list-mode

(provide 'jerry-mode)

;;; jerry-mode.el ends here

jerry-function.el

;;; jerry-function.el --- my function

;;{{{ 如果你正在编辑一个东西(在位置A),突然想到别的某处(位置B)要修改或查看

;;或别的,总之你要过去看看,你可以用C-.来在当前位置做个标记,然后去你想去的
;;地方B,看了一会你觉的我可以回A去了,用C-,就回到刚才做标记的地方A,再用C-,又会回到B
;;这个由王垠创作
(global-set-key [(control ?.)] 'ska-point-to-register)
(global-set-key [(control ?\,)] 'ska-jump-to-register)
(defun ska-point-to-register()
  "Store cursorposition _fast_ in a register.
  Use ska-jump-to-register to jump back to the stored
  position."
  (interactive)
  (setq zmacs-region-stays t)
  (point-to-register 8))

(defun ska-jump-to-register()
  "Switches between current cursorposition and position
  that was stored with ska-point-to-register."
  (interactive)
  (setq zmacs-region-stays t)
  (let ((tmp (point-marker)))
  (jump-to-register 8)
  (set-register 8 tmp)))

;;}}}

;;{{{ 使用%就可以上下翻动,匹配的括号
;;如果没有括号就输入%
;;这个由王垠创作
(defun my-match-paren (arg)
  "Go to the matching paren if on a paren; otherwise insert %.
Argument ARG paren."
  (interactive "p")
  (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
 ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
 (t (self-insert-command (or arg 1)))))
;;}}}

;;{{{ go-to-char
(defun my-go-to-char (n char)
  "Move forward to Nth occurence of CHAR.
Typing `my-go-to-char-key' again will move forwad to the next Nth
occurence of CHAR."
  (interactive "p\ncGo to char: ")
  (search-forward (string char) nil nil n)
  (while (char-equal (read-char)
  char)
  (search-forward (string char) nil nil n))
  (setq unread-command-events (list last-input-event)))
;;}}}
;; emacs-lisp-mode

;; 1. 再emacs中编译整个目录下的.el文件输入 [Alt]-x 。 当提示输入命令时,输入
;; byte-force-recompile [Enter] 。
;; 2. 如何再emacs下编译整个目录下的*.el文件两个办法,一是在dired里面用m标记,
;; 然后用B编译还有就是用emacs的批处理:

;; emacs -batch -f batch-byte-compile *.el

;; 这个忘了是从哪个地方弄来的,在保存~/.emacs文件自动编译为.elc文件
;;目前只是对~/.emacs有效,其余的*.el文件还没有去弄,以后有空我会改的
;;小知识:由于配置文件越来越大,你的*.el配置文件最好都编译为*.elc文件,这样
;;在启动emacs速度会有很大的提升
;; (defun autocompile nil
;; "Compile itself if ~/.emacs."
;; (interactive)
;; (if (string= (buffer-file-name) (concat default-directory ".emacs"))
;; (byte-compile-file (buffer-file-name))))
;; (add-hook 'after-save-hook 'autocompile)

;;{{{ 自动编译一个目录下的el文件
(defconst dotemacs-basic-conf-dir "~/lib/emacs-lisp/")
;(defconst dotemacs-ext-elisp-dir "~/.emacs.d/config/ext-elisp/")
;(defconst dotemacs-program-dir "~/.emacs.d/config/program/")

(defun autocompile nil
  "Automagically compile change to .emacs and other dotfiles."
  (interactive)
  (cond ((string= (buffer-file-name) (concat default-directory ".emacs"))
  (byte-compile-file (buffer-file-name)))

  ((string= (abbreviate-file-name (buffer-file-name))
  (concat dotemacs-basic-conf-dir
  (replace-regexp-in-string "\\.el" "" (buffer-name)) ".el"))
  (byte-compile-file (buffer-file-name)))

 ;; ((string= (abbreviate-file-name (buffer-file-name))
 ;; (concat dotemacs-ext-elisp-dir
 ;; (replace-regexp-in-string "\\.el" "" (buffer-name)) ".el"))
 ;; (byte-compile-file (buffer-file-name)))

 ;; ((string= (abbreviate-file-name (buffer-file-name))
 ;; (concat dotemacs-program-dir
 ;; (replace-regexp-in-string "\\.el" "" (buffer-name)) ".el"))
 ;; (byte-compile-file (buffer-file-name)))
  )

  )
(add-hook 'after-save-hook 'autocompile)
;; emacs-lisp-mode
;; 1. 再emacs中编译整个目录下的.el文件输入 [Alt]-x 。 当提示输入命令时,输入
;; byte-force-recompile [Enter] 。
;; 2. 如何再emacs下编译整个目录下的*.el文件两个办法,一是在dired里面用m标记,然后用B编译还有就是用emacs的批处理:
;; emacs -batch -f batch-byte-compile *.el
;;}}}
;;{{{ 自定义自动补齐命令,如果在单词中间就补齐,否则就是tab。
(defun my-indent-or-complete ()
  "在单词中间就补齐,否则就tab."
  (interactive)
  (if (looking-at "\\>")
  (hippie-expand nil)
  (indent-for-tab-command))
  )
;;}}}

;;这个是从emacs-lisp-introduction的那个文档拷过来
;;{{{ 功能同word的计算文字数相似,不过这个功能有待完善,对中文不大好使
(defun my-recursive-count-words (region-end)
  "Number of words between point and REGION-END."
  (if (and (< (point) region-end)
  (re-search-forward "\\w+\\W*" region-end t))
  (1+ (my-recursive-count-words region-end))
  0))
(defun my-count-words-region (beginning end)
  "Print number of words in the region.
Words are defined as at least one word-constituent
character followed by at least one character that is
not a word-constituent. The buffer's syntax table
determines which characters these are.
Argument BEGINNING region's beginning.
Argument END region's end."
  (interactive "r")
  (message "Counting words in region ... ")
  (save-excursion
  (goto-char beginning)
  (let ((count (my-recursive-count-words end)))
  (cond ((zerop count)
  (message
  "The region does NOT have any words."))
  ((= 1 count)
  (message "The region has 1 word."))
  (t
  (message
  "The region has %d words." count))))))
(defun my-count-words-buffer ()
  "Count the number of words in current buffer;
print a message in the minibuffer with the result."
  (interactive)
  (save-excursion
  (let ((count 0))
  (goto-char (point-min))
  (while (< (point) (point-max))
 (forward-word 1)
 (setq count (1+ count)))
  (message "buffer contains %d words." count))))
;;}}}

;;这也忘了是从哪弄来的了 ; replace C-u 0 C-l
;;{{{ 功能是将当前行设为本页第一行,同终端下的clear命令有点相似
(defun my-line-to-top-of-window ()
  "Move the line point is on to top of window."
  (interactive)
  (recenter 0))
;;}}}
;;{{{ 在文档里插入时间,用户名还有系统的信息
(defun my-stamp (&optional arg)
  "Insert current date, user, and system information.
With optional argument ARG, use \"*Created: -- *\" format."
  (interactive "*P")
  ;; Get this from time-stamp-format somehow?
  (let ((string (format " %s %s on %s "
  (format-time-string " %04y-%02m-%02d %02H:%02M:%02S")
  user-login-name
  system-name)))
  (if arg (setq string (format "*Creation: %s*" string)))
  (if (interactive-p)
  (insert string)
  string)))
;;}}}
;;{{{ 时间戳设置,插入文档内的
(defun my-timestamp ()
  "Insert the \"Time-stamp: <>\" string at point."
  (interactive)
  (if (interactive-p)
  (insert " Time-stamp: <>")
  " Time-stamp: <>"))
;;}}}

;;{{{ 打开.sawfishrc的快捷方式,ctrl-f1
(defun my-open-dot-sawfishrc ()
  "Open the dot-sawfishrc file."
  (interactive)
  (find-file "~/.sawfishrc")
  )
;;}}}

;; NB :添加的几个函数
;;{{{ 打开.emacs的快捷方式,ctrl-f2
(defun my-open-dot-emacs ()
  "Open the dot-emacs file."
  (interactive)
  (find-file "~/.emacs")
  )
;;}}}

;;{{{ 打开.sawfishrc配置文件,ctrl-f3
(defun my-open-fvwmconfig ()
  "Open the fvwm's config file."
  (interactive)
  (find-file "~/.fvwm/config")
;(find-file "~/.fvwm/fvwm.strokes")
  )
;;}}}

;;{{{ 找到这个buffer里最长的一行,并且到达哪里,很不错的功能
(defun my-longest-line (&optional goto)
  "Find visual length (ie in columns) of longest line in buffer.
If optional argument GOTO is non-nil, go to that line."
  (interactive "p") ; NB not p
  (let ((maxlen 0)
  (line 1)
  len maxline)
  (save-excursion
  (goto-char (point-min))
  (goto-char (line-end-position))
  ;; Not necessarily same as line-end - line-beginning (eg tabs)
  ;; and this function is for visual purposes.
  (setq len (current-column))
  (if (eobp) ; 1 line in buffer
  (setq maxlen len
  maxline line)
  (while (zerop (forward-line))
  (goto-char (line-end-position))
  (setq line (1+ line)
  len (current-column))
  (if (> len maxlen)
  (setq maxlen len
  maxline line)))))
  (if (not (interactive-p))
  maxlen
  (message "最长的一行是第%s行 (%s)" maxline maxlen)
  ;(message "Longest line is line %s (%s)" maxline maxlen)
  (if goto (goto-line maxline)))))
;;}}}

;;{{{ 给 Options 增加一个"去掉文件末尾空白"的菜单
(when (boundp 'show-trailing-whitespace)
  ;; Mode name must be same as mode variable.
  (define-minor-mode show-trailing-whitespace
  "Toggle display of trailing whitespace.
With optional numeric argument ARG, activate trailing whitespace display if
ARG is positive, otherwise deactivate it."
  :init-value nil
  :lighter " WS")

  (defun my-show-trailing-whitespace ()
  "Activate `show-trailing-whitespace' mode."
  (show-trailing-whitespace 1))

  (mapcar (lambda (hook) (add-hook hook 'my-show-trailing-whitespace))
  '(sh-mode-hook emacs-lisp-mode-hook f90-mode-hook
  fortran-mode-hook awk-mode-hook
  change-log-mode-hook c-mode-hook)))
;;}}}
;;{{{ TODO 去掉文件尾部的空白,在写文件的时候自动加载
;; Better functions than this exist in Emacs.
(defun my-delete-trailing-whitespace ()
  "Delete all trailing whitespace in buffer.
Return values are suitable for use with `write-file-functions'."
  (condition-case nil
  (progn
  ;; Don't want to do this to mail messages, etc.
  ;; Would an exclude list be better?
  ;; Error was occurring in VM-mode for some reason.
  (when (memq major-mode '(text-mode sh-mode emacs-lisp-mode
  f90-mode awk-mode c-mode))
  (message "Cleaning up whitespace...")
  (delete-trailing-whitespace)
  (message "Cleaning up whitespace...done")
  nil))
  (error (message "Cleaning up whitespace...ERROR")
  t)))
;;Too invasive?
(add-hook (if (boundp 'write-file-functions) 'write-file-functions
  'write-file-hooks) 'my-delete-trailing-whitespace)
;;}}}

;;{{{ 删除一些临时的buffers,少占我的内存
(defvar my-clean-buffers-names
  '("\\*Completions" "\\*Compile-Log" "\\*.*[Oo]utput\\*$"
  "\\*Apropos" "\\*compilation" "\\*Customize" "\\*Calc""\\keywiz-scores"
  "\\*BBDB\\*" "\\*trace of SMTP" "\\*vc" "\\*cvs" "\\*keywiz"
  "\\*WoMan-Log" "\\*tramp" "\\*desktop\\*" ;;"\\*Async Shell Command"
  )
  "List of regexps matching names of buffers to kill.")

(defvar my-clean-buffers-modes
  '(help-mode );Info-mode)
  "List of modes whose buffers will be killed.")

(defun my-clean-buffers ()
  "Kill buffers as per `my-clean-buffer-list' and `my-clean-buffer-modes'."
  (interactive)
  (let (string buffname)
  (mapcar (lambda (buffer)
  (and (setq buffname (buffer-name buffer))
  (or (catch 'found
  (mapcar '(lambda (name)
  (if (string-match name buffname)
  (throw 'found t)))
  my-clean-buffers-names)
  nil)
  (save-excursion
  (set-buffer buffname)
  (catch 'found
  (mapcar '(lambda (mode)
  (if (eq major-mode mode)
  (throw 'found t)))
  my-clean-buffers-modes)
  nil)))
  (kill-buffer buffname)
  (setq string (concat string
  (and string ", ") buffname))))
  (buffer-list))
  (if string (message "清理buffer: %s" string)
  ;(if string (message "Deleted: %s" string)
  (message "没有多余的buffer"))))
  ;(message "No buffers deleted"))))
;;}}}

;;{{{ 打印出我的键盘图,很酷吧.
(defun my-keytable (arg)
  "Print the key bindings in a tabular form.
Argument ARG Key."
  (interactive "sEnter a modifier string:")
  (with-output-to-temp-buffer "*Key table*"
  (let* ((i 0)
  (keys (list "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n"
  "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"
  "" "" "" "" ""
  "" "" "" "" "" "" ""
  "" "" "" "" "" "" ""
  "1" "2" "3" "4" "5" "6" "7" "8" "9" "0"
  "`" "~" "!" "@" "#" "$" "%" "^" "&" "*" "(" ")" "-" "_"
  "=" "+" "\\" "|" "{" "[" "]" "}" ";" "'" ":" "\""
  "<" ">" "," "." "/" "?"))
  (n (length keys))
  (modifiers (list "" "C-" "M-" "S-" "M-C-" "S-C-")))
  (or (string= arg "") (setq modifiers (list arg)))
  (setq k (length modifiers))
  (princ (format " %-10.10s |" "Key"))
  (let ((j 0))
  (while (< j k)
  (princ (format " %-50.50s |" (nth j modifiers)))
  (setq j (1+ j))))
  (princ "\n")
  (princ (format "_%-10.10s_|" "__________"))
  (let ((j 0))
  (while (< j k)
  (princ (format "_%-50.50s_|"
  "__________________________________________________"))
  (setq j (1+ j))))
  (princ "\n")
  (while (< i n)
  (princ (format " %-10.10s |" (nth i keys)))
  (let ((j 0))
  (while (< j k)
  (let* ((binding
  (key-binding (read-kbd-macro (concat (nth j modifiers)
  (nth i keys)))))
  (binding-string "_"))
  (when binding
  (if (eq binding 'self-insert-command)
  (setq binding-string (concat "'" (nth i keys) "'"))
  (setq binding-string (format "%s" binding))))
  (setq binding-string
  (substring binding-string 0 (min (length
  binding-string) 48)))
  (princ (format " %-50.50s |" binding-string))
  (setq j (1+ j)))))
  (princ "\n")
  (setq i (1+ i)))
  (princ (format "_%-10.10s_|" "__________"))
  (let ((j 0))
  (while (< j k)
  (princ (format "_%-50.50s_|"
  "__________________________________________________"))
  (setq j (1+ j))))))
  (delete-window)
  (hscroll-mode)
  (setq truncate-lines t)) ; for emacs 21
;;}}}

;;{{{
;; ;; 调用 stardict 的命令行接口来查辞典
;; ;; 如果选中了 region 就查询 region 的内容,
;; ;; 否则就查询当前光标所在的词
;; (defun kid-star-dict ()
;; "Serch dict in stardict."
;; (interactive)
;; (let ((begin (point-min))
;; (end (point-max)))
;; (if mark-active
;; (setq begin (region-beginning)
;; end (region-end))
;; (save-excursion
;; (backward-word)
;; (mark-word)
;; (setq begin (region-beginning)
;; end (region-end))))
;; ;; 有时候 stardict 会很慢,所以在回显区显示一点东西
;; ;; 以免觉得 Emacs 在干什么其他奇怪的事情。
;; (message "searching for %s ..." (buffer-substring begin end))
;; (tooltip-show
;; (shell-command-to-string
;; (concat "sdcv -n "
;; (buffer-substring begin end))))))

;; ;; 如果选中了 region 就查询 region 的内容,否则查询当前光标所在的单词
;; ;; 查询结果在一个叫做 *sdcv* 的 buffer 里面显示出来,在这个 buffer 里面
;; ;; 按 q 可以把这个 buffer 放到 buffer 列表末尾,按 d 可以查询单词
;; (defun kid-sdcv-to-buffer ()
;; "Search dict in region or world."
;; (interactive)
;; (let ((word (if mark-active
;; (buffer-substring-no-properties (region-beginning) (region-end))
;; (current-word nil t))))
;; (setq word (read-string (format "Search the dictionary for (default %s): " word)
;; nil nil word))
;; (set-buffer (get-buffer-create "*sdcv*"))
;; (buffer-disable-undo)
;; (erase-buffer)
;; (let ((process (start-process-shell-command "sdcv" "*sdcv*" "sdcv" "-n" word)))
;; (set-process-sentinel
;; process
;; (lambda (process signal)
;; (when (memq (process-status process) '(exit signal))
;; (unless (string= (buffer-name) "*sdcv*")
;; (setq kid-sdcv-window-configuration (current-window-configuration))
;; (switch-to-buffer-other-window "*sdcv*")
;; (local-set-key (kbd "d") 'kid-sdcv-to-buffer)
;; (local-set-key (kbd "q") (lambda ()
;; (interactive)
;; (bury-buffer)
;; (unless (null (cdr (window-list))) ; only one window
;; (delete-window)))))
;; (goto-char (point-min))))))))
;;}}}

;;{{{ lisp 里快速找到函数
(defvar my-defun-re
  (regexp-opt '("defun" "defsubst" "defmacro" "defadvice") 'paren)
  "Regular expression used to identify a defun.")

(defun my-jump-to-defun (func)
  "Jump to the definition of function FUNC in the current buffer, if found.
Return the position of the defun, or nil if not found."
  (interactive
  ;; From `describe-function'. *NB ?*
  (let ((fn (function-called-at-point)))
  (list (completing-read (if fn
  (format "Find defun for (default %s): " fn)
  "Find defun for: ")
  obarray 'fboundp t nil nil (symbol-name fn)))))
  (let (place)
  (save-excursion
  (goto-char (point-min))
  (if (re-search-forward
  (concat "^[ \t]*(" my-defun-re "[ \t]+"
  (regexp-quote func) "[ \t]+") (point-max) t)
  (setq place (point))))
  (if (not place)
  (if (interactive-p) (message "No defun found for `%s'" func))
  (when (interactive-p)
  (push-mark)
  (goto-char place)
  (message "Found defun for `%s'" func))
  place)))
;;}}}

;;{{{ 改变 tabbar-buffer-groups-function
;; 原来的 tabbar 强行对你的 buffer 进行分组,但是如果你想在你编辑的buffer间切换而不论它们是什么组,那么似乎没有
;; 一个好办法。但是 tabbar 本来提供了一个机制,让你可以自己确定 tab 属于哪组,只要修改
;; tabbar-buffer-groups-function 就行了。

;; 这样,我可以把每个 buffer 同时加入它所在的 major mode 的组和一个叫做 "default" 的组,这样我在 default 组里就
;; 可以方便的浏览到所有的 buffer 了。而切换到其它组就可以分组浏览。你还可以自行把某些 buffer 分到一组,比如我可
;; 以把 scheme-mode 的 buffer 和 inferer-scheme-mode 的 buffer 分到同一个组。
(setq tabbar-buffer-groups-function 'tabbar-buffer-ignore-groups)

(defun tabbar-buffer-ignore-groups (buffer)
  "Return the list of group names BUFFER belongs to.
Return only one group for each buffer."
  (with-current-buffer (get-buffer buffer)
  (cond
  ((or (get-buffer-process (current-buffer))
  (memq major-mode
  '(comint-mode compilation-mode)))
  '("Process")
  )
  ((member (buffer-name)
  '("*scratch*" "*Messages*"))
  '("Common")
  )
  ((eq major-mode 'dired-mode)
  '("Dired")
  )
  ((memq major-mode
  '(help-mode apropos-mode Info-mode Man-mode))
  '("Help")
  )
  ((memq major-mode
  '(rmail-mode
  rmail-edit-mode vm-summary-mode vm-mode mail-mode
  mh-letter-mode mh-show-mode mh-folder-mode
  gnus-summary-mode message-mode gnus-group-mode
  gnus-article-mode score-mode gnus-browse-killed-mode))
  '("Mail")
  )
  (t
  (list
  "default" ;; no-grouping
  (if (and (stringp mode-name) (string-match "[^ ]" mode-name))
  mode-name
  (symbol-name major-mode)))
  )
  )))
;;}}}

;;{{{ TODO 让speedbar获得类似ECB的显示效果,把speedbar集成到emacs主窗口里
;; (require 'tramp)
;; (defconst my-junk-buffer-name "Junk")
;; (setq junk-buffer (get-buffer-create my-junk-buffer-name)
;; )
;; (require 'speedbar)
;; (defconst my-speedbar-buffer-name "SPEEDBAR")
;; (setq speedbar-buffer (get-buffer-create my-speedbar-buffer-name)
;; speedbar-frame (selected-frame)
;; dframe-attached-frame (selected-frame)
;; speedbar-select-frame-method 'attached
;; speedbar-verbosity-level 0
;; speedbar-last-selected-file nil)
;; (setq right-window (split-window-horizontally 24))
;; (setq left-window (frame-first-window))
;; ;;(walk-windows (lambda (w) (setq left-window w)) "nominibuffer" t)
;; (set-buffer speedbar-buffer)
;; (speedbar-mode)
;; (speedbar-reconfigure-keymaps)
;; (speedbar-update-contents)
;; (speedbar-set-timer 1)
;; (set-window-buffer left-window "SPEEDBAR")
;; (set-window-dedicated-p left-window t)
;; (toggle-read-only) ; HACK, REQUIRED for Tramp to work ????
;; (select-window right-window)
;; (defun select-right-window () (select-window right-window))
;; ;;(defun reset-window-config () (interactive)
;; ;; (walk-windows (lambda (w) (when (not (or (eq w left-window) (eq w right-window))) (delete-window w))) "nominibuffer" t)
;; ;; )
;; (defun reset-window-config () (interactive)
;; (delete-other-windows)
;; (setq right-window (split-window-horizontally 24))
;; (setq left-window (frame-first-window))
;; (set-window-buffer left-window speedbar-buffer)
;; (set-window-dedicated-p left-window t)
;; (select-window right-window)
;; (set-window-dedicated-p right-window nil)
;; (when (eq speedbar-buffer (window-buffer right-window)) (set-window-buffer right-window (next-buffer)))
;; (set-window-dedicated-p right-window nil)
;; )
;; ;;(global-set-key "\C-x1" 'reset-window-config)
;;}}}

(provide 'jerry-function)

;;; jerry-function.el ends here