How to use PopsEdit plugin

Background

I’ve always hated under-powered editors and am a firm believer that the editor should not only take a lot of the drudgery out of programming but also work with you as you are coding to show you potential mistakes and does all this quickly.  I created PopsEdit based on features I would like to see in an editor and tried to make it as customizable as possible for other people to enjoy. 

 

Some of the features are:

1)      Undo/Redo

2)      Color syntax highlighting (for both Java & C++)

3)      Line numbering

4)      Auto Indentation

5)      Code Shifting

6)      Extensive bracket matching as you type (because I’m really bad at that)

7)      Word Completion (not code completion)

8)      Code library pasting

9)      Abbreviation substitution

10)  Code pretty’ing (to see where my brackets are still screwed up)

11)  Block comment/uncomment ability

12)  Local compilation and within code error highlighting (Java only)

13)  Complete control over the look and feel (tab size, fonts, colors)

14)  Complete control over the hotkeys (including support for multiple hotkey combos like CTRL-K CTRL-C) that should allow you to emulate most other editors.

15)  TopCoder specific functionality:  initial code templates that can build the initial problem

16)  Integrated debugger and local testing (Java only)

17)  Full screen editor and full screen problem description viewing

 

 

If you were to say “Hey – this looks like the open-source editors JEdit and Jext” – you’d be right (www.jedit.org and www.jext.org).  The underlying code was borrowed and heavily modified from different versions of both those projects.  I essentially took the source code and ripped out/replaced about 50% of the code to make them fast yet retain the essential features.  The local compilation for java is accomplished by Sun’s javac functionality and the  debugger is based (somewhat) on Sun’s example console debugger.

 

Last note: this is my editor and reflects my personal choices.  I don’t like response boxes getting in my way while coding so you won’t find any here (even with find/replace).  Don’t like the default hotkeys or colors – change them!  Find a bug that rarely appears – it rarely appears – get over it!  Find some action confusing – tough – write your own editor.  J

Policy File Settings

To use this plugin – you need to allow the contestapplet to create and set a security manager.  Find the policy file that is being used by the java plugin and add to the top of the file:

 

grant codeBase "http://www.topcoder.com/-" {

  permission java.lang.RuntimePermission "setSecurityManager";

  permission java.lang.RuntimePermission "createSecurityManager";

};

 

After making this change, you should either reboot your PC or atleast close all browser windows and restart your browser for the settings to take affect.

Use

First you must define the PopsEdit plugin within the TCApplet:

1)      Start the TCApplet and sign in

2)      From the options menu, select Editors

3)      Press the ADD button

4)      For the name, type “PopsEdit”

5)      For the entry point, type “popsedit.EntryPoint”  (case is important here)

6)      For the classpath, press the browse button and navigate to where you put the PopsEdit.jar – double click on it.

7)      If you program in java, use Sun’s jdk and wish to enable local compiling/debugging, press the browse button again and navigate to where the tools.jar file is – double click on it (it’s location will be added to the classpath).

8)      Press OK.  The new PopsEdit plugin should appear.  If you have made a mistake anywhere, simply double-click and correct.

9)      If you want to make PopsEdit your default editor – check the default box next to the plugin.

10)  Configure the PopsEdit plugin (see below for configuration options) by pressing the Configure button.  Note: this will take some time to come up – since it’s rarely used, I didn’t to anything to improve this.

11)  Press the Save button and exit.

 

The next section assumes you are using the default configuration, your default language is Java and that you made the PopsEdit plugin the default editor.

 

Now the fun part!

 

Go to any practice room and open up any problem.  When the problem opens, you will notice the editor area now contains the PopsEdit editor (you will see it’s banner line at the bottom).  I can’t give you the full tour as to functionality but will hit some of the highlights.  You can look through the actions section for an explanation of what actions are available and then toy with them to see how they work.

 

Start coding you solution.  You should immediately notice the extensive bracket matching.  Every time you type a bracket (or parenthesis) – the matching one will be highlighted.  Additionally – the gutter area (line number area) will continually show you a visual representation of the scope of the brackets the cursor is enclosed by.  Still confused – press CTRL-B and it will highlight all the code between the brackets.  Ugh – still can’t tell because my code sucks – press CTRL-SHIFT A and your code will be reformatted with indentation at each new bracket level.  Yes – I am that bad at it…

 

