;;; semantic.el --- Semantic buffer evaluator.
-;;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
-;;; 2007, 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+;; 2008, 2009, 2010 Free Software Foundation, Inc.
;; Author: Eric M. Ludlam <zappo@gnu.org>
;; Keywords: syntax
;;
;; API for providing the semantic content of a buffer.
;;
-;; The semantic API provides an interface to a series of different parser
+;; The Semantic API provides an interface to a series of different parser
;; implementations. Each parser outputs a parse tree in a similar format
;; designed to handle typical functional and object oriented languages.
+;;
+;; To enable Semantic, turn on `semantic-mode', a global minor mode
+;; (M-x semantic-mode RET, or "Source Code Parsers" from the Tools
+;; menu). To enable it at startup, put (semantic-mode 1) in your init
+;; file.
(require 'cedet)
(require 'semantic/tag)
(declare-function semanticdb-load-ebrowse-caches "semantic/db-ebrowse")
(defun semantic-require-version (major minor &optional beta)
- "Non-nil if this version of semantic does not satisfy a specific version.
+ "Non-nil if this version of Semantic does not satisfy a specific version.
Arguments can be:
(MAJOR MINOR &optional BETA)
(defgroup semantic nil
"Parser Generator and parser framework."
- :group 'lisp)
+ :group 'tools)
(defgroup semantic-faces nil
"Faces used for Semantic enabled tools."
external parser used.")
(make-variable-buffer-local 'semantic--parse-table)
(semantic-varalias-obsolete 'semantic-toplevel-bovine-table
- 'semantic--parse-table)
+ 'semantic--parse-table "23.2")
(defvar semantic-symbol->name-assoc-list
'((type . "Types")
DO NOT USE THIS VARIABLE IN PROGRAMS.
If you need a tag list, use `semantic-fetch-tags'. If you need the
-cached values for some reason, chances are you can, add a hook to
+cached values for some reason, chances are you can add a hook to
`semantic-after-toplevel-cache-change-hook'.")
(make-variable-buffer-local 'semantic--buffer-cache)
(semantic-varalias-obsolete 'semantic-toplevel-bovine-cache
- 'semantic--buffer-cache)
+ 'semantic--buffer-cache "23.2")
(defvar semantic-unmatched-syntax-cache nil
"A cached copy of unmatched syntax tokens.")
(make-variable-buffer-local 'semantic-unmatched-syntax-cache)
(defvar semantic-unmatched-syntax-cache-check nil
- "Non nil if the unmatched syntax cache is out of date.
+ "Non-nil if the unmatched syntax cache is out of date.
This is tracked with `semantic-change-function'.")
(make-variable-buffer-local 'semantic-unmatched-syntax-cache-check)
`top-level' comments.")
(defvar semantic-unmatched-syntax-hook nil
- "Hooks run when semantic detects syntax not matched in a grammar.
+ "Hooks run when Semantic detects syntax not matched in a grammar.
Each individual piece of syntax (such as a symbol or punctuation
character) is called with this hook when it doesn't match in the
grammar, and multiple unmatched syntax elements are not grouped
-together. Each hook is called with one argument, which is a list of
-syntax tokens created by the semantic lexer. Use the functions
+together. Each hook is called with one argument, which is a list
+of syntax tokens created by the semantic lexer. Use the functions
`semantic-lex-token-start', `semantic-lex-token-end' and
-`semantic-lex-token-text' to get information about these tokens. The
-current buffer is the buffer these tokens are derived from.")
+`semantic-lex-token-text' to get information about these tokens.
+The current buffer is the buffer these tokens are derived from.")
(defvar semantic--before-fetch-tags-hook nil
- "Hooks run before a buffer is parses for tags.
+ "Hooks run before a buffer is parsed for tags.
It is called before any request for tags is made via the function
`semantic-fetch-tags' by an application.
If any hook returns a nil value, the cached value is returned
immediately, even if it is empty.")
(semantic-varalias-obsolete 'semantic-before-toplevel-bovination-hook
- 'semantic--before-fetch-tags-hook)
+ 'semantic--before-fetch-tags-hook "23.2")
(defvar semantic-after-toplevel-bovinate-hook nil
"Hooks run after a toplevel parse.
This hook should not be used any more.
Use `semantic-after-toplevel-cache-change-hook' instead.")
-(make-obsolete-variable 'semantic-after-toplevel-bovinate-hook nil)
+(make-obsolete-variable 'semantic-after-toplevel-bovinate-hook nil "23.2")
(defvar semantic-after-toplevel-cache-change-hook nil
"Hooks run after the buffer tag list has changed.
:group 'semantic
:type 'hook)
+(defcustom semantic-new-buffer-setup-functions
+ '((c-mode . semantic-default-c-setup)
+ (c++-mode . semantic-default-c-setup)
+ (html-mode . semantic-default-html-setup)
+ (java-mode . wisent-java-default-setup)
+ (js-mode . wisent-javascript-setup-parser)
+ (python-mode . wisent-python-default-setup)
+ (scheme-mode . semantic-default-scheme-setup)
+ (srecode-template-mode . srecode-template-setup-parser)
+ (makefile-automake-mode . semantic-default-make-setup)
+ (makefile-gmake-mode . semantic-default-make-setup)
+ (makefile-makepp-mode . semantic-default-make-setup)
+ (makefile-bsdmake-mode . semantic-default-make-setup)
+ (makefile-imake-mode . semantic-default-make-setup)
+ (makefile-mode . semantic-default-make-setup))
+ "Alist of functions to call to set up Semantic parsing in the buffer.
+Each element has the form (MODE . FN), where MODE is a value of
+`major-mode' for the buffer and FN is the corresponding function
+to call, with no arguments, to set up the parser.
+
+These functions are called by `semantic-new-buffer-fcn', before
+`semantic-inhibit-functions'."
+ :group 'semantic
+ :type '(alist :key-type symbol :value-type function))
+
(defvar semantic-init-hook nil
"Hook run when a buffer is initialized with a parsing table.")
a parse of the buffer.")
(semantic-varalias-obsolete 'semantic-init-hooks
- 'semantic-init-hook)
+ 'semantic-init-hook "23.2")
(semantic-varalias-obsolete 'semantic-init-mode-hooks
- 'semantic-init-mode-hook)
+ 'semantic-init-mode-hook "23.2")
(semantic-varalias-obsolete 'semantic-init-db-hooks
- 'semantic-init-db-hook)
+ 'semantic-init-db-hook "23.2")
(defvar semantic-new-buffer-fcn-was-run nil
- "Non nil after `semantic-new-buffer-fcn' has been executed.")
+ "Non-nil after `semantic-new-buffer-fcn' has been executed.")
(make-variable-buffer-local 'semantic-new-buffer-fcn-was-run)
(defsubst semantic-active-p ()
(defsubst semantic--umatched-syntax-needs-refresh-p ()
"Return non-nil if the unmatched syntax cache needs a refresh.
-That is if it is dirty or if the current parse tree isn't up to date."
+That is, if it is dirty or if the current parse tree isn't up to date."
(or semantic-unmatched-syntax-cache-check
(not (semantic-parse-tree-up-to-date-p))))
If the major mode is ready for Semantic, and no
`semantic-inhibit-functions' disabled it, the current buffer is setup
to use Semantic, and `semantic-init-hook' is run."
+ ;; In upstream Semantic, the parser setup functions are called from
+ ;; mode hooks. In the version bundled with Emacs, we do it here.
+ (let ((entry (assq major-mode semantic-new-buffer-setup-functions)))
+ (when entry
+ (funcall (cdr entry))))
;; Do stuff if semantic was activated by a mode hook in this buffer,
;; and not afterwards disabled.
(when (and semantic--parse-table
Do not set this yourself. Call `semantic-debug'.")
(defun semantic-elapsed-time (start end)
- "Copied from elp.el. Was elp-elapsed-time.
+ "Copied from elp.el. Was `elp-elapsed-time'.
Argument START and END bound the time being calculated."
(+ (* (- (car end) (car start)) 65536.0)
(- (car (cdr end)) (car (cdr start)))
(define-overloadable-function semantic-parse-stream (stream nonterminal)
"Parse STREAM, starting at the first NONTERMINAL rule.
For bovine and wisent based parsers, STREAM is from the output of
-`semantic-lex', and NONTERMINAL is a rule in the apropriate language
+`semantic-lex', and NONTERMINAL is a rule in the appropriate language
specific rules file.
The default parser table used for bovine or wisent based parsers is
`semantic--parse-table'.
Must return a list: (STREAM TAGS) where STREAM is the unused elements
-from STREAM, and TAGS is the list of semantic tags found, usually only
-one tag is returned with the exception of compound statements")
+from STREAM, and TAGS is the list of semantic tags found; usually only
+one tag is returned with the exception of compound statements.")
(define-overloadable-function semantic-parse-changes ()
"Reparse changes in the current buffer.
Optional arguments:
NONTERMINAL is the rule to start parsing at.
-DEPTH specifies the lexical depth to decend for parser that use
+DEPTH specifies the lexical depth to descend for parser that use
lexical analysis as their first step.
RETURNONERROR specifies that parsing should stop on the first
unmatched syntax encountered. When nil, parsing skips the syntax,
(defun semantic-parse-region-default
(start end &optional nonterminal depth returnonerror)
"Parse the area between START and END, and return any tags found.
-If END needs to be extended due to a lexical token being too large, it
-will be silently ignored.
+If END needs to be extended due to a lexical token being too large,
+it will be silently ignored.
Optional arguments:
NONTERMINAL is the rule to start parsing at if it is known.
DEPTH specifies the lexical depth to scan.
(defvar semantic-bovinate-nonterminal-check-obarray)
(defun semantic--set-buffer-cache (tagtable)
- "Set the toplevel cache cache to TAGTABLE."
+ "Set the toplevel tag cache to TAGTABLE."
(setq semantic--buffer-cache tagtable
semantic-unmatched-syntax-cache-check nil)
;; This is specific to the bovine parser.
'percent means we are doing a linear parse through the buffer.
'dynamic means we are reparsing specific tags.")
(semantic-varalias-obsolete 'semantic-bovination-working-type
- 'semantic-working-type)
+ 'semantic-working-type "23.2")
(defvar semantic-minimum-working-buffer-size (* 1024 5)
"*The minimum size of a buffer before working messages are displayed.
-Buffers smaller than will parse silently.
-Bufferse larger than this will display the working progress bar.")
+Buffers smaller than this will parse silently.
+Buffers larger than this will display the working progress bar.")
(defsubst semantic-parser-working-message (&optional arg)
"Return the message string displayed while parsing.
If the buffer cache is out of date, attempt an incremental reparse.
If the buffer has not been parsed before, or if the incremental reparse
fails, then parse the entire buffer.
-If a lexcial error had been previously discovered and the buffer
+If a lexical error had been previously discovered and the buffer
was marked unparseable, then do nothing, and return the cache."
(and
;; Is this a semantic enabled buffer?
semantic--buffer-cache)
(defun semantic-refresh-tags-safe ()
- "Refreshes the current buffer's tags safely.
+ "Refresh the current buffer's tags safely.
Return non-nil if the refresh was successful.
Return nil if there is some sort of syntax error preventing a reparse.
lexically-safe))))
(defun semantic-bovinate-toplevel (&optional ignored)
- "Backward Compatibility Function."
+ "Backward compatibility function."
(semantic-fetch-tags))
-(make-obsolete 'semantic-bovinate-toplevel 'semantic-fetch-tags)
+(make-obsolete 'semantic-bovinate-toplevel 'semantic-fetch-tags "23.2")
;; Another approach is to let Emacs call the parser on idle time, when
;; needed, use `semantic-fetch-available-tags' to only retrieve
commands, use `semantic-bovinate-from-nonterminal-full'."
(semantic-parse-region start end nonterm depth t))
(make-obsolete 'semantic-bovinate-region-until-error
- 'semantic-parse-region)
+ 'semantic-parse-region "23.2")
(defsubst semantic-bovinate-from-nonterminal
(start end nonterm &optional depth length)
a START and END part."
(semantic-parse-region start end nonterm (or depth 1)))
(make-obsolete 'semantic-bovinate-from-nonterminal-full
- 'semantic-parse-region)
+ 'semantic-parse-region "23.2")
;;; User interface
'(menu-item "Show Tag Completions" global-semantic-idle-completions-mode
:help "Show tag completions when idle"
:visible semantic-mode
+ :enable global-semantic-idle-scheduler-mode
:button (:toggle . global-semantic-idle-completions-mode)))
(define-key cedet-menu-map [global-semantic-idle-summary-mode]
'(menu-item "Show Tag Summaries" global-semantic-idle-summary-mode
:help "Show tag summaries when idle"
:visible semantic-mode
+ :enable global-semantic-idle-scheduler-mode
:button (:toggle . global-semantic-idle-summary-mode)))
- (define-key cedet-menu-map [global-semanticdb-minor-mode]
- '(menu-item "Semantic Database" global-semanticdb-minor-mode
- :help "Store tag information in a database"
- :visible semantic-mode
- :button (:toggle . global-semanticdb-minor-mode)))
(define-key cedet-menu-map [global-semantic-idle-scheduler-mode]
'(menu-item "Reparse When Idle" global-semantic-idle-scheduler-mode
:help "Keep a buffer's parse tree up to date when idle"
:visible semantic-mode
:button (:toggle . global-semantic-idle-scheduler-mode)))
- (define-key cedet-menu-map [ede-menu-separator] 'undefined)
- (define-key cedet-menu-map [cedet-menu-separator] 'undefined)
- (define-key cedet-menu-map [semantic-menu-separator] '("--")))
+ (define-key cedet-menu-map [global-semanticdb-minor-mode]
+ '(menu-item "Semantic Database" global-semanticdb-minor-mode
+ :help "Store tag information in a database"
+ :visible semantic-mode
+ :button (:toggle . global-semanticdb-minor-mode))))
;; The `semantic-mode' command, in conjuction with the
;; `semantic-default-submodes' variable, toggles Semantic's various
-;; auxilliary minor modes.
+;; auxiliary minor modes.
(defvar semantic-load-system-cache-loaded nil
- "Non nil when the Semantic system caches have been loaded.
+ "Non-nil when the Semantic system caches have been loaded.
Prevent this load system from loading files in twice.")
(defconst semantic-submode-list
global-semanticdb-minor-mode
global-semantic-idle-summary-mode
global-semantic-mru-bookmark-mode)
- "List of auxilliary minor modes in the Semantic package.")
+ "List of auxiliary minor modes in the Semantic package.")
;;;###autoload
(defcustom semantic-default-submodes
'(global-semantic-idle-scheduler-mode global-semanticdb-minor-mode)
- "List of auxilliary Semantic minor modes enabled by `semantic-mode'.
+ "List of auxiliary Semantic minor modes enabled by `semantic-mode'.
The possible elements of this list include the following:
- `semantic-highlight-func-mode' - Highlight the current tag.
- `semantic-decoration-mode' - Decorate tags based on various attributes.
- `semantic-stickyfunc-mode' - Track current function in the header-line.
- `semantic-idle-completions-mode' - Provide smart symbol completion
- automatically when idle.
- `semantic-idle-scheduler-mode' - Keep a buffer's parse tree up to date.
- `semanticdb-minor-mode' - Store tags when a buffer is not in memory.
- `semantic-idle-summary-mode' - Show a summary for the code at point.
- `semantic-mru-bookmark-mode' - Provide `switch-to-buffer'-like
- keybinding for tag names."
+ `global-semanticdb-minor-mode' - Maintain tag database.
+ `global-semantic-idle-scheduler-mode' - Reparse buffer when idle.
+ `global-semantic-idle-summary-mode' - Show summary of tag at point.
+ `global-semantic-idle-completions-mode' - Show completions when idle.
+ `global-semantic-decoration-mode' - Additional tag decorations.
+ `global-semantic-highlight-func-mode' - Highlight the current tag.
+ `global-semantic-stickyfunc-mode' - Show current fun in header line.
+ `global-semantic-mru-bookmark-mode' - Provide `switch-to-buffer'-like
+ keybinding for tag names."
:group 'semantic
:type `(set ,@(mapcar (lambda (c) (list 'const c))
semantic-submode-list)))
In Semantic mode, Emacs parses the buffers you visit for their
semantic content. This information is used by a variety of
-auxilliary minor modes, listed in `semantic-default-submodes';
+auxiliary minor modes, listed in `semantic-default-submodes';
all the minor modes in this list are also enabled when you enable
Semantic mode.
(if semantic-mode
;; Turn on Semantic mode
(progn
- ;; Enable all the global auxilliary minor modes in
+ ;; Enable all the global auxiliary minor modes in
;; `semantic-submode-list'.
(dolist (mode semantic-submode-list)
(if (memq mode semantic-default-submodes)
(require 'semantic/db-ebrowse)
(semanticdb-load-ebrowse-caches)))
(add-hook 'mode-local-init-hook 'semantic-new-buffer-fcn)
- ;; Add mode-local hooks
- (add-hook 'javascript-mode-hook 'wisent-javascript-setup-parser)
- (add-hook 'ecmascript-mode-hook 'wisent-javascript-setup-parser)
- (add-hook 'java-mode-hook 'wisent-java-default-setup)
- (add-hook 'scheme-mode-hook 'semantic-default-scheme-setup)
- (add-hook 'makefile-mode-hook 'semantic-default-make-setup)
- (add-hook 'c-mode-hook 'semantic-default-c-setup)
- (add-hook 'c++-mode-hook 'semantic-default-c-setup)
- (add-hook 'html-mode-hook 'semantic-default-html-setup))
+ (if global-ede-mode
+ (define-key cedet-menu-map [cedet-menu-separator] '("--")))
+ (dolist (b (buffer-list))
+ (with-current-buffer b
+ (semantic-new-buffer-fcn))))
;; Disable all Semantic features.
(remove-hook 'mode-local-init-hook 'semantic-new-buffer-fcn)
- (remove-hook 'javascript-mode-hook 'wisent-javascript-setup-parser)
- (remove-hook 'ecmascript-mode-hook 'wisent-javascript-setup-parser)
- (remove-hook 'java-mode-hook 'wisent-java-default-setup)
- (remove-hook 'scheme-mode-hook 'semantic-default-scheme-setup)
- (remove-hook 'makefile-mode-hook 'semantic-default-make-setup)
- (remove-hook 'c-mode-hook 'semantic-default-c-setup)
- (remove-hook 'c++-mode-hook 'semantic-default-c-setup)
- (remove-hook 'html-mode-hook 'semantic-default-html-setup)
-
+ (define-key cedet-menu-map [cedet-menu-separator] nil)
+ (define-key cedet-menu-map [semantic-options-separator] nil)
;; FIXME: handle semanticdb-load-ebrowse-caches
(dolist (mode semantic-submode-list)
(if (and (boundp mode) (eval mode))
the current buffer was set up for parsing. Return non-nil if the
minor mode is enabled." t nil)
+(autoload 'srecode-template-setup-parser "srecode/srecode-template"
+ "Set up buffer for parsing SRecode template files." t nil)
+
(provide 'semantic)
;; Semantic-util is a part of the semantic API. Include it last
;; (require 'semantic/load)
+;; arch-tag: 31583e10-6508-41a9-be40-f83d0ae0a4ed
;;; semantic.el ends here