aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-06-25 10:42:10 +0200
committerOmar Polo <op@omarpolo.com>2021-06-25 10:42:10 +0200
commit1c412d480d6f8b782a3aa610e0396a678bfecddb (patch)
tree4afdf12a20ad91ac39c79e38fc2a2353c167cb11
parent355bef226138f678eb361d2bf22a519aac1480db (diff)
downloadtelescope-1c412d480d6f8b782a3aa610e0396a678bfecddb.tar.gz
telescope-1c412d480d6f8b782a3aa610e0396a678bfecddb.tar.bz2
added next/previous-heading
-rw-r--r--ChangeLog5
-rw-r--r--cmd.c44
-rw-r--r--cmd.h2
-rw-r--r--telescope.18
-rw-r--r--ui.c3
5 files changed, 62 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 6aa7db1..0cc60ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2021-06-25 Omar Polo <op@omarpolo.com>
+
+ * cmd.c (cmd_next_heading): added next-heading (C-c n)
+ (cmd_previous_heading): added previous-heading (C-c p)
+
2021-06-24 Omar Polo <op@omarpolo.com>
* ui.c (load_default_keys): bind > to load-url
diff --git a/cmd.c b/cmd.c
index 10a5e49..0dfc9e5 100644
--- a/cmd.c
+++ b/cmd.c
@@ -276,6 +276,50 @@ cmd_next_button(struct buffer *buffer)
} while (buffer->current_line->parent->type != LINE_LINK);
}
+static inline int
+is_heading(const struct line *l)
+{
+ return l->type == LINE_TITLE_1 ||
+ l->type == LINE_TITLE_2 ||
+ l->type == LINE_TITLE_3;
+}
+
+void
+cmd_previous_heading(struct buffer *buffer)
+{
+ struct excursion place;
+
+ save_excursion(&place, buffer);
+
+ do {
+ if (buffer->current_line == NULL ||
+ buffer->current_line == TAILQ_FIRST(&buffer->head)) {
+ restore_excursion(&place, buffer);
+ message("No previous heading");
+ return;
+ }
+ cmd_previous_line(buffer);
+ } while (!is_heading(buffer->current_line->parent));
+}
+
+void
+cmd_next_heading(struct buffer *buffer)
+{
+ struct excursion place;
+
+ save_excursion(&place, buffer);
+
+ do {
+ if (buffer->current_line == NULL ||
+ buffer->current_line == TAILQ_LAST(&buffer->head, vhead)) {
+ restore_excursion(&place, buffer);
+ message("No next heading");
+ return;
+ }
+ cmd_next_line(buffer);
+ } while (!is_heading(buffer->current_line->parent));
+}
+
void
cmd_previous_page(struct buffer *buffer)
{
diff --git a/cmd.h b/cmd.h
index c7a8148..8cceff5 100644
--- a/cmd.h
+++ b/cmd.h
@@ -27,6 +27,8 @@ CMD(cmd_push_button);
CMD(cmd_push_button_new_tab);
CMD(cmd_previous_button);
CMD(cmd_next_button);
+CMD(cmd_previous_heading);
+CMD(cmd_next_heading);
CMD(cmd_previous_page);
CMD(cmd_next_page);
CMD(cmd_clear_minibuf);
diff --git a/telescope.1 b/telescope.1
index 837944f..e2c7d64 100644
--- a/telescope.1
+++ b/telescope.1
@@ -168,6 +168,10 @@ kill-telescope
clear-minibuf
.It M-x
execute-extended-command
+.It C-c p
+previous-heading
+.It C-c n
+next-heading
.It >
load-url
.It C-x C-f
@@ -347,10 +351,14 @@ Move point at the beginning of the current (visual) line.
Move point at the end of the current (visual) line.
.It Ic next-button
Move point to the next link.
+.It Ic next-heading
+Move point to the next heading.
.It Ic next-line
Move point to the next (visual) line, in the same column if possible.
.It Ic previous-button
Move point to the previous link.
+.It Ic previous-heading
+Move point to the previous heading.
.It Ic previous-line
Move point to the previous (visual) line.
.El
diff --git a/ui.c b/ui.c
index fd9b8a7..a5f10a6 100644
--- a/ui.c
+++ b/ui.c
@@ -180,6 +180,9 @@ load_default_keys(void)
global_set_key("M-x", cmd_execute_extended_command);
+ global_set_key("C-c p", cmd_previous_heading);
+ global_set_key("C-c n", cmd_next_heading);
+
global_set_key(">", cmd_load_url);
global_set_key("C-x C-f", cmd_load_url);
global_set_key("C-x M-f", cmd_load_current_url);