Re: "Literate" mode

New Message Reply Date view Thread view Subject view Author view

From: Craig B Upright (cupright@PRINCETON.EDU)
Date: 14 Jun 00, 02:10 EST


From: Craig B Upright <cupright@PRINCETON.EDU>
Subject:      Re: "Literate" mode

On Sun, 11 Jun 2000, Shin-Cheng Mu wrote:

| Some programming languages, in particular Haskell, has a 'literate' mode
| in which only the lines starting with some prompt (e.g. '>') are program
| codes. All the other lines are comments. How do I get keyword
| highlighting to work this way?
|
| I was pointed to the code written by Vince Darley for examples. But I
| still don't see how regModeKeywords could do what I want.

What Tom was suggesting earlier is that you create two different color
schemes for Haskell mode, one for colorizing command lines, the other for
comments.  This doesn't quite achieve the effect that you're looking for,
but it is an end-run that's pretty easy to implement.

I've included some code below that I think would work for you.  It does
the following:

Creates two menu items for you, "Comment Colors" and "Default Colors".
The mode will automatically color command lines.  If you want to
concentrate on comments, the "Comment Colors" menu item will comment out
all of the command lines in red, and remove keyword colors elsewhere in
the file. When you're ready to focus on command lines again, "Default
Colors" will restore the original color scheme.  These menu items are also
bound to control-0 and control-9 so that you can toggle back and forth
between the two color schemes.

-- Craig

______________________________________________________________

Craig Barton Upright            email:  cupright@princeton.edu
Department of Sociology         phone:  (609) 258.4539
Princeton University            fax:    (609) 258.2180
Princeton, New Jersey  08544    http://www.princeton.edu/~cupright/
______________________________________________________________


proc menu::buildHaskMenu {} {

        [snip]

        "\(-"
        "/0<BcommentColors"
        "/9<BdefaultColors"
        "\(-"

        [snip]
}

newPref v keywordColor {blue} Hask

set HaskKeywords {
        blah bladdity
}


#============================================================================
#
# Colorize Hask
#

proc Hask::colorizeHask {} {

        global HaskmodeVars HaskKeywords

        regModeKeywords -a -e {} -c {none} \
          -k $HaskmodeVars{keywordColor} Hask $HaskKeywords
}

# This is a "dummy" command, necessary for the above proc so that all of
# the "regModeKeywords" commands in the called color procs can be "adds"
# (-a).  When the mode is first invoked, this has to occur before the color
# procs are called.

regModeKeywords -k {none} Hask {}

# now we finally colorize

Hask::colorizeHask


#============================================================================
#
# Comment Colors --
#
# Changes color scheme of current window to make it easier to read
# commented text.  Preferences aren't actually changed.  "defaultColors"
# will restore to the last stored values of the colors.  -cbu
#

proc Hask::commentColors {} {

        global HaskmodeVars HaskKeywords

        regModeKeywords -a -e {>} -c {red} \
          -k {none} Hask $HaskKeywords
}

proc Hask::defaultColors {} {Hask::colorizeHask}


New Message Reply Date view Thread view Subject view Author view

This archive was generated by das@users.sourceforge.net with hypermail 2b29 on 31 Mar 01, 11:51 EST