最近在寻找好的 Erlang IDE…抛开那些一般的文本编辑器,目前已知的就是:
Erlide - Eclipse插件,试用 0.10 beta 最大的问题是对 UTF-8 的支持,代码中写入中文高亮就乱掉了,注释中写中文关闭之后打开会报错,无法打开
Erlybird - Netbeans插件,支持NB6.7,不支持6.9,而且试了一下6.7,启动报错,新建 erlang 应用囧住了…下一步总是灰的
Emacs Erlang mode -功能比较全面,不过因为是 *NIX 的东西,上手难度大一些,操作需要熟悉和适应
最后唯一的选择就是 Emacs 了,其他实在 Ungelievable….
首先进行下载&安装: Erlang OTP 最新版的 Windows binary:http://www.erlang.org/download.html EmacsW32 选择 Download latest EmacsW32+Emacs patched:http://www.ourcomments.org/cgi-bin/emacsw32-dl-latest.pl Distel 下载最新的包:https://github.com/massemanet/distel
Erlang OTP 和 EmacsW32 按照安装程序装就好了,Distel 随便找个地方解压,自己规划路径吧
安装好EmacsW32,先运行,启动进去,点击首页的 Customize Startup 并保存,这是为了生成 Emacs 的自定义配置文件 .emacs,后面配置会用到它
.emacs 的路径:
- XP下:系统盘符(一般是C):\Documents and Settings\你的用户名\Application Data\.emacs
- Vista&7:系统盘符(一般是C):\Users\你的用户名\AppData\Roaming\.emacs
一、配置 Erlang mode + distel: 参考:http://bc.tech.coop/blog/070528.html
添加以下内容到 .emacs 文件,注意修改里面的那些路径,注意路径里面不要用\,全部写/: [lisp] ;; Erlang mode (setq load-path (cons “<Erlang OTP 安装路径>/lib/tools-<版本号>/emacs” load-path)) (setq erlang-root-dir “<Erlang OTP 安装路径>”) (setq exec-path (cons “<Erlang OTP 安装路径>/bin” exec-path)) (require ’erlang-start)
;; This is needed for Distel setup (let ((distel-dir “<Distel 解压位置的路径>/elisp”)) (unless (member distel-dir load-path) ;; Add distel-dir to the end of load-path (setq load-path (append load-path (list distel-dir)))))
(require ‘distel) (distel-setup) ;; Some Erlang customizations (add-hook ’erlang-mode-hook (lambda () ;; when starting an Erlang shell in Emacs, default in the node name (setq inferior-erlang-machine-options ‘("-sname" “emacs”)) ;; add Erlang functions to an imenu menu (imenu-add-to-menubar “imenu”)))
;; A number of the erlang-extended-mode key bindings are useful in the shell too (defconst distel-shell-keys ‘(("\C-\M-i" erl-complete) ("\M-?" erl-complete) ("\M-." erl-find-source-under-point) ("\M-," erl-find-source-unwind) ("\M-*" erl-find-source-unwind) ) “Additional keys to bind when in Erlang shell.”)
(add-hook ’erlang-shell-mode-hook (lambda () ;; add some Distel bindings to the Erlang shell (dolist (spec distel-shell-keys) (define-key erlang-shell-mode-map (car spec) (cadr spec)))) [/lisp]
Distel 设置断点可能会有问题,需要注释掉 <Distel 路径>/elisp/edb.el 的两行代码: [lisp] ;; (unless (edb-module-interpreted-p module) ;; (error “Module is not interpreted, can’t set breakpoints.”)) [/lisp]
二、给 Emacs 增加行号: 编辑 .emacs 添加配置: [lisp] (require ’linum) (global-linum-mode 1) [/lisp]
三、autocomplete
下载 auto-complete :http://cx4a.org/software/auto-complete/#Latest_Stable
随便解压个什么地方
打开 Emacs,输入 M-x load-file RET <Autocomplete 解压路径>/etc/install.el RET 如果你没有改 Emacs 什么设置的话,这个操作是这样:Alt + x,注意窗口最下面一行会有一个黄底的 M-x 突出显示出来,并且光标会自动移到 M-x 后面,输入load-file,回车,输入 <Autocomplete 解压路径>/etc/install.el 回车
接着是输入安装路径,默认是 ~/.emacs.d,也不用改了..直接回车吧 .emcs.d 目录和 .emacs 文件是在同一路径下
编辑 .emacs 添加: [lisp] (add-hook ’erlang-shell-mode-hook (lambda () ;; add some Distel bindings to the Erlang shell (dolist (spec distel-shell-keys) (define-key erlang-shell-mode-map (car spec) (cadr spec)))))
(add-to-list ’load-path “/.emacs.d/”)
(require ‘auto-complete-config)
(add-to-list ‘ac-dictionary-directories “/.emacs.d//ac-dict”)
(ac-config-default)
[/lisp]
四、eflymake 下载最新的 Flymake:http://sourceforge.net/projects/flymake/ 将 .el 文件解压到 ~/.emacs.d/ 下,注意别带路径过去
编辑 .emacs 添加: [lisp] (require ’erlang-flymake) [/lisp]
这个配置可能还有问题,等着再测试看看
五、yasnippet 下载最新的 yasnippet-bundle:http://code.google.com/p/yasnippet/ 把 yasnippet-bundle.el 解压到 ~/.emacs.d/
编辑 .emacs 添加: [lisp] (require ‘yasnippet-bundle) [/lisp]
这样开发环境基本差不多了,以后需要继续添加/修改