Function: c-comment-indent

c-comment-indent is a byte-compiled function defined in cc-cmds.el.gz.

Signature

(c-comment-indent)

Documentation

Used by indent-for-comment to create and indent comments.

See c-indent-comment-alist for a description.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-cmds.el.gz
(defun c-comment-indent ()
  "Used by `indent-for-comment' to create and indent comments.
See `c-indent-comment-alist' for a description."
  (save-excursion
    (end-of-line)
    (c-save-buffer-state
	  ((eot (let ((lim (c-literal-limits (c-point 'bol) t)))
		  (or (when (consp lim)
			(goto-char (car lim))
			(when (looking-at "/[/*]")
			  (skip-chars-backward " \t")
			  (point)))
		      (progn
			(skip-chars-backward " \t")
			(point)))))
	   (line-type
	    (cond ((looking-at "^/[/*]")
		   'anchored-comment)
		  ((progn (beginning-of-line)
			  (eq (point) eot))
		   'empty-line)
		  ((progn (back-to-indentation)
			  (and (eq (char-after) ?})
			       (eq (point) (1- eot))))
		   'end-block)
		  ((and (looking-at "#[ \t]*\\(endif\\|else\\)")
			(eq (match-end 0) eot))
		   'cpp-end-block)
		  (t
		   'other)))
	   case-fold-search)
      (if (and (memq line-type '(anchored-comment empty-line))
	       c-indent-comments-syntactically-p)
	  (let ((c-syntactic-context (c-guess-basic-syntax)))
	    ;; BOGOSITY ALERT: if we're looking at the eol, its
	    ;; because indent-for-comment hasn't put the comment-start
	    ;; in the buffer yet.  this will screw up the syntactic
	    ;; analysis so we kludge in the necessary info.  Another
	    ;; kludge is that if we're at the bol, then we really want
	    ;; to ignore any anchoring as specified by
	    ;; c-comment-only-line-offset since it doesn't apply here.
	    (if (eolp)
		(c-add-syntax 'comment-intro))
	    (let ((c-comment-only-line-offset
		   (if (consp c-comment-only-line-offset)
		       c-comment-only-line-offset
		     (cons c-comment-only-line-offset
			   c-comment-only-line-offset))))
	      (c-get-syntactic-indentation c-syntactic-context)))
	(goto-char eot)
	(c-calc-comment-indent line-type)))))