home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 May / maximum-cd-2009-05.iso / DiscContents / npp.5.2.Installer.exe / plugins / doc / NppExec_Guide.txt < prev    next >
Encoding:
Text File  |  2008-11-03  |  9.5 KB  |  192 lines

  1. Guide: Using NppExec to compile sources with associated compilers
  2.  
  3. As a Notepad++ user, did you ever think about ability to compile your source 
  4. file with its associated compiler in a single action?
  5. You may use the NppExec plugin to perform certain actions on your files, but
  6. what about the automatization? What if you want your .c files to be compiled
  7. with tcc, .cpp files to be compiled with g++ and .awk files to be interpretted
  8. with gawk automatically, without explicit call to required compiler or
  9. interpretter? Is it possible?
  10. Yes, NppExec ALREADY allows you to do this. All you need is some imagination
  11. and several things to do. And I'm about to tell what is needed.
  12.  
  13. Let's begin with several theoretical questions.
  14. At first, how can NppExec understand which compiler/interpretter is required
  15. by your current source file? NppExec is not a compiler, it does not have
  16. any information about your file and does not know what to do with it. 
  17. Moreover, Notepad++ itself is not such IDE as Visual C++ Express or Dev-C++,
  18. it does not include any compiler and also does not know what to do with your
  19. source file.
  20. So, the only way to compile your source file with required compiler is to tell
  21. Notepad++ (to tell NppExec in our case) _which_ compiler to use and _how_ to
  22. use it.
  23. This is the solution which you may use already - explicit usage of certain
  24. compiler/interpretter with certain source file. For example, you may want to
  25. compile and run your .c source file with tcc. A simple NppExec's script can
  26. be created for this purpose:
  27.  
  28.   "C:\tools\tcc\tcc.exe" "$(FULL_CURRENT_PATH)" -run
  29.   
  30. The full path "C:\tools\tcc\tcc.exe" specifies a path to required compiler;
  31. Notepad++'es environment variable "$(FULL_CURRENT_PATH)" specifies full path
  32. name to your current source file; and "-run" in tcc's command line means
  33. "run compiled source". The full path was given in quotes, because, in general,
  34. it can contain spaces.
  35. Now, we are talking about NppExec's script. It assumes the script has been
  36. created and saved with some name which identified that script. If you are
  37. not sure about NppExec's script creation & saving, let me guide you.
  38.  
  39. To create & save some NppExec's script, do the following:
  40. 1) Open NppExec's "Execute..." window: press the hotkey (F6 by default)
  41.    or select (main menu) Plugins -> NppExec -> Execute...
  42. 2) Type the text of your script in the "Execute..." window. For example:
  43.  
  44.      "C:\tools\tcc\tcc.exe" "$(FULL_CURRENT_PATH)" -run
  45.      
  46. 3) Save this new script: press the "Save..." button, type your script name
  47.    (for example, type "run@.c") and press Save.
  48.  
  49. Now you can compile & run any single .c file opened in Notepad++. To do it,
  50. press F6 (default hotkey for the "Execute..." window), select "run@.c" in
  51. the combo-box and press OK.
  52. You can press Ctrl+F6 (by default) to execute the same script again without
  53. showing the "Execute..." window.
  54.  
  55. As you can see, currently you have to call the "run@.c" script explicitly 
  56. in order to compile & run your .c source file. Thus, to compile & run
  57. another source file (.cpp, .asm, .php, .lua, ...) you also have to call
  58. corresponding script explicitly. [The last sentence assumes you have created
  59. separate scripts for every language you use (.cpp, .asm, .php, .lua, ...)]
  60. However, we don't want to call required script explicitly. We want NppExec
  61. to call the "run@.c" script for a .c file and call different script required 
  62. for different (.cpp, .asm, .php, .lua, ...) file automatically.
  63. So, a question: how can we do it?
  64. The first part of the answer is in your source file's extension. There is 
  65. such environment varible as $(EXT_PART) which contains the extension of 
  66. current file opened in Notepad++.
  67. The second part of the answer is in NppExec's internal command NPP_EXEC.
  68. As you probably know already, this command expects an existing script name 
  69. or a script file name as its first argument. The purpose of this command is
  70. to execute specified NppExec's script.
  71. Thus, if you use NPP_EXEC command, and its first argument (a script to be
  72. executed) depends on current file's extension, you can call different scripts
  73. for different file types from one starting script!
  74. Let's examine it in more detail.
  75.  
  76. We are about to create a general NppExec's script which would allow us to 
  77. call different scripts for different source files depending on their extension.
  78. In other words, we use the NPP_EXEC command to call required script, and the 
  79. script name depends on current file's extension. The name of the script above,
  80. "run@.c", consists of two parts: the prefix "run@" and the extension ".c".
  81. As the file's extension can be got from Notepad++, we can write general form 
  82. of this script's name: "run@$(EXT_PART)".
  83. It's not hard to understand that this script's name transforms to "run@.cpp"
  84. for .cpp source file, "run@.lua" for .lua source file and so on.
  85. So, let's create our general compile-or-run script which will be called each
  86. time you want compile or run ANY source file:
  87.  
  88.   // save current file
  89.   NPP_SAVE
  90.   // construct the script name to be called  
  91.   SET Compiler = run@$(EXT_PART)
  92.   // call the script
  93.   NPP_EXEC "$(Compiler)"
  94.   
  95. Save this script as "compile_or_run". Now this is your only starting script
  96. which will allow you to compile or run ANY source file. I.e. press F6, select
  97. the "compile_or_run" and press OK in order to compile or run ANY source file.
  98. However, don't forget that this script requires existing scripts for every
  99. source file you want to compile. Thus, "run@.cpp" must exist to compile a .cpp
  100. file, "run@.php" must exist to compile a .php file and so on.
  101. You can see several examples of such scripts below:
  102.  
  103.   // run@.c
  104.   "C:\tools\tcc\tcc.exe" "$(FULL_CURRENT_PATH)" -run
  105.   
  106.   // run@.cpp
  107.   SET g++ = C:\Dev-Cpp\bin\g++.exe
  108.   SET obj = $(CURRENT_DIRECTORY)\$(NAME_PART)
  109.   "$(g++)" -c "$(FULL_CURRENT_PATH)" -o "$(obj).o"
  110.   "$(g++)" "$(obj).o" -o "$(obj).exe"
  111.   NPP_RUN "$(obj).exe"
  112.   UNSET obj
  113.   UNSET g++
  114.   
  115.   // run@.awk
  116.   "C:\tools\gawk\gawk.exe" -f "$(FULL_CURRENT_PATH)"
  117.   
  118. All of these scripts will be started automatically from the "compile_or_run"
  119. script for .c, .cpp and .awk files. You can create more "run@..." scripts to
  120. support any source file extension you use.
  121.  
  122. Now, let's return to our "compile_or_run" script. It uses the NPP_EXEC command
  123. which supports a script file name as its first argument. What does it mean?
  124. It means you can execute NppExec's script from a file.
  125. As you can see, current implementation of the "compile_or_run" script requires
  126. a lot of additional "run@..." scripts to exist together with other scripts
  127. which you may want to call explicitly. In the same time, you do not call the 
  128. "run@..." scripts explicitly. So, the "run@..." scripts may be undesired in 
  129. the NppExec's script combo-box (in the "Execute..." window).
  130. Thus, you may modify the "compile_or_run" script in order to call script files
  131. instead of internal scripts. For example:
  132.  
  133.   // compile_or_run
  134.   NPP_SAVE
  135.   SET Compiler = C:\tools\NppExec Scripts\run@$(EXT_PART).txt
  136.   NPP_EXEC "$(Compiler)"
  137.   
  138. Now you must create a directory "C:\tools\NppExec Scripts" which contains
  139. the following files: "run@.c.txt", "run@.cpp.txt", "run@.awk.txt" and so on.
  140. The text of these files must be exactly the same as in the scripts "run@.c",
  141. "run@.cpp" and "run@.awk" above. 
  142. E.g. the file "C:\tools\NppExec Scripts\run@.awk.txt" must contain
  143.  
  144.   "C:\tools\gawk\gawk.exe" -f "$(FULL_CURRENT_PATH)"
  145.   
  146. and so on for other file extensions (.c, .cpp, ...).
  147. To read more information about the NPP_EXEC command, open the NppExec's
  148. Console in Notepad++, and type:
  149.  
  150.   help npp_exec
  151.   
  152. and press Enter.
  153. To get general NppExec's help information, type just
  154.  
  155.   help
  156.   
  157. and press Enter.
  158.  
  159.  
  160. One more thing regarding NppExec usage. Compiler/interpreter's output is shown
  161. in NppExec's Console and can be parsed by NppExec. It means that different
  162. error/warning messages can be shown using different colours, and you can jump
  163. to corresponding line in the source file by double-clicking on such warning
  164. or error message in the NppExec's Console.
  165. To enable such parsing, you must tell NppExec what form do these error/warning
  166. messages have (i.e. specify the message mask). You can configure it from 
  167. (main menu) Plugins -> NppExec -> Console Output Filters... -> HighLight. 
  168. That window contains an example of parsing (highlighting) masks for GCC: 
  169.  
  170.   Example 1: %ABSFILE%:%LINE%: warning:* => detects the warning lines from gcc
  171.   Example 2: %ABSFILE%:%LINE%: error:* => detects the error lines from gcc
  172.  
  173. I.e. to enable detection (parsing) of GCC errors in NppExec, you must specify
  174. the mask of the compiler's error line ("%ABSFILE%:%LINE%: error:*") and, 
  175. optionally, specify Red, Green and Blue components of the line to be 
  176. highlighted and, also optionally, this line can be shown using Italic, Bold
  177. and/or Underlined font typeface. And, of course, corresponding check-box must
  178. be checked to enable this parsing mask. 
  179. For example, if you want to see GCC's errors as Bold lines with Red colour
  180. and GCC's warnings as Italic lines with Blue colour, it will look similar to
  181. the following: 
  182.  
  183.   [v] [%ABSFILE%:%LINE%: error:*       ]  0x80 0x00 0x00  [ ] [v] [ ]
  184.   [v] [%ABSFILE%:%LINE%: warning:*     ]  0x00 0x00 0x80  [v] [ ] [ ]
  185.  
  186.  
  187. Well, seems it's time to finish the guide. I hope this guide was usefull for 
  188. you, because otherwise it was waste of time for both of us: the reader (you) 
  189. and the writer (me).
  190. If you like this guide, I hope it will inspire you to find your own usefull
  191. application of NppExec's functions, and maybe to share it with us.
  192.