Hi to all. I wrote patch, that adds cinoptions 's'. sN - indent
inside C++ namespace N characters extra. (default 0). For example,
you can set cino=s-s, and remove indent level inside C++ namespace
(look Google C++ Coding Style).
I made patch from Mercurial repo by 'hg diff'.
--
(sandbox)[pitman@sansa]$ cat cin_cpp_namespace.patch
diff -r 951641b8784d runtime/doc/indent.txt
--- a/runtime/doc/indent.txt Mon Jan 17 20:08:11 2011 +0100
+++ b/runtime/doc/indent.txt Tue Jan 18 18:40:18 2011 +0300
@@ -476,6 +476,18 @@
that lines starting with # will still be seen as
preprocessor
lines.
+ sN Indent inside C++ namespace N characters extra.
(default 0).
+
+ cino= cino=s-s >
+ namespace { namespace {
+ void function(); void function();
+ } }
+
+ namespace my namespace my
+ { {
+ void function(); void function();
+ } }
+<
The defaults, spelled out in full, are:
cinoptions=>s,e0,n0,f0,{0,}0,^0,L-1,:s,=s,l0,b0,gs,hs,ps,ts,is,
+s,
diff -r 951641b8784d src/misc1.c
--- a/src/misc1.c Mon Jan 17 20:08:11 2011 +0100
+++ b/src/misc1.c Tue Jan 18 18:40:18 2011 +0300
@@ -14,6 +14,8 @@
#include "vim.h"
#include "version.h"
+#define FIND_NAMESPACE_LIM 20
+
static char_u *vim_version_dir __ARGS((char_u *vimdir));
static char_u *remove_tail __ARGS((char_u *p, char_u *pend, char_u
*name));
static int copy_indent __ARGS((int size, char_u *src));
@@ -4924,6 +4926,7 @@
static int corr_ind_maxparen __ARGS((int ind_maxparen, pos_T
*startpos));
static int find_last_paren __ARGS((char_u *l, int start, int
end));
static int find_match __ARGS((int lookfor, linenr_T ourscope, int
ind_maxparen, int ind_maxcomment));
+static int cin_is_cpp_namespace __ARGS((char_u *));
static int ind_hash_comment = 0; /* # starts a comment */
@@ -5187,6 +5190,59 @@
}
/*
+ * Recognize a "namespace" scope declaration.
+ */
+ static int
+cin_is_cpp_namespace(s)
+ char_u *s;
+{
+ char_u *p;
+ int has_name = FALSE;
+
+ s = cin_skipcomment(s);
+ if (STRNCMP(s, "namespace", 9) == 0)
+ {
+ if (strlen(s) == 9)
+ return TRUE;
+
+ p = s + 9;
+ if (vim_iswordc(*p))
+ return FALSE;
+
+ p = cin_skipcomment(skipwhite(p));
+
+ while (*p != '\0')
+ {
+ if (vim_iswhite(*p))
+ {
+ has_name = TRUE;
+ p = cin_skipcomment(skipwhite(p));
+ }
+ else if (*p == '{')
+ {
+ return TRUE;
+ }
+ else if (vim_iswordc(*p))
+ {
+ if (has_name)
+ {
+ return FALSE;
+ }
+ ++p;
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/*
* Return a pointer to the first non-empty non-comment character
after a ':'.
* Return NULL if not found.
* case 234: a = b;
@@ -6223,6 +6279,11 @@
*/
int ind_keep_case_label = 0;
+ /*
+ * handle C++ namespace
+ */
+ int ind_cpp_namespace = 0;
+
pos_T cur_curpos;
int amount;
int scope_amount;
@@ -6263,6 +6324,7 @@
int n;
int iscase;
int lookfor_break;
+ int lookfor_cpp_namespace = FALSE;
int cont_amount = 0; /* amount for continuation
line */
int original_line_islabel;
@@ -6336,6 +6398,7 @@
case 'J': ind_js = n; break;
case 'l': ind_keep_case_label = n; break;
case '#': ind_hash_comment = n; break;
+ case 's': ind_cpp_namespace = n; break;
}
if (*options == ',')
++options;
@@ -6902,11 +6965,24 @@
if (start_brace == BRACE_IN_COL0) /* '{' is in
column 0 */
{
amount = ind_open_left_imag;
+ lookfor_cpp_namespace = TRUE;
+ }
+ else if (start_brace == BRACE_AT_START &&
+ lookfor_cpp_namespace) /* '{' is at start
*/
+ {
+
+ lookfor_cpp_namespace = TRUE;
}
else
{
if (start_brace == BRACE_AT_END) /* '{' is at end
of line */
+ {
amount += ind_open_imag;
+
+ l = skipwhite(ml_get_curline());
+ if (cin_is_cpp_namespace(l))
+ amount += ind_cpp_namespace;
+ }
else
{
/* Compensate for adding ind_open_extra later. */
@@ -6968,7 +7044,44 @@
* int x,
* here; <-- add ind_continuation
*/
- if (lookfor == LOOKFOR_ENUM_OR_INIT)
+ if (lookfor_cpp_namespace)
+ {
+ if (curwin->w_cursor.lnum == 0
+ || curwin->w_cursor.lnum
+ < ourscope - FIND_NAMESPACE_LIM)
+ break;
+
+ l = ml_get_curline();
+
+ /*
+ * If we're in a comment now, skip to the
start of the
+ * comment.
+ */
+ trypos = find_start_comment(ind_maxcomment);
+ if (trypos != NULL)
+ {
+ curwin->w_cursor.lnum = trypos->lnum + 1;
+ curwin->w_cursor.col = 0;
+ continue;
+ }
+
+ /*
+ * Skip preprocessor directives and blank
lines.
+ */
+ if (cin_ispreproc_cont(&l, &curwin-
>w_cursor.lnum))
+ continue;
+
+ if (cin_is_cpp_namespace(l))
+ {
+ amount += ind_cpp_namespace;
+ break;
+ }
+
+ if (cin_nocode(l) || (strlen(l) == 1 && l[0]
== '{'))
+ continue;
+
+ }
+ else if (lookfor == LOOKFOR_ENUM_OR_INIT)
{
if (curwin->w_cursor.lnum == 0
|| curwin->w_cursor.lnum
--
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