[vim/vim] mksession: link between shared views into a buffer (#6930)

10 views
Skip to first unread message

Rob Pilling

unread,
Sep 10, 2020, 5:02:42 PM9/10/20
to vim/vim, Subscribed

Before this commit, if a terminal buffer was visible in multiple windows, a :mksession would generate a script which would not "re-link" these terminal buffers, duplicating the command across the previously linked windows.

This commit looks handles a terminal buffer that's open in multiple windows, ensuring the buffer is shared between those windows when the session is restored.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/6930

Commit Summary

  • mksession: link between shared views into a buffer

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Yegappan Lakshmanan

unread,
Sep 10, 2020, 5:09:54 PM9/10/20
to vim_dev, reply+ACY5DGCVFGI76GSAH3...@reply.github.com, vim/vim, Subscribed
Hi,

On Thu, Sep 10, 2020 at 2:02 PM Rob Pilling <vim-dev...@256bit.org> wrote:

Before this commit, if a terminal buffer was visible in multiple windows, a :mksession would generate a script which would not "re-link" these terminal buffers, duplicating the command across the previously linked windows.

This commit looks handles a terminal buffer that's open in multiple windows, ensuring the buffer is shared between those windows when the session is restored.


Can you add a test for this change?

Thanks,
Yegappan

Rob Pilling

unread,
Sep 10, 2020, 5:09:55 PM9/10/20
to vim/vim, Push

@bobrippling pushed 1 commit.

  • c86655a mksession: link between shared views into a buffer


You are receiving this because you are subscribed to this thread.

View it on GitHub or unsubscribe.

vim-dev ML

unread,
Sep 10, 2020, 5:10:14 PM9/10/20
to vim/vim, vim-dev ML, Your activity

Hi,

On Thu, Sep 10, 2020 at 2:02 PM Rob Pilling <vim-dev...@256bit.org>
wrote:

> Before this commit, if a terminal buffer was visible in multiple windows,
> a :mksession would generate a script which would not "re-link" these
> terminal buffers, duplicating the command across the previously linked
> windows.
>
> This commit looks handles a terminal buffer that's open in multiple
> windows, ensuring the buffer is shared between those windows when the
> session is restored.
>

Can you add a test for this change?

Thanks,
Yegappan


> ------------------------------

> You can view, comment on, or merge this pull request online at:
>
> https://github.com/vim/vim/pull/6930
> Commit Summary
>
> - mksession: link between shared views into a buffer
>
> File Changes
>
> - *M* src/hashtab.c
> <https://github.com/vim/vim/pull/6930/files#diff-f66fb35fb2e2837513621ac04f3678eb>
> (2)
> - *M* src/proto/terminal.pro
> <https://github.com/vim/vim/pull/6930/files#diff-f99bbf5901acfc552c426972aa73bc9e>
> (2)
> - *M* src/session.c
> <https://github.com/vim/vim/pull/6930/files#diff-c4be88194b2ccabe7ff34fece6d27ca7>
> (114)
> - *M* src/terminal.c
> <https://github.com/vim/vim/pull/6930/files#diff-f83301fc7928a73575f006ec59a872b6>
> (32)
>
> Patch Links:
>
> - https://github.com/vim/vim/pull/6930.patch
> - https://github.com/vim/vim/pull/6930.diff

Rob Pilling

unread,
Sep 10, 2020, 5:24:21 PM9/10/20
to vim/vim, vim-dev ML, Push

@bobrippling pushed 1 commit.

  • 8895ecf Test :mksession's terminal linking


You are receiving this because you are subscribed to this thread.

Rob Pilling

unread,
Sep 10, 2020, 5:24:27 PM9/10/20
to vim/vim, vim-dev ML, Comment

Sure - added


You are receiving this because you commented.

K.Takata

unread,
Sep 10, 2020, 10:56:52 PM9/10/20
to vim/vim, vim-dev ML, Comment

@k-takata commented on this pull request.

coding style


In src/terminal.c:

>      term_T *term = wp->w_buffer->b_term;

 

+    if (wp->w_buffer->b_nwindows > 1) {

⬇️ Suggested change
-    if (wp->w_buffer->b_nwindows > 1) {

+    if (wp->w_buffer->b_nwindows > 1)

+    {


In src/terminal.c:

>      term_T *term = wp->w_buffer->b_term;

 

+    if (wp->w_buffer->b_nwindows > 1) {

+	// There are multiple views into this terminal buffer. We don't want to

+	// create the terminal multiple times. If it's the first time, create,

+	// otherwise link to the first buffer.

+	char id_as_str[NUMBUFLEN];

+	hashitem_T *entry;

+

+	vim_snprintf(id_as_str, sizeof(id_as_str), "%d", bufid);

+

+	entry = hash_find(terminal_bufs, (char_u *)id_as_str);

+	if (!HASHITEM_EMPTY(entry)) {

⬇️ Suggested change
-	if (!HASHITEM_EMPTY(entry)) {

+	if (!HASHITEM_EMPTY(entry))

+	{


In src/terminal.c:

> @@ -951,6 +970,17 @@ term_write_session(FILE *fd, win_T *wp)

 #endif

     if (term->tl_command != NULL && fputs((char *)term->tl_command, fd) < 0)

 	return FAIL;

+    if (put_eol(fd) != OK)

+	return FAIL;

+

+    if (fprintf(fd, "let s:term_buf_%d = bufnr()", bufid) < 0)

+	return FAIL;

+

+    if (wp->w_buffer->b_nwindows > 1) {

⬇️ Suggested change
-    if (wp->w_buffer->b_nwindows > 1) {

+    if (wp->w_buffer->b_nwindows > 1)

+    {


You are receiving this because you commented.

Rob Pilling

unread,
Sep 11, 2020, 1:20:43 PM9/11/20
to vim/vim, vim-dev ML, Push

@bobrippling pushed 1 commit.

  • cecfc44 mksession: link between shared views into a buffer


You are receiving this because you are subscribed to this thread.

Yegappan Lakshmanan

unread,
Sep 11, 2020, 2:14:28 PM9/11/20
to vim_dev, nor...@github.com, vim/vim, vim-dev ML, Push
Hi,

On Fri, Sep 11, 2020 at 10:20 AM Rob Pilling <vim-dev...@256bit.org> wrote:

@bobrippling pushed 1 commit.

  • cecfc44 mksession: link between shared views into a buffer



The address sanitizer (ASAN) test in Travis/CI is detecting a problem with this change:


- Yegappan
 

Bram Moolenaar

unread,
Sep 11, 2020, 2:37:11 PM9/11/20
to vim/vim, vim-dev ML, Comment

Closed #6930 via 0e65511.


You are receiving this because you commented.

Bram Moolenaar

unread,
Sep 11, 2020, 2:52:04 PM9/11/20
to vim...@googlegroups.com, Yegappan Lakshmanan, nor...@github.com

Yegappan wrote:

> On Fri, Sep 11, 2020 at 10:20 AM Rob Pilling <vim-dev...@256bit.org>
> wrote:
>
> > @bobrippling <https://github.com/bobrippling> pushed 1 commit.
> >
> > - cecfc44
> > <https://github.com/vim/vim/commit/cecfc447c2a898a70714b693561d012160eca961>
> > mksession: link between shared views into a buffer
> >
> >
> >
> The address sanitizer (ASAN) test in Travis/CI is detecting a problem with
> this change:
>
> https://travis-ci.org/github/vim/vim/jobs/726359052

The hashtable wasn't cleaned up when returning OK.
I fixed that.

--
BRIDGEKEEPER: What is your favorite editor?
GAWAIN: Emacs ... No, Viiiiiiiiiiimmmmmmm!
"Monty Python and the Holy editor wars" PYTHON (MONTY) SOFTWARE LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages