Macros | Functions
autocmd.c File Reference
#include <signal.h>
#include "lauxlib.h"
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/autocmd.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/eval/userfunc.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
#include "nvim/getchar.h"
#include "nvim/lua/executor.h"
#include "nvim/map.h"
#include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/regexp.h"
#include "nvim/search.h"
#include "nvim/state.h"
#include "nvim/ui_compositor.h"
#include "nvim/vim.h"
#include "nvim/window.h"

Macros

#define FOR_ALL_AUPATS_IN_EVENT(event, ap)   for (AutoPat *ap = first_autopat[event]; ap != NULL; ap = ap->next)
 Iterates over all the AutoPats for a particular event. More...
 
#define PROTO   "term://"
 

Functions

void aupat_del_for_event_and_group (event_T event, int group)
 
AutoPatau_get_autopat_for_event (event_T event) FUNC_ATTR_PURE
 
void aubuflocal_remove (buf_T *buf)
 
int augroup_add (char *name)
 
void augroup_del (char *name, bool stupid_legacy_mode)
 
int augroup_find (const char *name) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
 
char * augroup_name (int group)
 Gets the name for a particular group. More...
 
bool augroup_exists (const char *name) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
 
void do_augroup (char *arg, int del_group)
 ":augroup {name}". More...
 
event_T event_name2nr (const char *start, char **end)
 
const char * event_nr2name (event_T event) FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_CONST
 
int check_ei (void)
 
char * au_event_disable (char *what)
 
void au_event_restore (char *old_ei)
 
void do_autocmd (char *arg_in, int forceit)
 
void do_all_autocmd_events (char *pat, bool once, int nested, char *cmd, bool delete, int group)
 
int do_autocmd_event (event_T event, char *pat, bool once, int nested, char *cmd, bool delete, int group) FUNC_ATTR_NONNULL_ALL
 
int autocmd_register (int64_t id, event_T event, char *pat, int patlen, int group, bool once, bool nested, char *desc, AucmdExecutable aucmd)
 
size_t aucmd_pattern_length (char *pat) FUNC_ATTR_PURE
 
char * aucmd_next_pattern (char *pat, size_t patlen) FUNC_ATTR_PURE
 
int do_doautocmd (char *arg_start, bool do_msg, bool *did_something)
 
void ex_doautoall (exarg_T *eap)
 
bool check_nomodeline (char **argp) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
 
void aucmd_prepbuf (aco_save_T *aco, buf_T *buf)
 
void aucmd_restbuf (aco_save_T *aco)
 
bool apply_autocmds (event_T event, char_u *fname, char_u *fname_io, bool force, buf_T *buf)
 
bool apply_autocmds_exarg (event_T event, char *fname, char *fname_io, bool force, buf_T *buf, exarg_T *eap)
 
bool apply_autocmds_retval (event_T event, char *fname, char *fname_io, bool force, buf_T *buf, int *retval)
 
bool has_event (event_T event) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
 
bool has_cursorhold (void)
 
bool trigger_cursorhold (void)
 Return true if the CursorHold/CursorHoldI event can be triggered. More...
 
bool apply_autocmds_group (event_T event, char *fname, char *fname_io, bool force, int group, buf_T *buf, exarg_T *eap)
 
void block_autocmds (void)
 
void unblock_autocmds (void)
 
bool is_autocmd_blocked (void)
 
void auto_next_pat (AutoPatCmd *apc, int stop_at_last)
 
char * getnextac (int c, void *cookie, int indent, bool do_concat)
 
bool has_autocmd (event_T event, char *sfname, buf_T *buf) FUNC_ATTR_WARN_UNUSED_RESULT
 
char * expand_get_augroup_name (expand_T *xp, int idx)
 
char * set_context_in_autocmd (expand_T *xp, char *arg, int doautocmd)
 
char * expand_get_event_name (expand_T *xp, int idx)
 
bool autocmd_supported (const char *const event) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
 
bool au_exists (const char *const arg) FUNC_ATTR_WARN_UNUSED_RESULT
 
