When I’m mucking around at home, it’s Linux all the way. Unfortunately, at work ( in desktop terms, at least) I’m still stuck with being a Microsofty.
This leaves me with Textpad as my program editor of choice.
As promised then, here’s the quick and dirty guide to enabling syntax highlighting for PL/SQL in Textpad ( works for versions 4 and 5) …
Step 1 – write a syntax definition file
This file is split into sections :
The first line tells textpad how the language in question is likely to be structured. In the case of PL/SQL, it’s a ‘C’ like language in this sense ( pretty standard 3GL), so we specify :
This is followed by the syntax section, most of which is fairly self-explainatory :
[Syntax] Namespace1 = 6 IgnoreCase = Yes InitKeyWordChars = A-Za-z_ KeyWordChars = A-Za-z0-9_ PreprocStart = SyntaxStart = SyntaxEnd = CommentStart = /* CommentEnd = */ CommentStartAlt = CommentEndAlt = SingleComment = -- SingleCommentCol = StringStart = ' StringEnd = ' StringAlt = StringEsc = CharStart = ' CharEnd = ' CharEsc =
Namespace1 is set to 6 because we're going to divide our keywords into six different categories, each of which can – if we so wish – be highlighted using a different colour.
In this example, I've split the keywords into six categories :
- SQL keywords
- SQL functions
- PL/SQL keywords
- SQL*Plus formatting commands
- Other SQL*Plus commands.
The entire file looks like this :
C=1 [Syntax] Namespace1 = 6 IgnoreCase = Yes InitKeyWordChars = A-Za-z_ KeyWordChars = A-Za-z0-9_ PreprocStart = SyntaxStart = SyntaxEnd = CommentStart = /* CommentEnd = */ CommentStartAlt = CommentEndAlt = SingleComment = -- SingleCommentCol = StringStart = ' StringEnd = ' StringAlt = StringEsc = CharStart = ' CharEnd = ' CharEsc = [Keywords 1] (+) all and any as between cast commit connect by cube delete distinct exists explain plan for update from group by having in insert is null like lock table intersect multiset minus not or order by partition returning rollback rollup sample savepoint select set constraint set transaction some start with subpartition table the union update values where where current of with [Keywords 2] abs acos add_months ascii asin atan atan2 avg bfilename bitand ceil chartorowid chr concat convert cos cosh count dangling decode deref dump empty_blob empty_clob exists exp floor glb greatest grouping hextoraw initcap instr instrb last_day least length lengthb like ln log lower lpad ltrim make_ref max min mod months_between new_time next_day nls_charset_decl_len nls_charset_id nls_charset_name nls_initcap nls_lower nls_upper nlssort null nvl power rawtohex ref reftohex replace round rowidtochar rpad rtrim sign sin sinh soundex sqrt stddev substr substrb sum sys_context sys_guid sysdate tan tanh to_char to_date to_lob to_multi_byte to_number translate trim trunc uid upper user userenv variance vsize [Keywords 3] level currval nextval rownum rowid [Keywords 4] %found %isopen %notfound %rowcount %rowtype %type authid autonomous_transaction begin bulk collect bulk collect into call close constant count create function create package create package body create procedure create trigger create type create type body cursor declare delete else elsif end end if exception exception_init execute immediate exists exit extend fetch first for forall function goto if insert into label language last limit lock table loop map member next null open open for order pragma prior procedure raise raise_application_error record restrict_references return savepoint self serially_reusable set transaction sql sqlcode sqlerrm subtype table then trim type when where current of while varchar2 number boolean binary_integer integer char long blob clob [Keywords 5] / @ @@ accept attribute break btitle clear col column comp compute def define exit ho host pause prompt rem remark repf repfooter reph repheader run set spool start sta timi timing ttitle undef undefine var variable [Keywords 6] app appinfo array arraysize autocommit autop autoprint autotrace blo blockterminator cmds cmdsep colsep com compatibility con concat copyc copycommit copytypecheck echo esc escape feed feedback flu flush hea heading heads headsep lines linesize long longchunksize newpage numformat numwidth pages pause recsep recsepchar serveroutput show showmode sqlcase sqlcontinue sqlnumber sqlprefix sqlprompt suffix tab termout term time timing trim trimout underline verify wrap
Once we're done, save the file under the Textpad Home system directory ( usually C:\Program Files\ Textpad n\System ( where n is the version of Textpad you're using).
Step 2 - Setup a New Document Class
Open Textpad and select the Configure menu then New Document Class. You'll then get a series of dialog boxes to step through.
Specify the class name as PL/SQL
Class members – the file extensions for which this definition file is to be used (*.sql, *.fnc, *.pkb, *.pks, *.prc, *.trg, *.tbl)
Check Enable Syntax Highlighting
Syntax Definition File :
select plsql.syn from the drop-down
Finally, hit Finish.
Step 3 - Configure the PL/SQL Class
Close and restart Textpad.
In the Configure menu, select Preferences
Select Document Classes from the Tree in the left hand pane
PL/SQL should be there.
In the Document class options, you can set further preferences, mine are usually :
Word wrapped text : Save with no breaks in lines
Default encoding : ANSI
Create new files as : PC
If the mood takes you, you can also specify the colours to be used for each class of keyword you specified in the definition file. I usually leave them at the default ( but then, I never was artistic).
When it comes to running code written in Textpad, I usually just run a command line from within Textpad( Tools/Run then cmd in the command dialog) and start a sqlplus session.
The command session starts in the same directory as the saved file in focus in Textpad, which is handy for making quick edits as you can just switch between Textpad and the command prompt.