Function: c-awk-beginning-of-defun
c-awk-beginning-of-defun is an interactive and byte-compiled function
defined in cc-awk.el.gz.
Signature
(c-awk-beginning-of-defun &optional ARG)
Documentation
Move backward to the beginning of an AWK "defun".
With ARG, do it that many times. Negative arg -N means move forward to Nth following beginning of defun. Returns t unless search stops due to beginning or end of buffer.
By a "defun" is meant either a pattern-action pair or a function. The start of a defun is recognized as code starting at column zero which is neither a closing brace nor a comment nor a continuation of the previous line. Unlike in some other modes, having an opening brace at column 0 is neither necessary nor helpful.
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-beginning-of-defun (&optional arg)
"Move backward to the beginning of an AWK \"defun\".
With ARG, do it that many times. Negative arg -N means move
forward to Nth following beginning of defun. Returns t unless
search stops due to beginning or end of buffer.
By a \"defun\" is meant either a pattern-action pair or a function. The start
of a defun is recognized as code starting at column zero which is neither a
closing brace nor a comment nor a continuation of the previous line. Unlike
in some other modes, having an opening brace at column 0 is neither necessary
nor helpful.
Note that this function might do hidden buffer changes. See the
comment at the start of cc-engine.el for more info."
(interactive "p")
(or arg (setq arg 1))
(save-match-data
(c-save-buffer-state ; ensures the buffer is writable.
nil
(let ((found t)) ; Has the most recent regexp search found b-of-defun?
(if (>= arg 0)
;; Go back one defun each time round the following loop. (For +ve arg)
(while (and found (> arg 0) (not (eq (point) (point-min))))
;; Go back one "candidate" each time round the next loop until one
;; is genuinely a beginning-of-defun.
(while (and (setq found (search-backward-regexp
"^[^#} \t\n\r]" (point-min) 'stop-at-limit))
(not (memq (c-awk-get-NL-prop-prev-line) '(?\$ ?\} ?\#)))))
(setq arg (1- arg)))
;; The same for a -ve arg.
(if (not (eq (point) (point-max))) (forward-char 1))
(while (and found (< arg 0) (not (eq (point) (point-max)))) ; The same for -ve arg.
(while (and (setq found (search-forward-regexp
"^[^#} \t\n\r]" (point-max) 'stop-at-limit))
(not (memq (c-awk-get-NL-prop-prev-line) '(?\$ ?\} ?\#)))))
(setq arg (1+ arg)))
(if found (goto-char (match-beginning 0))))
(eq arg 0)))))