bool aupat_is_buflocal (char *pat, int patlen) FUNC_ATTR_PURE
 
int aupat_get_buflocal_nr (char *pat, int patlen)
 
void aupat_normalize_buflocal_pat (char *dest, char *pat, int patlen, int buflocal_nr)
 
int autocmd_delete_event (int group, event_T event, char *pat) FUNC_ATTR_NONNULL_ALL
 
bool autocmd_delete_id (int64_t id)
 
char * aucmd_exec_default_desc (AucmdExecutable acc)
 
char * aucmd_exec_to_string (AutoCmd *ac, AucmdExecutable acc) FUNC_ATTR_PURE
 
void aucmd_exec_free (AucmdExecutable *acc)
 
AucmdExecutable aucmd_exec_copy (AucmdExecutable src)
 
bool aucmd_exec_is_deleted (AucmdExecutable acc) FUNC_ATTR_PURE
 
bool au_event_is_empty (event_T event) FUNC_ATTR_PURE
 
void do_autocmd_uienter (uint64_t chanid, bool attached)
 
void autocmd_schedule_focusgained (bool gained)
 
void init_default_autocmds (void)
 

Macro Definition Documentation

◆ FOR_ALL_AUPATS_IN_EVENT

#define FOR_ALL_AUPATS_IN_EVENT (   event,
  ap 
)    for (AutoPat *ap = first_autopat[event]; ap != NULL; ap = ap->next)

Iterates over all the AutoPats for a particular event.

◆ PROTO

#define PROTO   "term://"

Function Documentation

◆ apply_autocmds()

bool apply_autocmds ( event_T  event,
char_u fname,
char_u fname_io,
bool  force,
buf_T buf 
)

Execute autocommands for "event" and file name "fname".

Parameters
eventevent that occurred
fnamefilename, NULL or empty means use actual file name
fname_iofilename to use for <afile> on cmdline
forceWhen true, ignore autocmd_busy
bufBuffer for <abuf>
Returns
true if some commands were executed.

◆ apply_autocmds_exarg()

bool apply_autocmds_exarg ( event_T  event,
char *  fname,
char *  fname_io,
bool  force,
buf_T buf,
exarg_T eap 
)

Like apply_autocmds(), but with extra "eap" argument. This takes care of setting v:filearg.

Parameters
eventevent that occurred
fnameNULL or empty means use actual file name
fname_iofname to use for <afile> on cmdline
forceWhen true, ignore autocmd_busy
bufBuffer for <abuf>
exargEx command arguments
Returns
true if some commands were executed.

◆ apply_autocmds_group()

bool apply_autocmds_group ( event_T  event,
char *  fname,
char *  fname_io,
bool  force,
int  group,
buf_T buf,
exarg_T eap 
)

Execute autocommands for "event" and file name "fname".

Parameters
eventevent that occurred
fnamefilename, NULL or empty means use actual file name
fname_iofilename to use for <afile> on cmdline, NULL means use fname.
forceWhen true, ignore autocmd_busy
groupautocmd group ID or AUGROUP_ALL
bufBuffer for <abuf>
eapEx command arguments
Returns
true if some commands were executed.

◆ apply_autocmds_retval()

bool apply_autocmds_retval ( event_T  event,
char *  fname,
char *  fname_io,
bool  force,
buf_T buf,
int *  retval 
)

Like apply_autocmds(), but handles the caller's retval. If the script processing is being aborted or if retval is FAIL when inside a try conditional, no autocommands are executed. If otherwise the autocommands cause the script to be aborted, retval is set to FAIL.

Parameters
eventevent that occurred
fnameNULL or empty means use actual file name
fname_iofname to use for <afile> on cmdline
forceWhen true, ignore autocmd_busy
bufBuffer for <abuf>
[in,out]retvalcaller's retval
Returns
true if some autocommands were executed

◆ au_event_disable()

char* au_event_disable ( char *  what)

◆ au_event_is_empty()

bool au_event_is_empty ( event_T  event)

◆ au_event_restore()

void au_event_restore ( char *  old_ei)

◆ au_exists()

bool au_exists ( const char *const  arg)

