Function: c-narrow-to-most-enclosing-decl-block

c-narrow-to-most-enclosing-decl-block is a byte-compiled function defined in cc-cmds.el.gz.

Signature

(c-narrow-to-most-enclosing-decl-block &optional INCLUSIVE LEVEL)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-cmds.el.gz
(defun c-narrow-to-most-enclosing-decl-block (&optional inclusive level)
  ;; If we are inside a decl-block (in the sense of c-looking-at-decl-block),
  ;; i.e. something like namespace{} or extern{}, narrow to the insides of
  ;; that block (NOT including the enclosing braces) if INCLUSIVE is nil,
  ;; otherwise include the braces and the declaration which introduces them.
  ;; If the closing brace is missing, (point-max) is used instead.  LEVEL, if
  ;; non-nil, says narrow to the LEVELth decl-block outward, default value
  ;; being 1.
  (let ((paren-state (c-parse-state))
	encl-decl)
    (setq level (or level 1))
    (while (> level 0)
      (setq encl-decl (c-most-enclosing-decl-block paren-state))
      (if encl-decl
	  (progn
	    (while (> (c-pull-open-brace paren-state) encl-decl))
	    (setq level (1- level)))
	(setq level 0)))
    (if encl-decl
	(save-excursion
	  (narrow-to-region
	   (if inclusive
	       (progn (goto-char encl-decl)
		      (c-beginning-of-decl-1)
		      (point))
	     (1+ encl-decl))
	   (progn
	     (goto-char encl-decl)
	     (or (c-safe (forward-list)
			 (if inclusive
			     (point)
			   (1- (point))))
		 (point-max))))))))