2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include "telescope.h"
25 * Provide completions for execute-extended-command (eecmd).
28 compl_eecmd(void **data, void **ret, const char **descr)
30 struct cmd **state = (struct cmd **)data;
32 /* first time: init the state */
36 if ((*state)->cmd == NULL)
39 *descr = (*state)->descr;
40 return (*state)++->cmd;
44 * Provide completions for tab-select.
47 compl_ts(void **data, void **ret, const char **descr)
49 struct tab **tab = (struct tab **)data;
51 /* first time: init the state */
53 *tab = TAILQ_FIRST(&tabshead);
54 else if ((*tab = TAILQ_NEXT(*tab, tabs)) == NULL)
59 if (*(*tab)->buffer.page.title == '\0')
60 return (*tab)->hist_cur->h;
61 *descr = (*tab)->hist_cur->h;
62 return (*tab)->buffer.page.title;
66 * Provide completions for link-select.
69 compl_ls(void **data, void **ret, const char **descr)
71 struct line **line = (struct line **)data;
76 while (l != NULL && l->type != LINE_LINK)
77 l = TAILQ_NEXT(l, lines);
83 if ((link = l->line) == NULL) {
90 *line = TAILQ_NEXT(l, lines);
95 * Provide completions for swiper.
98 compl_swiper(void **data, void **ret, const char **descr)
100 struct line **line = (struct line **)data;
103 while (*line != NULL && (*line)->line == NULL)
104 *line = TAILQ_NEXT(*line, lines);
109 text = (*line)->line;
111 *line = TAILQ_NEXT(*line, lines);
116 * Provide completions for toc
119 compl_toc(void **data, void **ret, const char **descr)
121 struct line **line = (struct line **)data;
126 while (l != NULL && (l->line == NULL ||
127 (l->type != LINE_TITLE_1 &&
128 l->type != LINE_TITLE_2 &&
129 l->type != LINE_TITLE_3)))
130 l = TAILQ_NEXT(l, lines);
138 *line = TAILQ_NEXT(l, lines);