Return true if an autocommand is defined for a group, event and pattern: The group can be omitted to accept any group. event and pattern can be omitted to accept any event and pattern. Buffer-local patterns <buffer> or <buffer=N> are accepted. Used for: exists("#Group") or exists("#Group#Event") or exists("#Group#Event#pat") or exists("#Event") or exists("#Event#pat")

Parameters
argautocommand string

◆ au_get_autopat_for_event()

AutoPat* au_get_autopat_for_event ( event_T  event)

◆ aubuflocal_remove()

void aubuflocal_remove ( buf_T buf)

◆ aucmd_exec_copy()

AucmdExecutable aucmd_exec_copy ( AucmdExecutable  src)

◆ aucmd_exec_default_desc()

char* aucmd_exec_default_desc ( AucmdExecutable  acc)

◆ aucmd_exec_free()

void aucmd_exec_free ( AucmdExecutable acc)

◆ aucmd_exec_is_deleted()

bool aucmd_exec_is_deleted ( AucmdExecutable  acc)

◆ aucmd_exec_to_string()

char* aucmd_exec_to_string ( AutoCmd ac,
AucmdExecutable  acc 
)

◆ aucmd_next_pattern()

char* aucmd_next_pattern ( char *  pat,
size_t  patlen 
)

◆ aucmd_pattern_length()

size_t aucmd_pattern_length ( char *  pat)

◆ aucmd_prepbuf()

void aucmd_prepbuf ( aco_save_T aco,
buf_T buf 
)

Prepare for executing autocommands for (hidden) buffer buf. If the current buffer is not in any visible window, put it in a temporary floating window aucmd_win. Set curbuf and curwin to match buf.

Parameters
acostructure to save values in
bufnew curbuf

◆ aucmd_restbuf()

void aucmd_restbuf ( aco_save_T aco)

Cleanup after executing autocommands for a (hidden) buffer. Restore the window as it was (if possible).

Parameters
acostructure holding saved values

◆ augroup_add()

int augroup_add ( char *  name)

◆ augroup_del()

void augroup_del ( char *  name,
bool  stupid_legacy_mode 
)

Delete the augroup that matches name.

Parameters
stupid_legacy_modebool: This parameter determines whether to run the augroup deletion in the same fashion as :augroup! {name} where if there are any remaining autocmds left in the augroup, it will change the name of the augroup to --- DELETED --- but leave the autocmds existing. These are separate augroups, so if you do this for multiple augroups, you will have a bunch of --- DELETED --- augroups at the same time. There is no way, as far as I could tell, how to actually delete them at this point as a user

