Data Structures | Macros | Typedefs | Functions | Variables
edit.c File Reference
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/change.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/digraph.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/eval/typval.h"
#include "nvim/event/loop.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/extmark.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
#include "nvim/indent.h"
#include "nvim/indent_c.h"
#include "nvim/keymap.h"
#include "nvim/main.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/mouse.h"
#include "nvim/move.h"
#include "nvim/normal.h"
#include "nvim/ops.h"
#include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/time.h"
#include "nvim/path.h"
#include "nvim/plines.h"
#include "nvim/popupmnu.h"
#include "nvim/quickfix.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/search.h"
#include "nvim/spell.h"
#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/tag.h"
#include "nvim/terminal.h"
#include "nvim/ui.h"
#include "nvim/undo.h"
#include "nvim/vim.h"
#include "nvim/window.h"

Data Structures

struct  compl_S
 
struct  insert_state
 

Macros

#define CTRL_X_WANT_IDENT   0x100
 
#define CTRL_X_NORMAL   0
 CTRL-N CTRL-P completion, default. More...
 
#define CTRL_X_NOT_DEFINED_YET   1
 
#define CTRL_X_SCROLL   2
 
#define CTRL_X_WHOLE_LINE   3
 
#define CTRL_X_FILES   4
 
#define CTRL_X_TAGS   (5 + CTRL_X_WANT_IDENT)
 
#define CTRL_X_PATH_PATTERNS   (6 + CTRL_X_WANT_IDENT)
 
#define CTRL_X_PATH_DEFINES   (7 + CTRL_X_WANT_IDENT)
 
#define CTRL_X_FINISHED   8
 
#define CTRL_X_DICTIONARY   (9 + CTRL_X_WANT_IDENT)
 
#define CTRL_X_THESAURUS   (10 + CTRL_X_WANT_IDENT)
 
#define CTRL_X_CMDLINE   11
 
#define CTRL_X_FUNCTION   12
 
#define CTRL_X_OMNI   13
 
#define CTRL_X_SPELL   14
 
#define CTRL_X_LOCAL_MSG   15
 only used in "ctrl_x_msgs" More...
 
#define CTRL_X_EVAL   16
 for builtin function complete() More...
 
#define CTRL_X_CMDLINE_CTRL_X   17
 CTRL-X typed in CTRL_X_CMDLINE. More...
 
#define CTRL_X_MSG(i)   ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]
 
#define CTRL_X_MODE_LINE_OR_EVAL(m)   ((m) == CTRL_X_WHOLE_LINE || (m) == CTRL_X_EVAL)
 
#define BACKSPACE_CHAR   1
 
#define BACKSPACE_WORD   2
 
#define BACKSPACE_WORD_NOT_SPACE   3
 
#define BACKSPACE_LINE   4
 
#define PC_STATUS_UNSET   0
 
#define PC_STATUS_RIGHT   1
 
#define PC_STATUS_LEFT   2
 
#define PC_STATUS_SET   3
 
#define FREE_CPTEXT(cptext, cptext_allocated)
 
#define DICT_FIRST   (1)
 
#define DICT_EXACT   (2)
 
#define CI_WHAT_MODE   0x01
 
#define CI_WHAT_PUM_VISIBLE   0x02
 
#define CI_WHAT_ITEMS   0x04
 
#define CI_WHAT_SELECTED   0x08
 
#define CI_WHAT_INSERTED   0x10
 
#define CI_WHAT_ALL   0xff
 
#define MIN_SPACE   75
 
#define ISSPECIAL(c)   ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^')
 
#define WHITECHAR(cc)
 
#define INPUT_BUFLEN   100
 

Typedefs

typedef struct compl_S compl_T
 
typedef struct insert_state InsertState
 

Functions

bool edit (int cmdchar, bool startln, long count)
 
void edit_putchar (int c, bool highlight)
 
char_ubuf_prompt_text (const buf_T *const buf) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
 Return the effective prompt for the specified buffer. More...
 
char_uprompt_text (void)
 
bool prompt_curpos_editable (void)
 
void edit_unputchar (void)
 
void display_dollar (colnr_T col)
 
void change_indent (int type, int amount, int round, int replaced, int call_changed_bytes)
 
