Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion runtime/doc/fold.txt
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,8 @@ handles differently: Space, backslash and double-quote. |option-backslash|
FOLDCOLUMN *fold-foldcolumn*

'foldcolumn' is a number, which sets the width for a column on the side of the
window to indicate folds. When it is zero, there is no foldcolumn. A normal
window to indicate folds. When it is -1, the width is found automatically.
When it is zero, there is no foldcolumn. A normal
value is 4 or 5. The minimal useful value is 2, although 1 still provides
some information. The maximum is 12.

Expand Down
5 changes: 5 additions & 0 deletions runtime/doc/options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,10 @@ A jump table for the options with a short description can be found at |Q_op|.
stlnc:c ' ' or '=' statusline of the non-current windows
vert:c '│' or '|' vertical separators |:vsplit|
fold:c '·' or '-' filling 'foldtext'
foldopen:c '-' mark the beginning of a fold
foldclose:c '+' show a closed fold
foldend:c '└' mark the end of a fold
foldsep:c '|' open fold middle marker
diff:c '-' deleted lines of the 'diff' option

Any one that is omitted will fall back to the default. For "stl" and
Expand Down Expand Up @@ -2448,6 +2452,7 @@ A jump table for the options with a short description can be found at |Q_op|.
When non-zero, a column with the specified width is shown at the side
of the window which indicates open and closed folds. The maximum
value is 12.
When set to -1, adopt the maximum fold level as column width.
See |folding|.

*'foldenable'* *'fen'* *'nofoldenable'* *'nofen'*
Expand Down
40 changes: 40 additions & 0 deletions src/nvim/api/vim.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "nvim/vim.h"
#include "nvim/buffer.h"
#include "nvim/file_search.h"
#include "nvim/fold.h"
#include "nvim/window.h"
#include "nvim/types.h"
#include "nvim/ex_docmd.h"
Expand All @@ -44,6 +45,45 @@
# include "api/vim.c.generated.h"
#endif


/// Create a fold from line "start" to line "end" (inclusive) in the current
/// window.
/// @param window
/// @param start starting line
/// @param end starting end
/// @param err
void nvim_fold_create(Window window, Integer start, Integer end, Error *err)
Copy link
Member

@justinmk justinmk Mar 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be in api/window.c ?

see :help dev-api for API naming conventions: nvim_win_add_fold(), nvim_win_del_fold().

FUNC_API_SINCE(4)
{
win_T *win = find_window_by_handle(window, err);

if (!win) {
return;
}
// Window is
foldCreate(win, start, end);
}

/// Delete a fold at line "start" in the current window.
/// When "end" is not 0, delete all folds from "start" to "end".
/// When "recursive" is TRUE delete recursively.
/// @param window
void nvim_fold_delete(Window window, Integer start, Integer end, Boolean recursive, Error *err)
FUNC_API_SINCE(4)
{
win_T *win = find_window_by_handle(window, err);

if (!win) {
return;
}

deleteFold(
start,
end,
recursive,
false);
}

/// Executes an ex-command.
///
/// On parse error: forwards the Vim error; does not update v:errmsg.
Expand Down
3 changes: 2 additions & 1 deletion src/nvim/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2378,8 +2378,9 @@ void get_winopts(buf_T *buf)
curwin->w_fold_manual = wip->wi_fold_manual;
curwin->w_foldinvalid = true;
cloneFoldGrowArray(&wip->wi_folds, &curwin->w_folds);
} else
} else {
copy_winopt(&curwin->w_allbuf_opt, &curwin->w_onebuf_opt);
}

