[patch] New method for C code and expression indenting

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[patch] New method for C code and expression indenting

Lech Lorens
I implemented an option for Vim which modifies the way C indenting is performed
and the value returned by 'indentexpr' option affects indentation. The option
has been described in todo.txt:

7   Use Tabs for the indent of starting lines, pad with spaces for
    continuation lines.  Allows changing 'tabstop' without messing up the

Basically, indenting the following piece of C code will yield:
- without the option set:
void func()
        if (opta)
                while (optb)
                        if (optc)
                                printf("opta == %d, optb == %d, optc == %d\n",
// vim: ft=c ts=4 sw=4 cino=(0,l1

- with the option set:
void func2()
        if (opta)
                while (optb)
                        if (optc)
                                printf("opta == %d, optb == %d, optc == %d\n",
// vim: ft=c ts=4 sw=4 cino=(0,l1 tabindent
If you setting of your tab stops, you will see how in the first example
the indentation becomes invalid.

If any readers of vim-dev find this option interesting, I would like to ask
them for help:
- Would you be so kind and review the code?
- I called the option 'tabindent' ('ti' for short). I don't like the name
        because it doesn't make obvious what the option does. At first I chose
        'tablevelindent', but this is hardly any better and seems long. What
        name would you suggest?
- There are so many options available for 'cinoptions'. It is probably
        impossible to test the interaction between 'ti' and all possible
        'cinoptions' values. Bug reports would be very appreciated.
- I wrote some documentation for 'ti'. I don't know if I should mention
        the option in any other place? Perhaps I mentioned it too many times?
        Perhaps the descriptions are unclear?
- It is possible to get indentation in Vim script by calling cindent()
        or lispindent(). Should the values returned by these functions change
        when 'ti' is set? Should I add new functions to the Vim scripting
        language to make the new indentation values available to the user?
- It is now possible to use the new indenting style when 'indentexpr' is
        set. I modified $VIMRUNTIME/indent/vim.vim to use the new indenting
        style if 'ti' is set. Perhaps you could update indent script for your
        favourite language and test it? For description refer to 'indentexpr'

What I know that remains to be done at this point:
- handle 'tabindent' for Lisp indenting,
- return lists when appropriate when cindent() or lispindent() is called
  from Vim script (?),
- add more tests.

The attached files include:
- tabindent-src.patch - patch against Vim 7.2.403 for the source code,
- tabindent-doc.patch - patch for the documentation,
- tabindent-runtime.patch - patch for script defining indentation for
        Vim scripting language indent/vim.vim,
- tabindent-tests.patch - tests for the new functionality.

Thank you in advance for your help!


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

To unsubscribe from this group, send email to vim_dev+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

tabindent-src.patch (31K) Download Attachment
tabindent-doc.patch (5K) Download Attachment
tabindent-tests.patch (7K) Download Attachment
tabindent-runtime.patch (2K) Download Attachment