diff options
author | Alexandre Dubray <alexandre.dubray@student.uclouvain.be> | 2018-01-09 12:01:02 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2020-01-26 17:13:00 -0800 |
commit | cf67f19ac2104ece76d040c8184bc287428299b3 (patch) | |
tree | dbf5f357e8985dd23bad128617a534b53363b36a /src | |
parent | 88f133c30d4b46e371f0cdb0797113cbbca9cc59 (diff) | |
download | rneovim-cf67f19ac2104ece76d040c8184bc287428299b3.tar.gz rneovim-cf67f19ac2104ece76d040c8184bc287428299b3.tar.bz2 rneovim-cf67f19ac2104ece76d040c8184bc287428299b3.zip |
mksession: restore same :term buf in split windows
Problem: When session-restore creates a terminal buffer with command
like `:edit term://.//16450:/bin/bash`, the buffer gets
a different name (depends on PID). Thus the later call to
`bufexists('term://.//16450:/bin/bash)` will return false.
Solution: Force the buffer name with :file. This as least ensures
the same buffer will show in multiple windows correctly, as
expected when saving the session. But it still has problems:
1. the PID in the buffer name is bogus
2. redundant :terminal buffers still hang around
fix #5250
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/ex_docmd.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 02bee838d5..0732409666 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -9346,6 +9346,10 @@ makeopens( /* * Restore the view of the window (options, file, cursor, etc.). */ + if (put_line(fd, "let s:buffer_names = []") == FAIL) { + return FAIL; + } + for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) { if (!ses_do_win(wp)) continue; @@ -9357,6 +9361,16 @@ makeopens( next_arg_idx = wp->w_arg_idx; } + if (put_line(fd, "for [s:name, s:tbuf] in s:buffer_names") == FAIL + || put_line(fd, " if buflisted(s:tbuf)") == FAIL + || put_line(fd, " execute 'buffer' fnameescape(s:tbuf)") == FAIL + || put_line(fd, " execute 'file' fnameescape(s:name)") == FAIL + || put_line(fd, " endif") == FAIL + || put_line(fd, "endfor") == FAIL + || put_line(fd, "unlet! s:buffer_names s:tbuf s:name") == FAIL) { + return FAIL; + } + /* The argument index in the first tab page is zero, need to set it in * each window. For further tab pages it's the window where we do * "tabedit". */ @@ -9662,6 +9676,19 @@ put_view( || put_eol(fd) == FAIL) { return FAIL; } + + if (fputs("call add(s:buffer_names, [bufname('%'),'", fd) < 0 + || ses_fname(fd, wp->w_buffer, flagp, false) == FAIL + || fputs("'])", fd) < 0 + || put_eol(fd) == FAIL) { + return FAIL; + } + + if (fputs("file ", fd) < 0 + || ses_fname(fd, wp->w_buffer, flagp, false) == FAIL + || put_eol(fd) == FAIL) { + return FAIL; + } } else { // No file in this buffer, just make it empty. if (put_line(fd, "enew") == FAIL) { |