diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-05-31 17:49:30 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-05-31 17:49:30 +0200 |
commit | d881b516da0184052d2f9d33c3f72c5c014316bd (patch) | |
tree | faadc52b11a24da6c1ba2b147fd1f7a061198e88 /src | |
parent | e023e88bed3f2e0a7ea4cf10cac2de80bc9c271c (diff) | |
download | vim-git-d881b516da0184052d2f9d33c3f72c5c014316bd.tar.gz |
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')
-rw-r--r-- | src/cindent.c | 15 | ||||
-rw-r--r-- | src/structs.h | 1 | ||||
-rw-r--r-- | src/testdir/test_cindent.vim | 36 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 51 insertions, 3 deletions
diff --git a/src/cindent.c b/src/cindent.c index 3dc7b1635..aeecc4b95 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: diff --git a/src/structs.h b/src/structs.h index f67aba33f..9968e9205 100644 --- a/src/structs.h +++ b/src/structs.h @@ -2803,6 +2803,7 @@ struct file_buffer int b_ind_cpp_namespace; int b_ind_if_for_while; int b_ind_cpp_extern_c; + int b_ind_pragma; #endif linenr_T b_no_eol_lnum; // non-zero lnum when last line of next binary diff --git a/src/testdir/test_cindent.vim b/src/testdir/test_cindent.vim index 925819289..dc8c51dbf 100644 --- a/src/testdir/test_cindent.vim +++ b/src/testdir/test_cindent.vim @@ -5272,4 +5272,40 @@ func Test_cindent_change_multline() close! endfunc +func Test_cindent_pragma() + new + setl cindent ts=4 sw=4 + setl cino=Ps + + let code =<< trim [CODE] + { + #pragma omp parallel + { + #pragma omp task + foo(); + # pragma omp taskwait + } + } + [CODE] + + call append(0, code) + normal gg + normal =G + + let expected =<< trim [CODE] + { + #pragma omp parallel + { + #pragma omp task + foo(); + # pragma omp taskwait + } + } + + [CODE] + + call assert_equal(expected, getline(1, '$')) + enew! | close +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index e6caf8d96..6f77139a3 100644 --- a/src/version.c +++ b/src/version.c @@ -747,6 +747,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 864, +/**/ 863, /**/ 862, |