Automatic Syntax Highlighting…

In Windows Live Writer you can add Plugins that do certain things for you. One of those things is to add syntax highlighting to your postings.

I found a Code Formatter for Windows Live Writer that does just about all you need, except of course for PL/SQL (and Delphi) code. Doing some more searching on the internet, brought me to this page. On this page is explained how to implement code formatting for Delphi Code. It was done relatively easy by placing a new XML file in the languages folder and overwriting one file in your plugins folder. (scroll down to ‘Wrap up’ to find the instructions).

Now, that’s part of the issue solved, how about that PL/SQL code.

I have this code:

CREATE OR REPLACE FUNCTION betwnstr (
   string_in      IN   VARCHAR2
 , start_in       IN   PLS_INTEGER
 , end_in         IN   PLS_INTEGER
 , inclusive_in   IN   BOOLEAN := TRUE
)
   RETURN VARCHAR2
IS
   v_start      PLS_INTEGER;
   v_numchars   PLS_INTEGER;
BEGIN
   IF    string_in IS NULL
      OR (start_in < 0 AND end_in > 0)
      OR (start_in > 0 AND end_in < 0)
      OR (start_in < 0 AND end_in > start_in)
      OR (start_in > 0 AND end_in < start_in)
   THEN
      RETURN NULL;
   ELSE
      IF start_in < 0
      THEN
         v_numchars := ABS (end_in) – ABS (start_in) + 1;
         v_start := GREATEST (end_in, -1 * LENGTH (string_in));
      ELSIF start_in = 0
      THEN
         v_start := 1;
         v_numchars := ABS (end_in) – ABS (v_start) + 1;
      ELSE
         v_start := start_in;
         v_numchars := ABS (end_in) – ABS (v_start) + 1;
      END IF;

      IF NOT NVL (inclusive_in, FALSE)
      THEN
         v_start := v_start + 1;
         v_numchars := v_numchars – 2;
      END IF;

      RETURN (SUBSTR (string_in, v_start, v_numchars));
   END IF;
END betwnstr;

And I want to easily format it into this:

CREATE OR REPLACE FUNCTION betwnstr ( string_in IN VARCHAR2 , start_in IN PLS_INTEGER , end_in IN PLS_INTEGER , inclusive_in IN BOOLEAN := TRUE ) RETURN VARCHAR2 IS v_start PLS_INTEGER; v_numchars PLS_INTEGER; BEGIN IF string_in IS NULL OR (start_in < 0 AND end_in > 0) OR (start_in > 0 AND end_in < 0) OR (start_in < 0 AND end_in > start_in) OR (start_in > 0 AND end_in < start_in) THEN RETURN NULL; ELSE IF start_in < 0 THEN v_numchars := ABS (end_in) - ABS (start_in) + 1; v_start := GREATEST (end_in, -1 * LENGTH (string_in)); ELSIF start_in = 0 THEN v_start := 1; v_numchars := ABS (end_in) - ABS (v_start) + 1; ELSE v_start := start_in; v_numchars := ABS (end_in) - ABS (v_start) + 1; END IF; IF NOT NVL (inclusive_in, FALSE) THEN v_start := v_start + 1; v_numchars := v_numchars - 2; END IF; RETURN (SUBSTR (string_in, v_start, v_numchars)); END IF; END betwnstr;

So I decided to create my own XML file to do the syntax highlighting using this plugin. You can download the XML file here. Please note that I am not an expert on the subject of these XML files, so if you have any ideas on how to make the XML file better, please don’t hesitate to contact me and maybe we can make the PL/SQL code formatter better.

Leave a Reply

Your email address will not be published. Required fields are marked *