diff options
| author | Alan Mackenzie | 2020-03-08 16:21:15 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2020-03-08 16:21:15 +0000 |
| commit | 35a13fca32c3371ca25d87f7447b4bd4f65de710 (patch) | |
| tree | a6d40a7e845b45f43421fb8378eaaf5281fe86f9 /doc/misc | |
| parent | 66bc47d12aba72ff738a9f5575e0b93eefc641ba (diff) | |
| download | emacs-35a13fca32c3371ca25d87f7447b4bd4f65de710.tar.gz emacs-35a13fca32c3371ca25d87f7447b4bd4f65de710.zip | |
CC Mode: allow specified directives (e.g. pragma) to be indented as statements
* lisp/progmodes/cc-cmds.el (c-align-cpp-indent-to-body)
(c-cpp-indent-to-body-flag, c-electric-pragma)
(c-add-indent-to-body-to-abbrev-table, c-clear-stale-indent-to-body-abbrevs)
(c-toggle-cpp-indent-to-body): New functions and variables.
* lisp/progmodes/cc-langs.el (c-std-abbrev-keywords): New lang const/var.
* lisp/progmodes/cc-mode.el (c-populate-abbrev-table): New function.
(c-basic-common-init): call the c-populate-abbrev-table.
(c-mode, c++-mode, objc-mode, java-mode, idl-mode, pike-mode, awk-mode):
Remove the setting of MODE-abbrev-table.
* lisp/progmodes/cc-vars.el (c-cpp-indent-to-body-directives): New defcustom.
* doc/misc/cc-mode.texi (Custom Macros): Introduce and refer to ....
(Indenting Directives): New page documenting the new mechanism.
Diffstat (limited to 'doc/misc')
| -rw-r--r-- | doc/misc/cc-mode.texi | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi index 544ff853351..f99a890670f 100644 --- a/doc/misc/cc-mode.texi +++ b/doc/misc/cc-mode.texi | |||
| @@ -350,11 +350,12 @@ Line-Up Functions | |||
| 350 | * Misc Line-Up:: | 350 | * Misc Line-Up:: |
| 351 | 351 | ||
| 352 | 352 | ||
| 353 | Customizing Macros | 353 | Custom Macros |
| 354 | 354 | ||
| 355 | * Macro Backslashes:: | 355 | * Macro Backslashes:: |
| 356 | * Macros with ;:: | 356 | * Macros with ;:: |
| 357 | * Noise Macros:: | 357 | * Noise Macros:: |
| 358 | * Indenting Directives:: | ||
| 358 | 359 | ||
| 359 | @end detailmenu | 360 | @end detailmenu |
| 360 | @end menu | 361 | @end menu |
| @@ -6949,6 +6950,10 @@ is @code{nil}, all lines inside macro definitions are analyzed as | |||
| 6949 | @code{cpp-macro-cont}. | 6950 | @code{cpp-macro-cont}. |
| 6950 | @end defopt | 6951 | @end defopt |
| 6951 | 6952 | ||
| 6953 | Sometimes you may want to indent particular directives | ||
| 6954 | (e.g. @code{#pragma}) as though they were statements. To do this, see | ||
| 6955 | @ref{Indenting Directives}. | ||
| 6956 | |||
| 6952 | Because a macro can expand into anything at all, near where one is | 6957 | Because a macro can expand into anything at all, near where one is |
| 6953 | invoked @ccmode{} can only indent and fontify code heuristically. | 6958 | invoked @ccmode{} can only indent and fontify code heuristically. |
| 6954 | Sometimes it gets it wrong. Usually you should try to design your | 6959 | Sometimes it gets it wrong. Usually you should try to design your |
| @@ -6965,6 +6970,7 @@ Macros}. | |||
| 6965 | * Macro Backslashes:: | 6970 | * Macro Backslashes:: |
| 6966 | * Macros with ;:: | 6971 | * Macros with ;:: |
| 6967 | * Noise Macros:: | 6972 | * Noise Macros:: |
| 6973 | * Indenting Directives:: | ||
| 6968 | @end menu | 6974 | @end menu |
| 6969 | 6975 | ||
| 6970 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 6976 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| @@ -7074,7 +7080,7 @@ initialization code, after the mode hooks have run. | |||
| 7074 | @end defun | 7080 | @end defun |
| 7075 | 7081 | ||
| 7076 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 7082 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 7077 | @node Noise Macros, , Macros with ;, Custom Macros | 7083 | @node Noise Macros, Indenting Directives, Macros with ;, Custom Macros |
| 7078 | @comment node-name, next, previous, up | 7084 | @comment node-name, next, previous, up |
| 7079 | @section Noise Macros | 7085 | @section Noise Macros |
| 7080 | @cindex noise macros | 7086 | @cindex noise macros |
| @@ -7131,6 +7137,48 @@ after the mode hooks have run. | |||
| 7131 | @end defun | 7137 | @end defun |
| 7132 | 7138 | ||
| 7133 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 7139 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 7140 | @node Indenting Directives, , Noise Macros, Custom Macros | ||
| 7141 | @comment node-name, next, previous, up | ||
| 7142 | @section Indenting Directives | ||
| 7143 | @cindex Indenting Directives | ||
| 7144 | @cindex Indenting #pragma | ||
| 7145 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 7146 | |||
| 7147 | Sometimes you may want to indent particular preprocessor directives | ||
| 7148 | (e.g. @code{#pragma}) as though they were statements. To do this, | ||
| 7149 | first set up @code{c-cpp-indent-to-body-directives} to include the | ||
| 7150 | directive name(s), then enable the ``indent to body'' feature with | ||
| 7151 | @code{c-toggle-cpp-indent-to-body}. | ||
| 7152 | |||
| 7153 | @defopt c-cpp-indent-to-body-directives | ||
| 7154 | @vindex cpp-indent-to-body-directives (c-) | ||
| 7155 | This variable is a list of names of CPP directives (not including the | ||
| 7156 | introducing @samp{#}) which will be indented as though statements. | ||
| 7157 | Each element is a string, and must be a valid identifier. The default | ||
| 7158 | value is @code{("pragma")}. | ||
| 7159 | |||
| 7160 | If you add more directives to this variable, or remove directives from | ||
| 7161 | it, whilst ``indent to body'' is active, you need to re-enable the | ||
| 7162 | feature by calling @code{c-toggle-cpp-indent-to-body} for these | ||
| 7163 | changes to take effect@footnote{Note that the removal of directives | ||
| 7164 | doesn't work satisfactorally on XEmacs or on very old versions of | ||
| 7165 | Emacs}. | ||
| 7166 | @end defopt | ||
| 7167 | |||
| 7168 | @defun c-toggle-cpp-indent-to-body | ||
| 7169 | @findex toggle-cpp-indent-to-body (c-) | ||
| 7170 | With @kbd{M-x c-toggle-cpp-indent-to-body}, you enable or disable the | ||
| 7171 | ``indent to body'' feature. When called programmatically, it takes an | ||
| 7172 | optional numerical argument. A positive value will enable the | ||
| 7173 | feature, a zero or negative value will disable it. | ||
| 7174 | |||
| 7175 | You should set up @code{c-cpp-indent-to-body-directives} before | ||
| 7176 | calling this function, since the function sets internal state which | ||
| 7177 | depends on that variable. | ||
| 7178 | @end defun | ||
| 7179 | |||
| 7180 | |||
| 7181 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 7134 | @node Odds and Ends, Sample Init File, Custom Macros, Top | 7182 | @node Odds and Ends, Sample Init File, Custom Macros, Top |
| 7135 | @comment node-name, next, previous, up | 7183 | @comment node-name, next, previous, up |
| 7136 | @chapter Odds and Ends | 7184 | @chapter Odds and Ends |