Mercurial > vim
comparison src/cindent.c @ 20621:d30b16692ce0 v8.2.0864
patch 8.2.0864: pragmas are indented all the way to the left
Commit: https://github.com/vim/vim/commit/d881b516da0184052d2f9d33c3f72c5c014316bd
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 31 17:49:30 2020 +0200
patch 8.2.0864: pragmas are indented all the way to the left
Problem: Pragmas are indented all the way to the left.
Solution: Add an option to indent progmas like normal code. (Max Rumpf,
closes #5468)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 31 May 2020 18:00:03 +0200 |
parents | 9f4648953f1a |
children | b545334ae654 |
comparison
equal
deleted
inserted
replaced
20620:3c6739c316cc | 20621:d30b16692ce0 |
---|---|
1842 // indentation for # comments | 1842 // indentation for # comments |
1843 buf->b_ind_hash_comment = 0; | 1843 buf->b_ind_hash_comment = 0; |
1844 | 1844 |
1845 // Handle C++ extern "C" or "C++" | 1845 // Handle C++ extern "C" or "C++" |
1846 buf->b_ind_cpp_extern_c = 0; | 1846 buf->b_ind_cpp_extern_c = 0; |
1847 | |
1848 // Handle C #pragma directives | |
1849 buf->b_ind_pragma = 0; | |
1847 | 1850 |
1848 for (p = buf->b_p_cino; *p; ) | 1851 for (p = buf->b_p_cino; *p; ) |
1849 { | 1852 { |
1850 l = p++; | 1853 l = p++; |
1851 if (*p == '-') | 1854 if (*p == '-') |
1918 case 'l': buf->b_ind_keep_case_label = n; break; | 1921 case 'l': buf->b_ind_keep_case_label = n; break; |
1919 case '#': buf->b_ind_hash_comment = n; break; | 1922 case '#': buf->b_ind_hash_comment = n; break; |
1920 case 'N': buf->b_ind_cpp_namespace = n; break; | 1923 case 'N': buf->b_ind_cpp_namespace = n; break; |
1921 case 'k': buf->b_ind_if_for_while = n; break; | 1924 case 'k': buf->b_ind_if_for_while = n; break; |
1922 case 'E': buf->b_ind_cpp_extern_c = n; break; | 1925 case 'E': buf->b_ind_cpp_extern_c = n; break; |
1926 case 'P': buf->b_ind_pragma = n; break; | |
1923 } | 1927 } |
1924 if (*p == ',') | 1928 if (*p == ',') |
1925 ++p; | 1929 ++p; |
1926 } | 1930 } |
1927 } | 1931 } |
2114 { | 2118 { |
2115 amount = -1; | 2119 amount = -1; |
2116 goto laterend; | 2120 goto laterend; |
2117 } | 2121 } |
2118 | 2122 |
2119 // #defines and so on always go at the left when included in 'cinkeys'. | 2123 // #defines and so on go at the left when included in 'cinkeys', |
2124 // exluding pragmas when customized in 'cinoptions' | |
2120 if (*theline == '#' && (*linecopy == '#' || in_cinkeys('#', ' ', TRUE))) | 2125 if (*theline == '#' && (*linecopy == '#' || in_cinkeys('#', ' ', TRUE))) |
2121 { | 2126 { |
2122 amount = curbuf->b_ind_hash_comment; | 2127 char_u *directive = skipwhite(theline + 1); |
2123 goto theend; | 2128 if (curbuf->b_ind_pragma == 0 || STRNCMP(directive, "pragma", 6) != 0) |
2129 { | |
2130 amount = curbuf->b_ind_hash_comment; | |
2131 goto theend; | |
2132 } | |
2124 } | 2133 } |
2125 | 2134 |
2126 // Is it a non-case label? Then that goes at the left margin too unless: | 2135 // Is it a non-case label? Then that goes at the left margin too unless: |
2127 // - JS flag is set. | 2136 // - JS flag is set. |
2128 // - 'L' item has a positive value. | 2137 // - 'L' item has a positive value. |