Solve the Problem of code viewing in linux

Source: Internet
Author: User
Solve the Problem of code viewing in linux-Linux general technology-Linux programming and kernel information. The following is a detailed description. In windows, We have source in sight to conveniently browse the code in a large project. When we switch to a linux environment for development,
We can also build an environment like this. The following content describes how to build such a development environment (we assume that you are familiar
Install and configure emacs ).

Step 1 install the following software

1) cscope (version 15.6): cscope is a code browsing tool that helps you in a large project,
Quickly locate the Declaration location of a function/variable, all references, and so on. It can be used together with vim and emacs.
It is difficult to process the redirection between different files when csflood is used separately. Here we will introduce the csflood In the emacs environment.
Use;

2) cedet-1.0pre4: ecb needs to depend on this;

3) ecb-2.32: This is the emacs plug-in, you can divide several different windows in emacs, such as the source code window,
Project Directory window, method window, etc;

4) emacs-22.1.1
5) display-line-number.el display line

Step 2 modify or create the. emacs file

; Load the plug-in we need

(Load-file "path/cedet. el ")
(Load-file "path/ecb. el ")
(Load-file "path/xcsw.el ")
(Load-file "path/display-line-number ")
(Global-display-line-number-mode 1)
(Setq display-line-number-format "% 4d | ")

; Below are two commonly used shortcut keys

(Grobal-set-key "\ M-g" 'Goto-line)
(Grobal-set-key "\ M-m" 'set-mark-command)

Step 3 add a project

Suppose we want to add the source code of/home/src/linux-2.6.23 to the project, we can do this,
1) cd/home/src/linux-2.6.23 to enter the source code root directory;
2) touch cscope. sh: Create a script file with the following content:

#! /Bin/bash

LNX =/home/src/linux-2.6.23
Find $ LNX \
-Path "$ LNX/arch /*"! -Path "$ LNX/arch/i386 *"-prune-o \
-Path "$ LNX/include/asm -*"! -Path "$ LNX/include/asm-i386 *"-prune-o \
-Path "$ LNX/tmp *"-prune-o \
-Path "$ LNX/Documentation *"-prune-o \
-Path "$ LNX/scripts *"-prune-o \
-Path "$ LNX/drivers *"-prune-o \
-Name "*. [chxsS]"-print> cscope. files

Cscope-B-k

3) after running the cssag. sh script, run emacs, activate ecb through M-x ecb-activate, and then run
M-x ecb-add-source-path: add $ LNX to the project.
Command emacs-nw to activate emacs ).


Step 4 familiarize yourself with the commands

1) several commonly used modes:
M-x ecb-activate
M-x hs-minor-mode 'Code folding
M-x display-line-number-mode-on 'displays the row number and requires display-line-number.el
M-x ediff/ediff-revision comparison Mode
M-x compile
M-x gdb 'debug Mode
...
2) window switch command
C-c. g d: Enter the project browsing window
C-c. g s: Enter the source file browsing window
C-c. g m: Enter the method browsing window
C-c. g l: Enter the recently edited File
C-c. e enters eshell Mode

3) code browsing command
All references of C-c s
C-c s c all caller
C-c s g declaration, prototype
...

4) column Editing:
M-m/M-W' sets mark
M-x string-insert-regtangle 'inserts text, or C-x r t
C-x r K' to delete text. You can use C-x r y to copy it to another place.
C-x r c
C-x r d

5) version Comparison
If you use svn to manage code, you can enter emacs and use M-x ediff-revision for version comparison. General comparison
It is very convenient to use M-x ediff/ediff-directiories.

Supplement: emacs or vim has many commands. If you really want to use these tools well, you need to read more relevant information and
Multiple exercises

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.