commit - ab9de1611f1ef9b6436c7253064801259c54ab6d
commit + b3be07eaecf5d226ff4bb675d86fedda432b2e5b
blob - 9d704ebc217737c63b2b5b1f1144b3c1caf5ec32
blob + 9c8e763cda7dbd381e15afd454c5e52cc7d5bd4e
--- ChangeLog
+++ ChangeLog
+2021-07-18 Omar Polo <op@omarpolo.com>
+
+ * minibuffer.c (populate_compl_buffer): add an optional description to completion items.
+ (recompute_completions): filter completion results using the description too (if available)
+
2021-07-17 Omar Polo <op@omarpolo.com>
* telescope.c (load_url): lazy loading for telescope: don't load all the tabs when starting up, only the current one. Defer the loading of the others when switching to them.
blob - 76faa5a173f140f4347a5d30db2264f8a91dca06
blob + e9bb9ef720e8a94495753a15802443db171073de
--- cmd.h
+++ cmd.h
struct buffer;
-#define CMD(fnname) void fnname(struct buffer *)
-#define DEFALIAS(s, d) /* nothing */
+#define CMD(fnname, descr) void fnname(struct buffer *)
+#define DEFALIAS(s, d) /* nothing */
-CMD(cmd_backward_char);
-CMD(cmd_backward_paragraph);
-CMD(cmd_beginning_of_buffer);
-CMD(cmd_bookmark_page);
-CMD(cmd_clear_minibuf);
-CMD(cmd_dec_fill_column);
-CMD(cmd_end_of_buffer);
-CMD(cmd_execute_extended_command);
-CMD(cmd_forward_char);
-CMD(cmd_forward_paragraph);
-CMD(cmd_inc_fill_column);
-CMD(cmd_insert_current_candidate);
-CMD(cmd_kill_telescope);
-CMD(cmd_link_select);
-CMD(cmd_list_bookmarks);
-CMD(cmd_load_current_url);
-CMD(cmd_load_url);
-CMD(cmd_mini_abort);
-CMD(cmd_mini_complete_and_exit);
-CMD(cmd_mini_delete_backward_char);
-CMD(cmd_mini_delete_char);
-CMD(cmd_mini_goto_beginning);
-CMD(cmd_mini_goto_end);
-CMD(cmd_mini_kill_line);
-CMD(cmd_mini_next_history_element);
-CMD(cmd_mini_previous_history_element);
-CMD(cmd_move_beginning_of_line);
-CMD(cmd_move_end_of_line);
-CMD(cmd_next_button);
-CMD(cmd_next_completion);
-CMD(cmd_next_heading);
-CMD(cmd_next_line);
-CMD(cmd_next_page);
-CMD(cmd_olivetti_mode);
-CMD(cmd_previous_button);
-CMD(cmd_previous_completion);
-CMD(cmd_previous_heading);
-CMD(cmd_previous_line);
-CMD(cmd_previous_page);
-CMD(cmd_push_button);
-CMD(cmd_push_button_new_tab);
-CMD(cmd_redraw);
-CMD(cmd_reload_page);
-CMD(cmd_scroll_down);
-CMD(cmd_scroll_line_down);
-CMD(cmd_scroll_line_up);
-CMD(cmd_scroll_up);
-CMD(cmd_suspend_telescope);
-CMD(cmd_swiper);
-CMD(cmd_tab_close);
-CMD(cmd_tab_close_other);
-CMD(cmd_tab_move);
-CMD(cmd_tab_move_to);
-CMD(cmd_tab_new);
-CMD(cmd_tab_next);
-CMD(cmd_tab_previous);
-CMD(cmd_tab_select);
-CMD(cmd_toc);
-CMD(cmd_toggle_help);
-CMD(cmd_toggle_pre_wrap);
+CMD(cmd_backward_char, "Move point one character backward.");
+CMD(cmd_backward_paragraph, "Move point on paragraph backward.");
+CMD(cmd_beginning_of_buffer, "Move point to the beginning of the buffer.");
+CMD(cmd_bookmark_page, "Save a page in the bookmark file.");
+CMD(cmd_clear_minibuf, "Clear the echo area.");
+CMD(cmd_dec_fill_column, "Decrement fill-column by two.");
+CMD(cmd_end_of_buffer, "Move the point to the end of the buffer.");
+CMD(cmd_execute_extended_command, "Execute an internal command.");
+CMD(cmd_forward_char, "Move point one character forward.");
+CMD(cmd_forward_paragraph, "Move point one paragraph forward.");
+CMD(cmd_inc_fill_column, "Increment fill-column by two");
+CMD(cmd_insert_current_candidate, "Copy the current selection text as minibuffer input.");
+CMD(cmd_kill_telescope, "Quit Telescope.");
+CMD(cmd_link_select, "Select and visit a link using the minibuffer.");
+CMD(cmd_list_bookmarks, "Load the bookmarks page.");
+CMD(cmd_load_current_url, "Edit the current URL.");
+CMD(cmd_load_url, "Prompt for an URL.");
+CMD(cmd_mini_abort, "Abort the current minibuffer action.");
+CMD(cmd_mini_complete_and_exit, "Complete the current minibuffer action.");
+CMD(cmd_mini_delete_backward_char, "Delete the character before the point.");
+CMD(cmd_mini_delete_char, "Delete the character after the point.");
+CMD(cmd_mini_goto_beginning, "Select the first completion.");
+CMD(cmd_mini_goto_end, "Select the last completion.");
+CMD(cmd_mini_kill_line, "Delete from point until the end of the line.");
+CMD(cmd_mini_next_history_element, "Load the next history element.");
+CMD(cmd_mini_previous_history_element, "Load the previous history element.");
+CMD(cmd_move_beginning_of_line, "Move point at the beginning of the current visual line.");
+CMD(cmd_move_end_of_line, "Move point at the end of the current visual line.");
+CMD(cmd_next_button, "Move point to the next link.");
+CMD(cmd_next_completion, "Select the next completion.");
+CMD(cmd_next_heading, "Move point to the next heading.");
+CMD(cmd_next_line, "Move point to the next visual line.");
+CMD(cmd_next_page, "Go forward in the page history.");
+CMD(cmd_olivetti_mode, "Toggle olivetti-mode.");
+CMD(cmd_previous_button, "Move point to the previous link.");
+CMD(cmd_previous_completion, "Select the previous completion.");
+CMD(cmd_previous_heading, "Move point to the previous heading.");
+CMD(cmd_previous_line, "Move point to the previous visual line.");
+CMD(cmd_previous_page, "Go backward in the page history.");
+CMD(cmd_push_button, "Follow link at point or toggle pre-visibility.");
+CMD(cmd_push_button_new_tab, "Follow link at point in a new tab.n");
+CMD(cmd_redraw, "Redraw the screen.");
+CMD(cmd_reload_page, "Reload the current page.");
+CMD(cmd_scroll_down, "Scroll down by one visual page");
+CMD(cmd_scroll_line_down, "Scroll down by one line");
+CMD(cmd_scroll_line_up, "Scroll up by one line.");
+CMD(cmd_scroll_up, "Scroll up by one visual page");
+CMD(cmd_suspend_telescope, "Suspend the current Telescope session.");
+CMD(cmd_swiper, "Jump to a line using the minibuffer.");
+CMD(cmd_tab_close, "Close the current tab.");
+CMD(cmd_tab_close_other, "Close all tabs but the current one.");
+CMD(cmd_tab_move, "Move the current tab to the right.");
+CMD(cmd_tab_move_to, "Move the current tab to the left.");
+CMD(cmd_tab_new, "Open a new tab.");
+CMD(cmd_tab_next, "Focus next tab.");
+CMD(cmd_tab_previous, "Focus previous tab.");
+CMD(cmd_tab_select, "Switch to a tab using the minibuffer.");
+CMD(cmd_toc, "Jump to a heading using the minibuffer.");
+CMD(cmd_toggle_help, "Toggle side window with help.");
+CMD(cmd_toggle_pre_wrap, "Toggle the wrapping of preformatted blocks.");
DEFALIAS(q, cmd_kill_telescope)
DEFALIAS(tabn, cmd_tab_next)
blob - 0a7c493876aeb1857676c6804221a0a410059e95
blob + 29f34ecf5a1275a4e92d8ca93e87f13b3e535b7a
--- compl.c
+++ compl.c
* Provide completions for execute-extended-command (eecmd).
*/
const char *
-compl_eecmd(void **data, void **ret)
+compl_eecmd(void **data, void **ret, const char **descr)
{
struct cmd **state = (struct cmd **)data;
if ((*state)->cmd == NULL)
return NULL;
+ *descr = (*state)->descr;
return (*state)++->cmd;
}
* Provide completions for tab-select.
*/
const char *
-compl_ts(void **data, void **ret)
+compl_ts(void **data, void **ret, const char **descr)
{
struct tab **tab = (struct tab **)data;
if (*(*tab)->buffer.page.title == '\0')
return (*tab)->hist_cur->h;
+ *descr = (*tab)->hist_cur->h;
return (*tab)->buffer.page.title;
}
* Provide completions for link-select.
*/
const char *
-compl_ls(void **data, void **ret)
+compl_ls(void **data, void **ret, const char **descr)
{
struct line **line = (struct line **)data;
struct line *l;
if (l == NULL)
return NULL;
- if ((link = l->line) == NULL)
+ if ((link = l->line) == NULL) {
link = l->alt;
+ *descr = NULL;
+ } else
+ *descr = l->alt;
*ret = l;
*line = TAILQ_NEXT(l, lines);
* Provide completions for swiper.
*/
const char *
-compl_swiper(void **data, void **ret)
+compl_swiper(void **data, void **ret, const char **descr)
{
struct line **line = (struct line **)data;
const char *text;
* Provide completions for toc
*/
const char *
-compl_toc(void **data, void **ret)
+compl_toc(void **data, void **ret, const char **descr)
{
struct line **line = (struct line **)data;
struct line *l;
blob - 2c7008336e7f79ffac30ca77847323dedfc5cc17
blob + 895de6a295c781e74309b1b0bb844f82ae5e6f11
--- compl.h
+++ compl.h
#ifndef COMPL_H
#define COMPL_H
-const char *compl_eecmd(void **, void **);
-const char *compl_ts(void **, void **);
-const char *compl_ls(void **, void **);
-const char *compl_swiper(void **, void **);
-const char *compl_toc(void **, void **);
+const char *compl_eecmd(void **, void **, const char **);
+const char *compl_ts(void **, void **, const char **);
+const char *compl_ls(void **, void **, const char **);
+const char *compl_swiper(void **, void **, const char **);
+const char *compl_toc(void **, void **, const char **);
#endif
blob - b7c71b5cf95bda2b517ef7c5a6a5e197403acbe5
blob + 7ae780a0b0e0120f09b81338617fadfd983b56bb
--- gencmd.awk
+++ gencmd.awk
s = $2;
sub("^cmd_", "", s);
gsub("_", "-", s);
- printf("\t{ \"%s\", %s },\n", s, $2);
+ printf("\t{ \"%s\", %s, %s },\n", s, $2, $3);
next;
}
/^DEFALIAS/ {
s = $2;
d = $3;
- printf("\t{ \"%s\", %s },\n", s, d);
+ printf("\t{ \"%s\", %s, NULL },\n", s, d);
next
}
}
END {
- printf("\t{ NULL, NULL },\n");
+ printf("\t{ NULL, NULL, NULL },\n");
print "};";
}
blob - 070b0eb02e2d41e1e4177b0f99faff43cb889232
blob + e55decd47096ace54c207171f55bd45b5e98f92f
--- minibuffer.c
+++ minibuffer.c
l->type = LINE_COMPL;
if (add && l->flags & L_HIDDEN)
continue;
- if (strcasestr(l->line, ministate.buf) != NULL) {
+ if (strcasestr(l->line, ministate.buf) != NULL ||
+ (l->alt != NULL && strcasestr(l->alt, ministate.buf) != NULL)) {
if (l->flags & L_HIDDEN)
b->line_max++;
l->flags &= ~L_HIDDEN;
static inline void
populate_compl_buffer(complfn *fn, void *data)
{
- const char *s;
+ const char *s, *descr;
struct line *l;
struct buffer *b;
struct parser *p;
b = &ministate.compl.buffer;
p = &b->page;
- while ((s = fn(&data, &linedata)) != NULL) {
+ while ((s = fn(&data, &linedata, &descr)) != NULL) {
if ((l = calloc(1, sizeof(*l))) == NULL)
abort();
l->type = LINE_COMPL;
l->data = linedata;
+ l->alt = (char*)descr;
if ((l->line = strdup(s)) == NULL)
abort();
TAILQ_INSERT_TAIL(&p->head, l, lines);
linedata = NULL;
+ descr = NULL;
}
if ((l = TAILQ_FIRST(&p->head)) != NULL)
blob - 3122276ec1fb889d51dfc6949ca481f422ebe850
blob + e07841bc3b4eb1348dfa5ca514d0e9c5272ddbc6
--- minibuffer.h
+++ minibuffer.h
* signal the end of the completions, complfn should return NULL: the
* value of state will then be discarded and the function never called
* again. The second parameter is some extra metadata per-line; it'll
- * be available as line->meta.data on the selected line during the
- * minibuffer lifecycle.
+ * be available as line->data on the selected line during the
+ * minibuffer lifecycle. The third parameter is an extra description
+ * field for the current item.
*/
-typedef const char *(complfn)(void **, void **);
+typedef const char *(complfn)(void **, void **, const char **);
struct ministate {
char *curmesg;
blob - e35a439c63608e583ab15f617ea4e74c5aec5da1
blob + 69d5fc361c01198f5941c739f52b02b9fe611878
--- telescope.1
+++ telescope.1
.Ss Bookmark-related commands
.Bl -tag -width execute-extended-command -compact
.It Ic bookmark-page
-Add a link to the bookmark file.
+Save a page in the bookmark file.
It preloads the minibuffer with the current URL.
.It Ic list-bookmarks
Load the bookmarks page.
.Ss Misc commands
.Bl -tag -width execute-extended-command -compact
.It Ic clear-minibuf
-Clears the echo area.
+Clear the echo area.
.It Ic dec-fill-column
-Decrements fill-column by two.
+Decrement fill-column by two.
.It Ic execute-extended-command
-Prompts for a command name using the minibuffer.
+Execute an internal command.
.It Ic kill-telescope
Quit
.Nm .
.It Ic inc-fill-column
-Increments fill-column by two.
+Increment fill-column by two.
.It Ic link-select
Select and visit a link using the minibuffer.
.It Ic load-current-url
-Prompts for an URL, the minibuffer is preloaded with the current
-one.
+Edit the current URL.
.It Ic load-url
-Prompts for an URL.
+Prompt for an URL.
.It Ic next-page
-Load the next item in the history list.
+Go forward in the page history.
.It Ic olivetti-mode
Toggle olivetti mode (i.e. horizontal centering of the lines of the
window.)
.It Ic previous-page
-Load the previous item in the history list.
+Go backward in the page history.
.It Ic push-button
-Follow the link on the current line, or toggle the visibility of the
-following preformatted block if called when the cursor is on the
-heading of the block.
+Follow link at point, or toggle the visibility of the following
+preformatted block if called when the cursor is on the heading of the block.
.It Ic push-button-new-tab
-Follow the link on the current line on a new tab.
+Follow link at point in a new tab.
.It Ic redraw
Redraw the screen, useful if some background program messed up the
display.
.It Ic swiper
Jump to a line using the minibuffer.
.It Ic toc
-Select and jump to a heading of the page using the minibuffer.
+Jump to a heading using the minibuffer.
.It Ic toggle-help
Toggle side window with help about available keys and their associated
interactive command.
.It Ic mini-goto-end
Select the last completion, if any.
.It Ic mini-kill-line
-Delete from the point until the end of the line.
+Delete from point until the end of the line.
.It Ic mini-next-history-element
Load the previous history element.
.It Ic mini-previous-history-element
blob - a4bcbd09e802e5eaac68d7c62f8d9fc16bb4c735
blob + 0da6cb218cdd79482477250ca15f821435846658
--- telescope.h
+++ telescope.h
struct cmd {
const char *cmd;
void (*fn)(struct buffer *);
+ const char *descr;
};
extern struct cmd cmds[];
blob - c3f4512ee8ec681c6265e8fb7572ace12d8f4f97
blob + c1dbb20e11cc69f82dcf390af90f3d2ba9daef1a
--- ui.c
+++ ui.c
*prfx_ret = buf;
}
+
+static inline void
+print_vline_descr(int width, WINDOW *window, struct vline *vl)
+{
+ int x, y, goal;
+
+ if (vl->parent->type != LINE_COMPL &&
+ vl->parent->type != LINE_COMPL_CURRENT)
+ return;
+ if (vl->parent->alt == NULL)
+ return;
+
+ (void)y;
+ getyx(window, y, x);
+
+ goal = width/2;
+ if (goal <= x)
+ wprintw(window, " ");
+ for (; goal > x; ++x)
+ wprintw(window, " ");
+
+ wprintw(window, "%s", vl->parent->alt);
+}
+
/*
* Core part of the rendering. It prints a vline starting from the
* current cursor position. Printing a vline consists of skipping
wattr_on(window, f->text, NULL);
wprintw(window, "%s", text);
+ print_vline_descr(width, window, vl);
wattr_off(window, f->text, NULL);
getyx(window, y, x);
blob - 5f22692e02c8b74c7a144dd07420fb6daf6dfa24
blob + 134e93189917b4e80892236b4330d9873f3fb903
--- wrap.c
+++ wrap.c
TAILQ_FOREACH_SAFE(l, &buffer->page.head, lines, lt) {
TAILQ_REMOVE(&buffer->page.head, l, lines);
free(l->line);
- free(l->alt);
+
+ if (l->type != LINE_COMPL &&
+ l->type != LINE_COMPL_CURRENT)
+ free(l->alt);
+
free(l);
}
}