comparison src/sign.c @ 15864:9e0154efac3a v8.1.0939

patch 8.1.0939: no completion for sign group names commit https://github.com/vim/vim/commit/3678f65d43d10b36dc62738aab2f341fa1e18a32 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Feb 17 14:50:25 2019 +0100 patch 8.1.0939: no completion for sign group names Problem: No completion for sign group names. Solution: Add completion for sign group names and buffer names. (Yegappan Lakshmanan, closes #3980)
author Bram Moolenaar <Bram@vim.org>
date Sun, 17 Feb 2019 15:00:06 +0100
parents 62b3805506b3
children 695d9ef00b03
comparison
equal deleted inserted replaced
15863:7c92dfb1bdd7 15864:9e0154efac3a
1765 static enum 1765 static enum
1766 { 1766 {
1767 EXP_SUBCMD, // expand :sign sub-commands 1767 EXP_SUBCMD, // expand :sign sub-commands
1768 EXP_DEFINE, // expand :sign define {name} args 1768 EXP_DEFINE, // expand :sign define {name} args
1769 EXP_PLACE, // expand :sign place {id} args 1769 EXP_PLACE, // expand :sign place {id} args
1770 EXP_LIST, // expand :sign place args
1770 EXP_UNPLACE, // expand :sign unplace" 1771 EXP_UNPLACE, // expand :sign unplace"
1771 EXP_SIGN_NAMES // expand with name of placed signs 1772 EXP_SIGN_NAMES, // expand with name of placed signs
1773 EXP_SIGN_GROUPS // expand with name of placed sign groups
1772 } expand_what; 1774 } expand_what;
1775
1776 /*
1777 * Return the n'th sign name (used for command line completion)
1778 */
1779 static char_u *
1780 get_nth_sign_name(int idx)
1781 {
1782 int current_idx;
1783 sign_T *sp;
1784
1785 // Complete with name of signs already defined
1786 current_idx = 0;
1787 for (sp = first_sign; sp != NULL; sp = sp->sn_next)
1788 if (current_idx++ == idx)
1789 return sp->sn_name;
1790 return NULL;
1791 }
1792
1793 /*
1794 * Return the n'th sign group name (used for command line completion)
1795 */
1796 static char_u *
1797 get_nth_sign_group_name(int idx)
1798 {
1799 int current_idx;
1800 int todo;
1801 hashitem_T *hi;
1802 signgroup_T *group;
1803
1804 // Complete with name of sign groups already defined
1805 current_idx = 0;
1806 todo = (int)sg_table.ht_used;
1807 for (hi = sg_table.ht_array; todo > 0; ++hi)
1808 {
1809 if (!HASHITEM_EMPTY(hi))
1810 {
1811 --todo;
1812 if (current_idx++ == idx)
1813 {
1814 group = HI2SG(hi);
1815 return group->sg_name;
1816 }
1817 }
1818 }
1819 return NULL;
1820 }
1773 1821
1774 /* 1822 /*
1775 * Function given to ExpandGeneric() to obtain the sign command 1823 * Function given to ExpandGeneric() to obtain the sign command
1776 * expansion. 1824 * expansion.
1777 */ 1825 */
1778 char_u * 1826 char_u *
1779 get_sign_name(expand_T *xp UNUSED, int idx) 1827 get_sign_name(expand_T *xp UNUSED, int idx)
1780 { 1828 {
1781 sign_T *sp;
1782 int current_idx;
1783
1784 switch (expand_what) 1829 switch (expand_what)
1785 { 1830 {
1786 case EXP_SUBCMD: 1831 case EXP_SUBCMD:
1787 return (char_u *)cmds[idx]; 1832 return (char_u *)cmds[idx];
1788 case EXP_DEFINE: 1833 case EXP_DEFINE:
1800 "line=", "name=", "group=", "priority=", "file=", 1845 "line=", "name=", "group=", "priority=", "file=",
1801 "buffer=", NULL 1846 "buffer=", NULL
1802 }; 1847 };
1803 return (char_u *)place_arg[idx]; 1848 return (char_u *)place_arg[idx];
1804 } 1849 }
1850 case EXP_LIST:
1851 {
1852 char *list_arg[] =
1853 {
1854 "group=", "file=", "buffer=", NULL
1855 };
1856 return (char_u *)list_arg[idx];
1857 }
1805 case EXP_UNPLACE: 1858 case EXP_UNPLACE:
1806 { 1859 {
1807 char *unplace_arg[] = { "group=", "file=", "buffer=", NULL }; 1860 char *unplace_arg[] = { "group=", "file=", "buffer=", NULL };
1808 return (char_u *)unplace_arg[idx]; 1861 return (char_u *)unplace_arg[idx];
1809 } 1862 }
1810 case EXP_SIGN_NAMES: 1863 case EXP_SIGN_NAMES:
1811 // Complete with name of signs already defined 1864 return get_nth_sign_name(idx);
1812 current_idx = 0; 1865 case EXP_SIGN_GROUPS:
1813 for (sp = first_sign; sp != NULL; sp = sp->sn_next) 1866 return get_nth_sign_group_name(idx);
1814 if (current_idx++ == idx)
1815 return sp->sn_name;
1816 return NULL;
1817 default: 1867 default:
1818 return NULL; 1868 return NULL;
1819 } 1869 }
1820 } 1870 }
1821 1871
1846 1896
1847 // :sign {subcmd} {subcmd_args} 1897 // :sign {subcmd} {subcmd_args}
1848 // | 1898 // |
1849 // begin_subcmd_args 1899 // begin_subcmd_args
1850 begin_subcmd_args = skipwhite(end_subcmd); 1900 begin_subcmd_args = skipwhite(end_subcmd);
1851 p = skiptowhite(begin_subcmd_args); 1901
1852 if (*p == NUL) 1902 // expand last argument of subcmd
1853 { 1903
1854 // 1904 // :sign define {name} {args}...
1855 // Expand first argument of subcmd when possible. 1905 // |
1856 // For ":jump {id}" and ":unplace {id}", we could 1906 // p
1857 // possibly expand the ids of all signs already placed. 1907
1858 // 1908 // Loop until reaching last argument.
1859 xp->xp_pattern = begin_subcmd_args; 1909 p = begin_subcmd_args;
1910 do
1911 {
1912 p = skipwhite(p);
1913 last = p;
1914 p = skiptowhite(p);
1915 } while (*p != NUL);
1916
1917 p = vim_strchr(last, '=');
1918
1919 // :sign define {name} {args}... {last}=
1920 // | |
1921 // last p
1922 if (p == NULL)
1923 {
1924 // Expand last argument name (before equal sign).
1925 xp->xp_pattern = last;
1860 switch (cmd_idx) 1926 switch (cmd_idx)
1861 { 1927 {
1928 case SIGNCMD_DEFINE:
1929 expand_what = EXP_DEFINE;
1930 break;
1931 case SIGNCMD_PLACE:
1932 // List placed signs
1933 if (VIM_ISDIGIT(*begin_subcmd_args))
1934 // :sign place {id} {args}...
1935 expand_what = EXP_PLACE;
1936 else
1937 // :sign place {args}...
1938 expand_what = EXP_LIST;
1939 break;
1862 case SIGNCMD_LIST: 1940 case SIGNCMD_LIST:
1863 case SIGNCMD_UNDEFINE: 1941 case SIGNCMD_UNDEFINE:
1864 // :sign list <CTRL-D> 1942 // :sign list <CTRL-D>
1865 // :sign undefine <CTRL-D> 1943 // :sign undefine <CTRL-D>
1866 expand_what = EXP_SIGN_NAMES; 1944 expand_what = EXP_SIGN_NAMES;
1867 break;
1868 default:
1869 xp->xp_context = EXPAND_NOTHING;
1870 }
1871 return;
1872 }
1873
1874 // expand last argument of subcmd
1875
1876 // :sign define {name} {args}...
1877 // |
1878 // p
1879
1880 // Loop until reaching last argument.
1881 do
1882 {
1883 p = skipwhite(p);
1884 last = p;
1885 p = skiptowhite(p);
1886 } while (*p != NUL);
1887
1888 p = vim_strchr(last, '=');
1889
1890 // :sign define {name} {args}... {last}=
1891 // | |
1892 // last p
1893 if (p == NULL)
1894 {
1895 // Expand last argument name (before equal sign).
1896 xp->xp_pattern = last;
1897 switch (cmd_idx)
1898 {
1899 case SIGNCMD_DEFINE:
1900 expand_what = EXP_DEFINE;
1901 break;
1902 case SIGNCMD_PLACE:
1903 expand_what = EXP_PLACE;
1904 break; 1945 break;
1905 case SIGNCMD_JUMP: 1946 case SIGNCMD_JUMP:
1906 case SIGNCMD_UNPLACE: 1947 case SIGNCMD_UNPLACE:
1907 expand_what = EXP_UNPLACE; 1948 expand_what = EXP_UNPLACE;
1908 break; 1949 break;
1915 // Expand last argument value (after equal sign). 1956 // Expand last argument value (after equal sign).
1916 xp->xp_pattern = p + 1; 1957 xp->xp_pattern = p + 1;
1917 switch (cmd_idx) 1958 switch (cmd_idx)
1918 { 1959 {
1919 case SIGNCMD_DEFINE: 1960 case SIGNCMD_DEFINE:
1920 if (STRNCMP(last, "texthl", p - last) == 0 1961 if (STRNCMP(last, "texthl", 6) == 0
1921 || STRNCMP(last, "linehl", p - last) == 0) 1962 || STRNCMP(last, "linehl", 6) == 0)
1922 xp->xp_context = EXPAND_HIGHLIGHT; 1963 xp->xp_context = EXPAND_HIGHLIGHT;
1923 else if (STRNCMP(last, "icon", p - last) == 0) 1964 else if (STRNCMP(last, "icon", 4) == 0)
1924 xp->xp_context = EXPAND_FILES; 1965 xp->xp_context = EXPAND_FILES;
1925 else 1966 else
1926 xp->xp_context = EXPAND_NOTHING; 1967 xp->xp_context = EXPAND_NOTHING;
1927 break; 1968 break;
1928 case SIGNCMD_PLACE: 1969 case SIGNCMD_PLACE:
1929 if (STRNCMP(last, "name", p - last) == 0) 1970 if (STRNCMP(last, "name", 4) == 0)
1930 expand_what = EXP_SIGN_NAMES; 1971 expand_what = EXP_SIGN_NAMES;
1972 else if (STRNCMP(last, "group", 5) == 0)
1973 expand_what = EXP_SIGN_GROUPS;
1974 else if (STRNCMP(last, "file", 4) == 0)
1975 xp->xp_context = EXPAND_BUFFERS;
1976 else
1977 xp->xp_context = EXPAND_NOTHING;
1978 break;
1979 case SIGNCMD_UNPLACE:
1980 case SIGNCMD_JUMP:
1981 if (STRNCMP(last, "group", 5) == 0)
1982 expand_what = EXP_SIGN_GROUPS;
1983 else if (STRNCMP(last, "file", 4) == 0)
1984 xp->xp_context = EXPAND_BUFFERS;
1931 else 1985 else
1932 xp->xp_context = EXPAND_NOTHING; 1986 xp->xp_context = EXPAND_NOTHING;
1933 break; 1987 break;
1934 default: 1988 default:
1935 xp->xp_context = EXPAND_NOTHING; 1989 xp->xp_context = EXPAND_NOTHING;