Function: c-awk-end-of-defun

c-awk-end-of-defun is an interactive and byte-compiled function defined in cc-awk.el.gz.

Signature

(c-awk-end-of-defun &optional ARG)

Documentation

Move forward to next end of defun. With argument, do it that many times.

Negative argument -N means move back to Nth preceding end of defun.

An end of a defun occurs right after the closing brace that matches the opening brace at its start, or immediately after the AWK pattern when there is no explicit action; see function c-awk-beginning-of-defun.

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

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-awk.el.gz
(defun c-awk-end-of-defun (&optional arg)
  "Move forward to next end of defun.  With argument, do it that many times.
Negative argument -N means move back to Nth preceding end of defun.

An end of a defun occurs right after the closing brace that matches the
opening brace at its start, or immediately after the AWK pattern when there is
no explicit action; see function `c-awk-beginning-of-defun'.

Note that this function might do hidden buffer changes.  See the
comment at the start of cc-engine.el for more info."
  (interactive "p")
  (c-with-string-fences
   (or arg (setq arg 1))
   (save-match-data
     (c-save-buffer-state
	 nil
       (let ((start-point (point)) end-point)
	 ;; Strategy: (For +ve ARG): If we're not already at a beginning-of-defun,
	 ;; move backwards to one.
	 ;; Repeat [(i) move forward to end-of-current-defun (see below);
	 ;;         (ii) If this isn't it, move forward to beginning-of-defun].
	 ;; We start counting ARG only when step (i) has passed the original point.
	 (when (> arg 0)
           ;; Try to move back to a beginning-of-defun, if not already at one.
           (if (not (c-awk-beginning-of-defun-p))
               (when (not (c-awk-beginning-of-defun 1)) ; No bo-defun before point.
		 (goto-char start-point)
		 (c-awk-beginning-of-defun -1))) ; if this fails, we're at EOB, tough!
           ;; Now count forward, one defun at a time
           (while (and (not (eobp))
                       (c-awk-end-of-defun1)
                       (if (> (point) start-point) (setq arg (1- arg)) t)
                       (> arg 0)
                       (c-awk-beginning-of-defun -1))))

	 (when (< arg 0)
           (setq end-point start-point)
           (while (and (not (bobp))
                       (c-awk-beginning-of-defun 1)
                       (if (< (setq end-point (if (bobp) (point)
						(save-excursion (c-awk-end-of-defun1))))
                              start-point)
                           (setq arg (1+ arg)) t)
                       (< arg 0)))
           (goto-char (min start-point end-point))))))))