123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439 |
- (require 'semantic)
- (eval-when-compile
- (require 'semantic/db-find)
-
-
- (require 'semantic/find))
- (declare-function data-debug-insert-stuff-list "data-debug")
- (declare-function data-debug-insert-thing "data-debug")
- (declare-function semantic-ctxt-current-symbol-and-bounds "semantic/ctxt")
- (defvar semantic-type-relation-separator-character '(".")
- "Character strings used to separate a parent/child relationship.
- This list of strings are used for displaying or finding separators
- in variable field dereferencing. The first character will be used for
- display. In C, a type field is separated like this: \"type.field\"
- thus, the character is a \".\". In C, and additional value of \"->\"
- would be in the list, so that \"type->field\" could be found.")
- (make-variable-buffer-local 'semantic-type-relation-separator-character)
- (defvar semantic-equivalent-major-modes nil
- "List of major modes which are considered equivalent.
- Equivalent modes share a parser, and a set of override methods.
- A value of nil means that the current major mode is the only one.")
- (make-variable-buffer-local 'semantic-equivalent-major-modes)
- (defun semantic-file-tag-table (file)
- "Return a tag table for FILE.
- If it is loaded, return the stream after making sure it's ok.
- If FILE is not loaded, check to see if `semanticdb' feature exists,
- and use it to get tags from files not in memory.
- If FILE is not loaded, and semanticdb is not available, find the file
- and parse it."
- (save-match-data
- (if (find-buffer-visiting file)
- (with-current-buffer (find-buffer-visiting file)
- (semantic-fetch-tags))
-
- (if (and (require 'semantic/db-mode)
- (semanticdb-minor-mode-p))
-
- (semanticdb-file-stream file)
-
- (with-current-buffer (find-file-noselect file)
- (semantic-fetch-tags))))))
- (semantic-alias-obsolete 'semantic-file-token-stream
- 'semantic-file-tag-table "23.2")
- (defun semantic-something-to-tag-table (something)
- "Convert SOMETHING into a semantic tag table.
- Something can be a tag with a valid BUFFER property, a tag table, a
- buffer, or a filename. If SOMETHING is nil return nil."
- (cond
-
- ((and (listp something)
- (semantic-tag-p (car something)))
- something)
-
- ((bufferp something)
- (with-current-buffer something
- (semantic-fetch-tags)))
-
- ((and (semantic-tag-with-position-p something)
- (semantic-tag-in-buffer-p something))
- (with-current-buffer (semantic-tag-buffer something)
- (semantic-fetch-tags)))
-
- ((and (semantic-tag-p something)
- (semantic-tag-file-name something)
- (file-exists-p (semantic-tag-file-name something)))
- (semantic-file-tag-table
- (semantic-tag-file-name something)))
-
- ((and (stringp something)
- (file-exists-p something))
- (semantic-file-tag-table something))
-
- ((and (featurep 'semantic/db)
- (semanticdb-minor-mode-p)
- (semanticdb-abstract-table-child-p something))
- (semanticdb-refresh-table something)
- (semanticdb-get-tags something))
-
- ((and (featurep 'semantic/db)
- (semanticdb-minor-mode-p)
- (require 'semantic/db-find)
- (semanticdb-find-results-p something))
- (semanticdb-strip-find-results something))
-
-
-
-
- (t nil)))
- (semantic-alias-obsolete 'semantic-something-to-stream
- 'semantic-something-to-tag-table "23.2")
- (defvar semantic-read-symbol-history nil
- "History for a symbol read.")
- (defun semantic-read-symbol (prompt &optional default stream filter)
- "Read a symbol name from the user for the current buffer.
- PROMPT is the prompt to use.
- Optional arguments:
- DEFAULT is the default choice. If no default is given, one is read
- from under point.
- STREAM is the list of tokens to complete from.
- FILTER is provides a filter on the types of things to complete.
- FILTER must be a function to call on each element."
- (if (not default) (setq default (thing-at-point 'symbol)))
- (if (not stream) (setq stream (semantic-fetch-tags)))
- (setq stream
- (if filter
- (semantic--find-tags-by-function filter stream)
- (semantic-brute-find-tag-standard stream)))
- (if (and default (string-match ":" prompt))
- (setq prompt
- (concat (substring prompt 0 (match-end 0))
- " (default: " default ") ")))
- (completing-read prompt stream nil t ""
- 'semantic-read-symbol-history
- default))
- (defun semantic-read-variable (prompt &optional default stream)
- "Read a variable name from the user for the current buffer.
- PROMPT is the prompt to use.
- Optional arguments:
- DEFAULT is the default choice. If no default is given, one is read
- from under point.
- STREAM is the list of tokens to complete from."
- (semantic-read-symbol
- prompt default
- (or (semantic-find-tags-by-class
- 'variable (or stream (current-buffer)))
- (error "No local variables"))))
- (defun semantic-read-function (prompt &optional default stream)
- "Read a function name from the user for the current buffer.
- PROMPT is the prompt to use.
- Optional arguments:
- DEFAULT is the default choice. If no default is given, one is read
- from under point.
- STREAM is the list of tags to complete from."
- (semantic-read-symbol
- prompt default
- (or (semantic-find-tags-by-class
- 'function (or stream (current-buffer)))
- (error "No local functions"))))
- (defun semantic-read-type (prompt &optional default stream)
- "Read a type name from the user for the current buffer.
- PROMPT is the prompt to use.
- Optional arguments:
- DEFAULT is the default choice. If no default is given, one is read
- from under point.
- STREAM is the list of tags to complete from."
- (semantic-read-symbol
- prompt default
- (or (semantic-find-tags-by-class
- 'type (or stream (current-buffer)))
- (error "No local types"))))
- (defun semantic-describe-tag (&optional tag)
- "Describe TAG in the minibuffer.
- If TAG is nil, describe the tag under the cursor."
- (interactive)
- (if (not tag) (setq tag (semantic-current-tag)))
- (semantic-fetch-tags)
- (if tag (message (semantic-format-tag-summarize tag))))
- (defun semantic-add-label (label value &optional tag)
- "Add a LABEL with VALUE on TAG.
- If TAG is not specified, use the tag at point."
- (interactive "sLabel: \nXValue (eval): ")
- (if (not tag)
- (progn
- (semantic-fetch-tags)
- (setq tag (semantic-current-tag))))
- (semantic--tag-put-property tag (intern label) value)
- (message "Added label %s with value %S" label value))
- (defun semantic-show-label (label &optional tag)
- "Show the value of LABEL on TAG.
- If TAG is not specified, use the tag at point."
- (interactive "sLabel: ")
- (if (not tag)
- (progn
- (semantic-fetch-tags)
- (setq tag (semantic-current-tag))))
- (message "%s: %S" label (semantic--tag-get-property tag (intern label))))
- (defun semantic-describe-buffer-var-helper (varsym buffer)
- "Display to standard out the value of VARSYM in BUFFER."
- (require 'data-debug)
- (let ((value (with-current-buffer buffer
- (symbol-value varsym))))
- (cond
- ((and (consp value)
- (< (length value) 10))
-
- (princ (format " %s: #<list of %d items>\n"
- varsym (length value)))
- (data-debug-insert-stuff-list
- value " " )
- )
- (t
-
- (data-debug-insert-thing
- value " " (concat " " (symbol-name varsym) ": "))
- ))))
- (defun semantic-describe-buffer ()
- "Describe the semantic environment for the current buffer."
- (interactive)
- (let ((buff (current-buffer))
- )
- (with-output-to-temp-buffer (help-buffer)
- (help-setup-xref (list #'semantic-describe-buffer)
- (called-interactively-p 'interactive))
- (with-current-buffer standard-output
- (princ "Semantic Configuration in ")
- (princ (buffer-name buff))
- (princ "\n\n")
- (princ "Buffer specific configuration items:\n")
- (let ((vars '(major-mode
- semantic-case-fold
- semantic-tag-expand-function
- semantic-parser-name
- semantic-parse-tree-state
- semantic-lex-analyzer
- semantic-lex-reset-hooks
- semantic-lex-syntax-modifications
- )))
- (dolist (V vars)
- (semantic-describe-buffer-var-helper V buff)))
- (princ "\nGeneral configuration items:\n")
- (let ((vars '(semantic-inhibit-functions
- semantic-init-hook
- semantic-init-db-hook
- semantic-unmatched-syntax-hook
- semantic--before-fetch-tags-hook
- semantic-after-toplevel-bovinate-hook
- semantic-after-toplevel-cache-change-hook
- semantic-before-toplevel-cache-flush-hook
- semantic-dump-parse
- semantic-type-relation-separator-character
- semantic-command-separation-character
- )))
- (dolist (V vars)
- (semantic-describe-buffer-var-helper V buff)))
- (princ "\n\n")
- (mode-local-describe-bindings-2 buff)
- )))
- )
- (defun semantic-assert-valid-token (tok)
- "Assert that TOK is a valid token."
- (if (semantic-tag-p tok)
- (if (semantic-tag-with-position-p tok)
- (let ((o (semantic-tag-overlay tok)))
- (if (and (semantic-overlay-p o)
- (not (semantic-overlay-live-p o)))
- (let ((debug-on-error t))
- (error "Tag %s is invalid!" (semantic-tag-name tok)))
-
- ))
-
- )
- (let ((debug-on-error t))
- (error "Not a semantic tag: %S" tok))))
- (defun semantic-sanity-check (&optional cache over notfirst)
- "Perform a sanity check on the current buffer.
- The buffer's set of overlays, and those overlays found via the cache
- are verified against each other.
- CACHE, and OVER are the semantic cache, and the overlay list.
- NOTFIRST indicates that this was not the first call in the recursive use."
- (interactive)
- (if (and (not cache) (not over) (not notfirst))
- (setq cache semantic--buffer-cache
- over (semantic-overlays-in (point-min) (point-max))))
- (while cache
- (let ((chil (semantic-tag-components-with-overlays (car cache))))
- (if (not (memq (semantic-tag-overlay (car cache)) over))
- (message "Tag %s not in buffer overlay list."
- (semantic-format-tag-concise-prototype (car cache))))
- (setq over (delq (semantic-tag-overlay (car cache)) over))
- (setq over (semantic-sanity-check chil over t))
- (setq cache (cdr cache))))
- (if (not notfirst)
-
- (let ((o nil))
- (while over
- (when (and (semantic-overlay-get (car over) 'semantic)
- (not (eq (semantic-overlay-get (car over) 'semantic)
- 'unmatched)))
- (setq o (cons (car over) o)))
- (setq over (cdr over)))
- (when (called-interactively-p 'any)
- (message "Remaining overlays: %S" o))))
- over)
- (defun semantic-find-tag-for-completion (prefix)
- "Find all tags with name starting with PREFIX.
- This uses `semanticdb' when available."
- (let (result ctxt)
-
- (condition-case nil
- (and (featurep 'semantic/analyze)
- (setq ctxt (semantic-analyze-current-context))
- (setq result (semantic-analyze-possible-completions ctxt)))
- (error nil))
- (or result
-
- (if (and (featurep 'semantic/db)
- (semanticdb-minor-mode-p)
- (require 'semantic/db-find))
- (semanticdb-fast-strip-find-results
- (semanticdb-deep-find-tags-for-completion prefix))
- (semantic-deep-find-tags-for-completion prefix (current-buffer))))))
- (defun semantic-complete-symbol (&optional predicate)
- "Complete the symbol under point, using Semantic facilities.
- When called from a program, optional arg PREDICATE is a predicate
- determining which symbols are considered."
- (interactive)
- (require 'semantic/ctxt)
- (let* ((start (car (nth 2 (semantic-ctxt-current-symbol-and-bounds
- (point)))))
- (pattern (regexp-quote (buffer-substring start (point))))
- collection completion)
- (when start
- (if (and semantic--completion-cache
- (eq (nth 0 semantic--completion-cache) (current-buffer))
- (= (nth 1 semantic--completion-cache) start)
- (save-excursion
- (goto-char start)
- (looking-at (nth 3 semantic--completion-cache))))
-
- (setq collection (nthcdr 4 semantic--completion-cache))
-
- (setq collection (semantic-find-tag-for-completion pattern))
- (setq semantic--completion-cache
- (append (list (current-buffer) start 0 pattern)
- collection))))
- (if (null collection)
- (let ((str (if pattern (format " for \"%s\"" pattern) "")))
- (if (window-minibuffer-p (selected-window))
- (minibuffer-message (format " [No completions%s]" str))
- (message "Can't find completion%s" str)))
- (setq completion (try-completion pattern collection predicate))
- (if (string= pattern completion)
- (let ((list (all-completions pattern collection predicate)))
- (setq list (sort list 'string<))
- (if (> (length list) 1)
- (with-output-to-temp-buffer "*Completions*"
- (display-completion-list list pattern))
-
- (let ((win (get-buffer-window "*Completions*" 0)))
- (if win (with-selected-window win (bury-buffer))))))
-
- (delete-region start (point))
- (insert completion)
-
- (let ((win (get-buffer-window "*Completions*" 0)))
- (if win (with-selected-window win (bury-buffer))))))))
- (provide 'semantic/util)
- (require 'semantic/util-modes)
|