Commit Diff


commit - e427b5d09369c9ddc37f4997c80462361ee0a55e
commit + edd9a650d8d4794139f5e32b9d2ea6abc1e78a84
blob - 507a8c83952f012c75e524d3f698f5eb640130a5
blob + 7f1c5d3720d41147accd18265792a9d731f6e670
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,9 @@
+2021-07-15  Omar Polo  <op@omarpolo.com>
+
+	* defaults.c (load_default_keys): bind t to toc
+
+	* cmd.c (cmd_toc): add toc
+
 2021-07-14  Omar Polo  <op@omarpolo.com>
 
 	* defaults.c (load_default_keys): bind M-L to link-select
blob - 13ef1e8480f65cd928897a7238162eb2f281fe8b
blob + c606a8a6d5b408f4a5573e6fa819cd138719b1a6
--- cmd.c
+++ cmd.c
@@ -581,6 +581,20 @@ cmd_swiper(struct buffer *buffer)
 	enter_minibuffer(sensible_self_insert, swiper_select, exit_minibuffer,
 	    NULL, compl_swiper, TAILQ_FIRST(&buffer->page.head));
 	strlcpy(ministate.prompt, "Select line: ", sizeof(ministate.prompt));
+}
+
+void
+cmd_toc(struct buffer *buffer)
+{
+	if (in_minibuffer) {
+		message("We don't have enable-recursive-minibuffers");
+		return;
+	}
+
+	enter_minibuffer(sensible_self_insert, toc_select, exit_minibuffer,
+	    NULL, compl_toc, TAILQ_FIRST(&buffer->page.head));
+	strlcpy(ministate.prompt, "Select heading: ",
+	    sizeof(ministate.prompt));
 }
 
 void
blob - 227bf3ff7479cefd2f2b35611bb7c2b86ef2d988
blob + efe85c819c64194aa642ef52f03670ac95911c66
--- cmd.h
+++ cmd.h
@@ -57,6 +57,7 @@ CMD(cmd_toggle_help);
 
 CMD(cmd_link_select);
 CMD(cmd_swiper);
+CMD(cmd_toc);
 
 CMD(cmd_inc_fill_column);
 CMD(cmd_dec_fill_column);
blob - b9ccbc738a4ebfdad48680cd847a2685ffff08ae
blob + f248a4bc4328eda9e59316ef8ae08c7a90634dc4
--- compl.c
+++ compl.c
@@ -102,3 +102,30 @@ compl_swiper(void **data, void **ret)
 	*line = TAILQ_NEXT(*line, lines);
 	return text;
 }
+
+/*
+ * Provide completions for toc
+ */
+const char *
+compl_toc(void **data, void **ret)
+{
+	struct line	**line = (struct line **)data;
+	struct line	*l;
+	const char	*text;
+
+	l = *line;
+	while (l != NULL &&
+	    l->type != LINE_TITLE_1 &&
+	    l->type != LINE_TITLE_2 &&
+	    l->type != LINE_TITLE_3)
+		l = TAILQ_NEXT(l, lines);
+
+	/* end of buffer */
+	if (l == NULL)
+		return NULL;
+
+	text = l->line;
+	*ret = l;
+	*line = TAILQ_NEXT(l, lines);
+	return text;
+}
blob - f1f98044e05a618124876db167f4fcaa1d4b9be3
blob + 2c7008336e7f79ffac30ca77847323dedfc5cc17
--- compl.h
+++ compl.h
@@ -21,5 +21,6 @@ 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 **);
 
 #endif
blob - bda216af5d2d4091efe0a0de4e7e40fb95b40cab
blob + f24ee9563c3abb2d9ad32ce41dfb5eb625a823b9
--- minibuffer.c
+++ minibuffer.c
@@ -283,6 +283,20 @@ jump_to_line(struct line *l)
 
 void
 swiper_select(void)
+{
+	struct line	*l;
+
+	if ((l = minibuffer_metadata()) == NULL) {
+		message("No line selected");
+		return;
+	}
+
+	exit_minibuffer();
+	jump_to_line(l);
+}
+
+void
+toc_select(void)
 {
 	struct line	*l;
 
blob - 1f5cbed437ee9f3ad8d621f47dfa8b6263c0d9d9
blob + 3122276ec1fb889d51dfc6949ca481f422ebe850
--- minibuffer.h
+++ minibuffer.h
@@ -75,6 +75,7 @@ void	 bp_select(void);
 void	 ts_select(void);
 void	 ls_select(void);
 void	 swiper_select(void);
+void	 toc_select(void);
 
 void	 enter_minibuffer(void(*)(void), void(*)(void), void(*)(void),
     struct histhead *,
blob - 025bd1e18ef08a04c142e7b5b208c1915bdd2ac4
blob + 2f62250aa909bbd36238614a21416050435e7b3e
--- telescope.1
+++ telescope.1
@@ -474,6 +474,8 @@ Scroll up by one line.
 Scroll up by one visual page.
 .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.
 .It Ic toggle-help
 Toggle side window with help about available keys and their associated
 interactive command.