aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Prager <splinterofchaos@gmail.com>2014-09-26 20:29:17 -0400
committerScott Prager <splinterofchaos@gmail.com>2014-12-19 18:57:45 -0500
commit12b3f49ea1c5a60e81e445756d1a5a1a850095b0 (patch)
tree5f40532ca521d5456a97c90105f0bd54d71122bf
parent949fb9721f8cf3f6e9d27d7a56f0b57daf587312 (diff)
downloadrneovim-12b3f49ea1c5a60e81e445756d1a5a1a850095b0.tar.gz
rneovim-12b3f49ea1c5a60e81e445756d1a5a1a850095b0.tar.bz2
rneovim-12b3f49ea1c5a60e81e445756d1a5a1a850095b0.zip
vim-patch:7.4.350
Problem: Using C indenting for Javascript does not work well for a {} block inside parenthesis. Solution: When looking for a matching paren ignore one that is before the start of a {} block. https://code.google.com/p/vim/source/detail?r=v7-4-350
-rw-r--r--src/nvim/indent_c.c34
-rw-r--r--src/nvim/testdir/test3.in4
-rw-r--r--src/nvim/testdir/test3.ok4
-rw-r--r--src/nvim/version.c2
4 files changed, 38 insertions, 6 deletions
diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c
index 5c38a444ad..8ad0a997f1 100644
--- a/src/nvim/indent_c.c
+++ b/src/nvim/indent_c.c
@@ -1198,7 +1198,7 @@ static pos_T *find_start_brace(void)
return trypos;
}
-/// Find the matching '(', failing if it is in a comment.
+/// Find the matching '(', ignoring it if it is in a comment.
/// @returns NULL or the found match.
static pos_T *find_match_paren(int ind_maxparen)
{
@@ -1223,6 +1223,29 @@ static pos_T *find_match_paren(int ind_maxparen)
return trypos;
}
+/// Find the matching '(', ignoring it if it is in a comment or before an
+/// unmatched {.
+/// @returns NULL or the found match.
+static pos_T *find_match_paren_after_brace(int ind_maxparen)
+{
+ pos_T *trypos = find_match_paren(ind_maxparen);
+ if (trypos == NULL) {
+ return NULL;
+ }
+
+ pos_T *tryposBrace = find_start_brace();
+ // If both an unmatched '(' and '{' is found. Ignore the '('
+ // position if the '{' is further down.
+ if (tryposBrace != NULL
+ && (trypos->lnum != tryposBrace->lnum
+ ? trypos->lnum < tryposBrace->lnum
+ : trypos->col < tryposBrace->col)) {
+ trypos = NULL;
+ }
+ return trypos;
+}
+
+
/*
* Return ind_maxparen corrected for the difference in line number between the
* cursor position and "startpos". This makes sure that searching for a
@@ -1934,13 +1957,14 @@ int get_c_indent(void)
else {
curwin->w_cursor.lnum = our_paren_pos.lnum;
curwin->w_cursor.col = col;
- if (find_match_paren(curbuf->b_ind_maxparen) != NULL)
+ if (find_match_paren_after_brace(curbuf->b_ind_maxparen)) {
amount += curbuf->b_ind_unclosed2;
- else {
- if (is_if_for_while)
+ } else {
+ if (is_if_for_while) {
amount += curbuf->b_ind_if_for_while;
- else
+ } else {
amount += curbuf->b_ind_unclosed;
+ }
}
}
/*
diff --git a/src/nvim/testdir/test3.in b/src/nvim/testdir/test3.in
index 46e5767062..287ed8e5b3 100644
--- a/src/nvim/testdir/test3.in
+++ b/src/nvim/testdir/test3.in
@@ -1950,6 +1950,10 @@ ENDTEST
JSSTART
(function($){
+if (cond &&
+cond) {
+stmt;
+}
var class_name='myclass';
function private_method() {
diff --git a/src/nvim/testdir/test3.ok b/src/nvim/testdir/test3.ok
index d73a5e1230..edd9e236a6 100644
--- a/src/nvim/testdir/test3.ok
+++ b/src/nvim/testdir/test3.ok
@@ -1728,6 +1728,10 @@ JSEND
JSSTART
(function($){
+ if (cond &&
+ cond) {
+ stmt;
+ }
var class_name='myclass';
function private_method() {
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 43b759e9fb..0f885cde01 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -387,7 +387,7 @@ static int included_patches[] = {
353,
352,
351,
- //350,
+ 350,
349,
348,
347,