Press CTRL-F and a find line will appear in the banner area.  Simply type what you want to find and press ENTER to highlight the next instance.  You can press the “…” button next to the find label to have more control over the find.  Press F3 to then repeat your find.  Press CTRL-R and a find/replace line will appear in the banner area.  Enter your find text, press enter, enter your replace text and press enter to execute the replace.  CTRL-L then repeat the find.  Again – press the “…” button next to the find label to have more fine control over the process (including replace all).

 

Ugh – the method has a parameter called “thisisaverylongparameter”.  Type in “this” and press SHIFT-ENTER – the word will be completed (if more than one word matches what you entered – a dropdown with the choices will be shown).

 

Tired of typing loops in.  Define an abbreviation call “FR” that contains “for(int $1=0,$1<$2;$1++) {}”.  Then in your code type in “FR#x#stringparm.length()#” and press CTRL-ENTER.  The code will be expanded to “for(int x=0;x<stringparm.length();x++) {}”

 

Got a generic month end table, isVowel routine, breadth first routine.  Define it in HotCode and press it’s corresponding hotkey to have it automatically pasted.

 

Using Sun’s JDK and are using Java?  Press CTRL-F7 to compile your source code – any errors will be highlighted within your code and the banner line will display the error as you cursor to it (or press F7 find the next error).

 

Want to debug your program – define a main method in your source and press CTRL-F5.  The debugger will open up in a separate window allowing you to step through your code, set breakpoints and run to them, look at variable values and see what’s written to sysout and syserr.  Note:  you will NOT step into any of the standard java libraries and many of the java utility objects will display their values immediately (StringBuffer will show what’s in it’s buffer, StringTokenizer will show what the next token is, etc).  You can set breakpoints by simply clicking on the line IN THE DEBUGGER (not while coding).  The debug points will be remembered if you debug the same code more than once.

 

One hint – you can also use the debugger to do local testing.  Define the test criteria in your main method writing the results to sysout.  Run the debugger and simply step over all your tests – then view the sysout tab to see the results.

Gotcha’s…

1).  If you are using the local compilation option – you need to remember to compile using the TCApplet compile button prior to testing or submitting.  The reason is that the TC system will use the last compiled code during the test/submit process.  The TC system cannot detect when you compile locally with this plugin.  If you were to remotely compile, make a change, then locally compile – the test (or worse submit) will use the code that was remotely compiled.

2).  Be careful when running the debugger on a function that causes an endless loop.  Although you can cancel the session using the “Stop Debug” icon – the endless loop function is taking nearing 100% of the CPU and it will take time (a few frightening seconds) for the stop to get communicated to the java VM.  It will appear that everything has locked up in the meantime…

3).  Local testing timeout does NOT correspond directly to the timeout parameters of the TC System.  Local testing timeout will time out your main method – regardless of how many tests you are running in that method.

Functionality of the standard TCApplet Keys

SAVE

The save key will save the source found in PopsEdit

 

CLEAR

The clear key will clear the source code found in PopsEdit

 

COMPILE

The compile key will compile the source code found in PopsEdit

 

TEST

The test key will remotely test the last compiled (with the compile key above) source code.  See Gotcha’s above.

SUBMIT

The submit key will submit the last compiled (with the compile key above) source code. See Gotcha’s above.

 

 

Configuration Options – General Tab

Include Signature

This tells the PopsEdit plugin to either include or exclude the method signature.  If checked (the default), the method signature (see “Code Template” below) will be written to the file.

Default to Case-Sensitive Find/Replace

Whether the default of find/replace is to be case sensitive or not.   Default: false

Default to Wrap-Around Find/Replace

Whether the find/replace should wrap around to the beginning of the file or not.  Default : true

Default to Finding-Forward

Whether the find should default to forward or reversed.  Default: true

Block Caret

Whether the caret should be a block.  Personally – I hate this so the default is false.

Blink Caret

Whether the caret should blink.  Ugh – even more annoying and you should be ashamed if you like this - default is false.

Highlight Line

Whether the line the caret is on should be highlighted.  Default: true

Highlight Bracket

Whether the the matching bracket should be highlighted.  Default: true

Include Line Numbers

Whether the “gutter” containing the line numbers should appear.  Default: true

Auto-Indent

