在 windows 下的快速搭建 emacs

来源:互联网 发布:天猫淘宝网商城首页 编辑:程序博客网 时间:2024/06/11 21:30

前言

emacs 是来源于 linux,并且在那里使用时,是最让我觉得舒服的。但大多数情况我还是在 windows 下使用。经过两年的使用,经常会遇到这种情况:在某个地方(公共机或别人的电脑上)不能使用 emacs 软件,又需要编辑一些文件,用记事本用着会很不舒服。尽管可以在官方下载到 emacs 对应的版本,但需要重新配置那还是挺麻烦的。所以,以我现在的使用经验,整理了在 windows 快速搭建 emacs 的方法,仅供参考。


现在笔者选定的是 emacs-23.4-bin-i386.zip,而且以下的配置过程均以这个版本进行测试的。快速搭建的主要思想是采用执行注册表脚本,设定 emacs 查找配置文件的路径为 c:/emacs-home/.emacs,同时又在此文件中定位到我们现在刚下载的路径,及更改 home 目录的方式。包含最基本的配置(颜色、字体等)、脚本以及常用的库。已上传到了我的资源中:http://download.csdn.net/detail/lvye1221/6576789。


快速搭建三步曲


相当于快速搭建只需要这三步即可。


1. 下载 emacs 软件包:emacs-23.4-bin-i386.zip

http://mirrors.ustc.edu.cn/gnu/emacs/windows/

2. 下载配置工具包,解压到 emacs-23.4/ 目录下。修改压缩包中 install/emacs-home/emacs-home/.emacs 第一行 "D:/emacs-22.3/home" 为实际 emacs 的 home 路径


3. 执行 install/install.bat 批处理即可


注意:如果当前系统为 Win7 或者 Windows Server,用管理员权限执行就 OK 了。否则,就手动点击 setHomel.reg 注册,参照脚本拷贝文件夹到 C 盘对应位置即可。

脚本分析

如果大家不想浪费积分下载资源,或者想尝试手动编写脚本。这里附上对应文件的代码:


setHomel.reg


Windows Registry Editor Version 5.00


[HKEY_CURRENT_USER\Software\GNU]


[HKEY_CURRENT_USER\Software\GNU\Emacs]
"HOME"="C:\\emacs-home"


install.bat


@echo off
xcopy emacs-home /s c:\ /y
regedit /s setHome.reg.reg&&echo 导入成功||echo 导入失败


emacs-home\.emacs


(setenv "HOME" "D:/emacs-22.3/home")


;;set the default file path
(setq default-directory "~/")
(load-file "~/.emacs")
(add-to-list 'load-path "~/emacs/site-lisp")



快速搭建后,执行 bin\runemacs.exe 看到了我所喜爱的界面(不知道大家喜不喜欢哈~)。那如果还想添加其他的功能,怎么办呢? 答案是直接编辑 home 目录下 .emacs 文件,尽情地添加如下如下扩展功能吧!


其他扩展好用的插件


当然这里仅仅提供了配置文件中的配置方式,有些地方是需要下载对应的 el 文件,并包含到加载路径中,这里我就不提供下载链接啦。

php 编辑模式



(require 'php-mode)

bit编码


;; 优先使用chinese-iso-8bit编码,这句话不管用。在打开中文乱码时,用revert-buffer-with-coding-system修改
(prefer-coding-system 'chinese-iso-8bit)

画图插件


(load-file "../site-lisp/graphviz-dot-mode.el")


加载已经定义的宏

;; 加载已经定义的宏
(load-file "~/macros")


mew 邮件配置

;; mew 邮件配置
(add-to-list 'load-path "../site-lisp/mew")
(autoload 'mew "mew" nil t)  
(autoload 'mew-send "mew" nil t)  


;; Optional setup (Read Mail menu for Emacs 21):  
(if (boundp 'read-mail-command)  
    (setq read-mail-command 'mew))  


;; Optional setup (e.g. C-xm for sending a message):  
(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 user-full-name "yangjie")  
(setq user-mail-address "yangjie.green@gmail.com")  
(setq mew-cite-fields '("From:" "Subject:" "Date:"))  
(setq mew-cite-format "From: %s\nSubject: %s\nDate: %s\n\n")  
(setq mew-cite-prefix "> ")
(setq mew-use-cached-passwd t)  


;; 设置 mew 密码生存时间
;; (setq mew-passwd-timer-unit 999)
;; (setq mew-passwd-lifetime 999)


;; 下面的图标路径和安装路径有关,具体请看Mew的安装过程    
(setq mew-icon-directory "~/../site-lisp/mew/etc")    
(setq mew-use-cached-passwd t)    


;; mew-pop-size设置成0时,pop邮件大小没有限制    
(setq mew-pop-size 0)    
(setq toolbar-mail-reader 'Mew)
(set-default 'mew-decode-quoted 't)
(setq mew-prog-pgp "gpg")
(setq mew-name "yangjie")
(setq mew-user "yangjie")


;; 不删除服务器上的邮件    
;; (setq mew-pop-delete nil)    


;; 回复邮件位置设定,如果设置为 body,即回复出现在引文之前,如设置为 end,在引文后回复
(setq mew-summary-reply-with-citation-position 'body)


;; 签名档设置
(setq mew-signature-file "~/Mail/signature")
(setq mew-signature-as-lastpart t)
(setq mew-signature-insert-last t)
(add-hook 'mew-before-cite-hook 'mew-header-goto-body)
(add-hook 'mew-draft-mode-newdraft-hook 'mew-draft-insert-signature)


;; 新邮件通知
(load "biff")
;; 必须
(setq mew-use-cached-passwd t)
(setq mew-use-biff t)
(setq mew-use-biff-bell t)
;; 这个值一定要小于下面的timer-unit和lifetime值,这个可以使用describe-variable查看一下
(setq mew-biff-interval 5) 
(setq mew-pop-biff-interval 3)
(setq mew-passwd-timer-unit 60)       ; 60 minutes = 1 hour                                            
(setq mew-passwd-lifetime 24)         ; timer-unit x 24 = 24 hours 


(put 'downcase-region 'disabled nil)
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 )

时间戳功能


;;时间戳设置(time-stamp),设定文档上次保存的信息  
;;只要里在你得文档里有Time-stamp:的设置,就会自动保存时间戳  
;;启用time-stamp  
(setq time-stamp-active t)


;;去掉time-stamp的警告?  
(setq time-stamp-warn-inactive t)


;;设置time-stamp的格式,
(setq time-stamp-format "%04y-%02m-%02d %02H:%02M:%02S, by %:u")


;;将修改时间戳添加到保存文件的动作里。  
(add-hook 'write-file-hooks 'time-stamp)
原创粉丝点击