1 \input texinfo @c -*-texinfo-*-
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}
8 @c *************************************************************************
10 @c *************************************************************************
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.
20 @c @footnotestyle separate
26 This is the Semantic User's Manual
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
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
46 * Semantic User's guide: (semantic-user).
54 @c @setchapternewpage odd
55 @c @setchapternewpage off
58 This is the Semantic User's Guide
59 @emph{Infrastructure for parser based text analysis in Emacs}
61 Copyright @copyright{} 1999, 2000, 2001, 2002, 2003, 2004 @value{AUTHOR}
67 @author by @value{AUTHOR}
68 @vskip 0pt plus 1 fill
69 Copyright @copyright{} 1999, 2000, 2001, 2002, 2003, 2004 @value{AUTHOR}
71 @vskip 0pt plus 1 fill
77 @include semanticheader.texi
79 @c *************************************************************************
81 @c *************************************************************************
87 This chapter describes how to use @b{applications} enabled by
89 Many of these come with semantic, but others are distributed apart
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.
106 * GNU Free Documentation License::
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:
118 (add-hook 'speedbar-load-hook (lambda () (require 'semantic-sb)))
121 or you can simply add:
124 (require 'semantic-sb)
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
132 If you use @file{semantic-load.el}, you do not need to add the above
133 lines in your @file{.emacs} file.
135 Two additional speedbar modes are described in @ref{Speedbar Analysis}, and
142 From the ECB Website: @url{http://ecb.sourceforge.net}:
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.
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.
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:
164 (add-hook 'semantic-init-hooks (lambda ()
165 (imenu-add-to-menubar "TAGS")))
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.
172 If you use @file{semantic-load.el}, you do not need to add the above
173 lines in your @file{.emacs} file.
175 You can customize imenu with the following options:
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}.
182 @deffn Option semantic-imenu-bucketize-file
183 Non-@code{nil} if tags in a file are to be grouped into buckets.
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.
191 @deffn Option semantic-imenu-expand-type-members
192 Non-@code{nil} if types should have submenus with members in them.
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.
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.
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.
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.
219 When adding support to a language, this variable may need to be set:
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.
233 Senator stands for SEmantic NAvigaTOR and was written by David Ponce.
235 This library defines commands and a minor mode to navigate and manage
236 semantic language tags in the current buffer.
240 The following user level commands are provided by Senator.
242 @subsection Navigation
244 @defun senator-next-tag
245 Navigate to the next Semantic tag.
246 Return the tag or @code{nil} if at end of buffer.
249 @defun senator-previous-tag
250 Navigate to the previous Semantic tag.
251 Return the tag or @code{nil} if at beginning of buffer.
255 Jump to the semantic symbol @var{SYM}.
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.
261 When called interactively you can combine the @var{IN-CONTEXT} and
262 @var{NO-DEFAULT} switches like this:
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}.
269 @subsection Searching
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
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.
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.
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
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}.
299 @subsection Completion
301 Completion in senator scans all known definitions in the local file,
302 and uses that information to provide the completion.
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.
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.
317 @subsection Copy/Paste
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.
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.
329 @deffn Command senator-copy-tag
330 Take the current tag, and place it in the tag ring.
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}.
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
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
351 For programmers, to provide specialized pasting, created an override
352 function for @code{insert-foreign-tag} (see @inforef{Writing Parsers, , semantic-langdev}.)
354 @subsection Minor Mode
356 @deffn Command senator-minor-mode
357 Toggle the SEmantic NAvigaTOR key bindings in the current buffer.
359 The following default key bindings are provided when semantic minor
369 senator-isearch-toggle-semantic-mode
371 semantic-complete-jump-local
373 semantic-complete-jump
375 senator-complete-symbol
377 senator-completion-menu-popup
391 @section Customization
393 To enable the Senator keymap in all modes that support semantic parsing,
397 (add-hook 'semantic-init-hooks 'senator-minor-mode)
400 If you use @file{semantic-load.el}, you do not need to add the above
401 lines in your @file{.emacs} file.
403 To customize navigation around different types of tokens, use the
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
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.
424 To have a mode specific customization, do something like this in a hook:
429 (setq senator-step-at-tag-classes '(function variable))
430 (setq senator-step-at-start-end-tag-classes '(function))
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
442 The semantic analyzer is a library tool that performs context
443 analysis and can derive useful information.
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}.
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}.
457 Another command that uses the analyzer context can derive a completion
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:
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
481 * Smart Completion:: Functions you can bind to keys for completion
482 * Smart Idle Completion:: Automatic completion popups
483 * Speedbar Analysis:: Speedbar provided completion
486 @node Smart Completion
487 @section Smart Completion
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
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}.
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}.
507 @deffn Command semantic-ia-complete-tip point
508 @anchor{semantic-ia-complete-tip}
509 Pop up a tooltip for completion at @var{point}.
512 @deffn Command semantic-ia-show-summary point
513 @anchor{semantic-ia-show-summary}
514 Display a summary for the symbol under @var{point}.
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}.
522 @node Smart Idle Completion
523 @section Smart Idle Completion
525 You can get smart completions or summary information to automatically
526 popup without explicity pressing a key or running a function.
528 This is accomplished through the Idle Scheduler and related features.
529 See @ref{Idle Scheduler} for more on the Scheduler.
531 Summaries are provided with @code{semantic-idle-summary-mode}. See
532 @ref{Idle Summary Mode}.
534 Completions are provided with @code{semantic-idle-completions-mode}.
535 See @ref{Idle Completions Mode}.
537 @node Speedbar Analysis
538 @section Speedbar Analysis
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}
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.
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.
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.
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.
566 You can also enter speedbar analyzer mode by selecting ``Analyze''
567 from the ``Display'' menu item on speedbar's menu.
570 @chapter Class Browser
571 @cindex Class Browser
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
578 The core to this library is one function in @file{semantic-cb.el}.
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}.
587 Use the Emacs function @dfn{describe-class} to learn more about these
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:
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
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:
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."
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:
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.
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
641 This example provides just a glimpse of what is possible with the
642 syntactic information provided by semantic.
645 The main entry point for the documentation generator are the following
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.
654 @deffn Command document-inline
655 Document the current function with an inline comment.
658 @deffn Command document-insert-defun-comment tag buffer
659 Insert mode-comment documentation about @var{TAG} from @var{BUFFER}.
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.
667 In addition to these base documentation commands, the texinfo semantic
668 parser includes a two convenience functions when working directly with
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.
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}.
688 Some commands to draw charts of statistics generated from parsing:
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}.
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}.
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}.
714 @chapter Idle Scheduler
715 @cindex Idle Scheduler
717 The Idle Scheduler in Semantic 2.0 replaces what was once Auto-Parse
718 mode. The Idle Scheduler now performs multiple duties.
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.
724 Once that has been accomplished, sheduled idle processes that use the
725 semantic tag tables are run.
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}
737 @obsolete{semantic-auto-parse-mode, semantic-idle-scheduler-mode}
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.
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}.
751 You can add new functionality to the idle scheduler by reading the
752 Application Developers Guide
753 @inforef{Idle Scheduling, , semantic-appdev.info}.
756 * Reparsing Options::
757 * Idle Summary Mode::
758 * Idle Completions Mode::
761 @node Reparsing Options
762 @section Reparsing Options
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
768 @subsection Reparse Configuration
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.
777 @subsection Reparse Messages
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.
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.
791 @subsection Reprasing Hooks
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.
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.
807 @node Idle Summary Mode
808 @section Idle Summary Mode
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.
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
825 @obsolete{semantic-summary-mode, semantic-idle-summary-mode}
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}.
833 @node Idle Completions Mode
834 @section Idle Completions Mode
836 The definition of completion lists is described in the Analyzer
837 section @ref{Analyzer}.
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.
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
855 This mode operates by using the command
856 @code{semantic-complete-inline-analyzer}.
862 @include minor-modes.texi
865 @chapter Semantic Database
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.
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.
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.
883 To use semanticdb, add the following to your @file{.emacs} file:
886 (require 'semanticdb)
887 (global-semanticdb-minor-mode 1)
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
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.
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
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.
911 You can execute hooks when semanticdb is activated using its mode hook.
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
921 * Semanticdb Tag Storage::
922 * Semanticdb Search Configuration::
923 * Semanticdb System Backends::
924 * Changing Backends::
925 * Script Generated Cache Files::
926 * Create System Databases::
929 @node Semanticdb Tag Storage
930 @section Semanticdb Tag Storage
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.
936 @deffn Option semanticdb-default-file-name
937 @anchor{semanticdb-default-file-name}
938 File name of the semantic tag cache.
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.
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}.
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.
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.
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.
981 @node Semanticdb Search Configuration
982 @section Semanticdb Search Configuration
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.
989 The search path should include:
995 a table for each #include file
997 if 'recursive is in the throttle, then all include files included in
1001 Include files or equivalent are found in:
1007 directories specified by your project. (such as EDE, or the
1008 @code{semanticdb-project-roots} variable.)
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.
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}.
1022 You can use the command:
1025 M-x semantic-add-system-include RET /some/path
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.
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::
1038 @node Semanticdb Roots
1039 @subsection SemanticDB project roots
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
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.
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}.
1066 @subsection Include Paths
1068 You can add and remove system include paths based on major mode using
1069 the following commands:
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}.
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}.
1085 @node Search Throttle
1086 @subsection SemanticDB Search Throttle
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.
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
1102 The file the search is being performed from. This option is here for
1103 completeness only, and is assumed to always be on.
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
1109 Tables from the same local project are included If @code{project} is
1110 specified, then @code{local} is assumed.
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.
1115 Tables from system databases. These are specifically tables
1116 from system header files, or language equivalent.
1118 For include based searches, includes tables referenced by included
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.
1129 To set the throttle, use a command like this:
1132 (setq-mode-local c-mode
1133 semanticdb-find-default-throttle
1134 '(project unloaded system recursive))
1139 @node Semanticdb search debugging commands
1140 @subsection Semanticdb search debugging commands
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.
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.
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.
1159 Lastly, you can test an explicit search term using this command:
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.
1167 @node Semanticdb System Backends
1168 @section Semanticdb System Backends
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
1179 These system databases are a part of the `omniscience' throttle value.
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.
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.
1191 @node Changing Backends
1192 @section Changing Backends
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
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
1206 @node Script Generated Cache Files
1207 @section Script Generated Cache Files
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.
1214 $ semanticdb.sh *.el
1217 @node Create System Databases
1218 @section Create System Databases
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.
1225 Use the following command to create new system databases:
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.
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}.
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
1250 @chapter Debugging Speed Problems
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
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.
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
1267 @section Interruptibility
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.
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.
1278 @section Incremental parsing
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.
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}
1294 @section Symbol lookup
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.
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.
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}.
1311 @chapter Customizing
1314 Customizations can be divided into two categories.
1318 @node GNU Free Documentation License
1319 @appendix GNU Free Documentation License
1334 @c Following comments are for the benefit of ispell.