void truncate_spaces (char_u *line)
 
void backspace_until_column (int col)
 
bool ctrl_x_mode_not_default (void)
 
bool ctrl_x_mode_not_defined_yet (void)
 
bool vim_is_ctrl_x_key (int c) FUNC_ATTR_WARN_UNUSED_RESULT
 
int ins_compl_add_infercase (char_u *str_arg, int len, bool icase, char_u *fname, Direction dir, bool cont_s_ipos) FUNC_ATTR_NONNULL_ARG(1)
 
void completeopt_was_set (void)
 
void set_completion (colnr_T startcol, list_T *list)
 
void ins_compl_show_pum (void)
 
 for (i=0;i< count &&!got_int &&!compl_interrupted;i++)
 
char_ufind_word_start (char_u *ptr)
 
char_ufind_word_end (char_u *ptr)
 
bool ins_compl_active (void)
 Check that Insert completion is active. More...
 
void get_complete_info (list_T *what_list, dict_T *retdict)
 
int ins_compl_add_tv (typval_T *const tv, const Direction dir, bool fast) FUNC_ATTR_NONNULL_ALL
 
void pum_ext_select_item (int item, bool insert, bool finish)
 
void ins_compl_check_keys (int frequency, int in_compl_func)
 
int get_literal (void)
 
void insertchar (int c, int flags, int second_indent)
 
void auto_format (bool trailblank, bool prev_line)
 
int comp_textwidth (bool ff)
 
int stop_arrow (void)
 
void set_last_insert (int c)
 
char_uadd_char2buf (int c, char_u *s) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
 
void beginline (int flags)
 
int oneright (void)
 
int oneleft (void)
 
int cursor_up (long n, int upd_topline)
 @oaram upd_topline When TRUE: update topline More...
 
int cursor_down (long n, int upd_topline)
 
int stuff_inserted (int c, long count, int no_esc)
 
char_uget_last_insert (void)
 
char_uget_last_insert_save (void)
 
void replace_push (int c)
 
int replace_push_mb (char_u *p)
 
void fixthisline (IndentGetter get_the_indent)
 
void fix_indent (void)
 
bool in_cinkeys (int keytyped, int when, bool line_is_empty)
 
int hkmap (int c)
 
int ins_copychar (linenr_T lnum)
 
colnr_T get_nolist_virtcol (void)
 

Variables

struct {
   bool   active
 
   int   item
 
   bool   insert
 
