Function: c-mark-function

c-mark-function is an interactive and byte-compiled function defined in cc-cmds.el.gz.

Signature

(c-mark-function)

Documentation

Put mark at end of current top-level declaration or macro, point at beginning.

If point is not inside any then the closest following one is chosen. Each successive call of this command extends the marked region by one function.

A mark is left where the command started, unless the region is already active
(in Transient Mark mode).

As opposed to M-x c-beginning-of-defun (c-beginning-of-defun) and M-x c-end-of-defun (c-end-of-defun), this function does not require the declaration to contain a brace block.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-cmds.el.gz
(defun c-mark-function ()
  "Put mark at end of current top-level declaration or macro, point at beginning.
If point is not inside any then the closest following one is
chosen.  Each successive call of this command extends the marked
region by one function.

A mark is left where the command started, unless the region is already active
\(in Transient Mark mode).

As opposed to \\[c-beginning-of-defun] and \\[c-end-of-defun], this
function does not require the declaration to contain a brace block."
  (interactive)

  (c-with-string-fences
   (let (decl-limits case-fold-search)
     (c-save-buffer-state nil
       ;; We try to be line oriented, unless there are several
       ;; declarations on the same line.
       (if (looking-at c-syntactic-eol)
	   (c-backward-token-2 1 nil (c-point 'bol)))
       (setq decl-limits (c-declaration-limits t)))

     (if (not decl-limits)
	 (error "Cannot find any declaration")
       (let* ((extend-region-p
	       (and (eq this-command 'c-mark-function)
		    (eq last-command 'c-mark-function)))
	      (push-mark-p (and (eq this-command 'c-mark-function)
				(not extend-region-p)
				(not (c-region-is-active-p)))))
	 (if push-mark-p (push-mark))
	 (if extend-region-p
	     (progn
	       (exchange-point-and-mark)
	       (setq decl-limits (c-declaration-limits t))
	       (when (not decl-limits)
		 (exchange-point-and-mark)
		 (error "Cannot find any declaration"))
	       (goto-char (cdr decl-limits))
	       (exchange-point-and-mark))
	   (goto-char (car decl-limits))
	   (push-mark (cdr decl-limits) nil t)))))))