jed-users mailing list

[2003 Date Index] [2003 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: Mail mode


On Wed, May 07, 2003 at 08:39:40AM +0200, Paul Boekholt wrote:
> > > G|nter Milde <milde@xxxxxxxxxxxxxxxxxxxx> wrote:
> > ... How about using the
> > comments.sl functions for quoting and dequoting by
> >   set_comment_info("> ", "", flags);
> > in mail_mode()?
> >
> > In order to do this, routines to reformat a quoted text should be
> > incorporated (as reformat_comment) into comments.sl. ...
>
> Reformatting for comments would be nice. However comments and mail quotes
> are two different things, because mail can  be quoted multiple levels
> whereas in comments only the first "%" character is significant.

However, it should work, as long as the levels are separated by space (i.e.
"> >" != ">>")

Furthermore, I thought about making comments a bit more relaxed about the
space, i.e.
   %variable c =3;
should be accepted as a commented line as well. Generally I'd prefer if the
spaces where handled by the comment_* functions, i.e. instead of
   set_comment_info("> ", " <", 0);
we had
   set_comment_info(">", "<", 0);
. I did not think about the
> ... if you
> have "%%%" at the beginning of the line that's a section separator and
> should be left alone...
yet.

Also, it would be nice if one did not have to give the comment string(s)
twice to jed: with define_syntax and with set_comment_info.


I append my net-search finding regarding a mail mode -- a stripped down
version of mailmode.sl.

G|nter

--
Milde at ife.et.tu-dresden.de
% mailmode.sl
%
% This file was originally written by the following people:
%      Ulli "Framstag" Horlacher <framstag@xxxxxxxxx>
%      Thomas Roessler <roessler@xxxxxxx>
%      ftp://ftp.mutt.org/pub/mutt/contrib/
%
% It was substantially modified by the following people:
%      Abraham vd Merwe <abz@xxxxxxxxxxxx>
%      Johann Botha <joe@xxxxxxxxxxxx>
%      http://oasis.frogfoot.net/index.php?feedme=jed
%
% 2001-03-21: Stripped down to a 'light' mode again..
% /Ulf
%

$1 = "MAIL";
!if (keymap_p ($1)) make_keymap ($1);

% Do we recognize mbox style "From " lines as headers?
variable mail_mode_have_mbox = 1;
variable mail_maybe_header = 1;

create_syntax_table ($1);

define_syntax ("([{",")]}",'(',$1);             % parentheses
define_syntax ("-0-9a-zA-Z_",'w',$1);           % words
define_syntax ("-+0-9",'0',$1);                 % numbers
define_syntax (",;:",',',$1);                   % delimiters
define_syntax ("%-+/&*=<>|!~^",'+',$1);  % operators

static variable color_from = "preprocess";
static variable color_to = "keyword1";
static variable color_subject = "number";
static variable color_header = "...";
static variable color_url = "keyword";
static variable color_email = "keyword";
static variable color_signature = "error";
static variable color_reply1 = "comment";
static variable color_reply2 = "string";
static variable color_smiley = "operator";
static variable color_bold = "delimiter";
static variable color_underline = "delimiter";
static variable color_italic = "delimiter";

% never do this in a mode not configurable:
% set_color ("preprocess","magenta","black");     % from
% set_color ("keyword1","magenta","black");       % to
% set_color ("number","magenta","black");         % subject
% set_color ("...","magenta","black");            % headers
% set_color ("keyword","red","black");            % url/email
% set_color ("error","red","black");              % signature
% set_color ("comment","cyan","black");           % quote1
% set_color ("string","green","black");           % quote2
% set_color ("operator","white","black");         % smiley
% set_color ("delimiter","white","black");        % underline/bold/italic
% set_color ("normal", "lightgray", "black");

#ifdef HAS_DFA_SYNTAX
% The highlighting copes with email addresses and url's
dfa_enable_highlight_cache ("mailmode.dfa",$1);

dfa_define_highlight_rule ("^To: .*",color_to,$1);
dfa_define_highlight_rule ("^Cc: .*",color_header,$1);
dfa_define_highlight_rule ("^Bcc: .*",color_header,$1);
dfa_define_highlight_rule ("^Date: .*",color_header,$1);
dfa_define_highlight_rule ("^From: .*",color_from,$1);
dfa_define_highlight_rule ("^Subject: .*",color_subject,$1);
dfa_define_highlight_rule ("^(Reply-To|X-Uptime): .*",color_header,$1);
dfa_define_highlight_rule ("^(Message-ID|User-Agent): .*",color_header,$1);
dfa_define_highlight_rule ("^In-Reply-To: .*",color_header,$1);
dfa_define_highlight_rule ("^Organi[sz]ation: .*",color_header,$1);
dfa_define_highlight_rule ("^X-GPG-Public-Key: .*",color_header,$1);
dfa_define_highlight_rule ("^X-Operating-System: .*",color_header,$1);
dfa_define_highlight_rule ("^X-Edited-With-Muttmode: .*",color_header,$1);
dfa_define_highlight_rule ("^Newsgroups: .*",color_header,$1);
dfa_define_highlight_rule ("^Followup-To: .*",color_header,$1);
dfa_define_highlight_rule ("^Keywords: .*",color_header,$1);
dfa_define_highlight_rule ("^Summary: .*",color_header,$1);
dfa_define_highlight_rule ("^References: .*",color_header,$1);

dfa_define_highlight_rule ("(http|ftp|file|https)://[^ \t\n>]+",color_url,$1);
dfa_define_highlight_rule ("[^ \t\n<]*@[^ \t\n>]+",color_email,$1);

dfa_define_highlight_rule ("^-- $",color_signature,$1);
dfa_define_highlight_rule ("^> ?> ?> ?> ?> ?>.*",color_reply2,$1);
dfa_define_highlight_rule ("^> ?> ?> ?> ?>.*",   color_reply1,$1);
dfa_define_highlight_rule ("^> ?> ?> ?>.*",      color_reply2,$1);
dfa_define_highlight_rule ("^> ?> ?>.*",         color_reply1,$1);
dfa_define_highlight_rule ("^> ?>.*",            color_reply2,$1);
dfa_define_highlight_rule ("^>.*",               color_reply1,$1);

dfa_define_highlight_rule ("[\\(\\)]+-?[:;P\\^]|[:;P\\^]-?[\\(\\)]+",color_smiley,$1);
dfa_define_highlight_rule ("_[a-zA-Z]+_",color_underline,$1);
dfa_define_highlight_rule ("\\*[a-zA-Z]+\\*",color_bold,$1);
dfa_define_highlight_rule ("/[a-zA-Z]+/",color_italic,$1);

dfa_build_highlight_table ($1);
#endif

% this is broken, but I wanted to move it to DFA anyway...
%() = define_keywords_n ($1,"CcTo",2,0);
%() = define_keywords_n ($1,"Bcc",3,0);
%() = define_keywords_n ($1,"DateFrom",4,0);
%() = define_keywords_n ($1,"Subject",7,0);
%() = define_keywords_n ($1,"Reply-ToX-Uptime",8,0);
%() = define_keywords_n ($1,"Message-IDUser-Agent",10,0);
%() = define_keywords_n ($1,"In-Reply-To",11,0);
%() = define_keywords_n ($1,"Organization",12,0);
%() = define_keywords_n ($1,"X-GPG-Public-Key",16,0);
%() = define_keywords_n ($1,"X-Operating-System",18,0);
%() = define_keywords_n ($1,"X-Edited-With-Muttmode",22,0);

define skip_header ()
{
   while (not (re_looking_at ("^[ \t]*$"))) 
     !if (down_1 ()) 
       break;
}

define top_view ()
{
   recenter (what_line ());
}

define bol_skip_tags (ntags)
{
   variable col = 0;
   variable n = 0;
   bol ();
   while (looking_at_char ('>') or looking_at_char (' ') or looking_at_char ('\t'))
   {
      if (looking_at_char ('>'))
      {
         if (n == ntags) break;
         n++;
         col = what_column ();
      }
      !if (right (1)) break;
   }
   goto_column (col);
   if (looking_at_char ('>')) go_right_1 ();
}

define count_tags ()
{
   variable n = 0;
   push_spot ();
   bol ();
   while (looking_at_char ('>') or looking_at_char (' ') or looking_at_char ('\t'))
   {
      if (looking_at_char ('>')) n++;
      !if (right (1)) break;
   }
   pop_spot ();
   return (n);
}

define bol_skip_all_tags ()
{
   bol_skip_tags (count_tags ());
}

define maybe_signature ()
{
   variable a,b;
   push_spot ();
   bol_skip_all_tags ();
   skip_white ();
   !if (re_looking_at ("--[ \t]*$"))
   {
      pop_spot ();
      return 0;
   }
   right (2);
   skip_white ();
   eolp ();
   pop_spot ();
}

define dequote_buffer (ntags)
{
   variable n = count_tags ();
   push_spot ();
   bob ();
   forever
   {
      bol ();
      push_mark ();
      bol_skip_tags (ntags);
      % uncomment the following line if you prefer the space
      if (looking_at_char (' ')) go_right_1 ();
      if (ntags < n) skip_white ();
      del_region ();
      !if (down_1 ()) break;
   }
   pop_spot ();
}

define requote_buffer (ntags)
{
   variable i;
   push_spot ();
   bob ();
   forever
   {
      bol ();
      for(i = 0; i < ntags; i++) insert("> ");
      !if (down_1 ()) break;
   }
   pop_spot ();
}

define empty_quoted_line ()
{
   push_spot ();
   bol ();
   while (looking_at_char ('>') or looking_at_char (' ') or looking_at_char ('\t'))
   {
      if (not (right (1))) break;
   }
   skip_white ();
   eolp ();
   pop_spot ();
}

define mail_is_tag ()
{
   push_spot ();
   bol ();
   (mail_mode_have_mbox and bobp () and looking_at ("From ")) or (1 == re_looking_at ("^[A-Za-z][^: ]*:"));
   pop_spot ();
}

define mail_have_header ()
{
   push_spot ();
   bob ();
   mail_is_tag ();
   pop_spot ();
}

define mail_is_body ()
{
   !if (mail_maybe_header) return 1;
   !if (mail_have_header ()) return 1;
   push_spot ();
   re_bsearch ("^$");
   pop_spot ();
}

define mail_is_header_tag ()
{
   if (mail_is_body ()) return 0;
   return (mail_is_tag ());
}

define mail_parsep ()
{
   push_spot ();
   bol ();
   if (not (mail_is_body ()))
   {
      (mail_is_header_tag () or (skip_white (),eolp ()));
   }
   else
   {
      (maybe_signature () or (skip_white (),eolp ()) or empty_quoted_line ());
   }
   pop_spot ();
}

define mail_backward_paragraph ()
{
   variable n;
   if (mail_parsep ()) return;
   n = count_tags ();
   while (not (mail_parsep ()) and (count_tags () == n))
   {
      !if (up_1 ()) break;
   }
   bol ();
}

define mail_forward_paragraph ()
{
   variable n;
   if (mail_parsep ()) return;
   n = count_tags ();
   while (not (mail_parsep ()) and (count_tags () == n))
   {
      !if(down_1 ()) break;
   }
   bol ();
}

define mail_begin_of_paragraph ()
{
   mail_backward_paragraph ();
   !if (bobp ()) go_down_1 ();
}

define mail_select_paragraph ()
{
   if (mail_parsep ())
   {
      push_mark ();
      return;
   }
   mail_begin_of_paragraph ();
   push_mark ();
   mail_forward_paragraph ();
   eol ();
   !if (eobp ()) go_up_1 ();
   eol ();
}

define dequote ()
{
   push_spot ();
   !if (markp ()) mail_select_paragraph ();
   narrow ();
   dequote_buffer (1);
   widen ();
   pop_spot ();
}

define requote ()
{
   push_spot ();
   !if (markp ()) mail_select_paragraph ();
   narrow ();
   requote_buffer (1);
   widen ();
   pop_spot ();
}

define reformat_header ()
{
   push_spot ();
   while (not (mail_is_header_tag ()))
   {
      !if(up_1 ()) break;
   }
   if (not (mail_is_header_tag ()))
   {
      pop_spot ();
      return;
   }
   bol ();
   while (not (looking_at (":"))) go_right_1 ();
   go_right_1 ();
   push_spot ();
   insert ("\n");
   bol_trim ();
   bol ();
   insert (" ");
   call ("format_paragraph");
   pop_spot ();
   del ();
   pop_spot ();
}

define reformat_quote ()
{
   variable n,o,l1,l2;
   n = count_tags ();
   o = mail_maybe_header;
   l1 = 0;
   l2 = 0;
   mail_maybe_header = 0;
   push_spot ();
   !if (markp ())
   {
      push_spot ();
      mail_begin_of_paragraph ();
      l1 = what_line ();
      pop_spot ();
      l2 = what_line ();
      mail_select_paragraph ();
   }
   narrow ();
   dequote_buffer (n);
   bob ();
   down (l2 - l1);
   WRAP -= 2*n;
   call ("format_paragraph");
   WRAP += 2*n;
   requote_buffer (n);
   widen ();
   mail_maybe_header = o;
   pop_spot ();
}

define mail_indent_calculate ()
{
   variable col = 0;
   push_spot_bol ();
   !if (re_bsearch ("[^ \t\n]"))
   {
      pop_spot ();
      return col;
   }
   bol_skip_white ();
   col = what_column () - 1;
   pop_spot ();
   return col;
}

define mail_indent_line ()
{
   variable col;
   push_spot ();
   col = mail_indent_calculate ();
   if (not (mail_is_body ()))
   {
      if (mail_is_header_tag ())
        col = 0;
      else
      {
         if (col == 0) col = 1;
      }
   }
   bol_trim ();
   whitespace (col);
   pop_spot ();
}

define mail_reformat ()
{
   if (mail_is_body ()) reformat_quote (); else reformat_header ();
}

public define mail_mode ()
{
   no_mode ();
   set_mode ($1,1);
   use_keymap ($1);
   use_syntax_table ($1);
   local_setkey ("mail_reformat","\eq");
   local_setkey ("dequote","^c<");
   local_setkey ("requote","^c>");
   
   set_buffer_hook ("par_sep","mail_parsep");
   set_buffer_hook ("indent_hook","mail_indent_line");
   runhooks ("text_mode_hook");
   runhooks ("mail_mode_hook");
   skip_header ();

   top_view ();
%   save_buffers ();
}

[2003 date index] [2003 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]