Data Structures | Macros | Functions | Variables
ops.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/edit.h"
#include "nvim/eval.h"
#include "nvim/eval/typval.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_getln.h"
#include "nvim/extmark.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
#include "nvim/globals.h"
#include "nvim/indent.h"
#include "nvim/indent_c.h"
#include "nvim/lib/kvec.h"
#include "nvim/log.h"
#include "nvim/macros.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.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/screen.h"
#include "nvim/search.h"
#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/terminal.h"
#include "nvim/ui.h"
#include "nvim/undo.h"
#include "nvim/vim.h"
#include "nvim/window.h"

Data Structures

struct  block_def
 

Macros

#define OPF_LINES   1
 
#define OPF_CHANGE   2
 
#define MSG_NO_CLIP
 

Functions

yankreg_Tget_y_previous (void)
 
void set_y_previous (yankreg_T *yreg)
 
int get_op_type (int char1, int char2)
 
int op_on_lines (int op)
 
int op_is_change (int op)
 
int get_op_char (int optype)
 
int get_extra_op_char (int optype)
 Get second operator command character. More...
 
void op_shift (oparg_T *oap, int curs_top, int amount)
 handle a shift operation More...
 
void shift_line (int left, int round, int amount, int call_changed_bytes)
 
void op_reindent (oparg_T *oap, Indenter how)
 Handle reindenting a block of lines. More...
 
int get_expr_register (void)
 
void set_expr_line (char_u *new_line)
 
char_uget_expr_line (void)
 
char_uget_expr_line_src (void)
 Get the '=' register expression itself, without evaluating it. More...
 
bool valid_yank_reg (int regname, bool writing)
 
yankreg_Tget_yank_register (int regname, int mode)
 
yankreg_Tcopy_register (int name) FUNC_ATTR_NONNULL_RET
 
bool yank_register_mline (int regname)
 Check if the current yank register has kMTLineWise register type. More...
 
int do_record (int c)
 
int do_execreg (int regname, int colon, int addcr, int silent)
 
int insert_reg (int regname, bool literally_arg)
 
bool get_spec_reg (int regname, char_u **argp, bool *allocated, bool errmsg)
 
bool cmdline_paste_reg (int regname, bool literally_arg, bool remcr)
 
int op_delete (oparg_T *oap)
 
void op_tilde (oparg_T *oap)
 Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?". More...
 
bool swapchar (int op_type, pos_T *pos) FUNC_ATTR_NONNULL_ARG(2)
 
void op_insert (oparg_T *oap, long count1)
 Insert and append operators for Visual mode. More...
 
int op_change (oparg_T *oap)
 
void free_register (yankreg_T *reg) FUNC_ATTR_NONNULL_ALL
 
bool op_yank (oparg_T *oap, bool message) FUNC_ATTR_NONNULL_ALL
 
void do_put (int regname, yankreg_T *reg, int dir, long count, int flags)
 
void adjust_cursor_eol (void)
 
int preprocs_left (void)
 
int get_register_name (int num)
 
int get_unname_register (void)
 
void ex_display (exarg_T *eap)
 ":dis" and ":registers": Display the contents of the yank registers. More...
 
char_uskip_comment (char_u *line, bool process, bool include_space, bool *is_comment)
 
int do_join (size_t count, int insert_space, int save_undo, int use_formatoptions, bool setmark)
 
int fex_format (linenr_T lnum, long count, int c)
 
void format_lines (linenr_T line_count, int avoid_fex)
 
int paragraph_start (linenr_T lnum)
 
void op_addsub (oparg_T *oap, linenr_T Prenum1, bool g_cmd)
 
int do_addsub (int op_type, pos_T *pos, int length, linenr_T Prenum1)
 
MotionType get_reg_type (int regname, colnr_T *reg_width)
 
void format_reg_type (MotionType reg_type, colnr_T reg_width, char *buf, size_t buf_len) FUNC_ATTR_NONNULL_ALL
 
