Function: c-end-of-statement
c-end-of-statement is an interactive and byte-compiled function
defined in cc-cmds.el.gz.
Signature
(c-end-of-statement &optional COUNT LIM SENTENCE-FLAG)
Documentation
Go to the end of the innermost C statement.
With prefix arg, go forward N - 1 statements. Move forward to the end
of the next statement if already at end, and move into nested blocks
(use C-M-f (forward-sexp) to skip over a block). If within or next to a
comment or multiline string, move by sentences instead of statements.
When called from a program, this function takes 3 optional args: the repetition count, a buffer position limit which is the farthest back to search for the syntactic context, and a flag saying whether to do sentence motion in or near comments and multiline strings.
Probably introduced at or before Emacs version 19.20.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-cmds.el.gz
(defun c-end-of-statement (&optional count lim sentence-flag)
"Go to the end of the innermost C statement.
With prefix arg, go forward N - 1 statements. Move forward to the end
of the next statement if already at end, and move into nested blocks
\(use \\[forward-sexp] to skip over a block). If within or next to a
comment or multiline string, move by sentences instead of statements.
When called from a program, this function takes 3 optional args: the
repetition count, a buffer position limit which is the farthest back
to search for the syntactic context, and a flag saying whether to do
sentence motion in or near comments and multiline strings."
(interactive (list (prefix-numeric-value current-prefix-arg)
nil t))
(setq count (or count 1))
(if (< count 0) (c-beginning-of-statement (- count) lim sentence-flag)
(c-save-buffer-state
(here ; start point for going forward ONE statement. Updated each statement.
(macro-fence
(save-excursion
(and (not (eobp)) (c-beginning-of-macro)
(progn (c-end-of-macro) (point)))))
res
(range (c-collect-line-comments (c-literal-limits lim)))) ; (start.end) of current literal or NIL
;; Go back/forward one statement at each iteration of the following loop.
(while (and (/= count 0)
(or (not lim) (< (point) lim)))
(setq here (point)) ; ONLY HERE is HERE updated
;; Go forward one "chunk" each time round the following loop, stopping
;; when we reach a statement boundary, etc.
(while
(cond ; Each arm of this cond returns NIL on reaching a desired
; statement boundary, non-NIL otherwise.
((eobp)
(setq count 0)
nil)
(range ; point is within a literal.
(cond
;; sentence-flag is null => skip the entire literal.
;; or a Single line string.
((or (null sentence-flag)
(c-one-line-string-p range))
(goto-char (cdr range))
(setq range (c-ascertain-following-literal))
;; Is there a virtual semicolon here (e.g. for AWK)?
(not (c-at-vsemi-p)))
;; Comment or multi-line string.
(t (when (setq res ; gets non-nil when we go out of the literal
(if (eq (c-literal-type range) 'string)
(c-end-of-sentence-in-string range)
(c-end-of-sentence-in-comment range)))
(setq range (c-ascertain-following-literal)))
;; If we've just come forward out of a literal, check for
;; vsemi. (N.B. AWK can't have a vsemi after a comment, but
;; some other language may do in the future)
(and res
(not (c-at-vsemi-p))))))
;; Non-literal code.
(t (setq res (c-forward-over-illiterals macro-fence
(> (point) here)))
;; Are we about to move forward into or out of a
;; preprocessor command?
(when (eq (cdr res) 'macro-boundary)
(setq macro-fence
(save-excursion
(if macro-fence
(progn
(end-of-line)
(and (not (eobp))
(progn (c-skip-ws-forward)
(c-beginning-of-macro))
(progn (c-end-of-macro)
(point))))
(and (not (eobp))
(c-beginning-of-macro)
(progn (c-end-of-macro) (point)))))))
;; Are we about to move forward into a literal?
(when (memq (cdr res) '(macro-boundary literal))
(setq range (c-ascertain-following-literal)))
(car res))))
(if (/= count 0) (setq count (1- count))))
(c-keep-region-active))))