`
zhongwencool
  • 浏览: 27317 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

安装erlang开发环境++emacs

阅读更多

1.下载erlang最新版本: http://www.erlang.org/download.html

 我用的是 Erlang/OTP R15B02
1)tar  -xzvf  otp_src_R15B02.tar.gz
2) 按照INSTER.md中的说明一步步安装好;(检查环境,配置,编译工具....) ./configure
      By default, Erlang/OTP will be installed in `/usr/local/{bin,lib/erlang}`.
     To instead install in `<BaseDir>/{bin,lib/erlang}`, use the
      `--prefix=<BaseDir>` option.
3) make make install
4)安装好前把老版本先干掉,装好后,记得设置PATH;
5)最后在shell中用erl出现如下:
恭喜你成功了。
 
2.下载emacs最新版本:http://www.gnu.org/software/emacs/
同理:安装好emacs吧。我安装了30分钟(要有耐心哦,太慢了)

 1)erlang_mode package commes with erlang distribution;
 2)安装erlang_mode,只要装了完整的erlang,就会用的,只是要自己使生效,在.emacs中:
(add-to-list 'load-path ".....")
(require 'erlang-start)

(add-to-list 'auto-mode-alist '("\\.erl?$" . erlang-mode))
(add-to-list 'auto-mode-alist '("\\.hrl?$" . erlang-mode))

(setq erlang-root-dir "/opt/local/lib/erlang")
(add-to-list 'exec-path "/opt/local/lib/erlang/bin")
(setq erlang-man-root-dir "/opt/local/lib/erlang/man")
3)我们也可以定义自己的启动shell
     (defun my-erlang-mode-hook ()

        ;; 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")
        ;; customize keys
        (local-set-key [return] 'newline-and-indent)
        )
;; Some Erlang customizations
(add-hook 'erlang-mode-hook 'my-erlang-mode-hook)
4)erlang提供了我们一系列的命令来写代码,(导向,代码编写,和缩进..)navigation, code editing & indenting.
4.1)C-c C-j --(插入一个新的函数)erlang-generate-new-clause to insert new clause in current point — this command takes name of function from previous clause,
接着有个吊一点的命令:建了一个相同的函数(是不是没有参数,用下C-c c-y,神奇的一下就是一样的函数了);
4.2)会区分erlang中的;与enter,这个谁用谁知道:就是打;会跳到下个分支,enter会到下一行;
4.3)c-c c-q对齐一个Function.Tab会对齐一行;对齐全buffer没有bond,要自己设置erlang-indent-current-buffer.
4.4)c-h mark 一个函数哦(这个不要用,与help有冲突。C-M-h 也是(这个准一点,推荐)方便。
4.5)C-c C-C用于注释,C-c C-u解除注释;----不要和c-x c-u搞错了,这个是撤消,不是erlang_mode的。
4.6)M-q:这个只对注释用,会让注释更+readable的
4.7)C-a M-a会跳到函数的开头,c-a M-e会到函数的结尾; C-M-a中到上一个clause,C-M-e中到下一个clause
4.8)代码补全:通用模块会gen_server,case if 什么 的会。其它要配置了。

4.9)c-c c-z打开erl c-c c-l看打下的shell发生了什么,c-c c-k打开shell并编译当前文件(这个最后不要用,自己定义行为的好)。

4.10)编译的太麻烦了,还不实用,还不如自己定义。

Compilation and work with erl

User can execute Erlang's commands interactively using erl process running in the Emacs's buffer (process is running with comint, so user can use standard commands of this package, for example, navigation through history of commands with M-p & M-n keys). This process is also used by erlang-mode to compile source code.

To run new erl process, user can use the erlang-shell command, but it will implicitly run when user run compilation of source code, or try to switch to *erlang* buffer with erlang-shell-display command (C-c C-z).

Compilation and loading of compiled code is performed with erlang-compile command (C-c C-k). If user gives prefix argument to this command, then compilation will performed with options debug_info & export_all. To view compilation results, user can run erlang-compile-display command (C-c C-l). To move between errors, the erlang-next-error command (C-x `) is could be used. In this case, if you want to move to first error, you need to give prefix argument to this command, for example with C-u C-x `.
还有很多很多的mode,比如:只是行为不同,特定于一定的项目,(可以自己定义项目中的各种行为哦)

erlware-mode package is replacement for erlang-mode, using it as a base, but adding following new functionality:

  • code templates are changed — now they contain information for edoc utility;
  • started work on the integration with Sinan & Faxien projects, that allows to make installation & maintenance of Erlang's packages more easy.
  • Execution of basic commands also not differs from execution of the erlang-mode commands. Description of new commands will added in future, as they will released.
5)好了,接下来搞个强大点的:传说的distel,http://code.google.com/p/distel/
 dister  is a library in Emacs Lisp, that allows to write Emacs code in distributed style, and also allows to communicate with code, written in Erlang. This allows to implement set of commands, not existing in erlang-mode, that allow  to perform following tasks:就是不能在erlang-mode中没有的,又要用的功能了。
  • 找函数定义和文档;search for function's definitions & access to actual documentation;
  • 不懂..)module's & function's names completion, using actual information from Erlang environment;
  • 直接评价代码;direct evaluation of the code snippets;
  • base support for source code refactoring(重构);
  • debugging of Erlang programs;
  • display information about Erlang processes and work with them;
  • code profiling(分析).
5.1)安装distel(这个要下载的哦,http://code.google.com/p/distel/)。
To install package, you need to download it from the project's site and unpack it into selected place, and than add following code into initialization file
(add-to-list 'load-path "~/emacs/distel/elisp")
(require 'distel)
(distel-setup)
为了更好的定义,给个通用的参照吧。
;; 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)))))
这个模式和elang的环境有很大关系,第一次要输入节点什么的。
that some of them requires running Erlang environment, and when you'll execute them first time, they will ask you for a name of the node, that will be used to get all necessary information. User can switch between nodes with the erl-choose-nodename command(C-c C-d n). And for checking availability of the concrete node the erl-pingcommand(C-c C-d g) could be used. The command will ask you for name of the node, and if it available, it will load to node all modules are needed to work with distel. Name of the current node is displayed in the status line.
PS:
distel还可以启动debugger,i不过我觉得没什么用,不好玩。也玩不来,算了吧。
c_c c+d l erl-process-list 打开连接node的进程结构,可以看到,够强大
  • 大小: 75.6 KB
  • 大小: 23.8 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics