aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/progmodes/cc-cmds.el245
-rw-r--r--lisp/progmodes/cc-defs.el52
-rw-r--r--lisp/progmodes/cc-engine.el3
3 files changed, 158 insertions, 142 deletions
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index 764f44a8dd8..59f2729c43d 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -1594,70 +1594,69 @@ defun."
1594 (c-region-is-active-p) 1594 (c-region-is-active-p)
1595 (push-mark)) 1595 (push-mark))
1596 1596
1597 (c-self-bind-state-cache ; We must not share with other users of c-state-cache. 1597 (c-save-buffer-state
1598 (c-save-buffer-state 1598 (beginning-of-defun-function
1599 (beginning-of-defun-function 1599 end-of-defun-function
1600 end-of-defun-function 1600 (start (point))
1601 (start (point)) 1601 (paren-state (c-parse-state))
1602 (paren-state (c-parse-state)) 1602 (orig-point-min (point-min)) (orig-point-max (point-max))
1603 (orig-point-min (point-min)) (orig-point-max (point-max)) 1603 lim ; Position of { which has been widened to.
1604 lim ; Position of { which has been widened to. 1604 where pos case-fold-search)
1605 where pos case-fold-search) 1605
1606 1606 (save-restriction
1607 (save-restriction 1607 (if (eq c-defun-tactic 'go-outward)
1608 (if (eq c-defun-tactic 'go-outward) 1608 (setq lim (c-widen-to-enclosing-decl-scope ; e.g. class, namespace.
1609 (setq lim (c-widen-to-enclosing-decl-scope ; e.g. class, namespace. 1609 paren-state orig-point-min orig-point-max)))
1610 paren-state orig-point-min orig-point-max))) 1610
1611 1611 ;; Move back out of any macro/comment/string we happen to be in.
1612 ;; Move back out of any macro/comment/string we happen to be in. 1612 (c-beginning-of-macro)
1613 (c-beginning-of-macro) 1613 (setq pos (c-literal-limits))
1614 (setq pos (c-literal-limits)) 1614 (if pos (goto-char (car pos)))
1615 (if pos (goto-char (car pos))) 1615
1616 1616 (setq where (c-where-wrt-brace-construct))
1617 (setq where (c-where-wrt-brace-construct)) 1617
1618 1618 (if (< arg 0)
1619 (if (< arg 0) 1619 ;; Move forward to the closing brace of a function.
1620 ;; Move forward to the closing brace of a function. 1620 (progn
1621 (progn 1621 (if (memq where '(at-function-end outwith-function))
1622 (if (memq where '(at-function-end outwith-function)) 1622 (setq arg (1+ arg)))
1623 (setq arg (1+ arg))) 1623 (if (< arg 0)
1624 (if (< arg 0) 1624 (c-while-widening-to-decl-block
1625 (c-while-widening-to-decl-block 1625 (< (setq arg (- (c-forward-to-nth-EOF-} (- arg) where))) 0)))
1626 (< (setq arg (- (c-forward-to-nth-EOF-} (- arg) where))) 0))) 1626 ;; Move forward to the next opening brace....
1627 ;; Move forward to the next opening brace.... 1627 (when (and (= arg 0)
1628 (when (and (= arg 0) 1628 (progn
1629 (progn 1629 (c-while-widening-to-decl-block
1630 (c-while-widening-to-decl-block 1630 (not (c-syntactic-re-search-forward "{" nil 'eob)))
1631 (not (c-syntactic-re-search-forward "{" nil 'eob))) 1631 (eq (char-before) ?{)))
1632 (eq (char-before) ?{))) 1632 (backward-char)
1633 (backward-char) 1633 ;; ... and backward to the function header.
1634 ;; ... and backward to the function header. 1634 (c-beginning-of-decl-1)
1635 (c-beginning-of-decl-1) 1635 t))
1636 t)) 1636
1637 1637 ;; Move backward to the opening brace of a function, making successively
1638 ;; Move backward to the opening brace of a function, making successively 1638 ;; larger portions of the buffer visible as necessary.
1639 ;; larger portions of the buffer visible as necessary. 1639 (when (> arg 0)
1640 (when (> arg 0) 1640 (c-while-widening-to-decl-block
1641 (c-while-widening-to-decl-block 1641 (> (setq arg (c-backward-to-nth-BOF-{ arg where)) 0)))
1642 (> (setq arg (c-backward-to-nth-BOF-{ arg where)) 0))) 1642
1643 1643 (when (eq arg 0)
1644 (when (eq arg 0) 1644 ;; Go backward to this function's header.
1645 ;; Go backward to this function's header. 1645 (c-beginning-of-decl-1)
1646 (c-beginning-of-decl-1) 1646
1647 1647 (setq pos (point))
1648 (setq pos (point)) 1648 ;; We're now there, modulo comments and whitespace.
1649 ;; We're now there, modulo comments and whitespace. 1649 ;; Try to be line oriented; position point at the closest
1650 ;; Try to be line oriented; position point at the closest 1650 ;; preceding boi that isn't inside a comment, but if we hit
1651 ;; preceding boi that isn't inside a comment, but if we hit 1651 ;; the previous declaration then we use the current point
1652 ;; the previous declaration then we use the current point 1652 ;; instead.
1653 ;; instead. 1653 (while (and (/= (point) (c-point 'boi))
1654 (while (and (/= (point) (c-point 'boi)) 1654 (c-backward-single-comment)))
1655 (c-backward-single-comment))) 1655 (if (/= (point) (c-point 'boi))
1656 (if (/= (point) (c-point 'boi)) 1656 (goto-char pos)))
1657 (goto-char pos))) 1657
1658 1658 (c-keep-region-active)
1659 (c-keep-region-active) 1659 (= arg 0)))))
1660 (= arg 0))))))
1661 1660
1662(defun c-forward-to-nth-EOF-} (n where) 1661(defun c-forward-to-nth-EOF-} (n where)
1663 ;; Skip to the closing brace of the Nth function after point. If 1662 ;; Skip to the closing brace of the Nth function after point. If
@@ -1719,68 +1718,66 @@ the open-parenthesis that starts a defun; see `beginning-of-defun'."
1719 (c-region-is-active-p) 1718 (c-region-is-active-p)
1720 (push-mark)) 1719 (push-mark))
1721 1720
1722 (c-self-bind-state-cache ; c-state-cache's list structure must not be shared 1721 (c-save-buffer-state
1723 ; with other users. 1722 (beginning-of-defun-function
1724 (c-save-buffer-state 1723 end-of-defun-function
1725 (beginning-of-defun-function 1724 (start (point))
1726 end-of-defun-function 1725 (paren-state (c-parse-state))
1727 (start (point)) 1726 (orig-point-min (point-min)) (orig-point-max (point-max))
1728 (paren-state (c-parse-state)) 1727 lim
1729 (orig-point-min (point-min)) (orig-point-max (point-max)) 1728 where pos case-fold-search)
1730 lim
1731 where pos case-fold-search)
1732
1733 (save-restriction
1734 (if (eq c-defun-tactic 'go-outward)
1735 (setq lim (c-widen-to-enclosing-decl-scope ; e.g. class, namespace
1736 paren-state orig-point-min orig-point-max)))
1737
1738 ;; Move back out of any macro/comment/string we happen to be in.
1739 (c-beginning-of-macro)
1740 (setq pos (c-literal-limits))
1741 (if pos (goto-char (car pos)))
1742
1743 (setq where (c-where-wrt-brace-construct))
1744
1745 (if (< arg 0)
1746 ;; Move backwards to the } of a function
1747 (progn
1748 (if (memq where '(at-header outwith-function))
1749 (setq arg (1+ arg)))
1750 (if (< arg 0)
1751 (c-while-widening-to-decl-block
1752 (< (setq arg (- (c-backward-to-nth-BOF-{ (- arg) where))) 0)))
1753 (if (= arg 0)
1754 (c-while-widening-to-decl-block
1755 (progn (c-syntactic-skip-backward "^}")
1756 (not (eq (char-before) ?}))))))
1757
1758 ;; Move forward to the } of a function
1759 (if (> arg 0)
1760 (c-while-widening-to-decl-block
1761 (> (setq arg (c-forward-to-nth-EOF-} arg where)) 0))))
1762
1763 ;; Do we need to move forward from the brace to the semicolon?
1764 (when (eq arg 0)
1765 (if (c-in-function-trailer-p) ; after "}" of struct/enum, etc.
1766 (c-syntactic-re-search-forward ";"))
1767 1729
1768 (setq pos (point)) 1730 (save-restriction
1769 ;; We're there now, modulo comments and whitespace. 1731 (if (eq c-defun-tactic 'go-outward)
1770 ;; Try to be line oriented; position point after the next 1732 (setq lim (c-widen-to-enclosing-decl-scope ; e.g. class, namespace
1771 ;; newline that isn't inside a comment, but if we hit the 1733 paren-state orig-point-min orig-point-max)))
1772 ;; next declaration then we use the current point instead.
1773 (while (and (not (bolp))
1774 (not (looking-at "\\s *$"))
1775 (c-forward-single-comment)))
1776 (cond ((bolp))
1777 ((looking-at "\\s *$")
1778 (forward-line 1))
1779 (t
1780 (goto-char pos))))
1781 1734
1782 (c-keep-region-active) 1735 ;; Move back out of any macro/comment/string we happen to be in.
1783 (= arg 0))))) 1736 (c-beginning-of-macro)
1737 (setq pos (c-literal-limits))
1738 (if pos (goto-char (car pos)))
1739
1740 (setq where (c-where-wrt-brace-construct))
1741
1742 (if (< arg 0)
1743 ;; Move backwards to the } of a function
1744 (progn
1745 (if (memq where '(at-header outwith-function))
1746 (setq arg (1+ arg)))
1747 (if (< arg 0)
1748 (c-while-widening-to-decl-block
1749 (< (setq arg (- (c-backward-to-nth-BOF-{ (- arg) where))) 0)))
1750 (if (= arg 0)
1751 (c-while-widening-to-decl-block
1752 (progn (c-syntactic-skip-backward "^}")
1753 (not (eq (char-before) ?}))))))
1754
1755 ;; Move forward to the } of a function
1756 (if (> arg 0)
1757 (c-while-widening-to-decl-block
1758 (> (setq arg (c-forward-to-nth-EOF-} arg where)) 0))))
1759
1760 ;; Do we need to move forward from the brace to the semicolon?
1761 (when (eq arg 0)
1762 (if (c-in-function-trailer-p) ; after "}" of struct/enum, etc.
1763 (c-syntactic-re-search-forward ";"))
1764
1765 (setq pos (point))
1766 ;; We're there now, modulo comments and whitespace.
1767 ;; Try to be line oriented; position point after the next
1768 ;; newline that isn't inside a comment, but if we hit the
1769 ;; next declaration then we use the current point instead.
1770 (while (and (not (bolp))
1771 (not (looking-at "\\s *$"))
1772 (c-forward-single-comment)))
1773 (cond ((bolp))
1774 ((looking-at "\\s *$")
1775 (forward-line 1))
1776 (t
1777 (goto-char pos))))
1778
1779 (c-keep-region-active)
1780 (= arg 0))))
1784 1781
1785(defun c-defun-name () 1782(defun c-defun-name ()
1786 "Return the name of the current defun, or NIL if there isn't one. 1783 "Return the name of the current defun, or NIL if there isn't one.
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el
index f458904c87a..4c78bc3975c 100644
--- a/lisp/progmodes/cc-defs.el
+++ b/lisp/progmodes/cc-defs.el
@@ -1400,25 +1400,41 @@ been put there by c-put-char-property. POINT remains unchanged."
1400 (c-set-cpp-delimiters ,beg ,end))))) 1400 (c-set-cpp-delimiters ,beg ,end)))))
1401 1401
1402(defmacro c-self-bind-state-cache (&rest forms) 1402(defmacro c-self-bind-state-cache (&rest forms)
1403 ;; Bind the state cache to itself and execute the FORMS. It is assumed that no 1403 ;; Bind the state cache to itself and execute the FORMS. Return the result
1404 ;; buffer changes will happen in FORMS, and no hidden buffer changes which could 1404 ;; of the last FORM executed. It is assumed that no buffer changes will
1405 ;; affect the parsing will be made by FORMS. 1405 ;; happen in FORMS, and no hidden buffer changes which could affect the
1406 `(let ((c-state-cache (copy-tree c-state-cache)) 1406 ;; parsing will be made by FORMS.
1407 (c-state-cache-good-pos c-state-cache-good-pos) 1407 `(let* ((c-state-cache (copy-tree c-state-cache))
1408 ;(c-state-nonlit-pos-cache (copy-tree c-state-nonlit-pos-cache)) 1408 (c-state-cache-good-pos c-state-cache-good-pos)
1409 ;(c-state-nonlit-pos-cache-limit c-state-nonlit-pos-cache-limit) 1409 ;(c-state-nonlit-pos-cache (copy-tree c-state-nonlit-pos-cache))
1410 ;(c-state-semi-nonlit-pos-cache (copy-tree c-state-semi-nonlit-pos-cache)) 1410 ;(c-state-nonlit-pos-cache-limit c-state-nonlit-pos-cache-limit)
1411 ;(c-state-semi-nonlit-pos-cache-limit c-state-semi-nonlit-pos-cache) 1411 ;(c-state-semi-nonlit-pos-cache (copy-tree c-state-semi-nonlit-pos-cache))
1412 (c-state-brace-pair-desert (copy-tree c-state-brace-pair-desert)) 1412 ;(c-state-semi-nonlit-pos-cache-limit c-state-semi-nonlit-pos-cache)
1413 (c-state-point-min c-state-point-min) 1413 (c-state-brace-pair-desert (copy-tree c-state-brace-pair-desert))
1414 (c-state-point-min-lit-type c-state-point-min-lit-type) 1414 (c-state-point-min c-state-point-min)
1415 (c-state-point-min-lit-start c-state-point-min-lit-start) 1415 (c-state-point-min-lit-type c-state-point-min-lit-type)
1416 (c-state-min-scan-pos c-state-min-scan-pos) 1416 (c-state-point-min-lit-start c-state-point-min-lit-start)
1417 (c-state-old-cpp-beg c-state-old-cpp-beg) 1417 (c-state-min-scan-pos c-state-min-scan-pos)
1418 (c-state-old-cpp-end c-state-old-cpp-end)) 1418 (c-state-old-cpp-beg-marker (if (markerp c-state-old-cpp-beg-marker)
1419 ,@forms)) 1419 (copy-marker c-state-old-cpp-beg-marker)
1420 c-state-old-cpp-beg-marker))
1421 (c-state-old-cpp-beg (if (markerp c-state-old-cpp-beg)
1422 c-state-old-cpp-beg-marker
1423 c-state-old-cpp-beg))
1424 (c-state-old-cpp-end-marker (if (markerp c-state-old-cpp-end-marker)
1425 (copy-marker c-state-old-cpp-end-marker)
1426 c-state-old-cpp-end-marker))
1427 (c-state-old-cpp-end (if (markerp c-state-old-cpp-end)
1428 c-state-old-cpp-end-marker
1429 c-state-old-cpp-end))
1430 (c-parse-state-state c-parse-state-state))
1431 (prog1
1432 (progn ,@forms)
1433 (if (markerp c-state-old-cpp-beg-marker)
1434 (move-marker c-state-old-cpp-beg-marker nil))
1435 (if (markerp c-state-old-cpp-end-marker)
1436 (move-marker c-state-old-cpp-end-marker nil)))))
1420 1437
1421
1422;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1438;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1423;; The following macros are to be used only in `c-parse-state' and its 1439;; The following macros are to be used only in `c-parse-state' and its
1424;; subroutines. Their main purpose is to simplify the handling of C++/Java 1440;; subroutines. Their main purpose is to simplify the handling of C++/Java
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index afe87c5ee6a..aac7e631087 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -3472,6 +3472,9 @@ comment at the start of cc-engine.el for more info."
3472(make-variable-buffer-local 'c-parse-state-state) 3472(make-variable-buffer-local 'c-parse-state-state)
3473(defun c-record-parse-state-state () 3473(defun c-record-parse-state-state ()
3474 (setq c-parse-state-point (point)) 3474 (setq c-parse-state-point (point))
3475 (when (markerp (cdr (assq 'c-state-old-cpp-beg c-parse-state-state)))
3476 (move-marker (cdr (assq 'c-state-old-cpp-beg c-parse-state-state)) nil)
3477 (move-marker (cdr (assq 'c-state-old-cpp-end c-parse-state-state)) nil))
3475 (setq c-parse-state-state 3478 (setq c-parse-state-state
3476 (mapcar 3479 (mapcar
3477 (lambda (arg) 3480 (lambda (arg)