123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- (require 'semantic/tag)
- (define-overloadable-function semantic-documentation-for-tag (&optional tag nosnarf)
- "Find documentation from TAG and return it as a clean string.
- TAG might have DOCUMENTATION set in it already. If not, there may be
- some documentation in a comment preceding TAG's definition which we
- can look for. When appropriate, this can be overridden by a language specific
- enhancement.
- Optional argument NOSNARF means to only return the lexical analyzer token for it.
- If nosnarf if 'lex, then only return the lex token."
- (if (not tag) (setq tag (semantic-current-tag)))
- (save-excursion
- (when (semantic-tag-with-position-p tag)
- (set-buffer (semantic-tag-buffer tag)))
- (:override
-
- (save-excursion
- (semantic-go-to-tag tag)
- (let ((doctmp (semantic-tag-docstring tag (current-buffer))))
- (or
-
- doctmp
-
- (when (semantic-tag-with-position-p tag)
- (semantic-documentation-comment-preceeding-tag tag nosnarf))
-
-
- nil))))))
- (defun semantic-documentation-comment-preceeding-tag (&optional tag nosnarf)
- "Find a comment preceding TAG.
- If TAG is nil. use the tag under point.
- Searches the space between TAG and the preceding tag for a comment,
- and converts the comment into clean documentation.
- Optional argument NOSNARF with a value of 'lex means to return
- just the lexical token and not the string."
- (if (not tag) (setq tag (semantic-current-tag)))
- (save-excursion
-
- (semantic-go-to-tag tag)
- (let* ((starttag (semantic-find-tag-by-overlay-prev
- (semantic-tag-start tag)))
- (start (if starttag
- (semantic-tag-end starttag)
- (point-min))))
- (when (and comment-start-skip
- (re-search-backward comment-start-skip start t))
-
-
- (semantic-doc-snarf-comment-for-tag nosnarf)))
- ))
- (defun semantic-doc-snarf-comment-for-tag (nosnarf)
- "Snarf up the comment at POINT for `semantic-documentation-for-tag'.
- Attempt to strip out comment syntactic sugar.
- Argument NOSNARF means don't modify the found text.
- If NOSNARF is 'lex, then return the lex token."
- (let* ((semantic-ignore-comments nil)
- (semantic-lex-analyzer #'semantic-comment-lexer))
- (if (memq nosnarf '(lex flex))
- (car (semantic-lex (point) (1+ (point))))
- (let ((ct (semantic-lex-token-text
- (car (semantic-lex (point) (1+ (point)))))))
- (if nosnarf
- nil
-
-
- (while (string-match (concat "^\\s-*" comment-start-skip) ct)
- (setq ct (concat (substring ct 0 (match-beginning 0))
- (substring ct (match-end 0)))))
-
- (while (string-match "^\\s-*\\s.+\\s-*" ct)
- (setq ct (concat (substring ct 0 (match-beginning 0))
- (substring ct (match-end 0)))))
-
- (if (and (boundp 'block-comment-end)
- block-comment-end
- (string-match block-comment-end ct))
- (setq ct (concat (substring ct 0 (match-beginning 0))
- (substring ct (match-end 0)))))
-
- (while (string-match "\\s-*\\s\"+\\s-*" ct)
- (setq ct (concat (substring ct 0 (match-beginning 0))
- (substring ct (match-end 0))))))
-
- ct))))
- (provide 'semantic/doc)
|