! ----------------------------------------------------------
! Patterns for Syntax Highlighting and Smart Indenting in Scheme
!   - started 3/99 by Clif Kussmaul <kussmaul@cs.moravian.edu>
!                                   http://www.cs.moravian.edu
 
! comments specific to this file...
! ----------------------------------------------------------
! 
! - this file contains patterns and other configuration info 
!   for syntax highlighting and smart indenting in Scheme
! - all entries are added to the .nedit file (see below)
! - written for MIT Scheme, although other dialects are similar.
! - Scheme numbers can take a huge variety of forms; 
!   and the "Numeric Constant" pattern below only matches 
!   the common decimal integers and reals.
!
! Please let me know if you have additions, corrections, or suggestions.
!
! ----------------------------------------------------------

! comments adapted from other nedit patterns (Matlab)...
! ----------------------------------------------------------
!
! Patterns for Scheme
!
! In NEdit Version 5.0.1 and beyond, load this pattern by running:
!
!     nedit -import <name of this file>
!
! Then, check that the patterns were loaded correctly, and choose 
! Save Defaults from the Preferences menu.  The new patterns will 
! now be incorporated into your own .nedit file, so the next time 
! you start NEdit, you will no longer need to use -import.
!
! In version 5.0, without -import, you must edit your .nedit file 
! by hand and add the contents of each resource below to the 
! corresponding list in your .nedit file.  Be sure to separate 
! new entries with \n, and continue resource strings by escaping 
! all newlines within a resource value with \ (backslash),
! leaving only the last line of the resource value not ending in \.
!
! ----------------------------------------------------------

! ----------------------------------------
! Scheme language mode

nedit.languageModes: \
        Scheme:.scheme .scm::::::

! ----------------------------------------
! Scheme highlighting patterns

nedit.highlightPatterns: \
        Scheme:1:0{\n\
                Comment:";":"$"::Comment::\n\
                Quoted Constant:"'[^()""; \\t]+":::Text Key::\n\
                Character Constant:"<(#t|#f|#\\\\space|#\\\\newline|#\\\\.)>":::Text Key::\n\
                Numeric Constant:"<(([0-9]+\\.?[0-9]*)|(\\.[0-9]+))>":::Text Key1::\n\
                Keyword + Prefix:"[^()""; \\t]<(=>|and|begin|case|cond|define|delay|do|else|if|lambda|let|let\\*|letrec|or|quasiquote|quote|set!|unquote|unquote-splicing)>":::Plain::\n\
                Keyword + Suffix:"<(=>|and|begin|case|cond|define|delay|do|else|if|lambda|let|let\\*|letrec|or|quasiquote|quote|set!|unquote|unquote-splicing)>[^()""; \\t]":::Plain::\n\
                Keyword:"<(=>|and|begin|case|cond|define|delay|do|else|if|lambda|let|let\\*|letrec|or|quasiquote|quote|set!|unquote|unquote-splicing)>":::Keyword::\n\
                String:"""":""""::String1::\n\
                String Escape:"\\\\.":::String:String:\n\
        }

! ----------------------------------------
! Scheme smart indenting

nedit.smartIndentInit: \
        Scheme: # number of characters in normal indent level  \n\
        $scheme_indent = "default"\n\
\n\
        # count occurrences of "(" and ")" in line containing $1\n\
        define count_in_line {\n\
            # find ends of current line\n\
            start = search("\\n", $1, "backward")\n\
            stop  = search("\\n", $1,  "forward")\n\
            if (start == -1) start = 0\n\
            if (stop  == -1) stop = $text_length\n\
            # count occurrences\n\
            count = 0\n\
            for (p=start; p<stop; p++) {\n\
                # if double-quote, skip to matching double-quote\n\
                if ("\\"" == get_character(p)) {\n\
                    for (p++; p<stop; p++)\n\
                        if      ("\\\\" == get_character(p)) p++\n\
                        else if ("\\"" == get_character(p)) break\n\
                    }\n\
                # if backslash, skip next character\n\
                else if ("\\\\" == get_character(p)) p++\n\
                # if target character, increment count\n\
                else if ( "(" == get_character(p)) count++\n\
                else if ( ")" == get_character(p)) count-- \n\
                }\n\
            return count\n\
            } # end count_in_line\n\
\n\
        # adapted from nedit's smart indenting for C/C++\n\
        define default_indent {\n\
            if ($1 != "default")                return $1\n\
            else if ($em_tab_dist != -1)        return $em_tab_dist\n\
            else if ($tab_dist <= 8)            return $tab_dist\n\
            else                                return 4\n\
            } # end default_indent\n\
\n\
        # adapted from nedit's smart indenting for C/C++\n\
        define measure_indent {\n\
            # find start of current line\n\
            start = search("\\n", $1, "backward")\n\
            if (start == -1) start = 0\n\
            # measure indentation to first non-white character on the line\n\
            indent = 0\n\
            for (p=start+1; p<$1; p++) {\n\
                c = get_character(p)\n\
                if      (c == " ")      indent++\n\
                else if (c == "\\t")    indent += $tab_dist - (indent % $tab_dist)\n\
                else                    break\n\
            }\n\
            return indent\n\
            } # end measure_indent\n\
        --End-of-Macro--\n\
        return(measure_indent($1) + \\\n\
                  (default_indent($scheme_indent) * count_in_line($1-1)))\n\
        --End-of-Macro--\n\
        --End-of-Macro--

! ----------------------------------------
! that's all folks

