Use of the cedet that comes with Emacs 23.2 (if you download the cedet, you may encounter some trouble)
Decrease font to increase font size
Cedet is self-contained in Emacs 23.2. The version is the same as cedet on SourceForge, but the content (mainly the function name) has many changes. This article is based on a gentle introduction to cedet. The structure of this article is similar to that of this Article. Some parts of the content are translations,
1. What is cedet?
Cedet is the abbreviation of collection of Emacs Development Environment tools, meaning "Emacs development environment tool set". It aims to establish an advanced development environment in Emacs. It mainly includes the following components:
Semantic-basic component for syntax analysis in multiple programming languages.
Semanticdb-A database contained in semantic, used to save code syntax, interfaces, and other information.
Senator-navegation in the code file composed of information extracted by semantic.
Srecode-code generation component.
Ede-provides engineering management functions;
Speedbar -- used to display the sidebar of the current buffer.
Eieio is a library, implementating Clos-like (Common LISP Object System) Infrastructure for Emacs lisp;
Cogre is a library for drawing of UML-like diagrams in Emacs buffer, with basic integration with semantic.
I have never used the last two.
2. Install and enable cedet
Emacs 23.2 already comes with cedet, so you do not need to install it separately and enable it directly:
(Require 'cedet)
If you want to use the project management function of cedet, you can enable Ede mode ----
(Global-Ede-mode t)
3 cedet Customization
3.1 basic helpter Customization
In cedet in Emacs 23.2, commands such as semantic-load-enable-minimum-features and semantic-load-enable-code-helpers are removed, instead, you can customize the sub-mode (semantic-default-submodes) to determine which auxiliary functions are used, and finally enable these functions using semantic-mode.
Here are my settings:
; Helper tools.
(Custom-set-Variables
'(Semantic-default-submodes (Quote (Global-semantic-Decoration-mode global-semantic-idle-completions-Mode
Global-semantic-idle-scheduler-mode global-semanticdb-minor-Mode
Global-semantic-idle-Summary-mode global-semantic-MRU-bookmark-mode )))
'(Semantic-idle-scheduler-idle-time 3 ))
(Semantic-mode)
3.2 semantic/IA Configuration
Semantic/IA provides semantic auto-completion, tag information display, and other functions. semantic/IA can be enabled and optimized using the following code.
; Smart complitions
(Require 'semantic/IA)
(Setq-mode-Local C-mode semanticdb-find-default-Throttle
'(Project unloaded system recursive ))
(Setq-mode-Local C ++-mode semanticdb-find-default-Throttle
'(Project unloaded system recursive ))
3.3 header file settings
C/C ++ development requires a lot of dealing with header files. There are two types of header files: System header files and custom header files.
3.3.1 system header file
If we use GCC, we can use semantic/GCC to automatically load the system's header file path.
Of course, on this basis, we can also use semantic-add-system-include to manually add certain paths.
3.3.2 user header files
The user-defined header file can be expressed by the relative relationship between its location and the current path, and then manually added.
The system header file and user header file settings code is as follows:
; Include settings
(Require 'semantic/bovine/GCC)
(Require 'semantic/bovine/C)
(Defconst cedet-user-include-dirs
(List ".." "../include" "../INC" "../common" "../Public ""."
".. /.. "".. /.. /Include "".. /.. /INC "".. /.. /common "".. /.. /Public "))
(Setq cedet-sys-include-dirs (list
"/Usr/include"
"/Usr/include/bits"
"/Usr/include/glib-2.0"
"/Usr/include/gnu"
"/Usr/include/gtk-2.0"
"/Usr/include/gtk-2.0/gdk-pixbuf"
& Quot;/usr/include/gtk-2.0/GTK & quot"
"/Usr/local/include"
"/Usr/local/include "))
(Let (include-dirs cedet-user-include-dirs ))
(Setq include-dirs (append include-dirs cedet-sys-include-dirs ))
(Mapc (lambda (DIR)
(Semantic-add-system-include dir 'C ++-mode)
(Semantic-add-system-include dir 'C-mode ))
Include-dirs ))
(Setq semantic-C-dependency-system-include-path "/usr/include /")
3.4 integration of imenu
Semantic can be integrated into the Emacs menu through imenu to display and access the list of functions, variables and other tags through the menu.
In Emacs 23.2, you can use the following code to implement this function:
; Tags menu
(Defun my-semantic-hook ()
(Imenu-add-to-menubar "tags "))
(Add-hook 'semantic-init-hooks' my-semantic-hook)
3.5 semanticdb Customization
If you customize the helpertool according to the preceding code, sematicdb is automatically enabled. Here we need to first customize the storage path of semanticdb, for example, my:
; Semantic database storage location
(Setq semanticdb-default-save-directory
(Expand-file-name "~ /. Emacs. d/semanticdb "))
Semanticdb can use tags generated by other tools. For example, the tags generated by GNU global can be enabled according to the following code:
; Use the tags of GNU global.
(Require 'semantic/DB-Global)
(Semanticdb-enable-GNU-global-databases 'C-mode)
(Semanticdb-enable-GNU-global-databases 'C ++-mode)
3.6 manage C/C ++ Projects
We recommend that you use Ede to manage C/C ++ projects. The following code can be used to define a project:
(EDE-CPP-root-project "kernel"
: Name "kernel Project"
: File "~ /Work/projects/kernel/linux-2.6.34/makefile"
: Include-path '("/"
"/Include"
)
: System-include-path' ("/usr/include "))
There are several variables worth noting:
File:
File can be any file under the root directory of the program. This file does not need to be parsed, but is only a sign of this project.
Include-path:
This variable is a relative path that specifies the custom include directory. "/" Does not represent the root directory of the system, but the root directory of the project.
System-include-path:
This is an absolute path that specifies the include directory of the system.
4 cedet usage
4.1 Name completion
The completion includes the function name and variable name. It is a common function. In my opinion, the most practical complement is semantic-Ia-complete-symbol, which can be called through the shortcut key "c-c. For ease of use and unification with other packages, I added this function to hippie-expand, in addition, hippie-expand is packaged into the custom function indent-or-complete (found in someone else's configuration file) and bound to the tab. In this way, in most cases, you can use tab to complete or align. If the tab fails occasionally, use "M-/" or "C-C,/" to correct it.
The LISP code for this configuration is as follows:
; Indent or fill
; Hippie-try-expand settings
(Setq hippie-expand-try-functions-list
'(
Yas/hippie-try-expand
Semantic-Ia-complete-Symbol
Try-expand-dabbrev
Try-expand-dabbrev-visible
Try-expand-dabbrev-all-Buffers
Try-expand-dabbrev-from-kill
Try-complete-file-name-partially
Try-complete-file-name
Try-expand-all-abbrevs ))
(Defun indent-or-complete ()
"Complete if point is at end of a word, otherwise indent line ."
(Interactive)
(If (looking-at "//> ")
(Hippie-expand nil)
(Indent-for-tab-command)
))
(Defun yyc/indent-key-setup ()
"Set Tab as key for indent-or-complete"
(Local-set-Key [(Tab)] 'indent-or-complete)
)
In addition, for the struct/class structure of C and C ++, the semantic-complete-Self-insert function can insert member variables in the class or structure and bind them ". "or"> "to accelerate the efficiency of code writing:
; C-mode-hooks.
(Defun yyc/C-mode-keys ()
"Description"
; Semantic functions.
(Semantic-default-C-Setup)
(Local-set-key "/c-c? "'Semantic-Ia-complete-symbol-menu)
(Local-set-key "/C-CB" 'semantic-mrub-switch-tags)
(Local-set-key "/C-Cr" 'semantic-symref)
(Local-set-key "/C-CJ" 'semantic-Ia-fast-jump)
(Local-set-key "/C-CP" 'semantic-Ia-show-summary)
(Local-set-key "/C-Cl" 'semantic-Ia-show-Doc)
(Local-set-key "/C-Cr" 'semantic-symref-symbol)
(Local-set-key "/c-c/" 'semantic-Ia-complete-symbol)
(Local-set-Key [(control return)] 'semantic-Ia-complete-symbol)
(Local-set-key "." 'semantic-complete-Self-insert)
(Local-set-key ">" 'semantic-complete-Self-insert)
; Indent or complete
(Local-set-Key [(Tab)] 'indent-or-complete)
)
(Add-hook 'C-mode-common-hook 'yyc/C-mode-keys)
4.2 obtain Tag Information
The semantic-Ia-show-Doc, semantic-Ia-show-Summary, and semantic-Ia-describe-class functions can be used to obtain tag information, the code comments (including doxgen comments) are helpful for reading the code.
These functions can be bound according to your own habits. The first two binding processes can be found in the previous yyc/C-mode-Keys.
4.3 jump in code
When reading the code, redirection is a useful function in different tags. Cedet provides this function, but the cedet we bring in Emacs 23.2 has a problem in tag jump-you can use semantic-Ia-fast-jump to the tag definition, however, you cannot jump back after each jump.
After setting helper according to the method in section 3.1 of this article, add the following code to the configuration file to solve this problem:
(Defadvice push-mark (around semantic-MRU-bookmark activate)
"Push a mark at location with nomsg and activate passed to 'push-mark '.
If 'semantic-MRU-bookmark-mode' is active, also pushes a tag
The MRU bookmark stack ."
(Semantic-mrub-push semantic-MRU-bookmark-ring
(Point)
'Mark)
Ad-do-it)
4.4 search for function calls
In the previous section, we will jump to the tag definition in the current function. Here, we will show which functions under the current cursor are called. The semantic-symref in cedet implements this function. You can bind the function to your favorite shortcut key, as shown in 4.1.
Most of the time I use the global tool for code browsing, It is very convenient to configure xgtags in global.
4.5 Use of srecode
Cedet provides srecode for automatically generating code. However, I personally feel that this function is not very useful, or I will not use it.
The cedet self-contained in Emacs 23.2 only provides the srecode function, but does not publish the template together with Emacs.
In this regard, I modified srecode-Map-load-path and added "~ /. Emacs. d/templates/srecode ",
; Custom template for srecode
(Setq srecode-Map-load-Path
(List (srecode-Map-base-template-DIR)
(Expand-file-name "~ /. Emacs. d/templates/srecode ")
))
Download the source code package from the cedet official website and decompress the template "~ /. Emacs. d/templates/srecode.
Then, you can use functions such as srecode-insert to insert Code templates.