mirror of
https://github.com/neovim/neovim.git
synced 2025-09-19 09:48:19 +00:00
Port vim's patch 7.4.338 ('breakindent')
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "nvim/charset.h"
|
||||
#include "nvim/farsi.h"
|
||||
#include "nvim/func_attr.h"
|
||||
#include "nvim/indent.h"
|
||||
#include "nvim/main.h"
|
||||
#include "nvim/mbyte.h"
|
||||
#include "nvim/memline.h"
|
||||
@@ -775,9 +776,10 @@ int linetabsize(char_u *s)
|
||||
int linetabsize_col(int startcol, char_u *s)
|
||||
{
|
||||
colnr_T col = startcol;
|
||||
char_u *line = s; /* pointer to start of line, for breakindent */
|
||||
|
||||
while (*s != NUL) {
|
||||
col += lbr_chartabsize_adv(&s, col);
|
||||
col += lbr_chartabsize_adv(line, &s, col);
|
||||
}
|
||||
return (int)col;
|
||||
}
|
||||
@@ -785,17 +787,17 @@ int linetabsize_col(int startcol, char_u *s)
|
||||
/// Like linetabsize(), but for a given window instead of the current one.
|
||||
///
|
||||
/// @param wp
|
||||
/// @param p
|
||||
/// @param line
|
||||
/// @param len
|
||||
///
|
||||
/// @return Number of characters the string will take on the screen.
|
||||
int win_linetabsize(win_T *wp, char_u *p, colnr_T len)
|
||||
int win_linetabsize(win_T *wp, char_u *line, colnr_T len)
|
||||
{
|
||||
colnr_T col = 0;
|
||||
char_u *s;
|
||||
|
||||
for (s = p; *s != NUL && (len == MAXCOL || s < p + len); mb_ptr_adv(s)) {
|
||||
col += win_lbr_chartabsize(wp, s, col, NULL);
|
||||
for (s = line; *s != NUL && (len == MAXCOL || s < line + len); mb_ptr_adv(s)) {
|
||||
col += win_lbr_chartabsize(wp, line, s, col, NULL);
|
||||
}
|
||||
return (int)col;
|
||||
}
|
||||
@@ -922,32 +924,34 @@ int vim_isprintc_strict(int c)
|
||||
|
||||
/// like chartabsize(), but also check for line breaks on the screen
|
||||
///
|
||||
/// @param line
|
||||
/// @param s
|
||||
/// @param col
|
||||
///
|
||||
/// @return The number of characters taken up on the screen.
|
||||
int lbr_chartabsize(unsigned char *s, colnr_T col)
|
||||
int lbr_chartabsize(char_u *line, unsigned char *s, colnr_T col)
|
||||
{
|
||||
if (!curwin->w_p_lbr && (*p_sbr == NUL)) {
|
||||
if (!curwin->w_p_lbr && (*p_sbr == NUL) && !curwin->w_p_bri) {
|
||||
if (curwin->w_p_wrap) {
|
||||
return win_nolbr_chartabsize(curwin, s, col, NULL);
|
||||
}
|
||||
RET_WIN_BUF_CHARTABSIZE(curwin, curbuf, s, col)
|
||||
}
|
||||
return win_lbr_chartabsize(curwin, s, col, NULL);
|
||||
return win_lbr_chartabsize(curwin, line == NULL ? s: line, s, col, NULL);
|
||||
}
|
||||
|
||||
/// Call lbr_chartabsize() and advance the pointer.
|
||||
///
|
||||
/// @param line
|
||||
/// @param s
|
||||
/// @param col
|
||||
///
|
||||
/// @return The number of characters take up on the screen.
|
||||
int lbr_chartabsize_adv(char_u **s, colnr_T col)
|
||||
int lbr_chartabsize_adv(char_u *line, char_u **s, colnr_T col)
|
||||
{
|
||||
int retval;
|
||||
|
||||
retval = lbr_chartabsize(*s, col);
|
||||
retval = lbr_chartabsize(line, *s, col);
|
||||
mb_ptr_adv(*s);
|
||||
return retval;
|
||||
}
|
||||
@@ -959,12 +963,13 @@ int lbr_chartabsize_adv(char_u **s, colnr_T col)
|
||||
/// value, init to 0 before calling.
|
||||
///
|
||||
/// @param wp
|
||||
/// @param line
|
||||
/// @param s
|
||||
/// @param col
|
||||
/// @param headp
|
||||
///
|
||||
/// @return The number of characters taken up on the screen.
|
||||
int win_lbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp)
|
||||
int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *headp)
|
||||
{
|
||||
colnr_T col2;
|
||||
colnr_T colmax;
|
||||
@@ -975,8 +980,8 @@ int win_lbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp)
|
||||
int tab_corr = (*s == TAB);
|
||||
int n;
|
||||
|
||||
// No 'linebreak' and 'showbreak': return quickly.
|
||||
if (!wp->w_p_lbr && (*p_sbr == NUL)) {
|
||||
// No 'linebreak', 'showbreak' and 'breakindent': return quickly.
|
||||
if (!wp->w_p_lbr && !wp->w_p_bri && (*p_sbr == NUL)) {
|
||||
if (wp->w_p_wrap) {
|
||||
return win_nolbr_chartabsize(wp, s, col, headp);
|
||||
}
|
||||
@@ -1039,11 +1044,12 @@ int win_lbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp)
|
||||
mb_added = 1;
|
||||
}
|
||||
|
||||
// May have to add something for 'showbreak' string at start of line
|
||||
// May have to add something for 'breakindent' and/or 'showbreak'
|
||||
// string at start of line.
|
||||
// Set *headp to the size of what we add.
|
||||
added = 0;
|
||||
|
||||
if ((*p_sbr != NUL) && wp->w_p_wrap && (col != 0)) {
|
||||
if ((*p_sbr != NUL || wp->w_p_bri) && wp->w_p_wrap && (col != 0)) {
|
||||
numberextra = win_col_off(wp);
|
||||
col += numberextra + mb_added;
|
||||
|
||||
@@ -1056,7 +1062,12 @@ int win_lbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp)
|
||||
}
|
||||
|
||||
if ((col == 0) || (col + size > (colnr_T)wp->w_width)) {
|
||||
added = vim_strsize(p_sbr);
|
||||
added = 0;
|
||||
if (*p_sbr != NUL)
|
||||
added += vim_strsize(p_sbr);
|
||||
if (wp->w_p_bri)
|
||||
added += get_breakindent_win(wp, line);
|
||||
|
||||
if (tab_corr) {
|
||||
size += (added / wp->w_buffer->b_p_ts) * wp->w_buffer->b_p_ts;
|
||||
} else {
|
||||
@@ -1157,13 +1168,14 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor,
|
||||
colnr_T vcol;
|
||||
char_u *ptr; // points to current char
|
||||
char_u *posptr; // points to char at pos->col
|
||||
char_u *line; // start of the line
|
||||
int incr;
|
||||
int head;
|
||||
int ts = wp->w_buffer->b_p_ts;
|
||||
int c;
|
||||
|
||||
vcol = 0;
|
||||
ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE);
|
||||
line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE);
|
||||
|
||||
if (pos->col == MAXCOL) {
|
||||
// continue until the NUL
|
||||
@@ -1173,11 +1185,13 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor,
|
||||
}
|
||||
|
||||
// This function is used very often, do some speed optimizations.
|
||||
// When 'list', 'linebreak' and 'showbreak' are not set use a simple loop.
|
||||
// Also use this when 'list' is set but tabs take their normal size.
|
||||
// When 'list', 'linebreak', 'showbreak' and 'breakindent' are not set
|
||||
// use a simple loop.
|
||||
// Also use this when 'list' is set but tabs take their normal size.
|
||||
if ((!wp->w_p_list || (lcs_tab1 != NUL))
|
||||
&& !wp->w_p_lbr
|
||||
&& (*p_sbr == NUL)) {
|
||||
&& (*p_sbr == NUL)
|
||||
&& !wp->w_p_bri ) {
|
||||
for (;;) {
|
||||
head = 0;
|
||||
c = *ptr;
|
||||
@@ -1229,7 +1243,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor,
|
||||
for (;;) {
|
||||
// A tab gets expanded, depending on the current column
|
||||
head = 0;
|
||||
incr = win_lbr_chartabsize(wp, ptr, vcol, &head);
|
||||
incr = win_lbr_chartabsize(wp, line, ptr, vcol, &head);
|
||||
|
||||
// make sure we don't go past the end of the line
|
||||
if (*ptr == NUL) {
|
||||
|
Reference in New Issue
Block a user