Loading ...
Sorry, an error occurred while loading the content.
 

Re: Function to complete #if's

Expand Messages
  • Thomas S. Urban
    ... [another nice script cut] Here is an improved (well, maybe just expanded) version that will automatically indent your preprocessor directives if they are
    Message 1 of 10 , Sep 1, 2001
      On Wed, Aug 01, 2001 at 08:29:22PM +0100, Mark Zealey wrote:
      > On Wed, Aug 01, 2001 at 09:48:50PM +0300, Bohdan Vlasyuk wrote:
      >
      > > On Wed, Aug 01, 2001 at 07:38:10PM +0100, Mark Zealey wrote:
      > >
      > > > And vim could automatically fill in the #else and #endif with /* __foo__ */
      > > > after them, as is commonly the style in complexed .h files.
      >
      > [Nice script cut]
      >
      >
      > Thanks! here's a slightly fixed version which works with #ifndef too.
      > preprocessor macro's can't have whitepsace before the # however, I believe, so I
      > fixed that:
      >

      [another nice script cut]

      Here is an improved (well, maybe just expanded) version that will
      automatically indent your preprocessor directives if they are nested.
      It also handles mutliple #elif directives (adding to the comments on
      each subsequent #el* and the #endif). It uses // for C++, /* */ for C.

      The imaps are:
      #i -> #if (user completes to #ifdef, #ifndef, or just #if args)
      #d -> #define
      #u -> #undef
      #el -> #el (user completes to #else or #elif)
      #en -> #endif
      (you might want to change them to the full words if you don't like
      suprises as you type)

      Like the inspiring script, comment adding is only triggered for the #en
      mapping. All the others do the nested indenting. So if I type this:

      #idef BILL
      #indef BOB
      #d FRED
      #en
      #en
      #i 1
      #i !defined(BILL)
      #elif defined(FRED)
      #elif defined(F) || !defined(R)
      #d 2 3
      #else
      #idef TRUE
      #d 3 2
      #en
      #en
      #u BOB
      #en

      I get this output (with ts=2):

      #ifdef BILL
      # ifndef BOB
      # define FRED
      # endif /* !BOB */
      #endif /* BILL */
      #if 1
      # if !defined(BILL)
      # elif defined(FRED) /* !defined(BILL) */
      # elif defined(F) || !defined(R) /* !defined(BILL) + defined(FRED) */
      # define 2 3
      # else /* !defined(BILL) + defined(FRED) + defined(F) || !defined(R) */
      # ifdef TRUE
      # define 3 2
      # endif /* TRUE */
      # endif /* !defined(BILL) + defined(FRED) + defined(F) || !defined(R) */
      # undef BOB
      #endif /* 1 */

      If you don't find this indenting style attractive, you might find this
      all that useful. It's implemented with two functions though, so you
      could separate them. Moderated numbers of #elif's can produce really
      long comments.



      Scott

      --
      If all men were brothers, would you let one marry your sister?
    Your message has been successfully submitted and would be delivered to recipients shortly.