GNU Emacs
Emacs
Dashboard

26.10 Semantic

Semantic is a package that provides language-aware editing commands based on source code parsers. This section provides a brief description of Semantic; for full details, see Semantic in Semantic.

Most of the language-aware features in Emacs, such as Font Lock mode (see Font Lock mode), rely on rules of thumb 14 that usually give good results but are never completely exact. In contrast, the parsers used by Semantic have an exact understanding of programming language syntax. This allows Semantic to provide search, navigation, and completion commands that are powerful and precise.

To begin using Semantic, type M-x semantic-mode or click on the menu item named ‘ Source Code Parsers (Semantic)’ in the ‘ Tools’ menu. This enables Semantic mode, a global minor mode.

When Semantic mode is enabled, Emacs automatically attempts to parse each file you visit. Currently, Semantic understands C, C++, HTML, Java, Javascript, Make, Python, Scheme, SRecode, and Texinfo. Within each parsed buffer, the following commands are available:

C-c , j

Prompt for the name of a function defined in the current file, and move point there ( semantic-complete-jump-local).

C-c , J

Prompt for the name of a function defined in any file Emacs has parsed, and move point there ( semantic-complete-jump).

C-c , SPC

Display a list of possible completions for the symbol at point ( semantic-complete-analyze-inline). This also activates a set of special key bindings for choosing a completion: RET accepts the current completion, M-n and M-p cycle through possible completions, TAB completes as far as possible and then cycles, and C-g or any other key aborts completion.

C-c , l

Display a list of the possible completions of the symbol at point, in another window ( semantic-analyze-possible-completions).

In addition to the above commands, the Semantic package provides a variety of other ways to make use of parser information. For instance, you can use it to display a list of completions when Emacs is idle. See Semantic in Semantic, for details.


Footnotes

(14)

Regular expressions and syntax tables.