123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448 |
- (require 'semantic/analyze)
- (require 'semantic/format)
- (require 'pulse)
- (eval-when-compile
- (require 'semantic/analyze)
- (require 'semantic/analyze/refs)
- (require 'semantic/find))
- (declare-function imenu--mouse-menu "imenu")
- (defcustom semantic-ia-completion-format-tag-function
- 'semantic-format-tag-prototype
- "Function used to convert a tag to a string during completion."
- :group 'semantic
- :type semantic-format-tag-custom-list)
- (define-overloadable-function semantic-ia-insert-tag (tag)
- "Insert TAG into the current buffer based on completion.")
- (defun semantic-ia-insert-tag-default (tag)
- "Insert TAG into the current buffer based on completion."
- (insert (semantic-tag-name tag))
- (let ((tt (semantic-tag-class tag)))
- (cond ((eq tt 'function)
- (insert "("))
- (t nil))))
- (defalias 'semantic-ia-get-completions 'semantic-ia-get-completions-deprecated
- "`Semantic-ia-get-completions' is obsolete.
- Use `semantic-analyze-possible-completions' instead.")
- (defun semantic-ia-get-completions-deprecated (context point)
- "A function to help transition away from `semantic-ia-get-completions'.
- Return completions based on CONTEXT at POINT.
- You should not use this, nor the aliased version.
- Use `semantic-analyze-possible-completions' instead."
- (semantic-analyze-possible-completions context))
- (defun semantic-ia-complete-symbol (&optional pos)
- "Complete the current symbol at POS.
- If POS is nil, default to point.
- Completion options are calculated with `semantic-analyze-possible-completions'."
- (interactive "d")
- (when (semantic-active-p)
- (or pos (setq pos (point)))
-
-
-
-
-
-
- (let* ((a (semantic-analyze-current-context pos))
- (syms (semantic-analyze-possible-completions a))
- (pre (car (reverse (oref a prefix)))))
-
-
- (if (semantic-tag-p pre)
-
- (setq pre (semantic-tag-name pre)))
-
- (if (null syms)
- (if (semantic-analyze-context-p a)
-
-
-
-
-
-
- (semantic-complete-symbol))
-
- (let ((tc (try-completion (or pre "") syms)))
- (if (and (stringp tc) (not (string= tc (or pre ""))))
- (let ((tok (semantic-find-first-tag-by-name
- tc syms)))
-
- (when (and (car (oref a bounds)) (cdr (oref a bounds)))
- (delete-region (car (oref a bounds))
- (cdr (oref a bounds)))
- (goto-char (car (oref a bounds))))
-
- (if tok
- (semantic-ia-insert-tag tok)
- (insert tc)))
-
- (when (cdr (oref a bounds))
- (goto-char (cdr (oref a bounds))))
- (with-output-to-temp-buffer "*Completions*"
- (display-completion-list
- (mapcar semantic-ia-completion-format-tag-function syms)))))))))
- (defcustom semantic-ia-completion-menu-format-tag-function
- 'semantic-uml-concise-prototype-nonterminal
- "*Function used to convert a tag to a string during completion."
- :group 'semantic
- :type semantic-format-tag-custom-list)
- (defun semantic-ia-complete-tip (point)
- "Pop up a tooltip for completion at POINT."
- (interactive "d")
- (let* ((a (semantic-analyze-current-context point))
- (syms (semantic-analyze-possible-completions a))
- (x (mod (- (current-column) (window-hscroll))
- (window-width)))
- (y (save-excursion
- (save-restriction
- (widen)
- (narrow-to-region (window-start) (point))
- (goto-char (point-min))
- (1+ (vertical-motion (buffer-size))))))
- (str (mapconcat #'semantic-tag-name
- syms
- "\n"))
- )
- (cond ((fboundp 'x-show-tip)
- (x-show-tip str
- (selected-frame)
- nil
- nil
- x y)
- )
- (t (message str))
- )))
- (defun semantic-ia-show-summary (point)
- "Display a summary for the symbol under POINT."
- (interactive "P")
- (let* ((ctxt (semantic-analyze-current-context point))
- (pf (when ctxt
-
-
-
- (semantic-analyze-interesting-tag ctxt)))
- )
- (if pf
- (message "%s" (semantic-format-tag-summarize pf nil t))
- (message "No summary info available"))))
- (defun semantic-ia-show-variants (point)
- "Display a list of all variants for the symbol under POINT."
- (interactive "P")
- (let* ((ctxt (semantic-analyze-current-context point))
- (comp nil))
-
-
-
- (when (semantic-analyze-context-functionarg-p ctxt)
- (goto-char (cdr (oref ctxt bounds)))
- (setq ctxt (semantic-analyze-current-context (point))))
-
-
- (setq comp (semantic-analyze-possible-completions ctxt 'no-unique 'no-tc))
-
- (when (and (= (length comp) 1) (semantic-tag-of-class-p (car comp) 'type))
- (setq comp (semantic-find-tags-by-name (semantic-tag-name (car comp))
- (semantic-tag-type-members (car comp)))))
-
- (cond ((= (length comp) 0)
- (message "No Variants found."))
- ((= (length comp) 1)
- (message "%s" (semantic-format-tag-summarize (car comp) nil t)))
- (t
- (with-output-to-temp-buffer "*Symbol Variants*"
- (semantic-analyze-princ-sequence comp "" (current-buffer)))
- (shrink-window-if-larger-than-buffer
- (get-buffer-window "*Symbol Variants*")))
- )))
- (defun semantic-ia--fast-jump-helper (dest)
- "Jump to DEST, a Semantic tag.
- This helper manages the mark, buffer switching, and pulsing."
-
-
-
- (when (semantic-tag-prototype-p dest)
- (let* ((refs (semantic-analyze-tag-references dest))
- (impl (semantic-analyze-refs-impl refs t))
- )
- (when impl (setq dest (car impl)))))
-
- (if (not (and (or (semantic-tag-with-position-p dest)
- (semantic-tag-get-attribute dest :line))
- (semantic-tag-file-name dest)))
- (error "Tag %s has no buffer information"
- (semantic-format-tag-name dest)))
-
-
-
-
- (push-mark)
- (when (fboundp 'push-tag-mark)
- (push-tag-mark))
-
- (semantic-go-to-tag dest)
-
-
- (switch-to-buffer (current-buffer))
-
- (pulse-momentary-highlight-one-line (point))
- )
- (declare-function semantic-decoration-include-visit "semantic/decorate/include")
- (defun semantic-ia-fast-jump (point)
- "Jump to the tag referred to by the code at POINT.
- Uses `semantic-analyze-current-context' output to identify an accurate
- origin of the code at point."
- (interactive "d")
- (let* ((ctxt (semantic-analyze-current-context point))
- (pf (and ctxt (reverse (oref ctxt prefix))))
-
-
-
-
-
-
-
-
-
-
- (first (car pf))
- (second (nth 1 pf))
- )
- (cond
- ((semantic-tag-p first)
-
- (semantic-ia--fast-jump-helper first))
- ((semantic-tag-p second)
-
-
-
-
-
- (let ((secondclass (car (reverse (oref ctxt prefixtypes)))))
- (cond
- ((and (semantic-tag-with-position-p secondclass)
- (y-or-n-p (format "Could not find `%s'. Jump to %s? "
- first (semantic-tag-name secondclass))))
- (semantic-ia--fast-jump-helper secondclass)
- )
-
-
- ((and (semantic-tag-p second)
- (y-or-n-p (format "Could not find `%s'. Jump to %s? "
- first (semantic-tag-name second))))
- (semantic-ia--fast-jump-helper second)
- ))))
- ((semantic-tag-of-class-p (semantic-current-tag) 'include)
-
- (require 'semantic/decorate/include)
- (semantic-decoration-include-visit)
- )
- (t
- (error "Could not find suitable jump point for %s"
- first))
- )))
- (defun semantic-ia-fast-mouse-jump (evt)
- "Jump to the tag referred to by the point clicked on.
- See `semantic-ia-fast-jump' for details on how it works.
- This command is meant to be bound to a mouse event."
- (interactive "e")
- (semantic-ia-fast-jump
- (save-excursion
- (posn-set-point (event-end evt))
- (point))))
- (defun semantic-ia-show-doc (point)
- "Display the code-level documentation for the symbol at POINT."
- (interactive "d")
- (let* ((ctxt (semantic-analyze-current-context point))
- (pf (reverse (oref ctxt prefix)))
- )
-
-
-
- (cond
- ((stringp (car pf))
- (message "Incomplete symbol name."))
- ((semantic-tag-p (car pf))
-
-
-
-
-
-
- (let ((doc (semantic-documentation-for-tag (car pf))))
- (if (or (null doc) (string= doc ""))
- (message "Doc unavailable for: %s"
- (semantic-format-tag-prototype (car pf)))
- (with-output-to-temp-buffer "*TAG DOCUMENTATION*"
- (princ "Tag: ")
- (princ (semantic-format-tag-prototype (car pf)))
- (princ "\n")
- (princ "\n")
- (princ "Snarfed Documentation: ")
- (princ "\n")
- (princ "\n")
- (if doc
- (princ doc)
- (princ " Documentation unavailable."))
- ))))
- (t
- (message "Unknown tag.")))
- ))
- (defun semantic-ia-describe-class (typename)
- "Display all known parts for the datatype TYPENAME.
- If the type in question is a class, all methods and other accessible
- parts of the parent classes are displayed."
-
- (interactive "sType Name: ")
-
-
-
-
-
-
-
- (let ((class (semantic-analyze-find-tag typename)))
- (when (not (semantic-tag-p class))
- (error "Cannot find class %s" class))
- (with-output-to-temp-buffer "*TAG DOCUMENTATION*"
-
-
- (princ (semantic-format-tag-summarize class))
- (princ "\n")
- (princ " Type Members:\n")
-
-
-
-
-
- (let ((parts (semantic-analyze-scoped-type-parts class)))
- (while parts
- (princ " ")
- (princ (semantic-format-tag-summarize (car parts)))
- (princ "\n")
- (setq parts (cdr parts)))
- )
- )))
- (provide 'semantic/ia)
|