SnippetProcessor

Well, whilst writing my last post about generics, I realised one of the long standing issues I have with pre-formatted code segments in my blog. It doesn’t handle it very well as illustrated in this example:-


function countLeadingSpaces(src:string):integer;
var
loop : integer;
begin
if (length(trim(src))>0) then
begin

Having had to manually tweak code segments for quite some time I decided it was time to write something that will automate the process for me. If you have a need for something similar read on.

This little program, takes text such as this:-

        if (temp<>'') then
        begin
          if (globalShortWordsToIgnore.IndexOf(temp)<0) then
          begin
            if (individualWords.indexOf(temp)<0) then
            begin
              individualWords.add(temp);
            end;
          end;
        end;

And formats it (adding the line numbers) so that it looks like this:-

1: if (temp<>'') then
2: begin
3:   if (globalShortWordsToIgnore.IndexOf(temp)<0) then
4:   begin
5:     if (individualWords.indexOf(temp)<0) then
6:     begin
7:       individualWords.add(temp);
8:     end;
9:   end;
10: end;

And then, when it's in a specially classed PRE tag, like this:-

1: if (temp<>'') then
2: begin
3:   if (globalShortWordsToIgnore.IndexOf(temp)<0) then
4:   begin
5:     if (individualWords.indexOf(temp)<0) then
6:     begin
7:       individualWords.add(temp);
8:     end;
9:   end;
10: end;

You can download it here:- SnippetProcessor (Ver. 1.1.1). It's very basic. Paste the text into the memo, click the 'Process' button and hey presto, the job gets done. It supports the following keyboard shortcuts (when the memo has focus):-

  • CTRL+A - Select all
  • CTRL+C - Copy selected text
  • CTRL+V - Paste
  • CTRL+X - Cut selected text

Thats all :-)

Tags:

Leave a Reply

 

Bad Behavior has blocked 120 access attempts in the last 7 days.