diff options
| author | Alan Mackenzie | 2016-05-09 17:49:45 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2016-05-09 17:49:45 +0000 |
| commit | a8231e00cbad60652ff7ab6ae51a758f1d939971 (patch) | |
| tree | abbdd240734fb41710e542335fea763e12601596 | |
| parent | 608f2bd0ac9d950a04ad73bf36d96d25b469b9be (diff) | |
| download | emacs-a8231e00cbad60652ff7ab6ae51a758f1d939971.tar.gz emacs-a8231e00cbad60652ff7ab6ae51a758f1d939971.zip | |
CC Mode now uses the new :after-hook feature of define-derived-mode
It now runs internal variable setting functions after the mode hooks, no
longer runs the mode hooks twice, and declares the configuration variables for
noise macros and macros with semicolons as safe variables (when given suitable
arguments).
Fixes bug #16759 and bug #23476.
* .dir-locals: Put the c-noise-macros-with-paren-names setting back into the C
Mode value.
* lisp/progmodes/cc-mode.el: (c-basic-common-init): Remove the call to
c-make-macro-with-semi-re.
(c-mode, c++-mode, objc-mode, java-mode, idl-mode, pike-mode, awk-mode): Move
c-make-noise-macro-regexps and c-make-macro-with-semi-re (where appropriate)
and c-update-modeline into the :after-hook form. Remove the explicit settings
of the syntax table, the abbreviation table and the local key map, since they
duplicate forms generated by define-derived-mode. Remove the explicit
invocation of each mode's mode hook, since they duplicate ones generated by
define-derived-mode.
* lisp/progmodes/cc-vars.el: (c-string-list-p, c-string-or-string-list-p): New
functions.
(c-noise-macro-names, c-noise-macro-with-parens-names): give the
save-local-variable property c-string-list-p.
(c-macro-names-with-semicolon): give the save-local-variable property
c-string-or-string-list-p.
* doc/misc/cc-mode.texi: (Macros with ;, Noise Macros): Note that it's not
necessary to call the regexp generating functions after setting the pertinent
configuration values in a mode hook.
| -rw-r--r-- | .dir-locals.el | 3 | ||||
| -rw-r--r-- | doc/misc/cc-mode.texi | 13 | ||||
| -rw-r--r-- | lisp/progmodes/cc-mode.el | 72 | ||||
| -rw-r--r-- | lisp/progmodes/cc-vars.el | 19 |
4 files changed, 53 insertions, 54 deletions
diff --git a/.dir-locals.el b/.dir-locals.el index 9853d7b5d88..7c14802b66e 100644 --- a/.dir-locals.el +++ b/.dir-locals.el | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | ((nil . ((tab-width . 8) | 1 | ((nil . ((tab-width . 8) |
| 2 | (sentence-end-double-space . t) | 2 | (sentence-end-double-space . t) |
| 3 | (fill-column . 70))) | 3 | (fill-column . 70))) |
| 4 | (c-mode . ((c-file-style . "GNU"))) | 4 | (c-mode . ((c-file-style . "GNU") |
| 5 | (c-noise-macro-with-parens-names . ("IF_LINT")))) | ||
| 5 | (objc-mode . ((c-file-style . "GNU"))) | 6 | (objc-mode . ((c-file-style . "GNU"))) |
| 6 | (log-edit-mode . ((log-edit-font-lock-gnu-style . t) | 7 | (log-edit-mode . ((log-edit-font-lock-gnu-style . t) |
| 7 | (log-edit-setup-add-author . t))) | 8 | (log-edit-setup-add-author . t))) |
diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi index 70146b2eb57..82f8cbc2e33 100644 --- a/doc/misc/cc-mode.texi +++ b/doc/misc/cc-mode.texi | |||
| @@ -6767,10 +6767,10 @@ example: | |||
| 6767 | @defun c-make-macro-with-semi-re | 6767 | @defun c-make-macro-with-semi-re |
| 6768 | @findex make-macro-with-semi-re (c-) | 6768 | @findex make-macro-with-semi-re (c-) |
| 6769 | Call this (non-interactive) function, which sets internal variables, | 6769 | Call this (non-interactive) function, which sets internal variables, |
| 6770 | each time you change the value of | 6770 | each time you change the value of @code{c-macro-names-with-semicolon} |
| 6771 | @code{c-macro-names-with-semicolon}. It takes no arguments, and its | 6771 | after the major mode function has run. It takes no arguments, and its |
| 6772 | return value has no meaning. This function is called by @ccmode{}'s | 6772 | return value has no meaning. This function is called by @ccmode{}'s |
| 6773 | initialization code. | 6773 | initialization code, after the mode hooks have run. |
| 6774 | @end defun | 6774 | @end defun |
| 6775 | 6775 | ||
| 6776 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 6776 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| @@ -6822,9 +6822,10 @@ but doing so is OK. | |||
| 6822 | @defun c-make-noise-macro-regexps | 6822 | @defun c-make-noise-macro-regexps |
| 6823 | @findex make-noise-macro-regexps (c-) | 6823 | @findex make-noise-macro-regexps (c-) |
| 6824 | Call this (non-interactive) function, which sets internal variables, | 6824 | Call this (non-interactive) function, which sets internal variables, |
| 6825 | after changing the value of @code{c-noise-macro-names} or | 6825 | on changing the value of @code{c-noise-macro-names} or |
| 6826 | @code{c-noise-macro-with-parens-names} (e.g. in a hook (@pxref{CC | 6826 | @code{c-noise-macro-with-parens-names} after the major mode's function |
| 6827 | Hooks})). This function is called by @ccmode{}'s initialization code. | 6827 | has run. This function is called by @ccmode{}'s initialization code, |
| 6828 | after the mode hooks have run. | ||
| 6828 | @end defun | 6829 | @end defun |
| 6829 | 6830 | ||
| 6830 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 6831 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 2ab1d6b0d70..6a78992756b 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el | |||
| @@ -596,7 +596,6 @@ that requires a literal mode spec at compile time." | |||
| 596 | (not (string-equal c-indentation-style | 596 | (not (string-equal c-indentation-style |
| 597 | style))))))) | 597 | style))))))) |
| 598 | (c-setup-paragraph-variables) | 598 | (c-setup-paragraph-variables) |
| 599 | (c-make-noise-macro-regexps) | ||
| 600 | 599 | ||
| 601 | ;; we have to do something special for c-offsets-alist so that the | 600 | ;; we have to do something special for c-offsets-alist so that the |
| 602 | ;; buffer local value has its own alist structure. | 601 | ;; buffer local value has its own alist structure. |
| @@ -1487,18 +1486,16 @@ initialization, then `c-mode-hook'. | |||
| 1487 | 1486 | ||
| 1488 | Key bindings: | 1487 | Key bindings: |
| 1489 | \\{c-mode-map}" | 1488 | \\{c-mode-map}" |
| 1489 | :after-hook (progn (c-make-noise-macro-regexps) | ||
| 1490 | (c-make-macro-with-semi-re) | ||
| 1491 | (c-update-modeline)) | ||
| 1490 | (c-initialize-cc-mode t) | 1492 | (c-initialize-cc-mode t) |
| 1491 | (set-syntax-table c-mode-syntax-table) | 1493 | (setq abbrev-mode t) |
| 1492 | (setq local-abbrev-table c-mode-abbrev-table | ||
| 1493 | abbrev-mode t) | ||
| 1494 | (use-local-map c-mode-map) | ||
| 1495 | (c-init-language-vars-for 'c-mode) | 1494 | (c-init-language-vars-for 'c-mode) |
| 1496 | (c-make-macro-with-semi-re) ; matches macro names whose expansion ends with ; | ||
| 1497 | (c-common-init 'c-mode) | 1495 | (c-common-init 'c-mode) |
| 1498 | (easy-menu-add c-c-menu) | 1496 | (easy-menu-add c-c-menu) |
| 1499 | (cc-imenu-init cc-imenu-c-generic-expression) | 1497 | (cc-imenu-init cc-imenu-c-generic-expression) |
| 1500 | (c-run-mode-hooks 'c-mode-common-hook 'c-mode-hook) | 1498 | (c-run-mode-hooks 'c-mode-common-hook)) |
| 1501 | (c-update-modeline)) | ||
| 1502 | 1499 | ||
| 1503 | 1500 | ||
| 1504 | ;; Support for C++ | 1501 | ;; Support for C++ |
| @@ -1542,18 +1539,16 @@ initialization, then `c++-mode-hook'. | |||
| 1542 | 1539 | ||
| 1543 | Key bindings: | 1540 | Key bindings: |
| 1544 | \\{c++-mode-map}" | 1541 | \\{c++-mode-map}" |
| 1542 | :after-hook (progn (c-make-noise-macro-regexps) | ||
| 1543 | (c-make-macro-with-semi-re) | ||
| 1544 | (c-update-modeline)) | ||
| 1545 | (c-initialize-cc-mode t) | 1545 | (c-initialize-cc-mode t) |
| 1546 | (set-syntax-table c++-mode-syntax-table) | 1546 | (setq abbrev-mode t) |
| 1547 | (setq local-abbrev-table c++-mode-abbrev-table | ||
| 1548 | abbrev-mode t) | ||
| 1549 | (use-local-map c++-mode-map) | ||
| 1550 | (c-init-language-vars-for 'c++-mode) | 1547 | (c-init-language-vars-for 'c++-mode) |
| 1551 | (c-make-macro-with-semi-re) ; matches macro names whose expansion ends with ; | ||
| 1552 | (c-common-init 'c++-mode) | 1548 | (c-common-init 'c++-mode) |
| 1553 | (easy-menu-add c-c++-menu) | 1549 | (easy-menu-add c-c++-menu) |
| 1554 | (cc-imenu-init cc-imenu-c++-generic-expression) | 1550 | (cc-imenu-init cc-imenu-c++-generic-expression) |
| 1555 | (c-run-mode-hooks 'c-mode-common-hook 'c++-mode-hook) | 1551 | (c-run-mode-hooks 'c-mode-common-hook)) |
| 1556 | (c-update-modeline)) | ||
| 1557 | 1552 | ||
| 1558 | 1553 | ||
| 1559 | ;; Support for Objective-C | 1554 | ;; Support for Objective-C |
| @@ -1595,18 +1590,16 @@ initialization, then `objc-mode-hook'. | |||
| 1595 | 1590 | ||
| 1596 | Key bindings: | 1591 | Key bindings: |
| 1597 | \\{objc-mode-map}" | 1592 | \\{objc-mode-map}" |
| 1593 | :after-hook (progn (c-make-noise-macro-regexps) | ||
| 1594 | (c-make-macro-with-semi-re) | ||
| 1595 | (c-update-modeline)) | ||
| 1598 | (c-initialize-cc-mode t) | 1596 | (c-initialize-cc-mode t) |
| 1599 | (set-syntax-table objc-mode-syntax-table) | 1597 | (setq abbrev-mode t) |
| 1600 | (setq local-abbrev-table objc-mode-abbrev-table | ||
| 1601 | abbrev-mode t) | ||
| 1602 | (use-local-map objc-mode-map) | ||
| 1603 | (c-init-language-vars-for 'objc-mode) | 1598 | (c-init-language-vars-for 'objc-mode) |
| 1604 | (c-make-macro-with-semi-re) ; matches macro names whose expansion ends with ; | ||
| 1605 | (c-common-init 'objc-mode) | 1599 | (c-common-init 'objc-mode) |
| 1606 | (easy-menu-add c-objc-menu) | 1600 | (easy-menu-add c-objc-menu) |
| 1607 | (cc-imenu-init nil 'cc-imenu-objc-function) | 1601 | (cc-imenu-init nil 'cc-imenu-objc-function) |
| 1608 | (c-run-mode-hooks 'c-mode-common-hook 'objc-mode-hook) | 1602 | (c-run-mode-hooks 'c-mode-common-hook)) |
| 1609 | (c-update-modeline)) | ||
| 1610 | 1603 | ||
| 1611 | 1604 | ||
| 1612 | ;; Support for Java | 1605 | ;; Support for Java |
| @@ -1656,17 +1649,14 @@ initialization, then `java-mode-hook'. | |||
| 1656 | 1649 | ||
| 1657 | Key bindings: | 1650 | Key bindings: |
| 1658 | \\{java-mode-map}" | 1651 | \\{java-mode-map}" |
| 1652 | :after-hook (c-update-modeline) | ||
| 1659 | (c-initialize-cc-mode t) | 1653 | (c-initialize-cc-mode t) |
| 1660 | (set-syntax-table java-mode-syntax-table) | 1654 | (setq abbrev-mode t) |
| 1661 | (setq local-abbrev-table java-mode-abbrev-table | ||
| 1662 | abbrev-mode t) | ||
| 1663 | (use-local-map java-mode-map) | ||
| 1664 | (c-init-language-vars-for 'java-mode) | 1655 | (c-init-language-vars-for 'java-mode) |
| 1665 | (c-common-init 'java-mode) | 1656 | (c-common-init 'java-mode) |
| 1666 | (easy-menu-add c-java-menu) | 1657 | (easy-menu-add c-java-menu) |
| 1667 | (cc-imenu-init cc-imenu-java-generic-expression) | 1658 | (cc-imenu-init cc-imenu-java-generic-expression) |
| 1668 | (c-run-mode-hooks 'c-mode-common-hook 'java-mode-hook) | 1659 | (c-run-mode-hooks 'c-mode-common-hook)) |
| 1669 | (c-update-modeline)) | ||
| 1670 | 1660 | ||
| 1671 | 1661 | ||
| 1672 | ;; Support for CORBA's IDL language | 1662 | ;; Support for CORBA's IDL language |
| @@ -1705,16 +1695,13 @@ initialization, then `idl-mode-hook'. | |||
| 1705 | 1695 | ||
| 1706 | Key bindings: | 1696 | Key bindings: |
| 1707 | \\{idl-mode-map}" | 1697 | \\{idl-mode-map}" |
| 1698 | :after-hook (c-update-modeline) | ||
| 1708 | (c-initialize-cc-mode t) | 1699 | (c-initialize-cc-mode t) |
| 1709 | (set-syntax-table idl-mode-syntax-table) | ||
| 1710 | (setq local-abbrev-table idl-mode-abbrev-table) | ||
| 1711 | (use-local-map idl-mode-map) | ||
| 1712 | (c-init-language-vars-for 'idl-mode) | 1700 | (c-init-language-vars-for 'idl-mode) |
| 1713 | (c-common-init 'idl-mode) | 1701 | (c-common-init 'idl-mode) |
| 1714 | (easy-menu-add c-idl-menu) | 1702 | (easy-menu-add c-idl-menu) |
| 1715 | ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO | 1703 | ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO |
| 1716 | (c-run-mode-hooks 'c-mode-common-hook 'idl-mode-hook) | 1704 | (c-run-mode-hooks 'c-mode-common-hook)) |
| 1717 | (c-update-modeline)) | ||
| 1718 | 1705 | ||
| 1719 | 1706 | ||
| 1720 | ;; Support for Pike | 1707 | ;; Support for Pike |
| @@ -1757,17 +1744,14 @@ initialization, then `pike-mode-hook'. | |||
| 1757 | 1744 | ||
| 1758 | Key bindings: | 1745 | Key bindings: |
| 1759 | \\{pike-mode-map}" | 1746 | \\{pike-mode-map}" |
| 1747 | :after-hook (c-update-modeline) | ||
| 1760 | (c-initialize-cc-mode t) | 1748 | (c-initialize-cc-mode t) |
| 1761 | (set-syntax-table pike-mode-syntax-table) | 1749 | (setq abbrev-mode t) |
| 1762 | (setq local-abbrev-table pike-mode-abbrev-table | ||
| 1763 | abbrev-mode t) | ||
| 1764 | (use-local-map pike-mode-map) | ||
| 1765 | (c-init-language-vars-for 'pike-mode) | 1750 | (c-init-language-vars-for 'pike-mode) |
| 1766 | (c-common-init 'pike-mode) | 1751 | (c-common-init 'pike-mode) |
| 1767 | (easy-menu-add c-pike-menu) | 1752 | (easy-menu-add c-pike-menu) |
| 1768 | ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO | 1753 | ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO |
| 1769 | (c-run-mode-hooks 'c-mode-common-hook 'pike-mode-hook) | 1754 | (c-run-mode-hooks 'c-mode-common-hook)) |
| 1770 | (c-update-modeline)) | ||
| 1771 | 1755 | ||
| 1772 | 1756 | ||
| 1773 | ;; Support for AWK | 1757 | ;; Support for AWK |
| @@ -1821,22 +1805,18 @@ initialization, then `awk-mode-hook'. | |||
| 1821 | 1805 | ||
| 1822 | Key bindings: | 1806 | Key bindings: |
| 1823 | \\{awk-mode-map}" | 1807 | \\{awk-mode-map}" |
| 1808 | :after-hook (c-update-modeline) | ||
| 1824 | ;; We need the next line to stop the macro defining | 1809 | ;; We need the next line to stop the macro defining |
| 1825 | ;; `awk-mode-syntax-table'. This would mask the real table which is | 1810 | ;; `awk-mode-syntax-table'. This would mask the real table which is |
| 1826 | ;; declared in cc-awk.el and hasn't yet been loaded. | 1811 | ;; declared in cc-awk.el and hasn't yet been loaded. |
| 1827 | :syntax-table nil | 1812 | :syntax-table nil |
| 1828 | (require 'cc-awk) ; Added 2003/6/10. | 1813 | (require 'cc-awk) ; Added 2003/6/10. |
| 1829 | (c-initialize-cc-mode t) | 1814 | (c-initialize-cc-mode t) |
| 1830 | (set-syntax-table awk-mode-syntax-table) | 1815 | (setq abbrev-mode t) |
| 1831 | (setq local-abbrev-table awk-mode-abbrev-table | ||
| 1832 | abbrev-mode t) | ||
| 1833 | (use-local-map awk-mode-map) | ||
| 1834 | (c-init-language-vars-for 'awk-mode) | 1816 | (c-init-language-vars-for 'awk-mode) |
| 1835 | (c-common-init 'awk-mode) | 1817 | (c-common-init 'awk-mode) |
| 1836 | (c-awk-unstick-NL-prop) | 1818 | (c-awk-unstick-NL-prop) |
| 1837 | 1819 | (c-run-mode-hooks 'c-mode-common-hook)) | |
| 1838 | (c-run-mode-hooks 'c-mode-common-hook 'awk-mode-hook) | ||
| 1839 | (c-update-modeline)) | ||
| 1840 | 1820 | ||
| 1841 | 1821 | ||
| 1842 | ;; bug reporting | 1822 | ;; bug reporting |
diff --git a/lisp/progmodes/cc-vars.el b/lisp/progmodes/cc-vars.el index 98195da9456..8cad27fd86d 100644 --- a/lisp/progmodes/cc-vars.el +++ b/lisp/progmodes/cc-vars.el | |||
| @@ -229,7 +229,20 @@ See `c-offsets-alist'." | |||
| 229 | (setq offset (cdr offset))) | 229 | (setq offset (cdr offset))) |
| 230 | (null offset))))) | 230 | (null offset))))) |
| 231 | 231 | ||
| 232 | 232 | (defun c-string-list-p (val) | |
| 233 | "Return non-nil if VAL is a list of strings." | ||
| 234 | (and | ||
| 235 | (listp val) | ||
| 236 | (catch 'string | ||
| 237 | (dolist (elt val) | ||
| 238 | (if (not (stringp elt)) | ||
| 239 | (throw 'string nil))) | ||
| 240 | t))) | ||
| 241 | |||
| 242 | (defun c-string-or-string-list-p (val) | ||
| 243 | "Return non-nil if VAL is a string or a list of strings." | ||
| 244 | (or (stringp val) | ||
| 245 | (c-string-list-p val))) | ||
| 233 | 246 | ||
| 234 | ;;; User variables | 247 | ;;; User variables |
| 235 | 248 | ||
| @@ -1633,6 +1646,7 @@ If you change this variable's value, call the function | |||
| 1633 | this implicitly by reinitializing C/C++/Objc Mode on any buffer)." | 1646 | this implicitly by reinitializing C/C++/Objc Mode on any buffer)." |
| 1634 | :type '(repeat :tag "List of names" string) | 1647 | :type '(repeat :tag "List of names" string) |
| 1635 | :group 'c) | 1648 | :group 'c) |
| 1649 | (put 'c-noise-macro-names 'safe-local-variable #'c-string-list-p) | ||
| 1636 | 1650 | ||
| 1637 | (defcustom c-noise-macro-with-parens-names nil | 1651 | (defcustom c-noise-macro-with-parens-names nil |
| 1638 | "A list of names of macros \(or compiler extensions like \"__attribute__\") | 1652 | "A list of names of macros \(or compiler extensions like \"__attribute__\") |
| @@ -1640,6 +1654,7 @@ which optionally have arguments in parentheses, and which expand to nothing. | |||
| 1640 | These are recognized by CC Mode only in declarations." | 1654 | These are recognized by CC Mode only in declarations." |
| 1641 | :type '(regexp :tag "List of names (possibly empty)" string) | 1655 | :type '(regexp :tag "List of names (possibly empty)" string) |
| 1642 | :group 'c) | 1656 | :group 'c) |
| 1657 | (put 'c-noise-macro-with-parens-names 'safe-local-variable #'c-string-list-p) | ||
| 1643 | 1658 | ||
| 1644 | (defun c-make-noise-macro-regexps () | 1659 | (defun c-make-noise-macro-regexps () |
| 1645 | ;; Convert `c-noise-macro-names' and `c-noise-macro-with-parens-names' into | 1660 | ;; Convert `c-noise-macro-names' and `c-noise-macro-with-parens-names' into |
| @@ -1690,6 +1705,8 @@ variables. | |||
| 1690 | Note that currently \(2008-11-04) this variable is a prototype, | 1705 | Note that currently \(2008-11-04) this variable is a prototype, |
| 1691 | and is likely to disappear or change its form soon.") | 1706 | and is likely to disappear or change its form soon.") |
| 1692 | (make-variable-buffer-local 'c-macro-names-with-semicolon) | 1707 | (make-variable-buffer-local 'c-macro-names-with-semicolon) |
| 1708 | (put 'c-macro-names-with-semicolon 'safe-local-variable | ||
| 1709 | #'c-string-or-string-list-p) | ||
| 1693 | 1710 | ||
| 1694 | (defun c-make-macro-with-semi-re () | 1711 | (defun c-make-macro-with-semi-re () |
| 1695 | ;; Convert `c-macro-names-with-semicolon' into the regexp | 1712 | ;; Convert `c-macro-names-with-semicolon' into the regexp |