123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- (require 'semantic/db)
- (declare-function semantic-lex-spp-set-dynamic-table "semantic/lex-spp")
- (defvar semanticdb-hooks
- '((semanticdb-semantic-init-hook-fcn semantic-init-db-hook)
- (semanticdb-synchronize-table semantic-after-toplevel-cache-change-hook)
- (semanticdb-partial-synchronize-table semantic-after-partial-cache-change-hook)
- (semanticdb-revert-hook before-revert-hook)
- (semanticdb-kill-hook kill-buffer-hook)
- (semanticdb-kill-hook change-major-mode-hook)
- (semanticdb-kill-emacs-hook kill-emacs-hook)
- (semanticdb-save-all-db-idle auto-save-hook)
- )
- "List of hooks and values to add/remove when configuring semanticdb.")
- (defun semanticdb-minor-mode-p ()
- "Return non-nil if `semanticdb-minor-mode' is active."
- (member (car (car semanticdb-hooks))
- (symbol-value (car (cdr (car semanticdb-hooks))))))
- (define-minor-mode global-semanticdb-minor-mode
- "Toggle Semantic DB mode.
- With ARG, turn Semantic DB mode on if ARG is positive, off otherwise.
- In Semantic DB mode, Semantic parsers store results in a
- database, which can be saved for future Emacs sessions."
- :global t
- :group 'semantic
- (if global-semanticdb-minor-mode
-
- (dolist (elt semanticdb-hooks)
- (add-hook (cadr elt) (car elt)))
-
- (dolist (elt semanticdb-hooks)
- (add-hook (cadr elt) (car elt)))))
- (defvaralias 'semanticdb-mode-hook 'global-semanticdb-minor-mode-hook)
- (defvaralias 'semanticdb-global-mode 'global-semanticdb-minor-mode)
- (semantic-varalias-obsolete 'semanticdb-mode-hooks
- 'global-semanticdb-minor-mode-hook "23.2")
- (defun semanticdb-toggle-global-mode ()
- "Toggle use of the Semantic Database feature.
- Update the environment of Semantic enabled buffers accordingly."
- (interactive)
- (if (semanticdb-minor-mode-p)
-
- (semanticdb-save-all-db))
-
- (global-semanticdb-minor-mode))
- (defun semanticdb-semantic-init-hook-fcn ()
- "Function saved in `semantic-init-db-hook'.
- Sets up the semanticdb environment."
-
-
-
- (when (buffer-file-name)
- (let* ((ans (semanticdb-create-table-for-file (buffer-file-name)))
- (cdb (car ans))
- (ctbl (cdr ans))
- )
-
- (setq semanticdb-current-database cdb)
-
- (oset ctbl major-mode major-mode)
-
- (setq semanticdb-current-table ctbl)
-
- (if (or (not (slot-boundp ctbl 'tags)) (not (oref ctbl tags))
- (/= (or (oref ctbl pointmax) 0) (point-max))
- )
- (semantic-clear-toplevel-cache)
-
- (condition-case nil
- (semantic-set-unmatched-syntax-cache
- (oref ctbl unmatched-syntax))
- (unbound-slot
-
-
- (semantic-clear-unmatched-syntax-cache)
-
- (oset ctbl unmatched-syntax nil)
- ))
-
-
- (let ((lt (oref ctbl lexical-table)))
- (when lt
- (require 'semantic/lex-spp)
- (semantic-lex-spp-set-dynamic-table lt)))
-
-
-
- (semantic--set-buffer-cache (oref ctbl tags))
-
- (oset ctbl dirty nil)
- (oset ctbl buffer (current-buffer))
-
- (semantic--tag-link-cache-to-buffer)
- )
- )))
- (defun semanticdb-revert-hook ()
- "Hook run before a revert buffer.
- We can't track incremental changes due to a revert, so just clear the cache.
- This will prevent the next batch of hooks from wasting time parsing things
- that don't need to be parsed."
- (if (and (semantic-active-p)
- semantic--buffer-cache
- semanticdb-current-table)
- (semantic-clear-toplevel-cache)))
- (defun semanticdb-kill-hook ()
- "Function run when a buffer is killed.
- If there is a semantic cache, slurp out the overlays, and store
- it in our database. If that buffer has no cache, ignore it, we'll
- handle it later if need be."
- (when (and (semantic-active-p)
- semantic--buffer-cache
- semanticdb-current-table)
-
- (semantic-fetch-tags-fast)
-
- (if (semantic-parse-tree-needs-rebuild-p)
-
- (progn
- (semantic-clear-toplevel-cache)
- (oset semanticdb-current-table pointmax 0)
- (oset semanticdb-current-table fsize 0)
- (oset semanticdb-current-table lastmodtime nil)
- )
-
- (condition-case nil
- (progn
- (semantic--tag-unlink-cache-from-buffer)
-
- (oset semanticdb-current-table pointmax (point-max))
- (let ((fattr (file-attributes
- (semanticdb-full-filename
- semanticdb-current-table))))
- (oset semanticdb-current-table fsize (nth 7 fattr))
- (oset semanticdb-current-table lastmodtime (nth 5 fattr))
- (oset semanticdb-current-table buffer nil)
- ))
-
- (error
- (semantic-clear-toplevel-cache)
- (message "semanticdb: Failed to deoverlay tag cache.")))
- )
- ))
- (defun semanticdb-kill-emacs-hook ()
- "Function called when Emacs is killed.
- Save all the databases."
- (semanticdb-save-all-db))
- (defun semanticdb-synchronize-table (new-table)
- "Function run after parsing.
- Argument NEW-TABLE is the new table of tags."
- (when semanticdb-current-table
- (semanticdb-synchronize semanticdb-current-table new-table)))
- (defun semanticdb-partial-synchronize-table (new-table)
- "Function run after parsing.
- Argument NEW-TABLE is the new table of tags."
- (when semanticdb-current-table
- (semanticdb-partial-synchronize semanticdb-current-table new-table)))
- (provide 'semantic/db-mode)
|