Function: c-declaration-limits-1
c-declaration-limits-1 is a byte-compiled function defined in
cc-cmds.el.gz.
Signature
(c-declaration-limits-1 NEAR)
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-cmds.el.gz
(defun c-declaration-limits-1 (near)
;; Return a cons of the beginning and end position of the current
;; declaration or macro in the current narrowing. If there is no current
;; declaration or macro, return nil, unless NEAR is non-nil, in which case
;; the closest following one is chosen instead (if there is any). The end
;; position is at the next line, providing there is one before the
;; declaration.
;;
;; This function might do hidden buffer changes.
(save-excursion
(let ((start (point))
(paren-state (c-parse-state))
lim pos end-pos where)
(or
;; Note: Some code duplication in `c-beginning-of-defun' and
;; `c-end-of-defun'.
(catch 'exit
(unless (c-safe
(goto-char (c-least-enclosing-brace paren-state))
;; If we moved to the outermost enclosing paren
;; then we can use c-safe-position to set the
;; limit. Can't do that otherwise since the
;; earlier paren pair on paren-state might very
;; well be part of the declaration we should go
;; to.
(setq lim (c-safe-position (point) paren-state))
;; We might have a struct foo {...} as the type of the
;; function, so set LIM back one further block.
(if (eq (char-before lim) ?})
(setq lim
(or
(save-excursion
(and
(c-go-list-backward lim)
(let ((paren-state-1 (c-parse-state)))
(c-safe-position
(point) paren-state-1))))
(point-min))))
t)
;; At top level. Make sure we aren't inside a literal.
(setq pos (c-literal-start
(c-safe-position (point) paren-state)))
(if pos (goto-char pos)))
(when (c-beginning-of-macro)
(throw 'exit
(cons (point)
(save-excursion
(c-end-of-macro)
(forward-line 1)
(point)))))
(setq pos (point))
(setq where (and (not (save-excursion (c-beginning-of-macro)))
(c-where-wrt-brace-construct)))
(when (and (not (eq where 'at-header))
(or (and near
(memq where
'(at-function-end outwith-function))
;; Check we're not inside a declaration without
;; braces.
(save-excursion
(memq (car (c-beginning-of-decl-1 lim))
'(previous label))))
(eq (car (c-beginning-of-decl-1 lim)) 'previous)
(= pos (point))))
;; We moved back over the previous defun. Skip to the next
;; one. Not using c-forward-syntactic-ws here since we
;; should not skip a macro. We can also be directly after
;; the block in a `c-opt-block-decls-with-vars-key'
;; declaration, but then we won't move significantly far
;; here.
(goto-char pos)
(c-forward-comments)
(when (and near (c-beginning-of-macro))
(throw 'exit
(cons (point)
(save-excursion
(c-end-of-macro)
(forward-line 1)
(point))))))
(if (eobp) (throw 'exit nil))
;; Check if `c-beginning-of-decl-1' put us after the block in a
;; declaration that doesn't end there. We're searching back and
;; forth over the block here, which can be expensive.
(setq pos (point))
(if (and c-opt-block-decls-with-vars-key
(progn
(c-backward-syntactic-ws)
(eq (char-before) ?}))
(eq (car (c-beginning-of-decl-1))
'previous)
(save-excursion
(c-end-of-decl-1)
(and (> (point) pos)
(setq end-pos (point)))))
nil
(goto-char pos))
(if (or (and (not near) (> (point) start))
(not (eq (c-where-wrt-brace-construct) 'at-header)))
nil
;; Try to be line oriented; position the limits at the
;; closest preceding boi, and after the next newline, that
;; isn't inside a comment, but if we hit a neighboring
;; declaration then we instead use the exact declaration
;; limit in that direction.
(cons (progn
(setq pos (point))
(while (and (/= (point) (c-point 'boi))
(c-backward-single-comment)))
(if (/= (point) (c-point 'boi))
pos
(point)))
(progn
(if end-pos
(goto-char end-pos)
(c-end-of-decl-1))
(setq pos (point))
(while (and (not (bolp))
(not (looking-at "\\s *$"))
(c-forward-single-comment)))
(cond ((bolp)
(point))
((looking-at "\\s *$")
(forward-line 1)
(point))
(t
pos))))))
(and (not near)
(goto-char (point-min))
(c-forward-decl-or-cast-1 -1 nil nil)
(eq (char-after) ?\{)
(cons (point-min) (point-max)))))))