Discussion:
[PATCH] Add commands to goto the top/middle/bottom of the visible window
Johannes Weißl
2012-06-14 17:37:50 UTC
Permalink
:win-page-top
:win-page-middle
:win-page-bottom

Suggested-by: ale rimoldi <***@xox.ch>
---
Doc/cmus.txt | 9 +++++++++
command_mode.c | 24 ++++++++++++++++++++++++
window.c | 28 ++++++++++++++++++++++++++++
window.h | 3 +++
4 files changed, 64 insertions(+)

diff --git a/Doc/cmus.txt b/Doc/cmus.txt
index c1b4654..fa8b37d 100644
--- a/Doc/cmus.txt
+++ b/Doc/cmus.txt
@@ -677,9 +677,18 @@ win-mv-before (*P*)
win-next (*tab*)
Activate next window. Only relevant in view 1.

+win-page-bottom
+ Goto the bottom of the visible part of the current window.
+
win-page-down (*^F*, *page_down*)
Goto down one page in the current window.

+win-page-middle
+ Goto the middle of the visible part of the current window.
+
+win-page-top
+ Goto the top of the visible part of the current window.
+
win-page-up (*^B*, *page_up*)
Goto up one page in the current window.

diff --git a/command_mode.c b/command_mode.c
index cc6ff08..6f3a374 100644
--- a/command_mode.c
+++ b/command_mode.c
@@ -1670,6 +1670,27 @@ static void cmd_win_pg_up(char *arg)
editable_unlock();
}

+static void cmd_win_pg_top(char *arg)
+{
+ editable_lock();
+ window_page_top(current_win());
+ editable_unlock();
+}
+
+static void cmd_win_pg_bottom(char *arg)
+{
+ editable_lock();
+ window_page_bottom(current_win());
+ editable_unlock();
+}
+
+static void cmd_win_pg_middle(char *arg)
+{
+ editable_lock();
+ window_page_middle(current_win());
+ editable_unlock();
+}
+
static void cmd_win_update_cache(char *arg)
{
struct track_info_selection sel = { .tis = NULL };
@@ -2500,7 +2521,10 @@ struct command commands[] = {
{ "win-mv-after", cmd_win_mv_after,0, 0, NULL, 0, 0 },
{ "win-mv-before", cmd_win_mv_before,0, 0, NULL, 0, 0 },
{ "win-next", cmd_win_next, 0, 0, NULL, 0, 0 },
+ { "win-page-bottom", cmd_win_pg_bottom,0, 0, NULL, 0, 0 },
{ "win-page-down", cmd_win_pg_down,0, 0, NULL, 0, 0 },
+ { "win-page-middle", cmd_win_pg_middle,0, 0, NULL, 0, 0 },
+ { "win-page-top", cmd_win_pg_top, 0, 0, NULL, 0, 0 },
{ "win-page-up", cmd_win_pg_up, 0, 0, NULL, 0, 0 },
{ "win-remove", cmd_win_remove, 0, 0, NULL, 0, CMD_UNSAFE },
{ "win-sel-cur", cmd_win_sel_cur,0, 0, NULL, 0, 0 },
diff --git a/window.c b/window.c
index a8e2bdb..667ca51 100644
--- a/window.c
+++ b/window.c
@@ -313,6 +313,34 @@ void window_page_down(struct window *win)
window_down(win, win->nr_rows - 1);
}

+static void window_goto_pos(struct window *win, int pos)
+{
+ struct iter old_sel;
+ int i;
+
+ old_sel = win->sel;
+ win->sel = win->top;
+ for (i = 0; i < pos; i++)
+ win->get_next(&win->sel);
+ if (!iters_equal(&old_sel, &win->sel))
+ sel_changed(win);
+}
+
+void window_page_top(struct window *win)
+{
+ window_goto_pos(win, 0);
+}
+
+void window_page_bottom(struct window *win)
+{
+ window_goto_pos(win, win->nr_rows - 1);
+}
+
+void window_page_middle(struct window *win)
+{
+ window_goto_pos(win, win->nr_rows / 2);
+}
+
int window_get_nr_rows(struct window *win)
{
return win->nr_rows;
diff --git a/window.h b/window.h
index e0bbdf2..da7b543 100644
--- a/window.h
+++ b/window.h
@@ -89,6 +89,9 @@ void window_goto_top(struct window *win);
void window_goto_bottom(struct window *win);
void window_page_up(struct window *win);
void window_page_down(struct window *win);
+void window_page_top(struct window *win);
+void window_page_bottom(struct window *win);
+void window_page_middle(struct window *win);

int window_get_nr_rows(struct window *win);
--
1.7.10
Gregory Petrosyan
2012-06-15 08:44:40 UTC
Permalink
Post by Johannes Weißl
:win-page-top
:win-page-middle
:win-page-bottom
Hope someone will later come up with a good idea about the bindings! Merged,
thanks.

Gregory

Loading...