voidget_reg_contents (int regname, int flags)
 
void write_reg_contents (int name, const char_u *str, ssize_t len, int must_append)
 
void write_reg_contents_lst (int name, char_u **strings, bool must_append, MotionType yank_type, colnr_T block_len)
 
void write_reg_contents_ex (int name, const char_u *str, ssize_t len, bool must_append, MotionType yank_type, colnr_T block_len)
 
void clear_oparg (oparg_T *oap)
 
void cursor_pos_info (dict_T *dict)
 
void do_pending_operator (cmdarg_T *cap, int old_col, bool gui_yank)
 
int get_default_register_name (void)
 
bool prepare_yankreg_from_object (yankreg_T *reg, String regtype, size_t lines)
 
void finish_yankreg_from_object (yankreg_T *reg, bool clipboard_adjust)
 
void start_batch_changes (void)
 Avoid slow things (clipboard) during batch operations (while/for-loops). More...
 
void end_batch_changes (void)
 Counterpart to start_batch_changes(). More...
 
int save_batch_count (void)
 
void restore_batch_count (int save_count)
 
const voidop_global_reg_iter (const void *const iter, char *const name, yankreg_T *const reg, bool *is_unnamed) FUNC_ATTR_NONNULL_ARG(2
 
const voidop_reg_iter (const void *const iter, const yankreg_T *const regs, char *const name, yankreg_T *const reg, bool *is_unnamed) FUNC_ATTR_NONNULL_ARG(3
 
 while (iter_reg - &(regs[0])< NUM_SAVED_REGISTERS &&reg_empty(iter_reg))
 
 if (iter_reg - &(regs[0])==NUM_SAVED_REGISTERS||reg_empty(iter_reg))
 
size_t op_reg_amount (void)
 Get a number of non-empty registers. More...
 
bool op_reg_set (const char name, const yankreg_T reg, bool is_unnamed)
 
const yankreg_Top_reg_get (const char name)
 
bool op_reg_set_previous (const char name)
 
bcount_t get_region_bytecount (buf_T *buf, linenr_T start_lnum, linenr_T end_lnum, colnr_T start_col, colnr_T end_col)
 

Variables

const void FUNC_ATTR_WARN_UNUSED_RESULT
 
const yankreg_Titer_reg
 
int iter_off = (int)(iter_reg - &(regs[0]))
 
name = (char)get_register_name(iter_off)
 
is_unnamed = (iter_reg == y_previous)
 
return NULL
 
reg = *iter_reg
 

Macro Definition Documentation

◆ MSG_NO_CLIP

#define MSG_NO_CLIP
Value:
"clipboard: No provider. " \
"Try \":checkhealth\" or \":h clipboard\"."

◆ OPF_CHANGE

#define OPF_CHANGE   2

◆ OPF_LINES

#define OPF_LINES   1

Function Documentation

◆ adjust_cursor_eol()

void adjust_cursor_eol ( void  )

When the cursor is on the NUL past the end of the line and it should not be there move it left.

◆ clear_oparg()

void clear_oparg ( oparg_T oap)

◆ cmdline_paste_reg()

bool cmdline_paste_reg ( int  regname,
bool  literally_arg,
bool  remcr 
)

Paste a yank register into the command line. Only for non-special registers. Used by CTRL-R in command-line mode. insert_reg() can't be used here, because special characters from the register contents will be interpreted as commands.

Parameters
regnameRegister name.
literally_argInsert text literally instead of "as typed".
remcrWhen true, don't add CR characters.
Returns
FAIL for failure, OK otherwise

◆ copy_register()

yankreg_T* copy_register ( int  name)
Returns
a copy of contents in register name for use in do_put. Should be freed by caller.

◆ cursor_pos_info()

void cursor_pos_info ( dict_T dict)

Give some info about the position of the cursor (for "g CTRL-G"). In Visual mode, give some info about the selected region. (In this case, the *_count_cursor variables store running totals for the selection.)

Parameters
dictwhen not NULL, store the info there instead of showing it.

◆ do_addsub()

int do_addsub ( int  op_type,
pos_T pos,
int  length,
linenr_T  Prenum1 
)

Add or subtract from a number in a line.

Parameters
op_typeOP_NR_ADD or OP_NR_SUB.
posCursor position.
lengthTarget number length.
Prenum1Amount of addition or subtraction.
Returns
true if some character was changed.

◆ do_execreg()

int do_execreg ( int  regname,
int  colon,
int  addcr,
int  silent 
)

Execute a yank register: copy it into the stuff buffer

Parameters
coloninsert ':' before each line
addcralways add '
' to end of line
silentset "silent" flag in typeahead buffer
Returns
FAIL for failure, OK otherwise

◆ do_join()

int do_join ( size_t  count,
int  insert_space,
int  save_undo,
int  use_formatoptions,
bool  setmark 
)
Parameters
countnumber of lines (minimal 2) to join at cursor position.
save_undowhen TRUE, save lines for undo first.
use_formatoptionsset to FALSE when e.g. processing backspace and comment leaders should not be removed.
setmarkwhen true, sets the '[ and '] mark, else, the caller is expected to set those marks.
Returns
FAIL for failure, OK otherwise

◆ do_pending_operator()

void do_pending_operator ( cmdarg_T cap,
int  old_col,
bool  gui_yank 
)

Handle an operator after Visual mode or when the movement is finished. "gui_yank" is true when yanking text for the clipboard.

◆ do_put()

void do_put ( int  regname,
yankreg_T reg,
int  dir,
long  count,
int  flags 
)

Put contents of register "regname" into the text. Caller must check "regname" to be valid!

Parameters
flagsPUT_FIXINDENT make indent look nice PUT_CURSEND leave cursor after end of new text PUT_LINE force linewise put (":put") PUT_BLOCK_INNER in block mode, do not add trailing spaces
dirBACKWARD for 'P', FORWARD for 'p'

◆ do_record()

int do_record ( int  c)

Start or stop recording into a yank register.

Returns
FAIL for failure, OK otherwise.

◆ end_batch_changes()

void end_batch_changes ( void  )

Counterpart to start_batch_changes().

◆ ex_display()

void ex_display ( exarg_T eap)

":dis" and ":registers": Display the contents of the yank registers.

◆ fex_format()

int fex_format ( linenr_T  lnum,
long  count,
int  c 
)
Parameters
ccharacter to be inserted

◆ finish_yankreg_from_object()

void finish_yankreg_from_object ( yankreg_T reg,
bool  clipboard_adjust 
)

◆ format_lines()

void format_lines ( linenr_T  line_count,
int  avoid_fex 
)
Parameters
line_countnumber of lines to format, starting at the cursor position. when negative, format until the end of the paragraph.

Lines after the cursor line are saved for undo, caller must have saved the first line.

Parameters
avoid_fexdon't use 'formatexpr'

◆ format_reg_type()

void format_reg_type ( MotionType  reg_type,
colnr_T  reg_width,
char *  buf,
size_t  buf_len 
)

Format the register type as a string.

Parameters
reg_typeThe register type.
reg_widthThe width, only used if "reg_type" is kMTBlockWise.
[out]bufBuffer to store formatted string. The allocated size should be at least NUMBUFLEN+2 to always fit the value.
buf_lenThe allocated size of the buffer.

◆ free_register()

void free_register ( yankreg_T reg)

Free contents of yankreg reg. Called for normal freeing and in case of error.

Parameters
regmust not be NULL (but reg->y_array might be)

◆ get_default_register_name()

int get_default_register_name ( void  )

Check if the default register (used in an unnamed paste) should be a clipboard register. This happens when clipboard=unnamed[plus] is set and a provider is available.

Returns
the name of of a clipboard register that should be used, or NUL if none.

◆ get_expr_line()

char_u* get_expr_line ( void  )

Get the result of the '=' register expression.

Returns
a pointer to allocated memory, or NULL for failure.

◆ get_expr_line_src()

char_u* get_expr_line_src ( void  )

Get the '=' register expression itself, without evaluating it.

◆ get_expr_register()

int get_expr_register ( void  )

Get an expression for the "\"=expr1" or "CTRL-R =expr1"

Returns
'=' when OK, NUL otherwise.

◆ get_extra_op_char()

int get_extra_op_char ( int  optype)

Get second operator command character.

◆ get_op_char()

int get_op_char ( int  optype)

Get first operator command character.

Returns
'g' or 'z' if there is another command character.

◆ get_op_type()

int get_op_type ( int  char1,
int  char2 
)

Translate a command name into an operator type. Must only be called with a valid operator name!

◆ get_reg_contents()

void* get_reg_contents ( int  regname,
int  flags 
)

Gets the contents of a register.

Remarks
Used for @r in expressions and for getreg().
Parameters
regnameThe register.
flagssee GRegFlags
Returns
The contents of the register as an allocated string.
A linked list when flags contains kGRegList.
NULL for error.

◆ get_reg_type()

MotionType get_reg_type ( int  regname,
colnr_T reg_width 
)

Used for getregtype()

Returns
the type of a register or kMTUnknown for error.

◆ get_region_bytecount()

bcount_t get_region_bytecount ( buf_T buf,
linenr_T  start_lnum,
linenr_T  end_lnum,
colnr_T  start_col,
colnr_T  end_col 
)

Get the byte count of buffer region. End-exclusive.

Returns
number of bytes

◆ get_register_name()

int get_register_name ( int  num)
Returns
the character name of the register with the given number

◆ get_spec_reg()

bool get_spec_reg ( int  regname,
char_u **  argp,
bool allocated,
bool  errmsg 
)

If "regname" is a special register, return true and store a pointer to its value in "argp".

Parameters
allocatedreturn: true when value was allocated
errmsggive error message when failing
Returns
true if "regname" is a special register,

◆ get_unname_register()

int get_unname_register ( void  )
Returns
the index of the register "" points to.

◆ get_y_previous()

yankreg_T* get_y_previous ( void  )

◆ get_yank_register()

yankreg_T* get_yank_register ( int  regname,
int  mode 
)
Returns
yankreg_T to use, according to the value of regname. Cannot handle the '_' (black hole) register. Must only be called with a valid register name!
Parameters
regnameThe name of the register used or 0 for the unnamed register
modeOne of the following three flags:

YREG_PASTE: Prepare for pasting the register regname. With no regname specified, read from last written register, or from unnamed clipboard (depending on the clipboard=unnamed option). Queries the clipboard provider if necessary.

YREG_YANK: Preparare for yanking into regname. With no regname specified, yank into "0 register. Update y_previous for next unnamed paste.

YREG_PUT: Obtain the location that would be read when pasting regname.

◆ if()

if ( iter_reg - &  regs[0] = NUM_SAVED_REGISTERS || reg_empty(iter_reg))

◆ insert_reg()

int insert_reg ( int  regname,
bool  literally_arg 
)

Insert a yank register: copy it into the Read buffer. Used by CTRL-R command and middle mouse button in insert mode.

Parameters
literally_arginsert literally, not as if typed
Returns
FAIL for failure, OK otherwise

◆ op_addsub()

void op_addsub ( oparg_T oap,
linenr_T  Prenum1,
bool  g_cmd 
)

Handle the add/subtract operator.

Parameters
[in]oapArguments of operator.
[in]Prenum1Amount of addition or subtraction.
[in]g_cmdPrefixed with g.

◆ op_change()

int op_change ( oparg_T oap)

handle a change operation

Returns
TRUE if edit() returns because of a CTRL-O command

◆ op_delete()

int op_delete ( oparg_T oap)

Handle a delete operation.

Returns
FAIL if undo failed, OK otherwise.

◆ op_global_reg_iter()

const void* op_global_reg_iter ( const void *const  iter,
char *const  name,
yankreg_T *const  reg,
bool is_unnamed 
)

Iterate over global registers.

See also
op_register_iter

◆ op_insert()

void op_insert ( oparg_T oap,
long  count1 
)

Insert and append operators for Visual mode.

◆ op_is_change()

int op_is_change ( int  op)
Returns
TRUE if operator "op" changes text.

◆ op_on_lines()

int op_on_lines ( int  op)
Returns
TRUE if operator "op" always works on whole lines.

◆ op_reg_amount()

size_t op_reg_amount ( void  )

Get a number of non-empty registers.

◆ op_reg_get()

const yankreg_T* op_reg_get ( const char  name)

Get register with the given name

Parameters
[in]nameRegister name.
Returns
Pointer to the register contents or NULL.

◆ op_reg_iter()

const void* op_reg_iter ( const void *const  iter,
const yankreg_T *const  regs,
char *const  name,
yankreg_T *const  reg,
bool is_unnamed 
)

Iterate over registers regs.

Parameters
[in]iterIterator. Pass NULL to start iteration.
[in]regsRegisters list to be iterated.
[out]nameRegister name.
[out]regRegister contents.
Returns
Pointer that must be passed to next op_register_iter call or NULL if iteration is over.

◆ op_reg_set()

bool op_reg_set ( const char  name,
const yankreg_T  reg,
bool  is_unnamed 
)

Set register to a given value

Parameters
[in]nameRegister name.
[in]regRegister value.
[in]is_unnamedWhether to set the unnamed regiseter to reg
Returns
true on success, false on failure.

◆ op_reg_set_previous()

bool op_reg_set_previous ( const char  name)

Set the previous yank register

Parameters
[in]nameRegister name.
Returns
true on success, false on failure.

◆ op_reindent()

void op_reindent ( oparg_T oap,
Indenter  how 
)

Handle reindenting a block of lines.

◆ op_shift()

void op_shift ( oparg_T oap,
int  curs_top,
int  amount 
)

handle a shift operation

◆ op_tilde()

void op_tilde ( oparg_T oap)

Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?".

◆ op_yank()

bool op_yank ( oparg_T oap,
bool  message 
)

Yanks the text between "oap->start" and "oap->end" into a yank register. If we are to append (uppercase register), we first yank into a new yank register and then concatenate the old and the new one. Do not call this from a delete operation. Use op_yank_reg() instead.

Parameters
oapoperator arguments
messageshow message when more than &report lines are yanked.
Returns
whether the operation register was writable.

◆ paragraph_start()

int paragraph_start ( linenr_T  lnum)

Used for auto-formatting.

Returns
TRUE when a paragraph starts in line "lnum". FALSE when the previous line is in the same paragraph.

◆ prepare_yankreg_from_object()

bool prepare_yankreg_from_object ( yankreg_T reg,
String  regtype,
size_t  lines 
)
Parameters
[out]regExpected to be empty

◆ preprocs_left()

int preprocs_left ( void  )
Returns
TRUE if lines starting with '#' should be left aligned.

◆ restore_batch_count()

void restore_batch_count ( int  save_count)

◆ save_batch_count()

int save_batch_count ( void  )

◆ set_expr_line()

void set_expr_line ( char_u new_line)

Set the expression for the '=' register. Argument must be an allocated string.

◆ set_y_previous()

void set_y_previous ( yankreg_T yreg)

◆ shift_line()

void shift_line ( int  left,
int  round,
int  amount,
int  call_changed_bytes 
)

Shift the current line one shiftwidth left (if left != 0) or right leaves cursor on first blank in the line.

Parameters
call_changed_bytescall changed_bytes()

◆ skip_comment()

char_u* skip_comment ( char_u line,
bool  process,
bool  include_space,
bool is_comment 
)

If "process" is true and the line begins with a comment leader (possibly after some white space), return a pointer to the text after it. Put a boolean value indicating whether the line ends with an unclosed comment in "is_comment".

Parameters
line- line to be processed
process- if false, will only check whether the line ends with an unclosed comment,
include_space- whether to skip space following the comment leader
[out]is_comment- whether the current line ends with an unclosed comment.

◆ start_batch_changes()

void start_batch_changes ( void  )

Avoid slow things (clipboard) during batch operations (while/for-loops).

◆ swapchar()

bool swapchar ( int  op_type,
pos_T pos 
)
Parameters
op_type== OP_UPPER: make uppercase, == OP_LOWER: make lowercase, == OP_ROT13: do rot13 encoding, else swap case of character at 'pos'
Returns
true when something actually changed.

◆ valid_yank_reg()

bool valid_yank_reg ( int  regname,
bool  writing 
)
Returns
whether regname is a valid name of a yank register.
Note
: There is no check for 0 (default register), caller should do this. The black hole register '_' is regarded as valid.
Parameters
regnamename of register
writingallow only writable registers

◆ while()

while ( )

◆ write_reg_contents()

void write_reg_contents ( int  name,
const char_u str,
ssize_t  len,
int  must_append 
)

store str in register name

See also
write_reg_contents_ex

◆ write_reg_contents_ex()

void write_reg_contents_ex ( int  name,
const char_u str,
ssize_t  len,
bool  must_append,
MotionType  yank_type,
colnr_T  block_len 
)

write_reg_contents_ex - store str in register name

If str ends in '
' or '\r', use linewise, otherwise use charwise.

Warning
when name is '/', len and must_append are ignored. This means that str MUST be NUL-terminated.
Parameters
nameThe name of the register
strThe contents to write
lenIf >= 0, write len bytes of str. Otherwise, write strlen(str) bytes. If len is larger than the allocated size of src, the behaviour is undefined.
must_appendIf true, append the contents of str to the current contents of the register. Note that regardless of must_append, this function will append when name is an uppercase letter.
yank_typeThe motion type (kMTUnknown to auto detect)
block_lenwidth of visual block

◆ write_reg_contents_lst()

void write_reg_contents_lst ( int  name,
char_u **  strings,
bool  must_append,
MotionType  yank_type,
colnr_T  block_len 
)

◆ yank_register_mline()

bool yank_register_mline ( int  regname)

Check if the current yank register has kMTLineWise register type.

Variable Documentation

◆ FUNC_ATTR_WARN_UNUSED_RESULT

const void FUNC_ATTR_WARN_UNUSED_RESULT
Initial value:
{
return op_reg_iter(iter, y_regs, name, reg, is_unnamed)

◆ is_unnamed

* is_unnamed = (iter_reg == y_previous)

◆ iter_off

int iter_off = (int)(iter_reg - &(regs[0]))

◆ iter_reg

const yankreg_T* iter_reg
Initial value:
= (iter == NULL
? &(regs[0])
: (const yankreg_T *const)iter)

◆ name

* name = (char)get_register_name(iter_off)

◆ NULL

return NULL

◆ reg

static char_u * reg = *iter_reg

Parse regular expression, i.e. main body or parenthesized thing.

Caller must absorb opening parenthesis.

Combining parenthesis handling with the base level of regular expression is a trifle forced, but the need to tie the tails of the branches to what follows makes it hard to avoid.

Parameters
parenREG_NOPAREN, REG_PAREN, REG_NPAREN or REG_ZPAREN
yankreg
Definition of one register.
Definition: ops.h:84
reg
* reg
Definition: ops.c:7268
is_unnamed
* is_unnamed
Definition: ops.c:7269
NULL
return NULL
Definition: ops.c:7275
name
* name
Definition: ops.c:7267
op_reg_iter
const void * op_reg_iter(const void *const iter, const yankreg_T *const regs, char *const name, yankreg_T *const reg, bool *is_unnamed) FUNC_ATTR_NONNULL_ARG(3