Whether the code should be auto-indenting as you type.  Default: true

Compressed Pretty Print

Whether pretty print will output a compress version of your code.  This will eliminate blank lines and put the bracket at the end of the associated line.  Default: true

Show Bracketing in Gutter

Whether the scope of the current bracket is show in the gutter.  Default: true

End of Line Marker

Whether the specified character represents the end of the line.  Default: true

End of Code Marker

Whether the specified character represents the end of the code.  Default: false

Enable local Java Compile

Whether to enable local compiles.  You need to specify the location of the Sun’s tools.jar file on your PC.  Note: someday I will add a browse button to this.  Default: true

Undo Limit

How far back undo can go.  Default: 100

Tab Stops

Almost the single best feature – setting the tab stops used by the editor.  Say goodbye to Sun’s default of 8!   Default: 8 J

Electric Scroll

The number of lines ahead of the cursor to show on the screen.  Example: if you have an electric scroll of 3 and you are scrolling down the window – it will attempt to keep three lines of code displayed ahead of the cursor.  Default: 3

Abbreviation Separator

The character used to separate parameters in abbreviations.  Be careful in choosing your separator!  If you use a commonly used character in your language – you will get bizarre abbreviation expansions.  Default: #

Enter signature file

Enter the location of a signature file you wish added to the top of your source when it is submitted.  Please note: this file is taken as is – so make sure that it contains information that can be compiled correctly in your chosen language

Configuration Options – Look and Feel

Here is where you can specify the font and what colors the editor uses to display everything.  Everything is self-explanatory except for the Code Highlight section.  Each support language (Java & C++) is mapped to those categories.  You can set how the mappings are displayed.  What is mapped where – create an example code and see what color comes out.  If you really want to know – email me and I’ll send you the list.

 

BTW – you may think – wow it would be nice if you showed an example as we changed it.  That was simply not worth the time and effort to do.  You can simulate that by coding out a problem in a practice room and pressing F1 – then split the screen so you see both the code and configuration.  Make a change – press save – the code will be updated (I think).

Configuration Options – Code Template

 

The Code Template panel allows you to specify two things the generic template to initially use for which language.  You can setup your imports/includes and the initial code (include main method if you want).

 

The PopsEdit plugin allows you to specify variables that will be replaced at the time of the initial write:

 

$CLASSNAME$ will be replaced with the classname for the problem

$RC$ will be replace with the return type for the problem (example: “String” for a java string or “string” for a C++ string)

$METHODNAME$ will be replaced with the methodname for the problem

$METHODPARMS$ will be replaced with the parameter list (type followed by space followed by name) for method.  Please note that the PopsEdit plugin will scan the problem description in an attempt to provide the real names for each parameter.  If it is unable to find or parse the parameter names, they will be named by ascending letter (“a” for the first parameter, “b” for the next, etc).

 

$CARETPOSITION$ will be replaced with the caret when the problem is opened.

 

Configuration Options – Hot Code

Think of this as your code library.  You have up to 10 (get more in the professional version J) code snippets that you can store here.  Note:  you are not limited to one or two lines – hit the “…” button to expand it and put in your favorite A* snippet.  You can then paste it in by pressing the HotKey associated with the library (see the hotkey tab).

 

Configuration Options – Hot Keys

PopsEdit allows every one of the actions to be mapped to the hotkey of your desire.  To assign a different hot key to an action:

1)      Press the CLEAR button next to the line

2)      Press the desired key combinations to activate the action. 

 

You can type more than a single key.  If you want CTRL-K CTRL-C to perform a copy, simply press CTRL-K followed by CTRL-C.

 

See the actions section for a description of what the actions do.

Configuration Options – Abbreviations

Abbreviations are similar to shorthand.  You type in an abbreviation and then hit the hotkey to expand that abbreviation.  What makes them especially powerful is that you can specify substitution to the abbreviation at expansion time…

 

This tab allows you to add/edit/delete abbreviations.  Press the ADD key or Edit key on an existing one or double clicking on an existing one will bring up the abbreviation detail dialog.

 

You should type the in the provided line.  Then the text that will be inserted prior to the caret and the text that will be insert after the caret.  You can specify substitution placeholders by $x where x is a unique number.

 

All this should be clear with the use of an example:

 

