Karsten Hopp 91e38d
To: vim_dev@googlegroups.com
Karsten Hopp 91e38d
Subject: Patch 7.3.1248
Karsten Hopp 91e38d
Fcc: outbox
Karsten Hopp 91e38d
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 91e38d
Mime-Version: 1.0
Karsten Hopp 91e38d
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 91e38d
Content-Transfer-Encoding: 8bit
Karsten Hopp 91e38d
------------
Karsten Hopp 91e38d
Karsten Hopp 91e38d
Patch 7.3.1248
Karsten Hopp 91e38d
Problem:    Still have old hacking code for Input Method.
Karsten Hopp 91e38d
Solution:   Add 'imactivatefunc' and 'imstatusfunc' as a generic solution to
Karsten Hopp 91e38d
	    Input Method activation. (Yukihiro Nakadaira)
Karsten Hopp 91e38d
Files:	    runtime/doc/options.txt, src/fileio.c, src/mbyte.c, src/option.c,
Karsten Hopp 91e38d
	    src/option.h, src/proto/fileio.pro
Karsten Hopp 91e38d
Karsten Hopp 91e38d
Karsten Hopp 91e38d
*** ../vim-7.3.1247/runtime/doc/options.txt	2013-06-04 22:13:45.000000000 +0200
Karsten Hopp 91e38d
--- runtime/doc/options.txt	2013-06-26 19:00:28.000000000 +0200
Karsten Hopp 91e38d
***************
Karsten Hopp 91e38d
*** 3937,3942 ****
Karsten Hopp 91e38d
--- 3993,4018 ----
Karsten Hopp 91e38d
  	Can be overruled by using "\c" or "\C" in the pattern, see
Karsten Hopp 91e38d
  	|/ignorecase|.
Karsten Hopp 91e38d
  
Karsten Hopp 91e38d
+ 						*'imactivatefunc'* *'imaf'*
Karsten Hopp 91e38d
+ 'imactivatefunc' 'imaf'	string (default "")
Karsten Hopp 91e38d
+ 			global
Karsten Hopp 91e38d
+ 			{not in Vi}
Karsten Hopp 91e38d
+ 			{only available when compiled with |+xim| and
Karsten Hopp 91e38d
+ 			|+GUI_GTK|}
Karsten Hopp 91e38d
+ 	This option specifies a function that will be called to
Karsten Hopp 91e38d
+ 	activate/inactivate Input Method.
Karsten Hopp 91e38d
+ 
Karsten Hopp 91e38d
+ 	Example: >
Karsten Hopp 91e38d
+ 		function ImActivateFunc(active)
Karsten Hopp 91e38d
+ 		  if a:active
Karsten Hopp 91e38d
+ 		    ... do something
Karsten Hopp 91e38d
+ 		  else
Karsten Hopp 91e38d
+ 		    ... do something
Karsten Hopp 91e38d
+ 		  endif
Karsten Hopp 91e38d
+ 		  " return value is not used
Karsten Hopp 91e38d
+ 		endfunction
Karsten Hopp 91e38d
+ 		set imactivatefunc=ImActivateFunc
Karsten Hopp 91e38d
+ <
Karsten Hopp 91e38d
  						*'imactivatekey'* *'imak'*
Karsten Hopp 91e38d
  'imactivatekey' 'imak'	string (default "")
Karsten Hopp 91e38d
  			global
Karsten Hopp 91e38d
***************
Karsten Hopp 91e38d
*** 4033,4038 ****
Karsten Hopp 91e38d
--- 4109,4132 ----
Karsten Hopp 91e38d
  	The value 0 may not work correctly with Athena and Motif with some XIM
Karsten Hopp 91e38d
  	methods.  Use 'imdisable' to disable XIM then.
Karsten Hopp 91e38d
  
