patch 8.0.1497: getting the jump list requires parsing the output of :jumps

Problem:    Getting the jump list requires parsing the output of :jumps.
Solution:   Add getjumplist(). (Yegappan Lakshmanan, closes #2609)
diff --git a/src/Makefile b/src/Makefile
index e0d601c..7cd501e 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2198,6 +2198,7 @@
 	test_job_fails \
 	test_join \
 	test_json \
+	test_jumplist \
 	test_jumps \
 	test_lambda \
 	test_langmap \
diff --git a/src/evalfunc.c b/src/evalfunc.c
index f09be92..da870c6 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -180,6 +180,7 @@
 static void f_getfsize(typval_T *argvars, typval_T *rettv);
 static void f_getftime(typval_T *argvars, typval_T *rettv);
 static void f_getftype(typval_T *argvars, typval_T *rettv);
+static void f_getjumplist(typval_T *argvars, typval_T *rettv);
 static void f_getline(typval_T *argvars, typval_T *rettv);
 static void f_getloclist(typval_T *argvars UNUSED, typval_T *rettv UNUSED);
 static void f_getmatches(typval_T *argvars, typval_T *rettv);
@@ -621,6 +622,7 @@
     {"getfsize",	1, 1, f_getfsize},
     {"getftime",	1, 1, f_getftime},
     {"getftype",	1, 1, f_getftype},
+    {"getjumplist",	0, 2, f_getjumplist},
     {"getline",		1, 2, f_getline},
     {"getloclist",	1, 2, f_getloclist},
     {"getmatches",	0, 0, f_getmatches},
@@ -4841,6 +4843,56 @@
 }
 
 /*
+ * "getjumplist()" function
+ */
+    static void
+f_getjumplist(typval_T *argvars, typval_T *rettv)
+{
+#ifdef FEAT_JUMPLIST
+    win_T	*wp;
+    int		i;
+    list_T	*l;
+    dict_T	*d;
+#endif
+
+    if (rettv_list_alloc(rettv) != OK)
+	return;
+
+#ifdef FEAT_JUMPLIST
+    wp = find_tabwin(&argvars[0], &argvars[1]);
+    if (wp == NULL)
+	return;
+
+    l = list_alloc();
+    if (l == NULL)
+	return;
+
+    if (list_append_list(rettv->vval.v_list, l) == FAIL)
+	return;
+    list_append_number(rettv->vval.v_list, (varnumber_T)wp->w_jumplistidx);
+
+    for (i = 0; i < wp->w_jumplistlen; ++i)
+    {
+	if ((d = dict_alloc()) == NULL)
+	    return;
+	if (list_append_dict(l, d) == FAIL)
+	    return;
+	dict_add_nr_str(d, "lnum", (long)wp->w_jumplist[i].fmark.mark.lnum,
+		NULL);
+	dict_add_nr_str(d, "col", (long)wp->w_jumplist[i].fmark.mark.col,
+		NULL);
+# ifdef FEAT_VIRTUALEDIT
+	dict_add_nr_str(d, "coladd", (long)wp->w_jumplist[i].fmark.mark.coladd,
+		NULL);
+# endif
+	dict_add_nr_str(d, "bufnr", (long)wp->w_jumplist[i].fmark.fnum, NULL);
+	if (wp->w_jumplist[i].fmark.fnum == 0)
+	    dict_add_nr_str(d, "filename", 0L, wp->w_jumplist[i].fname);
+    }
+#endif
+}
+
+/*
  * "getline(lnum, [end])" function
  */
     static void
@@ -5612,11 +5664,11 @@
 	"beos",
 #endif
 #ifdef MACOS_X
-       "mac",		/* Mac OS X (and, once, Mac OS Classic) */
-       "osx",		/* Mac OS X */
+	"mac",		/* Mac OS X (and, once, Mac OS Classic) */
+	"osx",		/* Mac OS X */
 # ifdef MACOS_X_DARWIN
-       "macunix",	/* Mac OS X, with the darwin feature */
-       "osxdarwin",	/* synonym for macunix */
+	"macunix",	/* Mac OS X, with the darwin feature */
+	"osxdarwin",	/* synonym for macunix */
 # endif
 #endif
 #ifdef __QNX__