I did not consider this good behavior, so now when NOT in stupid_legacy_mode, we actually delete these groups and their commands, like you would expect (and don't leave hanging --- DELETED --- groups around)

◆ augroup_exists()

bool augroup_exists ( const char *  name)

Return true if augroup "name" exists.

Parameters
nameaugroup name

◆ augroup_find()

int augroup_find ( const char *  name)

Find the ID of an autocmd group name.

Parameters
nameaugroup name
Returns
the ID or AUGROUP_ERROR (< 0) for error.

◆ augroup_name()

char* augroup_name ( int  group)

Gets the name for a particular group.

◆ aupat_del_for_event_and_group()

void aupat_del_for_event_and_group ( event_T  event,
int  group 
)

◆ aupat_get_buflocal_nr()

int aupat_get_buflocal_nr ( char *  pat,
int  patlen 
)

◆ aupat_is_buflocal()

bool aupat_is_buflocal ( char *  pat,
int  patlen 
)

◆ aupat_normalize_buflocal_pat()

void aupat_normalize_buflocal_pat ( char *  dest,
char *  pat,
int  patlen,
int  buflocal_nr 
)

◆ auto_next_pat()

void auto_next_pat ( AutoPatCmd apc,
int  stop_at_last 
)

Find next autocommand pattern that matches. stop when 'last' flag is set

◆ autocmd_delete_event()

int autocmd_delete_event ( int  group,
event_T  event,
char *  pat 
)

◆ autocmd_delete_id()

bool autocmd_delete_id ( int64_t  id)

Deletes an autocmd by ID. Only autocmds created via the API have IDs associated with them. There is no way to delete a specific autocmd created via :autocmd

◆ autocmd_register()

int autocmd_register ( int64_t  id,
event_T  event,
char *  pat,
int  patlen,
int  group,
bool  once,
bool  nested,
char *  desc,
AucmdExecutable  aucmd 
)

◆ autocmd_schedule_focusgained()

void autocmd_schedule_focusgained ( bool  gained)

◆ autocmd_supported()

bool autocmd_supported ( const char *const  event)

Check whether given autocommand is supported

Parameters
[in]eventEvent to check.
Returns
True if it is, false otherwise.

◆ block_autocmds()

void block_autocmds ( void  )

◆ check_ei()

int check_ei ( void  )

◆ check_nomodeline()

bool check_nomodeline ( char **  argp)

Check *argp for <nomodeline>. When it is present return false, otherwise return true and advance *argp to after it. Thus do_modelines() should be called when true is returned.

Parameters
[in,out]argpargument string

◆ do_all_autocmd_events()

void do_all_autocmd_events ( char *  pat,
bool  once,
int  nested,
char *  cmd,
bool  delete,
int  group 
)

◆ do_augroup()

void do_augroup ( char *  arg,
int  del_group 
)

":augroup {name}".

◆ do_autocmd()

void do_autocmd ( char *  arg_in,
int  forceit 
)

◆ do_autocmd_event()

int do_autocmd_event ( event_T  event,
char *  pat,
bool  once,
int  nested,
char *  cmd,
bool  delete,
int  group 
)

◆ do_autocmd_uienter()

void do_autocmd_uienter ( uint64_t  chanid,
bool  attached 
)

◆ do_doautocmd()

int do_doautocmd ( char *  arg_start,
bool  do_msg,
bool did_something 
)

Implementation of ":doautocmd [group] event [fname]". Return OK for success, FAIL for failure;

Parameters
do_msggive message for no matching autocmds?

◆ event_name2nr()

event_T event_name2nr ( const char *  start,
char **  end 
)

◆ event_nr2name()

const char* event_nr2name ( event_T  event)

Return the name for event

Parameters
[in]eventEvent to return name for.
Returns
Event name, static string. Returns "Unknown" for unknown events.

◆ ex_doautoall()

void ex_doautoall ( exarg_T eap)

◆ expand_get_augroup_name()

char* expand_get_augroup_name ( expand_T xp,
int  idx 
)

◆ expand_get_event_name()

char* expand_get_event_name ( expand_T xp,
int  idx 
)

◆ getnextac()

char* getnextac ( int  c,
void cookie,
int  indent,
bool  do_concat 
)

Get next autocommand command. Called by do_cmdline() to get the next line for ":if".

Returns
allocated string, or NULL for end of autocommands.

◆ has_autocmd()

bool has_autocmd ( event_T  event,
char *  sfname,
buf_T buf 
)

Return true if there is a matching autocommand for "fname". To account for buffer-local autocommands, function needs to know in which buffer the file will be opened.

Parameters
eventevent that occurred.
sfnamefilename the event occurred in.
bufbuffer the file is open in

◆ has_cursorhold()

bool has_cursorhold ( void  )

Return true when there is a CursorHold/CursorHoldI autocommand defined for the current mode.

◆ has_event()

bool has_event ( event_T  event)

Return true if "event" autocommand is defined.

Parameters
eventthe autocommand to check

◆ init_default_autocmds()

void init_default_autocmds ( void  )

◆ is_autocmd_blocked()

bool is_autocmd_blocked ( void  )

◆ set_context_in_autocmd()

char* set_context_in_autocmd ( expand_T xp,
char *  arg,
int  doautocmd 
)
Parameters
doautocmdtrue for :doauto*, false for :autocmd

◆ trigger_cursorhold()

bool trigger_cursorhold ( void  )

Return true if the CursorHold/CursorHoldI event can be triggered.

◆ unblock_autocmds()

void unblock_autocmds ( void  )