首页 > 初级, 配置 > Emacs配置系统

Emacs配置系统

2010年3月4日 ahei 发表评论 阅读评论

作者: shell909090

emacs是个超级复杂的程序,尤其在配置问题上。贝壳的emacs要跨越三个环境。环境一,WindowsXP+Emacs23。环境二,Debian Testing + Xfce4。环境三,CentOS + Ssh。而整个的操作方式,个性设定需要保持一致。因此,引出一个问题。配置如何设置,跨平台,同步。
首先解决配置的同步问题,贝壳建立了一个svn仓库,用于存储该配置系统。然后在各个系统中co出这个仓库,当有需要调整时ci就可以保持同步了。 Linux下可以使用ln连接文件,Windows下比较麻烦点,NTFS格式(大多都是NTFS格式了吧)可以去sysinternals下一个叫做 junction的工具,以建立目录的工具链接,当然,.emacs文件只能手工拷贝了。
然后是配置的切分问题,如果只有一个文件,即使使用了版本控制,意义也不大。同时,将配置切割成不同的部分,控制载入过程,也可以跨平台和加速。以下是贝壳的.emacs文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
;; .emacs profile, written by shell.xu
 
;; load other set
(add-to-list 'load-path "~/.emacs.d/")
(add-to-list 'load-path "~/.emacs.d/auto-complete/")
(add-to-list 'load-path "~/.emacs.d/plugins/")
(load "emacs-setup")
(load "emacs-redef")
(load "emacs-plugin")
(cond
 ((not (boundp 'initial-window-system)) (load "emacs-console"))
 ((memq initial-window-system '(x w32))
  (cond
   ((memq system-type '(windows-nt cygwin)) (load "emacs-win"))
   ((memq system-type '(gnu/linux)) (load "emacs-linux"))
   )
  )
 )
(load "emacs-keymap")

从上可以看出,我们先设定了.emacs.d作为默认加载路径——大多数文件都是放在这里。plugins是各种第三方程序的安装路径,这样这些程序就无需在各个平台上各自安装一次。而auto-complete单独拆出来纯粹是因为文件太多了。而后,我们加载了setup,这个文件内定义了emacs的基本配置,redef文件内定义了各种自定义函数和变量,plugin内控制了需要加载的各个插件和配置。
下面就有点复杂,简单来说,设定无Windows系统的时候加载emacs-console文件,有Windows的情况下,在windows下加载emacs-win,在linux下加载emacs-linux。这是实现跨平台设置的核心。
最后是keymap,经过上面复杂的设定,按键设置是统一的。
setup文件就不细说了,大家按照自己的习惯设定就好。下面我说几个redef中定义的函数。

1
2
3
4
5
6
7
8
(defun switch-windows-buffer ()
  (interactive)
  (let ((this-buffer (window-buffer)))
    (switch-to-buffer (window-buffer (next-window (selected-window))))
    (switch-to-buffer-other-window this-buffer)
    (other-window 1)
    )
)

这个函数的目标是用热键交换两个窗口的位置。如果你经常用C-x 3分栏,并且在两者间跳来跳去的话,有的时候往往希望两者的位置换一下。通常都是C-x b切换当前的窗口,然后C-x o切到隔壁去再换。这个太繁琐了。

1
2
3
4
(defun popup-term ()
  (interactive)
  (apply 'start-process "terminal" nil popup-terminal-command)
  )

这个函数是用于在当前文件所在路径弹出一个term的。也许有人说了,emacs有term啊。问题是,那个term只能开一个,而且有些东西操作不了。例如你如果想在这个term里面跑aptitude…
注意这个函数里面的popup-terminal-command,这个需要跨平台的,因此在windows和linux下设定各自不同。以下是两个典型设定,至于哪个是哪个我想都看得懂。注意console下面没必要搞这个。

1
2
(setq popup-terminal-command '("xfce4-terminal"))
(setq popup-terminal-command '("cmd" "/c" "start"))

然后我们说plugin,这个文件其实很简单,加载插件,然后设定就好。下面是一部分范例。

1
2
3
4
5
6
;; load template
(require 'template)
;;here set the templates directory
(setq template-subdirectories '("./" "Templates/" "~/.emacs.d/templates/"))
(template-initialize)
(setq template-auto-insert t)

这部分范例说明了如何载入template,并且进行设定。
下面是一点细节问题,tool-bar-mode这个设定相信多数人都有做。问题是,针对某些console系统,如果你设定了(tool-bar-mode -1),立刻会报错。具体的条件是,编译的时候没有加入X的支持。因此,为了兼容性起见,针对console下就忽略这个设定。
最后,这些设定,推荐进行编译加速,包括所有第三方插件。不编译也是可以载入的,然而记得删除el文件对应的elc。否则emacs默认载入elc,从而导致你对el文件的修改无效——emacs是不认文件时间的。而显然,每个平台编译一遍是个脑残的事情。因此,我们需要写一个Makefile。

1
2
3
4
5
6
7
8
9
10
11
DEPENDS=auto-complete plugins
SOURCES=emacs-console.el emacs-keymap.el emacs-linux.el emacs-redef.el emacs-setup.el emacs-win.el
 
build: $(SOURCES) emacs-plugin.el
    for i in $(DEPENDS); do $(MAKE) -C $$i build || exit 1; done
    emacs --batch -f batch-byte-compile $(SOURCES)
    emacs --batch -l ~/.emacs -f batch-byte-compile emacs-plugin.el
 
clean:
    rm -rf *.elc
    for i in $(DEPENDS); do $(MAKE) -C $$i clean || exit 1; done

注意,在每个目录中也要分别写Makefile,不过内容简单多了,基本就是emacs –batch -f batch-byte-compile *.el而已。而plugin这个文件比较特殊——他必须依赖于所有插件才能工作,所以最后才进行编译。
以上工作,基本完成了一个跨平台的emacs配置系统的组建。当然,如果你高兴向其中加入更多的内容,可以遵循以上规范进行。

分享家:Addthis中国
GD Star Rating
loading...
Emacs配置系统, 8.7 out of 10 based on 10 ratings 标签:buffer, ede, Emacs, keymap, linux, lisp, mode, plugin, profile, screenshot, se, shell909090, ssh, term, windows, 安装, 按键, 插件, 编译, 配置, 配色, 配色

相关日志

分类: 初级, 配置
  1. cs007
    2010年11月10日09:27 | #1

    hi 我想请教下 在console的emacs 如何拷贝数据到系统剪贴板?

    [回复]

    ahei 回复:

    @cs007, 这个是不行的

    [回复]

  2. 2011年8月13日14:00 | #2

    请问你使用的这个语法高亮插件是什么~?

    [回复]

    ahei 回复:

    @碎星De雨, wp-codebox

    [回复]

  3. 1477237152
    2011年11月17日10:18 | #3

    p.php is not in a version controlled directory.
    Use VC backend: 配置出问题额。提交网上数据库,怎么配置额。

    [回复]

  4. 2016年4月7日11:49 | #4

    On Nov. 17, police learned from the Oregon State Police crime lab that DNA swabs from the pistol recovered matched the DNA profile of Kince. coach outlet store online March 19. e louis vuitton outlet online
    II-9 Consolidation Collaboration Continue to be the Buzzwords II-9 Select SUV Models Currently in Production II-10 Select Successful SUV Models Produced in the Past II-14 cheap jordans Red Mountain C.
    Thomas caught five passes for 28 yards and a touchdown (5 yards) during 19-13 win against Tennessee. louis vuitton handbags Since Williams doesn’t play other sports, his sole focus the last several years has been improving and developing every facet of his game. j coach handbags
    Passover is one of three agriculturally-linked festivals in Judaism and occurs during Nisan, the first month of the Jewish calendar, a new year for the growing season. http://www.michaelkorshandbagsup.us.com Holy Cross is the 20th team since 1985 to make the NCAA Tournament with a losing record, per STATS LLC.
    l Nicolaos G. Peroulakis and Effie P. Peroulakis to Nicolaos G. Peroulakis, trustee, Effie P. Peroulakis, trustee, and Peroulakis Family Trust, trustee of, 88 Tannery Road, $100. michael kors outlet online Hutchinson has called a special session, to start April 6, during which he wants the Legislature to change the private option to encourage recipients to work and take more personal responsibility. michael kors outlet
    David Cobb, TEN, vs. coach outlet store online “Beatles records, in English, were to sell in millions in every country, Germany included. http://www.coachoutletstoreonline.me
    — Into his third season now, Brad Stevens has only coached against Durant once. michael kors online Nutt said his text messages with Bragg related to her work as a professional fundraiser for a nonprofit organization that provided services for the developmentally disabled; her insights concerning the media; condolences and support after Nutt’s motherinlaw died from cancer; and information about a friend of Bragg’s who was diagnosed with cancer. v coach outlet store
    What I like about the Renegade pricing structure, however, is that you can equip it how you want to, adding as much or as little content as you’d like. http://www.louisvuittonbagsbuy.us.com 28 ERA his last six starts heading into Wednesday’s game against Arizona.
    But why would you not have the drug grown in one or maybe two places in California and be distributed to state licensed pharmacies ? If you need an aspirin is there a aspirin factory in each county ? I’ve said this before and I’m saying it now. michael kors outlet This way, we can get to the key easily, even at night, if we happen to lock ourselves out.
    every Thursday. michael kors outlet Johnson recalled his intensity on the days he pitched, remembering himself “morphing into something I didn’t know I was becoming.
    And how can Mr Friend vote to give his own organization money without being in violation of ethics laws? michael kors outlet In changing a core part of Facebook — the 7yearold “like” button has become synonymous with the social network — the company said it tried to keep things familiar.
    n Not one to miss a trick, he also recorded instrumental versions of the band’s hits during the height of Beatlemania and provided incidental music to the group’s film “A Hard Day’s Night. oakley sunglasses Colorado is 43-87.
    Kirby made comics lofty, legitimate, and fun, and in my humble opinion, nowadays, artists achieve maybe one of those, but not all three. oakley glasses He said it contained a photo of Goshert and a reference to the recall, leading him to question Goshert’s connection with the group. m coach factory outlet
    “School choice is right,” he said. michael kors handbags Maybe we’ll talk about this Steph shot in the same way 20-plus years from now.
    y “My close friends are mostly all the guys who were on the hockey team (at Cathedral), all that, so those are guys that I work out with in the summer, I skate with in the summer,” Vatrano said. “So we’re definitely a close-knit group, and it’s awesome. We do everything together.” louis vuitton outlet Scholarship exhibition, March 419. z
    DeAngelo Williams was signed on a two-year deal worth $4 million. ray ban sunglasses outlet To come out with a win would propel us this season toward the postseason and nationals. cheap air jordans
    Nancy Nathanson, D-Eugene coach outlet store online That is why schools screen them out from being teachers as they cannot be trusted. g michael kors bags
    blockquote!–EndFragment–video-ad-asset-container, video-ad-asset-container-played max-height: 0px; overflow: hidden; -webkit-transition: max-height 1s; -moz-transition: max-height 1s; transition: max-height 1s;video-ad-asset-container. louis vuitton handbags But then came the afternoon where Grimes found bogeys and lots of them.
    After sitting out the first eight games of the season while he worked his way back from offseason hip surgery, Henderson will likely don a Blazers jersey for the first time on Wednesday when Portland hosts the San Antonio Spurs. The Blazers are officially listingHenderson as “probable” for the game against the Spurs. louis vuitton outlet online That was another vote of confidence in the economy. b michael kors online
    No one expected us to hand in a four-page dissection of “To Kill a Mockingbird. michael kors outlet SAG Lieppert 6 5-6 19, Arrick 5 2-2 14, Lux 4 0-0 8, Murphy 3 0-2 6.

    [回复]

评论分页
1 2 40784
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
:wink: :-| :-x :twisted: :) 8-O :( :roll: :-P :oops: :-o :mrgreen: :lol: :idea: :-D :evil: :cry: 8) :arrow: :-? :?: :!: