On Fri, Sep 30, 2011 at 4:12 PM, Bram Moolenaar wrote:
> Xavier de Gaye wrote:
>> ...
>> When building an automated test case with netbeans, it is not obvious
>> how to have Vim made to call the idle loop. The attached patch adds a
>> call to netbeans_parse_messages() when the Vim ":sleep" command is
>> run. This allows for a more deterministic way of writing the test
>> cases (instead of inserting ":sleep" commands randomly until it works,
>> on this hardware).
>
> OK, this makes sense.  So you would run a Vim script that calls sleep in
> an endless loop?


Yes, this is right. It is a bit complicated due to the fact that there
are three processes running asynchronously (Vim, pyclewn and gdb), so
it is better to give an example. A typical pyclewn test case checks
that the content of a ${test_out} file contains the expected Vim signs
list:

    * the test starts by running the sequence of Vim and pyclewn
      commands that triggers gdb and sets breakpoint signs in Vim
      buffers
    * the test ends with the following commands:

            :call Wait_eop()
            :redir! > ${test_out}
            :sign place
            :qa

    * the definition of Wait_eop() follows:

# wait for pyclewn to process all previous commands
WAIT_EOP = """
:let g:testrun_key = ${key}
:function Wait_eop()
:   let g:testrun_key += 1
:   exe "Cdumprepr " . ${eop_file} . " " . g:testrun_key
:   let l:start = localtime()
:   while 1
:       " allow vim to process netbeans events and messages
:       sleep 10m
:       if localtime() - l:start > 5
:           break
:       endif
:       if filereadable(${eop_file})
:           let l:lines = readfile(${eop_file})
:           if len(lines) && l:lines[0] == g:testrun_key
:               sleep ${time}m
:               break
:           endif
:       endif
:   endwhile
:endfunction
"""

The call to the pyclewn 'Cdumprepr' command in Wait_eop() causes
pyclewn to create the temporary file named ${eop_file} and to write in
this file the value of ${key}. Thus, Wait_eop() can break out of the
while loop when detecting that the ${eop_file} contains the ${key},
which means that gdb and pyclewn have completed all their tasks. Note
that Wait_eop() still needs to sleep ${time} milliseconds, just before
the 'break' statement, to make sure that netbeans in Vim has processed
all the netbeans messages and has completed its share of the tasks.


> Please add a note in the documentation about this.  And perhaps a hint
> in the netbeans interface about what you are doing, it would be useful
> to others.


See the attached patch updated with documentation. I have also added a
paragraph to the ":nbkey" command to explain that it can be used to
pass any text to the IDE.


-- 
Xavier

Les Chemins de Lokoti: http://lokoti.alwaysdata.net

-- 
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
diff --git a/runtime/doc/netbeans.txt b/runtime/doc/netbeans.txt
--- a/runtime/doc/netbeans.txt
+++ b/runtime/doc/netbeans.txt
@@ -1,4 +1,4 @@
-*netbeans.txt*  For Vim version 7.3.  Last change: 2010 Sep 29
+*netbeans.txt*  For Vim version 7.3.  Last change: 2011 Oct 1st
 
 
 		  VIM REFERENCE MANUAL    by Gordon Prieur et al.
@@ -263,6 +263,12 @@
 plain UTF-8 text this protocol could also be used with any other communication
 mechanism.
 
+Netbeans messages are processed when Vim is idle, waiting for user input.
+When Vim is run in non-interactive mode, for example when running an automated
+test case that sources a Vim script, the idle loop may not be called often
+enough. In that case, insert |sleep| commands in the Vim script. The |sleep|
+command does invoke netbeans messages processing.
+
 6.1 Kinds of messages		|nb-messages|
 6.2 Terms			|nb-terms|
 6.3 Commands			|nb-commands|
@@ -833,11 +839,16 @@
 			signs.
 
 							*:nbkey*
-:nb[key] {key}		Pass the {key} to the Vim Controller for processing
-
-When a hot-key has been installed with the specialKeys command, this command
-can be used to generate a hotkey messages to the Vim Controller. The events
-newDotAndMark, keyCommand and keyAtPos are generated (in this order).
+:nb[key] {key}		Pass the {key} to the Vim Controller for processing.
+			When a hot-key has been installed with the specialKeys
+			command, this command can be used to generate a hotkey
+			message to the Vim Controller.
+			This command can also be used to pass any text to the
+			Vim  Controller. It is used by Pyclewn, for example,
+			to build the complete set of gdb commands as Vim user
+			commands.
+			The events newDotAndMark, keyCommand and keyAtPos are
+			generated (in this order).
 
 
 ==============================================================================
diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt
--- a/runtime/doc/various.txt
+++ b/runtime/doc/various.txt
@@ -1,4 +1,4 @@
-*various.txt*   For Vim version 7.3.  Last change: 2011 May 19
+*various.txt*   For Vim version 7.3.  Last change: 2011 Oct 1st
 
 
 		  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -602,6 +602,10 @@
 			"gs" stands for "goto sleep".
 			While sleeping the cursor is positioned in the text,
 			if at a visible position.  {not in Vi}
+			Also process the received netbeans messages. {only
+			available when compiled with the |+netbeans_intg|
+			feature}
+
 
 							*g_CTRL-A*
 g CTRL-A		Only when Vim was compiled with MEM_PROFILING defined
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -8207,6 +8207,12 @@
     {
 	ui_delay(msec - done > 1000L ? 1000L : msec - done, TRUE);
 	ui_breakcheck();
+#ifdef FEAT_NETBEANS_INTG
+	/* Process the netbeans messages that may have been received in the
+	 * call to ui_breakcheck when the gui is in use. This may occur when
+	 * running a test case.*/
+	netbeans_parse_messages();
+#endif
     }
 }
 
diff --git a/src/netbeans.c b/src/netbeans.c
--- a/src/netbeans.c
+++ b/src/netbeans.c
@@ -14,6 +14,13 @@
  * which are *between* characters, whereas vim uses line number
  * and column number which are *on* characters.
  * See ":help netbeans-protocol" for explanation.
+ *
+ * The Netbeans messages are received and queued in the gui event loop, or in
+ * the select loop when Vim runs in a terminal. These messages are processed
+ * by netbeans_parse_messages() which is invoked in the idle loop when Vim is
+ * waiting for user input. The function netbeans_parse_messages() is also
+ * called from the ":sleep" command, to allow the execution of test cases that
+ * may not invoke the idle loop.
  */
 
 #include "vim.h"

Raspunde prin e-mail lui