diff --git a/src/list.c b/src/list.c
index b593f71..1dfaa21 100644
--- a/src/list.c
+++ b/src/list.c
@@ -475,6 +475,27 @@
 }
 
 /*
+ * Append list2 to list1.
+ * Return FAIL when out of memory.
+ */
+    int
+list_append_list(list1, list2)
+    list_T	*list1;
+    list_T	*list2;
+{
+    listitem_T	*li = listitem_alloc();
+
+    if (li == NULL)
+	return FAIL;
+    li->li_tv.v_type = VAR_LIST;
+    li->li_tv.v_lock = 0;
+    li->li_tv.vval.v_list = list2;
+    list_append(list1, li);
+    ++list2->lv_refcount;
+    return OK;
+}
+
+/*
  * Make a copy of "str" and append it as an item to list "l".
  * When "len" >= 0 use "str[len]".
  * Returns FAIL when out of memory.
diff --git a/src/proto/list.pro b/src/proto/list.pro
index fe54bab..c4fd195 100644
--- a/src/proto/list.pro
+++ b/src/proto/list.pro
@@ -21,6 +21,7 @@
 void list_append(list_T *l, listitem_T *item);
 int list_append_tv(list_T *l, typval_T *tv);
 int list_append_dict(list_T *list, dict_T *dict);
+int list_append_list(list_T *list1, list_T *list2);
 int list_append_string(list_T *l, char_u *str, int len);
 int list_append_number(list_T *l, varnumber_T n);
 int list_insert_tv(list_T *l, typval_T *tv, listitem_T *item);
diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
index 4626d80..2d98fa6 100644
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -120,6 +120,7 @@
 	    test_ins_complete.res \
 	    test_job_fails.res \
 	    test_json.res \
+	    test_jumplist.res \
 	    test_langmap.res \
 	    test_let.res \
 	    test_lineending.res \
diff --git a/src/testdir/test_jumplist.vim b/src/testdir/test_jumplist.vim
new file mode 100644
index 0000000..7079d21
--- /dev/null
+++ b/src/testdir/test_jumplist.vim
@@ -0,0 +1,64 @@
+" Tests for the jumplist functionality
+
+" Tests for the getjumplist() function
+func Test_getjumplist()
+  if !has("jumplist")
+    return
+  endif
+
+  %bwipe
+  clearjumps
+  call assert_equal([[], 0], getjumplist())
+  call assert_equal([[], 0], getjumplist(1))
+  call assert_equal([[], 0], getjumplist(1, 1))
+
+  call assert_equal([], getjumplist(100))
+  call assert_equal([], getjumplist(1, 100))
+
+  let lines = []
+  for i in range(1, 100)
+    call add(lines, "Line " . i)
+  endfor
+  call writefile(lines, "Xtest")
+
+  " Jump around and create a jump list
+  edit Xtest
+  let bnr = bufnr('%')
+  normal 50%
+  normal G
+  normal gg
+
+  call assert_equal([[
+	      \ {'lnum': 1, 'bufnr': bnr, 'col': 0, 'coladd': 0},
+	      \ {'lnum': 1, 'bufnr': bnr, 'col': 0, 'coladd': 0},
+	      \ {'lnum': 50, 'bufnr': bnr, 'col': 0, 'coladd': 0},
+	      \ {'lnum': 100, 'bufnr': bnr, 'col': 0, 'coladd': 0}], 4],
+	      \ getjumplist())
+
+  " Traverse the jump list and verify the results
+  5
+  exe "normal \<C-O>"
+  call assert_equal(2, getjumplist(1)[1])
+  exe "normal 2\<C-O>"
+  call assert_equal(0, getjumplist(1, 1)[1])
+  exe "normal 3\<C-I>"
+  call assert_equal(3, getjumplist()[1])
+  exe "normal \<C-O>"
+  normal 20%
+  call assert_equal([[
+	      \ {'lnum': 1, 'bufnr': bnr, 'col': 0, 'coladd': 0},
+	      \ {'lnum': 50, 'bufnr': bnr, 'col': 0, 'coladd': 0},
+	      \ {'lnum': 100, 'bufnr': bnr, 'col': 0, 'coladd': 0},
+	      \ {'lnum': 5, 'bufnr': bnr, 'col': 0, 'coladd': 0},
+	      \ {'lnum': 100, 'bufnr': bnr, 'col': 0, 'coladd': 0}], 5],
+	      \ getjumplist())
+
+  let l = getjumplist()
+  call test_garbagecollect_now()
+  call assert_equal(5, l[1])
+  clearjumps
+  call test_garbagecollect_now()
+  call assert_equal(5, l[1])
+
+  call delete("Xtest")
+endfunc
diff --git a/src/version.c b/src/version.c
index dbd2721..87ae3f5 100644
--- a/src/version.c
+++ b/src/version.c
@@ -772,6 +772,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1497,
+/**/
     1496,
 /**/
     1495,