Data Structures | Macros | Enumerations | Functions | Variables
ops.c File Reference
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/ops.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/fileio.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
#include "nvim/indent.h"
#include "nvim/log.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/move.h"
#include "nvim/normal.h"
#include "nvim/option.h"
#include "nvim/path.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/macros.h"
#include "nvim/window.h"
#include "nvim/os/input.h"
#include "nvim/os/time.h"

Data Structures

struct  block_def
 

Macros

#define MSG_NO_CLIP
 

Enumerations

enum  yreg_mode_t { YREG_PASTE, YREG_YANK, YREG_PUT }
 

Functions

int get_op_type (int char1, int char2)
 
int op_on_lines (int op)
 
int get_op_char (int optype)
 
int get_extra_op_char (int optype)
 
void op_shift (oparg_T *oap, int curs_top, int amount)
 
void shift_line (int left, int round, int amount, int call_changed_bytes)
 
void op_reindent (oparg_T *oap, Indenter how)
 
int get_expr_register (void)
 
void set_expr_line (char_u *new_line)
 
char_uget_expr_line (void)
 
char_uget_expr_line_src (void)
 
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, int literally)
 
bool get_spec_reg (int regname, char_u **argp, bool *allocated, bool errmsg)
 
bool cmdline_paste_reg (int regname, bool literally, bool remcr)
 
int op_delete (oparg_T *oap)
 
int op_replace (oparg_T *oap, int c)
 
void op_tilde (oparg_T *oap)
 
bool swapchar (int op_type, pos_T *pos) FUNC_ATTR_NONNULL_ARG(2)
 
void op_insert (oparg_T *oap, long count1)
 
int op_change (oparg_T *oap)
 
void init_yank (void)
 
void free_register (yankreg_T *reg) FUNC_ATTR_NONNULL_ALL
 
bool op_yank (oparg_T *oap, bool message, int deleting) 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)
 
void ex_display (exarg_T *eap)
 
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)
 
void op_format (oparg_T *oap, int keep_cursor)
 
void op_formatexpr (oparg_T *oap)
 
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
 
void * get_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)
 
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 void * op_global_reg_iter (const void *const iter, char *const name, yankreg_T *const reg, bool *is_unnamed) FUNC_ATTR_NONNULL_ARG(2
 
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
 
 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) FUNC_ATTR_WARN_UNUSED_RESULT
 

Variables

ifclipboard
 
if or NUL if unnamed *param quiet Suppress error messages *param writing if we re setting the contents of the clipboard **returns the yankreg that should be written into
 
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)
 
reg = *iter_reg
 
is_unnamed = (iter_reg == y_previous)
 
return NULL
 

Macro Definition Documentation

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

Enumeration Type Documentation

Enumerator
YREG_PASTE 
YREG_YANK 
YREG_PUT 

Function Documentation

void adjust_cursor_eol ( void  )
void clear_oparg ( oparg_T oap)
bool cmdline_paste_reg ( int  regname,
bool  literally,
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.
literallyInsert text literally instead of "as typed".
remcrWhen true, don't add CR characters.
Returns
FAIL for failure, OK otherwise
yankreg_T* copy_register ( int  name)

Returns a copy of contents in register name for use in do_put. Should be freed by caller.

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.) When "dict" is not NULL store the info there instead of showing it.

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.
int do_execreg ( int  regname,
int  colon,
int  addcr,
int  silent 
)

Execute a yank register: copy it into the stuff buffer

Return FAIL for failure, OK otherwise

int do_join ( size_t  count,
int  insert_space,
int  save_undo,
int  use_formatoptions,
bool  setmark 
)
void do_put ( int  regname,
yankreg_T reg,
int  dir,
long  count,
int  flags 
)
int do_record ( int  c)
void end_batch_changes ( void  )

Counterpart to start_batch_changes().

void ex_display ( exarg_T eap)
int fex_format ( linenr_T  lnum,
long  count,
int  c 
)
void finish_yankreg_from_object ( yankreg_T reg,
bool  clipboard_adjust 
)
void format_lines ( linenr_T  line_count,
int  avoid_fex 
)
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.
void free_register ( yankreg_T reg)

