diff 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
line wrap: on
line diff
--- 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: