Patch 8.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)
Files:      runtime/doc/indent.txt, src/cindent.c, src/structs.h,
            src/testdir/test_cindent.vim


*** ../vim-8.2.0863/runtime/doc/indent.txt      2019-12-12 12:49:05.000000000 
+0100
--- runtime/doc/indent.txt      2020-05-31 17:42:45.123006750 +0200
***************
*** 570,578 ****
              with "#" does not work.
  
  
  The defaults, spelled out in full, are:
        cinoptions=>s,e0,n0,f0,{0,}0,^0,L-1,:s,=s,l0,b0,gs,hs,N0,E0,ps,ts,is,+s,
!                       c3,C0,/0,(2s,us,U0,w0,W0,k0,m0,j0,J0,)20,*70,#0
  
  Vim puts a line in column 1 if:
  - It starts with '#' (preprocessor directives), if 'cinkeys' contains '#0'.
--- 570,584 ----
              with "#" does not work.
  
  
+       PN    When N is non-zero recognize C pragmas, and indent them like any
+             other code; does not concern other preprocessor directives.
+             When N is zero (default): don't recognize C pragmas, treating
+             them like every other preprocessor directive.
+ 
+ 
  The defaults, spelled out in full, are:
        cinoptions=>s,e0,n0,f0,{0,}0,^0,L-1,:s,=s,l0,b0,gs,hs,N0,E0,ps,ts,is,+s,
!                       c3,C0,/0,(2s,us,U0,w0,W0,k0,m0,j0,J0,)20,*70,#0,P0
  
  Vim puts a line in column 1 if:
  - It starts with '#' (preprocessor directives), if 'cinkeys' contains '#0'.
*** ../vim-8.2.0863/src/cindent.c       2020-01-12 13:48:15.627286141 +0100
--- src/cindent.c       2020-05-31 17:42:45.123006750 +0200
***************
*** 1845,1850 ****
--- 1845,1853 ----
      // 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,1925 ****
--- 1923,1929 ----
            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,2126 ****
        goto laterend;
      }
  
!     // #defines and so on always go at the left when included in 'cinkeys'.
      if (*theline == '#' && (*linecopy == '#' || in_cinkeys('#', ' ', TRUE)))
      {
!       amount = curbuf->b_ind_hash_comment;
!       goto theend;
      }
  
      // Is it a non-case label?        Then that goes at the left margin too 
unless:
--- 2120,2135 ----
        goto laterend;
      }
  
!     // #defines and so on go at the left when included in 'cinkeys',
!     // exluding pragmas when customized in 'cinoptions'
      if (*theline == '#' && (*linecopy == '#' || in_cinkeys('#', ' ', TRUE)))
      {
!       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:
*** ../vim-8.2.0863/src/structs.h       2020-05-31 16:41:04.646603340 +0200
--- src/structs.h       2020-05-31 17:42:45.123006750 +0200
***************
*** 2803,2808 ****
--- 2803,2809 ----
      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
*** ../vim-8.2.0863/src/testdir/test_cindent.vim        2020-03-08 
05:13:10.007536782 +0100
--- src/testdir/test_cindent.vim        2020-05-31 17:42:45.123006750 +0200
***************
*** 5272,5275 ****
--- 5272,5311 ----
    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
*** ../vim-8.2.0863/src/version.c       2020-05-31 16:41:04.650603321 +0200
--- src/version.c       2020-05-31 17:43:25.034847653 +0200
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     864,
  /**/

-- 
The term "free software" is defined by Richard M. Stallman as
being software that isn't necessarily for free.  Confusing?
Let's call it "Stallman software" then!
                                -- Bram Moolenaar

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202005311550.04VFoepD665894%40masaka.moolenaar.net.

Raspunde prin e-mail lui