Macros | Enumerations | Functions
buffer.c File Reference
#include <stdbool.h>
#include <string.h>
#include <inttypes.h>
#include <assert.h>
#include "nvim/api/private/handle.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/vim.h"
#include "nvim/ascii.h"
#include "nvim/channel.h"
#include "nvim/vim.h"
#include "nvim/buffer.h"
#include "nvim/change.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/digraph.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_eval.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
#include "nvim/file_search.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
#include "nvim/hashtab.h"
#include "nvim/highlight.h"
#include "nvim/indent.h"
#include "nvim/indent_c.h"
#include "nvim/main.h"
#include "nvim/mark.h"
#include "nvim/extmark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/garray.h"
#include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/quickfix.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/sign.h"
#include "nvim/spell.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/ui.h"
#include "nvim/undo.h"
#include "nvim/version.h"
#include "nvim/window.h"
#include "nvim/shada.h"
#include "nvim/os/os.h"
#include "nvim/os/time.h"
#include "nvim/os/input.h"
#include "nvim/buffer_updates.h"


#define SPACE_FOR_FNAME   (sizeof(buf) - 100)
#define SPACE_FOR_DIR   (sizeof(buf) - 20)
#define SPACE_FOR_ARGNR   (sizeof(buf) - 10)
#define TMPLEN   70


enum  BufFreeFlags { kBffClearWinInfo = 1, kBffInitChangedtick = 2 }
enum  NumberBase { kNumBaseDecimal = 10, kNumBaseHexadecimal = 16 }


int open_buffer (int read_stdin, exarg_T *eap, int flags)
void set_bufref (bufref_T *bufref, buf_T *buf)
bool bufref_valid (bufref_T *bufref)
void close_buffer (win_T *win, buf_T *buf, int action, bool abort_if_last)
void buf_clear_file (buf_T *buf)
 Make buffer not contain a file. More...
void buf_clear (void)
 Clears the current buffer contents. More...
void buf_freeall (buf_T *buf, int flags)
void goto_buffer (exarg_T *eap, int start, int dir, int count)
void handle_swap_exists (bufref_T *old_curbuf)
char_udo_bufdel (int command, char_u *arg, int addr_count, int start_bnr, int end_bnr, int forceit)
int do_buffer (int action, int start, int dir, int count, int forceit)
void set_curbuf (buf_T *buf, int action)
void enter_buffer (buf_T *buf)
void do_autochdir (void)
void no_write_message (void)
void no_write_message_nobang (void)
buf_Tbuflist_new (char_u *ffname, char_u *sfname, linenr_T lnum, int flags)
bool curbuf_reusable (void)
void free_buf_options (buf_T *buf, int free_p_ff)
int buflist_getfile (int n, linenr_T lnum, int options, int forceit)
void buflist_getfpos (void)
buf_Tbuflist_findname_exp (char_u *fname)
buf_Tbuflist_findname (char_u *ffname)
int buflist_findpat (const char_u *pattern, const char_u *pattern_end, int unlisted, int diffmode, int curtab_only)
int ExpandBufnames (char_u *pat, int *num_file, char_u ***file, int options)
buf_Tbuflist_findnr (int nr)
 Find a file in the buffer list by buffer number. More...
char_ubuflist_nr2name (int n, int fullname, int helptail)
void buflist_setfpos (buf_T *const buf, win_T *const win, linenr_T lnum, colnr_T col, bool copy_options) FUNC_ATTR_NONNULL_ALL
void get_winopts (buf_T *buf)
pos_Tbuflist_findfpos (buf_T *buf)
linenr_T buflist_findlnum (buf_T *buf)
void buflist_list (exarg_T *eap)
int buflist_name_nr (int fnum, char_u **fname, linenr_T *lnum)
int setfname (buf_T *buf, char_u *ffname, char_u *sfname, bool message)
void buf_set_name (int fnum, char_u *name)
void buf_name_changed (buf_T *buf)
buf_Tsetaltfname (char_u *ffname, char_u *sfname, linenr_T lnum)
char_ugetaltfname (bool errmsg)
int buflist_add (char_u *fname, int flags)
void buflist_altfpos (win_T *win)
void buf_set_file_id (buf_T *buf)
void fileinfo (int fullname, int shorthelp, int dont_truncate)
void col_print (char_u *buf, size_t buflen, int col, int vcol)
void maketitle (void)
void resettitle (void)
 Set current window title. More...
