4.  Source-Code Editors (for Windows) A program editor (or source code editor ) is programming language sensitive and context-aware . I...

Programmer's Survival Guide for Windows CMD Shell, File System & Source-code Editors Part 4

8:14:00 PM Unknown 0 Comments

4.  Source-Code Editors (for Windows)

A program editor (or source code editor) is programming language sensitive and context-aware. It highlights the syntax elements of your programs; and provides many features that aid in your program development (such as auto-complete, compile/build/run, help menu, etc.). On the other hand, a plain text editor, such as "NotePad", is not language-sensitive and, therefore, is NOT suitable for writing programs. For full-scale software development, you should use an appropriate IDE (Integrated Development Environment).
It is important to use a mono-space font (such as "Courier New", "Consola") for programming, so that the columns are properly aligned.
There are tons of free program editors available. Here are some program editors that I am currently using. Unfortunately, there isn't one magic wane (or silver bullet) that suits all my programming needs.


4.1  TextPad

TextPad is an excellent source-code editor, especially for writing toy Java programs. It is simple to use, fast to launch, and it can be configured to run JDK commands directly. TextPad is a shareware (not a freeware). The full-function version can be downloaded from www.textpad.com. It has no time limit but a message will keep reminding you to purchase the shareware.
To install, simply run the downloaded installer.
Using TextPad for Writing Toy Java Programs
TextPad is great in writing toy Java programs, as it can be configured to run JDK command directly, bypassing the command shell. From the TextPad editor, you can invoke the JDK compiler and runtime directly via "Tools" ⇒ (Version 5 only) "External Tools" ⇒ "Compile Java" or "Run Java Application". Take note of the keyboard shortcuts.
TextpadJava.png If you cannot find these commands in the "Tools" menu, goto "Configure" ⇒ Preferences... ⇒ Tools ⇒ Add ⇒ JDK Commands. You can also configure the attributes of "compile" and "run" there, such as prompting for command-line arguments.
Tips for Using TextPad
  1. Error Message Hyperlink: Double-click on the first-line of an error message will hyperlink to the corresponding source statement.
  2. Find & Replace: Most important commands for programmers (after the copy/paste), available under the "Search" menu.
  3. Block Select Mode: The Block Select mode allows you to operate on a block of texts, such as deleting a few columns and filling in blank columns. To enable/disable Block Select mode, select "Configure" menu ⇒ check/uncheck "Block Select Mode".
  4. Line Numbers: To display the line numbers, choose "View" menu ⇒ check the "Line Number" option.
  5. Command-Line Arguments: To provide command-line arguments to your Java program in TextPad, choose "Configure" menu ⇒ "Tools" ⇒ "Run Java Application" ⇒ check "Prompt for parameters" box. When running your program, place your command-line arguments after $BaseName (which denotes the Java program name).
Configuring TextPad
TextPad is highly configurable to suit your personal programming style (such as your preferred font, color, layout, tab spaces, etc). Select "Configure" menu ⇒ Preferences.
  1. Font: "Configure" ⇒ "Preferences" ⇒ Expand "Document classes" node ⇒ Select your desired class, e.g., "Java", and expand the node ⇒ "Font" ⇒ Select monospace font for programming, e.g., Courier New, Courier, Consola, Lucida Console.
  2. Add File Association (e.g., *.xml to use HTML Syntax Highlighting): "Configure" ⇒ "Preferences" ⇒ Expand "Document classes" node ⇒ Click on your desired class, e.g., "HTML" ⇒ In "Files in class xxx", add your file extension, e.g., *.xml, *.jsp.
TextPad Common Errors
ERROR MESSAGE: error: illegal character: \29
SOLUTION: 
  You has non-printable character "\29" (Ctrl-]) in your source code. (You probably meant to use Shift-] for '}'.)
  Remove this character if you can figure out its location. Otherwise, remove the whole line and re-enter the line.

4.2  NotePad++

NotePad++ is an open-source and free program editor that supports syntax highlighting for many languages. It is meant as a "Notepad replacement". You can download NotePad++ from http://notepad-plus-plus.org.
Plug-ins
Notepad++ is highly expandable via third-party plug-ins. Google "notepad++ plug-in" to search for plug-in. To install a plug-in, download, unzip, and move the "dll" file into notepad++'s "plugins" directory.
These are the useful plug-ins:
  1. Hex Editor Plug-in: The hex editor plug-in allows you to view/edit binary files in hex codes. Google "notepad++ plugin hex editor", or from http://sourceforge.net/projects/npp-plugins/files ⇒ from the file list, select "Hex Editor" ⇒ download ⇒ unzip ⇒ move the dll file into notepad++'s "plugins" directory. The Hex Editor will be available from the "Plugins" menu ⇒ "Hex Editor", or the "H" icon on the menu bar.
