]> granicus.if.org Git - vim/commitdiff
patch 8.2.4007: session does not restore help buffer properly v8.2.4007
authormatveyt <matthewtarasov@gmail.com>
Wed, 5 Jan 2022 14:01:30 +0000 (14:01 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 5 Jan 2022 14:01:30 +0000 (14:01 +0000)
Problem:    Session does not restore help buffer properly when "options' is
            missing from 'sessionoptions'.
Solution:   Use a ":help" command to create the help window. (closes #9475,
            closes #9458, closes #9472)

src/session.c
src/testdir/test_mksession.vim
src/version.c

index fdda5ee20e4ae0eb9f8eaeebc640e6a6353e190d..21af90245954a3f934ca75c6b8c6cd30736586b7 100644 (file)
@@ -348,16 +348,32 @@ put_view(
     // Edit the file.  Skip this when ":next" already did it.
     if (add_edit && (!did_next || wp->w_arg_idx_invalid))
     {
+       if (bt_help(wp->w_buffer))
+       {
+           char *curtag = "";
+
+           // A help buffer needs some options to be set.
+           // First, create a new empty buffer with "buftype=help".
+           // Then ":help" will re-use both the buffer and the window and set
+           // the options, even when "options" is not in 'sessionoptions'.
+           if (0 < wp->w_tagstackidx
+                   && wp->w_tagstackidx <= wp->w_tagstacklen)
+               curtag = (char *)wp->w_tagstack[wp->w_tagstackidx - 1].tagname;
+
+           if (put_line(fd, "enew | setl bt=help") == FAIL
+                   || fprintf(fd, "help %s", curtag) < 0
+                   || put_eol(fd) == FAIL)
+               return FAIL;
+       }
 # ifdef FEAT_TERMINAL
-       if (bt_terminal(wp->w_buffer))
+       else if (bt_terminal(wp->w_buffer))
        {
            if (term_write_session(fd, wp, terminal_bufs) == FAIL)
                return FAIL;
        }
-       else
 # endif
        // Load the file.
-       if (wp->w_buffer->b_ffname != NULL
+       else if (wp->w_buffer->b_ffname != NULL
 # ifdef FEAT_QUICKFIX
                && !bt_nofilename(wp->w_buffer)
 # endif
index a0a2cb461e6a3c5fc980f4519dc06f49d592e67e..301ff0514e4997075b2d853e24e8f323161ead22 100644 (file)
@@ -909,6 +909,36 @@ func Test_mksession_foldopt()
   set sessionoptions&
 endfunc
 
+" Test for mksession with "help" but not "options" in 'sessionoptions'
+func Test_mksession_help_noopt()
+  set sessionoptions-=options
+  set sessionoptions+=help
+  help
+  let fname = expand('%')
+  mksession! Xtest_mks.out
+  bwipe
+
+  source Xtest_mks.out
+  call assert_equal('help', &buftype)
+  call assert_equal('help', &filetype)
+  call assert_equal(fname, expand('%'))
+  call assert_false(&modifiable)
+  call assert_true(&readonly)
+
+  helpclose
+  help index
+  let fname = expand('%')
+  mksession! Xtest_mks.out
+  bwipe
+
+  source Xtest_mks.out
+  call assert_equal('help', &buftype)
+  call assert_equal(fname, expand('%'))
+
+  call delete('Xtest_mks.out')
+  set sessionoptions&
+endfunc
+
 " Test for mksession with window position
 func Test_mksession_winpos()
   " Only applicable in GUI Vim
index ad0d49e5d6b13c8e1529ae88077ebc53fe779be3..c12bbead444eff5a0c5017fa12a207e7ac1f34e6 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4007,
 /**/
     4006,
 /**/