diff options
author | Michal Mazurek <akfaew@jasminek.net> | 2011-08-03 16:21:04 +0000 |
---|---|---|
committer | Michal Mazurek <akfaew@jasminek.net> | 2011-08-03 16:21:04 +0000 |
commit | 52c0899bfce7678036487061f2782469f68b8a8b (patch) | |
tree | cdf0cebd1de7b06d39e0e308941147ace5669b28 | |
parent | 0da4d631563d478927f2f9e20709be1ad2a7b82d (diff) | |
download | xombrero-52c0899bfce7678036487061f2782469f68b8a8b.tar.gz |
Add the "mark" buffer command. This is diff bcmd #6
ok marco, todd finds this appealing
-rw-r--r-- | xxxterm.1 | 9 | ||||
-rw-r--r-- | xxxterm.c | 52 |
2 files changed, 61 insertions, 0 deletions
diff --git a/xxxterm.1 b/xxxterm.1 index ab2baca..bd81b86 100644 --- a/xxxterm.1 +++ b/xxxterm.1 @@ -574,6 +574,15 @@ level up means going to a uri obtained from the current one by removing the last slash ('/') character and everything that follows it .It Cm gh open the home page in the current tab +.It Cm m[a-zA-Z0-9] +set a mark denoted by +.Cm arg +at the current page position. These marks behave like those in vi or +less. +.It Cm [`'][a-zA-Z0-9] +go to the position where mark +.Cm arg +was set .It Cm M[a-zA-Z0-9] set the current uri as quickmark .Cm arg diff --git a/xxxterm.c b/xxxterm.c index 0323e61..51f71e5 100644 --- a/xxxterm.c +++ b/xxxterm.c @@ -247,6 +247,9 @@ struct tab { /* settings */ WebKitWebSettings *settings; gchar *user_agent; + + /* marks */ + double mark[XT_NOMARKS]; }; TAILQ_HEAD(tab_list, tab); @@ -337,6 +340,7 @@ struct karg { #define XT_MAX_UNDO_CLOSE_TAB (32) #define XT_RESERVED_CHARS "$&+,/:;=?@ \"<>#%%{}|^~[]`" #define XT_PRINT_EXTRA_MARGIN 10 +#define XT_INVALID_MARK (-1) /* XXX this is a double, maybe use something else, like a nan */ /* colors */ #define XT_COLOR_RED "#cc0000" @@ -414,6 +418,9 @@ struct karg { #define XT_QMARK_OPEN (1) #define XT_QMARK_TAB (2) +#define XT_MARK_SET (0) +#define XT_MARK_GOTO (1) + #define XT_TAB_LAST (-4) #define XT_TAB_FIRST (-3) #define XT_TAB_PREV (-2) @@ -606,6 +613,7 @@ void recalc_tabs(void); void recolor_compact_tabs(void); void set_current_tab(int page_num); gboolean update_statusbar_position(GtkAdjustment* adjustment, gpointer data); +void marks_clear(struct tab *t); struct special { int (*set)(struct settings *, char *); @@ -1665,6 +1673,7 @@ load_uri(struct tab *t, gchar *uri) } set_status(t, (char *)uri, XT_STATUS_LOADING); + marks_clear(t); webkit_web_view_load_uri(t->wv, uri); if (newuri) @@ -2184,6 +2193,7 @@ run_script(struct tab *t, char *s) /* handle return value right here */ if (!strncmp(es, XT_JS_OPEN, XT_JS_OPEN_LEN)) { disable_hints(t); + marks_clear(t); webkit_web_view_load_uri(t->wv, &es[XT_JS_OPEN_LEN]); } @@ -3752,9 +3762,11 @@ navaction(struct tab *t, struct karg *args) switch (args->i) { case XT_NAV_BACK: + marks_clear(t); webkit_web_view_go_back(t->wv); break; case XT_NAV_FORWARD: + marks_clear(t); webkit_web_view_go_forward(t->wv); break; case XT_NAV_RELOAD: @@ -5771,6 +5783,7 @@ activate_search_entry_cb(GtkWidget* entry, struct tab *t) newuri = g_strdup_printf(search_string, enc_search); g_free(enc_search); + marks_clear(t); webkit_web_view_load_uri(t->wv, newuri); focus_webview(t); @@ -6645,6 +6658,40 @@ webview_hover_cb(WebKitWebView *wv, gchar *title, gchar *uri, struct tab *t) } int +mark(struct tab *t, struct karg *arg) +{ + char mark; + int index; + + mark = arg->s[1]; + if ((index = marktoindex(mark)) == -1) + return -1; + + if (arg->i == XT_MARK_SET) + t->mark[index] = gtk_adjustment_get_value(t->adjust_v); + else if (arg->i == XT_MARK_GOTO) { + if (t->mark[index] == XT_INVALID_MARK) { + show_oops(t, "mark '%c' does not exist", mark); + return -1; + } + /* XXX t->mark[index] can be bigger than the maximum if ajax or + something changes the document size */ + gtk_adjustment_set_value(t->adjust_v, t->mark[index]); + } + + return 0; +} + +void +marks_clear(struct tab *t) +{ + int i; + + for (i = 0; i < LENGTH(t->mark); i++) + t->mark[i] = XT_INVALID_MARK; +} + +int qmarks_load() { char file[PATH_MAX]; @@ -6817,6 +6864,8 @@ struct buffercmd { { "^gG$", move, XT_MOVE_BOTTOM }, { "^[0-9]+%$", move, XT_MOVE_PERCENT }, { "^gh$", go_home, 0 }, + { "^m[a-zA-Z0-9]$", mark, XT_MARK_SET }, + { "^[`'][a-zA-Z0-9]$", mark, XT_MARK_GOTO }, { "^[0-9]+t$", gototab, 0 }, { "^M[a-zA-Z0-9]$", qmark, XT_QMARK_SET }, { "^go[a-zA-Z0-9]$", qmark, XT_QMARK_OPEN }, @@ -8157,6 +8206,9 @@ create_new_tab(char *title, struct undo *u, int focus, int position) gtk_box_pack_start(GTK_BOX(t->vbox), t->toolbar, FALSE, FALSE, 0); + /* marks */ + marks_clear(t); + /* browser */ t->browser_win = create_browser(t); gtk_box_pack_start(GTK_BOX(t->vbox), t->browser_win, TRUE, TRUE, 0); |