(font_load_for_lface, font_open_by_name): Don't store name
[bpt/emacs.git] / doc / misc / sem-user.texi
CommitLineData
3149927d
CY
1@c This file is included by semantic.texi
2
77fd3e0c 3@c Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2009
3149927d
CY
4@c Free Software Foundation, Inc.
5
6@c Permission is granted to copy, distribute and/or modify this
7@c document under the terms of the GNU Free Documentation License,
8@c Version 1.3 or any later version published by the Free Software
9@c Foundation; with no Invariant Sections, no Front-Cover Texts, and
10@c no Back-Cover Texts. A copy of the license is included in the
11@c section entitled ``GNU Free Documentation License''.
12
13You can begin using @semantic{} by enabling Semantic mode, a global
14minor mode: type @kbd{M-x semantic-mode}, or click on the @samp{Source
15Code Parsers (Semantic)} menu item in the @samp{Tools} menu.
16
17When Semantic mode is turned on, Emacs automatically parses each file
18you visit. This allows you to use @semantic{} user commands in those
19buffers. It also enables a number of ``helper'' minor modes for
20saving tags, displaying tag information, and so forth. @xref{Semantic
21mode}.
22
23To enable Semantic mode each time you start Emacs, add the line
24@code{(semantic-mode 1)} to your initialization file. @xref{Init
25File,,,emacs,Emacs manual}.
26
27@menu
28* Semantic mode:: Global minor mode for @semantic{}.
29* SemanticDB:: Caching parsed buffers between sessions.
30* Idle Scheduler:: Performing @semantic{} operations when idle.
fd1cefda 31* Analyzer:: Semantic tools for analyzing code.
3149927d
CY
32@end menu
33
34@node Semantic mode
35@section Semantic mode
36@cindex Semantic mode
37
38Semantic mode is a global minor mode for @semantic{} as a whole. When
39enabled, each file you visit is automatically parsed, provided its
40major mode is specified in the variable
41@code{semantic-new-buffer-setup-functions} (the default is to parse
42every buffer @semantic{} knows how to parse).
43
44In each parser-enabled buffer, a number of @semantic{} commands are
45available for navigating, querying, and editing source code.
46@xref{Semantic mode user commands}. Enabling Semantic mode also
47installs a @samp{Development} menu on the menu-bar, with many of these
48commands.
49
be479117 50In addition, enabling Semantic mode turns on certain auxiliary global
3149927d 51minor modes, as specified by the variable
be479117 52@code{semantic-default-submodes}. The default auxiliary modes are
3149927d 53SemanticDB mode (@pxref{SemanticDB}) and Global Semantic Idle
9d542758
CY
54Scheduler mode (@pxref{Idle Scheduler}). You can also toggle the
55auxiliary minor modes separately, using their mode functions
56(e.g. @kbd{M-x semanticdb-minor-mode}), or via the @samp{Development}
57menu. These auxiliary minor modes are described in the following
58sections.
3149927d
CY
59
60@defvar semantic-new-buffer-setup-functions
61The value of this variable is an alist of functions to call for
62setting up @semantic{} parsing in the buffer. Each element has the
63form @code{(@var{mode} . @var{fn})}, where @var{mode} is a value of
64@code{major-mode} for the buffer and @var{fn} is the corresponding
65function for setting up the parser. @var{fn} is called, with no
66arguments, after the major mode is initialized (and after the mode
67hooks have been run).
68
69The default value enables @semantic{} for all supported major modes
70(i.e., C, C++, Scheme, Javascript, Java, HTML, SRecode, and Make), but
71you can remove modes from this list if you don't want to use
72@semantic{} with them.
73@end defvar
74
75@defvar semantic-default-submodes
76The value of this variable is a list of symbols, specifying the
be479117 77auxiliary minor modes to enable when enabling Semantic mode. The
3149927d
CY
78valid mode symbols are:
79
80@itemize
81@item @code{semantic-idle-scheduler-mode} (@pxref{Idle Scheduler}).
82@item @code{semanticdb-minor-mode} (@pxref{SemanticDB}).
83@item @code{semantic-idle-summary-mode} (@pxref{Idle Summary Mode}).
84@item @code{semantic-idle-completions-mode} (@pxref{Idle Completions Mode}).
85@item @code{semantic-highlight-func-mode}
86@item @code{semantic-decoration-mode}
87@item @code{semantic-stickyfunc-mode}
88@item @code{semantic-mru-bookmark-mode}
89@end itemize
90@end defvar
91
92@menu
93* Semantic mode user commands::
94@end menu
95
96@node Semantic mode user commands
97@subsection Semantic mode user commands
98
99Semantic mode provides a number of commands for navigating, querying,
100and editing source code in a language-aware manner. These commands
101generally act on @dfn{tags}, which are the source-code units deemed
102``important'' by the present programming language (e.g. functions in
103the C programming language).
104
105These commands may be used in any buffer that has been parsed by
106@semantic{}. Several of them prompt for a tag name using the
107minibuffer; here, the @kbd{TAB} key can be used to complete tag names.
108Others act on the @dfn{current tag}, meaning the tag at (or around)
109point.
110
111@table @kbd
fd1cefda 112@item C-c , j
3149927d
CY
113Prompt for a tag defined in the current file, and move point to it
114(@code{semantic-complete-jump-local}).
115
fd1cefda 116@item C-c , J
3149927d
CY
117Prompt for a tag defined in any file that Emacs has parsed, and move
118point to it (@code{semantic-complete-jump}).
119
fd1cefda 120@item C-c , l
3149927d
CY
121Display a list of the possible completions of the current tag
122(@code{semantic-analyze-possible-completions}).
123
fd1cefda 124@item C-c , g
3149927d
CY
125Prompt for a tag, and display a list of tags that call it
126(@code{semantic-symref-symbol}).
127
fd1cefda 128@item C-c , G
3149927d
CY
129Display a list of tags that call the current tag
130(@code{semantic-symref}).
131
fd1cefda 132@item C-c , p
3149927d
CY
133Move point to the previous tag (@code{senator-previous-tag}).
134
fd1cefda 135@item C-c , n
3149927d
CY
136Move point to the next tag (@code{senator-next-tag}).
137
fd1cefda 138@item C-c , u
3149927d
CY
139Move point ``up'' one reference (@code{senator-go-to-up-reference}).
140The meaning of ``up'' is language-dependent; in C++, for instance,
141this means moving to the parent of the current tag.
142
fd1cefda
CY
143@item C-c, @key{SPC}
144Display a list of possible completions for the symbol at point
145(@code{semantic-complete-analyze-inline}). This also activates a
146special set of keybindings for choosing a completion: @key{RET}
147accepts the current completion, @kbd{M-n} and @kbd{M-p} cycle through
148possible completions, @key{TAB} completes as far as possible and then
149cycles, and @kbd{C-g} or any other key aborts the completion.
150@xref{Smart Completion}.
3149927d 151
fd1cefda 152@item C-c , C-w
3149927d
CY
153Kill the current tag (@code{senator-kill-tag}). This removes the text
154for that tag, placing it in the kill ring. You can retrieve the text
155with @kbd{C-y}. This also places the tag in the @dfn{tag ring}, so
156that you can yank it with @kbd{\C-c,\C-y}, below.
157
fd1cefda 158@item C-c , M-w
3149927d
CY
159Copy the current tag into the kill ring as well as the tag ring
160(@code{senator-copy-tag}).
161
fd1cefda 162@item C-c , C-y
3149927d
CY
163Yank a tag from the tag ring (@code{senator-yank-tag}).
164
fd1cefda 165@item C-c , r
3149927d
CY
166Copy the current tag into a register
167(@code{senator-copy-tag-to-register}). With an optional argument,
168kill it as well. This allows you to insert or jump to that tag with
169the usual register commands. @xref{Registers,,,emacs,Emacs manual}.
170
fd1cefda 171@item \C-c , @kbd{up}
3149927d
CY
172Transpose the current tag with the previous one
173(@code{senator-transpose-tags-up}).
174
fd1cefda 175@item C-c , @kbd{down}
3149927d
CY
176Transpose the current tag with the next one
177(@code{senator-transpose-tags-down}).
178@end table
179
180@node SemanticDB
181@section Semantic Database
182@cindex SemanticDB
183
184The Semantic Database (SemanticDB) caches the results of parsing
185source code files. This data can be saved to disk when you exit
186Emacs, and reloaded automatically when you subsequently revisit the
187same source code files. This saves time by eliminating the need to
188re-parse unmodified files.
189
190SemanticDB also provides an @acronym{API} that programs can use to
191acquire information about source code tags. This information can be
192accessed without loading the original the source files into memory.
193It can also be used to create alternate ``back-ends'' for storing tag
194information in alternative on-disk formats.
195
196By default, SemanticDB is enabled together with Semantic mode. To
197disable it, remove it from @code{semantic-default-submodes}
198(@pxref{Semantic mode}). You can also enable or disable SemanticDB
199with @kbd{M-x global-semanticdb-minor-mode}.
200
201@deffn Command global-semanticdb-minor-mode
202Toggle SemanticDB mode. When enabled, any source code parsed by
203@semantic{} is cached in a database.
204@end deffn
205
206SemanticDB offers a large number of customizable options, which are
207described in the following subsections.
208
209@menu
210* Semanticdb Tag Storage::
211* Semanticdb Search Configuration::
212* Changing Backends::
3149927d
CY
213* Create System Databases::
214@end menu
215
216@node Semanticdb Tag Storage
217@subsection Semanticdb Tag Storage
218
219Each time you exit Emacs, any data cached by SemanticDB is saved in
220the directory @file{.emacs.d/semanticdb/}, located in your home
221directory. Within this directory, the cache data is written into a
222set of files according to a SemanticDB-specific filename convention.
223If the SemanticDB directory does not exist, Emacs first asks if you
224want to create it.
225
226You can change the name of the SemanticDB directory by customizing the
227variable @code{semanticdb-default-save-directory}.
228
229@anchor{semanticdb-default-save-directory}
230@deffn Option semanticdb-default-save-directory
231The name of the directory where SemanticDB cache files are saved. If
232the value is @code{nil}, SemanticDB saves its data into a single file,
233in the current directory, whose filename is given by
234@code{semanticdb-default-file-name}.
235@end deffn
236
237@anchor{semanticdb-default-file-name}
238@deffn Option semanticdb-default-file-name
239The name of a cache file in which to save SemanticDB, when
240@code{semanticdb-default-save-directory} is @code{nil}.
241@end deffn
242
243You can force SemanticDB to save the data from only certain files, or
244suppress saving altogether, by customizing
245@code{semanticdb-persistent-path}:
246
247@anchor{semanticdb-persistent-path}
248@deffn Option semanticdb-persistent-path
249List of valid paths for SemanticDB to cache. Each element should be a
250directory name (a string); then the parse data from any file in that
251directory is saved.
252
253As a special exception, the value of this variable can be a list
254containing a single symbol: @code{never}, @code{always}, or
255@code{project}. The symbol @code{never} disables saving anywhere;
256@code{always} enables saving everywhere; and @code{project} enables
257saving directory based on the variable
258@code{semanticdb-project-predicate-functions}.
259
260The default value is @code{(always)}.
261@end deffn
262
263@anchor{semanticdb-project-predicate-functions}
264@defvar semanticdb-project-predicate-functions
265The value of this variable is a list of predicates for indicating that
266a directory belongs to a project. This list is used when the value of
267@code{semanticdb-persistent-path} is @code{(project)}. If the list is
268empty, all paths are considered valid.
269
270Project management packages, such as EDE (@pxref{Top,,,ede,EDE
271manual}), may add their own predicates with @dfn{add-hook} to this
272variable. This allows SemanticDB to save tag caches in directories
273controlled by them.
274@end defvar
275
276@anchor{semanticdb-save-database-hooks}
277@deffn Option semanticdb-save-database-hooks
278Abnormal hook run after a database is saved. Each function is called
279with one argument, the object representing the database recently
280written.
281@end deffn
282
283@node Semanticdb Search Configuration
284@subsection Semanticdb Search Configuration
285
286 When another part of @semantic{} (or another Emacs package using
bd6f6833
CY
287@semantic{}) queries the SemanticDB library for a source code tag, the
288search need not be limited to tags defined within the current file.
289It can include tags defined elsewhere, such as @dfn{header files}
290referenced by the current file (e.g., via the C/C++ @code{#include}
291directive). While performing the search, the SemanticDB library may
292even automatically visit other files and parse them, if necessary.
293
294 The variable @code{semanticdb-find-default-throttle} determines how
295aggressively SemanticDB searches for source code tags. @xref{Search
296Throttle}.
297
298 The details of SemanticDB searches can vary from language to
299language. In C/C++ code, for example, SemanticDB distinguishes
300between @dfn{project header files} and @dfn{system header files},
301based on whether the @code{#include} directive uses the @code{""} or
302@code{<>} filename delimiter. SemanticDB looks for system header in
303the @dfn{system include path} (@pxref{Include paths}).
3149927d
CY
304
305@menu
bd6f6833 306* Search Throttle:: Controlling how semanticdb searches occur
3149927d
CY
307* Semanticdb Roots:: Specifying the root of different projects
308* Include paths:: Add/Remove directories to include search paths
3149927d
CY
309* Semanticdb search debugging commands::
310@end menu
311
bd6f6833
CY
312@node Search Throttle
313@subsubsection SemanticDB Search Throttle
314
315The SemanticDB @dfn{search throttle} determines how aggressive
316SemanticDB searches are. It is controlled by the variable
317@code{semanticdb-find-default-throttle}. The default value of this
318variable aims for maximum accuracy, at the expense of search time.
319
320Other parts of the @semantic{} package, particularly the different
321language parsers, may change the value of
322@code{semanticdb-find-default-throttle}. You can override its value,
323for a given major mode, like this:
324
325@example
326(setq-mode-local c-mode
327 semanticdb-find-default-throttle
328 '(project unloaded system recursive))
329@end example
330
331@anchor{semanticdb-find-default-throttle}
332@defvar semanticdb-find-default-throttle
333The default throttle for @code{semanticdb-find} routines.
334The throttle controls how detailed the list of database
335tables is for a symbol lookup. The value is a list with
336the following keys:
337
338@table @code
339@item file
340The file the search is being performed from. This option is here for
341completeness only, and is assumed to always be on.
342@item local
343Tables from the same local directory are included. This includes
344files directly referenced by a file name which might be in a different
345directory.
346@item project
347Tables from the same local project are included If @code{project} is
348specified, then @code{local} is assumed.
349@item unloaded
350If a table is not in memory, load it. If it is not cached on disk
351either, get the source, parse it, and create the table.
352@item system
353Tables from system databases. These are specifically tables
354from system header files, or language equivalent.
355@item recursive
356For include based searches, includes tables referenced by included
357files.
358@item omniscience
359Included system databases which are omniscience, or somehow know
360everything. Omniscience databases are found in
361@code{semanticdb-project-system-databases}. The Emacs Lisp system
362@var{db} is an omniscience database.
363@end table
364@end defvar
365
3149927d
CY
366@node Semanticdb Roots
367@subsubsection SemanticDB project roots
368
bd6f6833
CY
369The @code{project} setting in the SemanticDB search throttle
370(@pxref{Search Throttle}) tells SemanticDB to search within the
371current single code project. For @semantic{}'s point of view,
372@dfn{projects} are determined by their top-level directories, or
373@dfn{project roots}; every subdirectory of a project root is
374considered part of the same project.
375
376If you use EDE for project management, it will set the project roots
377automatically. @xref{Top,,,ede,EDE manual}. You can also specify
378them yourself.
3149927d
CY
379
380@anchor{semanticdb-project-roots}
381@deffn Option semanticdb-project-roots
382The value of this variable is a list of directories (strings) that are
bd6f6833
CY
383project roots. All subdirectories of a project root are considered
384part of the same project. This variable can be overriden by
385@code{semanticdb-project-root-functions}.
3149927d
CY
386@end deffn
387
388@anchor{semanticdb-project-root-functions}
389@defvar semanticdb-project-root-functions
390The value of this variable is a list of functions to determine a given
391directory's project root. These functions are called, one at a time,
392with one argument (the directory name), and must return either
393@code{nil}, a string (the project root), or a list of strings
394(multiple project roots, for complex systems). The first
395non-@code{nil} return value, if any, is taken to be the project root,
396overriding @code{semanticdb-project-roots}.
397@end defvar
398
3149927d
CY
399@node Include paths
400@subsubsection Include Paths
401
402System include paths are standard locations to find source code tags,
403such as the @dfn{header files} in @file{/usr/include} and its
bd6f6833
CY
404subdirectories on Unix-like operating systems.
405
406You can add and remove system include paths using the following
407commands:
3149927d
CY
408
409@anchor{semantic-add-system-include}
410@deffn Command semantic-add-system-include dir &optional mode
bd6f6833
CY
411Prompts for a directory, @var{dir}, and add it as a system include
412path for the current major mode. When called non-interactively, the
413major mode can be specified with the @var{mode} argument.
3149927d
CY
414@end deffn
415
416@anchor{semantic-remove-system-include}
417@deffn Command semantic-remove-system-include dir &optional mode
bd6f6833
CY
418Prompt for a directory, @var{dir}, and remove it from the system
419include path for the current major mode (or @var{mode}).
3149927d
CY
420@end deffn
421
422@anchor{semantic-customize-system-include-path}
423@deffn Command semantic-customize-system-include-path &optional mode
424Customize the system include path for the current major mode (or
be479117 425@var{mode}).
3149927d
CY
426@end deffn
427
428@anchor{semanticdb-implied-include-tags}
429@defun semanticdb-implied-include-tags
430Include tags implied for all files of a given mode. You can set this
431variable with @code{defvar-mode-local} for a particular mode so that
432any symbols that exist for all files for that mode are included.
433@end defun
434
435@c @xref{Search Optimization}, for more information on include paths.
436
3149927d
CY
437@node Semanticdb search debugging commands
438@subsubsection Semanticdb search debugging commands
439
bd6f6833
CY
440You can use @kbd{M-x semanticdb-dump-all-table-summary} to see the
441list of databases that will be searched from a given buffer. You can
442follow up with @kbd{M-x semanticdb-find-test-translate-path} to then
443make sure specific tables from the path are discovered correctly.
3149927d 444Alternately, you can get a list of include files @semantic{}
bd6f6833
CY
445encountered, but could not find on disk using @kbd{M-x
446semanticdb-find-adebug-lost-includes}.
3149927d
CY
447
448@deffn Command semanticdb-dump-all-table-summary
449@anchor{semanticdb-dump-all-table-summary}
450Dump a list of all databases in Emacs memory.
451@end deffn
452
3149927d 453@anchor{semanticdb-find-test-translate-path}
fd1cefda
CY
454@deffn Command semanticdb-find-test-translate-path &optional arg
455Call and output results of @dfn{semanticdb-find-translate-path}. In
456the displayed buffer, you can type @key{SPC} to expand items. With
457@var{arg} non-@code{nil}, specify a @var{brutish} translation.
3149927d
CY
458@end deffn
459
460@deffn Command semanticdb-find-adebug-lost-includes
461@anchor{semanticdb-find-adebug-lost-includes}
462Translate the current path, then display the lost includes.
463Examines the variable @code{semanticdb-find-lost-includes}.
464@end deffn
465
466Lastly, you can test an explicit search term using this command:
467
468@deffn Command semantic-adebug-searchdb regex
469@anchor{semantic-adebug-searchdb}
470Search the semanticdb for @var{regex} for the current buffer.
471Display the results as a debug list.
472@end deffn
473
474@node Changing Backends
475@subsection Changing Backends
476
477If you want to use some other form of backend, you can use this
478variable to choose which back end class to use for your general tag
479storage.
480
481The default is to save databases in flat files. Alternatively, you
482could write a new database backend that stores tags into a database,
483or other storage system.
484
3149927d 485@anchor{semanticdb-new-database-class}
bd6f6833
CY
486@defvar semanticdb-new-database-class
487The default type of database created for new files. This can be
488changed on a per file basis, so that some directories are saved using
489one mechanism, and some directories via a different mechanism.
3149927d
CY
490@end defvar
491
3149927d
CY
492@node Create System Databases
493@subsection Create System Databases
494
495If your supported language stores the system libraries in readily
496available parsable source code, you can pre-generate database files
497for them once, which will be used over and over for tools such as
498summary-mode, or the analyzer.
499
500@deffn Command semanticdb-create-ebrowse-database dir
501@anchor{semanticdb-create-ebrowse-database}
502Create an @var{ebrowse} database for directory @var{dir}.
503The database file is stored in ~/.semanticdb, or whichever directory
504is specified by @code{semanticdb-default-system-save-directory}.
505@end deffn
506
3149927d
CY
507@node Idle Scheduler
508@section Idle Scheduler
509@cindex Idle Scheduler
510
bd6f6833
CY
511The @dfn{Semantic idle scheduler} is a part of @semantic{} that
512performs various operations while Emacs is waiting for user input
513(idle time). Its primary job is to perform buffer parsing, but it is
514also used for other purposes, such as displaying information about
515tags.
3149927d 516
3149927d 517@anchor{global-semantic-idle-scheduler-mode}
bd6f6833
CY
518@deffn Command global-semantic-idle-scheduler-mode &optional arg
519This command toggles Semantic Idle Scheduler mode in every
520@semantic{}-enabled buffer. This minor mode ensures that the buffer
521is automatically reparsed whenever Emacs is idle. If there is
522additional idle time, it runs jobs scheduled by other parts of
523@semantic{}, such as Semantic Idle Summary mode (@pxref{Idle Summary
524Mode}) and Semantic Idle Completions mode (@pxref{Idle Completions
525Mode}).
3149927d
CY
526@end deffn
527
3149927d 528@anchor{semantic-idle-scheduler-idle-time}
bd6f6833
CY
529@deffn Option semantic-idle-scheduler-idle-time
530The value of this variable is the amount of idle time, in seconds,
531before the Semantic idle scheduler activates. The default is 1.
3149927d
CY
532@end deffn
533
3149927d 534@anchor{semantic-idle-scheduler-verbose-flag}
bd6f6833
CY
535@deffn Option semantic-idle-scheduler-verbose-flag
536If this variable is non-@code{nil}, the idle scheduler prints verbose
537messages while running, which are useful for debugging.
3149927d
CY
538@end deffn
539
3149927d 540@menu
bd6f6833
CY
541* Reparsing Options:: Reparsing the current buffer in idle time
542* Idle Working Options:: Options for extra work done at idle time
543* Debugging Idle Time Issues:: How to produce good bug reports
544* Idle Summary Mode:: Display prototype of symbol under cursor
545* Idle Completions Mode:: Smart completion pop-up help
3149927d
CY
546@end menu
547
548@node Reparsing Options
549@subsection Reparsing Options
550
bd6f6833
CY
551When activated during idle time, the Semantic idle scheduler
552automatically reparses all buffers that need it. Any arriving user
553input cancels this, returning Emacs to its normal editing behavior.
3149927d 554
3149927d 555@anchor{semantic-idle-scheduler-max-buffer-size}
bd6f6833
CY
556@deffn Option semantic-idle-scheduler-max-buffer-size
557Maximum size in bytes of buffers automatically reparsed. If this
558value is less than or equal to @var{0}, buffers are automatically
3149927d
CY
559reparsed regardless of their size.
560@end deffn
561
3149927d 562@anchor{semantic-idle-scheduler-no-working-message}
bd6f6833
CY
563@deffn Option semantic-idle-scheduler-no-working-message
564If non-@code{nil}, disable display of working messages whie reparsing.
3149927d
CY
565@end deffn
566
3149927d 567@anchor{semantic-idle-scheduler-working-in-modeline-flag}
bd6f6833
CY
568@deffn Option semantic-idle-scheduler-working-in-modeline-flag
569If non-@code{nil}, show working messages in the mode line. Normally,
570re-parsing shows messages in the minibuffer; this moves the parse
571message to the modeline instead.
3149927d
CY
572@end deffn
573
bd6f6833
CY
574@anchor{semantic-before-idle-scheduler-reparse-hook}
575@defvar semantic-before-idle-scheduler-reparse-hook
576This normal hook is run just before the idle scheduler begins
577reparsing. If any hook function throws an error, the value of this
578variable is reset to @code{nil}. This hook is not protected from
579lexical errors.
3149927d
CY
580@end defvar
581
bd6f6833
CY
582@anchor{semantic-after-idle-scheduler-reparse-hook}
583@defvar semantic-after-idle-scheduler-reparse-hook
584
585This normal hook is run after the idle scheduler finishes reparsing.
586If any hook throws an error, this variable is reset to @code{nil}.
3149927d
CY
587This hook is not protected from lexical errors.
588@end defvar
589
590@node Idle Working Options
591@subsection Idle Working Options
592
673286f5
CY
593In addition to reparsing buffers, the Semantic idle scheduler performs
594additional operations, including the following:
3149927d 595
673286f5
CY
596@itemize
597@item
598Creating the include path caches required for symbol lookup.
599@item
600Create data type caches.
601@item
602Saving SemanticDB caches to disk.
603@item
604Speculatively parsing the files in the same directory as the current
605buffer.
606@end itemize
607
608Because this extra work is quite time-consuming, it is only carried
609out after a longer idle delay. The following features control how the
610idle work is performed.
3149927d 611
3149927d 612@anchor{semantic-idle-scheduler-work-idle-time}
673286f5
CY
613@deffn Option semantic-idle-scheduler-work-idle-time
614The value of this variable is the amount of idle time, in seconds,
615before commencing idle work. The default is 60.
3149927d
CY
616@end deffn
617
3149927d 618@anchor{semantic-idle-work-parse-neighboring-files-flag}
673286f5
CY
619@deffn Option semantic-idle-work-parse-neighboring-files-flag
620If the value of this variable is non-@code{nil}, the Semantic idle
621scheduler uses idle work time to parse files in the same directory as
622the current buffer. This improves the accuracy of tag searches and
623saves time when visiting those files later, at the cost of doing a lot
624of parsing. The default is @code{t}.
3149927d
CY
625@end deffn
626
627@node Debugging Idle Time Issues
628@subsection Debugging Idle Time Issues
629
673286f5
CY
630If you see an error signalled during idle time, it could be an
631indication of a more serious issue elsewhere. It is not enough to
632enable @code{debug-on-error}, because the idle scheduler inhibits the
633debugger. Instead, use the following commands to debug the error:
3149927d
CY
634
635@deffn Command semantic-debug-idle-function
636@anchor{semantic-debug-idle-function}
637Run the Semantic idle function with debugging turned on.
638@end deffn
639
640@deffn Command semantic-debug-idle-work-function
641@anchor{semantic-debug-idle-work-function}
642Run the Semantic idle work function with debugging turned on.
643@end deffn
644
3149927d
CY
645@node Idle Summary Mode
646@subsection Idle Summary Mode
647
673286f5
CY
648Semantic Idle Summary mode is a minor mode that displays a short
649summary of the symbol at point, such as its function prototype, in the
650echo area. Its functionality is similar to what ElDoc mode provides
651for Emacs Lisp (@pxref{Lisp Doc,,,emacs,Emacs manual}).
3149927d 652
673286f5 653@anchor{global-semantic-idle-summary-mode}
3149927d 654@anchor{semantic-idle-summary-mode}
673286f5
CY
655@deffn global-semantic-idle-summary-mode &optional arg
656This command toggles Semantic Idle Summary mode in all
657@semantic{}-enabled buffers. You can also toggle it via the
658@samp{Show Tag Summaries} menu item in the @samp{Development} menu.
3149927d
CY
659@end deffn
660
673286f5
CY
661When Semantic Idle Summary mode is active, a summary of the tag at
662point is displayed in the echo area. This display takes place during
663the idle time, as given by @code{semantic-idle-scheduler-idle-time}
664(@pxref{Idle Scheduler}).
665
666You can override the method for getting the current tag to display by
667setting @code{idle-summary-current-symbol-info}.
3149927d 668
3149927d 669@anchor{semantic-idle-summary-function}
673286f5
CY
670@deffn Option semantic-idle-summary-function
671The value of this variable should be a function to call to display tag
672information during idle time. See the variable
673@code{semantic-format-tag-functions} for a list of useful functions.
3149927d
CY
674@end deffn
675
3149927d 676@anchor{semantic-idle-summary-out-of-context-faces}
673286f5
CY
677@defvar semantic-idle-summary-out-of-context-faces
678The value of this variable is a list of font-lock faces indicating
679useless summary contexts. These are generally faces used to highlight
680comments or strings. Semantic Idle Summary mode does not display its
681usual summary if the text at point has one of these faces.
3149927d
CY
682@end defvar
683
684@node Idle Completions Mode
685@subsection Idle Completions Mode
686
673286f5
CY
687Semantic Idle Completions mode is a minor mode for performing
688@dfn{code completions} during idle time. The completions are
689displayed inline, with keybindings that allow you to cycle through
690different alternatives.
3149927d 691
fd1cefda
CY
692Semantic Idle Completions mode performs completion based on the
693Semantic Analyzer (@pxref{Analyzer}).
3149927d 694
673286f5 695@anchor{global-semantic-idle-completions-mode}
3149927d 696@anchor{semantic-idle-completions-mode}
673286f5
CY
697@deffn global-semantic-idle-completions-mode &optional arg
698This command toggles Semantic Idle Completions mode in every
699@semantic{}-enabled buffer. You can also toggle it via the @samp{Show
700Tag Completions} menu item in the @samp{Development} menu.
3149927d
CY
701@end deffn
702
673286f5
CY
703If the tag at point has at least one completion, Semantic Idle
704Completions mode displays that completion inline---i.e., as part of
705the buffer text (you can change the display method by customizing
706@code{semantic-complete-inline-analyzer-idle-displayor-class}, as
707described below). The completed part is highlighted, to indicate that
708it is not yet properly inserted into the buffer. The echo area shows
709the completion, and whether there are other possible completions, like
710this:
3149927d 711
673286f5
CY
712@example
713besselj [1 of 6 matches]
714@end example
715
716@noindent
717While the completion is being displayed, the following keybindings
718take effect:
719
720@table @kbd
721@item @key{RET}
722@itemx C-m
723Accept the current completion (@code{semantic-complete-inline-done}),
724placing it in the buffer and moving point to the end of the completed
725tag.
726@item M-n
727Select the next possible completion
728(@code{semantic-complete-inline-down}). The new completion is shown
729inline, replacing the old completion.
730@item M-p
731Select the previous possible completion
732(@code{semantic-complete-inline-up}).
733@item @key{TAB}
734@item C-i
735Accept as much of the completion as possible. If no additional
736completion can be accepted without ambiguity, select the next possible
737completion (@code{semantic-complete-inline-TAB}).
738@item C-g
739Quit without completing (@code{semantic-complete-inline-quit}).
740@end table
741
742@noindent
743You can also exit inline completion by issuing any other Emacs
744command. The completion text then disappears from the buffer.
3149927d 745
3149927d 746@anchor{semantic-complete-analyze-inline-idle}
673286f5
CY
747@deffn Command semantic-complete-analyze-inline-idle
748This is the command for performing inline code completion. It is
749called by Semantic Idle Completions mode during idle time, but you can
750also call it yourself. It returns immediately, leaving the buffer in
751a state for inline completion.
3149927d
CY
752@end deffn
753
3149927d 754@anchor{semantic-complete-inline-analyzer-idle-displayor-class}
673286f5
CY
755@deffn Option semantic-complete-inline-analyzer-idle-displayor-class
756The value of this variable determines how
757@code{semantic-complete-analyze-inline-idle} shows its completions.
758Possible values include:
3149927d 759
673286f5
CY
760@table @code
761@item semantic-displayor-ghost
762Display completions ``inline'' with the buffer text, as described
763above. This is the default value.
764
765@item semantic-displayor-tooltip
766Display completions in a tooltip.
767
768@item semantic-displayor-traditional
769Display completions in a separate window.
770@end table
3149927d 771@end deffn
fd1cefda
CY
772
773@node Analyzer
774@section Analyzer
775@cindex Analyzer
776
777The Semantic Analyzer is a library for performing context analysis on
778source code. It provides user commands for displaying, completing,
779and navigating through source code.
780
781@menu
782* Smart Completion:: Performing code completion.
783* Smart Summary:: Displaying help on a symbol.
784* Smart Jump:: Jumping to the definition of a tag.
785* Analyzer Debug:: Debugging problems with the analyzer.
786@end menu
787
788@node Smart Completion
789@subsection Smart Completion
790
791The Semantic Analyzer can be used to perform code completion in a
792manner that takes the local context into account.
793
794In addition to the user commands documented in this section, the
795completions performed by Semantic Idle Completions mode also uses the
796Semantic Analyzer. @xref{Idle Completions Mode}.
797
798@deffn Command semantic-analyze-possible-completions context
799This is the most basic command for Semantic Analyzer-based completion.
800Called interactively, it displays in another window a list of the
801possible completions for the symbol at point.
802
803When called from a Lisp program,
804@code{semantic-analyze-possible-completions} does not display a
805completions list. The argument @var{context} should be either a
806buffer position, or a context object. The return value is a list of
807@semantic{} tag objects that complete the symbol for @var{context},
808based on the following criteria:
809
810@itemize
811@item Elements currently in scope.
812@item Constants currently in scope.
813@item Elements matching the context's @code{:prefix}.
814@item Type of the completion matching the type of the context.
815@end itemize
816
817Most of the other commands documented in this section call
818@code{semantic-analyze-possible-completions} internally.
819@end deffn
820
821@anchor{semantic-complete-analyze-inline}
822@deffn Command semantic-complete-analyze-inline
823This command is bound to @kbd{C-c , @key{SPC}} when Semantic mode is
824enabled (@pxref{Semantic mode user commands}). It displays a list of
825possible completions for the symbol at point, and activates a special
826set of keybindings for choosing a completion.
827
828You can type @key{RET} to accept the current completion, @kbd{M-n} and
829@kbd{M-p} to cycle through the possible completions, @key{TAB} to
830complete as far as possible and then cycle through completions, and
831either @kbd{C-g} or any other key to abort the completion.
832
833This command is similar to the completion performed by Semantic Idle
834Completions mode. The main difference is that it is called
835explicitly, whereas Semantic Idle Completions mode completes during
836idle time (@pxref{Idle Completions Mode}).
837@end deffn
838
839@anchor{semantic-complete-inline-analyzer-displayor-class}
840@deffn Option semantic-complete-inline-analyzer-idle-displayor-class
841The value of this variable determines how
842@code{semantic-complete-analyze-inline} shows its completions.
843Possible values include:
844
845@table @code
846@item semantic-displayor-traditional
847Display completions in a separate window. This is the default value.
848
849@item semantic-displayor-ghost
850Display completions ``inline'' with the buffer text, similar to the
851default behavior of Semantic Idle Completions mode (@pxref{Idle
852Completions Mode}).
853
854@item semantic-displayor-tooltip
855Display completions in a tooltip.
856@end table
857@end deffn
858
859In addition to @code{semantic-complete-analyze-inline}, you can use
860the simpler command @code{semantic-ia-complete-symbol point}. This
861behaves like the usual @kbd{M-@key{TAB}} (@code{complete-symbol})
862command (@pxref{Symbol Completion,,,emacs,Emacs manual}), except it
863uses Semantic Analyzer.
864
865@anchor{semantic-ia-complete-symbol}
866@deffn Command semantic-ia-complete-symbol point
867Complete the current symbol at @var{point}.
868@end deffn
869
870@node Smart Summary
871@subsection Smart Summary
872
873You can use the commands in this section to find information about the
874code at point:
875
876@anchor{semantic-ia-show-summary}
877@deffn Command semantic-ia-show-summary pos
878Display a summary for the symbol at @var{pos}. Called interactively,
879@var{pos} defaults to point.
880@end deffn
881
882@anchor{semantic-ia-show-doc}
883@deffn Command semantic-ia-show-doc pos
884Display the code-level documentation for the symbol at @var{pos}.
885Called interactively, @var{pos} defaults to point.
886@end deffn
887
888@anchor{semantic-ia-describe-class}
889@deffn Command semantic-ia-describe-class typename
890Prompt for the name of a data type, @var{typename}, and display its
891components. For instance, if the type in question is a class, this
892displays the methods and member variables.
893@end deffn
894
895You can also use Semantic Idle Summary mode to show information about
896the current symbol in the echo area during idle time. @xref{Idle
897Summary Mode}.
898
899@node Smart Jump
900@subsection Smart Jump
901
902The Semantic Analyzer can be used to jump directly to the definition
903for a code symbol. Because it is based on code analysis, its behavior
904is often more accurate than than the @code{find-tag} command
905(@pxref{Tags,,,emacs,Emacs manual}).
906
907@anchor{semantic-ia-fast-jump}
908@deffn Command semantic-ia-fast-jump pos
909Jump to the definition for the symbol at @var{pos}. Called
910interactively, @var{pos} defaults to point.
911@end deffn
912
913@anchor{semantic-ia-fast-mouse-jump}
914@defun semantic-ia-fast-mouse-jump event
915Jump to the definition for the symbol at the position of the mouse
916event @var{event}. This command is meant to be bound to a mouse
917command, like this:
918
919@example
920(global-set-key '[(S-mouse-1)] semantic-ia-fast-mouse-jump)
921@end example
922@end defun
923
924You can also use @kbd{C-c , j} (@code{semantic-complete-jump-local})
925and @kbd{C-c , J} (@code{semantic-complete-jump}) to navigate tags.
926@xref{Semantic mode user commands}. Those commands do not make use of
927the Semantic Analyzer.
928
929@node Analyzer Debug
930@subsection Debugging the Semantic Analyzer
931
932In the event that the Semantic Analyzer does not analyze your code
933properly, you can take steps to identify and solve the problem. This
934section was written with C/C++ in mind, but should be relevant for any
935typed language.
936
937@subsubsection Step 1: Check the context
938
939The first thing to do is check the current context. You can do this
940with @kbd{M-x semantic-analyze-current-context}.
941
942@deffn Command semantic-analyze-current-context pos
943Analyze the context at @var{pos}. This function is used by most of
944the other Semantic Analyzer commands to obtain the context of the code
945at a given buffer position. The return value is an EIEIO object
946describing the context at @var{pos} (@pxref{Top,,,eieio,EIEIO
947manual}).
948
949When called interactively, this displays a @samp{*Semantic Context
950Analysis*} buffer in a separate window. This buffer contains a
951summary of the context at point.
952@end deffn
953
954The Prefix section of the @samp{*Semantic Context Analysis*} buffer
955lists the tags based on the text at point. If it shows only a simple
956string, the Semantic was unable to identify what the data type was.
957
958The first item in the list of the prefix is the first lookup failure
959in the chain, and that is the item to focus debugging effort on. For
960example:
961
962@example
963Context Type: #<semantic-analyze-context context>
964Bounds: (182 . 185)
965Prefix: Foo* bar
966 int bbb (const char* y)
967Prefix Types: class Foo @{@}
968--------
969-> Local Vars: int argc
970 char** argv
971@end example
972
973In this example you can see that the prefix has two fully found tags.
974In the following example, the symbol ``bbb'' is incomplete, and could
975not be found:
976
977@example
978Context Type: #<semantic-analyze-context context>
979Bounds: (182 . 184)
980Prefix: Foo* bar
981 "bb"
982Prefix Classes: 'function
983 'variable
984Prefix Types: class Foo @{@}
985--------
986-> Local Vars: int argc
987 char** argv
988@end example
989
990@subsubsection Step 2 : Check your include path
991
992Once you know what symbol can't be found, the next thing to check is
993your include path. Is the header or include file that has the
994definitions you need actually in the list of headers @semantic{} is
995searching through? To get a basic list, you can use @kbd{M-x
996semanticdb-find-test-translate-path}. @xref{Semanticdb search
997debugging commands}.
998
999For C++, check to make sure that your project level include files are
1000in quotes, and not angle brackets. Items in angle brackets are system
1001includes.
1002
1003If items should be loaded but aren't, you may need to update the
1004search throttle. @xref{Search Throttle}. If you see some tables that
1005have 0 tags in them, then you you may have an incorrectly set
1006throttle. For example,
1007
1008@example
1009*#<semanticdb-table main.cpp (4 tags DIRTY)>
1010*#<semanticdb-table foo.hh (0 tags DIRTY)>
1011@end example
1012
1013Here, @semantic{} found @file{foo.hh}, but there are 0 tags. This may
1014be because the throttle was set to not read in and parse files that
1015Emacs has not yet loaded in. To fix this case, visit the file, and
1016let @semantic{} parse and save the tags table.
1017
1018@subsubsection Step 3: Check the local scope
1019
1020If your data type is somehow abbreviated based on scope, such as from
1021a @code{using} statement, you should make sure that the symbol you
1022want is in the local scope. Examine the scope with @kbd{M-x
1023semantic-calculate-scope}. The scope structure is displayed in ADEBUG
1024mode, so use @kbd{SPC} to expand different elements and looking for
1025your symbol.
1026
1027If your symbol should be in the scope, but you cannot find it, then
1028you may have found a language support bug in the local-variable
1029parser, or using statement parser.
1030
1031Calling @kbd{M-x bovinte} should force a reset on the scope in case
1032there is merely some bad state.
1033
1034@example
1035 ] Name: Cache
1036 ] Class: #'semantic-scope-cache
1037 ] :table #<semanticdb-table testsubclass.cpp (13 tags DIRTY)>
1038 ] tag createMoose : class moose
1039 ] scopetypes 'nil
1040 ] parents #<TAG LIST: 1 entries>
1041 ] scope #<TAG LIST: 22 entries>
1042 ] fullscope #<TAG LIST: 23 entries>
1043 ] localvar #<TAG LIST: 6 entries>
1044@end example
1045
1046In the above sample output, the @code{tag} slot specifies where within
1047you source this scope is relevant. @code{Parents} should contain any
1048in scope parents, such as the class a method belongs to.
1049@code{Localvar} should contain your local variables. @code{Scope}
1050should contain datatypes in scope due to a @code{using} statement or
1051the like.
1052
1053@subsubsection Step 4: Check the typecache
1054
1055For complex typed languages like C++, @semantic{} creates a typecache,
1056or an optimized search table with all the various data types in it.
1057Elements in the typecache do not obey local scope. It only contains
1058fully qualified names. You can examine the typecache with
1059@kbd{M-x semanticdb-typecache-dump}.
1060
1061If your data types are not in the typecache, there may be some parsing
1062error or other bug. Calling @kbd{M-x bovinte} should force a reset on
1063the typecache in case there is merely some bad state.
1064
1065@example
1066]#<semanticdb-typecache /home/zappo/cedet/semantic/tests/testsubclass.cpp>
1067 ] Name: /home/zappo/cedet/semantic/tests/testsubclass.cpp
1068 ] Class: #'semanticdb-typecache
1069 ] filestream 'nil
1070 ] includestream #<TAG LIST: 84 entries>
1071 ] stream 'nil
1072 ] dependants 'nil
1073@end example
1074
1075In the above example, the output of @kbd{M-x semanticdb-typecache-dump}
1076was expanded one level. The @code{filestream} slot should contain
1077datatypes in the current file. The @code{includestream} should
1078contain all the datatypes in all included header files.
1079
1080The @code{dependants} slot will specify other files that depend on
1081this one.
1082
1083@section Step 5: Check the parser
1084
1085Go to the location where your unfound tag should be. You can call
1086@kbd{M-x bovinate}, and see a dump of the raw tag structure. To see a
1087navigable tree, use @kbd{M-x semantic-adebug-bovinate} instead. You
1088can then look to make sure your tag has been properly parsed.
1089
1090If it has not, then you may have found a parser bug. To get a feel
1091how @semantic{} treats your file, type @kbd{M-x
1092global-semantic-show-unmatched-syntax-mode}. This causes any syntax
1093it cannot parse to be underlined in red.
1094
1095If your type is not parsable, it could be for a couple of reasons:
1096
1097@enumerate
1098@item
1099If there is a MACRO keyword used in the definition of the type, you
1100may need to update the @code{semantic-lex-c-preprocessor-symbol-map}
1101to account for it.
1102
1103@item
1104Or perhaps the parser needs to be fixed.
1105@end enumerate