Karsten Hopp 91e38d
+ 						*'imstatusfunc'* *'imsf'*
Karsten Hopp 91e38d
+ 'imstatusfunc' 'imsf'	string (default "")
Karsten Hopp 91e38d
+ 			global
Karsten Hopp 91e38d
+ 			{not in Vi}
Karsten Hopp 91e38d
+ 			{only available when compiled with |+xim| and
Karsten Hopp 91e38d
+ 			|+GUI_GTK|}
Karsten Hopp 91e38d
+ 	This option specifies a function that is called to obtain the status
Karsten Hopp 91e38d
+ 	of Input Method.  It must return a positive number when IME is active.
Karsten Hopp 91e38d
+ 
Karsten Hopp 91e38d
+ 	Example: >
Karsten Hopp 91e38d
+ 		function ImStatusFunc()
Karsten Hopp 91e38d
+ 		  let is_active = ...do something
Karsten Hopp 91e38d
+ 		  return is_active ? 1 : 0
Karsten Hopp 91e38d
+ 		endfunction
Karsten Hopp 91e38d
+ 		set imstatusfunc=ImStatusFunc
Karsten Hopp 91e38d
+ <
Karsten Hopp 91e38d
+ 	NOTE: This function is invoked very often.  Keep it fast.
Karsten Hopp 91e38d
+ 
Karsten Hopp 91e38d
  						*'include'* *'inc'*
Karsten Hopp 91e38d
  'include' 'inc'		string	(default "^\s*#\s*include")
Karsten Hopp 91e38d
  			global or local to buffer |global-local|
Karsten Hopp 91e38d
*** ../vim-7.3.1247/src/fileio.c	2013-06-12 22:41:30.000000000 +0200
Karsten Hopp 91e38d
--- src/fileio.c	2013-06-26 18:41:39.000000000 +0200
Karsten Hopp 91e38d
***************
Karsten Hopp 91e38d
*** 9572,9577 ****
Karsten Hopp 91e38d
--- 9572,9583 ----
Karsten Hopp 91e38d
  # endif
Karsten Hopp 91e38d
  }
Karsten Hopp 91e38d
  
Karsten Hopp 91e38d
+     int
Karsten Hopp 91e38d
+ is_autocmd_blocked()
Karsten Hopp 91e38d
+ {
Karsten Hopp 91e38d
+     return autocmd_blocked != 0;
Karsten Hopp 91e38d
+ }
Karsten Hopp 91e38d
+ 
Karsten Hopp 91e38d
  /*
Karsten Hopp 91e38d
   * Find next autocommand pattern that matches.
Karsten Hopp 91e38d
   */
Karsten Hopp 91e38d
*** ../vim-7.3.1247/src/mbyte.c	2013-05-06 04:21:35.000000000 +0200
Karsten Hopp 91e38d
--- src/mbyte.c	2013-06-26 19:10:41.000000000 +0200
Karsten Hopp 91e38d
***************
Karsten Hopp 91e38d
*** 4447,4453 ****
Karsten Hopp 91e38d
  {
Karsten Hopp 91e38d
      int was_active;
Karsten Hopp 91e38d
  
Karsten Hopp 91e38d
!     was_active = !!im_is_active;
Karsten Hopp 91e38d
      im_is_active = (active && !p_imdisable);
Karsten Hopp 91e38d
  
Karsten Hopp 91e38d
      if (im_is_active != was_active)
Karsten Hopp 91e38d
--- 4447,4453 ----
Karsten Hopp 91e38d
  {
Karsten Hopp 91e38d
      int was_active;
Karsten Hopp 91e38d
  
Karsten Hopp 91e38d
!     was_active = !!im_get_status();
Karsten Hopp 91e38d
      im_is_active = (active && !p_imdisable);
Karsten Hopp 91e38d
  
Karsten Hopp 91e38d
      if (im_is_active != was_active)
Karsten Hopp 91e38d
***************
Karsten Hopp 91e38d
*** 5071,5114 ****
Karsten Hopp 91e38d
  {
Karsten Hopp 91e38d
      if (xic != NULL)
Karsten Hopp 91e38d
      {
Karsten Hopp 91e38d
- 	/*
Karsten Hopp 91e38d
- 	 * The third-party imhangul module (and maybe others too) ignores
Karsten Hopp 91e38d
- 	 * gtk_im_context_reset() or at least doesn't reset the active state.
Karsten Hopp 91e38d
- 	 * Thus sending imactivatekey would turn it off if it was on before,
Karsten Hopp 91e38d
- 	 * which is clearly not what we want.  Fortunately we can work around
Karsten Hopp 91e38d
- 	 * that for imhangul by sending GDK_Escape, but I don't know if it
Karsten Hopp 91e38d
- 	 * works with all IM modules that support an activation key :/
Karsten Hopp 91e38d
- 	 *
Karsten Hopp 91e38d
- 	 * An alternative approach would be to destroy the IM context and
Karsten Hopp 91e38d
- 	 * recreate it.  But that means loading/unloading the IM module on
Karsten Hopp 91e38d
- 	 * every mode switch, which causes a quite noticeable delay even on
Karsten Hopp 91e38d
- 	 * my rather fast box...
Karsten Hopp 91e38d
- 	 * *
Karsten Hopp 91e38d
- 	 * Moreover, there are some XIM which cannot respond to
Karsten Hopp 91e38d
- 	 * im_synthesize_keypress(). we hope that they reset by
Karsten Hopp 91e38d
- 	 * xim_shutdown().
Karsten Hopp 91e38d
- 	 */
Karsten Hopp 91e38d
- 	if (im_activatekey_keyval != GDK_VoidSymbol && im_is_active)
Karsten Hopp 91e38d
- 	    im_synthesize_keypress(GDK_Escape, 0U);
Karsten Hopp 91e38d
- 
Karsten Hopp 91e38d
  	gtk_im_context_reset(xic);
Karsten Hopp 91e38d
  
Karsten Hopp 91e38d
- 	/*
Karsten Hopp 91e38d
- 	 * HACK for Ami: This sequence of function calls makes Ami handle
Karsten Hopp 91e38d
- 	 * the IM reset graciously, without breaking loads of other stuff.
Karsten Hopp 91e38d
- 	 * It seems to force English mode as well, which is exactly what we
Karsten Hopp 91e38d
- 	 * want because it makes the Ami status display work reliably.
Karsten Hopp 91e38d
- 	 */
Karsten Hopp 91e38d
- 	gtk_im_context_set_use_preedit(xic, FALSE);
Karsten Hopp 91e38d
- 
Karsten Hopp 91e38d
  	if (p_imdisable)
Karsten Hopp 91e38d
  	    im_shutdown();
Karsten Hopp 91e38d
  	else
Karsten Hopp 91e38d
  	{
Karsten Hopp 91e38d
- 	    gtk_im_context_set_use_preedit(xic, TRUE);
Karsten Hopp 91e38d
  	    xim_set_focus(gui.in_focus);
Karsten Hopp 91e38d
  
Karsten Hopp 91e38d
! 	    if (im_activatekey_keyval != GDK_VoidSymbol)
Karsten Hopp 91e38d
  	    {
Karsten Hopp 91e38d
  		if (im_is_active)
Karsten Hopp 91e38d
  		{
Karsten Hopp 91e38d
--- 5071,5095 ----
Karsten Hopp 91e38d
  {
Karsten Hopp 91e38d
      if (xic != NULL)
Karsten Hopp 91e38d
      {
Karsten Hopp 91e38d
  	gtk_im_context_reset(xic);
Karsten Hopp 91e38d
  
Karsten Hopp 91e38d
  	if (p_imdisable)
Karsten Hopp 91e38d
  	    im_shutdown();
Karsten Hopp 91e38d
  	else
Karsten Hopp 91e38d
  	{
Karsten Hopp 91e38d
  	    xim_set_focus(gui.in_focus);
Karsten Hopp 91e38d
  
Karsten Hopp 91e38d
! 	    if (p_imaf[0] != NUL)
Karsten Hopp 91e38d
! 	    {
Karsten Hopp 91e38d
! 		char_u *argv[1];
Karsten Hopp 91e38d
! 
Karsten Hopp 91e38d
! 		if (im_is_active)
Karsten Hopp 91e38d
! 		    argv[0] = (char_u *)"1";
Karsten Hopp 91e38d
! 		else
Karsten Hopp 91e38d
! 		    argv[0] = (char_u *)"0";
Karsten Hopp 91e38d
! 		(void)call_func_retnr(p_imaf, 1, argv, FALSE);
Karsten Hopp 91e38d
! 	    }
Karsten Hopp 91e38d
! 	    else if (im_activatekey_keyval != GDK_VoidSymbol)
Karsten Hopp 91e38d
  	    {
Karsten Hopp 91e38d
  		if (im_is_active)
Karsten Hopp 91e38d
  		{
Karsten Hopp 91e38d
***************
Karsten Hopp 91e38d
*** 5268,5273 ****
Karsten Hopp 91e38d
--- 5249,5268 ----
Karsten Hopp 91e38d
      int
Karsten Hopp 91e38d
  im_get_status(void)
Karsten Hopp 91e38d
  {
Karsten Hopp 91e38d
+     if (p_imsf[0] != NUL)
Karsten Hopp 91e38d
+     {
Karsten Hopp 91e38d
+ 	int is_active;
Karsten Hopp 91e38d
+ 
Karsten Hopp 91e38d
+ 	/* FIXME: Don't execute user function in unsafe situation. */
Karsten Hopp 91e38d
+ 	if (exiting || is_autocmd_blocked())
Karsten Hopp 91e38d
+ 	    return FALSE;
Karsten Hopp 91e38d
+ 	/* FIXME: :py print 'xxx' is shown duplicate result.
Karsten Hopp 91e38d
+ 	 * Use silent to avoid it. */
Karsten Hopp 91e38d
+ 	++msg_silent;
Karsten Hopp 91e38d
+ 	is_active = call_func_retnr(p_imsf, 0, NULL, FALSE);
Karsten Hopp 91e38d
+ 	--msg_silent;
Karsten Hopp 91e38d
+ 	return (is_active > 0);
Karsten Hopp 91e38d
+     }
Karsten Hopp 91e38d
      return im_is_active;
Karsten Hopp 91e38d
  }
Karsten Hopp 91e38d
  
Karsten Hopp 91e38d
*** ../vim-7.3.1247/src/option.c	2013-06-16 16:01:20.000000000 +0200
Karsten Hopp 91e38d
--- src/option.c	2013-06-26 18:41:39.000000000 +0200
Karsten Hopp 91e38d
***************
Karsten Hopp 91e38d
*** 1425,1430 ****
Karsten Hopp 91e38d
--- 1425,1439 ----
Karsten Hopp 91e38d
      {"ignorecase",  "ic",   P_BOOL|P_VI_DEF,
Karsten Hopp 91e38d
  			    (char_u *)&p_ic, PV_NONE,
Karsten Hopp 91e38d
  			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Karsten Hopp 91e38d
+     {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Karsten Hopp 91e38d
+ # if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Karsten Hopp 91e38d
+ 			    (char_u *)&p_imaf, PV_NONE,
Karsten Hopp 91e38d
+ 			    {(char_u *)"", (char_u *)NULL}
Karsten Hopp 91e38d
+ # else
Karsten Hopp 91e38d
+ 			    (char_u *)NULL, PV_NONE,
Karsten Hopp 91e38d
+ 			    {(char_u *)NULL, (char_u *)0L}
Karsten Hopp 91e38d
+ # endif
Karsten Hopp 91e38d
+ 			    SCRIPTID_INIT},
Karsten Hopp 91e38d
      {"imactivatekey","imak",P_STRING|P_VI_DEF,
Karsten Hopp 91e38d
  #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Karsten Hopp 91e38d
  			    (char_u *)&p_imak, PV_NONE,
Karsten Hopp 91e38d
***************
Karsten Hopp 91e38d
*** 1467,1472 ****
Karsten Hopp 91e38d
--- 1476,1490 ----
Karsten Hopp 91e38d
  			    {(char_u *)B_IMODE_NONE, (char_u *)0L}
Karsten Hopp 91e38d
  #endif
Karsten Hopp 91e38d
  			    SCRIPTID_INIT},
Karsten Hopp 91e38d
+     {"imstatusfunc","imse",P_STRING|P_VI_DEF|P_SECURE,
Karsten Hopp 91e38d
+ # if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Karsten Hopp 91e38d
+ 			    (char_u *)&p_imsf, PV_NONE,
Karsten Hopp 91e38d
+ 			    {(char_u *)"", (char_u *)NULL}
Karsten Hopp 91e38d
+ # else
Karsten Hopp 91e38d
+ 			    (char_u *)NULL, PV_NONE,
Karsten Hopp 91e38d
+ 			    {(char_u *)NULL, (char_u *)0L}
Karsten Hopp 91e38d
+ # endif
Karsten Hopp 91e38d
+ 			    SCRIPTID_INIT},
Karsten Hopp 91e38d
      {"include",	    "inc",  P_STRING|P_ALLOCED|P_VI_DEF,
Karsten Hopp 91e38d
  #ifdef FEAT_FIND_ID
Karsten Hopp 91e38d
  			    (char_u *)&p_inc, PV_INC,
Karsten Hopp 91e38d
*** ../vim-7.3.1247/src/option.h	2013-05-19 19:16:25.000000000 +0200
Karsten Hopp 91e38d
--- src/option.h	2013-06-26 18:41:39.000000000 +0200
Karsten Hopp 91e38d
***************
Karsten Hopp 91e38d
*** 558,563 ****
Karsten Hopp 91e38d
--- 558,565 ----
Karsten Hopp 91e38d
  EXTERN int	p_ic;		/* 'ignorecase' */
Karsten Hopp 91e38d
  #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Karsten Hopp 91e38d
  EXTERN char_u	*p_imak;	/* 'imactivatekey' */
Karsten Hopp 91e38d
+ EXTERN char_u	*p_imaf;	/* 'imactivatefunc' */
Karsten Hopp 91e38d
+ EXTERN char_u	*p_imsf;	/* 'imstatusfunc' */
Karsten Hopp 91e38d
  #endif
Karsten Hopp 91e38d
  #ifdef USE_IM_CONTROL
Karsten Hopp 91e38d
  EXTERN int	p_imcmdline;	/* 'imcmdline' */
Karsten Hopp 91e38d
*** ../vim-7.3.1247/src/proto/fileio.pro	2013-03-19 13:33:18.000000000 +0100
Karsten Hopp 91e38d
--- src/proto/fileio.pro	2013-06-26 18:45:49.000000000 +0200
Karsten Hopp 91e38d
***************
Karsten Hopp 91e38d
*** 49,54 ****
Karsten Hopp 91e38d
--- 49,55 ----
Karsten Hopp 91e38d
  int has_insertcharpre __ARGS((void));
Karsten Hopp 91e38d
  void block_autocmds __ARGS((void));
Karsten Hopp 91e38d
  void unblock_autocmds __ARGS((void));
Karsten Hopp 91e38d
+ int is_autocmd_blocked __ARGS((void));
Karsten Hopp 91e38d
  char_u *getnextac __ARGS((int c, void *cookie, int indent));
Karsten Hopp 91e38d
  int has_autocmd __ARGS((event_T event, char_u *sfname, buf_T *buf));
Karsten Hopp 91e38d
  char_u *get_augroup_name __ARGS((expand_T *xp, int idx));
Karsten Hopp 91e38d
*** ../vim-7.3.1247/src/version.c	2013-06-26 18:16:55.000000000 +0200
Karsten Hopp 91e38d
--- src/version.c	2013-06-26 19:12:37.000000000 +0200
Karsten Hopp 91e38d
***************
Karsten Hopp 91e38d
*** 730,731 ****
Karsten Hopp 91e38d
--- 730,733 ----
Karsten Hopp 91e38d
  {   /* Add new patch number below this line */
Karsten Hopp 91e38d
+ /**/
Karsten Hopp 91e38d
+     1248,
Karsten Hopp 91e38d
  /**/
Karsten Hopp 91e38d
Karsten Hopp 91e38d
-- 
Karsten Hopp 91e38d
I'd like to meet the man who invented sex and see what he's working on now.
Karsten Hopp 91e38d
Karsten Hopp 91e38d
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 91e38d
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 91e38d
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 91e38d
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///