Tips on Using NotePad++
  1. Reformatting Source Code: TextFX ⇒ TextFXEdit ⇒ Re-indent C++ Code (which also work for java codes).
  2. Block Select: You can select columns of text by holding down the Alt key while selecting (similar to WinWord).
  3. Converting Source Code to HTML: TextFX ⇒ TextFXConvert ⇒ Encode HTML (&<>").
  4. Converting End-of-line (EOL) between Windows, Mac and Unix: Edit ⇒ EOL Conversion ⇒ Choose Windows, Unix or Mac format.
  5. Tile 2 Windows: Right-click on a window ⇒ Move to other view.
NotePad++ for Java Programming
To compile and run Java programs with a single hot-key (just like TextPad), I wrote two batch files called "JavaCompile.bat" and "JavaRun.bat" and save them in the NotePad++ installed directory (or a directory in the PATH).
JavaCompile.bat
@REM To run with: JavaCompile $(CURRENT_DIRECTORY) $(FILE_NAME)
@cd /d %1
javac %2
@pause
JavaRun.bat
@REM To run with: JavaRun $(CURRENT_DIRECTORY) $(NAME_PART)
@cd /d %1
java %2
@pause
To install the batch files, select the "Run" menu ⇒ "Run...", enter "JavaCompile $(CURRENT_DIRECTORY) $(FILE_NAME)" ⇒ Choose "Ctrl-1" as the hot-key for compiling Java program. Similarly, select the "Run" menu ⇒ "Run...", enter "JavaRun $(CURRENT_DIRECTORY) $(NAME_PART)" ⇒ Choose "Ctrl-2" as the hot-key for running Java program. (To use Ctrl-1, Ctrl-2, you need to re-configure and remove the existing mappings for these keys via "Settings" ⇒ "Shortcut Mapper...".)
These are the notepad++ internal variables:
  • $(FULL_CURRENT_PATH): the fully qualified path and name to the current document.
  • $(CURRENT_DIRECTORY): The directory the current document resides in.
  • $(FILE_NAME): The filename of the document, without the directory.
  • $(NAME_PART): The filename without the extension.
  • $(EXT_PART): The extension of the current document.
To modify the commands, you need to edit "shortcuts.xml" (search under your user's AppDate directory).
Using NppExec Plugin
The above Compile-Java batch file, unfortunately, does not automatically save the current file before running the compilation. To automatically save the file, I have to use the "NppExec" Plugin, as follows:
  1. Goto "Plugins" menu ⇒ Select "NppExec". (If you cannot find "NppExec" under plugins, you need to first install the "NppExec" plugin.)
  2. Choose "Execute..." and enter the following commands:
    NPP_SAVE
    cd $(CURRENT_DIRECTORY)
    javac $(FILE_NAME)
    Save it as script name "Java-Compile".
  3. Press "OK" to run the script. You shall see the output on the NppExec's console.
  4. To install a hot-key for this NppExec script:
    1. From "Plugins" menu ⇒ Select "NppExec" ⇒ "Advanced Options...".
    2. In "Menu Item" ⇒ "Associated script" ⇒ Select the script "Java-Compile" ⇒ "Add/Modify". You shall see the item appears in the "Menu Items". If you open the NppExec menu, you will see "Java-Compile" as a menu item.
    3. To install a hot-key (such as Ctrl-1 - make sure it is not used) ⇒ Goto "Settings" ⇒ "Shortcut Mapper" ⇒ "Plugin Commands" ⇒ Select "Java-Compile" ⇒ Modify ⇒ Assign your chosen hot-key.
The above "JavaRun" batch file is fine, as there is no need to save the current file.
NotePad++ for C++ Programming
Similarly, these scripts are used for compiling toy C++ programs using g++.
GccCompile.bat
@REM D:\MyScripts\GppCompile $(CURRENT_DIRECTORY) $(NAME_PART) $(EXT_PART)
@REM Need to save the source file before running this script?!!
@ECHO OFF
cd /D %1
IF /I %3 EQU cpp GOTO CPP
IF /I %3 EQU c GOTO C

:CPP
g++ -Wall -g %2.cpp -o %2
ECHO g++ -Wall -g %2.cpp -o %2
GOTO END

:C
gcc -Wall -g %2.c -o %2
ECHO gcc -Wall -g %2.c -o %2
GOTO END

:END
pause
GccRun.bat
@REM D:\MyScripts\JavaRun $(CURRENT_DIRECTORY) $(NAME_PART)
@cd %1
%2
@pause

4.3  Other Program Editors

Sublime
@ http://www.sublimetext.com.
PSPad
PSPad is an excellent program editor, especially for web programming such as writing JavaScript. It is a freeware and can be download from www.pspad.com. To install, simply run the downloaded installer. The "Help" menu provides many good links to various online programming guides and references.
Editra
Editra (@ http://editra.org): for Windows, Mac and Linux

4.4  Hex Editors

At times, you may need to display the hex values of a file. A Hex Editor is a handy tool that a good programmer should have in his/her toolbox. There are many freeware/shareware Hex Editor available. Try google "Hex Editor".
I recommend notepad++ with the "Hex Editor plugin". Read "NotePad++".

0 comments: