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