/* Set 'foldlevel' to 'foldlevelstart' if it's not negative. */
if (p_fdls >= 0)
Expand Down
17 changes: 7 additions & 10 deletions src/nvim/buffer_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1062,13 +1062,12 @@ struct window_S {
int w_lines_valid; /* number of valid entries */
wline_T *w_lines;

garray_T w_folds; /* array of nested folds */
bool w_fold_manual; /* when true: some folds are opened/closed
manually */
bool w_foldinvalid; /* when true: folding needs to be
recomputed */
int w_nrwidth; /* width of 'number' and 'relativenumber'
column being used */
garray_T w_folds; //!< array of nested folds
bool w_fold_manual; //!< when true: some folds are open/closed manually
bool w_foldinvalid; //!< when true: folding needs to be recomputed
int w_fdcwidth; //!< optimal width to draw 'foldcolumn'
int w_nrwidth; //!< width of 'number' and 'relativenumber'
//!< column being used
Copy link
Member

@justinmk justinmk Mar 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doxygen expects three slashes, no? Otherwise the !< has no effect. Actually I don't know what !< is, I've only see ///< .


/*
* === end of cached values ===
Expand Down Expand Up @@ -1166,9 +1165,7 @@ struct window_S {
int w_fraction;
int w_prev_fraction_row;

linenr_T w_nrwidth_line_count; /* line count when ml_nrwidth_width
* was computed. */
int w_nrwidth_width; /* nr of chars to print line count. */
int w_nrwidth_width; //!< nr of chars to print line count. */

qf_info_T *w_llist; /* Location list for this window */
/*
Expand Down
10 changes: 5 additions & 5 deletions src/nvim/charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ int chartabsize(char_u *p, colnr_T col)
RET_WIN_BUF_CHARTABSIZE(curwin, curbuf, p, col)
}

static int win_chartabsize(win_T *wp, char_u *p, colnr_T col)
static int win_chartabsize(const win_T *wp, char_u *p, colnr_T col)
{
RET_WIN_BUF_CHARTABSIZE(wp, wp->w_buffer, p, col)
}
Expand Down Expand Up @@ -738,7 +738,7 @@ int linetabsize_col(int startcol, char_u *s)
/// @param len
///
/// @return Number of characters the string will take on the screen.
unsigned int win_linetabsize(win_T *wp, char_u *line, colnr_T len)
unsigned int win_linetabsize(const win_T *wp, char_u *line, colnr_T len)
{
colnr_T col = 0;

Expand Down Expand Up @@ -928,7 +928,7 @@ int lbr_chartabsize_adv(char_u *line, char_u **s, colnr_T col)
/// @param headp
///
/// @return The number of characters taken up on the screen.
int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *headp)
int win_lbr_chartabsize(const win_T *wp, char_u *line, char_u *s, colnr_T col, int *headp)
{
colnr_T col2;
colnr_T col_adj = 0; /* col + screen size of tab */
Expand Down Expand Up @@ -1082,7 +1082,7 @@ int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *he
/// @param headp
///
/// @return The number of characters take up on the screen.
static int win_nolbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp)
static int win_nolbr_chartabsize(const win_T *wp, char_u *s, colnr_T col, int *headp)
{
int n;

Expand All @@ -1107,7 +1107,7 @@ static int win_nolbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp)
///
/// @param wp window
/// @param vcol column number
bool in_win_border(win_T *wp, colnr_T vcol)
bool in_win_border(const win_T *wp, colnr_T vcol)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
{
int width1; // width of first line (after line number)
Expand Down
9 changes: 6 additions & 3 deletions src/nvim/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -5776,22 +5776,25 @@ comp_textwidth (
)
{
int textwidth;
int fdc = compute_foldcolumn(curwin, 0);

textwidth = curbuf->b_p_tw;
if (textwidth == 0 && curbuf->b_p_wm) {
/* The width is the window width minus 'wrapmargin' minus all the
* things that add to the margin. */
textwidth = curwin->w_width - curbuf->b_p_wm;
if (cmdwin_type != 0)
if (cmdwin_type != 0) {
textwidth -= 1;
textwidth -= curwin->w_p_fdc;
}
textwidth -= fdc;

if (signcolumn_on(curwin)) {
textwidth -= 1;
}

if (curwin->w_p_nu || curwin->w_p_rnu)
if (curwin->w_p_nu || curwin->w_p_rnu) {
textwidth -= 8;
}
}
if (textwidth < 0)
textwidth = 0;
Expand Down
6 changes: 5 additions & 1 deletion src/nvim/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -8861,7 +8861,10 @@ static void f_foldtextresult(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
fold_count = foldedCount(curwin, lnum, &foldinfo);
if (fold_count > 0) {
text = get_foldtext(curwin, lnum, lnum + fold_count - 1, &foldinfo, buf);
text = get_foldtext(curwin, lnum, lnum + fold_count - 1,
foldinfo.fi_level, buf);
text = get_foldtext(curwin, lnum, lnum + fold_count - 1,
foldinfo.fi_level, buf);
if (text == buf) {
text = vim_strsave(text);
}
Expand Down Expand Up @@ -10609,6 +10612,7 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
"find_in_path",
"float",
"folding",
"folding_fillchars",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need these feature names since users can check has('nvim-0.3'). Also avoids having to guess what Vim will call a feature.

#if defined(UNIX)
"fork",
#endif
Expand Down
5 changes: 3 additions & 2 deletions src/nvim/ex_docmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -9847,8 +9847,9 @@ static void ex_match(exarg_T *eap)

static void ex_fold(exarg_T *eap)
{
if (foldManualAllowed(TRUE))
foldCreate(eap->line1, eap->line2);
if (foldManualAllowed(TRUE)) {
foldCreate(curwin, eap->line1, eap->line2);
}
}

static void ex_foldopen(exarg_T *eap)
Expand Down
Loading