Function: srecode-document-insert-function-comment
srecode-document-insert-function-comment is an autoloaded, interactive
and byte-compiled function defined in document.el.gz.
Signature
(srecode-document-insert-function-comment &optional FCN-IN)
Documentation
Insert or replace a function comment.
FCN-IN is the Semantic tag of the function to add a comment too. If FCN-IN is not provided, the current tag is used instead. It is assumed that the comment occurs just in front of FCN-IN.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/cedet/srecode/document.el.gz
;;;###autoload
(defun srecode-document-insert-function-comment (&optional fcn-in)
"Insert or replace a function comment.
FCN-IN is the Semantic tag of the function to add a comment too.
If FCN-IN is not provided, the current tag is used instead.
It is assumed that the comment occurs just in front of FCN-IN."
(interactive)
(srecode-load-tables-for-mode major-mode)
(srecode-load-tables-for-mode major-mode 'document)
(if (not (srecode-table))
(error "No template table found for mode %s" major-mode))
(let* ((dict (srecode-create-dictionary))
(temp (srecode-template-get-table (srecode-table)
"function-comment"
"declaration"
'document)))
(if (not temp)
(error "No templates for inserting function comments"))
;; Try to figure out the tag we want to use.
(when (not fcn-in)
(semantic-fetch-tags)
(setq fcn-in (semantic-current-tag)))
(when (or (not fcn-in)
(not (semantic-tag-of-class-p fcn-in 'function)))
(error "No tag of class `function' to insert comment for"))
(if (not (eq (current-buffer) (semantic-tag-buffer fcn-in)))
(error "Only insert comments for tags in the current buffer"))
;; Find any existing doc strings.
(semantic-go-to-tag fcn-in)
(beginning-of-line)
(forward-char -1)
(let ((lextok (semantic-documentation-comment-preceding-tag fcn-in 'lex))
(doctext
(srecode-document-function-name-comment fcn-in))
)
(when lextok
(let* ((s (semantic-lex-token-start lextok))
(e (semantic-lex-token-end lextok))
(plaintext
(srecode-document-trim-whitespace
(save-excursion
(goto-char s)
(semantic-doc-snarf-comment-for-tag nil))))
(extract (condition-case nil
(srecode-extract temp s e)
(error nil))
)
(distance (count-lines e (semantic-tag-start fcn-in)))
(belongelsewhere (save-excursion
(goto-char s)
(back-to-indentation)
(semantic-current-tag)))
)
(when (not belongelsewhere)
(pulse-momentary-highlight-region s e)
;; There are many possible states that comment could be in.
;; Take a guess about what the user would like to do, and ask
;; the right kind of question.
(when (or (not (> distance 2))
(y-or-n-p "Replace this comment? "))
(when (> distance 2)
(goto-char e)
(delete-horizontal-space)
(delete-blank-lines))
(cond
((and plaintext (not extract))
(if (y-or-n-p "Convert old-style comment to Template with old text? ")
(setq doctext plaintext))
(delete-region s e)
(goto-char s))
(extract
(when (y-or-n-p "Refresh pre-existing comment (recycle old doc)? ")
(delete-region s e)
(goto-char s)
(setq doctext
(srecode-document-trim-whitespace
(srecode-dictionary-lookup-name extract "DOC")))))
))
)))
(beginning-of-line)
;; Perform the insertion
(let ((srecode-semantic-selected-tag fcn-in)
(srecode-semantic-apply-tag-augment-hook
(lambda (tag dict)
(srecode-dictionary-set-value
dict "DOC"
(if (eq tag fcn-in)
doctext
(srecode-document-parameter-comment tag))
)))
)
(srecode-insert-fcn temp dict)
))
))