diff options
-rw-r--r-- | src/nvim/eval.c | 8 | ||||
-rw-r--r-- | src/nvim/fileio.c | 54 | ||||
-rw-r--r-- | src/nvim/move.c | 29 | ||||
-rw-r--r-- | src/nvim/move.h | 3 | ||||
-rw-r--r-- | src/nvim/os_unix.c | 2 | ||||
-rw-r--r-- | src/nvim/quickfix.c | 20 | ||||
-rw-r--r-- | src/nvim/testdir/test_fold.vim | 26 | ||||
-rw-r--r-- | src/nvim/testdir/test_maparg.vim | 8 | ||||
-rw-r--r-- | src/nvim/testdir/test_quickfix.vim | 24 |
9 files changed, 127 insertions, 47 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 8d8fdab351..e031b594a3 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -12149,8 +12149,12 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) if (!get_dict) { // Return a string. if (rhs != NULL) { - rettv->vval.v_string = (char_u *)str2special_save( - (const char *)rhs, false, false); + if (*rhs == NUL) { + rettv->vval.v_string = vim_strsave((char_u *)"<Nop>"); + } else { + rettv->vval.v_string = (char_u *)str2special_save( + (char *)rhs, false, false); + } } } else { diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 8b650d0d5b..290de034d7 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4311,38 +4311,46 @@ static int make_bom(char_u *buf, char_u *name) return (int)(p - buf); } +/// Shorten filename of a buffer. +/// When "force" is TRUE: Use full path from now on for files currently being +/// edited, both for file name and swap file name. Try to shorten the file +/// names a bit, if safe to do so. +/// When "force" is FALSE: Only try to shorten absolute file names. +/// For buffers that have buftype "nofile" or "scratch": never change the file +/// name. +void shorten_buf_fname(buf_T *buf, char_u *dirname, int force) +{ + char_u *p; + + if (buf->b_fname != NULL + && !bt_nofile(buf) + && !path_with_url((char *)buf->b_fname) + && (force + || buf->b_sfname == NULL + || path_is_absolute(buf->b_sfname))) { + xfree(buf->b_sfname); + buf->b_sfname = NULL; + p = path_shorten_fname(buf->b_ffname, dirname); + if (p != NULL) { + buf->b_sfname = vim_strsave(p); + buf->b_fname = buf->b_sfname; + } + if (p == NULL || buf->b_fname == NULL) { + buf->b_fname = buf->b_ffname; + } + } +} + /* * Shorten filenames for all buffers. - * When "force" is TRUE: Use full path from now on for files currently being - * edited, both for file name and swap file name. Try to shorten the file - * names a bit, if safe to do so. - * When "force" is FALSE: Only try to shorten absolute file names. - * For buffers that have buftype "nofile" or "scratch": never change the file - * name. */ void shorten_fnames(int force) { char_u dirname[MAXPATHL]; - char_u *p; os_dirname(dirname, MAXPATHL); FOR_ALL_BUFFERS(buf) { - if (buf->b_fname != NULL - && !bt_nofile(buf) - && !path_with_url((char *)buf->b_fname) - && (force - || buf->b_sfname == NULL - || path_is_absolute(buf->b_sfname))) { - xfree(buf->b_sfname); - buf->b_sfname = NULL; - p = path_shorten_fname(buf->b_ffname, dirname); - if (p != NULL) { - buf->b_sfname = vim_strsave(p); - buf->b_fname = buf->b_sfname; - } - if (p == NULL || buf->b_fname == NULL) - buf->b_fname = buf->b_ffname; - } + shorten_buf_fname(buf, dirname, force); /* Always make the swap file name a full path, a "nofile" buffer may * also have a swap file. */ diff --git a/src/nvim/move.c b/src/nvim/move.c index 41859a489f..1b84628ebc 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -16,7 +16,6 @@ #include <inttypes.h> #include <stdbool.h> -#include "nvim/vim.h" #include "nvim/ascii.h" #include "nvim/move.h" #include "nvim/charset.h" @@ -1726,7 +1725,7 @@ void cursor_correct(void) * * return FAIL for failure, OK otherwise */ -int onepage(int dir, long count) +int onepage(Direction dir, long count) { long n; int retval = OK; @@ -1884,16 +1883,18 @@ int onepage(int dir, long count) } curwin->w_valid &= ~(VALID_WCOL|VALID_WROW|VALID_VIRTCOL); - /* - * Avoid the screen jumping up and down when 'scrolloff' is non-zero. - * But make sure we scroll at least one line (happens with mix of long - * wrapping lines and non-wrapping line). - */ - if (retval == OK && dir == FORWARD && check_top_offset()) { - scroll_cursor_top(1, false); - if (curwin->w_topline <= old_topline - && old_topline < curbuf->b_ml.ml_line_count) { - curwin->w_topline = old_topline + 1; + if (retval == OK && dir == FORWARD) { + // Avoid the screen jumping up and down when 'scrolloff' is non-zero. + // But make sure we scroll at least one line (happens with mix of long + // wrapping lines and non-wrapping line). + if (check_top_offset()) { + scroll_cursor_top(1, false); + if (curwin->w_topline <= old_topline + && old_topline < curbuf->b_ml.ml_line_count) { + curwin->w_topline = old_topline + 1; + (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); + } + } else if (curwin->w_botline > curbuf->b_ml.ml_line_count) { (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); } } @@ -2166,9 +2167,7 @@ void do_check_cursorbind(void) restart_edit = restart_edit_save; } // Correct cursor for multi-byte character. - if (has_mbyte) { - mb_adjust_cursor(); - } + mb_adjust_cursor(); redraw_later(VALID); // Only scroll when 'scrollbind' hasn't done this. diff --git a/src/nvim/move.h b/src/nvim/move.h index 00fbcc580f..3670dc9086 100644 --- a/src/nvim/move.h +++ b/src/nvim/move.h @@ -2,8 +2,7 @@ #define NVIM_MOVE_H #include <stdbool.h> -#include "nvim/buffer_defs.h" -#include "nvim/pos.h" +#include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "move.h.generated.h" diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c index a27fee4e90..e52adfa1a9 100644 --- a/src/nvim/os_unix.c +++ b/src/nvim/os_unix.c @@ -138,8 +138,8 @@ void mch_exit(int r) { exiting = true; - ui_builtin_stop(); ui_flush(); + ui_builtin_stop(); ml_close_all(true); // remove all memfiles if (!event_teardown() && r == 0) { diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index ba2f2ba969..7c555da1a0 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -2240,8 +2240,12 @@ void qf_list(exarg_T *eap) } } - if (qi->qf_lists[qi->qf_curlist].qf_nonevalid) - all = TRUE; + // Shorten all the file names, so that it is easy to read. + shorten_fnames(false); + + if (qi->qf_lists[qi->qf_curlist].qf_nonevalid) { + all = true; + } qfp = qi->qf_lists[qi->qf_curlist].qf_start; for (i = 1; !got_int && i <= qi->qf_lists[qi->qf_curlist].qf_count; ) { if ((qfp->qf_valid || all) && idx1 <= i && i <= idx2) { @@ -2944,6 +2948,10 @@ static void qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last) /* Check if there is anything to display */ if (qi->qf_curlist < qi->qf_listcount) { + char_u dirname[MAXPATHL]; + + *dirname = NUL; + // Add one line for each error if (old_last == NULL) { qfp = qi->qf_lists[qi->qf_curlist].qf_start; @@ -2959,6 +2967,14 @@ static void qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last) if (qfp->qf_type == 1) { // :helpgrep STRLCPY(IObuff, path_tail(errbuf->b_fname), sizeof(IObuff)); } else { + // shorten the file name if not done already + if (errbuf->b_sfname == NULL + || path_is_absolute(errbuf->b_sfname)) { + if (*dirname == NUL) { + os_dirname(dirname, MAXPATHL); + } + shorten_buf_fname(errbuf, dirname, false); + } STRLCPY(IObuff, errbuf->b_fname, sizeof(IObuff)); } len = (int)STRLEN(IObuff); diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim index e7d5a2ae2c..b6a545f959 100644 --- a/src/nvim/testdir/test_fold.vim +++ b/src/nvim/testdir/test_fold.vim @@ -1,5 +1,7 @@ " Test for folding +source view_util.vim + func PrepIndent(arg) return [a:arg] + repeat(["\t".a:arg], 5) endfu @@ -648,3 +650,27 @@ func Test_foldtext_recursive() call assert_equal(3, foldclosedend(2)) bwipe! endfunc + +func Test_fold_last_line_with_pagedown() + enew! + set fdm=manual + + let expect = '+-- 11 lines: 9---' + let content = range(1,19) + call append(0, content) + normal dd9G + normal zfG + normal zt + call assert_equal('9', getline(foldclosed('.'))) + call assert_equal('19', getline(foldclosedend('.'))) + call assert_equal(expect, ScreenLines(1, len(expect))[0]) + call feedkeys("\<C-F>", 'xt') + call assert_equal(expect, ScreenLines(1, len(expect))[0]) + call feedkeys("\<C-F>", 'xt') + call assert_equal(expect, ScreenLines(1, len(expect))[0]) + call feedkeys("\<C-B>\<C-F>\<C-F>", 'xt') + call assert_equal(expect, ScreenLines(1, len(expect))[0]) + + set fdm& + enew! +endfunc diff --git a/src/nvim/testdir/test_maparg.vim b/src/nvim/testdir/test_maparg.vim index 9ad83836c6..0fb878b04a 100644 --- a/src/nvim/testdir/test_maparg.vim +++ b/src/nvim/testdir/test_maparg.vim @@ -29,9 +29,13 @@ function Test_maparg() \ maparg('foo', '', 0, 1)) map abc x<char-114>x - call assert_equal(maparg('abc'), "xrx") + call assert_equal("xrx", maparg('abc')) map abc y<S-char-114>y - call assert_equal(maparg('abc'), "yRy") + call assert_equal("yRy", maparg('abc')) + + map abc <Nop> + call assert_equal("<Nop>", maparg('abc')) + unmap abc endfunction function Test_range_map() diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 7a53db7605..624e642e7f 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -2584,3 +2584,27 @@ func Test_qf_id() call Xqfid_tests('c') call Xqfid_tests('l') endfunc + +" Test for shortening/simplifying the file name when opening the +" quickfix window or when displaying the quickfix list +func Test_shorten_fname() + if !has('unix') + return + endif + %bwipe + " Create a quickfix list with a absolute path filename + let fname = getcwd() . '/test_quickfix.vim' + call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'}) + call assert_equal(fname, bufname('test_quickfix.vim')) + " Opening the quickfix window should simplify the file path + cwindow + call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim')) + cclose + %bwipe + " Create a quickfix list with a absolute path filename + call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'}) + call assert_equal(fname, bufname('test_quickfix.vim')) + " Displaying the quickfix list should simplify the file path + silent! clist + call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim')) +endfunc |