int build_stl_str_hl (win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use_sandbox, char_u fillchar, int maxwidth, struct stl_hlrec *hltab, StlClickRecord *tabtab)
void get_rel_pos (win_T *wp, char_u *buf, int buflen)
void fname_expand (buf_T *buf, char_u **ffname, char_u **sfname)
char_ualist_name (aentry_T *aep)
void do_arg_all (int count, int forceit, int keep_tabs)
int bt_prompt (buf_T *buf)
void ex_buffer_all (exarg_T *eap)
void do_modelines (int flags)
bool bt_help (const buf_T *const buf) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
bool bt_normal (const buf_T *const buf) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
bool bt_quickfix (const buf_T *const buf) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
bool bt_terminal (const buf_T *const buf) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
bool bt_nofile (const buf_T *const buf) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
bool bt_dontwrite (const buf_T *const buf) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
bool bt_dontwrite_msg (const buf_T *const buf) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
bool buf_hide (const buf_T *const buf)
char_ubuf_spname (buf_T *buf)
bool find_win_for_buf (buf_T *buf, win_T **wp, tabpage_T **tp)
int buf_signcols (buf_T *buf)
void set_buflisted (int on)
bool buf_contents_changed (buf_T *buf) FUNC_ATTR_NONNULL_ALL
void wipe_buffer (buf_T *buf, int aucmd)
void buf_open_scratch (handle_T bufnr, char *bufname)

Macro Definition Documentation

#define SPACE_FOR_ARGNR   (sizeof(buf) - 10)
#define SPACE_FOR_DIR   (sizeof(buf) - 20)
#define SPACE_FOR_FNAME   (sizeof(buf) - 100)
#define TMPLEN   70

Enumeration Type Documentation

enum NumberBase

Enumeration specifying the valid numeric bases that can be used when printing numbers in the status line.


Function Documentation

char_u* alist_name ( aentry_T aep)
bool bt_dontwrite ( const buf_T *const  buf)
bool bt_dontwrite_msg ( const buf_T *const  buf)
bool bt_help ( const buf_T *const  buf)
bool bt_nofile ( const buf_T *const  buf)
bool bt_normal ( const buf_T *const  buf)
int bt_prompt ( buf_T buf)
bool bt_quickfix ( const buf_T *const  buf)
bool bt_terminal ( const buf_T *const  buf)
void buf_clear ( void  )

Clears the current buffer contents.

void buf_clear_file ( buf_T buf)

Make buffer not contain a file.

bool buf_contents_changed ( buf_T buf)

Read the file for "buf" again and check if the contents changed. Return true if it changed or this could not be checked.

