Initial Commit
[packages] / xemacs-packages / semantic / doc / user-guide.texi
1 \input texinfo  @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename semantic-user.info
4 @set TITLE  Semantic User's Guide
5 @set AUTHOR Eric M. Ludlam, David Ponce, and Richard Y. Kim
6 @settitle @value{TITLE}
7
8 @c *************************************************************************
9 @c @ Header
10 @c *************************************************************************
11
12 @c Merge all indexes into a single index for now.
13 @c We can always separate them later into two or more as needed.
14 @syncodeindex vr cp
15 @syncodeindex fn cp
16 @syncodeindex ky cp
17 @syncodeindex pg cp
18 @syncodeindex tp cp
19
20 @c @footnotestyle separate
21 @c @paragraphindent 2
22 @c @@smallbook
23 @c %**end of header
24
25 @copying
26 This is the Semantic User's Manual
27
28 Copyright @copyright{} 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Eric M. Ludlam
29 Copyright @copyright{} 2001, 2002, 2003, 2004 David Ponce
30 Copyright @copyright{} 2002, 2003 Richard Y. Kim
31
32 @quotation
33 Permission is granted to copy, distribute and/or modify this document
34 under the terms of the GNU Free Documentation License, Version 1.1 or
35 any later version published by the Free Software Foundation; with the
36 Invariant Sections being list their titles, with the Front-Cover Texts
37 being list, and with the Back-Cover Texts being list.  A copy of the
38 license is included in the section entitled ``GNU Free Documentation
39 License''.
40 @end quotation
41 @end copying
42
43 @ifinfo
44 @dircategory Emacs
45 @direntry
46 * Semantic User's guide: (semantic-user).
47 @end direntry
48 @end ifinfo
49
50 @iftex
51 @finalout
52 @end iftex
53
54 @c @setchapternewpage odd
55 @c @setchapternewpage off
56
57 @ifinfo
58 This is the Semantic User's Guide
59 @emph{Infrastructure for parser based text analysis in Emacs}
60
61 Copyright @copyright{} 1999, 2000, 2001, 2002, 2003, 2004 @value{AUTHOR}
62 @end ifinfo
63
64 @titlepage
65 @sp 10
66 @title @value{TITLE}
67 @author by @value{AUTHOR}
68 @vskip 0pt plus 1 fill
69 Copyright @copyright{} 1999, 2000, 2001, 2002, 2003, 2004 @value{AUTHOR}
70 @page
71 @vskip 0pt plus 1 fill
72 @insertcopying
73 @end titlepage
74 @page
75
76 @c MACRO inclusion
77 @include semanticheader.texi
78
79 @c *************************************************************************
80 @c @ Document
81 @c *************************************************************************
82 @contents
83
84 @node top
85 @top @value{TITLE}
86
87 This chapter describes how to use @b{applications} enabled by
88 semantic.
89 Many of these come with semantic, but others are distributed apart
90 from semantic.
91
92 @menu
93 * speedbar::                    How to use Semantic speedbar support
94 * ECB::                         Emacs Code Browser
95 * imenu::                       Special support for Imenu.
96 * senator::                     The Semantic Navigator
97 * Analyzer::                    Analyze local context
98 * Class Browser::               Class hierarchy browser
99 * Document::                    Document generation functions
100 * Charts::                      Charting code statistics
101 * Idle Scheduler::              The idle Scheduler and related modes
102 * Minor Modes::                 Useful minor modes
103 * semanticdb::                  Cache your parsed buffers between sessions.
104 * Speed Debug::                 How to debug speed issues.
105 * Customizing::                 
106 * GNU Free Documentation License::  
107 * Index::                       
108 @end menu
109
110 @node speedbar
111 @chapter speedbar
112 @cindex speedbar
113
114 Speedbar supports the display of tags through the Semantic parser.  To
115 use this utility, add a line like this to your @file{.emacs} file:
116
117 @example
118 (add-hook 'speedbar-load-hook (lambda () (require 'semantic-sb)))
119 @end example
120
121 or you can simply add:
122
123 @example
124 (require 'semantic-sb)
125 @end example
126
127 Once installed, speedbar will use semantic to find tags, and will
128 display them appropriately.  Tags from semantic will have additional
129 details which can be seen, such as return type, or arguments to
130 functions.
131
132 If you use @file{semantic-load.el}, you do not need to add the above
133 lines in your @file{.emacs} file.
134
135 Two additional speedbar modes are described in @ref{Speedbar Analysis}, and
136 @ref{Class Browser}.
137
138 @node ECB
139 @chapter ECB
140 @cindex ECB
141
142 From the ECB Website: @url{http://ecb.sourceforge.net}:
143
144 @example
145 ECB is a source code browser for Emacs. It is a global minor-mode
146 which displays a couple of windows that can be used to browse
147 directories, files and file-contents like methods and variables.
148 @end example
149
150
151 @node imenu
152 @chapter imenu
153 @cindex imenu
154
155 There is special support for creating Imenu entries using semantic.
156 This is a highly customizable tool which can create specialized menu
157 systems for navigating your source file.
158
159 By default, each language that wants special imenu support will set
160 itself up for it.  To setup imenu for your buffers, use this command
161 in your @file{.emacs} file:
162
163 @example
164 (add-hook 'semantic-init-hooks (lambda ()
165                                    (imenu-add-to-menubar "TAGS")))
166 @end example
167
168 Also supported is @dfn{which-func-mode}.  This usually uses imenu
169 tags to show the current function.  The semantic support for this
170 function uses overlays, which is much faster.
171
172 If you use @file{semantic-load.el}, you do not need to add the above
173 lines in your @file{.emacs} file.
174
175 You can customize imenu with the following options:
176
177 @deffn Option semantic-imenu-summary-function
178 Function to use when creating items in Imenu.
179 Some useful functions are found in @code{semantic-format-tag-functions}.
180 @end deffn
181
182 @deffn Option semantic-imenu-bucketize-file
183 Non-@code{nil} if tags in a file are to be grouped into buckets.
184 @end deffn
185
186 @deffn Option semantic-imenu-buckets-to-submenu
187 Non-@code{nil} if buckets of tags are to be turned into submenus.
188 This option is ignored if @code{semantic-imenu-bucketize-file} is nil.
189 @end deffn
190
191 @deffn Option semantic-imenu-expand-type-members
192 Non-@code{nil} if types should have submenus with members in them.
193 @end deffn
194
195 @deffn Option semantic-imenu-bucketize-type-members
196 Non-@code{nil} if members of a type should be grouped into buckets.
197 @code{nil} means to keep them in the same order.
198 Overriden to @code{nil} if @code{semantic-imenu-bucketize-file} is nil.
199 @end deffn
200
201 @deffn Option semantic-imenu-sort-bucket-function
202 Function to use when sorting tags in the buckets of functions.
203 See @dfn{semantic-bucketize} and the @var{FILTER} argument for more details on this function.
204 @end deffn
205
206 @deffn Option semantic-imenu-index-directory
207 Non @code{nil} to index the entire directory for tags.
208 Doesn't actually parse the entire directory, but displays tags for all files
209 currently listed in the current Semantic database.
210 This variable has no meaning if semanticdb is not active.
211 @end deffn
212
213 @deffn Option semantic-imenu-auto-rebuild-directory-indexes
214 If non-@code{nil} automatically rebuild directory index imenus.
215 That is when a directory index imenu is updated, automatically rebuild
216 other buffer local ones based on the same semanticdb.
217 @end deffn
218
219 When adding support to a language, this variable may need to be set:
220
221 @defvar semantic-imenu-expandable-tag-classes
222 @anchor{semantic-imenu-expandable-tag-classes}
223 List of expandable tag classes.
224 Tags of those classes will be given submenu with children.
225 By default, a @code{type} has interesting children.  In Texinfo, however, a
226 @code{section} has interesting children.
227 @end defvar
228
229 @node senator
230 @chapter senator
231 @cindex senator
232
233 Senator stands for SEmantic NAvigaTOR and was written by David Ponce.
234
235 This library defines commands and a minor mode to navigate and manage
236 semantic language tags in the current buffer.
237
238 @section Commands
239
240 The following user level commands are provided by Senator.
241
242 @subsection Navigation
243
244 @defun senator-next-tag
245 Navigate to the next Semantic tag.
246 Return the tag or @code{nil} if at end of buffer.
247 @end defun
248
249 @defun senator-previous-tag
250 Navigate to the previous Semantic tag.
251 Return the tag or @code{nil} if at beginning of buffer.
252 @end defun
253
254 @defun senator-jump
255 Jump to the semantic symbol @var{SYM}.
256
257 If optional @var{IN-CONTEXT} is non-@code{nil} jump in the local type's context
258 (see function @dfn{senator-current-type-context}).  If optional
259 @var{NO-DEFAULT} is non-@code{nil} do not provide a default value.
260
261 When called interactively you can combine the @var{IN-CONTEXT} and
262 @var{NO-DEFAULT} switches like this:
263
264 - @kbd{C-u}       @var{IN-CONTEXT}.
265 - @kbd{C-u} -     @var{NO-DEFAULT}.
266 - @kbd{C-u} @kbd{C-u}   @var{IN-CONTEXT} + @var{NO-DEFAULT}.
267 @end defun
268
269 @subsection Searching
270
271 Searching using senator mode restricts the search only to the
272 definition text, such as the name of the functions or variables in a
273 given buffer.
274
275 @deffn Command senator-isearch-toggle-semantic-mode
276 Toggle semantic searching on or off in isearch mode.
277 @kbd{C-c , i} toggle semantic searching.
278 @end deffn
279
280 @deffn Command senator-search-forward what &optional bound noerror count
281 @deffnx Command senator-search-backward what &optional bound noerror count
282 Search semantic tags forward or backward from point for string @var{WHAT}.
283 Set point to the end of the occurrence found, and return point.  See
284 @dfn{search-forward} for details and the meaning of @var{BOUND} @var{NOERROR} and
285 @var{COUNT}.  @var{COUNT} is just ignored in the current implementation.
286 @end deffn
287
288 @deffn Command re-search-forward regex
289 @deffnx Command re-search-backward regex
290 Search forward and backward for a token matching the regular expression
291 @var{regex}.
292 @end deffn
293
294 @deffn Command word-search-forward word
295 @deffnx Command word-search-backward word
296 Search forward and backward for a token whose name matches @var{word}.
297 @end deffn
298
299 @subsection Completion
300
301 Completion in senator scans all known definitions in the local file,
302 and uses that information to provide the completion.
303
304 @deffn Command senator-complete-symbol &optional cycle-once
305 Complete the current symbol under point.
306 If optional argument @var{CYCLE-ONCE} is non-@code{nil}, only cycle through the list
307 of completions once, doing nothing where there are no more matches.
308 @end deffn
309
310 @deffn Command senator-completion-menu-popup
311 Popup a completion menu for the symbol at point.
312 The popup menu displays all of the possible completions for the symbol
313 it was invoked on.  To automatically split large menus this function
314 use @dfn{imenu--mouse-menu} to handle the popup menu.
315 @end deffn
316
317 @subsection Copy/Paste
318
319 Token Copy/Paste is a high level form of the typical copy yank used by
320 Emacs.  Copying a tag saves the meta-information related to the
321 function or item the cursor is currently in.  When that information is
322 yanked into a new buffer, the form of the text created is based on the
323 current status of the programming buffer.
324
325 For example, pasting a function into a different file results in a
326 function call template to be inserted.  In a Texinfo file, a @@deffn
327 is created with documentation for that function or command.
328
329 @deffn Command senator-copy-tag
330 Take the current tag, and place it in the tag ring.
331 @end deffn
332
333 @deffn Command senator-kill-tag
334 Take the current tag, place it in the tag ring, and kill it.
335 Killing the tag removes the text for that tag, and places it into
336 the kill ring.  Retrieve that text with @kbd{C-y}.
337 @end deffn
338
339 @deffn Command senator-yank-tag
340 Yank a tag from the tag ring.
341 The form the tag takes is differnet depending on where it is being
342 yanked to.
343 @end deffn
344
345 @deffn Command senator-copy-tag-to-register register &optional kill-flag
346 Copy the current tag into @var{REGISTER}.
347 Optional argument @var{KILL-FLAG} will delete the text of the tag to the
348 kill ring.
349 @end deffn
350
351 For programmers, to provide specialized pasting, created an override
352 function for @code{insert-foreign-tag} (see @inforef{Writing Parsers, , semantic-langdev}.)
353
354 @subsection Minor Mode
355
356 @deffn Command senator-minor-mode
357 Toggle the SEmantic NAvigaTOR key bindings in the current buffer.
358
359 The following default key bindings are provided when semantic minor
360 mode is enabled:
361
362
363 @table @key
364 @item C-c , n
365 senator-next-tag
366 @item C-c , p
367 senator-previous-tag
368 @item C-c , i
369 senator-isearch-toggle-semantic-mode
370 @item C-c , j
371 semantic-complete-jump-local
372 @item C-c , J
373 semantic-complete-jump
374 @item C-c , TAB
375 senator-complete-symbol
376 @item C-c , SPC
377 senator-completion-menu-popup
378 @item C-c , C-y
379 senator-yank-tag
380 @item C-c , C-w
381 senator-kill-tag
382 @item C-c , M-w
383 senator-copy-tag
384 @item C-c , +
385 senator-unfold-tag
386 @item C-c , -
387 senator-fold-tag
388 @end table
389 @end deffn
390
391 @section Customization
392
393 To enable the Senator keymap in all modes that support semantic parsing,
394 use this:
395
396 @example
397 (add-hook 'semantic-init-hooks 'senator-minor-mode)
398 @end example
399
400 If you use @file{semantic-load.el}, you do not need to add the above
401 lines in your @file{.emacs} file.
402
403 To customize navigation around different types of tokens, use the
404 following variables:
405
406 @deffn Option senator-step-at-tag-classes
407 List of tag classes where to step.
408 A tag class is a symbol like @code{'variable}, @code{'function}, @code{'type}, or other.
409 If @code{nil} navigation steps at any tag found.  This is a buffer local
410 variable.  It can be set in a mode hook to get a specific langage
411 navigation.
412 @end deffn
413
414 @deffn Option senator-step-at-start-end-tag-classes
415 List of tag classes where to step at start and end.
416 A tag class is a symbol like @code{'variable}, @code{'function}, @code{'type}, or other.
417 If @code{nil}, navigation only step at beginning of tags.  If @code{t}, step at
418 start and end of any tag where it is allowed to step.  Also, stepping
419 at start and end of a tag prevent stepping inside its components.
420 This is a buffer local variable.  It can be set in a mode hook to get
421 a specific langage navigation.
422 @end deffn
423
424 To have a mode specific customization, do something like this in a hook:
425
426 @example
427 (add-hook 'mode-hook
428           (lambda ()
429             (setq senator-step-at-tag-classes '(function variable))
430             (setq senator-step-at-start-end-tag-classes '(function))
431             ))
432 @end example
433
434 This will cause navigation and search commands to stop only between
435 functions and variables, and to step at start and end of functions
436 only.
437
438 @node Analyzer
439 @chapter Analyzer
440 @cindex Analyzer
441
442 The semantic analyzer is a library tool that performs context
443 analysis and can derive useful information.
444
445 @deffn Command semantic-analyze-current-context position
446 Analyze the current context at @var{POSITION}.
447 If called interactively, display interesting information about @var{POSITION}
448 in a separate buffer.
449 Returns an object based on symbol @dfn{semantic-analyze-context}.
450 @end deffn
451
452 While this can be used as a command, it is mostly useful while
453 debugging the analyzer, or tools using the return value.  Use the
454 Emacs command @dfn{describe-class} to learn more about using
455 @code{semantic-analyze-context}.
456
457 Another command that uses the analyzer context can derive a completion
458 list.
459
460 @deffn Command semantic-analyze-possible-completions context
461 Return a list of semantic tags which are possible completions.
462 @var{CONTEXT} is either a position (such as point), or a precalculated
463 context.  Passing in a context is useful if the caller also needs
464 to access parts of the analysis.
465 Completions run through the following filters:
466 @table @asis
467 @item Elements currently in scope
468 @item Constants currently in scope
469 @item Elements match the @code{:prefix} in the @var{CONTEXT}.
470 @item Type of the completion matches the type of the context. 
471 Context type matching can identify the following:
472 @item No specific type
473 @item Assignment into a variable of some type.
474 @item Argument to a function with type constraints.
475 When called interactively, displays the list of possible completions
476 in a buffer.
477 @end table
478 @end deffn
479
480 @menu
481 * Smart Completion::       Functions you can bind to keys for completion
482 * Smart Idle Completion::  Automatic completion popups
483 * Speedbar Analysis::      Speedbar provided completion
484 @end menu
485
486 @node Smart Completion
487 @section Smart Completion
488
489 The file @file{semantic-ia.el} contains two commands for performing
490 smart completion using the analysis library.  Analysis to calculate
491 these completions are done through the analyzer and completion
492 mechanism.  These functions just provide commands that can be bound
493 to key bindings.
494
495 @deffn Command semantic-ia-complete-symbol point
496 @anchor{semantic-ia-complete-symbol}
497 Complete the current symbol at @var{point}.
498 Completion options are calculated with @dfn{semantic-analyze-possible-completions}.
499 @end deffn
500
501 @deffn Command semantic-ia-complete-symbol-menu point
502 @anchor{semantic-ia-complete-symbol-menu}
503 Complete the current symbol via a menu based at @var{point}.
504 Completion options are calculated with @dfn{semantic-analyze-possible-completions}.
505 @end deffn
506
507 @deffn Command semantic-ia-complete-tip point
508 @anchor{semantic-ia-complete-tip}
509 Pop up a tooltip for completion at @var{point}.
510 @end deffn
511
512 @deffn Command semantic-ia-show-summary point
513 @anchor{semantic-ia-show-summary}
514 Display a summary for the symbol under @var{point}.
515 @end deffn
516
517 @deffn Command semantic-ia-show-doc point
518 @anchor{semantic-ia-show-doc}
519 Display the code-level documentation for the symbol at @var{point}.
520 @end deffn
521
522 @node Smart Idle Completion
523 @section Smart Idle Completion
524
525 You can get smart completions or summary information to automatically
526 popup without explicity pressing a key or running a function.
527
528 This is accomplished through the Idle Scheduler and related features.
529 See @ref{Idle Scheduler} for more on the Scheduler.
530
531 Summaries are provided with @code{semantic-idle-summary-mode}.  See
532 @ref{Idle Summary Mode}.
533
534 Completions are provided with @code{semantic-idle-completions-mode}.
535 See @ref{Idle Completions Mode}.
536
537 @node Speedbar Analysis
538 @section Speedbar Analysis
539
540 The Analyzer output can be used through a speedbar interface.
541 This interface lists details about the analysis, such as the current
542 function, local arguments and variables, details on the prefix (the
543 symbol the cursor is on), and a list of all possible completions.
544 Completions are specified in
545 @dfn{semantic-analyze-possible-completions}
546 @ref{Analyzer}.
547
548 Each entry can be jumped to by clicking on the name.  For strongly
549 typed languages, this means you will jump to the definition of the
550 variable, slot, or type definition.
551
552 In addition each entry has an <i> button.  Clicking on this will
553 display a summary of everything that is known about the variable or
554 type displayed on that line.
555
556 If you click on the name of a variable in the ``Completions'' menu,
557 then the text that was recently analyzed will be replaced with the
558 name of the token that was clicked on in speedbar.
559
560 @deffn Command semantic-speedbar-analysis
561 Start Speedbar in semantic analysis mode.
562 The analyzer displays information about the current context, plus a smart
563 list of possible completions.
564 @end deffn
565
566 You can also enter speedbar analyzer mode by selecting ``Analyze''
567 from the ``Display'' menu item on speedbar's menu.
568
569 @node Class Browser
570 @chapter Class Browser
571 @cindex Class Browser
572
573 The semantic class browser is a library that can covert a project
574 file group into an object structure that contains links between
575 structures so that the inheritance links between semantic tags can
576 be easily navigated.
577
578 The core to this library is one function in @file{semantic-cb.el}.
579
580 @defun semantic-cb-new-class-browser
581 Create an object representing this project's organization.
582 The object returned is of type @dfn{semantic-cb-project}, which contains
583 the slot `:types', a list of all top-level types.  Each element is a
584 class of type @dfn{semantic-cb-token}, or @dfn{semantic-cb-type}.
585 @end defun
586
587 Use the Emacs function @dfn{describe-class} to learn more about these
588 classes.
589
590 You can access the class inheritance structure through a speedbar
591 interface.  You can choose the ``Class Browser'' option from
592 Speedbar's ``Display'' menu item, or use the following command:
593
594 @deffn Command semantic-cb-speedbar-mode
595 Bring speedbar up, and put it into Class Browser mode.
596 This will use the Class Browser logic applied to the current Semantic
597 project database to build the available relations.  The structure of
598 the class hierarchy can then be navigated using traditional speedbar
599 interactions.
600 @end deffn
601
602 @node Document
603 @chapter Document
604 @cindex Document
605
606 The document program uses semantic tag tables to aid in the
607 creation of texinfo documentation.
608 For example, the following is a code fragment from @file{document.el}
609 that comes with semantic:
610
611 @lisp
612 (defun document (&optional resetfile)
613   "Document the function or variable the cursor is in.
614 Optional argument RESETFILE is provided w/ universal argument.
615 When non-nil, query for a new documentation file."
616   ...
617   )
618 @end lisp
619
620 While visiting @file{document.el}, put the cursor somewhere within the
621 function shown above. Then type @kbd{M-x document}.
622 After asking for the texinfo file name, which in this case is
623 @file{semantic.texi}, this will update the texinfo
624 documentation of the @code{document} function in that file.
625 The result is that the following texinfo text will be either created
626 or updated in @file{user-guide.texi} file:
627
628 @example
629 @@deffn Command document &optional resetfile
630 Document the function or variable the cursor is in.
631 Optional argument @@var@{RESETFILE@} is provided w/ universal argument.
632 When non-@@code@{nil@}, query for a new documentation file.
633 @@end deffn
634 @end example
635
636 Note that the function name, arguments and documentation string
637 is put in the right place.
638 Within the doc-string, the function arguments are marked with
639 the @@var command and the @code{nil} code fragment is marked with
640 @@code command.
641 This example provides just a glimpse of what is possible with the
642 syntactic information provided by semantic.
643 @refill
644
645 The main entry point for the documentation generator are the following
646 commands:
647
648 @deffn Command document &optional resetfile
649 Document the function or variable the cursor is in.
650 Optional argument @var{RESETFILE} is provided w/ universal argument.
651 When non-@code{nil}, query for a new documentation file.
652 @end deffn
653
654 @deffn Command document-inline
655 Document the current function with an inline comment.
656 @end deffn
657
658 @deffn Command document-insert-defun-comment tag buffer
659 Insert mode-comment documentation about @var{TAG} from @var{BUFFER}.
660 @end deffn
661
662 @deffn Command document-insert-new-file-header header
663 Insert a new header file into this buffer.  Add reference to @var{HEADER}.
664 Used by @code{prototype} if this file doesn't have an introductory comment.
665 @end deffn
666
667 In addition to these base documentation commands, the texinfo semantic
668 parser includes a two convenience functions when working directly with
669 texinfo files.
670
671 @deffn Command semantic-texi-update-doc &optional tag
672 Update the documentation for @var{TAG}.
673 If the current buffer is a texinfo file, then find the source doc, and
674 update it.  If the current buffer is a source file, then get the
675 documentation for this item, find the existing doc in the associated
676 manual, and update that.
677 @end deffn
678
679 @deffn Command semantic-texi-goto-source &optional tag
680 Jump to the source for the definition in the texinfo file @var{TAG}.
681 If @var{TAG} is @code{nil}, it is derived from the deffn under @var{POINT}.
682 @end deffn
683
684 @node Charts
685 @chapter Charts
686 @cindex Charts
687
688 Some commands to draw charts of statistics generated from parsing:
689
690 @deffn Command semantic-chart-tags-by-class &optional tagtable
691 Create a bar chart representing the number of tags for a given tag class.
692 Each bar represents how many toplevel tags in @var{TAGTABLE}
693 exist with a given class.  See @code{semantic-symbol->name-assoc-list}
694 for tokens which will be charted.
695 @var{TAGTABLE} is passedto @dfn{semantic-something-to-tag-table}.
696 @end deffn
697
698 @deffn Command semantic-chart-database-size &optional tagtable
699 Create a bar chart representing the size of each file in semanticdb.
700 Each bar represents how many toplevel nonterminals in @var{TAGTABLE}
701 exist in each database entry.
702 @var{TAGTABLE} is passedto @dfn{semantic-something-to-tag-table}.
703 @end deffn
704
705 @deffn Command semantic-chart-tag-complexity &optional class tagtable
706 Create a bar chart representing the complexity of some tokens.
707 Complexity is calculated for tokens with a tag of @var{CLASS}.  Each bar
708 represents the complexity of some nonterminal in @var{TAGTABLE}.
709 Only the most complex items are charted.
710 @var{TAGTABLE} is passedto @dfn{semantic-something-to-tag-table}.
711 @end deffn
712
713 @node Idle Scheduler
714 @chapter Idle Scheduler
715 @cindex Idle Scheduler
716
717 The Idle Scheduler in Semantic 2.0 replaces what was once Auto-Parse
718 mode.  The Idle Scheduler now performs multiple duties.
719
720 The primary job is to schedule buffer parsing in idle time.  The
721 first buffer whose cache is checked is the current buffer.  After
722 this, all other buffers are checked.
723
724 Once that has been accomplished, sheduled idle processes that use the
725 semantic tag tables are run.
726
727 @deffn Command global-semantic-idle-scheduler-mode &optional arg
728 @anchor{global-semantic-idle-scheduler-mode}
729 Toggle global use of option @dfn{semantic-idle-scheduler-mode}.
730 The idle scheduler with automatically reparse buffers in idle time,
731 and then schedule other jobs setup with @dfn{semantic-idle-scheduler-add}.
732 If @var{ARG} is positive, enable, if it is negative, disable.
733 If @var{ARG} is @code{nil}, then toggle.
734 @obsolete{global-semantic-auto-parse-mode,global-semantic-idle-scheduler-mode}
735 @end deffn
736
737 @obsolete{semantic-auto-parse-mode, semantic-idle-scheduler-mode}
738
739 @deffn Option semantic-idle-scheduler-idle-time
740 @anchor{semantic-idle-scheduler-idle-time}
741 Time in seconds of idle before scheduling events.
742 This time should be short enough to ensure that idle-scheduler will be
743 run as soon as Emacs is idle.
744 @end deffn
745
746 @deffn Option semantic-idle-scheduler-mode-hook
747 @anchor{semantic-idle-scheduler-mode-hook}
748 Hook run at the end of function @dfn{semantic-idle-scheduler-mode}.
749 @end deffn
750
751 You can add new functionality to the idle scheduler by reading the
752 Application Developers Guide
753 @inforef{Idle Scheduling, , semantic-appdev.info}.
754
755 @menu
756 * Reparsing Options::           
757 * Idle Summary Mode::           
758 * Idle Completions Mode::
759 @end menu
760
761 @node Reparsing Options
762 @section Reparsing Options
763
764 The Idle Scheduler will automatically reparse all buffers that need
765 it.  User input at any time will cancel the operations and return to
766 normal editing.
767
768 @subsection Reparse Configuration
769
770 @deffn Option semantic-idle-scheduler-max-buffer-size
771 @anchor{semantic-idle-scheduler-max-buffer-size}
772 Maximum size in bytes of buffers automatically reparsed.
773 If this value is less than or equal to @var{0}, buffers are automatically
774 reparsed regardless of their size.
775 @end deffn
776
777 @subsection Reparse Messages
778
779 @deffn Option semantic-idle-scheduler-no-working-message
780 @anchor{semantic-idle-scheduler-no-working-message}
781 If non-@code{nil}, disable display of working messages during parse.
782 @end deffn
783
784 @deffn Option semantic-idle-scheduler-working-in-modeline-flag
785 @anchor{semantic-idle-scheduler-working-in-modeline-flag}
786 Non-@code{nil} means show working messages in the mode line.
787 Typically, parsing will show messages in the minibuffer.
788 This will move the parse message into the modeline.
789 @end deffn
790
791 @subsection Reprasing Hooks
792
793 @defvar semantic-before-idle-scheduler-reparse-hooks
794 @anchor{semantic-before-idle-scheduler-reparse-hooks}
795 Hooks run before option @code{semantic-idle-scheduler} begins parsing.
796 If any hook throws an error, this variable is reset to nil.
797 This hook is not protected from lexical errors.
798 @end defvar
799
800 @defvar semantic-after-idle-scheduler-reparse-hooks
801 @anchor{semantic-after-idle-scheduler-reparse-hooks}
802 Hooks run after option @code{semantic-idle-scheduler} has parsed.
803 If any hook throws an error, this variable is reset to nil.
804 This hook is not protected from lexical errors.
805 @end defvar
806
807 @node Idle Summary Mode
808 @section Idle Summary Mode
809
810 A summary describes a tag in a useful way.  These can be displayed
811 for the lexical token under the cursor in idle time using this mode.
812
813 @deffn semantic-idle-summary-mode &optional arg
814 @anchor{semantic-idle-summary-mode}
815 Display a tag summary of the lexical token under the cursor.
816 This means for getting the current tag to display information can
817 be overriden with @code{idle-summary-current-symbol-info}.
818 This is a minor mode which performs actions during idle time.
819 With prefix argument ARG, turn on if positive, otherwise off.  The
820 minor mode can be turned on only if semantic feature is available and
821 the current buffer was set up for parsing.  Return non-nil if the
822 minor mode is enabled
823 @end deffn
824
825 @obsolete{semantic-summary-mode, semantic-idle-summary-mode}
826
827 @deffn Option semantic-idle-summary-function
828 @anchor{semantic-idle-summary-function}
829 Function to use when displaying tag information during idle time.
830 Some useful functions are found in @code{semantic-format-tag-functions}.
831 @end deffn
832
833 @node Idle Completions Mode
834 @section Idle Completions Mode
835
836 The definition of completion lists is described in the Analyzer
837 section @ref{Analyzer}.
838
839 The Idle Completions mode will calculate the list of possible
840 completions in idle time, and display them in a popup list, and also
841 highlight the symbol that needs completion.
842
843 @deffn semantic-idle-completions-mode &optional arg
844 @anchor{semantic-idle-completions-mode}
845 Display a tooltip with a list of possible completions near the cursor.
846 There is no convenience for performing a completion replacement.  For
847 that you should bind @code{semantic-ia-complete-symbol}.
848 This is a minor mode which performs actions during idle time.
849 With prefix argument ARG, turn on if positive, otherwise off.  The
850 minor mode can be turned on only if semantic feature is available and
851 the current buffer was set up for parsing.  Return non-nil if the
852 minor mode is enabled
853 @end deffn
854
855 This mode operates by using the command
856 @code{semantic-complete-inline-analyzer}.
857
858 @node Minor Modes
859 @chapter Minor Modes
860 @cindex Minor Modes
861
862 @include minor-modes.texi
863
864 @node semanticdb
865 @chapter Semantic Database
866 @cindex semanticdb
867
868 Semanticdb is a utility which tracks your parsed files, and saves the
869 parsed information to disk.  When you reload your source files,
870 semanticdb automatically associates the file with the cached copy,
871 saving time by not re-parsing your buffer.
872
873 Semanticdb also provides an API for programs to use to look up
874 information about a tag.  These functions can return tag
875 information without loading the source file into memory.
876
877 Lastly, the semanticdb interface allows programmers to create
878 alternate back ends.  Such a back end could allow access to tag
879 information in binary files, not normally accessable to @semantic{}.  A
880 back end could also be written to store tag information in an
881 alternate form of persistent storage.
882
883 To use semanticdb, add the following to your @file{.emacs} file:
884
885 @example
886 (require 'semanticdb)
887 (global-semanticdb-minor-mode 1)
888 @end example
889
890 If you use @file{semantic-load.el}, or the default CEDET install
891 mechanism, you do not need to add the above lines in your
892 @file{.emacs} file.
893
894 The Semantic Database has several user level configuration options
895 that controls it's use.  From the user perspective, it appears to be
896 one large application.  Internally it is divided into sections.
897
898 @table @asis
899 @item Core Tables
900 These core tables for semanticdb are not associated with files, or
901 backends.  They define the basic behavior of a database and table.
902 @item Persistent Tables
903 These databases are what are generally used in semantic to store
904 information to disk.
905 @item Custom Backends
906 These databases and tables are interfaces to some other source of
907 tagging information, such as the symbols loaded in Emacs Lisp, or
908 perhaps symbols in a Java @file{.class} file.
909 @end table
910
911 You can execute hooks when semanticdb is activated using its mode hook.
912
913 @deffn Option semanticdb-mode-hooks
914 @anchor{semanticdb-mode-hooks}
915 Hooks run whenever @dfn{global-semanticdb-minor-mode} is run.
916 Use @dfn{semanticdb-minor-mode-p} to determine if the mode has been turned
917 on or off.
918 @end deffn
919
920 @menu
921 * Semanticdb Tag Storage::
922 * Semanticdb Search Configuration::
923 * Semanticdb System Backends::
924 * Changing Backends::
925 * Script Generated Cache Files::
926 * Create System Databases::
927 @end menu
928
929 @node Semanticdb Tag Storage
930 @section Semanticdb Tag Storage
931
932 Once you have tables of tags parsed from your files, the default
933 action is to save them when Emacs exits.  You can control the file
934 name and directories where the caches are stored.
935
936 @deffn Option semanticdb-default-file-name
937 @anchor{semanticdb-default-file-name}
938 File name of the semantic tag cache.
939 @end deffn
940
941 @deffn Option semanticdb-default-save-directory
942 @anchor{semanticdb-default-save-directory}
943 Directory name where semantic cache files are stored.
944 If this value is @code{nil}, files are saved in the current directory.  If the value
945 is a valid directory, then it overrides @code{semanticdb-default-file-name} and
946 stores caches in a coded file name in this directory.
947 @end deffn
948
949 @deffn Option semanticdb-persistent-path
950 @anchor{semanticdb-persistent-path}
951 List of valid paths that semanticdb will cache tags to.
952 When @dfn{global-semanticdb-minor-mode} is active, tag lists will
953 be saved to disk when Emacs exits.  Not all directories will have
954 tags that should be saved.
955 The value should be a list of valid paths.  @var{a} path can be a string,
956 indicating a directory in which to save a variable.  An element in the
957 list can also be a symbol.  Valid symbols are @code{never}, which will
958 disable any saving anywhere, @code{always}, which enables saving
959 everywhere, or @code{project}, which enables saving in any directory that
960 passes a list of predicates in @code{semanticdb-project-predicate-functions}.
961 @end deffn
962
963 @defvar semanticdb-project-predicate-functions
964 @anchor{semanticdb-project-predicate-functions}
965 List of predicates to try that indicate a directory belongs to a project.
966 This list is used when @code{semanticdb-persistent-path} contains the value
967 @code{'project}.  If the predicate list is @code{nil}, then presume all paths are valid.
968
969 Project Management software (such as @var{ede} and @var{jde}) should add their own
970 predicates with @dfn{add-hook} to this variable, and semanticdb will save tag
971 caches in directories controlled by them.
972 @end defvar
973
974 @deffn Option semanticdb-save-database-hooks
975 @anchor{semanticdb-save-database-hooks}
976 Hooks run after a database is saved.
977 Each function is called with one argument, the object representing
978 the database recently written.
979 @end deffn
980
981 @node Semanticdb Search Configuration
982 @section Semanticdb Search Configuration
983
984   When different tools such as smart completion or tag jumping needs
985 to find a tag, those routines call semanticdb search routines.  Some
986 time usually needs to be spent making sure semanticdb can find the
987 files your tags are in.
988
989 The search path should include:
990
991 @enumerate
992 @item
993 The current file
994 @item
995 a table for each #include file
996 @item
997 if 'recursive is in the throttle, then all include files included in
998 include files.
999 @end enumerate
1000
1001 Include files or equivalent are found in:
1002
1003 @enumerate
1004 @item
1005 current directory
1006 @item
1007 directories specified by your project.  (such as EDE, or the
1008 @code{semanticdb-project-roots} variable.)
1009 @item
1010 system directories
1011 @end enumerate
1012
1013 In C code, semantic tries to distinguish between project and system
1014 headers based on @code{""} or @code{<>} delimiters.  Each language can
1015 distinguish using it's own rules.
1016
1017 The system directory is set up via the variable
1018 @code{semantic-dependency-system-include-path}.  The path is also
1019 modified by some system database create routines, such as
1020 @code{semanticdb-create-ebrowse-database}. @xref{Include paths}.
1021
1022 You can use the command:
1023
1024 @example
1025 M-x semantic-add-system-include RET /some/path
1026 @end example
1027
1028   to add more paths interactively into the current mode's path.  This
1029 will allow semantic to find more files w/out using system databases.
1030
1031 @menu
1032 * Semanticdb Roots::    Specifying the root of different projects
1033 * Include paths::       Add/Remove directories to include search paths
1034 * Search Throttle::     Controlling how semanticdb searches occur
1035 * Semanticdb search debugging commands::
1036 @end menu
1037
1038 @node Semanticdb Roots
1039 @subsection SemanticDB project roots
1040
1041 Project roots specify where different code projects start.  Searching
1042 for files usually stops within a single project, so specifying these
1043 roots is important if you want semantic to find tags in other related
1044 directories.
1045
1046
1047 @deffn Option semanticdb-project-roots
1048 @anchor{semanticdb-project-roots}
1049 List of directories, where each directory is the root of some project.
1050 All subdirectories of a root project are considered a part of one project.
1051 Values in this string can be overriden by project management programs
1052 via the @code{semanticdb-project-root-functions} variable.
1053 @end deffn
1054
1055 @defvar semanticdb-project-root-functions
1056 @anchor{semanticdb-project-root-functions}
1057 List of functions used to determine a given directories project root.
1058 Functions in this variable can override @code{semanticdb-project-roots}.
1059 Functions set in the variable are given one argument (a directory) and
1060 must return a string, (the root directory) or a list of strings (multiple
1061 root directories in a more complex system).  This variable should be used
1062 by project management programs like @var{ede} or @var{jde}.
1063 @end defvar
1064
1065 @node Include paths
1066 @subsection Include Paths
1067
1068 You can add and remove system include paths based on major mode using
1069 the following commands:
1070
1071 @deffn Command semantic-add-system-include dir &optional mode
1072 @anchor{semantic-add-system-include}
1073 Add a system include @var{dir} to path for @var{mode}.
1074 Modifies a mode-local version of
1075 @code{semantic-dependency-system-include-path}.
1076 @end deffn
1077
1078 @deffn Command semantic-remove-system-include dir &optional mode
1079 @anchor{semantic-remove-system-include}
1080 Add a system include @var{dir} to path for @var{mode}.
1081 Modifies a mode-local version of
1082 @code{semantic-dependency-system-include-path}.
1083 @end deffn
1084
1085 @node Search Throttle
1086 @subsection SemanticDB Search Throttle
1087
1088 The semanticdb find throttle is a configuration variable that may
1089 often be configured by a language support author.  If you need to
1090 customize this for yourself, you may need to override the mode values
1091 in a mode support hook.
1092
1093 @defvar semanticdb-find-default-throttle
1094 @anchor{semanticdb-find-default-throttle}
1095 The default throttle for @code{semanticdb-find} routines.
1096 The throttle controls how detailed the list of database
1097 tables is for a symbol lookup.  The value is a list with
1098 the following keys:
1099
1100 @table @code
1101 @item file
1102 The file the search is being performed from.  This option is here for
1103 completeness only, and is assumed to always be on.
1104 @item local
1105 Tables from the same local directory are included.  This includes
1106 files directly referenced by a file name which might be in a different
1107 directory.
1108 @item project
1109 Tables from the same local project are included If @code{project} is
1110 specified, then @code{local} is assumed.
1111 @item unloaded
1112 If a table is not in memory, load it.  If it is not cached on disk
1113 either, get the source, parse it, and create the table.
1114 @item system
1115 Tables from system databases.  These are specifically tables
1116 from system header files, or language equivalent.
1117 @item recursive
1118 For include based searches, includes tables referenced by included
1119 files.
1120 @item omniscience
1121 Included system databases which are omniscience, or somehow know
1122 everything.  Omniscience databases are found in
1123 @code{semanticdb-project-system-databases}.  The Emacs Lisp system
1124 @var{db} is an omniscience database.
1125 @end table
1126
1127 @end defvar
1128
1129 To set the throttle, use a command like this:
1130
1131 @example
1132 (setq-mode-local c-mode
1133                  semanticdb-find-default-throttle
1134                  '(project unloaded system recursive))
1135 @end example
1136
1137
1138
1139 @node Semanticdb search debugging commands
1140 @subsection Semanticdb search debugging commands
1141
1142 You can use @kbd{M-x semanticdb-dump-all-table-summary RET} to see the
1143 list of databases that will be searched from a given buffer.  It
1144 should include DBs for the directories you expect.  You can follow up
1145 with @kbd{M-x semanticdb-find-test-translate-path RET} to then make
1146 sure specific tables from the path are discovered correctly. 
1147
1148 @deffn Command semanticdb-dump-all-table-summary
1149 @anchor{semanticdb-dump-all-table-summary}
1150 Dump a list of all databases in Emacs memory.
1151 @end deffn
1152
1153 @deffn Command semanticdb-find-test-translate-path &optional arg
1154 @anchor{semanticdb-find-test-translate-path}
1155 Call and output results of @dfn{semanticdb-find-translate-path}
1156 With @var{arg} non-@code{nil}, specify a @var{brutish} translation.
1157 @end deffn
1158
1159 Lastly, you can test an explicit search term using this command:
1160
1161 @deffn Command semantic-adebug-searchdb regex
1162 @anchor{semantic-adebug-searchdb}
1163 Search the semanticdb for @var{regex} for the current buffer.
1164 Display the results as a debug list.
1165 @end deffn
1166
1167 @node Semanticdb System Backends
1168 @section Semanticdb System Backends
1169
1170 @defvar semanticdb-project-system-databases
1171 @anchor{semanticdb-project-system-databases}
1172 List of databases containing system library information.
1173 Mode authors can create their own system databases which know
1174 detailed information about the system libraries for querying purposes.
1175 Put those into this variable as a buffer-local, or mode-local
1176 value.
1177 @end defvar
1178
1179 These system databases are a part of the `omniscience' throttle value.
1180
1181 While these are enabled with @code{semanticdb-find-default-throttle},
1182 a secondary flag is needed for internal controls that prevent
1183 recursive duplication.
1184
1185 @defvar semanticdb-search-system-databases
1186 @anchor{semanticdb-search-system-databases}
1187 Non @code{nil} if search routines are to include a system database.
1188 @end defvar
1189
1190
1191 @node Changing Backends
1192 @section Changing Backends
1193
1194 If you want to use some other form of backend, you can use this
1195 variable to choose which back end class to use for your general tag
1196 storage.
1197
1198 @defvar semanticdb-new-database-class
1199 @anchor{semanticdb-new-database-class}
1200 The default type of database created for new files.
1201 This can be changed on a per file basis, so that some directories
1202 are saved using one mechanism, and some directories via a different
1203 mechanism.
1204 @end defvar
1205
1206 @node Script Generated Cache Files
1207 @section Script Generated Cache Files
1208
1209 You can create new semantic databases with the @file{semanticdb.sh}
1210 script file.  Give this script the directory you want parsed, and it
1211 will create a cache file for you.
1212
1213 @example
1214 $ semanticdb.sh *.el
1215 @end example
1216
1217 @node Create System Databases
1218 @section Create System Databases
1219
1220 If your supported langauge stores the system libraries in readilly
1221 available parsable source code, you can pre-generate database files
1222 for them once, which will be used over and over for tools such as
1223 summary-mode, or the analyzer.
1224
1225 Use the following command to create new system databases:
1226
1227 @deffn Command semanticdb-create-system-database path &optional class
1228 @anchor{semanticdb-create-system-database}
1229 Create a system database starting at @var{path}.
1230 @var{path} should be a top level directory for a series of files containing
1231 declarations for @var{system} files.  In @var{c}, this would be header filaes.
1232 @var{class} is the class for the database to create.  Only child classes
1233 of symbol @dfn{semanticdb-project-database-system} are accepted.
1234 @end deffn
1235
1236
1237 @deffn Command semanticdb-create-ebrowse-database dir
1238 @anchor{semanticdb-create-ebrowse-database}
1239 Create an @var{ebrose} database for directory @var{dir}.
1240 The database file is stored in ~/.semanticdb, or whichever directory
1241 is specified by @code{semanticdb-default-system-save-directory}.
1242 @end deffn
1243
1244 The CLASS requested here is a bit of archana representing the class
1245 name for the language the entry is for.  Use completion @kbd{SPC} to
1246 see the ones available.  The name of the language should be part of
1247 the class name.
1248
1249 @node Speed Debug
1250 @chapter Debugging Speed Problems
1251
1252 If aspects of semantic cause your Emacs to slow down or block
1253 editing, there are several things that may be happening.  The most
1254 time consuming aspect of semantic is usually the parsing of files for
1255 tag information, and this action can be triggered from many possible
1256 sources.
1257
1258 A simple way to determine where the problem lies is to use the command
1259 @kbd{M-x debug-on-quit RET} and then just hit @kbd{C-g} next time it
1260 gets 'stuck' somewhere.  It will give you a stack and one of the many
1261 semantic mode functions will likely show up in that stack trace.
1262
1263 From a simple standpoint, your next action might be to use the the
1264 Senator menu under @kbd{Modes} and just toggle suspected modes on and
1265 off.
1266
1267 @section Interruptibility
1268
1269   One of the goals with the semantic based minor modes and auto parse
1270 is that it should be interruptible.  Thus, a keyboard action should
1271 interrupt any active parsing or mode activity.  In practice, I've
1272 found this doesn't always work and I've been a bit stymied as to why.
1273
1274   You can test the interruptibility framework by running
1275 @kbd{M-x semantic-test-throw-on-input RET} and seeing that you can
1276 press any key to break out of the loop.
1277
1278 @section Incremental parsing
1279
1280 The incremental parser used by semantic will reparse only small
1281 sections of a file you have edited, which eliminates the need to
1282 reparse entire files.  This speeds up minor modes that need the local
1283 buffer to be up to date, such as speedbar or ECB.
1284
1285 If the incremental parsing is not always working for you (meaning it
1286 will parse the whole file frequently while you edit) then perhaps you
1287 need to customize @code{semantic-edits-verbose-flag} to enable some
1288 friendly debug output.  Additionally using
1289 @code{semantic-load-enable-semantic-debugging-helpers} to help
1290 identify possible problem areas by enabling highlight edits mode and
1291 show parser state mode 
1292 @inforef{Incremental Parser Debugging, ,semantic-langdev.info}
1293
1294 @section Symbol lookup
1295
1296 There are many minor modes that have special behaviors tied into the
1297 current parser state, with the most complex modes being the summary
1298 and completion modes.  These modes can initiate parsing not only in
1299 the current buffer, but in other buffers that are referred to in the
1300 current source by some form of include statement.
1301
1302 If they turn out not to be useful in the language mode you are
1303 operating in, then it may be best to disable them.
1304
1305 Alternately, you can control how these major modes, and other modes
1306 like them parse alternate files by adjusting
1307 @code{semanticdb-find-default-throttle}. You can read more
1308 in @inforef{ DB Search Paths, , semantic-appdev.info}.
1309
1310 @node Customizing
1311 @chapter Customizing
1312 @cindex customizing
1313
1314 Customizations can be divided into two categories.
1315 * M-x customize
1316 * Low level hooks.
1317
1318 @node GNU Free Documentation License
1319 @appendix GNU Free Documentation License
1320
1321 @include fdl.texi
1322
1323 @node Index
1324 @unnumbered Index
1325 @printindex cp
1326
1327 @iftex
1328 @contents
1329 @summarycontents
1330 @end iftex
1331
1332 @bye
1333
1334 @c Following comments are for the benefit of ispell.
1335