Mercurial > vim
comparison src/testdir/test_quickfix.vim @ 20631:d6827bd31d1d v8.2.0869
patch 8.2.0869: it is not possible to customize the quickfix window contents
Commit: https://github.com/vim/vim/commit/858ba06d5f577b187da0367b231f7fa9461cb32d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 31 23:11:59 2020 +0200
patch 8.2.0869: it is not possible to customize the quickfix window contents
Problem: It is not possible to customize the quickfix window contents.
Solution: Add 'quickfixtextfunc'. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5465)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 31 May 2020 23:15:03 +0200 |
parents | a85a3207679f |
children | ada6f26e6eb1 |
comparison
equal
deleted
inserted
replaced
20630:b7bfe0a2b961 | 20631:d6827bd31d1d |
---|---|
4764 | 4764 |
4765 " Exit Vim with negative value | 4765 " Exit Vim with negative value |
4766 call assert_fails('-3cquit', 'E16:') | 4766 call assert_fails('-3cquit', 'E16:') |
4767 endfunc | 4767 endfunc |
4768 | 4768 |
4769 " Test for getting a specific item from a quickfix list | |
4770 func Xtest_getqflist_by_idx(cchar) | |
4771 call s:setup_commands(a:cchar) | |
4772 " Empty list | |
4773 call assert_equal([], g:Xgetlist({'idx' : 1, 'items' : 0}).items) | |
4774 Xexpr ['F1:10:L10', 'F1:20:L20'] | |
4775 let l = g:Xgetlist({'idx' : 2, 'items' : 0}).items | |
4776 call assert_equal(bufnr('F1'), l[0].bufnr) | |
4777 call assert_equal(20, l[0].lnum) | |
4778 call assert_equal('L20', l[0].text) | |
4779 call assert_equal([], g:Xgetlist({'idx' : -1, 'items' : 0}).items) | |
4780 call assert_equal([], g:Xgetlist({'idx' : 3, 'items' : 0}).items) | |
4781 %bwipe! | |
4782 endfunc | |
4783 | |
4784 func Test_getqflist_by_idx() | |
4785 call Xtest_getqflist_by_idx('c') | |
4786 call Xtest_getqflist_by_idx('l') | |
4787 endfunc | |
4788 | |
4789 " Test for the 'quickfixtextfunc' setting | |
4790 func Tqfexpr(info) | |
4791 if a:info.quickfix | |
4792 let qfl = getqflist({'id' : a:info.id, 'idx' : a:info.idx, | |
4793 \ 'items' : 1}).items | |
4794 else | |
4795 let qfl = getloclist(0, {'id' : a:info.id, 'idx' : a:info.idx, | |
4796 \ 'items' : 1}).items | |
4797 endif | |
4798 | |
4799 let e = qfl[0] | |
4800 let s = '' | |
4801 if e.bufnr != 0 | |
4802 let bname = bufname(e.bufnr) | |
4803 let s ..= fnamemodify(bname, ':.') | |
4804 endif | |
4805 let s ..= '-' | |
4806 let s ..= 'L' .. string(e.lnum) .. 'C' .. string(e.col) .. '-' | |
4807 let s ..= e.text | |
4808 | |
4809 return s | |
4810 endfunc | |
4811 | |
4812 func Xtest_qftextfunc(cchar) | |
4813 call s:setup_commands(a:cchar) | |
4814 | |
4815 set efm=%f:%l:%c:%m | |
4816 set quickfixtextfunc=Tqfexpr | |
4817 Xexpr ['F1:10:2:green', 'F1:20:4:blue'] | |
4818 Xwindow | |
4819 call assert_equal('F1-L10C2-green', getline(1)) | |
4820 call assert_equal('F1-L20C4-blue', getline(2)) | |
4821 Xclose | |
4822 set quickfixtextfunc&vim | |
4823 Xwindow | |
4824 call assert_equal('F1|10 col 2| green', getline(1)) | |
4825 call assert_equal('F1|20 col 4| blue', getline(2)) | |
4826 Xclose | |
4827 set efm& | |
4828 set quickfixtextfunc& | |
4829 | |
4830 " Test for per list 'quickfixtextfunc' setting | |
4831 func PerQfText(info) | |
4832 if a:info.quickfix | |
4833 let qfl = getqflist({'id' : a:info.id, 'idx' : a:info.idx, | |
4834 \ 'items' : 1}).items | |
4835 else | |
4836 let qfl = getloclist(0, {'id' : a:info.id, 'idx' : a:info.idx, | |
4837 \ 'items' : 1}).items | |
4838 endif | |
4839 if empty(qfl) | |
4840 return '' | |
4841 endif | |
4842 return 'Line ' .. qfl[0].lnum .. ', Col ' .. qfl[0].col | |
4843 endfunc | |
4844 set quickfixtextfunc=Tqfexpr | |
4845 call g:Xsetlist([], ' ', {'quickfixtextfunc' : "PerQfText"}) | |
4846 Xaddexpr ['F1:10:2:green', 'F1:20:4:blue'] | |
4847 Xwindow | |
4848 call assert_equal('Line 10, Col 2', getline(1)) | |
4849 call assert_equal('Line 20, Col 4', getline(2)) | |
4850 Xclose | |
4851 call g:Xsetlist([], 'r', {'quickfixtextfunc' : ''}) | |
4852 set quickfixtextfunc& | |
4853 delfunc PerQfText | |
4854 | |
4855 " Non-existing function | |
4856 set quickfixtextfunc=Tabc | |
4857 call assert_fails("Xexpr ['F1:10:2:green', 'F1:20:4:blue']", 'E117:') | |
4858 call assert_fails("Xwindow", 'E117:') | |
4859 Xclose | |
4860 set quickfixtextfunc& | |
4861 | |
4862 " set option to a non-function | |
4863 set quickfixtextfunc=[10,\ 20] | |
4864 call assert_fails("Xexpr ['F1:10:2:green', 'F1:20:4:blue']", 'E117:') | |
4865 call assert_fails("Xwindow", 'E117:') | |
4866 Xclose | |
4867 set quickfixtextfunc& | |
4868 | |
4869 " set option to a function with different set of arguments | |
4870 func Xqftext(a, b, c) | |
4871 return a:a .. a:b .. a:c | |
4872 endfunc | |
4873 set quickfixtextfunc=Xqftext | |
4874 call assert_fails("Xexpr ['F1:10:2:green', 'F1:20:4:blue']", 'E119:') | |
4875 call assert_fails("Xwindow", 'E119:') | |
4876 Xclose | |
4877 set quickfixtextfunc& | |
4878 delfunc Xqftext | |
4879 endfunc | |
4880 | |
4881 func Test_qftextfunc() | |
4882 call Xtest_qftextfunc('c') | |
4883 call Xtest_qftextfunc('l') | |
4884 endfunc | |
4885 | |
4769 " vim: shiftwidth=2 sts=2 expandtab | 4886 " vim: shiftwidth=2 sts=2 expandtab |