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

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

主站蜘蛛池模板: 延长县| 阳信县| 庆元县| 雷山县| 内黄县| 邢台县| 冀州市| 侯马市| 沙田区| 贵德县| 镇雄县| 瑞昌市| 兴城市| 鄂托克前旗| 牙克石市| 河曲县| 盈江县| 潜山县| 西安市| 蒙阴县| 虞城县| 紫阳县| 朝阳区| 鄂伦春自治旗| 永寿县| 铁岭县| 中方县| 大方县| 晋城| 磴口县| 南安市| 金昌市| 兴和县| 永清县| 积石山| 甘南县| 昭觉县| 延川县| 荣昌县| 太康县| 灌南县|