bufbuffer to check
true if the buffer's contents have changed
void buf_freeall ( buf_T buf,
int  flags 

buf_freeall() - free all things allocated for a buffer that are related to the file. Careful: get here with "curwin" NULL when exiting.

flagsBFA_DEL buffer is going to be deleted BFA_WIPE buffer is going to be wiped out BFA_KEEP_UNDO do not free undo information
bool buf_hide ( const buf_T *const  buf)
void buf_name_changed ( buf_T buf)
void buf_open_scratch ( handle_T  bufnr,
char *  bufname 

Creates or switches to a scratch buffer. :h special-buffers Scratch buffer is:

  • buftype=nofile bufhidden=hide noswapfile
  • Always considered 'nomodified'
bufnrBuffer to switch to, or 0 to create a new buffer.
See also
void buf_set_file_id ( buf_T buf)
void buf_set_name ( int  fnum,
char_u name 
int buf_signcols ( buf_T buf)
char_u* buf_spname ( buf_T buf)
bool buf_valid ( buf_T buf)

Check that "buf" points to a valid buffer in the buffer list.

Can be slow if there are many buffers, prefer using bufref_valid().

bufThe buffer to check for.
int buflist_add ( char_u fname,
int  flags 
void buflist_altfpos ( win_T win)
pos_T* buflist_findfpos ( buf_T buf)
linenr_T buflist_findlnum ( buf_T buf)
buf_T* buflist_findname ( char_u ffname)
buf_T* buflist_findname_exp ( char_u fname)
buf_T* buflist_findnr ( int  nr)

Find a file in the buffer list by buffer number.

int buflist_findpat ( const char_u pattern,
const char_u pattern_end,
int  unlisted,
int  diffmode,
int  curtab_only 

Find file in buffer list by a regexp pattern. Return fnum of the found buffer. Return < 0 for error.

int buflist_getfile ( int  n,
linenr_T  lnum,
int  options,
int  forceit 

Get alternate file "n". Set linenr to "lnum" or altfpos.lnum if "lnum" == 0. Also set cursor column to altfpos.col if 'startofline' is not set. if (options & GETF_SETMARK) call setpcmark() if (options & GETF_ALT) we are jumping to an alternate file. if (options & GETF_SWITCH) respect 'switchbuf' settings when jumping

Return FAIL for failure, OK for success.

void buflist_getfpos ( void  )
void buflist_list ( exarg_T eap)
int buflist_name_nr ( int  fnum,
char_u **  fname,
linenr_T lnum 
buf_T* buflist_new ( char_u ffname,
char_u sfname,
linenr_T  lnum,
int  flags 

Add a file name to the buffer list. If the same file name already exists return a pointer to that buffer. If it does not exist, or if fname == NULL, a new entry is created. If (flags & BLN_CURBUF) is true, may use current buffer. If (flags & BLN_LISTED) is true, add new buffer to buffer list. If (flags & BLN_DUMMY) is true, don't count it as a real buffer. If (flags & BLN_NEW) is true, don't use an existing buffer. If (flags & BLN_NOOPT) is true, don't copy options from the current buffer if the buffer already exists. This is the ONLY way to create a new buffer.

ffnamefull path of fname or relative
sfnameshort fname or NULL
lnumpreferred cursor line
flagsBLN_ defines
pointer to the buffer
char_u* buflist_nr2name ( int  n,
int  fullname,
int  helptail 
void buflist_setfpos ( buf_T *const  buf,
win_T *const  win,
linenr_T  lnum,
colnr_T  col,
bool  copy_options 

Set the line and column numbers for the given buffer and window

[in,out]bufBuffer for which line and column are set.
[in,out]winWindow for which line and column are set.
[in]lnumLine number to be set. If it is zero then only options are touched.
[in]colColumn number to be set.
[in]copy_optionsIf true save the local window option values.
bool bufref_valid ( bufref_T bufref)

Return true if "bufref->br_buf" points to the same buffer as when set_bufref() was called and it is a valid buffer. Only goes through the buffer list if buf_free_count changed. Also checks if b_fnum is still the same, a :bwipe followed by :new might get the same allocated memory, but it's a different buffer.

bufrefBuffer reference to check for.
int build_stl_str_hl ( win_T wp,
char_u out,
size_t  outlen,
char_u fmt,
int  use_sandbox,
char_u  fillchar,
int  maxwidth,
struct stl_hlrec hltab,
StlClickRecord tabtab 

Build a string from the status line items in "fmt". Return length of string in screen cells.

Normally works for window "wp", except when working for 'tabline' then it is "curwin".

Items are drawn interspersed with the text that surrounds it Specials: %-<wid>(xxx%) => group, %= => separation marker, %< => truncation Item: %-<minwid>.<maxwid><itemch> All but <itemch> are optional

If maxwidth is not zero, the string will be filled at any middle marker or truncated if too long, fillchar is used for all whitespace.

wpThe window to build a statusline for
outThe output buffer to write the statusline to Note: This should not be NameBuff
outlenThe length of the output buffer
fmtThe statusline format string
use_sandboxUse a sandboxed environment when evaluating fmt
fillcharCharacter to use when filling empty space in the statusline
maxwidthThe maximum width to make the statusline
hltabHL attributes (can be NULL)
tabtabTab clicks definition (can be NULL).
The final width of the statusline
void close_buffer ( win_T win,
buf_T buf,
int  action,
bool  abort_if_last 

Close the link to a buffer.

winIf not NULL, set b_last_cursor.
actionUsed when there is no longer a window for the buffer. Possible values: 0 buffer becomes hidden DOBUF_UNLOAD buffer is unloaded DOBUF_DELETE buffer is unloaded and removed from buffer list DOBUF_WIPE buffer is unloaded and really deleted When doing all but the first one on the current buffer, the caller should get a new buffer very soon! The 'bufhidden' option can force freeing and deleting.
abort_if_lastIf true, do not close the buffer if autocommands cause there to be only one window with this buffer. e.g. when ":quit" is supposed to close the window but autocommands close all other windows.
void col_print ( char_u buf,
size_t  buflen,
int  col,
int  vcol 
bool curbuf_reusable ( void  )

Return true if the current buffer is empty, unnamed, unmodified and used in only one window. That means it can be reused.

void do_arg_all ( int  count,
int  forceit,
int  keep_tabs 
void do_autochdir ( void  )
char_u* do_bufdel ( int  command,
char_u arg,
int  addr_count,
int  start_bnr,
int  end_bnr,
int  forceit 
int do_buffer ( int  action,
int  start,
int  dir,
int  count,
int  forceit 
void do_modelines ( int  flags)
void enter_buffer ( buf_T buf)
void ex_buffer_all ( exarg_T eap)
int ExpandBufnames ( char_u pat,
int *  num_file,
char_u ***  file,
int  options 
void fileinfo ( int  fullname,
int  shorthelp,
int  dont_truncate 
bool find_win_for_buf ( buf_T buf,
win_T **  wp,
tabpage_T **  tp 

Find a window for buffer "buf". If found true is returned and "wp" and "tp" are set to the window and tabpage. If not found, false is returned.

bufbuffer to find a window for
[out]wpstores the found window
[out]tpstores the found tabpage
true if a window was found for the buffer.
void fname_expand ( buf_T buf,
char_u **  ffname,
char_u **  sfname 
void free_buf_options ( buf_T buf,
int  free_p_ff 
void get_rel_pos ( win_T wp,
char_u buf,
int  buflen 
void get_winopts ( buf_T buf)
char_u* getaltfname ( bool  errmsg)
void goto_buffer ( exarg_T eap,
int  start,
int  dir,
int  count 
void handle_swap_exists ( bufref_T old_curbuf)

Handle the situation of swap_exists_action being set.

It is allowed for "old_curbuf" to be NULL or invalid.

old_curbufThe buffer to check for.
void maketitle ( void  )
void no_write_message ( void  )
void no_write_message_nobang ( void  )
int open_buffer ( int  read_stdin,
exarg_T eap,
int  flags 
bool otherfile ( char_u ffname)

Check that "ffname" is not the same file as current file. Fname must have a full path (expanded by path_to_absolute()).

ffnamefull path name to check
void resettitle ( void  )

Set current window title.

void set_buflisted ( int  on)
void set_bufref ( bufref_T bufref,
buf_T buf 

Store "buf" in "bufref" and set the free count.

bufrefReference to be used for the buffer.
bufThe buffer to reference.
void set_curbuf ( buf_T buf,
int  action 
buf_T* setaltfname ( char_u ffname,
char_u sfname,
linenr_T  lnum 
int setfname ( buf_T buf,
char_u ffname,
char_u sfname,
bool  message 
void wipe_buffer ( buf_T buf,
int  aucmd