aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2021-12-09 21:23:03 +0100
committerBjörn Linse <bjorn.linse@gmail.com>2021-12-09 23:17:29 +0100
commitd9c1669a5474ee0d09dbe60372a2959207187290 (patch)
tree2f2b3cf29f58c25bfe8e523cac394f8f225bbf52
parent51822f065590154561a59435ca920207fd39bdda (diff)
downloadrneovim-d9c1669a5474ee0d09dbe60372a2959207187290.tar.gz
rneovim-d9c1669a5474ee0d09dbe60372a2959207187290.tar.bz2
rneovim-d9c1669a5474ee0d09dbe60372a2959207187290.zip
refactor(misc1): move out misc functions which obviously belong elsewhere
Also make some function names more descriptive/regular.
-rw-r--r--src/nvim/buffer.c2
-rw-r--r--src/nvim/change.c4
-rw-r--r--src/nvim/change.h7
-rw-r--r--src/nvim/memline.c11
-rw-r--r--src/nvim/misc1.c64
-rw-r--r--src/nvim/misc1.h7
-rw-r--r--src/nvim/option.c2
-rw-r--r--src/nvim/path.c11
-rw-r--r--src/nvim/screen.c13
-rw-r--r--src/nvim/undo.c34
10 files changed, 73 insertions, 82 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index f2f4950e58..297d9743df 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -2719,7 +2719,7 @@ void buflist_list(exarg_T *eap)
IObuff[len++] = ' ';
} while (--i > 0 && len < IOSIZE - 18);
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 {
vim_snprintf((char *)IObuff + len, (size_t)(IOSIZE - len),
_("line %" PRId64),
diff --git a/src/nvim/change.c b/src/nvim/change.c
index ef771125f1..96fbaa9166 100644
--- a/src/nvim/change.c
+++ b/src/nvim/change.c
@@ -131,7 +131,7 @@ void changed_internal(void)
curbuf->b_changed = true;
curbuf->b_changed_invalid = true;
ml_setflags(curbuf);
- check_status(curbuf);
+ redraw_buf_status_later(curbuf);
redraw_tabline = true;
need_maketitle = true; // set window title later
}
@@ -517,7 +517,7 @@ void unchanged(buf_T *buf, int ff, bool always_inc_changedtick)
if (ff) {
save_file_ff(buf);
}
- check_status(buf);
+ redraw_buf_status_later(buf);
redraw_tabline = true;
need_maketitle = true; // set window title later
buf_inc_changedtick(buf);
diff --git a/src/nvim/change.h b/src/nvim/change.h
index e1a1bfba17..e7c8a2b031 100644
--- a/src/nvim/change.h
+++ b/src/nvim/change.h
@@ -4,6 +4,13 @@
#include "nvim/buffer_defs.h" // for buf_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
# include "change.h.generated.h"
#endif
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index 08202a6d5c..40da4b48f8 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -1841,6 +1841,17 @@ char_u *ml_get_pos(const pos_T *pos)
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
///
/// @param will_change true mark the buffer dirty (chars in the line will be changed)
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index bd2188ec15..103fb3b450 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -373,32 +373,6 @@ int get_last_leader_offset(char_u *line, char_u **flags)
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'
///
/// No other characters are accepted, the message is repeated until a valid
@@ -972,21 +946,6 @@ done:
}
/*
- * 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'.
* Don't do this when still processing a command or a mapping.
* Don't do this when inside a ":normal" command.
@@ -995,26 +954,3 @@ int goto_im(void)
{
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);
- }
-}
diff --git a/src/nvim/misc1.h b/src/nvim/misc1.h
index 4ce142c4c5..14ca361073 100644
--- a/src/nvim/misc1.h
+++ b/src/nvim/misc1.h
@@ -4,13 +4,6 @@
#include "nvim/os/shell.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
# include "misc1.h.generated.h"
#endif
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 1fe2e1d04c..ecfdc85153 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -7898,7 +7898,7 @@ void set_fileformat(int eol_style, int opt_flags)
}
// This may cause the buffer to become (un)modified.
- check_status(curbuf);
+ redraw_buf_status_later(curbuf);
redraw_tabline = true;
need_maketitle = true; // Set window title later.
}
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 7b9081eafa..01ac88d537 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -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;
}
+/// 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.
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index a666b9c8b0..d5b8b6db4c 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -314,6 +314,19 @@ void update_curbuf(int 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.
///
/// Most code shouldn't call this directly, rather use redraw_later() and
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index 5274fb98c7..3e7eb6d01e 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -2622,7 +2622,7 @@ static void u_undo_end(bool did_undo, bool absolute, bool quiet)
if (uhp == NULL) {
*msgbuf = NUL;
} else {
- add_time(msgbuf, sizeof(msgbuf), uhp->uh_time);
+ undo_fmt_time(msgbuf, sizeof(msgbuf), uhp->uh_time);
}
{
@@ -2642,6 +2642,29 @@ static void u_undo_end(bool did_undo, bool absolute, bool quiet)
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
///
/// @param force if true, also sync when no_u_sync is set.
@@ -2684,16 +2707,13 @@ void ex_undolist(exarg_T *eap)
while (uhp != NULL) {
if (uhp->uh_prev.ptr == NULL && uhp->uh_walk != nomark
&& uhp->uh_walk != mark) {
- vim_snprintf((char *)IObuff, IOSIZE, "%6ld %7d ",
- uhp->uh_seq, changes);
- add_time(IObuff + STRLEN(IObuff), IOSIZE - STRLEN(IObuff),
- uhp->uh_time);
+ vim_snprintf((char *)IObuff, IOSIZE, "%6ld %7d ", uhp->uh_seq, changes);
+ undo_fmt_time(IObuff + STRLEN(IObuff), IOSIZE - STRLEN(IObuff), uhp->uh_time);
if (uhp->uh_save_nr > 0) {
while (STRLEN(IObuff) < 33) {
STRCAT(IObuff, " ");
}
- vim_snprintf_add((char *)IObuff, IOSIZE,
- " %3ld", uhp->uh_save_nr);
+ vim_snprintf_add((char *)IObuff, IOSIZE, " %3ld", uhp->uh_save_nr);
}
GA_APPEND(char_u *, &ga, vim_strsave(IObuff));
}