define sl_comment_line()
{
  bol();
  while(looking_at (" ") or looking_at ("	"))
    right(1);
	
  if (looking_at ("%"))
  {
    del();
  }
  else
  {
    insert_char ('%');
  }
  down(1);
  bol();
}

define c_comment_line()
{
  bol();
  while(looking_at (" ") or looking_at ("	"))
    right(1);
  if (looking_at ("//"))
  {
    del();
    del();
  }
  else
  {
    insert ("//");
  }
  down(1);
  bol();
}

define perl_comment_line()
{
	push_spot ();
	bol_skip_white ();
	if (looking_at ("#"))
	{
		del ();
		if (looking_at (" "))
		  del ();
	} else {
		insert ("# ");
	}
	pop_spot ();
  down(1);
}

define php_comment_line()
{
  bol();
  while(looking_at (" ") or looking_at ("	"))
    right(1);
  if (looking_at ("//"))
  {
    deln(2);
		if (looking_at (" "))
		  del ();
  }
  else
  {
    insert ("// ");
  }
  down(1);
  bol();
}

define java_comment_line()
{
  bol();
  while(looking_at (" ") or looking_at ("	"))
    right(1);
  if (looking_at ("//"))
  {
    deln(2);
		if (looking_at (" "))
		  del ();
  }
  else
  {
    insert ("// ");
  }
  down(1);
  bol();
}

define sh_comment_line()
{
  bol();
  while(looking_at (" ") or looking_at ("	"))
    right(1);
	
  if (looking_at ("#"))
  {
    del();
  }
  else
  {
    insert_char ('#');
  }
  down(1);
  bol();
}

define comment_line()
{
   variable mode;
   variable flags;
   (mode, flags) = what_mode ();
  %!if (strcmp(mode,"SLang")) {	% Slang mode
    %tt_send("--(Slang)--");
  %}
  %!if (strcmp(mode,"Perl")) {	% Perl mode
    %tt_send("--(Perl)--");
  %}
		
  !if (strcmp(mode,"SLang")) {	% SLang mode
     sl_comment_line();
  }
  !if (strcmp(mode,"C")) {	% C mode
     c_comment_line();
  }
  !if (strcmp(mode,"php")) {	% PHP mode
     php_comment_line();
  }
  !if (strcmp(mode,"PHP")) {	% PHP mode
		php_comment_line();
  }
  !if (strcmp(mode,"java")) {	% PHP mode
		java_comment_line();
  }
  !if (strcmp(mode,"perl")) {	% Perl mode
     perl_comment_line();
  }
  !if (strcmp(mode,"PERL")) {	% Perl mode
     perl_comment_line();
  }
  !if (strcmp(mode,"SH")) {	% mode
     sh_comment_line();
  }
  %tt_send(mode);
   
}

setkey("comment_line",     "[12~");
setkey("comment_line",     "[20~");
