diff options
Diffstat (limited to 'src/nvim/buffer.c')
| -rw-r--r-- | src/nvim/buffer.c | 216 | 
1 files changed, 110 insertions, 106 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 2b5325a917..54b5f8283f 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -65,6 +65,7 @@  #include "nvim/os/time.h"  #include "nvim/os_unix.h"  #include "nvim/path.h" +#include "nvim/plines.h"  #include "nvim/quickfix.h"  #include "nvim/regexp.h"  #include "nvim/screen.h" @@ -98,13 +99,15 @@ typedef enum {    kBffInitChangedtick = 2,  } BufFreeFlags; -// Read data from buffer for retrying. -static int read_buffer(int     read_stdin,     // read file from stdin, otherwise fifo -                       exarg_T *eap,           // for forced 'ff' and 'fenc' or NULL -                       int     flags)          // extra flags for readfile() +/// Read data from buffer for retrying. +/// +/// @param read_stdin  read file from stdin, otherwise fifo +/// @param eap  for forced 'ff' and 'fenc' or NULL +/// @param flags  extra flags for readfile() +static int read_buffer(int read_stdin, exarg_T *eap, int flags)  { -  int       retval = OK; -  linenr_T  line_count; +  int retval = OK; +  linenr_T line_count;    //    // Read from the buffer which the text is already filled in and append at @@ -146,16 +149,18 @@ static int read_buffer(int     read_stdin,     // read file from stdin, otherwis    return retval;  } -// Open current buffer, that is: open the memfile and read the file into -// memory. -// Return FAIL for failure, OK otherwise. -int open_buffer(int read_stdin,   // read file from stdin -                exarg_T *eap,     // for forced 'ff' and 'fenc' or NULL -                int flags         // extra flags for readfile() -                ) +/// Open current buffer, that is: open the memfile and read the file into +/// memory. +/// +/// @param read_stdin  read file from stdin +/// @param eap  for forced 'ff' and 'fenc' or NULL +/// @param flags  extra flags for readfile() +/// +/// @return  FAIL for failure, OK otherwise. +int open_buffer(int read_stdin, exarg_T *eap, int flags)  {    int retval = OK; -  bufref_T       old_curbuf; +  bufref_T old_curbuf;    long old_tw = curbuf->b_p_tw;    int read_fifo = false; @@ -816,6 +821,7 @@ static void free_buffer_stuff(buf_T *buf, int free_flags)    uc_clear(&buf->b_ucmds);               // clear local user commands    buf_delete_signs(buf, (char_u *)"*");  // delete any signs    extmark_free_all(buf);                 // delete any extmarks +  clear_virt_lines(buf, -1);    map_clear_int(buf, MAP_ALL_MODES, true, false);    // clear local mappings    map_clear_int(buf, MAP_ALL_MODES, true, true);     // clear local abbrevs    XFREE_CLEAR(buf->b_start_fenc); @@ -939,23 +945,22 @@ void handle_swap_exists(bufref_T *old_curbuf)    swap_exists_action = SEA_NONE;  // -V519  } -/* - * do_bufdel() - delete or unload buffer(s) - * - * addr_count == 0: ":bdel" - delete current buffer - * addr_count == 1: ":N bdel" or ":bdel N [N ..]" - first delete - *                  buffer "end_bnr", then any other arguments. - * addr_count == 2: ":N,N bdel" - delete buffers in range - * - * command can be DOBUF_UNLOAD (":bunload"), DOBUF_WIPE (":bwipeout") or - * DOBUF_DEL (":bdel") - * - * Returns error message or NULL - */ -char_u *do_bufdel(int command, char_u *arg,               // pointer to extra arguments -                  int addr_count, int start_bnr,             // first buffer number in a range -                  int end_bnr,               // buffer nr or last buffer nr in a range -                  int forceit) +/// do_bufdel() - delete or unload buffer(s) +/// +/// addr_count == 0: ":bdel" - delete current buffer +/// addr_count == 1: ":N bdel" or ":bdel N [N ..]" - first delete +///                  buffer "end_bnr", then any other arguments. +/// addr_count == 2: ":N,N bdel" - delete buffers in range +/// +/// command can be DOBUF_UNLOAD (":bunload"), DOBUF_WIPE (":bwipeout") or +/// DOBUF_DEL (":bdel") +/// +/// @param arg  pointer to extra arguments +/// @param start_bnr  first buffer number in a range +/// @param end_bnr  buffer nr or last buffer nr in a range +/// +/// @return  error message or NULL +char_u *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int end_bnr, int forceit)  {    int do_current = 0;             // delete current buffer?    int deleted = 0;                // number of buffers deleted @@ -1097,26 +1102,26 @@ static int empty_curbuf(int close_others, int forceit, int action)    return retval;  } -/* - * Implementation of the commands for the buffer list. - * - * action == DOBUF_GOTO     go to specified buffer - * action == DOBUF_SPLIT    split window and go to specified buffer - * action == DOBUF_UNLOAD   unload specified buffer(s) - * action == DOBUF_DEL      delete specified buffer(s) from buffer list - * action == DOBUF_WIPE     delete specified buffer(s) really - * - * start == DOBUF_CURRENT   go to "count" buffer from current buffer - * start == DOBUF_FIRST     go to "count" buffer from first buffer - * start == DOBUF_LAST      go to "count" buffer from last buffer - * start == DOBUF_MOD       go to "count" modified buffer from current buffer - * - * Return FAIL or OK. - */ -int do_buffer(int action, int start, int dir,                        // FORWARD or BACKWARD -              int count,                      // buffer number or number of buffers -              int forceit                     // true for :...! -              ) + +/// Implementation of the commands for the buffer list. +/// +/// action == DOBUF_GOTO     go to specified buffer +/// action == DOBUF_SPLIT    split window and go to specified buffer +/// action == DOBUF_UNLOAD   unload specified buffer(s) +/// action == DOBUF_DEL      delete specified buffer(s) from buffer list +/// action == DOBUF_WIPE     delete specified buffer(s) really +/// +/// start == DOBUF_CURRENT   go to "count" buffer from current buffer +/// start == DOBUF_FIRST     go to "count" buffer from first buffer +/// start == DOBUF_LAST      go to "count" buffer from last buffer +/// start == DOBUF_MOD       go to "count" modified buffer from current buffer +/// +/// @param dir  FORWARD or BACKWARD +/// @param count  buffer number or number of buffers +/// @param forceit  true for :...! +/// +/// @return  FAIL or OK. +int do_buffer(int action, int start, int dir, int count, int forceit)  {    buf_T *buf;    buf_T *bp; @@ -2154,11 +2159,13 @@ static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id, bool fil  /// Find file in buffer list by a regexp pattern.  /// Return fnum of the found buffer.  /// Return < 0 for error. -int buflist_findpat(const char_u *pattern, const char_u *pattern_end,  // pointer to first char after pattern -                    bool unlisted,              // find unlisted buffers -                    bool diffmode,              // find diff-mode buffers only -                    bool curtab_only            // find buffers in current tab only -                    ) +/// +/// @param pattern_end  pointer to first char after pattern +/// @param unlisted  find unlisted buffers +/// @param diffmode  find diff-mode buffers only +/// @param curtab_only  find buffers in current tab only +int buflist_findpat(const char_u *pattern, const char_u *pattern_end, bool unlisted, bool diffmode, +                    bool curtab_only)    FUNC_ATTR_NONNULL_ARG(1)  {    int match = -1; @@ -2466,14 +2473,14 @@ buf_T *buflist_findnr(int nr)    return handle_get_buffer((handle_T)nr);  } -/* - * Get name of file 'n' in the buffer list. - * When the file has no name an empty string is returned. - * home_replace() is used to shorten the file name (used for marks). - * Returns a pointer to allocated memory, of NULL when failed. - */ -char_u *buflist_nr2name(int n, int fullname, int helptail                   // for help buffers return tail only -                        ) +/// Get name of file 'n' in the buffer list. +/// When the file has no name an empty string is returned. +/// home_replace() is used to shorten the file name (used for marks). +/// +/// @param helptail  for help buffers return tail only +/// +/// @return  a pointer to allocated memory, of NULL when failed. +char_u *buflist_nr2name(int n, int fullname, int helptail)  {    buf_T *buf; @@ -2800,13 +2807,14 @@ int buflist_name_nr(int fnum, char_u **fname, linenr_T *lnum)    return OK;  } -// Set the file name for "buf" to "ffname_arg", short file name to -// "sfname_arg". -// The file name with the full path is also remembered, for when :cd is used. -// Returns FAIL for failure (file name already in use by other buffer) -//      OK otherwise. -int setfname(buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, bool message                  // give message when buffer already exists -             ) +/// Set the file name for "buf" to "ffname_arg", short file name to +/// "sfname_arg". +/// The file name with the full path is also remembered, for when :cd is used. +/// +/// @param message  give message when buffer already exists +/// +/// @return  FAIL for failure (file name already in use by other buffer) OK otherwise. +int setfname(buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, bool message)  {    char_u *ffname = ffname_arg;    char_u *sfname = sfname_arg; @@ -2934,12 +2942,11 @@ buf_T *setaltfname(char_u *ffname, char_u *sfname, linenr_T lnum)    return buf;  } -/* - * Get alternate file name for current window. - * Return NULL if there isn't any, and give error message if requested. - */ -char_u *getaltfname(bool errmsg                   // give error message -                    ) +/// Get alternate file name for current window. +/// Return NULL if there isn't any, and give error message if requested. +/// +/// @param errmsg  give error message +char_u *getaltfname(bool errmsg)  {    char_u *fname;    linenr_T dummy; @@ -3078,11 +3085,10 @@ static bool buf_same_file_id(buf_T *buf, FileID *file_id)    return buf->file_id_valid && os_fileid_equal(&(buf->file_id), file_id);  } -/* - * Print info about the current buffer. - */ -void fileinfo(int fullname,               // when non-zero print full path -              int shorthelp, int dont_truncate) +/// Print info about the current buffer. +/// +/// @param fullname  when non-zero print full path +void fileinfo(int fullname, int shorthelp, int dont_truncate)  {    char_u *name;    int n; @@ -3112,12 +3118,13 @@ void fileinfo(int fullname,               // when non-zero print full path                   (size_t)(IOSIZE - (p - buffer)), true);    } +  bool dontwrite = bt_dontwrite(curbuf);    vim_snprintf_add((char *)buffer, IOSIZE, "\"%s%s%s%s%s%s",                     curbufIsChanged()                     ? (shortmess(SHM_MOD) ?  " [+]" : _(" [Modified]")) : " ", -                   (curbuf->b_flags & BF_NOTEDITED) && !bt_dontwrite(curbuf) +                   (curbuf->b_flags & BF_NOTEDITED) && !dontwrite                     ? _("[Not edited]") : "", -                   (curbuf->b_flags & BF_NEW) && !bt_dontwrite(curbuf) +                   (curbuf->b_flags & BF_NEW) && !dontwrite                     ? new_file_message() : "",                     (curbuf->b_flags & BF_READERR)                     ? _("[Read errors]") : "", @@ -3257,7 +3264,7 @@ void maketitle(void)          buf_p += MIN(size, SPACE_FOR_FNAME);        } else {          buf_p += transstr_buf((const char *)path_tail(curbuf->b_fname), -                              buf_p, SPACE_FOR_FNAME + 1); +                              buf_p, SPACE_FOR_FNAME + 1, true);        }        switch (bufIsChanged(curbuf) @@ -3306,7 +3313,7 @@ void maketitle(void)          // room for the server name.  When there is no room (very long          // file name) use (...).          if ((size_t)(buf_p - buf) < SPACE_FOR_DIR) { -          char *const tbuf = transstr(buf_p); +          char *const tbuf = transstr(buf_p, true);            const size_t free_space = SPACE_FOR_DIR - (size_t)(buf_p - buf) + 1;            const size_t dir_len = xstrlcpy(buf_p, tbuf, free_space);            buf_p += MIN(dir_len, free_space - 1); @@ -4652,7 +4659,7 @@ void get_rel_pos(win_T *wp, char_u *buf, int buflen)    long below;          // number of lines below window    above = wp->w_topline - 1; -  above += diff_check_fill(wp, wp->w_topline) - wp->w_topfill; +  above += win_get_fill(wp, wp->w_topline) - wp->w_topfill;    if (wp->w_topline == 1 && wp->w_topfill >= 1) {      // All buffer lines are displayed and there is an indication      // of filler lines, that can be considered seeing all lines. @@ -4750,12 +4757,11 @@ char_u *alist_name(aentry_T *aep)    return bp->b_fname;  } -/* - * do_arg_all(): Open up to 'count' windows, one for each argument. - */ -void do_arg_all(int count, int forceit,                  // hide buffers in current windows -                int keep_tabs                 // keep current tabs, for ":tab drop file" -                ) +/// do_arg_all(): Open up to 'count' windows, one for each argument. +/// +/// @param forceit  hide buffers in current windows +/// @param keep_tabs  keep current tabs, for ":tab drop file" +void do_arg_all(int count, int forceit, int keep_tabs)  {    char_u *opened;          // Array of weight for which args are open:                             //  0: not opened @@ -5253,12 +5259,11 @@ void do_modelines(int flags)    entered--;  } -/* - * chk_modeline() - check a single line for a mode string - * Return FAIL if an error encountered. - */ -static int chk_modeline(linenr_T lnum, int flags                      // Same as for do_modelines(). -                        ) +/// chk_modeline() - check a single line for a mode string +/// Return FAIL if an error encountered. +/// +/// @param flags  Same as for do_modelines(). +static int chk_modeline(linenr_T lnum, int flags)  {    char_u *s;    char_u *e; @@ -5630,13 +5635,12 @@ bool buf_contents_changed(buf_T *buf)    return differ;  } -/* - * Wipe out a buffer and decrement the last buffer number if it was used for - * this buffer.  Call this to wipe out a temp buffer that does not contain any - * marks. - */ -void wipe_buffer(buf_T *buf, bool aucmd                  // When true trigger autocommands. -                 ) +/// Wipe out a buffer and decrement the last buffer number if it was used for +/// this buffer.  Call this to wipe out a temp buffer that does not contain any +/// marks. +/// +/// @param aucmd  When true trigger autocommands. +void wipe_buffer(buf_T *buf, bool aucmd)  {    if (!aucmd) {      // Don't trigger BufDelete autocommands here.  | 
