mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #16597 from bfredl/nomisc1
refactor: move out some long-hanging fruit from misc1.c
This commit is contained in:
commit
26eb605152
@ -17,6 +17,7 @@
|
|||||||
#include "nvim/getchar.h"
|
#include "nvim/getchar.h"
|
||||||
#include "nvim/misc1.h"
|
#include "nvim/misc1.h"
|
||||||
#include "nvim/option.h"
|
#include "nvim/option.h"
|
||||||
|
#include "nvim/os/input.h"
|
||||||
#include "nvim/regexp.h"
|
#include "nvim/regexp.h"
|
||||||
#include "nvim/search.h"
|
#include "nvim/search.h"
|
||||||
#include "nvim/state.h"
|
#include "nvim/state.h"
|
||||||
|
@ -2719,7 +2719,7 @@ void buflist_list(exarg_T *eap)
|
|||||||
IObuff[len++] = ' ';
|
IObuff[len++] = ' ';
|
||||||
} while (--i > 0 && len < IOSIZE - 18);
|
} while (--i > 0 && len < IOSIZE - 18);
|
||||||
if (vim_strchr(eap->arg, 't') && buf->b_last_used) {
|
if (vim_strchr(eap->arg, 't') && buf->b_last_used) {
|
||||||
add_time(IObuff + len, (size_t)(IOSIZE - len), buf->b_last_used);
|
undo_fmt_time(IObuff + len, (size_t)(IOSIZE - len), buf->b_last_used);
|
||||||
} else {
|
} else {
|
||||||
vim_snprintf((char *)IObuff + len, (size_t)(IOSIZE - len),
|
vim_snprintf((char *)IObuff + len, (size_t)(IOSIZE - len),
|
||||||
_("line %" PRId64),
|
_("line %" PRId64),
|
||||||
|
@ -1116,12 +1116,6 @@ typedef struct {
|
|||||||
pos_T w_cursor_corr; // corrected cursor position
|
pos_T w_cursor_corr; // corrected cursor position
|
||||||
} pos_save_T;
|
} pos_save_T;
|
||||||
|
|
||||||
// Struct passed to get_v_event() and restore_v_event().
|
|
||||||
typedef struct {
|
|
||||||
bool sve_did_save;
|
|
||||||
hashtab_T sve_hashtab;
|
|
||||||
} save_v_event_T;
|
|
||||||
|
|
||||||
/// Indices into vimmenu_T->strings[] and vimmenu_T->noremap[] for each mode
|
/// Indices into vimmenu_T->strings[] and vimmenu_T->noremap[] for each mode
|
||||||
/// \addtogroup MENU_INDEX
|
/// \addtogroup MENU_INDEX
|
||||||
/// @{
|
/// @{
|
||||||
|
@ -131,7 +131,7 @@ void changed_internal(void)
|
|||||||
curbuf->b_changed = true;
|
curbuf->b_changed = true;
|
||||||
curbuf->b_changed_invalid = true;
|
curbuf->b_changed_invalid = true;
|
||||||
ml_setflags(curbuf);
|
ml_setflags(curbuf);
|
||||||
check_status(curbuf);
|
redraw_buf_status_later(curbuf);
|
||||||
redraw_tabline = true;
|
redraw_tabline = true;
|
||||||
need_maketitle = true; // set window title later
|
need_maketitle = true; // set window title later
|
||||||
}
|
}
|
||||||
@ -517,7 +517,7 @@ void unchanged(buf_T *buf, int ff, bool always_inc_changedtick)
|
|||||||
if (ff) {
|
if (ff) {
|
||||||
save_file_ff(buf);
|
save_file_ff(buf);
|
||||||
}
|
}
|
||||||
check_status(buf);
|
redraw_buf_status_later(buf);
|
||||||
redraw_tabline = true;
|
redraw_tabline = true;
|
||||||
need_maketitle = true; // set window title later
|
need_maketitle = true; // set window title later
|
||||||
buf_inc_changedtick(buf);
|
buf_inc_changedtick(buf);
|
||||||
|
@ -4,6 +4,13 @@
|
|||||||
#include "nvim/buffer_defs.h" // for buf_T
|
#include "nvim/buffer_defs.h" // for buf_T
|
||||||
#include "nvim/pos.h" // for linenr_T
|
#include "nvim/pos.h" // for linenr_T
|
||||||
|
|
||||||
|
// flags for open_line()
|
||||||
|
#define OPENLINE_DELSPACES 1 // delete spaces after cursor
|
||||||
|
#define OPENLINE_DO_COM 2 // format comments
|
||||||
|
#define OPENLINE_KEEPTRAIL 4 // keep trailing spaces
|
||||||
|
#define OPENLINE_MARKFIX 8 // fix mark positions
|
||||||
|
#define OPENLINE_COM_LIST 16 // format comments with list/2nd line indent
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "change.h.generated.h"
|
# include "change.h.generated.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -303,6 +303,31 @@ const list_T *eval_msgpack_type_lists[] = {
|
|||||||
[kMPExt] = NULL,
|
[kMPExt] = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dict_T *get_v_event(save_v_event_T *sve)
|
||||||
|
{
|
||||||
|
dict_T *v_event = get_vim_var_dict(VV_EVENT);
|
||||||
|
|
||||||
|
if (v_event->dv_hashtab.ht_used > 0) {
|
||||||
|
// recursive use of v:event, save, make empty and restore later
|
||||||
|
sve->sve_did_save = true;
|
||||||
|
sve->sve_hashtab = v_event->dv_hashtab;
|
||||||
|
hash_init(&v_event->dv_hashtab);
|
||||||
|
} else {
|
||||||
|
sve->sve_did_save = false;
|
||||||
|
}
|
||||||
|
return v_event;
|
||||||
|
}
|
||||||
|
|
||||||
|
void restore_v_event(dict_T *v_event, save_v_event_T *sve)
|
||||||
|
{
|
||||||
|
tv_dict_free_contents(v_event);
|
||||||
|
if (sve->sve_did_save) {
|
||||||
|
v_event->dv_hashtab = sve->sve_hashtab;
|
||||||
|
} else {
|
||||||
|
hash_init(&v_event->dv_hashtab);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Return "n1" divided by "n2", taking care of dividing by zero.
|
// Return "n1" divided by "n2", taking care of dividing by zero.
|
||||||
varnumber_T num_divide(varnumber_T n1, varnumber_T n2)
|
varnumber_T num_divide(varnumber_T n1, varnumber_T n2)
|
||||||
FUNC_ATTR_CONST FUNC_ATTR_WARN_UNUSED_RESULT
|
FUNC_ATTR_CONST FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
|
@ -193,6 +193,13 @@ extern const list_T *eval_msgpack_type_lists[LAST_MSGPACK_TYPE + 1];
|
|||||||
|
|
||||||
#undef LAST_MSGPACK_TYPE
|
#undef LAST_MSGPACK_TYPE
|
||||||
|
|
||||||
|
// Struct passed to get_v_event() and restore_v_event().
|
||||||
|
typedef struct {
|
||||||
|
bool sve_did_save;
|
||||||
|
hashtab_T sve_hashtab;
|
||||||
|
} save_v_event_T;
|
||||||
|
|
||||||
|
|
||||||
/// trans_function_name() flags
|
/// trans_function_name() flags
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TFN_INT = 1, ///< May use internal function name
|
TFN_INT = 1, ///< May use internal function name
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "nvim/mbyte.h"
|
#include "nvim/mbyte.h"
|
||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
#include "nvim/message.h"
|
#include "nvim/message.h"
|
||||||
|
#include "nvim/os/input.h"
|
||||||
#include "nvim/pos.h"
|
#include "nvim/pos.h"
|
||||||
#include "nvim/types.h"
|
#include "nvim/types.h"
|
||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "nvim/event/rstream.h"
|
#include "nvim/event/rstream.h"
|
||||||
#include "nvim/log.h"
|
#include "nvim/log.h"
|
||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
|
#include "nvim/main.h"
|
||||||
#include "nvim/misc1.h"
|
#include "nvim/misc1.h"
|
||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include "nvim/ops.h"
|
#include "nvim/ops.h"
|
||||||
#include "nvim/option.h"
|
#include "nvim/option.h"
|
||||||
#include "nvim/os/fs_defs.h"
|
#include "nvim/os/fs_defs.h"
|
||||||
|
#include "nvim/os/input.h"
|
||||||
#include "nvim/os/shell.h"
|
#include "nvim/os/shell.h"
|
||||||
#include "nvim/os_unix.h"
|
#include "nvim/os_unix.h"
|
||||||
#include "nvim/path.h"
|
#include "nvim/path.h"
|
||||||
|
@ -68,6 +68,7 @@
|
|||||||
#include "nvim/spell.h"
|
#include "nvim/spell.h"
|
||||||
#include "nvim/spellfile.h"
|
#include "nvim/spellfile.h"
|
||||||
#include "nvim/strings.h"
|
#include "nvim/strings.h"
|
||||||
|
#include "nvim/state.h"
|
||||||
#include "nvim/syntax.h"
|
#include "nvim/syntax.h"
|
||||||
#include "nvim/tag.h"
|
#include "nvim/tag.h"
|
||||||
#include "nvim/terminal.h"
|
#include "nvim/terminal.h"
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "nvim/move.h"
|
#include "nvim/move.h"
|
||||||
#include "nvim/ops.h"
|
#include "nvim/ops.h"
|
||||||
#include "nvim/option.h"
|
#include "nvim/option.h"
|
||||||
|
#include "nvim/os/input.h"
|
||||||
#include "nvim/plines.h"
|
#include "nvim/plines.h"
|
||||||
#include "nvim/screen.h"
|
#include "nvim/screen.h"
|
||||||
#include "nvim/strings.h"
|
#include "nvim/strings.h"
|
||||||
|
@ -696,6 +696,50 @@ void getout(int exitval)
|
|||||||
os_exit(exitval);
|
os_exit(exitval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Preserve files and exit.
|
||||||
|
/// @note IObuff must contain a message.
|
||||||
|
/// @note This may be called from deadly_signal() in a signal handler, avoid
|
||||||
|
/// unsafe functions, such as allocating memory.
|
||||||
|
void preserve_exit(void)
|
||||||
|
FUNC_ATTR_NORETURN
|
||||||
|
{
|
||||||
|
// 'true' when we are sure to exit, e.g., after a deadly signal
|
||||||
|
static bool really_exiting = false;
|
||||||
|
|
||||||
|
// Prevent repeated calls into this method.
|
||||||
|
if (really_exiting) {
|
||||||
|
if (input_global_fd() >= 0) {
|
||||||
|
// normalize stream (#2598)
|
||||||
|
stream_set_blocking(input_global_fd(), true);
|
||||||
|
}
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
really_exiting = true;
|
||||||
|
// Ignore SIGHUP while we are already exiting. #9274
|
||||||
|
signal_reject_deadly();
|
||||||
|
mch_errmsg(IObuff);
|
||||||
|
mch_errmsg("\n");
|
||||||
|
ui_flush();
|
||||||
|
|
||||||
|
ml_close_notmod(); // close all not-modified buffers
|
||||||
|
|
||||||
|
FOR_ALL_BUFFERS(buf) {
|
||||||
|
if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL) {
|
||||||
|
mch_errmsg("Vim: preserving files...\r\n");
|
||||||
|
ui_flush();
|
||||||
|
ml_sync_all(false, false, true); // preserve all swap files
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ml_close_all(false); // close all memfiles, without deleting
|
||||||
|
|
||||||
|
mch_errmsg("Vim: Finished.\r\n");
|
||||||
|
|
||||||
|
getout(1);
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets the integer value of a numeric command line argument if given,
|
/// Gets the integer value of a numeric command line argument if given,
|
||||||
/// such as '-o10'.
|
/// such as '-o10'.
|
||||||
///
|
///
|
||||||
|
@ -1841,6 +1841,17 @@ char_u *ml_get_pos(const pos_T *pos)
|
|||||||
return ml_get_buf(curbuf, pos->lnum, false) + pos->col;
|
return ml_get_buf(curbuf, pos->lnum, false) + pos->col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// get codepoint at pos. pos must be either valid or have col set to MAXCOL!
|
||||||
|
int gchar_pos(pos_T *pos)
|
||||||
|
FUNC_ATTR_NONNULL_ARG(1)
|
||||||
|
{
|
||||||
|
// When searching columns is sometimes put at the end of a line.
|
||||||
|
if (pos->col == MAXCOL) {
|
||||||
|
return NUL;
|
||||||
|
}
|
||||||
|
return utf_ptr2char(ml_get_pos(pos));
|
||||||
|
}
|
||||||
|
|
||||||
/// Return a pointer to a line in a specific buffer
|
/// Return a pointer to a line in a specific buffer
|
||||||
///
|
///
|
||||||
/// @param will_change true mark the buffer dirty (chars in the line will be changed)
|
/// @param will_change true mark the buffer dirty (chars in the line will be changed)
|
||||||
|
204
src/nvim/misc1.c
204
src/nvim/misc1.c
@ -373,32 +373,6 @@ int get_last_leader_offset(char_u *line, char_u **flags)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gchar_pos(pos_T *pos)
|
|
||||||
FUNC_ATTR_NONNULL_ARG(1)
|
|
||||||
{
|
|
||||||
// When searching columns is sometimes put at the end of a line.
|
|
||||||
if (pos->col == MAXCOL) {
|
|
||||||
return NUL;
|
|
||||||
}
|
|
||||||
return utf_ptr2char(ml_get_pos(pos));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* check_status: called when the status bars for the buffer 'buf'
|
|
||||||
* need to be updated
|
|
||||||
*/
|
|
||||||
void check_status(buf_T *buf)
|
|
||||||
{
|
|
||||||
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
|
|
||||||
if (wp->w_buffer == buf && wp->w_status_height) {
|
|
||||||
wp->w_redr_status = TRUE;
|
|
||||||
if (must_redraw < VALID) {
|
|
||||||
must_redraw = VALID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ask for a reply from the user, 'y' or 'n'
|
/// Ask for a reply from the user, 'y' or 'n'
|
||||||
///
|
///
|
||||||
/// No other characters are accepted, the message is repeated until a valid
|
/// No other characters are accepted, the message is repeated until a valid
|
||||||
@ -814,91 +788,6 @@ int match_user(char_u *name)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Preserve files and exit.
|
|
||||||
/// @note IObuff must contain a message.
|
|
||||||
/// @note This may be called from deadly_signal() in a signal handler, avoid
|
|
||||||
/// unsafe functions, such as allocating memory.
|
|
||||||
void preserve_exit(void)
|
|
||||||
FUNC_ATTR_NORETURN
|
|
||||||
{
|
|
||||||
// 'true' when we are sure to exit, e.g., after a deadly signal
|
|
||||||
static bool really_exiting = false;
|
|
||||||
|
|
||||||
// Prevent repeated calls into this method.
|
|
||||||
if (really_exiting) {
|
|
||||||
if (input_global_fd() >= 0) {
|
|
||||||
// normalize stream (#2598)
|
|
||||||
stream_set_blocking(input_global_fd(), true);
|
|
||||||
}
|
|
||||||
exit(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
really_exiting = true;
|
|
||||||
// Ignore SIGHUP while we are already exiting. #9274
|
|
||||||
signal_reject_deadly();
|
|
||||||
mch_errmsg(IObuff);
|
|
||||||
mch_errmsg("\n");
|
|
||||||
ui_flush();
|
|
||||||
|
|
||||||
ml_close_notmod(); // close all not-modified buffers
|
|
||||||
|
|
||||||
FOR_ALL_BUFFERS(buf) {
|
|
||||||
if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL) {
|
|
||||||
mch_errmsg("Vim: preserving files...\r\n");
|
|
||||||
ui_flush();
|
|
||||||
ml_sync_all(false, false, true); // preserve all swap files
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ml_close_all(false); // close all memfiles, without deleting
|
|
||||||
|
|
||||||
mch_errmsg("Vim: Finished.\r\n");
|
|
||||||
|
|
||||||
getout(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check for CTRL-C pressed, but only once in a while.
|
|
||||||
* Should be used instead of os_breakcheck() for functions that check for
|
|
||||||
* each line in the file. Calling os_breakcheck() each time takes too much
|
|
||||||
* time, because it can be a system call.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BREAKCHECK_SKIP
|
|
||||||
# define BREAKCHECK_SKIP 1000
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int breakcheck_count = 0;
|
|
||||||
|
|
||||||
void line_breakcheck(void)
|
|
||||||
{
|
|
||||||
if (++breakcheck_count >= BREAKCHECK_SKIP) {
|
|
||||||
breakcheck_count = 0;
|
|
||||||
os_breakcheck();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Like line_breakcheck() but check 10 times less often.
|
|
||||||
*/
|
|
||||||
void fast_breakcheck(void)
|
|
||||||
{
|
|
||||||
if (++breakcheck_count >= BREAKCHECK_SKIP * 10) {
|
|
||||||
breakcheck_count = 0;
|
|
||||||
os_breakcheck();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Like line_breakcheck() but check 100 times less often.
|
|
||||||
void veryfast_breakcheck(void)
|
|
||||||
{
|
|
||||||
if (++breakcheck_count >= BREAKCHECK_SKIP * 100) {
|
|
||||||
breakcheck_count = 0;
|
|
||||||
os_breakcheck();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// os_call_shell() wrapper. Handles 'verbose', :profile, and v:shell_error.
|
/// os_call_shell() wrapper. Handles 'verbose', :profile, and v:shell_error.
|
||||||
/// Invalidates cached tags.
|
/// Invalidates cached tags.
|
||||||
///
|
///
|
||||||
@ -1012,21 +901,6 @@ done:
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Free the list of files returned by expand_wildcards() or other expansion
|
|
||||||
* functions.
|
|
||||||
*/
|
|
||||||
void FreeWild(int count, char_u **files)
|
|
||||||
{
|
|
||||||
if (count <= 0 || files == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
while (count--) {
|
|
||||||
xfree(files[count]);
|
|
||||||
}
|
|
||||||
xfree(files);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return TRUE when need to go to Insert mode because of 'insertmode'.
|
* Return TRUE when need to go to Insert mode because of 'insertmode'.
|
||||||
* Don't do this when still processing a command or a mapping.
|
* Don't do this when still processing a command or a mapping.
|
||||||
@ -1036,81 +910,3 @@ int goto_im(void)
|
|||||||
{
|
{
|
||||||
return p_im && stuff_empty() && typebuf_typed();
|
return p_im && stuff_empty() && typebuf_typed();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Put the timestamp of an undo header in "buf[buflen]" in a nice format.
|
|
||||||
void add_time(char_u *buf, size_t buflen, time_t tt)
|
|
||||||
{
|
|
||||||
struct tm curtime;
|
|
||||||
|
|
||||||
if (time(NULL) - tt >= 100) {
|
|
||||||
os_localtime_r(&tt, &curtime);
|
|
||||||
if (time(NULL) - tt < (60L * 60L * 12L)) {
|
|
||||||
// within 12 hours
|
|
||||||
(void)strftime((char *)buf, buflen, "%H:%M:%S", &curtime);
|
|
||||||
} else {
|
|
||||||
// longer ago
|
|
||||||
(void)strftime((char *)buf, buflen, "%Y/%m/%d %H:%M:%S", &curtime);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
int64_t seconds = time(NULL) - tt;
|
|
||||||
vim_snprintf((char *)buf, buflen,
|
|
||||||
NGETTEXT("%" PRId64 " second ago",
|
|
||||||
"%" PRId64 " seconds ago", (uint32_t)seconds),
|
|
||||||
seconds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dict_T *get_v_event(save_v_event_T *sve)
|
|
||||||
{
|
|
||||||
dict_T *v_event = get_vim_var_dict(VV_EVENT);
|
|
||||||
|
|
||||||
if (v_event->dv_hashtab.ht_used > 0) {
|
|
||||||
// recursive use of v:event, save, make empty and restore later
|
|
||||||
sve->sve_did_save = true;
|
|
||||||
sve->sve_hashtab = v_event->dv_hashtab;
|
|
||||||
hash_init(&v_event->dv_hashtab);
|
|
||||||
} else {
|
|
||||||
sve->sve_did_save = false;
|
|
||||||
}
|
|
||||||
return v_event;
|
|
||||||
}
|
|
||||||
|
|
||||||
void restore_v_event(dict_T *v_event, save_v_event_T *sve)
|
|
||||||
{
|
|
||||||
tv_dict_free_contents(v_event);
|
|
||||||
if (sve->sve_did_save) {
|
|
||||||
v_event->dv_hashtab = sve->sve_hashtab;
|
|
||||||
} else {
|
|
||||||
hash_init(&v_event->dv_hashtab);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fires a ModeChanged autocmd.
|
|
||||||
void trigger_modechanged(void)
|
|
||||||
{
|
|
||||||
if (!has_event(EVENT_MODECHANGED)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *mode = get_mode();
|
|
||||||
if (STRCMP(mode, last_mode) == 0) {
|
|
||||||
xfree(mode);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
save_v_event_T save_v_event;
|
|
||||||
dict_T *v_event = get_v_event(&save_v_event);
|
|
||||||
tv_dict_add_str(v_event, S_LEN("new_mode"), mode);
|
|
||||||
tv_dict_add_str(v_event, S_LEN("old_mode"), last_mode);
|
|
||||||
|
|
||||||
char_u *pat_pre = concat_str((char_u *)last_mode, (char_u *)":");
|
|
||||||
char_u *pat = concat_str(pat_pre, (char_u *)mode);
|
|
||||||
xfree(pat_pre);
|
|
||||||
|
|
||||||
apply_autocmds(EVENT_MODECHANGED, pat, NULL, false, curbuf);
|
|
||||||
xfree(last_mode);
|
|
||||||
last_mode = mode;
|
|
||||||
|
|
||||||
xfree(pat);
|
|
||||||
restore_v_event(v_event, &save_v_event);
|
|
||||||
}
|
|
||||||
|
@ -4,13 +4,6 @@
|
|||||||
#include "nvim/os/shell.h"
|
#include "nvim/os/shell.h"
|
||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
|
|
||||||
// flags for open_line()
|
|
||||||
#define OPENLINE_DELSPACES 1 // delete spaces after cursor
|
|
||||||
#define OPENLINE_DO_COM 2 // format comments
|
|
||||||
#define OPENLINE_KEEPTRAIL 4 // keep trailing spaces
|
|
||||||
#define OPENLINE_MARKFIX 8 // fix mark positions
|
|
||||||
#define OPENLINE_COM_LIST 16 // format comments with list/2nd line indent
|
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "misc1.h.generated.h"
|
# include "misc1.h.generated.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -7899,7 +7899,7 @@ void set_fileformat(int eol_style, int opt_flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This may cause the buffer to become (un)modified.
|
// This may cause the buffer to become (un)modified.
|
||||||
check_status(curbuf);
|
redraw_buf_status_later(curbuf);
|
||||||
redraw_tabline = true;
|
redraw_tabline = true;
|
||||||
need_maketitle = true; // Set window title later.
|
need_maketitle = true; // Set window title later.
|
||||||
}
|
}
|
||||||
|
@ -183,6 +183,40 @@ void os_breakcheck(void)
|
|||||||
updating_screen = save_us;
|
updating_screen = save_us;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define BREAKCHECK_SKIP 1000
|
||||||
|
static int breakcheck_count = 0;
|
||||||
|
|
||||||
|
/// Check for CTRL-C pressed, but only once in a while.
|
||||||
|
///
|
||||||
|
/// Should be used instead of os_breakcheck() for functions that check for
|
||||||
|
/// each line in the file. Calling os_breakcheck() each time takes too much
|
||||||
|
/// time, because it will use system calls to check for input.
|
||||||
|
void line_breakcheck(void)
|
||||||
|
{
|
||||||
|
if (++breakcheck_count >= BREAKCHECK_SKIP) {
|
||||||
|
breakcheck_count = 0;
|
||||||
|
os_breakcheck();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Like line_breakcheck() but check 10 times less often.
|
||||||
|
void fast_breakcheck(void)
|
||||||
|
{
|
||||||
|
if (++breakcheck_count >= BREAKCHECK_SKIP * 10) {
|
||||||
|
breakcheck_count = 0;
|
||||||
|
os_breakcheck();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Like line_breakcheck() but check 100 times less often.
|
||||||
|
void veryfast_breakcheck(void)
|
||||||
|
{
|
||||||
|
if (++breakcheck_count >= BREAKCHECK_SKIP * 100) {
|
||||||
|
breakcheck_count = 0;
|
||||||
|
os_breakcheck();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Test whether a file descriptor refers to a terminal.
|
/// Test whether a file descriptor refers to a terminal.
|
||||||
///
|
///
|
||||||
|
@ -1337,6 +1337,17 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***fil
|
|||||||
return ((flags & EW_EMPTYOK) || ga.ga_data != NULL) ? OK : FAIL;
|
return ((flags & EW_EMPTYOK) || ga.ga_data != NULL) ? OK : FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Free the list of files returned by expand_wildcards() or other expansion functions.
|
||||||
|
void FreeWild(int count, char_u **files)
|
||||||
|
{
|
||||||
|
if (count <= 0 || files == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while (count--) {
|
||||||
|
xfree(files[count]);
|
||||||
|
}
|
||||||
|
xfree(files);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return TRUE if we can expand this backtick thing here.
|
* Return TRUE if we can expand this backtick thing here.
|
||||||
|
@ -65,6 +65,7 @@
|
|||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
#include "nvim/message.h"
|
#include "nvim/message.h"
|
||||||
#include "nvim/misc1.h"
|
#include "nvim/misc1.h"
|
||||||
|
#include "nvim/os/input.h"
|
||||||
#include "nvim/plines.h"
|
#include "nvim/plines.h"
|
||||||
#include "nvim/garray.h"
|
#include "nvim/garray.h"
|
||||||
#include "nvim/strings.h"
|
#include "nvim/strings.h"
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "nvim/ascii.h"
|
#include "nvim/ascii.h"
|
||||||
#include "nvim/garray.h"
|
#include "nvim/garray.h"
|
||||||
|
#include "nvim/os/input.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Logging of NFA engine.
|
* Logging of NFA engine.
|
||||||
|
@ -314,6 +314,19 @@ void update_curbuf(int type)
|
|||||||
update_screen(type);
|
update_screen(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// called when the status bars for the buffer 'buf' need to be updated
|
||||||
|
void redraw_buf_status_later(buf_T *buf)
|
||||||
|
{
|
||||||
|
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
|
||||||
|
if (wp->w_buffer == buf && wp->w_status_height) {
|
||||||
|
wp->w_redr_status = true;
|
||||||
|
if (must_redraw < VALID) {
|
||||||
|
must_redraw = VALID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Redraw the parts of the screen that is marked for redraw.
|
/// Redraw the parts of the screen that is marked for redraw.
|
||||||
///
|
///
|
||||||
/// Most code shouldn't call this directly, rather use redraw_later() and
|
/// Most code shouldn't call this directly, rather use redraw_later() and
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "nvim/move.h"
|
#include "nvim/move.h"
|
||||||
#include "nvim/normal.h"
|
#include "nvim/normal.h"
|
||||||
#include "nvim/option.h"
|
#include "nvim/option.h"
|
||||||
|
#include "nvim/os/input.h"
|
||||||
#include "nvim/os/time.h"
|
#include "nvim/os/time.h"
|
||||||
#include "nvim/path.h"
|
#include "nvim/path.h"
|
||||||
#include "nvim/regexp.h"
|
#include "nvim/regexp.h"
|
||||||
|
@ -239,6 +239,7 @@
|
|||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
#include "nvim/misc1.h"
|
#include "nvim/misc1.h"
|
||||||
#include "nvim/option.h"
|
#include "nvim/option.h"
|
||||||
|
#include "nvim/os/input.h"
|
||||||
#include "nvim/os/os.h"
|
#include "nvim/os/os.h"
|
||||||
#include "nvim/path.h"
|
#include "nvim/path.h"
|
||||||
#include "nvim/regexp.h"
|
#include "nvim/regexp.h"
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "nvim/ascii.h"
|
#include "nvim/ascii.h"
|
||||||
|
#include "nvim/autocmd.h"
|
||||||
#include "nvim/edit.h"
|
#include "nvim/edit.h"
|
||||||
|
#include "nvim/eval.h"
|
||||||
#include "nvim/ex_docmd.h"
|
#include "nvim/ex_docmd.h"
|
||||||
#include "nvim/getchar.h"
|
#include "nvim/getchar.h"
|
||||||
#include "nvim/lib/kvec.h"
|
#include "nvim/lib/kvec.h"
|
||||||
@ -202,3 +204,33 @@ char *get_mode(void)
|
|||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Fires a ModeChanged autocmd.
|
||||||
|
void trigger_modechanged(void)
|
||||||
|
{
|
||||||
|
if (!has_event(EVENT_MODECHANGED)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *mode = get_mode();
|
||||||
|
if (STRCMP(mode, last_mode) == 0) {
|
||||||
|
xfree(mode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
save_v_event_T save_v_event;
|
||||||
|
dict_T *v_event = get_v_event(&save_v_event);
|
||||||
|
tv_dict_add_str(v_event, S_LEN("new_mode"), mode);
|
||||||
|
tv_dict_add_str(v_event, S_LEN("old_mode"), last_mode);
|
||||||
|
|
||||||
|
char_u *pat_pre = concat_str((char_u *)last_mode, (char_u *)":");
|
||||||
|
char_u *pat = concat_str(pat_pre, (char_u *)mode);
|
||||||
|
xfree(pat_pre);
|
||||||
|
|
||||||
|
apply_autocmds(EVENT_MODECHANGED, pat, NULL, false, curbuf);
|
||||||
|
xfree(last_mode);
|
||||||
|
last_mode = mode;
|
||||||
|
|
||||||
|
xfree(pat);
|
||||||
|
restore_v_event(v_event, &save_v_event);
|
||||||
|
}
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "nvim/message.h"
|
#include "nvim/message.h"
|
||||||
#include "nvim/misc1.h"
|
#include "nvim/misc1.h"
|
||||||
#include "nvim/option.h"
|
#include "nvim/option.h"
|
||||||
|
#include "nvim/os/input.h"
|
||||||
#include "nvim/os/os.h"
|
#include "nvim/os/os.h"
|
||||||
#include "nvim/os/time.h"
|
#include "nvim/os/time.h"
|
||||||
#include "nvim/os_unix.h"
|
#include "nvim/os_unix.h"
|
||||||
|
@ -100,6 +100,7 @@
|
|||||||
#include "nvim/message.h"
|
#include "nvim/message.h"
|
||||||
#include "nvim/misc1.h"
|
#include "nvim/misc1.h"
|
||||||
#include "nvim/option.h"
|
#include "nvim/option.h"
|
||||||
|
#include "nvim/os/input.h"
|
||||||
#include "nvim/os/os.h"
|
#include "nvim/os/os.h"
|
||||||
#include "nvim/os/time.h"
|
#include "nvim/os/time.h"
|
||||||
#include "nvim/os_unix.h"
|
#include "nvim/os_unix.h"
|
||||||
@ -2621,7 +2622,7 @@ static void u_undo_end(bool did_undo, bool absolute, bool quiet)
|
|||||||
if (uhp == NULL) {
|
if (uhp == NULL) {
|
||||||
*msgbuf = NUL;
|
*msgbuf = NUL;
|
||||||
} else {
|
} else {
|
||||||
add_time(msgbuf, sizeof(msgbuf), uhp->uh_time);
|
undo_fmt_time(msgbuf, sizeof(msgbuf), uhp->uh_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -2641,6 +2642,29 @@ static void u_undo_end(bool did_undo, bool absolute, bool quiet)
|
|||||||
msgbuf);
|
msgbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Put the timestamp of an undo header in "buf[buflen]" in a nice format.
|
||||||
|
void undo_fmt_time(char_u *buf, size_t buflen, time_t tt)
|
||||||
|
{
|
||||||
|
struct tm curtime;
|
||||||
|
|
||||||
|
if (time(NULL) - tt >= 100) {
|
||||||
|
os_localtime_r(&tt, &curtime);
|
||||||
|
if (time(NULL) - tt < (60L * 60L * 12L)) {
|
||||||
|
// within 12 hours
|
||||||
|
(void)strftime((char *)buf, buflen, "%H:%M:%S", &curtime);
|
||||||
|
} else {
|
||||||
|
// longer ago
|
||||||
|
(void)strftime((char *)buf, buflen, "%Y/%m/%d %H:%M:%S", &curtime);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
int64_t seconds = time(NULL) - tt;
|
||||||
|
vim_snprintf((char *)buf, buflen,
|
||||||
|
NGETTEXT("%" PRId64 " second ago",
|
||||||
|
"%" PRId64 " seconds ago", (uint32_t)seconds),
|
||||||
|
seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// u_sync: stop adding to the current entry list
|
/// u_sync: stop adding to the current entry list
|
||||||
///
|
///
|
||||||
/// @param force if true, also sync when no_u_sync is set.
|
/// @param force if true, also sync when no_u_sync is set.
|
||||||
@ -2683,16 +2707,13 @@ void ex_undolist(exarg_T *eap)
|
|||||||
while (uhp != NULL) {
|
while (uhp != NULL) {
|
||||||
if (uhp->uh_prev.ptr == NULL && uhp->uh_walk != nomark
|
if (uhp->uh_prev.ptr == NULL && uhp->uh_walk != nomark
|
||||||
&& uhp->uh_walk != mark) {
|
&& uhp->uh_walk != mark) {
|
||||||
vim_snprintf((char *)IObuff, IOSIZE, "%6ld %7d ",
|
vim_snprintf((char *)IObuff, IOSIZE, "%6ld %7d ", uhp->uh_seq, changes);
|
||||||
uhp->uh_seq, changes);
|
undo_fmt_time(IObuff + STRLEN(IObuff), IOSIZE - STRLEN(IObuff), uhp->uh_time);
|
||||||
add_time(IObuff + STRLEN(IObuff), IOSIZE - STRLEN(IObuff),
|
|
||||||
uhp->uh_time);
|
|
||||||
if (uhp->uh_save_nr > 0) {
|
if (uhp->uh_save_nr > 0) {
|
||||||
while (STRLEN(IObuff) < 33) {
|
while (STRLEN(IObuff) < 33) {
|
||||||
STRCAT(IObuff, " ");
|
STRCAT(IObuff, " ");
|
||||||
}
|
}
|
||||||
vim_snprintf_add((char *)IObuff, IOSIZE,
|
vim_snprintf_add((char *)IObuff, IOSIZE, " %3ld", uhp->uh_save_nr);
|
||||||
" %3ld", uhp->uh_save_nr);
|
|
||||||
}
|
}
|
||||||
GA_APPEND(char_u *, &ga, vim_strsave(IObuff));
|
GA_APPEND(char_u *, &ga, vim_strsave(IObuff));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user