summaryrefslogtreecommitdiffstats
path: root/src/cindent.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-05-31 17:49:30 +0200
committerBram Moolenaar <Bram@vim.org>2020-05-31 17:49:30 +0200
commitd881b516da0184052d2f9d33c3f72c5c014316bd (patch)
treefaadc52b11a24da6c1ba2b147fd1f7a061198e88 /src/cindent.c
parente023e88bed3f2e0a7ea4cf10cac2de80bc9c271c (diff)
patch 8.2.0864: pragmas are indented all the way to the leftv8.2.0864
Problem: Pragmas are indented all the way to the left. Solution: Add an option to indent progmas like normal code. (Max Rumpf, closes #5468)
Diffstat (limited to 'src/cindent.c')
-rw-r--r--src/cindent.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/cindent.c b/src/cindent.c
index 3dc7b16354..aeecc4b95c 100644
--- a/src/cindent.c
+++ b/src/cindent.c
@@ -1845,6 +1845,9 @@ parse_cino(buf_T *buf)
// Handle C++ extern "C" or "C++"
buf->b_ind_cpp_extern_c = 0;
+ // Handle C #pragma directives
+ buf->b_ind_pragma = 0;
+
for (p = buf->b_p_cino; *p; )
{
l = p++;
@@ -1920,6 +1923,7 @@ parse_cino(buf_T *buf)
case 'N': buf->b_ind_cpp_namespace = n; break;
case 'k': buf->b_ind_if_for_while = n; break;
case 'E': buf->b_ind_cpp_extern_c = n; break;
+ case 'P': buf->b_ind_pragma = n; break;
}
if (*p == ',')
++p;
@@ -2116,11 +2120,16 @@ get_c_indent(void)
goto laterend;
}
- // #defines and so on always go at the left when included in 'cinkeys'.
+ // #defines and so on go at the left when included in 'cinkeys',
+ // exluding pragmas when customized in 'cinoptions'
if (*theline == '#' && (*linecopy == '#' || in_cinkeys('#', ' ', TRUE)))
{
- amount = curbuf->b_ind_hash_comment;
- goto theend;
+ char_u *directive = skipwhite(theline + 1);
+ if (curbuf->b_ind_pragma == 0 || STRNCMP(directive, "pragma", 6) != 0)
+ {
+ amount = curbuf->b_ind_hash_comment;
+ goto theend;
+ }
}
// Is it a non-case label? Then that goes at the left margin too unless: