Data Structures | Macros | Typedefs | Functions
fold.c File Reference
#include <inttypes.h>
#include <string.h>
#include "nvim/ascii.h"
#include "nvim/buffer_updates.h"
#include "nvim/change.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/eval.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_session.h"
#include "nvim/extmark.h"
#include "nvim/fold.h"
#include "nvim/func_attr.h"
#include "nvim/garray.h"
#include "nvim/indent.h"
#include "nvim/mark.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/move.h"
#include "nvim/ops.h"
#include "nvim/option.h"
#include "nvim/plines.h"
#include "nvim/screen.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/undo.h"
#include "nvim/vim.h"

Data Structures

struct  fold_T
 
struct  fline_T
 

Macros

#define FD_OPEN   0
 
#define FD_CLOSED   1
 
#define FD_LEVEL   2
 
#define MAX_LEVEL   20
 
#define DONE_NOTHING   0
 
#define DONE_ACTION   1
 
#define DONE_FOLD   2
 
#define DELETE_FOLD_NESTED(fd)   deleteFoldRecurse(bp, &((fd)->fd_nested))
 
#define FOLD_END(fp)   ((fp)->fd_top + (fp)->fd_len - 1)
 
#define VALID_FOLD(fp, gap)   ((gap)->ga_len > 0 && (fp) < ((fold_T *)(gap)->ga_data + (gap)->ga_len))
 
#define FOLD_INDEX(fp, gap)   ((size_t)(fp - ((fold_T *)(gap)->ga_data)))
 

Typedefs

typedef void(* LevelGetter) (fline_T *)
 

Functions

void copyFoldingState (win_T *wp_from, win_T *wp_to)
 
int hasAnyFolding (win_T *win)
 
bool hasFolding (linenr_T lnum, linenr_T *firstp, linenr_T *lastp)
 
bool hasFoldingWin (win_T *const win, const linenr_T lnum, linenr_T *const firstp, linenr_T *const lastp, const bool cache, foldinfo_T *const infop)
 
int foldLevel (linenr_T lnum)
 
bool lineFolded (win_T *const win, const linenr_T lnum)
 
foldinfo_T fold_info (win_T *win, linenr_T lnum)
 
int foldmethodIsManual (win_T *wp)
 
int foldmethodIsIndent (win_T *wp)
 
int foldmethodIsExpr (win_T *wp)
 
int foldmethodIsMarker (win_T *wp)
 
int foldmethodIsSyntax (win_T *wp)
 
int foldmethodIsDiff (win_T *wp)
 
void closeFold (pos_T pos, long count)
 
void closeFoldRecurse (pos_T pos)
 
void opFoldRange (pos_T firstpos, pos_T lastpos, int opening, int recurse, int had_visual)
 
void openFold (pos_T pos, long count)
 
void openFoldRecurse (pos_T pos)
 
void foldOpenCursor (void)
 
void newFoldLevel (void)
 
void foldCheckClose (void)
 
int foldManualAllowed (bool create)
 
void foldCreate (win_T *wp, pos_T start, pos_T end)
 
void deleteFold (win_T *const wp, const linenr_T start, const linenr_T end, const int recursive, const bool had_visual)
 
void clearFolding (win_T *win)
 
void foldUpdate (win_T *wp, linenr_T top, linenr_T bot)
 
void foldUpdateAfterInsert (void)
 Updates folds when leaving insert-mode. More...
 
void foldUpdateAll (win_T *win)
 
int foldMoveTo (const bool updown, const int dir, const long count)
 
void foldInitWin (win_T *new_win)
 
int find_wl_entry (win_T *win, linenr_T lnum)
 
void foldAdjustVisual (void)
 
void foldAdjustCursor (void)
 
void cloneFoldGrowArray (garray_T *from, garray_T *to)
 
void deleteFoldRecurse (buf_T *bp, garray_T *gap)
 
void foldMarkAdjust (win_T *wp, linenr_T line1, linenr_T line2, long amount, long amount_after)
 
int getDeepestNesting (win_T *wp)
 
char_uget_foldtext (win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldinfo, char_u *buf) FUNC_ATTR_NONNULL_ARG(1)
 
void foldtext_cleanup (char_u *str)
 
void foldMoveRange (win_T *const wp, garray_T *gap, const linenr_T line1, const linenr_T line2, const linenr_T dest)
 
int put_folds (FILE *fd, win_T *wp)
 

Macro Definition Documentation

◆ DELETE_FOLD_NESTED

#define DELETE_FOLD_NESTED (   fd)    deleteFoldRecurse(bp, &((fd)->fd_nested))

◆ DONE_ACTION

#define DONE_ACTION   1

◆ DONE_FOLD

#define DONE_FOLD   2

◆ DONE_NOTHING

#define DONE_NOTHING   0

◆ FD_CLOSED

#define FD_CLOSED   1

◆ FD_LEVEL

#define FD_LEVEL   2

◆ FD_OPEN

#define FD_OPEN   0

◆ FOLD_END

#define FOLD_END (   fp)    ((fp)->fd_top + (fp)->fd_len - 1)

◆ FOLD_INDEX

#define FOLD_INDEX (   fp,
  gap 
)    ((size_t)(fp - ((fold_T *)(gap)->ga_data)))

◆ MAX_LEVEL

#define MAX_LEVEL   20

◆ VALID_FOLD

#define VALID_FOLD (   fp,
  gap 
)    ((gap)->ga_len > 0 && (fp) < ((fold_T *)(gap)->ga_data + (gap)->ga_len))

Typedef Documentation

◆ LevelGetter

typedef void(* LevelGetter) (fline_T *)

Function Documentation

◆ clearFolding()

void clearFolding ( win_T win)

◆ cloneFoldGrowArray()

void cloneFoldGrowArray ( garray_T from,
garray_T to 
)

◆ closeFold()

void closeFold ( pos_T  pos,
long  count 
)

Close fold for current window at line "lnum". Repeat "count" times.

◆ closeFoldRecurse()

void closeFoldRecurse ( pos_T  pos)

◆ copyFoldingState()

void copyFoldingState ( win_T wp_from,
win_T wp_to 
)

◆ deleteFold()

void deleteFold ( win_T *const  wp,
const linenr_T  start,
const linenr_T  end,
const int  recursive,
const bool  had_visual 
)
Parameters
startdelete all folds from start to end when not 0
enddelete all folds from start to end when not 0
recursivedelete recursively if true
had_visualtrue when Visual selection used

◆ deleteFoldRecurse()

void deleteFoldRecurse ( buf_T bp,
garray_T gap 
)

◆ find_wl_entry()

int find_wl_entry ( win_T win,
linenr_T  lnum 
)

◆ fold_info()

foldinfo_T fold_info ( win_T win,
linenr_T  lnum 
)

