官术网_书友最值得收藏!

Using Emacs as the Scala IDE

If you haven't yet picked a Scala IDE to use, I would like to recommend the ENSIME mode for Emacs and other editors. You can find it at the following website:

https://github.com/ensime

Obviously installation instruction will be dependent on the kind of editor you are using. If using it with Emacs (a popular cross-platform editor), the installation process is described here. You can get Emacs from the Emacs website:

https://www.gnu.org/software/emacs/

There are a lot of books available on using it. It is completely open source and with ENSIME it makes probably the best open source IDE for Scala, in the author's opinion. After installing Emacs on your system, you can install ENSIME. To do this, first add the following lines to your .emacs file, which (on Linux) usually resides in your home directory. If you are not using Linux, consult the Emacs documentation for where the .emacs file is. The following code assumes a fairly recent version of Emacs. This was tested with Emacs 24:

(require 'package)
(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/"))
(when (< emacs-major-version 24)
  (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize)
(require 'ensime)
(add-hook 'scala-mode-hook 'ensime-scala-mode-hook)

After adding this and restarting Emacs, you need to actually install ENSIME, which is fortunately really simple. Just use the M-x package-install key combination, press Return, then enter ensime, and press Return again. Note that M in Emacs stands for the Alt key. So the combination is Alt-x. However, it is customary to write it the way we did.

Scala integrates well with the SBT tool, which we will discuss in the next section. Instructions on how to integrate the two are given in it. Here we will just list some of the things that ENSIME can do for you to enable you to write code more efficiently and mistake-free. These include code completion, type inspection, automated refactoring, and code navigation. ENSIME will also highlight parts of your code that contain compilation errors. It is usually easy to tell from the markings where you went wrong.

The code completion feature will show you possible completions for the code you are currently typing. If it is a variable name, it will try to guess how to complete it so that you can enter it quickly. Also, you can press the Tab key after entering the object name and a dot (.). This will show you a list of all methods you can use for that object.

Type inspection allows you to see what will be the result of Scala's type inference mechanism. To see what type has been inferenced, simply use the C-c C-v i key combination. This means Ctrl-c Ctrl-v i in Emacs notation.

Automated refactoring features let you conveniently rename variables, without worrying that you may have forgotten some, and do other similar stuff. This is more useful for larger projects.

Code navigation features in ENSIME let you move around in the code by finding the definitions of symbols under the cursor. You can use M-. to jump to the definition of the object under the cursor.

The complete command reference for ENSIME can be found at:

https://github.com/ensime/ensime-emacs/wiki/Emacs-Command-Reference

主站蜘蛛池模板: 岑溪市| 凤台县| 施秉县| 海口市| 繁昌县| 香河县| 筠连县| 铁岭县| 健康| 潜江市| 五原县| 清苑县| 闻喜县| 大足县| 定兴县| 昌黎县| 安泽县| 西乡县| 得荣县| 华亭县| 略阳县| 八宿县| 深水埗区| 克东县| 盱眙县| 四平市| 南开区| 塘沽区| 高台县| 涪陵区| 孝感市| 章丘市| 黔江区| 庐江县| 友谊县| 白河县| 米易县| 郸城县| 阜阳市| 玛曲县| 兴和县|