Function: c-backward-comments

c-backward-comments is a byte-compiled function defined in cc-engine.el.gz.

Signature

(c-backward-comments)

Documentation

Move backward past all preceding whitespace and comments.

Line continuations, i.e. a backslashes followed by line breaks, are treated as whitespace. The line breaks that end line comments are considered to be the comment enders, so the point cannot be at the end of the same line to move over a line comment. Unlike c-backward-syntactic-ws, this function doesn't move back over preprocessor directives.

Note that this function might do hidden buffer changes. See the comment at the start of cc-engine.el for more info.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-engine.el.gz
(defsubst c-backward-comments ()
  "Move backward past all preceding whitespace and comments.
Line continuations, i.e. a backslashes followed by line breaks, are
treated as whitespace.  The line breaks that end line comments are
considered to be the comment enders, so the point cannot be at the end
of the same line to move over a line comment.  Unlike
`c-backward-syntactic-ws', this function doesn't move back over
preprocessor directives.

Note that this function might do hidden buffer changes.  See the
comment at the start of cc-engine.el for more info."

  (let ((start (point)))
    (while (and
	    ;; `forward-comment' in some emacsen (e.g. XEmacs 21.4)
	    ;; return t when moving backwards at bob.
	    (not (bobp))

	    (if (let (moved-comment)
		  (while
		      (and (not (setq moved-comment (c-forward-comment-minus-1)))
		      ;; Cope specifically with ^M^J here -
		      ;; forward-comment sometimes gets stuck after ^Ms,
		      ;; sometimes after ^M^J.
			   (or
			    (when (eq (char-before) ?\r)
			      (backward-char)
			      t)
			    (when (and (eq (char-before) ?\n)
				       (eq (char-before (1- (point))) ?\r))
			      (backward-char 2)
			      t))))
		  moved-comment)
		(if (looking-at "\\*/")
		    ;; Emacs <= 20 and XEmacs move back over the
		    ;; closer of a block comment that lacks an opener.
		    (progn (forward-char 2) nil)
		  t)

	      ;; XEmacs treats line continuations as whitespace but
	      ;; only in the backward direction, which seems a bit
	      ;; odd.  Anyway, this is necessary for Emacs.
	      (when (and (looking-at "[\n\r]")
			 (eq (char-before) ?\\)
			 (< (point) start))
		(backward-char)
		t))))))