Re: modifyindent changes to ed.ex

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi Ferlin,

    To answer your question,
 1) There should be a space betwen the single quote.
 2) I have no problem using indent/undent.
     buffer[i][1]  should certainly be an atom
     and ' ' is certainly an atom too
     so
     if buffer[i][1] = ' ' then
     should not generated the kind of error you report.

I resend the ModifyIndend() procedure to be certain you have it right

----------------------------------------------------------------------------
----------
procedure ModifyIndent(integer action)
-- if action = 1  add a tab at beginning of each line.
-- if action = 0 undent a tab at beginning of each line or if no tab
-- suppress a blanck.

integer first, last, tab, space, BlkCount, LoopCount
sequence inp
   inp = {1,0}
   while inp[1] do
     if action then
       set_top_line("Number of lines to Indent? (+ down, - up) ")
     else
       set_top_line("Number of lines to undent? (+ down, - up) ")
     end if
     inp = value(key_gets(""))
   end while
   if inp[2] = 0 then
     normal_video()
     return
   end if
   if inp[2] < 0 then
     first = b_line + inp[2] + 1
     if first < 1 then
        first = 1
     end if
     last = b_line
   else
     first = b_line
     last = b_line + inp[2] - 1
     if last > length(buffer) then
        last = length(buffer)
     end if
   end if
   inp = {1,0}
   while inp[1] do
     if action then
      set_top_line("Number of blancks to insert? ")
     else
      set_top_line("Number of blancks to remove? ")
     end if
     inp = value(key_gets(""))
   end while
   BlkCount = inp[2]
   if BlkCount < 1 then
     normal_video()
     return
   end if
   if action then  -- indent
     for i = first to last do
       tab = floor(BlkCount/edit_tab_width)
       space = remainder(BlkCount,edit_tab_width)
       buffer[i] = repeat('\t',tab) & repeat(' ',space) & buffer[i]
       buffer[i] = TabsFirst(buffer[i])
     end for
   else -- undent
     for i = first to last do
       LoopCount = BlkCount
       while LoopCount > 0 do
          if buffer[i][1] = ' ' then
             buffer[i] = buffer[i][2..length(buffer[i])]
             LoopCount = LoopCount - 1
          elsif buffer[i][1] = '\t' then
             if LoopCount < edit_tab_width then
                space = edit_tab_width - LoopCount
                buffer[i] = repeat(32,space) & buffer[i][2..length(buffer[i])]
                LoopCount = 0
             else
                buffer[i] = buffer[2..length(buffer[i])]
                LoopCount =  LoopCount - edit_tab_width
             end if
          else
            exit
          end if
          buffer[i] = TabsFirst(buffer[i])
       end while
     end for
   end if
   b_col = 1
   s_col = 1
   set_modified()
   normal_video()
   DisplayWindow(b_line - s_line + 1, 1)
end procedure -- ModifyIndent()

----------------------------------------------------------------------------
-----------
Jacques Deschenes
Baie-Comeau, Quebec
Canada
desja at quebectel.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu