To: vim-dev@vim.org Subject: Patch 6.0.089 Fcc: outbox From: Bram Moolenaar MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.0.089 Problem: In a C file, using "==" to align a line starting with "* " after a line with "* -" indents one space too few. (Piet Delport) Solution: Align with the previous line if the comment-start-string matches there. Files: src/misc1.c *** ../vim60.88/src/misc1.c Wed Oct 24 13:22:11 2001 --- src/misc1.c Tue Nov 6 19:33:32 2001 *************** *** 4792,4797 **** --- 4792,4799 ---- && (trypos = find_start_comment(ind_maxcomment)) != NULL) /* XXX */ { int lead_start_len = 2; + int lead_middle_len = 1; + char_u lead_start[COM_MAX_LEN]; /* start-comment string */ char_u lead_middle[COM_MAX_LEN]; /* middle-comment string */ char_u lead_end[COM_MAX_LEN]; /* end-comment string */ char_u *p; *************** *** 4827,4858 **** (void)copy_option_part(&p, lead_end, COM_MAX_LEN, ","); if (what == COM_START) { ! lead_start_len = (int)STRLEN(lead_end); start_off = off; start_align = align; } else if (what == COM_MIDDLE) { STRCPY(lead_middle, lead_end); } else if (what == COM_END) { /* If our line starts with the middle comment string, line it * up with the comment opener per the 'comments' option. */ ! if (STRNCMP(theline, lead_middle, STRLEN(lead_middle)) == 0 && STRNCMP(theline, lead_end, STRLEN(lead_end)) != 0) { if (start_off != 0) amount += start_off; else if (start_align == COM_RIGHT) ! amount += lead_start_len - (int)STRLEN(lead_middle); ! done = TRUE; break; } /* If our line starts with the end comment string, line it up * with the middle comment */ ! if (STRNCMP(theline, lead_middle, STRLEN(lead_middle)) != 0 && STRNCMP(theline, lead_end, STRLEN(lead_end)) == 0) { amount = get_indent_lnum(curwin->w_cursor.lnum - 1); --- 4829,4878 ---- (void)copy_option_part(&p, lead_end, COM_MAX_LEN, ","); if (what == COM_START) { ! STRCPY(lead_start, lead_end); ! lead_start_len = (int)STRLEN(lead_start); start_off = off; start_align = align; } else if (what == COM_MIDDLE) { STRCPY(lead_middle, lead_end); + lead_middle_len = (int)STRLEN(lead_middle); } else if (what == COM_END) { /* If our line starts with the middle comment string, line it * up with the comment opener per the 'comments' option. */ ! if (STRNCMP(theline, lead_middle, lead_middle_len) == 0 && STRNCMP(theline, lead_end, STRLEN(lead_end)) != 0) { + done = TRUE; + if (curwin->w_cursor.lnum > 1) + { + /* If the start comment string matches in the previous + * line, use the indent of that line pluss offset. If + * the middle comment string matches in the previous + * line, use the indent of that line. XXX */ + look = skipwhite(ml_get(curwin->w_cursor.lnum - 1)); + if (STRNCMP(look, lead_start, lead_start_len) == 0) + amount = get_indent_lnum(curwin->w_cursor.lnum - 1); + else if (STRNCMP(look, lead_middle, + lead_middle_len) == 0) + { + amount = get_indent_lnum(curwin->w_cursor.lnum - 1); + break; + } + } if (start_off != 0) amount += start_off; else if (start_align == COM_RIGHT) ! amount += lead_start_len - lead_middle_len; break; } /* If our line starts with the end comment string, line it up * with the middle comment */ ! if (STRNCMP(theline, lead_middle, lead_middle_len) != 0 && STRNCMP(theline, lead_end, STRLEN(lead_end)) == 0) { amount = get_indent_lnum(curwin->w_cursor.lnum - 1); *************** *** 4860,4866 **** if (off != 0) amount += off; else if (align == COM_RIGHT) ! amount += lead_start_len - (int)STRLEN(lead_middle); done = TRUE; break; } --- 4880,4886 ---- if (off != 0) amount += off; else if (align == COM_RIGHT) ! amount += lead_start_len - lead_middle_len; done = TRUE; break; } *** ../vim60.88/src/version.c Tue Nov 6 19:38:36 2001 --- src/version.c Tue Nov 6 19:29:12 2001 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 89, /**/ -- If they don't keep on exercising their lips, he thought, their brains start working. -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy" /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net \\\ ((( Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim ))) \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///