comparison src/misc1.c @ 14:946da5994c01

updated for version 7.0006
author vimboss
date Mon, 05 Jul 2004 15:58:32 +0000
parents 4424b47a0797
children 3ba373b54370
comparison
equal deleted inserted replaced
13:24d5189d3956 14:946da5994c01
7375 * work correctly: now (v5.3) it seems all C/C++ oriented: 7375 * work correctly: now (v5.3) it seems all C/C++ oriented:
7376 * - it does not recognize the #\( and #\) notations as character literals 7376 * - it does not recognize the #\( and #\) notations as character literals
7377 * - it doesn't know about comments starting with a semicolon 7377 * - it doesn't know about comments starting with a semicolon
7378 * - it incorrectly interprets '(' as a character literal 7378 * - it incorrectly interprets '(' as a character literal
7379 * All this messes up get_lisp_indent in some rare cases. 7379 * All this messes up get_lisp_indent in some rare cases.
7380 * Update from Sergey Khorev:
7381 * I tried to fix the first two issues.
7380 */ 7382 */
7381 int 7383 int
7382 get_lisp_indent() 7384 get_lisp_indent()
7383 { 7385 {
7384 pos_T *pos, realpos; 7386 pos_T *pos, realpos, paren;
7385 int amount; 7387 int amount;
7386 char_u *that; 7388 char_u *that;
7387 colnr_T col; 7389 colnr_T col;
7388 colnr_T firsttry; 7390 colnr_T firsttry;
7389 int parencount, quotecount; 7391 int parencount, quotecount;
7393 vi_lisp = (vim_strchr(p_cpo, CPO_LISP) != NULL); 7395 vi_lisp = (vim_strchr(p_cpo, CPO_LISP) != NULL);
7394 7396
7395 realpos = curwin->w_cursor; 7397 realpos = curwin->w_cursor;
7396 curwin->w_cursor.col = 0; 7398 curwin->w_cursor.col = 0;
7397 7399
7398 if ((pos = findmatch(NULL, '(')) != NULL) 7400 if ((pos = findmatch(NULL, '(')) == NULL)
7401 pos = findmatch(NULL, '[');
7402 else
7403 {
7404 paren = *pos;
7405 pos = findmatch(NULL, '[');
7406 if (pos == NULL || ltp(pos, &paren))
7407 pos = &paren;
7408 }
7409 if (pos != NULL)
7399 { 7410 {
7400 /* Extra trick: Take the indent of the first previous non-white 7411 /* Extra trick: Take the indent of the first previous non-white
7401 * line that is at the same () level. */ 7412 * line that is at the same () level. */
7402 amount = -1; 7413 amount = -1;
7403 parencount = 0; 7414 parencount = 0;
7424 { 7435 {
7425 that++; 7436 that++;
7426 while (*that && (*that != '"' || *(that - 1) == '\\')) 7437 while (*that && (*that != '"' || *(that - 1) == '\\'))
7427 ++that; 7438 ++that;
7428 } 7439 }
7429 if (*that == '(') 7440 if (*that == '(' || *that == '[')
7430 ++parencount; 7441 ++parencount;
7431 else if (*that == ')') 7442 else if (*that == ')' || *that == ']')
7432 --parencount; 7443 --parencount;
7433 } 7444 }
7434 if (parencount == 0) 7445 if (parencount == 0)
7435 { 7446 {
7436 amount = get_indent(); 7447 amount = get_indent();
7463 * 7474 *
7464 * (let ((a 1)) instead (let ((a 1)) 7475 * (let ((a 1)) instead (let ((a 1))
7465 * (...)) of (...)) 7476 * (...)) of (...))
7466 */ 7477 */
7467 7478
7468 if (!vi_lisp && *that == '(' && lisp_match(that + 1)) 7479 if (!vi_lisp && (*that == '(' || *that == '[')
7480 && lisp_match(that + 1))
7469 amount += 2; 7481 amount += 2;
7470 else 7482 else
7471 { 7483 {
7472 that++; 7484 that++;
7473 amount++; 7485 amount++;
7481 7493
7482 if (*that && *that != ';') /* not a comment line */ 7494 if (*that && *that != ';') /* not a comment line */
7483 { 7495 {
7484 /* test *that != '(' to accomodate first let/do 7496 /* test *that != '(' to accomodate first let/do
7485 * argument if it is more than one line */ 7497 * argument if it is more than one line */
7486 if (!vi_lisp && *that != '(') 7498 if (!vi_lisp && *that != '(' && *that != '[')
7487 firsttry++; 7499 firsttry++;
7488 7500
7489 parencount = 0; 7501 parencount = 0;
7490 quotecount = 0; 7502 quotecount = 0;
7491 7503
7497 { 7509 {
7498 while (*that 7510 while (*that
7499 && (!vim_iswhite(*that) 7511 && (!vim_iswhite(*that)
7500 || quotecount 7512 || quotecount
7501 || parencount) 7513 || parencount)
7502 && (!(*that == '(' 7514 && (!((*that == '(' || *that == '[')
7503 && !quotecount 7515 && !quotecount
7504 && !parencount 7516 && !parencount
7505 && vi_lisp))) 7517 && vi_lisp)))
7506 { 7518 {
7507 if (*that == '"') 7519 if (*that == '"')
7508 quotecount = !quotecount; 7520 quotecount = !quotecount;
7509 if (*that == '(' && !quotecount) 7521 if ((*that == '(' || *that == '[')
7522 && !quotecount)
7510 ++parencount; 7523 ++parencount;
7511 if (*that == ')' && !quotecount) 7524 if ((*that == ')' || *that == ']')
7525 && !quotecount)
7512 --parencount; 7526 --parencount;
7513 if (*that == '\\' && *(that+1) != NUL) 7527 if (*that == '\\' && *(that+1) != NUL)
7514 amount += lbr_chartabsize_adv(&that, 7528 amount += lbr_chartabsize_adv(&that,
7515 (colnr_T)amount); 7529 (colnr_T)amount);
7516 amount += lbr_chartabsize_adv(&that, 7530 amount += lbr_chartabsize_adv(&that,
7528 } 7542 }
7529 } 7543 }
7530 } 7544 }
7531 } 7545 }
7532 else 7546 else
7533 amount = 0; /* no matching '(' found, use zero indent */ 7547 amount = 0; /* no matching '(' or '[' found, use zero indent */
7534 7548
7535 curwin->w_cursor = realpos; 7549 curwin->w_cursor = realpos;
7536 7550
7537 return amount; 7551 return amount;
7538 } 7552 }