Re: [BUG] ":execute 'if 1'" works like ":if 1"

2014-03-23 Fir de Conversatie Bram Moolenaar

Nikolay Pavlov wrote:

> On Mar 23, 2014 12:19 AM, "Bram Moolenaar"  wrote:
> >
> >
> > ZyX wrote:
> >
> > > > The docs are wrong, using "if" is allowed.  The other two are not.
> > >
> > > Why? It makes parsing impossible. E.g. like indicated by @Yukihiro
> > > Nakadaira, there is absolutely nothing you can do with this error
> > > unless you add hacks for some specific cases (e.g. if `execute` is
> > > followed by a string literal starting with `if`).
> >
> > The code is full of exceptions.  There is a lot of history, some dating
> > back to the days of Ex.  The language wasn't designed to make life for
> > parser writers easier.  Some parts of the language weren't designed at
> > all, they just happened.  Not breaking existing Vim scripts is the main
> > goal, thus making changes in the language to simplify the implementation
> > will cause headeaches for users.
> 
> The problem is that you have a parser (I mean what vim does when skipping)
> there and it is not correct and may not be correct with this rule in
> effect. This statement in the help file exists since the first version
> recorded in mercurial repository and was also found in a 6.0 version
> archive: ":exe 'if'" was never correct. I just ask to make it not only
> officially incorrect, but also not working.

The problem with skipping is that it should not evaluate ":execute"
statements, since that may have side effects.  But then the matching
"endif" could be missed.  And a nested "if-endif" is not seen. Sounds
like a catch 22.

Let me update the help text to this:

Note: The executed string may be any command-line, but
starting or ending "if", "while" and "for" does not
always work, because when commands are skipped the
":execute" is not evaluated and Vim loses track of
where blocks start and end.  Also "break" and
"continue" should not be inside ":execute".
This does not work, because the ":execute" is not
evaluated and Vim does not see the "while", and gives
an error for finding an ":endwhile": >
:if 0
: execute 'while i > 5'
:  echo "test"
: endwhile
:endif

Generally, it should not be necessary to put "if", "while" and "for"
inside an execute, since these commands evaluate an expression
themselves.

Should we turn these "don't do this" instructions into an error?

> Though it worked in 6.0 as well (not when skipping, of course).

How about writing tests for these cases?  If you are writing a new
parser you must have a way to verify it does the right thing.

-- 
Friends?  I have lots of friends!  In fact, I have all episodes ever made.

 /// Bram Moolenaar -- b...@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///

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Patch 7.4.213

2014-03-23 Fir de Conversatie Bram Moolenaar

Patch 7.4.213
Problem:It's not possible to open a new buffer without creating a swap
file.
Solution:   Add the ":noswapfile" modifier. (Christian Brabandt)
Files:  runtime/doc/recover.txt, src/ex_cmds.h, src/ex_docmd.c,
src/memline.c, src/structs.h


*** ../vim-7.4.212/runtime/doc/recover.txt  2013-08-10 13:25:00.0 
+0200
--- runtime/doc/recover.txt 2014-03-23 16:01:59.655309841 +0100
***
*** 81,87 
  'maxmemtot'.  And when making a change to a read-only file, the swap file is
  created anyway.
  
! The 'swapfile' option can be reset to avoid creating a swapfile.
  
  
  Detecting an existing swap file ~
--- 81,94 
  'maxmemtot'.  And when making a change to a read-only file, the swap file is
  created anyway.
  
! The 'swapfile' option can be reset to avoid creating a swapfile.  And the
! |:noswapfile| modifier can be used to not create a swapfile for a new buffer.
! 
! :noswap[file]   {command} *:noswap* *:noswapfile*
!   Execute {command}. If it contains a command that loads a new
!   buffer, it will be loaded without creating a swapfile and the
!   'swapfile' option will be reset.  If a buffer already had a
!   swapfile it is not removed and 'swapfile' is not reset.
  
  
  Detecting an existing swap file ~
