Patch 8.0.0836
Problem:    When a terminal buffer is changed it can still be accidentally
            abandoned.
Solution:   When making a change reset the 'buftype' option.
Files:      src/terminal.c, src/testdir/test_terminal.vim, src/option.c


*** ../vim-8.0.0835/src/terminal.c      2017-08-01 18:34:54.901292108 +0200
--- src/terminal.c      2017-08-01 20:23:48.061935203 +0200
***************
*** 36,44 ****
   * that buffer, attributes come from the scrollback buffer tl_scrollback.
   *
   * TODO:
!  * - Add StatusLineTerm highlighting
   * - in bash mouse clicks are inserting characters.
   * - mouse scroll: when over other window, scroll that window.
   * - For the scrollback buffer store lines in the buffer, only attributes in
   *   tl_scrollback.
   * - When the job ends:
--- 36,49 ----
   * that buffer, attributes come from the scrollback buffer tl_scrollback.
   *
   * TODO:
!  * - When closing a window with a terminal buffer where the job has ended, 
wipe
!  *   out the buffer.  Like 'bufhidden' is "wipe".
!  * - When a buffer with a terminal is wiped out, kill the job and close the
!  *   channel.
   * - in bash mouse clicks are inserting characters.
   * - mouse scroll: when over other window, scroll that window.
+  * - typing CTRL-C is not sent to the terminal.  need to setup controlling 
tty?
+  *    #1910
   * - For the scrollback buffer store lines in the buffer, only attributes in
   *   tl_scrollback.
   * - When the job ends:
***************
*** 221,237 ****
      if (cmd == NULL || *cmd == NUL)
        cmd = p_sh;
  
-     if (buflist_findname(cmd) == NULL)
-       curbuf->b_ffname = vim_strsave(cmd);
-     else
      {
        int     i;
        size_t  len = STRLEN(cmd) + 10;
        char_u  *p = alloc((int)len);
  
!       for (i = 1; p != NULL; ++i)
        {
!           vim_snprintf((char *)p, len, "%s (%d)", cmd, i);
            if (buflist_findname(p) == NULL)
            {
                curbuf->b_ffname = p;
--- 226,244 ----
      if (cmd == NULL || *cmd == NUL)
        cmd = p_sh;
  
      {
        int     i;
        size_t  len = STRLEN(cmd) + 10;
        char_u  *p = alloc((int)len);
  
!       for (i = 0; p != NULL; ++i)
        {
!           /* Prepend a ! to the command name to avoid the buffer name equals
!            * the executable, otherwise ":w!" would overwrite it. */
!           if (i == 0)
!               vim_snprintf((char *)p, len, "!%s", cmd);
!           else
!               vim_snprintf((char *)p, len, "!%s (%d)", cmd, i);
            if (buflist_findname(p) == NULL)
            {
                curbuf->b_ffname = p;
***************
*** 241,248 ****
      }
      curbuf->b_fname = curbuf->b_ffname;
  
!     /* Mark the buffer as changed, so that it's not easy to abandon the job. 
*/
!     curbuf->b_changed = TRUE;
      curbuf->b_p_ma = FALSE;
      set_string_option_direct((char_u *)"buftype", -1,
                                  (char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0);
--- 248,255 ----
      }
      curbuf->b_fname = curbuf->b_ffname;
  
!     /* Mark the buffer as not modifiable. It can only be made modifiable after
!      * the job finished. */
      curbuf->b_p_ma = FALSE;
      set_string_option_direct((char_u *)"buftype", -1,
                                  (char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0);
***************
*** 263,270 ****
         * free_terminal(). */
        do_buffer(DOBUF_WIPE, DOBUF_CURRENT, FORWARD, 0, TRUE);
      }
- 
-     /* TODO: Setup pty, see mch_call_shell(). */
  }
  
  /*
--- 270,275 ----
***************
*** 1571,1576 ****
--- 1576,1586 ----
      {
        free_scrollback(term);
        redraw_buf_later(term->tl_buffer, NOT_VALID);
+ 
+       /* The buffer is now like a normal buffer, it cannot be easily
+        * abandoned when changed. */
+       set_string_option_direct((char_u *)"buftype", -1,
+                                         (char_u *)"", OPT_FREE|OPT_LOCAL, 0);
      }
  }
  
*** ../vim-8.0.0835/src/testdir/test_terminal.vim       2017-08-01 
18:41:16.490535281 +0200
--- src/testdir/test_terminal.vim       2017-08-01 20:02:49.559147053 +0200
***************
*** 6,12 ****
  
  source shared.vim
  
! func Test_terminal_basic()
    let buf = term_start(&shell)
  
    let termlist = term_list()
--- 6,12 ----
  
  source shared.vim
  
! func Run_shell_in_terminal()
    let buf = term_start(&shell)
  
    let termlist = term_list()
***************
*** 20,25 ****
--- 20,44 ----
    call WaitFor('job_status(g:job) == "dead"')
    call assert_equal('dead', job_status(g:job))
  
+   return buf
+ endfunc
+ 
+ func Test_terminal_basic()
+   let buf = Run_shell_in_terminal()
+ 
+   exe buf . 'bwipe'
+   unlet g:job
+ endfunc
+ 
+ func Test_terminal_make_change()
+   let buf = Run_shell_in_terminal()
+   call term_wait(buf)
+ 
+   setlocal modifiable
+   exe "normal Axxx\<Esc>"
+   call assert_fails(buf . 'bwipe', 'E517')
+   undo
+ 
    exe buf . 'bwipe'
    unlet g:job
  endfunc
*** ../vim-8.0.0835/src/option.c        2017-07-31 22:29:29.792202736 +0200
--- src/option.c        2017-08-01 19:58:59.800816301 +0200
***************
*** 8228,8234 ****
      {
  # ifdef FEAT_TERMINAL
        /* Cannot set 'modifiable' when in Terminal mode. */
!       if (term_in_terminal_mode())
        {
            curbuf->b_p_ma = FALSE;
            return (char_u *)N_("E946: Cannot make a terminal with running job 
modifiable");
--- 8228,8235 ----
      {
  # ifdef FEAT_TERMINAL
        /* Cannot set 'modifiable' when in Terminal mode. */
!       if (term_in_terminal_mode()
!                        || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
        {
            curbuf->b_p_ma = FALSE;
            return (char_u *)N_("E946: Cannot make a terminal with running job 
modifiable");
*** ../vim-8.0.0835/src/version.c       2017-08-01 18:52:50.729522700 +0200
--- src/version.c       2017-08-01 19:35:31.111048655 +0200
***************
*** 771,772 ****
--- 771,774 ----
  {   /* Add new patch number below this line */
+ /**/
+     836,
  /**/

-- 
ARTHUR:    Will you ask your master if he wants to join my court at Camelot?!
GUARD #1:  But then of course African swallows are not migratory.
GUARD #2:  Oh, yeah...
GUARD #1:  So they couldn't bring a coconut back anyway...
                                  The Quest for the Holy Grail (Monty Python)

 /// Bram Moolenaar -- [email protected] -- 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    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui