Configure the c/c ++ compiling environment in Linux-Emacs-repost blog

Source: Internet
Author: User

In linux programming, we should first choose development tools. Naturally, we are looking at the two major online artifacts VIM and EMACS. Although they are just editors, they have a strong customizable system, it has become the first choice for linux workers. So today, I will write about the process and experience of using Emacs and configuring Emacs as a simple IDE. However, when talking about how to configure the IDE, Wu Yin, a senior in CSDN, has an article about how to configure VIM as the IDE. I have learned a lot about linux programming and I am very impressed. By the way, I used to write a program using VIM, so VIM seems to be a simple IDE, but later I switched to Emacs (Declaration: I have no intention of joining the competition between VIM and Emacs. It is my personal habit and preference to choose one ).

On the Internet, many people say that Emacs has a high threshold and is difficult to get started. In fact, it is not so exaggerated, it may be a little more difficult than VIM, but it is also very easy to get started, but it is easy to use. Well, let's talk less about it. Next we will go to today's topic: Creating Emacs.

Emacs is described as follows:

  1. Basic Emacs operations and key combinations
  2. Frame and size at startup and position on the screen
  3. Basic general settings of Emacs
  4. Emacs Development Environment Settings (C/C ++, script, etc)
  5. Some extension configurations of Emacs (such as changing the shape of the cursor)

Appendix: This article does not explain lisp programming.

My working environment is ubuntu11.04, and emacs is directly installed using sudo apt-get install emacs. The version is GNU Emacs 23.3.1. The example below is basically a demonstration in C language.

 

The following describes the names that may be used in some articles:

All the paths in this article are ~ /Directory. Some paths in the text are as follows ,~ /_ Emacs ,~ /Work, and so on. If you do not have one, you can create one by yourself. The. emacs file is in ~ /. Emacs.

 

Let's take a look at two images: My emacs interface, o (cost _ memory) o

Figure 1:

 

 

Comparison ID:

1: simple and clear buffer browsing and operations, as well as some file browsers and tag browsing

2: highlighted code editing area

3: Automatic completion

4: Better file browser

 

Figure 2: (debug)

 

Comparison:

1: Graphical debugging options

2: Variable display area

3: source code display area

4: Stack view area

5: breakpoint viewing area

 

2. Basic Emacs operations and key combinations 1. Definition of Emacs mode keys

Four mode keys: C ------ à ctrl; M ------ à alt; s ------ à super (win); S ---- à shift

For example, C-x: ctrl + x (ctrl + x ).

C-x c C-c: press ctrl, Press x, release, and then press c.

C-x k: press ctrl and press both the x and k keys.

2. Basic key combinations of Emacs

C-x C-c: Exit Emacs

C-x C-s: Save the Current buffer

C-x C-f: open and create a file

C-n: move the cursor to the next line.

C-p: move the cursor to the previous line.

C-k: delete a row

M-x: Execute the command

 

I have rebound many other key combinations, which will be described below.

 

3. The size at startup and the position on the screen

 

The statement indicates the Emacs with the height of 35 and 100 in width at x = 20, y = 0 on the screen after startup.

Note: There are two ways to modify the startup size of Emacs ~ /. Xdefault file, and then run xrdb ~ /. Xdefault; ② In ~ /. Modify it as shown in emacs. Then the online description is the first method better. Therefore, here is a description. Based on my experience, I prefer to use 2nd methods, because after the first method is used, the emacs configuration file is modified each time, both need to re-run xrdb ~ /. Xdefault. I personally feel annoyed and have some other problems. I will not mention it here, so I chose to modify it in the. emacs configuration file.

 

4. Basic general settings of Emacs

According to the general habits, the. emacs file usually does not contain too much configuration information, and usually contains some information about the search path of emacs. Here, my emacs configuration files, that is, the lisp scripts are all stored in ~ /_ Emacs folder.

Therefore, first add an emacs search path:

Then, load our setup script for emacs and add the following statement to. emacs:

Several script files in the figure will explain the usage of the tool separately below.

① Basic settings for emacs, that is, the base. el file (IN ~ In/_ emacs), part of the base. el file is as follows:

Set the default working directory, that is, the directory where emacs is started. Here I set the work folder under the main directory. Almost all my code is completed under this directory, in the base. in el, add the following sentence:

 

The above are some basic and important configurations. I did not add more instructions, because almost every line of statements in the figure has annotations, so you should be able to understand. O (partition _ partition) o

 

5. C/C ++ Configuration

The following describes the configuration of C/C ++, Because I mainly develop C/C ++ in Linux. My C/C ++ configuration is mainly in the cycode. el file.

① Debugging is an important step during development. Therefore, a good debugging environment is very important, so the first step is the graphical debugging interface:

 

Two lisp script files are loaded above. These two files are graphical debugging files directly on the Internet.

② To efficiently browse and edit code, you need to install the cedet plug-in (which can be downloaded from the official website). After downloading cedet, go ~ Extract the files from the/install directory, see the INSTALL file in the decompressed folder, and install cedet according to the description in it (Note: All the plug-ins I need to INSTALL are in ~ In the/install directory, we will not repeat the description below). One thing to note is that after the installation is complete, the installed files cannot be deleted, that is, the decompressed folder needs to be retained.

After the installation is complete, use the following statement to include the required items:

 

Now we can set the cedet. Here we just use a code folding and expansion example:

 

③ To make use more convenient, that is, to supplement the above cedet plug-in, you need to install a ecb plug-in. Download the ecb and put it in the intall directory. Unzip it (just extract it). Then add the following two sentences:

 

④ Automatic completion function. To achieve automatic completion function, two plug-ins need to be installed. These two plug-ins complement each other-auto-complete and yasnippet. Install auto-complete first, download it, and put it in the install directory to decompress it. Then enter the decompressed directory, and enter the make command. install yasnippet below and put it in the install directory, decompress the package. The following describes the configurations of these two plug-ins:

 

⑤ After the plug-in is installed, the following are some comprehensive configurations:

 

The following are two completion commands:

 

 

6. Key Binding

At this point, the C/C ++ development environment has been basically completed. To make it easier for you to use emacs, you need to create some bindings, that is, you need to define some key combinations, this is an essential step in emacs configuration. All of my custom keys are placed in cykbd. in the el file, the following is part of my key binding code:

In general, f1 is used to indicate help, that is, the man command:

 

This part is some bindings to the f1-f12:

 

The f6 here is debugging, that is, gdb debugging, f7 is to call make to compile the original file.

Perform some common operations on the buffer using f8:

 

Use f12 to view function definitions:

 

Bind the ecb key:

 

Bind some keys of the window:

 

 

7. Extended Emacs Configuration

The above has completed the basic work of configuring emacs. In other words, we can use emacs for development so far, but in order to further make emacs more in line with my habits, added another cyexpand. el is a more powerful emacs configuration file, cyexpand. the el part is set:

 

Emacs topic settings:

 

Change the cursor to a vertical line:

 

 

8. Summary

So far, emacs has been built into a simple IDE for c/C ++ development. Due to the limitations of my own capabilities, you are welcome to criticize and correct the shortcomings in this article. I will package and upload all my configuration files and plug-ins that need to be downloaded, and set up and encode them in detail. After downloading them, you can gain a deeper understanding in the usage process, you only need to check the base in the _ emacs directory. el, cycode. el, cykbd. el, cyexpand. el files and other script files are various configurations written by Daniel from various places. My Configuration File Download connection is:

Http://download.csdn.net/detail/karotte/3812760

 

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.