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

I added a procedure to ed to comment or uncomment a group of lines
the two functions are accessed by ALT_C to comment out and ALT_U to uncomment

to modify  ed.ex do (backup ed.ex before any change)

1) find "-- special input characters"
2) add ALT_C = 302, and ALT_U = 278 to the list of constants
3) add ALT_C,ALT_U to CONTROL_CHARS constant
4) find "edit_file()" procedure and paste the following lines
   at the right place

                                elsif key = ALT_C then
                                        SetComment(1)  -- comment lines

                                elsif key = ALT_U then
                                        SetComment(0) -- uncomment lines


5) paste the following procedure somewhere before edit_file()

procedure SetComment(integer action)
-- if action = 1 then comment out a group of lines
-- if action = 0 then uncomment a group of lines

integer first, last,j
sequence inp
   inp = {1,0}
   while inp[1] do
     if action then
       set_top_line("Number of lines to comment out? (+ down, - up) ")
     else
       set_top_line("Number of lines to uncomment? (+ down, - up) ")
     end if
     inp = value(key_gets(""))
   end while
   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
   if action then -- comment out
     for i = first to last do
           j = 1
           -- skip white space and tab at line start
           while j <= length(buffer[i]) and find(buffer[i][j], " \t") do
          j = j+1
           end while
          if match("--",buffer[i][j..length(buffer[i])]) != 1 then
                 buffer[i] = "--" & buffer[i]
          end if
     end for
   else  -- uncomment
     for i = first to last  do
           j = 1
           -- skip white space and tab at line start
           while j <= length(buffer[i]) and find(buffer[i][j], " \t") do
          j = j+1
           end while
       if j < length(buffer[i]) then
         if match("--", buffer[i][j..length(buffer[i])]) = 1 then
                buffer[i] = buffer[i][j+2..length(buffer[i])]
         end if
       end if
     end for
   end if
   set_modified()
   normal_video()
   DisplayWindow(b_line - s_line + 1, 1)
end procedure --SetComment()


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