### Copyright (C) 1995-1997 Jesper K. Pedersen
### This program is free software; you can redistribute it and/or modify
### it under the terms of the GNU General Public License as published by
### the Free Software Foundation; either version 2 of the License, or
### (at your option) any later version.
###
### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
### GNU General Public License for more details.
###
### You should have received a copy of the GNU General Public License
### along with this program; if not, write to the Free Software
### Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


proc editor {} {
  # command line editor / misc

  Desc "Here you configure the command line editor. The command line"\
      "editor is the one which permits you to edit your command lines"\
      "(move back and forth with the cursor, transpose characters,"\
      "delete part of the line etc.)\n\nFor more information on the"\
      "command line editor see the 'Editing' section in the tcsh man"\
      "page."
  
  ShortDesc "Configuration of the command line editor"

  ############################### Widgets ##############################
  CheckBox edit \
      -text "Use command line editor" \
      -default 1 

  Entry wordchars \
      -text "non-alphanumeric characters to be considered part of word"\
      -default {*?_-.[]~=} 

  CheckBox verbose \
      -text "Echo each command before executing them" 
  
  CheckBox echo \
      -text "Do all expansion on echoing"

  CheckBox n \
      -text "recognize `-n' option for echo" \
      -default 1
  
  CheckBox escape \
      -text "recognize backslashed escape sequences in echo strings" \
      -default 1

  Line l1

  Radio inputmode \
      -text "Which mode to edit in" \
      -entries {"insert mode" "overwrite mode"} \
      -packFrame:fill x

  ################################ Help ################################
  Help edit \
      "If you deselect this option, the command line editor will"\
      "be disabled. This means that you *CAN NOT* move with the"\
      "cursors, go to start of the line with Ctrl-a etc. Instead these"\
      "keys will insert their control codes.\nUnless you have a very"\
      "good reason I believe you would like to use the command line"\
      "editor."

  Help wordchars \
      "This is the non-alphanumeric characters to be considered part of"\
      "words by the \"forward-word\" and \"backward-word\" etc. editor"\
      "commands.\n\nExample: \nIf \"_\" isn't in this list, then ESC-f"\
      "(forward-word) will move the cursor to the \"_\" characters if"\
      "this is inside a word, exactly as it would move to a space."

  Help verbose \
      "If you select this option, each command is echoed before it is"\
      "executed.  History substitution occurs before echoing, but all"\
      "other substitution will first occur after"\
      "echoing.\n\nExample:\necho !\$ \$HOME will expand !\$, but not"\
      "\$HOME, so it will print echo /usr/bin/ \$HOME if !\$ is"\
      "/usr/bin."

  Help echo \
      "If you select this option, for non-builtin commands all"\
      "expansions occur before echoing.  Builtin commands are echoed before"\
      "command and filename substitution, since these substitutions are"\
      "then  done selectively.\n"\
      "This means that echo !\$ * \$HOME will expand !\$ and \$HOME, but not *"

  Help n \
      "If you select this option, echo will recognize -n as an option."\
      "The -n option will disable the final newline"

  Help escape \
      "If you select this option, backslashed escape sequences,"\
      "like \\n \\t, are recognized"

  Help inputmode \
      "This tells tcsh what to do when you insert a character, and the"\
      "cursor isn't at the end of the line."
  
  ############################### Change ###############################
  Change {
    if {$changeElm == "verbose"} {
      if {$verbose} {
        Enable echo
      } else {
        Disable echo
      }
    }
  }

  ################################ Save ################################
  Save {
    ########## edit ##########
    if {!$edit || $generateDefault} {
      print "[pick $edit set unset] edit"
    }
    ########## wordchars ##########
    if {$wordchars != {*?_-.[]~=} || $generateDefault} {
      if {$wordchars != {*?_-.[]~=}} {
        print "set wordchars = \"$wordchars\""
      } else {
        print "unset wordchars"
      }
    }
    ########## echo, verbose ##########
    if {$verbose} {
      if {$echo} {
        if {$generateDefault} {
          print "unset verbose"
        }
        print "set echo"
      } else {
        if {$generateDefault} {
          print "unset echo"
        }
        print "set verbose"
      }
    } elseif {$generateDefault} {
      print "unset verbose echo"
    }
    ########## echo_style ##########
    switch "$n $escape" {
      {0 0} {print "set echo_style = none"}
      {0 1} {print "set echo_style = sysv"}
      {1 0} {print "set echo_style = bsd"}
      {1 1} {print "set echo_style = both"}
    }
    ########## inputmode ##########
    if {$inputmode(index) == 1 || $generateDefault} {
      print "set inputmode = [pick $inputmode(index) overwrite insert]"
    }
  }
}
