Karsten Hopp 3c46ca
To: vim_dev@googlegroups.com
Karsten Hopp 3c46ca
Subject: Patch 7.4.414
Karsten Hopp 3c46ca
Fcc: outbox
Karsten Hopp 3c46ca
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 3c46ca
Mime-Version: 1.0
Karsten Hopp 3c46ca
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 3c46ca
Content-Transfer-Encoding: 8bit
Karsten Hopp 3c46ca
------------
Karsten Hopp 3c46ca
Karsten Hopp 3c46ca
Patch 7.4.414
Karsten Hopp 3c46ca
Problem:    Cannot define a command only when it's used.
Karsten Hopp 3c46ca
Solution:   Add the CmdUndefined autocommand event. (partly by Yasuhiro
Karsten Hopp 3c46ca
	    Matsumoto)
Karsten Hopp 3c46ca
Files:	    runtime/doc/autocmd.txt, src/ex_docmd.c, src/fileio.c,
Karsten Hopp 3c46ca
	    src/proto/fileio.pro
Karsten Hopp 3c46ca
Karsten Hopp 3c46ca
Karsten Hopp 3c46ca
*** ../vim-7.4.413/runtime/doc/autocmd.txt	2013-11-28 18:53:47.000000000 +0100
Karsten Hopp 3c46ca
--- runtime/doc/autocmd.txt	2014-08-22 20:10:24.026988365 +0200
Karsten Hopp 3c46ca
***************
Karsten Hopp 3c46ca
*** 278,283 ****
Karsten Hopp 3c46ca
--- 278,284 ----
Karsten Hopp 3c46ca
  |ShellCmdPost|		after executing a shell command
Karsten Hopp 3c46ca
  |ShellFilterPost|	after filtering with a shell command
Karsten Hopp 3c46ca
  
Karsten Hopp 3c46ca
+ |CmdUndefined|		a user command is used but it isn't defined
Karsten Hopp 3c46ca
  |FuncUndefined|		a user function is used but it isn't defined
Karsten Hopp 3c46ca
  |SpellFileMissing|	a spell file is used but it can't be found
Karsten Hopp 3c46ca
  |SourcePre|		before sourcing a Vim script
Karsten Hopp 3c46ca
***************
Karsten Hopp 3c46ca
*** 462,467 ****
Karsten Hopp 3c46ca
--- 466,481 ----
Karsten Hopp 3c46ca
  							*BufWritePost*
Karsten Hopp 3c46ca
  BufWritePost			After writing the whole buffer to a file
Karsten Hopp 3c46ca
  				(should undo the commands for BufWritePre).
Karsten Hopp 3c46ca
+ 							*CmdUndefined*
Karsten Hopp 3c46ca
+ CmdUndefined			When a user command is used but it isn't
Karsten Hopp 3c46ca
+ 				defined.  Useful for defining a command only
Karsten Hopp 3c46ca
+ 				when it's used.  The pattern is matched
Karsten Hopp 3c46ca
+ 				against the command name.  Both <amatch> and
Karsten Hopp 3c46ca
+ 				<afile> are set to the name of the command.
Karsten Hopp 3c46ca
+ 				NOTE: Autocompletion won't work until the
Karsten Hopp 3c46ca
+ 				command is defined.  An alternative is to
Karsten Hopp 3c46ca
+ 				always define the user command and have it
Karsten Hopp 3c46ca
+ 				invoke an autoloaded function.  See |autoload|.
Karsten Hopp 3c46ca
  							*CmdwinEnter*
Karsten Hopp 3c46ca
  CmdwinEnter			After entering the command-line window.
Karsten Hopp 3c46ca
  				Useful for setting options specifically for
Karsten Hopp 3c46ca
***************
Karsten Hopp 3c46ca
*** 663,668 ****
Karsten Hopp 3c46ca
--- 681,688 ----
Karsten Hopp 3c46ca
  				when it's used.  The pattern is matched
Karsten Hopp 3c46ca
  				against the function name.  Both <amatch> and
Karsten Hopp 3c46ca
  				<afile> are set to the name of the function.