Define the abbreviation of “FR” with the text before being “for(int $1=0;$1<$2;$1++) {\n\t“ (don’t actually type the \n and \t – use the newline and tab instead) and the text after being “}”

 

Save the changes and open up a problem.  Type in the editor:

 

FR#x#myString.length()#˙

 

(where ˙ represents the current caret position) and press CTRL-ENTER.  This will then be expanded to:

 

for(int x=0;x<myString.length();x++) {

            ˙

}

 

(again where ˙ represents the caret position).  Let your imagination come up with the abbreviations that you use the most and define them.

PopsEdit Actions

 

fAbbreviation – Expands the abbreviation preceding the current caret position

Backspace (and alternative backspace) deletes the prior character

Backspace Word – delete the prior word

Comment Code – line comment the selected lines of code

Compete Word – attempts to complete the word prior to the caret position

Configuration – opens up the configuration dialog

Copy – Copy’s the selected text to the clipboard

Cut – Cut’s the selected text to the clipboard

Delete Character – deletes the next character

Delete Line – deletes the line the caret is on

Delete to End of Line – deletes everything from the cursor position to the end of the line.  If this is all whitespace, then it deletes the newline character also.

Delete Word  - deletes the next word

End – goes to the end of the current line.  If at the end of the line, goes to the end of the file

End to End – goes to the end of the file

Find – opens the find line to find text

Find Next – repeats the last find

Goto Line – goto a specific line

Home – goes to the beginning of the line.  If at the start of the line, goes to the start of the file

Home to Beginning – goes to the beginning of the file.

Insert NewLine – inserts a newline if the caret is at the end of the line.  Splits the current line if the caret is in the middle of a line.

Insert Tab – inserts a tab at the current caret position.

Next Char – advances the caret one character position to the left.

Next Line – advances the caret down one line.

Next Page – advances the caret down one page.

Next Word – advances the caret to the next word

Paste – pastes the text from the clipboard to the current caret position

Pretty Code – attempts to make the code “pretty”

Prior Char – advances the caret one character position to the right.

Prior Line – advances the caret up one line.

Prior Page – advances the caret up one page.

Prior Word – advances the caret to the prior word

Redo – redoes the last undo

Replace – opens the replace line to replace text

Replace Next – repeats the last replace

Scroll Down – scrolls down one line without changing the caret position

Scroll Up- scrolls up one line without changing the caret position

Select All – selects all the text

Select End – selects all the text from the current caret position to the end of the line (repeat to select to the end of the file)

Select Home – selects all the text from the current caret position to the start of the line (repeat to select to the start of the file)

Select Inside Brackets – selects all the text within the brackets that enclose the current caret position

Select Next Character – selects the next character and advances the caret

Select Next Line – selects the text from the current caret position to the next line and advances the caret position

Select Next Page – selects the text from the current caret position to the next page and advances the caret position

Select Next Word – selects the text from the current caret position to the next word and advances the caret position

Select Prior Character – selects the prior character and advances the caret

Select Prior Line – selects the text from the current caret position to the prior line and advances the caret position

Select Prior Page – selects the text from the current caret position to the prior page and advances the caret position

Select Prior Word – selects the text from the current caret position to the prior word and advances the caret position

Select Next Character – selects the next character and advances the caret

Select Next Line – selects the text from the current caret position to the next line and advances the caret position

Select Next Page – selects the text from the current caret position to the next page and advances the caret position

Select to Beginning – selects all the text from the current caret position to the beginning of the file

Select to End – selects all the text from the current caret position to the end of the file

Shift Code Left – shifts all the selected lines of code one tab stop to the left

Shift Code Right – shifts all the selected lines of code one tab stop to the right

Toggle Overwrite – toggles the overwrite mode

Uncomment Code – attempts to uncomment any line comments

Undo – Undo the last change

 

Actions related to local Java Compiling

Compile Java – locally compiles the java source code

Goto Next Error – goes to the next compile error

Show Error Details – shows the details of the current error

Toggle Error Messages – toggles the highlight and display of error messages

 

Actions related to local Java Debugging

Run – run to the next breakpoint (or end)

Step – steps one line

Step out – steps out of the current method

Step over – steps over the current method (executes the method without breaking)

Stop – stops executing in the debugger

Toggle Break Point – toggles the breakpoint on the current line