PL/SQL Syntax Highlighting in Textpad – for when you can’t play with Penguins

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 :

C=1

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 :

  1. SQL keywords
  2. SQL functions
  3. Pseudo-columns
  4. PL/SQL keywords
  5. SQL*Plus formatting commands
  6. 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 :

Maintain indentation
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.

About these ads

8 thoughts on “PL/SQL Syntax Highlighting in Textpad – for when you can’t play with Penguins

  1. I am so very with you on Textpad. I’m at my 5th job since discovering it, and it is an invaluable tool. It does exactly what I need it to do and keeps out of my way.
    Personally, I just downloaded some syntax definitions and went through those til I found one I liked.
    I also find the ‘find in files’ function to be VERY useful.
    One of the things I do is load XML files through one of our applications. For each record in the file that generates an error, an XML file will be written out containing information about the error and the record.
    Sometimes 20…50…or 100+ of these error files will be created.
    Having Textpad do a find in files for the string ‘Error Is:’ allows me to quickly scan down the list of errors and make decisions without having to open each and every XML file.
    And when 99% of those errors are identical, I can go to the one-offs quickly by double-clicking the result.
    Very nice.

  2. Mike, this is very helpful. Very clear and very simple. Sharing is caring – thank you for caring and sharing! ;)

  3. Pingback: ANSI Joins and Uppercase Keywords – making PL/SQL look less like COBOL | The Anti-Kyte

  4. Pingback: ANSI Joins and Uppercase Keywords – making PL/SQL look less like COBOL - Oracle - Oracle - Toad World

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s