Karsten Hopp 3c46ca
+ 				NOTE: When writing Vim scripts a better
Karsten Hopp 3c46ca
+ 				alternative is to use an autoloaded function.
Karsten Hopp 3c46ca
  				See |autoload-functions|.
Karsten Hopp 3c46ca
  							*GUIEnter*
Karsten Hopp 3c46ca
  GUIEnter			After starting the GUI successfully, and after
Karsten Hopp 3c46ca
*** ../vim-7.4.413/src/ex_docmd.c	2014-08-10 13:34:59.056785459 +0200
Karsten Hopp 3c46ca
--- src/ex_docmd.c	2014-08-22 20:23:43.426959373 +0200
Karsten Hopp 3c46ca
***************
Karsten Hopp 3c46ca
*** 2143,2148 ****
Karsten Hopp 3c46ca
--- 2143,2168 ----
Karsten Hopp 3c46ca
      /* Find the command and let "p" point to after it. */
Karsten Hopp 3c46ca
      p = find_command(&ea, NULL);
Karsten Hopp 3c46ca
  
Karsten Hopp 3c46ca
+ #ifdef FEAT_AUTOCMD
Karsten Hopp 3c46ca
+     /* If this looks like an undefined user command and there are CmdUndefined
Karsten Hopp 3c46ca
+      * autocommands defined, trigger the matching autocommands. */
Karsten Hopp 3c46ca
+     if (p != NULL && ea.cmdidx == CMD_SIZE && !ea.skip
Karsten Hopp 3c46ca
+ 	    && ASCII_ISUPPER(*ea.cmd)
Karsten Hopp 3c46ca
+ 	    && has_cmdundefined())
Karsten Hopp 3c46ca
+     {
Karsten Hopp 3c46ca
+ 	char_u *p = ea.cmd;
Karsten Hopp 3c46ca
+ 	int ret;
Karsten Hopp 3c46ca
+ 
Karsten Hopp 3c46ca
+ 	while (ASCII_ISALNUM(*p))
Karsten Hopp 3c46ca
+ 	    ++p;
Karsten Hopp 3c46ca
+ 	p = vim_strnsave(ea.cmd, p - ea.cmd);
Karsten Hopp 3c46ca
+ 	ret = apply_autocmds(EVENT_CMDUNDEFINED, p, p, TRUE, NULL);
Karsten Hopp 3c46ca
+ 	vim_free(p);
Karsten Hopp 3c46ca
+ 	if (ret && !aborting())
Karsten Hopp 3c46ca
+ 	    p = find_command(&ea, NULL);
Karsten Hopp 3c46ca
+     }
Karsten Hopp 3c46ca
+ #endif
Karsten Hopp 3c46ca
+ 
Karsten Hopp 3c46ca
  #ifdef FEAT_USR_CMDS
Karsten Hopp 3c46ca
      if (p == NULL)
Karsten Hopp 3c46ca
      {
Karsten Hopp 3c46ca
*** ../vim-7.4.413/src/fileio.c	2014-08-13 21:58:24.820885492 +0200
Karsten Hopp 3c46ca
--- src/fileio.c	2014-08-22 20:25:26.826955623 +0200
Karsten Hopp 3c46ca
***************
Karsten Hopp 3c46ca
*** 7641,7646 ****
Karsten Hopp 3c46ca
--- 7641,7647 ----
Karsten Hopp 3c46ca
      {"BufWriteCmd",	EVENT_BUFWRITECMD},
Karsten Hopp 3c46ca
      {"CmdwinEnter",	EVENT_CMDWINENTER},
Karsten Hopp 3c46ca
      {"CmdwinLeave",	EVENT_CMDWINLEAVE},
Karsten Hopp 3c46ca
+     {"CmdUndefined",	EVENT_CMDUNDEFINED},
Karsten Hopp 3c46ca
      {"ColorScheme",	EVENT_COLORSCHEME},
Karsten Hopp 3c46ca
      {"CompleteDone",	EVENT_COMPLETEDONE},
Karsten Hopp 3c46ca
      {"CursorHold",	EVENT_CURSORHOLD},
Karsten Hopp 3c46ca
***************
Karsten Hopp 3c46ca
*** 9159,9164 ****
Karsten Hopp 3c46ca
--- 9160,9183 ----
Karsten Hopp 3c46ca
      return (first_autopat[(int)EVENT_INSERTCHARPRE] != NULL);
Karsten Hopp 3c46ca
  }