*** ../vim-7.4.212/src/ex_cmds.h2014-03-22 13:29:57.693846167 +0100
--- src/ex_cmds.h   2014-03-23 15:36:42.399286592 +0100
***
*** 655,660 
--- 655,662 
EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN),
  EX(CMD_noremenu,  "noremenu", ex_menu,

RANGE|NOTADR|ZEROR|BANG|EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN),
+ EX(CMD_noswapfile,"noswapfile",   ex_wrongmodifier,
+   NEEDARG|EXTRA|NOTRLCOM),
  EX(CMD_normal,"normal",   ex_normal,

RANGE|BANG|EXTRA|NEEDARG|NOTRLCOM|USECTRLV|SBOXOK|CMDWIN),
  EX(CMD_number,"number",   ex_print,
*** ../vim-7.4.212/src/ex_docmd.c   2014-03-23 15:12:29.919264336 +0100
--- src/ex_docmd.c  2014-03-23 15:44:42.335293946 +0100
***
*** 1874,1891 
  #endif
continue;
  
!   case 'n':   if (!checkforcmd(&ea.cmd, "noautocmd", 3))
!   break;
! #ifdef FEAT_AUTOCMD
!   if (cmdmod.save_ei == NULL)
{
!   /* Set 'eventignore' to "all". Restore the
!* existing option value later. */
!   cmdmod.save_ei = vim_strsave(p_ei);
!   set_string_option_direct((char_u *)"ei", -1,
 (char_u *)"all", OPT_FREE, SID_NONE);
!   }
  #endif
continue;
  
case 'r':   if (!checkforcmd(&ea.cmd, "rightbelow", 6))
--- 1874,1896 
  #endif
continue;
  
!   case 'n':   if (checkforcmd(&ea.cmd, "noautocmd", 3))
{
! #ifdef FEAT_AUTOCMD
!   if (cmdmod.save_ei == NULL)
!   {
!   /* Set 'eventignore' to "all". Restore the
!* existing option value later. */
!   cmdmod.save_ei = vim_strsave(p_ei);
!   set_string_option_direct((char_u *)"ei", -1,
 (char_u *)"all", OPT_FREE, SID_NONE);
!   }
  #endif
+   continue;
+   }
+   if (!checkforcmd(&ea.cmd, "noswapfile", 6))
+   break;
+   cmdmod.noswapfile = TRUE;
continue;
  
case 'r':   if (!checkforcmd(&ea.cmd, "rightbelow", 6))
***
*** 2596,2601 
--- 2601,2608 
case CMD_lua:
case CMD_match:
case CMD_mzscheme:
+   case CMD_noautocmd:
+   case CMD_noswapfile:
case CMD_perl:
case CMD_psearch:
case CMD_python:
***
*** 3099,3104 
--- 3106,3112 
  {"leftabove", 5, FALSE},
  {"lockmarks", 3, FALSE},
  {"noautocmd", 3, FALSE},
+ {"noswapfile", 3, FALSE},
  {"rightbelow", 6, FALSE},
  {"sandbox", 3, FALSE},
  {"silent", 3, FALSE},
***
*** 3611,3616 
--- 3619,3626 
case CMD_keeppatterns:
case CMD_leftabove:
case CMD_lockmarks:
+   case CMD_noautocmd:
+   case CMD_noswapfile:
case CMD_rightbelow:
case CMD_sandbox:
case CMD_silent:
*** ../vim-7.4.212/src/memline.c2014-02-11 15:23:27.942123631 +0100
--- src/memline.c   2014-03-23 15:48:05.679297062 +0100
***
*** 289,294 
--- 289,297 
  buf->b

Re: [patch] add sortuniq() function

2014-03-23 Fir de Conversatie lith
> > I think some of us would be rather surprised if the result weren't
> > [1,2,3].
> 
> Well, the more experienced among us would know that full (unsorted)
> unique would be nice, but expensive. :)

It eluded my mind that vimscript aims at high performance computing. I was 
talking about user expectations given that probably the majority of vim users 
are ruby, python, javascript developers -- at least from my perspective, which 
could be biased.

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.