   bool   finish
 
pum_want
 state for pum_ext_select_item. More...
 
static void int i
 
FILE * fp
 
int add_r
 

Macro Definition Documentation

◆ BACKSPACE_CHAR

#define BACKSPACE_CHAR   1

◆ BACKSPACE_LINE

#define BACKSPACE_LINE   4

◆ BACKSPACE_WORD

#define BACKSPACE_WORD   2

◆ BACKSPACE_WORD_NOT_SPACE

#define BACKSPACE_WORD_NOT_SPACE   3

◆ CI_WHAT_ALL

#define CI_WHAT_ALL   0xff

◆ CI_WHAT_INSERTED

#define CI_WHAT_INSERTED   0x10

◆ CI_WHAT_ITEMS

#define CI_WHAT_ITEMS   0x04

◆ CI_WHAT_MODE

#define CI_WHAT_MODE   0x01

◆ CI_WHAT_PUM_VISIBLE

#define CI_WHAT_PUM_VISIBLE   0x02

◆ CI_WHAT_SELECTED

#define CI_WHAT_SELECTED   0x08

◆ CTRL_X_CMDLINE

#define CTRL_X_CMDLINE   11

◆ CTRL_X_CMDLINE_CTRL_X

#define CTRL_X_CMDLINE_CTRL_X   17

CTRL-X typed in CTRL_X_CMDLINE.

◆ CTRL_X_DICTIONARY

#define CTRL_X_DICTIONARY   (9 + CTRL_X_WANT_IDENT)

◆ CTRL_X_EVAL

#define CTRL_X_EVAL   16

for builtin function complete()

◆ CTRL_X_FILES

#define CTRL_X_FILES   4

◆ CTRL_X_FINISHED

#define CTRL_X_FINISHED   8

◆ CTRL_X_FUNCTION

#define CTRL_X_FUNCTION   12

◆ CTRL_X_LOCAL_MSG

#define CTRL_X_LOCAL_MSG   15

only used in "ctrl_x_msgs"

◆ CTRL_X_MODE_LINE_OR_EVAL

#define CTRL_X_MODE_LINE_OR_EVAL (   m)    ((m) == CTRL_X_WHOLE_LINE || (m) == CTRL_X_EVAL)

◆ CTRL_X_MSG

#define CTRL_X_MSG (   i)    ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]

◆ CTRL_X_NORMAL

#define CTRL_X_NORMAL   0

CTRL-N CTRL-P completion, default.

◆ CTRL_X_NOT_DEFINED_YET

#define CTRL_X_NOT_DEFINED_YET   1

◆ CTRL_X_OMNI

#define CTRL_X_OMNI   13

◆ CTRL_X_PATH_DEFINES

#define CTRL_X_PATH_DEFINES   (7 + CTRL_X_WANT_IDENT)

◆ CTRL_X_PATH_PATTERNS

#define CTRL_X_PATH_PATTERNS   (6 + CTRL_X_WANT_IDENT)

◆ CTRL_X_SCROLL

#define CTRL_X_SCROLL   2

◆ CTRL_X_SPELL

#define CTRL_X_SPELL   14

◆ CTRL_X_TAGS

#define CTRL_X_TAGS   (5 + CTRL_X_WANT_IDENT)

◆ CTRL_X_THESAURUS

#define CTRL_X_THESAURUS   (10 + CTRL_X_WANT_IDENT)

◆ CTRL_X_WANT_IDENT

#define CTRL_X_WANT_IDENT   0x100

◆ CTRL_X_WHOLE_LINE

#define CTRL_X_WHOLE_LINE   3

◆ DICT_EXACT

#define DICT_EXACT   (2)

◆ DICT_FIRST

#define DICT_FIRST   (1)

◆ FREE_CPTEXT

#define FREE_CPTEXT (   cptext,
  cptext_allocated 
)
Value:
do { \
if (cptext != NULL && cptext_allocated) { \
for (size_t i = 0; i < CPT_COUNT; i++) { \
xfree(cptext[i]); \
} \
} \
} while (0)

◆ INPUT_BUFLEN

#define INPUT_BUFLEN   100

◆ ISSPECIAL

#define ISSPECIAL (   c)    ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^')

◆ MIN_SPACE

#define MIN_SPACE   75

◆ PC_STATUS_LEFT

#define PC_STATUS_LEFT   2

◆ PC_STATUS_RIGHT

#define PC_STATUS_RIGHT   1

◆ PC_STATUS_SET

#define PC_STATUS_SET   3

◆ PC_STATUS_UNSET

#define PC_STATUS_UNSET   0

◆ WHITECHAR

