#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/buffer_updates.h"
#include "nvim/change.h"
#include "nvim/channel.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/decoration.h"
#include "nvim/diff.h"
#include "nvim/digraph.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_eval.h"
#include "nvim/ex_getln.h"
#include "nvim/extmark.h"
#include "nvim/file_search.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/hashtab.h"
#include "nvim/highlight_group.h"
#include "nvim/indent.h"
#include "nvim/indent_c.h"
#include "nvim/main.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os/time.h"
#include "nvim/path.h"
#include "nvim/plines.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/vim.h"
#include "nvim/window.h"
Data Structures | |
struct | bufmatch_T |
Macros | |
#define | MAX_STL_EVAL_DEPTH 100 |
#define | SPACE_FOR_FNAME (sizeof(buf) - 100) |
#define | SPACE_FOR_DIR (sizeof(buf) - 20) |
#define | SPACE_FOR_ARGNR (sizeof(buf) - 10) |
#define | TMPLEN 70 |
Enumerations | |
enum | BufFreeFlags { kBffClearWinInfo = 1, kBffInitChangedtick = 2 } |
enum | NumberBase { kNumBaseDecimal = 10, kNumBaseHexadecimal = 16 } |
#define MAX_STL_EVAL_DEPTH 100 |
#define SPACE_FOR_ARGNR (sizeof(buf) - 10) |
#define SPACE_FOR_DIR (sizeof(buf) - 20) |
#define SPACE_FOR_FNAME (sizeof(buf) - 100) |
#define TMPLEN 70 |
enum BufFreeFlags |
enum NumberBase |
Read the file for "buf" again and check if the contents changed. Return true if it changed or this could not be checked.
buf | buffer to check |
buf_freeall() - free all things allocated for a buffer that are related to the file. Careful: get here with "curwin" NULL when exiting.
flags | BFA_DEL buffer is going to be deleted BFA_WIPE buffer is going to be wiped out BFA_KEEP_UNDO do not free undo information BFA_IGNORE_ABORT don't abort even when aborting() returns true |
Take care of what needs to be done when the name of buffer "buf" has changed.
Creates or switches to a scratch buffer. :h special-buffers Scratch buffer is:
bufnr | Buffer to switch to, or 0 to create a new buffer. |
Set file_id for a buffer. Must always be called when b_fname is changed!
Crude way of changing the name of a buffer. Use with care! The name should be relative to the current directory.
int buf_signcols | ( | buf_T * | buf, |
int | maximum | ||
) |
void buf_signcols_add_check | ( | buf_T * | buf, |
sign_entry_T * | added | ||
) |
Re-calculate the signcolumn after adding a sign.
buf | buffer to check |
added | sign being added |
Invalidate the signcolumn if needed after deleting signs between line1 and line2 (inclusive).
buf | buffer to check |
line1 | start of region being deleted |
line2 | end of region being deleted |
Check that "buf" points to a valid buffer in the buffer list.
Can be slow if there are many buffers, prefer using bufref_valid().
buf | The buffer to check for. |
int buflist_add | ( | char_u * | fname, |
int | flags | ||
) |
Add a file name to the buflist and return its number. Uses same flags as buflist_new(), except BLN_DUMMY.
Set alternate cursor position for the current buffer and window "win". Also save the local window option values.
Find the position (lnum and col) for the buffer 'buf' for the current window.
Find file in buffer list by name (it has to be for the current window). "ffname" must have a full path. Skips dummy buffers.
Find file in buffer list by name (it has to be for the current window).
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, | ||
bool | unlisted, | ||
bool | diffmode, | ||
bool | curtab_only | ||
) |
Find file in buffer list by a regexp pattern.
pattern_end | pointer to first char after pattern |
unlisted | find unlisted buffers |
diffmode | find diff-mode buffers only |
curtab_only | find buffers in current tab only |
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.
Get file name and line number for file 'fnum'. Used by DoOneCmd() for translating '' and '#'. Used by insert_reg() and cmdline_paste() for '#' register.
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.
ffname_arg | full path of fname or relative |
sfname_arg | short fname or NULL |
lnum | preferred cursor line |
flags | BLN_ defines |
bufnr |
char_u* buflist_nr2name | ( | int | n, |
int | fullname, | ||
int | helptail | ||
) |
Get name of file 'n' in the buffer list. When the file has no name an empty string is returned. home_replace() is used to shorten the file name (used for marks).
helptail | for help buffers return tail only |
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] | buf | Buffer for which line and column are set. |
[in,out] | win | Window for which line and column are set. May be NULL when using :badd. |
[in] | lnum | Line number to be set. If it is zero then only options are touched. |
[in] | col | Column number to be set. |
[in] | copy_options | If true save the local window option values. |
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.
bufref | Buffer reference to check for. |
int build_stl_str_hl | ( | win_T * | wp, |
char * | out, | ||
size_t | outlen, | ||
char * | fmt, | ||
int | use_sandbox, | ||
int | fillchar, | ||
int | maxwidth, | ||
stl_hlrec_t ** | 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.
wp | The window to build a statusline for |
out | The output buffer to write the statusline to Note: This should not be NameBuff |
outlen | The length of the output buffer |
fmt | The statusline format string |
use_sandbox | Use a sandboxed environment when evaluating fmt |
fillchar | Character to use when filling empty space in the statusline |
maxwidth | The maximum width to make the statusline |
hltab | HL attributes (can be NULL) |
tabtab | Tab clicks definition (can be NULL). |
Close the link to a buffer.
win | If not NULL, set b_last_cursor. |
buf | |
action | Used 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_last | If 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. |
ignore_abort | If true, don't abort even when aborting() returns true. |
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 | ||
) |
do_arg_all(): Open up to 'count' windows, one for each argument.
forceit | hide buffers in current windows |
keep_tabs | keep current tabs, for ":tab drop file" |
Change to the directory of the current buffer. Don't do this while still starting up.
char* do_bufdel | ( | int | command, |
char_u * | arg, | ||
int | addr_count, | ||
int | start_bnr, | ||
int | end_bnr, | ||
int | forceit | ||
) |
do_bufdel() - delete or unload buffer(s)
addr_count == 0: ":bdel" - delete current buffer addr_count == 1: ":N bdel" or ":bdel N [N ..]" - first delete buffer "end_bnr", then any other arguments. addr_count == 2: ":N,N bdel" - delete buffers in range
command can be DOBUF_UNLOAD (":bunload"), DOBUF_WIPE (":bwipeout") or DOBUF_DEL (":bdel")
arg | pointer to extra arguments |
start_bnr | first buffer number in a range |
end_bnr | buffer nr or last buffer nr in a range |
int do_buffer | ( | int | action, |
int | start, | ||
int | dir, | ||
int | count, | ||
int | forceit | ||
) |
Implementation of the commands for the buffer list.
action == DOBUF_GOTO go to specified buffer action == DOBUF_SPLIT split window and go to specified buffer action == DOBUF_UNLOAD unload specified buffer(s) action == DOBUF_DEL delete specified buffer(s) from buffer list action == DOBUF_WIPE delete specified buffer(s) really
start == DOBUF_CURRENT go to "count" buffer from current buffer start == DOBUF_FIRST go to "count" buffer from first buffer start == DOBUF_LAST go to "count" buffer from last buffer start == DOBUF_MOD go to "count" modified buffer from current buffer
dir | FORWARD or BACKWARD |
count | buffer number or number of buffers |
forceit | true for :...! |
void do_modelines | ( | int | flags | ) |
do_modelines() - process mode lines for the current file
flags | OPT_WINONLY only set options local to window OPT_NOWIN don't set options local to window |
Returns immediately if the "ml" option isn't set.
Enter a new current buffer. Old curbuf must have been abandoned already! This also means "curbuf" may be pointing to freed memory.
Find all buffer names that match. For command line expansion of ":buf" and ":sbuf".
void fileinfo | ( | int | fullname, |
int | shorthelp, | ||
int | dont_truncate | ||
) |
Print info about the current buffer.
fullname | when non-zero print full path |
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.
buf | buffer to find a window for | |
[out] | wp | stores the found window |
[out] | tp | stores the found tabpage |
Make "*ffname" a full file name, set "*sfname" to "*ffname" if not NULL. "*ffname" becomes a pointer to allocated memory (or NULL). When resolving a link both "*sfname" and "*ffname" will point to the same allocated memory. The "*ffname" and "*sfname" pointer values on call will not be freed. Note that the resulting "*ffname" pointer should be considered not allocated.
Free the memory for the options of a buffer. If "free_p_ff" is true also free 'fileformat', 'buftype' and 'fileencoding'.
Get relative cursor position in window into "buf[buflen]", in the form 99%, using "Top", "Bot" or "All" when appropriate.
Reset the local window options to the values last used in this window. If the buffer wasn't used in this window before, use the values from the most recently used window. If the values were never set, use the global values for the window.
Get alternate file name for current window. Return NULL if there isn't any, and give error message if requested.
errmsg | give error message |
Go to another buffer. Handles the result of the ATTENTION dialog.
Handle the situation of swap_exists_action being set.
It is allowed for "old_curbuf" to be NULL or invalid.
old_curbuf | The buffer to check for. |
int open_buffer | ( | int | read_stdin, |
exarg_T * | eap, | ||
int | flags | ||
) |
Open current buffer, that is: open the memfile and read the file into memory.
read_stdin | read file from stdin |
eap | for forced 'ff' and 'fenc' or NULL |
flags | extra flags for readfile() |
Check that "ffname" is not the same file as current file. Fname must have a full path (expanded by path_to_absolute()).
ffname | full path name to check |
void set_buflisted | ( | int | on | ) |
Set 'buflisted' for curbuf to "on" and trigger autocommands if it changed.
Store "buf" in "bufref" and set the free count.
bufref | Reference to be used for the buffer. |
buf | The buffer to reference. |
Set current buffer to "buf". Executes autocommands and closes current buffer.
action | tells how to close the current buffer: DOBUF_GOTO free or hide it DOBUF_SPLIT nothing DOBUF_UNLOAD unload it DOBUF_DEL delete it DOBUF_WIPE wipe it out |
Set alternate file name for current window
Used by do_one_cmd(), do_write() and do_ecmd().
Set the file name for "buf" to "ffname_arg", short file name to "sfname_arg". The file name with the full path is also remembered, for when :cd is used.
message | give message when buffer already exists |