Auto completion full guide in Emacs

Source: Internet
Author: User

Author: redguardtoo)

Version: 20120821

Original date:

The so-called "Automatic completion" means that Emacs intelligently guesses the words that the user wants to enter and helps the user enter them automatically. If Emacs finds multiple options, the drop-down menu may also pop up for users to select.

Generally, the intelliisense In the IDE can be regarded as an automatic completion ".

The Automatic completion of Emacs is far more powerful than the normal IDE's intelliisense. For example, emacs can automatically enter the name of the currently opened file (either with or without a filename suffix ).

I am not here to praise the power of Emacs. I am here to talk about it. There are too many automated frameworks in Emacs, and many of them have overlapping functions, which is really annoying.

Therefore, this article has two purposes,

  1. Describes which Automatic completion frameworks are mainstream
  2. How to configure and use the automatic completion framework
Table of contents
  • 1 Overview
  • 2 Auto-complete combined with clang
  • 3 hippie-expand
  • 4 complete-Symbol
  • 5 edevil-Mode
  • 6 Summary
1 Overview
Function/plug-in name Shortcut Key Recommendation degree
Complete-Symbol C-m-I Medium
Auto-complete (combined with clang) Tab Excellent
Hippie-expand M -/ Good
Edevil-Mode C-N/C-P (Completion word), C-x C-N/P (Completion line) Medium
2 Auto-complete combined with clang

This is a solution I strongly recommend. Auto-complete is a third-party plug-in that provides the required support for Automatic completion (for example, simulating the drop-down menu in the command line environment ).

Clang is the most excellent C/C ++/objective-C compiler developed by Apple. It parses C ++ syntax fast and well.

Obviously, this solution only applies to languages supported by clang. It supports Mac, Linux, and cygwin platforms. I don't know if it supports Windows platforms.

Third-party plug-ins auto-complete and auto-complete-clang must be installed through the elpa (Emacs appstore.

If you are a heavy ide user and like the intelliisense feature of IDE, this is what you need.

For specific configuration, please refer to my init-auto-complete.el.

By the way, for elpa configuration, you may need to refer to my init-elpa.el, because now there are multiple appstores that don't come with emacs24 support for elpa.

3 hippie-expand

Hippie-expand is an automatic completion framework provided by Emacs. Its default Automatic completion features can be used as a supplement to auto-complete. For example, the automatic completion of word/file name/line functions.

Since it is a framework, it can be expanded. The Emacs wiki provides a solution that combines with ctags.

Ctags are similar to clang, which performs Syntax Parsing on the backend of various languages, but their intelligence is far inferior to clang and the semantic mentioned later. The advantage is that all languages are fluent (such as JavaScript ), supports all operating systems and fast resolution (nonsense, regular expressions ).

For specific configuration, please refer to my init-hippie-expand.el.

4 complete-Symbol

Emacs comes with a function. I feel like this solution, because in emacs23, it only calls the background ctags by default.

Hippie-expand can also use ctags after instruction, and its default features are more than complete-symbol, so I am not interested in configuring the third Automatic completion framework.

It is worth introducing because I have read changelog of emacs24 and found that the complete-symbol can be used as the syntax to parse the backend after being configured. (After I tried it, I found that emacs23.4 is also supported, I don't understand why I should describe this feature in changelog of emacs24 ).

Semantic is a syntax parser written by LISP. It comes with Emacs and is intelligent between ctags and clang. The parsing speed is slow. If the machine configuration is poor (for example, My eeepc701 netbook ), will make Emacs very difficult.

I personally did not like this syntax parser. In the past, when semantic was still an open-source project cedet component that was not integrated into Emacs, I had to go through cedet. At that time, I felt that the speed was slow, the configuration is cumbersome and unstable.

Maybe it is much better to integrate semantic into Emacs now.

Semantic supports multiple languages, such as C ++/Java. If you are a Java programmer, you can consider the complete-symbol and semantic solutions.

See my init-semantic.el for specific configuration (note that I don't need semantic, so the corresponding code is commented out. If you want to use semantic, uncomment ).

5 edevil-Mode

Emacs is simulated into Vim by edevil-mode, which is my favorite third-party plug-in. Its Automatic completion is very simple. It is to automatically complete the word or line according to the content of the current file.

It is recommended because I used to be a heavy Vim user and Vim's automatic shortcut keys have become my instinct.

There is nothing to configure, just start edevil-mode, see my init-evil.el.

6 Summary

The so-called automatic completion framework consists of the front-end user interface and the back-end Syntax Parsing engine.

As a front-end user interface, I think the only thing that works well is auto-complete. Others are common.

The back-end Syntax Parsing engine, clang is the best. in fact, ctags cannot talk about Syntax Parsing, but they only play with regular expressions, so they can use all languages. semantic supports a little more languages than clang, with poor performance and stability.

As a C ++ programmer, I prefer auto-complete and clang.

If you use some scripting languages (Ruby/Python/JavaScript), I will use ctags and hippie-expand.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.