fold_info() {{{2

Count the number of lines that are folded at line number "lnum". Normally "lnum" is the first line of a possible fold, and the returned number is the number of lines in the fold. Doesn't use caching from the displayed window.

Returns
with the fold level info. fi_lines = number of folded lines from "lnum", or 0 if line is not folded.

◆ foldAdjustCursor()

void foldAdjustCursor ( void  )

◆ foldAdjustVisual()

void foldAdjustVisual ( void  )

◆ foldCheckClose()

void foldCheckClose ( void  )

◆ foldCreate()

void foldCreate ( win_T wp,
pos_T  start,
pos_T  end 
)

Create a fold from line "start" to line "end" (inclusive) in the current window.

◆ foldInitWin()

void foldInitWin ( win_T new_win)

◆ foldLevel()

int foldLevel ( linenr_T  lnum)

◆ foldManualAllowed()

int foldManualAllowed ( bool  create)

Return TRUE if it's allowed to manually create or delete a fold. Give an error message and return FALSE if not.

◆ foldMarkAdjust()

void foldMarkAdjust ( win_T wp,
linenr_T  line1,
linenr_T  line2,
long  amount,
long  amount_after 
)

◆ foldmethodIsDiff()

int foldmethodIsDiff ( win_T wp)

◆ foldmethodIsExpr()

int foldmethodIsExpr ( win_T wp)

◆ foldmethodIsIndent()

int foldmethodIsIndent ( win_T wp)

◆ foldmethodIsManual()

int foldmethodIsManual ( win_T wp)

◆ foldmethodIsMarker()

int foldmethodIsMarker ( win_T wp)

◆ foldmethodIsSyntax()

int foldmethodIsSyntax ( win_T wp)

◆ foldMoveRange()

void foldMoveRange ( win_T *const  wp,
garray_T gap,
const linenr_T  line1,
const linenr_T  line2,
const linenr_T  dest 
)

◆ foldMoveTo()

int foldMoveTo ( const bool  updown,
const int  dir,
const long  count 
)

If "updown" is false: Move to the start or end of the fold. If "updown" is true: move to fold at the same level.

Returns
FAIL if not moved.
Parameters
dirFORWARD or BACKWARD

◆ foldOpenCursor()

void foldOpenCursor ( void  )

◆ foldtext_cleanup()

void foldtext_cleanup ( char_u str)

◆ foldUpdate()

void foldUpdate ( win_T wp,
linenr_T  top,
linenr_T  bot 
)

◆ foldUpdateAfterInsert()

void foldUpdateAfterInsert ( void  )

Updates folds when leaving insert-mode.

◆ foldUpdateAll()

void foldUpdateAll ( win_T win)

◆ get_foldtext()

char_u* get_foldtext ( win_T wp,
linenr_T  lnum,
linenr_T  lnume,
foldinfo_T  foldinfo,
char_u buf 
)

Generates text to display

Parameters
bufallocated memory of length FOLD_TEXT_LEN. Used when 'foldtext' isn't set puts the result in "buf[FOLD_TEXT_LEN]".
atline "lnum", with last line "lnume".
Returns
the text for a closed fold

Otherwise the result is in allocated memory.

◆ getDeepestNesting()

int getDeepestNesting ( win_T wp)

◆ hasAnyFolding()

int hasAnyFolding ( win_T win)

◆ hasFolding()

bool hasFolding ( linenr_T  lnum,
linenr_T firstp,
linenr_T lastp 
)

When returning true, *firstp and *lastp are set to the first and last lnum of the sequence of folded lines (skipped when NULL).

Returns
true if line "lnum" in the current window is part of a closed fold.

◆ hasFoldingWin()

bool hasFoldingWin ( win_T *const  win,
const linenr_T  lnum,
linenr_T *const  firstp,
linenr_T *const  lastp,
const bool  cache,
foldinfo_T *const  infop 
)

Search folds starting at lnum

Parameters
lnumfirst line to search
[out]firstfirst line of fold containing lnum
[out]lastplast line with a fold
cachewhen true: use cached values of window
[out]infopwhere to store fold info
Returns
true if range contains folds

◆ lineFolded()

bool lineFolded ( win_T *const  win,
const linenr_T  lnum 
)

◆ newFoldLevel()

void newFoldLevel ( void  )

◆ openFold()

void openFold ( pos_T  pos,
long  count 
)

◆ openFoldRecurse()

void openFoldRecurse ( pos_T  pos)

◆ opFoldRange()

void opFoldRange ( pos_T  firstpos,
pos_T  lastpos,
int  opening,
int  recurse,
int  had_visual 
)

Open or Close folds for current window in lines "first" to "last". Used for "zo", "zO", "zc" and "zC" in Visual mode.

Parameters
openingTRUE to open, FALSE to close
recurseTRUE to do it recursively
had_visualTRUE when Visual selection used

◆ put_folds()

int put_folds ( FILE *  fd,
win_T wp 
)