Data Structures | Macros | Typedefs | Functions | Variables
edit.c File Reference
#include <assert.h>
#include <string.h>
#include <inttypes.h>
#include <stdbool.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/edit.h"
#include "nvim/buffer.h"
#include "nvim/change.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/digraph.h"
#include "nvim/eval.h"
#include "nvim/eval/typval.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
#include "nvim/indent.h"
#include "nvim/indent_c.h"
#include "nvim/main.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/keymap.h"
#include "nvim/move.h"
#include "nvim/normal.h"
#include "nvim/ops.h"
#include "nvim/option.h"
#include "nvim/path.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/strings.h"
#include "nvim/state.h"
#include "nvim/syntax.h"
#include "nvim/tag.h"
#include "nvim/ui.h"
#include "nvim/mouse.h"
#include "nvim/terminal.h"
#include "nvim/undo.h"
#include "nvim/window.h"
#include "nvim/event/loop.h"
#include "nvim/mark.h"
#include "nvim/os/input.h"
#include "nvim/os/time.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_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 /* pc_bytes was not set */
 
#define PC_STATUS_RIGHT   1 /* right halve of double-wide char */
 
#define PC_STATUS_LEFT   2 /* left halve of double-wide char */
 
#define PC_STATUS_SET   3 /* pc_bytes was filled */
 
#define FREE_CPTEXT(cptext, cptext_allocated)
 
#define DICT_FIRST   (1) /* use just first element in "dict" */
 
#define DICT_EXACT   (2) /* "dict" is the exact name of a file */
 
#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, int highlight)
 
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, int 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)
 
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) 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 (int trailblank, int prev_line)
 
int comp_textwidth (int 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)
 
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)
 

Variables

struct {
   bool   active
 
   int   item
 
   bool   insert
 
   bool   finish
 
pum_want
 state for pum_ext_select_item. More...
 

Macro Definition Documentation

#define BACKSPACE_CHAR   1
#define BACKSPACE_LINE   4
#define BACKSPACE_WORD   2
#define BACKSPACE_WORD_NOT_SPACE   3
#define CI_WHAT_ALL   0xff
#define CI_WHAT_INSERTED   0x10
#define CI_WHAT_ITEMS   0x04
#define CI_WHAT_MODE   0x01
#define CI_WHAT_PUM_VISIBLE   0x02
#define CI_WHAT_SELECTED   0x08
#define CTRL_X_CMDLINE   11
#define CTRL_X_DICTIONARY   (9 + CTRL_X_WANT_IDENT)
#define CTRL_X_EVAL   16

for builtin function complete()

#define CTRL_X_FILES   4
#define CTRL_X_FINISHED   8
#define CTRL_X_FUNCTION   12
#define CTRL_X_LOCAL_MSG   15

only used in "ctrl_x_msgs"

#define CTRL_X_MODE_LINE_OR_EVAL (   m)    ((m) == CTRL_X_WHOLE_LINE || (m) == CTRL_X_EVAL)
#define CTRL_X_MSG (   i)    ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]
#define CTRL_X_NORMAL   0

CTRL-N CTRL-P completion, default.

#define CTRL_X_NOT_DEFINED_YET   1
#define CTRL_X_OMNI   13
#define CTRL_X_PATH_DEFINES   (7 + CTRL_X_WANT_IDENT)
#define CTRL_X_PATH_PATTERNS   (6 + CTRL_X_WANT_IDENT)
#define CTRL_X_SCROLL   2
#define CTRL_X_SPELL   14
#define CTRL_X_TAGS   (5 + CTRL_X_WANT_IDENT)
#define CTRL_X_THESAURUS   (10 + CTRL_X_WANT_IDENT)
#define CTRL_X_WANT_IDENT   0x100
#define CTRL_X_WHOLE_LINE   3
#define DICT_EXACT   (2) /* "dict" is the exact name of a file */
#define DICT_FIRST   (1) /* use just first element in "dict" */
#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)
xfree(tofree)
if(len)
Definition: encode.c:222
return NULL
Definition: eval.c:23643
for(size_t i=1;i< ARRAY_SIZE(argv);i++)
Definition: typval.c:1215
#define CPT_COUNT
Definition: edit.h:14
int i
Definition: typval.c:868
#define INPUT_BUFLEN   100
#define ISSPECIAL (   c)    ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^')
#define MIN_SPACE   75
#define PC_STATUS_LEFT   2 /* left halve of double-wide char */
#define PC_STATUS_RIGHT   1 /* right halve of double-wide char */
#define PC_STATUS_SET   3 /* pc_bytes was filled */
#define PC_STATUS_UNSET   0 /* pc_bytes was not set */
#define WHITECHAR (   cc)
Value:
(ascii_iswhite(cc) && \
(!enc_utf8 || \
bool utf_iscomposing(int c)
Definition: mbyte.c:1025
int utf_ptr2char(const char_u *const p) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
Definition: mbyte.c:593
#define enc_utf8
Definition: globals.h:646
char_u * get_cursor_pos_ptr(void)
Definition: cursor.c:512

Typedef Documentation

typedef struct compl_S compl_T
typedef struct insert_state InsertState

Function Documentation

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.
void auto_format ( int  trailblank,
int  prev_line 
)
void backspace_until_column ( int  col)
void beginline ( int  flags)
void change_indent ( int  type,
int  amount,
int  round,
int  replaced,
int  call_changed_bytes 
)
int comp_textwidth ( int  ff)
void completeopt_was_set ( void  )
bool ctrl_x_mode_not_default ( void  )
bool ctrl_x_mode_not_defined_yet ( void  )
int cursor_down ( long  n,
int  upd_topline 
)
int cursor_up ( long  n,
int  upd_topline 
)
void display_dollar ( colnr_T  col)
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).
void edit_putchar ( int  c,
int  highlight 
)
void edit_unputchar ( void  )
char_u* find_word_end ( char_u ptr)
char_u* find_word_start ( char_u ptr)
void fix_indent ( void  )
void fixthisline ( IndentGetter  get_the_indent)
void get_complete_info ( list_T what_list,
dict_T retdict 
)
char_u* get_last_insert ( void  )
char_u* get_last_insert_save ( void  )
int get_literal ( void  )
int hkmap ( int  c)
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.
bool ins_compl_active ( void  )

Check that Insert completion is active.

int ins_compl_add_infercase ( char_u str_arg,
int  len,
bool  icase,
char_u fname,
int  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
int ins_compl_add_tv ( typval_T *const  tv,
const Direction  dir 
)

Add a match to the list of matches from VimL object

Parameters
[in]tvObject to get matches from.
[in]dirCompletion direction.
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.
void ins_compl_check_keys ( int  frequency,
int  in_compl_func 
)
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.

int ins_copychar ( linenr_T  lnum)
void insertchar ( int  c,
int  flags,
int  second_indent 
)
int oneleft ( void  )
int oneright ( void  )
void pum_ext_select_item ( int  item,
bool  insert,
bool  finish 
)
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)
int replace_push_mb ( char_u p)
void set_completion ( colnr_T  startcol,
list_T list 
)
void set_last_insert ( int  c)
int stop_arrow ( void  )
int stuff_inserted ( int  c,
long  count,
int  no_esc 
)
void truncate_spaces ( char_u line)
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

bool active
bool finish
bool insert
int item
struct { ... } pum_want

state for pum_ext_select_item.