1. Re: modifyindent changes to ed.ex
- Posted by Jacques Deschenes <desja at QUEBECTEL.COM> Dec 06, 1996
- 1532 views
- Last edited Dec 07, 1996
Hi Ferlin, There was really a bug in ModifyIndent, I found it after I sent you the last message There was a missing index somewhere in the undent part of the procedure. This was a typo error. But this error was not at the line you reported. To fall on it you had to do successives Indent/undent/indent has the undent was introducing a sequence inside the line. Following is the corrected ModifyIndent() ---------------------------------------------- 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[i][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