Emacs uses semantic

Source: Internet
Author: User

I always thought that semantic configuration was not successful. I finally succeeded by referring to the smth configuration file yesterday.

When installing ECB, you have installed semantic. Then you only need to add the following three lines to the. emacs file.

(require 'cedet)(semantic-load-enable-code-helpers)(global-set-key [(control tab)] 'semantic-ia-complete-symbol-menu)

Then use Emacs to open a C/C ++ file, and you can use Ctrl + TAB to pop up the prompt menu for Automatic completion. Semantic parse all currently include files and then intelligently prompts them.

 

:

 

 

This configuration is too simple. Let's talk about its configuration process in a configuration file that is a little complicated:

(Require 'cedet)

; Enabling semantic (Code-parsing, smart completion) feature, select one of the following:
; (Semantic-load-enable-minimum-features)
(Semantic-load-enable-code-helpers)
; (Semantic-load-enable-guady-code-helpers)
; (Semantic-load-enable-excessive-code-helpers)
; (Semantic-load-enable-semantic-debugging-helpers)

; (Global-set-Key [(control tab)] 'Senator-complete-symbol );
; (Global-set-Key [(control tab)] 'Senator-completion-menu-popup); use c-c, SPC instead
; (Global-set-Key [(control tab)] 'semantic-Ia-complete-symbol)
(Global-set-Key [(control tab)] 'semantic-Ia-complete-symbol-menu)

; Configure the search range of semantic:
; (Setq semanticdb-project-roots
; (List
; (Expand-file-name "/")))

; Set the path of the semantic cache temporary file to avoid temporary files everywhere
; (Setq semanticdb-default-save-directory "~ /. Emacs. d /")

; When C/C ++ is started, semantic pairs/usr/include index databases are automatically loaded.
; (Setq semanticdb-search-system-databases T)
; (Add-hook 'C-mode-common-hook
; (Lambda ()
; (Setq semanticdb-project-system-Databases
; (List (semanticdb-create-Database
; Semanticdb-New-database-class
; "/Usr/include ")))))

(Require 'cedet) is of course used to load cedet extensions. cedet includes semantic and some other extensions.

Semantic-load-enable-code-helpers is used to set the degree of the semantic analysis file, which has a total of five levels, increasing complexity from top to bottom. Semantic-load-enable-minimum-features is the minimum requirement. semantic-load-enable-code-helpers is a little more complex, an imenu menu is added (but this menu cannot be displayed on both Windows and Mac). semantic-load-enable-guady-code-helpers adds some useful functions, for example, display the current function in the first line (this command is not recommended ); semantic-load-enable-excessive-code-helpers adds the function of displaying the current function name in mode line, which is not very useful; semantic-load-enable-semantic-debugging-helpers is used to debug the semantic itself. So we generally use semantic-load-enable-code-helpers.

(Global-set-Key [(control tab)] 'semantic-Ia-complete-symbol-menu) is used to set the shortcut key. Because semantic does not set the default hotkey, I bound it to Ctrl + TAB. There are four options for completion: Senator-complete-symbol is to directly complete the analysis result of the senator call, without the pop-up menu; Senator-completion-menu-popup is also to call senator, however, a selection menu pops up. semantic-Ia-complete-symbol intelligently complements the analysis results of semantic, without the menu being popped up; semantic-Ia-complete-symbol-menu is also the result of calling semantic, but a selection menu is displayed. Because the analysis results of semantic are more intelligent, semantic-Ia-complete-symbol-menu is generally used.

Use semanticdb-project-roots to configure the search range of semantic. The simplest way is to directly configure the/root directory in Linux. However, I found that it can also be used without configuration. It is possible that semantic is set to/by default.

(Setq semanticdb-default-save-directory "~ /. Emacs. d/") set the location where the cache file is stored. If it is not set, it is in the directory of the analyzed file by default.

The last section let semantic automatically load the parse results of the C/C ++ standard library. However, my trial results are not very satisfactory.

So I usually only use the first three sentences to make semantic work very well.

I am a lazy and do not like it. emacs writes something, so the first three lines can not be written. emacs, and after Emacs is started, running the following commands in turn has the same effect:

load-library <RET> cedetsemantic-load-enable-code-helpersglobal-set-key <RET> <control tab> semantic-ia-complete-symbol-menu

2009-03-03:

1. semantic-Ia-fast-jump (as if it was added from cedet1.0pre5) can implement a function similar to F12 in Vs, jump to the definition of the symbol where the cursor is located, I bound it to F12.

2. cedet-contrib has an eassist. el, which can be easily switched between H/CPP files in C ++. The specific command is eassist-switch-H-CPP, you can bind it to a key (I used F11 ).

3. By default, semantic only searches for the current path, as if there is still a system path/usr/include. For Windows, run the following command:

(semantic-add-system-include "C:/MinGW/include/c++/3.4.5" 'c++-mode)(semantic-add-system-include "C:/Program Files/Microsoft Visual Studio 9.0/VC/atlmfc/include" 'c++-mode)

Add the header file path of mingw or Vc, so that you can use semantic to complete the MFC class.

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.