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