Tab-key For Cobol Users

Find Tips and tricks on how to better use the Zeus IDE. Feel free to post your own tips but please do not post bug reports, feature requests or questions here.
Post Reply
Berry Jansen
Posts: 4
Joined: Fri Sep 23, 2005 10:39 am

Tab-key For Cobol Users

Post by Berry Jansen »

This marco adds special features when using the tab-key for cobol users.
Of coarse you can makes changes for your own language.

Tabs will be inserted as spaces.
1st tab stop at position 8
2nd tab stop at postions 12
After position 12 it will look at lines above where the next word will begin. If no word can be found it will use 4 spaces.

When a selection has been made the selected lines will be indented in 2 possible ways:
When the line before the selected area starts at a higher position than the first line of the selected area, the lines will indented to the position of the line before the selected line.
When not it will be indented 3 positions higher that the line before the selected area (it will be indented backward when the position of the selected area is already more than 3).
Only lines which have colomn 1-11 empty will be indented. So comment lines or paragraph names will be untouched.

Code: Select all

function coboltab_macro()
    screen_update_disable()
    local int bottom = 0
    local int pos = get_cursor_pos()
    local marked = is_marked()
    if marked == 1 then
      local int found = 0
      local int b = 0
      -- get the marked text details
      top   = get_marked_top()
      bottom = get_marked_bottom()
      MarkHide()
      cursor_save()
      set_line_pos(top)
      local string msg = ""
      repeat
         MoveLineUp()
         MoveLineHome()
         MoveWordNext()
         b = get_cursor_pos()
      until (b >= 12 or get_line_pos() == 1)
      set_line_pos(top - 1)
      repeat
         MoveLineDown()
         MoveLineHome()
         MoveWordNext()
      until (get_cursor_pos() >= 12)
      pos = get_cursor_pos()
      local int i = 0
      if (pos < b) then
         i = b - pos
      else
         i = b - pos + 3
      end -- if
      b = i
      local string ident = ""
      while (i > 0) do
         ident = ident.." "
         i = i - 1
      end -- while
      while (top <= bottom) do
         set_line_pos(top)
         if (get_char_at(top,7) == 32 and get_char_at(top,8) == 32) then
            MoveLineHome()
            if (i < 0) then
               local int r = i
               while (r < 0) do
                  MarkDeleteEx()
                  r = r + 1
               end -- while
            else
               print(ident)
               MoveLineEnd()
               MoveLineLeft()
               if (get_char_at() == 46) then
                  MarkDeleteEx()
               end -- if
            end -- if
         end -- if
         top = top + 1
      end -- while
      cursor_restore()
      i = get_cursor_pos() + b
      set_cursor_pos(i)
    else
       local int b = 0
       local int line = get_line_pos()
       if (pos < 12) then
          if pos < 8 then
             b = 8
          else
             b = 12
          end -- if
       else
          if (get_char_at() == 32) then
             MoveWordNext()
             pos = get_cursor_pos()
          end -- if
          while (get_line_pos() > 1 and b == 0) do
             MoveLineUp()
             if (get_char_at() ~= 0) then
                while (get_char_at() ~= 32 and get_char_at() ~= 0) do
                   MoveLineRight()
                end -- while
                -- while (get_char_at() == 32) do
                --    MoveLineRight()
                -- end -- while
                MoveWordNext()
                if (get_char_at() ~= 0) then
                   b = get_cursor_pos()
                else
                   set_cursor_pos(pos)
                end -- if
             end -- if
          end -- while
          set_line_pos(line,pos)
          if (b <= pos) then
             b = pos + 4
          end -- if
       end -- if
       repeat
         print(" ")
         pos = pos + 1
       until (pos >= b)
    end -- if
    screen_update_enable()
    screen_update()
end

coboltab_macro() -- run the macro
Last edited by Berry Jansen on Mon Sep 26, 2005 7:33 am, edited 1 time in total.
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Berry,

There seems to be a small typo in the macro source. When I ran this Lua macro it reported and error when running the get_text_at function :(

I assumed this was meant to be the get_char_at function instead and sure enough when I made this small change the macro worked fine :D
After position 12 it will look at lines above where the next word will begin. If no word can be found it will use 4 spaces
I do like the way the your macro implements this behaviour. Nice work :wink:

Cheers Jussi
Berry Jansen
Posts: 4
Joined: Fri Sep 23, 2005 10:39 am

Post by Berry Jansen »

You might be right about that, but on Zeus V3.80 there is no diference between the get_text_at() and get_char_at() functions :( . So sometimes I mix them up.
I've changed it and I'll keep it in mind for the next time, thanks. (I wish there was a fix for this).
Post Reply