Free contents of yankreg reg. Called for normal freeing and in case of error. reg must not be NULL (but reg->y_array might be)

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.
char_u* get_expr_line ( void  )
char_u* get_expr_line_src ( void  )
int get_expr_register ( void  )
int get_extra_op_char ( int  optype)
int get_op_char ( int  optype)
int get_op_type ( int  char1,
int  char2 
)
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.
MotionType get_reg_type ( int  regname,
colnr_T reg_width 
)
int get_register_name ( int  num)
bool get_spec_reg ( int  regname,
char_u **  argp,
bool *  allocated,
bool  errmsg 
)
yankreg_T* get_yank_register ( int  regname,
int  mode 
)

Return 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 ( iter_reg-&  regs[0] = NUM_SAVED_REGISTERS || reg_empty(iter_reg))
void init_yank ( void  )
int insert_reg ( int  regname,
int  literally 
)
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.
int op_change ( oparg_T oap)
int op_delete ( oparg_T oap)
void op_format ( oparg_T oap,
int  keep_cursor 
)
void op_formatexpr ( oparg_T oap)
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
void op_insert ( oparg_T oap,
long  count1 
)
int op_on_lines ( int  op)
size_t op_reg_amount ( void  )

Get a number of non-empty registers.

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.
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.
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.
bool op_reg_set_previous ( const char  name)

Set the previous yank register

Parameters
[in]nameRegister name.
Returns
true on success, false on failure.
void op_reindent ( oparg_T oap,
Indenter  how 
)
int op_replace ( oparg_T oap,
int  c 
)
void op_shift ( oparg_T oap,
int  curs_top,
int  amount 
)
void op_tilde ( oparg_T oap)
bool op_yank ( oparg_T oap,
bool  message,
int  deleting 
)

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.

Parameters
oapoperator arguments
messageshow message when more than &report lines are yanked.
deletingwhether the function was called from a delete operation.
Returns
whether the operation register was writable.
int paragraph_start ( linenr_T  lnum)
bool prepare_yankreg_from_object ( yankreg_T reg,
String  regtype,
size_t  lines 
)
Parameters
[out]regExpected to be empty
int preprocs_left ( void  )
void restore_batch_count ( int  save_count)
int save_batch_count ( void  )
void set_expr_line ( char_u new_line)
void shift_line ( int  left,
int  round,
int  amount,
int  call_changed_bytes 
)
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.
void start_batch_changes ( void  )

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

bool swapchar ( int  op_type,
pos_T pos 
)
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 ( )
void write_reg_contents ( int  name,
const char_u str,
ssize_t  len,
int  must_append 
)

write_reg_contents - store str in register name

See also
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 '', use linewise, otherwise use characterwise.

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
void write_reg_contents_lst ( int  name,
char_u **  strings,
bool  must_append,
MotionType  yank_type,
colnr_T  block_len 
)
bool yank_register_mline ( int  regname)

check if the current yank register has kMTLineWise register type

Variable Documentation

if* clipboard
Initial value:
=unnamed[plus]` is set.
*
* @param name The name of register
* name
Definition: ops.c:6026

Determine if register *name should be used as a clipboard. In an unnamed operation, *name is NUL and will be adjusted to

const void FUNC_ATTR_WARN_UNUSED_RESULT
Initial value:
{
return op_reg_iter(iter, y_regs, name, reg, is_unnamed)
* name
Definition: ops.c:6026
* is_unnamed
Definition: ops.c:6028
* reg
Definition: ops.c:6027
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
if or NUL if unnamed* param quiet Suppress error messages* param writing if we re setting the contents of the clipboard* * returns the yankreg that should be written into
* is_unnamed = (iter_reg == y_previous)
int iter_off = (int)(iter_reg - &(regs[0]))
const yankreg_T* iter_reg
Initial value:
= (iter == NULL
? &(regs[0])
: (const yankreg_T *const)iter)
return NULL
Definition: ops.c:6034
Definition of one register.
Definition: ops.h:82
* name = (char)get_register_name(iter_off)
return NULL
* reg = *iter_reg