Added m-{a-z} and '-{a-z} commands (#57).
authorDaniel Carl <danielcarl@gmx.de>
Mon, 13 Jan 2014 21:05:17 +0000 (22:05 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Mon, 13 Jan 2014 21:05:17 +0000 (22:05 +0100)
These commands allow to set or jump to marked place of the current opened
page.

doc/vimb.1
src/main.c
src/main.h
src/normal.c

index 92cf5f5..1c55ee4 100644 (file)
@@ -172,6 +172,14 @@ Follow the last \fIN\fPth link matching `nextpattern'.
 .TP
 .BI [ N ][\-[
 Follow the last \fIN\fPth link matching `previouspattern'.
+.TP
+.BI m\-{ a-z }
+Set a page mark {\fIa-z\fP} at current possition on page. Such set marks are
+only available on the current page, if the page is left, all marks will be
+removed.
+.TP
+.BI '\-{ a-z }
+Jump to the mark {\fIa-z\fP} on current page.
 .SS Hinting
 The hinting is the way to do what you would do with the mouse in common
 mouse-driven browsers. Open URI, yank URI, save page and so on. If the hinting
index 14d14ca..1b7e3a3 100644 (file)
@@ -70,6 +70,7 @@ static void download_progress_cp(WebKitDownload *download, GParamSpec *pspec);
 /* functions */
 static void update_title(void);
 static void init_core(void);
+static void marks_clear(void);
 static void read_config(void);
 static void setup_signals();
 static void init_files(void);
@@ -408,6 +409,8 @@ static void webview_load_status_cb(WebKitWebView *view, GParamSpec *pspec)
             vb_update_statusbar();
             vb_update_urlbar(uri);
 
+            /* clear possible set marks */
+            marks_clear();
             break;
 
         case WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT:
@@ -592,6 +595,9 @@ static void init_core(void)
     mode_add('i', input_enter, input_leave, input_keypress, NULL);
     mode_add('p', pass_enter, pass_leave, pass_keypress, NULL);
 
+    /* initialize the marks with empty values */
+    marks_clear();
+
     init_files();
     session_init();
     setting_init();
@@ -610,6 +616,16 @@ static void init_core(void)
     gtk_widget_show_all(gui->window);
 }
 
+static void marks_clear(void)
+{
+    int i;
+
+    /* init empty marks array */
+    for (i = 0; i < VB_MARK_SIZE; i++) {
+        vb.state.marks[i] = -1;
+    }
+}
+
 static void read_config(void)
 {
     char *line, **lines;
index 3148506..c95f5dd 100644 (file)
 #define VB_WIDGET_SET_STATE(w, s)       (gtk_widget_set_state(w, s))
 #endif
 
+#define VB_MARK_CHARS   "abcdefghijklmnopqrstuvwxyz"
+#define VB_MARK_SIZE    (sizeof(VB_MARK_CHARS) - 1)
+
 /* enums */
 typedef enum {
     RESULT_COMPLETE,
@@ -274,6 +277,7 @@ typedef struct {
     char            *title;                 /* holds the window title */
 #define PROMPT_SIZE 4
     char            prompt[PROMPT_SIZE];    /* current prompt ':', 'g;t', '/' including nul */
+    gdouble         marks[VB_MARK_SIZE];    /* holds marks set to page with 'm{markchar}' */
 } State;
 
 typedef struct {
index 3e7b8f4..61fc739 100644 (file)
@@ -60,6 +60,7 @@ static VbResult normal_g_cmd(const NormalCmdInfo *info);
 static VbResult normal_hint(const NormalCmdInfo *info);
 static VbResult normal_do_hint(const char *prompt);
 static VbResult normal_input_open(const NormalCmdInfo *info);
+static VbResult normal_mark(const NormalCmdInfo *info);
 static VbResult normal_navigate(const NormalCmdInfo *info);
 static VbResult normal_open_clipboard(const NormalCmdInfo *info);
 static VbResult normal_open(const NormalCmdInfo *info);
@@ -117,7 +118,7 @@ static struct {
 /* $   0x24 */ {normal_scroll},
 /* %   0x25 */ {NULL},
 /* &   0x26 */ {NULL},
-/* '   0x27 */ {NULL},
+/* '   0x27 */ {normal_mark},
 /* (   0x28 */ {NULL},
 /* )   0x29 */ {NULL},
 /* *   0x2a */ {normal_search_selection},
@@ -187,7 +188,7 @@ static struct {
 /* j   0x6a */ {normal_scroll},
 /* k   0x6b */ {normal_scroll},
 /* l   0x6c */ {normal_scroll},
-/* m   0x6d */ {NULL},
+/* m   0x6d */ {normal_mark},
 /* n   0x6e */ {normal_search},
 /* o   0x6f */ {normal_input_open},
 /* p   0x70 */ {normal_open_clipboard},
@@ -258,7 +259,7 @@ VbResult normal_keypress(int key)
         info.phase = PHASE_COMPLETE;
     } else if (info.phase == PHASE_START && isdigit(key)) {
         info.count = info.count * 10 + key - '0';
-    } else if (strchr(";zg[]", (char)key)) {
+    } else if (strchr(";zg[]'m", (char)key)) {
         /* handle commands that needs additional char */
         info.phase      = PHASE_KEY2;
         info.key        = key;
@@ -496,6 +497,30 @@ static VbResult normal_input_open(const NormalCmdInfo *info)
     return RESULT_COMPLETE;
 }
 
+static VbResult normal_mark(const NormalCmdInfo *info)
+{
+    char *mark;
+    int  idx;
+    /* check if the second char is a valid mark char */
+    if (!(mark = strchr(VB_MARK_CHARS, info->key2))) {
+        return RESULT_ERROR;
+    }
+
+    /* get the index of the mark char */
+    idx = mark - VB_MARK_CHARS;
+
+    if ('m' == info->key) {
+        vb.state.marks[idx] = gtk_adjustment_get_value(vb.gui.adjust_v);
+    } else {
+        /* check if the mark was set */
+        if ((int)(vb.state.marks[idx] - .5) < 0) {
+            return RESULT_ERROR;
+        }
+        gtk_adjustment_set_value(vb.gui.adjust_v, vb.state.marks[idx]);
+    }
+    return RESULT_COMPLETE;
+}
+
 static VbResult normal_navigate(const NormalCmdInfo *info)
 {
     int count;