Karsten Hopp 3c46ca
  
Karsten Hopp 3c46ca
+ /*
Karsten Hopp 3c46ca
+  * Return TRUE when there is an CmdUndefined autocommand defined.
Karsten Hopp 3c46ca
+  */
Karsten Hopp 3c46ca
+     int
Karsten Hopp 3c46ca
+ has_cmdundefined()
Karsten Hopp 3c46ca
+ {
Karsten Hopp 3c46ca
+     return (first_autopat[(int)EVENT_CMDUNDEFINED] != NULL);
Karsten Hopp 3c46ca
+ }
Karsten Hopp 3c46ca
+ 
Karsten Hopp 3c46ca
+ /*
Karsten Hopp 3c46ca
+  * Return TRUE when there is an FuncUndefined autocommand defined.
Karsten Hopp 3c46ca
+  */
Karsten Hopp 3c46ca
+     int
Karsten Hopp 3c46ca
+ has_funcundefined()
Karsten Hopp 3c46ca
+ {
Karsten Hopp 3c46ca
+     return (first_autopat[(int)EVENT_FUNCUNDEFINED] != NULL);
Karsten Hopp 3c46ca
+ }
Karsten Hopp 3c46ca
+ 
Karsten Hopp 3c46ca
      static int
Karsten Hopp 3c46ca
  apply_autocmds_group(event, fname, fname_io, force, group, buf, eap)
Karsten Hopp 3c46ca
      event_T	event;
Karsten Hopp 3c46ca
*** ../vim-7.4.413/src/proto/fileio.pro	2014-08-10 13:34:59.060785459 +0200
Karsten Hopp 3c46ca
--- src/proto/fileio.pro	2014-08-22 20:25:38.862955186 +0200
Karsten Hopp 3c46ca
***************
Karsten Hopp 3c46ca
*** 47,52 ****
Karsten Hopp 3c46ca
--- 47,54 ----
Karsten Hopp 3c46ca
  int has_textchanged __ARGS((void));
Karsten Hopp 3c46ca
  int has_textchangedI __ARGS((void));
Karsten Hopp 3c46ca
  int has_insertcharpre __ARGS((void));
Karsten Hopp 3c46ca
+ int has_cmdundefined __ARGS((void));
Karsten Hopp 3c46ca
+ int has_funcundefined __ARGS((void));
Karsten Hopp 3c46ca
  void block_autocmds __ARGS((void));
Karsten Hopp 3c46ca
  void unblock_autocmds __ARGS((void));
Karsten Hopp 3c46ca
  int is_autocmd_blocked __ARGS((void));
Karsten Hopp 3c46ca
*** ../vim-7.4.413/src/version.c	2014-08-22 18:44:30.307175276 +0200
Karsten Hopp 3c46ca
--- src/version.c	2014-08-22 20:55:31.406890176 +0200
Karsten Hopp 3c46ca
***************
Karsten Hopp 3c46ca
*** 743,744 ****
Karsten Hopp 3c46ca
--- 743,746 ----
Karsten Hopp 3c46ca
  {   /* Add new patch number below this line */
Karsten Hopp 3c46ca
+ /**/
Karsten Hopp 3c46ca
+     414,
Karsten Hopp 3c46ca
  /**/
Karsten Hopp 3c46ca
Karsten Hopp 3c46ca
-- 
Karsten Hopp 3c46ca
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 3c46ca
44. Your friends no longer send you e-mail...they just log on to your IRC
Karsten Hopp 3c46ca
    channel.
Karsten Hopp 3c46ca
Karsten Hopp 3c46ca
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 3c46ca
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 3c46ca
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 3c46ca
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///