#define WHITECHAR (   cc)
Value:
( \
ascii_iswhite(cc) \

Typedef Documentation

◆ compl_T

typedef struct compl_S compl_T

◆ InsertState

typedef struct insert_state InsertState

Function Documentation

◆ add_char2buf()

char_u* add_char2buf ( int  c,
char_u s 
)

Add character "c" to buffer "s"

Escapes the special meaning of K_SPECIAL and CSI, handles multi-byte characters.

Parameters
[in]cCharacter to add.
[out]sBuffer to add to. Must have at least MB_MAXBYTES + 1 bytes.
Returns
Pointer to after the added bytes.

◆ auto_format()

void auto_format ( bool  trailblank,
bool  prev_line 
)

Called after inserting or deleting text: When 'formatoptions' includes the 'a' flag format from the current line until the end of the paragraph. Keep the cursor at the same position relative to the text. The caller must have saved the cursor line for undo, following ones will be saved here.

Parameters
trailblankwhen true also format with trailing blank
prev_linemay start in previous line

◆ backspace_until_column()

void backspace_until_column ( int  col)

◆ beginline()

void beginline ( int  flags)

◆ buf_prompt_text()

char_u* buf_prompt_text ( const buf_T *const  buf)

Return the effective prompt for the specified buffer.

◆ change_indent()

void change_indent ( int  type,
int  amount,
int  round,
int  replaced,
int  call_changed_bytes 
)

Insert an indent (for <Tab> or CTRL-T) or delete an indent (for CTRL-D). Keep the cursor on the same character. type == INDENT_INC increase indent (for CTRL-T or <Tab>) type == INDENT_DEC decrease indent (for CTRL-D) type == INDENT_SET set indent to "amount"

Parameters
roundif TRUE, round the indent to 'shiftwidth' (only with _INC and _Dec).
replacedreplaced character, put on replace stack
call_changed_bytescall changed_bytes()

◆ comp_textwidth()

int comp_textwidth ( bool  ff)

Find out textwidth to be used for formatting: if 'textwidth' option is set, use it else if 'wrapmargin' option is set, use curwin->w_width_inner-'wrapmargin' if invalid value, use 0. Set default to window width (maximum 79) for "gq" operator.

Parameters
ffforce formatting (for "gq" command)

◆ completeopt_was_set()

void completeopt_was_set ( void  )

◆ ctrl_x_mode_not_default()

bool ctrl_x_mode_not_default ( void  )

◆ ctrl_x_mode_not_defined_yet()

bool ctrl_x_mode_not_defined_yet ( void  )

◆ cursor_down()

int cursor_down ( long  n,
int  upd_topline 
)

Cursor down a number of logical lines.

Parameters
upd_toplineWhen TRUE: update topline

◆ cursor_up()

int cursor_up ( long  n,
int  upd_topline 
)

@oaram upd_topline When TRUE: update topline

◆ display_dollar()

void display_dollar ( colnr_T  col)

◆ edit()

bool edit ( int  cmdchar,
bool  startln,
long  count 
)

edit(): Start inserting text.

"cmdchar" can be: 'i' normal insert command 'a' normal append command 'R' replace command 'r' "r<CR>" command: insert one <CR>. Note: count can be > 1, for redo, but still only one <CR> is inserted. <Esc> is not used for redo. 'g' "gI" command. 'V' "gR" command for Virtual Replace mode. 'v' "gr" command for single character Virtual Replace mode.

This function is not called recursively. For CTRL-O commands, it returns and lets the caller handle the Normal-mode command.

Parameters
cmdcharcommand that started the insert
startlnif true, insert at start of line
countrepeat count for the command
Returns
true if a CTRL-O command caused the return (insert mode pending).

◆ edit_putchar()

void edit_putchar ( int  c,
bool  highlight 
)

◆ edit_unputchar()

void edit_unputchar ( void  )

◆ find_word_end()

char_u* find_word_end ( char_u ptr)

◆ find_word_start()

char_u* find_word_start ( char_u ptr)

◆ fix_indent()

void fix_indent ( void  )

◆ fixthisline()

void fixthisline ( IndentGetter  get_the_indent)

◆ for()

for ( )

◆ get_complete_info()

void get_complete_info ( list_T what_list,
dict_T retdict 
)

◆ get_last_insert()

char_u* get_last_insert ( void  )

◆ get_last_insert_save()

char_u* get_last_insert_save ( void  )

◆ get_literal()

int get_literal ( void  )

◆ get_nolist_virtcol()

colnr_T get_nolist_virtcol ( void  )

◆ hkmap()

int hkmap ( int  c)

◆ in_cinkeys()

bool in_cinkeys ( int  keytyped,
int  when,
bool  line_is_empty 
)

Check that "cinkeys" contains the key "keytyped", when == '*': Only if key is preceded with '*' (indent before insert) when == '!': Only if key is preceded with '!' (don't insert) when == ' ': Only if key is not preceded with '*' (indent afterwards)

"keytyped" can have a few special values: KEY_OPEN_FORW : KEY_OPEN_BACK : KEY_COMPLETE : Just finished completion.

Parameters
keytypedkey that was typed
whencondition on when to perform the check
line_is_emptywhen true, accept keys with '0' before them.

◆ ins_compl_active()

bool ins_compl_active ( void  )

Check that Insert completion is active.

◆ ins_compl_add_infercase()

int ins_compl_add_infercase ( char_u str_arg,
int  len,
bool  icase,
char_u fname,
Direction  dir,
bool  cont_s_ipos 
)

This is like ins_compl_add(), but if 'ic' and 'inf' are set, then the case of the originally typed text is used, and the case of the completed text is inferred, ie this tries to work out what case you probably wanted the rest of the word to be in – webb

Parameters
[in]cont_s_iposnext ^X<> will set initial_pos

◆ ins_compl_add_tv()

int ins_compl_add_tv ( typval_T *const  tv,
const Direction  dir,
bool  fast 
)

Add a match to the list of matches from VimL object

Parameters
[in]tvObject to get matches from.
[in]dirCompletion direction.
[in]fastuse fast_breakcheck() instead of os_breakcheck().
Returns
NOTDONE if the given string is already in the list of completions, otherwise it is added to the list and OK is returned. FAIL will be returned in case of error.

◆ ins_compl_check_keys()

void ins_compl_check_keys ( int  frequency,
int  in_compl_func 
)

◆ ins_compl_show_pum()

void ins_compl_show_pum ( void  )

Show the popup menu for the list of matches. Also adjusts "compl_shown_match" to an entry that is actually displayed.

◆ ins_copychar()

int ins_copychar ( linenr_T  lnum)

◆ insertchar()

void insertchar ( int  c,
int  flags,
int  second_indent 
)

"flags": INSCHAR_FORMAT - force formatting INSCHAR_CTRLV - char typed just after CTRL-V INSCHAR_NO_FEX - don't use 'formatexpr'

NOTE: passes the flags value straight through to internal_format() which, beside INSCHAR_FORMAT (above), is also looking for these: INSCHAR_DO_COM - format comments INSCHAR_COM_LIST - format comments with num list or 2nd line indent

Parameters
ccharacter to insert or NUL
flagsINSCHAR_FORMAT, etc.
second_indentindent for second line if >= 0

◆ oneleft()

int oneleft ( void  )

◆ oneright()

int oneright ( void  )

◆ prompt_curpos_editable()

bool prompt_curpos_editable ( void  )
Returns
true if the cursor is in the editable position of the prompt line.

◆ prompt_text()

char_u* prompt_text ( void  )

◆ pum_ext_select_item()

void pum_ext_select_item ( int  item,
bool  insert,
bool  finish 
)

◆ replace_push()

void replace_push ( int  c)

Push character that is replaced onto the the replace stack.

replace_offset is normally 0, in which case replace_push will add a new character at the end of the stack. If replace_offset is not 0, that many characters will be left on the stack above the newly inserted character.

Parameters
ccharacter that is replaced (NUL is none)

◆ replace_push_mb()

int replace_push_mb ( char_u p)

◆ set_completion()

void set_completion ( colnr_T  startcol,
list_T list 
)

◆ set_last_insert()

void set_last_insert ( int  c)

◆ stop_arrow()

int stop_arrow ( void  )

◆ stuff_inserted()

int stuff_inserted ( int  c,
long  count,
int  no_esc 
)

Stuff the last inserted text in the read buffer. Last_insert actually is a copy of the redo buffer, so we first have to remove the command.

Parameters
cCommand character to be inserted
countRepeat this many times
no_escDon't add an ESC at the end

◆ truncate_spaces()

void truncate_spaces ( char_u line)

◆ vim_is_ctrl_x_key()

bool vim_is_ctrl_x_key ( int  c)

Check that the character "c" a valid key to go to or keep us in CTRL-X mode? This depends on the current mode.

Parameters
ccharacter to check

Variable Documentation

◆ active

bool active

◆ add_r

int add_r

◆ finish

bool finish

◆ fp

FILE* fp

◆ i

void int i
Initial value:

◆ insert

bool insert

◆ item

int item

◆ pum_want

struct { ... } pum_want

state for pum_ext_select_item.

get_cursor_pos_ptr
char_u * get_cursor_pos_ptr(void)
Definition: cursor.c:520
ptr
char_u * ptr
Definition: normal.c:3176
i
static void int i
Definition: edit.c:3002
utf_iscomposing
bool utf_iscomposing(int c)
Definition: mbyte.c:1048
utf_ptr2char
int utf_ptr2char(const char_u *const p) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
Definition: mbyte.c:603
CPT_COUNT
#define CPT_COUNT
Definition: edit.h:13
char_u
unsigned char char_u
Definition: types.h:12
NULL
return NULL
Definition: eval.c:10355