[转]Emacs安装和设置tabbar

点击打开链接

Emacs是用Buffer来组织编辑区域的,一个Buffer就代表一个文件或者一个临时编辑区域,我们可以用一些函数来切换到前一个或后一个Buffer,也可以列出所有的Buffer来进行选择。一些现代编辑器都支持一种特性,那就是Tab,用标签来列出所有的文件并可以方便地在文件之间切换,直观而方便。万能的Emacs当然也可以做到这个。
增加标签特性需要tabbar.el,emacswiki上可以下载到这个插件:
http://www.emacswiki.org/emacs/tabbar.el
放在任意目录并把这个目录添加到载入列表中,比如我们把tabbar.el放在~/.mylisp/下:

1
2
;;main plugin path
(add-to-list 'load-path "~/.mylisp/")

然后require这个插件并打开tabbar模式:

1
2
(require 'tabbar)
(tabbar-mode 1)

进行一些快捷键设置:

1
2
(global-set-key [(meta j)] 'tabbar-backward)
(global-set-key [(meta k)] 'tabbar-forward)

重新启动Emacs或eval-buffer就可以看到tabbar了:

默认的tabbar样式很难看,而且字体太小,不容易看清楚,我们接下来需要做的就是修改它的样式和配色。
下面使用一段网友菩提老祖给出的代码:
在.emacs下加入:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
;; 设置tabbar外观
;; 设置默认主题: 字体, 背景和前景颜色,大小
(set-face-attribute 'tabbar-default-face nil
:family "DejaVu Sans Mono"
:background "gray80"
:foreground "gray30"
:height 1.0
)
;; 设置左边按钮外观:外框框边大小和颜色
(set-face-attribute 'tabbar-button-face nil
:inherit 'tabbar-default
:box '(:line-width 1 :color "yellow70")
)
;; 设置当前tab外观:颜色,字体,外框大小和颜色
(set-face-attribute 'tabbar-selected-face nil
:inherit 'tabbar-default
:foreground "DarkGreen"
:background "LightGoldenrod"
:box '(:line-width 2 :color "DarkGoldenrod")
:overline "black"
:underline "black"
:weight 'bold
)
;; 设置非当前tab外观:外框大小和颜色
(set-face-attribute 'tabbar-unselected-face nil
:inherit 'tabbar-default
:box '(:line-width 2 :color "#00B2BF")
)

现在我们的tabbar外观变成这样:

可以看出,已经几乎完成了,美中不足的是左边的几个按钮尺寸不正确,还需要修正。
打开~/.mylisp/tabbar.el,可以在里面找到类似这样的内容:

1
2
3
4
5
6
7
8
9
10
11
12
(defconst tabbar-home-button-enabled-image
'((:type pbm :ascent center :data "/
P2
10 10
255
184 184 184 184 0 184 184 184 184 184 184 184 184 0 0 0 184 184 184 184
184 184 0 0 0 0 0 184 184 184 184 0 0 0 0 0 0 0 184 184 184 184 255 0 0
0 255 255 255 184 184 0 0 0 0 0 0 0 184 184 184 184 0 0 0 0 0 255 255 184
184 184 184 0 0 0 255 255 184 184 184 184 184 184 0 255 255 184 184 184
184 184 184 184 184 255 184 184 184 184
"))
"Default image for the enabled home button.")

这部分就是设定home-button的图像,同样,另外几个按钮的图像也可以找到:
tabbar-home-button-disabled-image
tabbar-scroll-left-button-enabled-image
tabbar-scroll-left-button-disabled-image
tabbar-scroll-right-button-enabled-image
tabbar-scroll-right-button-disabled-image

这种图片的格式是pbm,pbm是Portable Bitmap Format(便携位图格式)的缩写,该系列共有三种格式:
PBM 位图黑白位图
PGM 灰度位图
PPM 带颜色的像素位图
文件的前两个字节指明了该文件到底属于哪种格式:
Magic Number 类型 编码
P1 Portable bitmap ASCII
P2 Portable graymap ASCII
P3 Portable pixmap ASCII
P4 Portable bitmap Binary
P5 Portable graymap Binary
P6 Portable pixmap Binary
如果编码是ASCII的话文件的内容就由直接可读的数字组成,数字之间用空格隔开。
我们修改后的tabbar高度变为20像素,宽度没变,减去原来的10像素那么上下分别加宽5像素。
也就是增加5 10 = 30个数字,5 10 = 10个数字。
修改tabbar里每个图片的数据块
P2保持不变,接下来的两个数字分别是宽度和高度,那么原来的”10 10”就要修改为”10 19”,255为白色的值,保持为原来的255.然后在描述各个像素的数据前后分别加上50个184,保持和原来的颜色一样。
tabbar-home-button-enabled-image的那段就变为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(defconst tabbar-home-button-enabled-image
'((:type pbm :ascent center :data "/
P2
10 20
255
184 184 184 184 184 184 184 184 184 184
184 184 184 184 184 184 184 184 184 184
184 184 184 184 184 184 184 184 184 184
184 184 184 184 184 184 184 184 184 184
184 184 184 184 184 184 184 184 184 184
184 184 184 184 0 184 184 184 184 184 184 184 184 0 0 0 184 184 184 184
184 184 0 0 0 0 0 184 184 184 184 0 0 0 0 0 0 0 184 184 184 184 255 0 0
0 255 255 255 184 184 0 0 0 0 0 0 0 184 184 184 184 0 0 0 0 0 255 255 184
184 184 184 0 0 0 255 255 184 184 184 184 184 184 0 255 255 184 184 184
184 184 184 184 184 255 184 184 184 184
184 184 184 184 184 184 184 184 184 184
184 184 184 184 184 184 184 184 184 184
184 184 184 184 184 184 184 184 184 184
184 184 184 184 184 184 184 184 184 184
184 184 184 184 184 184 184 184 184 184
"))
"Default image for the enabled home button.")

其他部分也照着这样修改就行了,最后的效果如图:

Jerky Lu wechat
欢迎加入微信公众号