### 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.


######################################################################
### Completion / Misc
######################################################################
proc completion_misc {} {
  # completion / misc

  Desc "Tcsh can do some typing for you, by performing filename"\
      "completion. You type a prefix, hit the TAB key, and if the"\
      "prefix is uniq (ie. it's only a prefix for one file), tcsh will"\
      "supply the rest of the filename.  In addition to filename"\
      "completion tcsh, can complete on usernames, directories, shell"\
      "variables and much more.\n For more information on completion,"\
      "see the section 'Completion and listing' in the tcsh manual for"\
      "more information\n\n On this page you configure diffenrent"\
      "asspect of the completion."
  ShortDesc "Configuration on filename completion"

  ############################### Widgets ##############################

  CheckBox addsuffix \
      -text "Add slash or space on completion" \
      -default 1
  
  Entry fignoreComponent \
      -text "suffix" 

  ExtEntry fignore \
      -text "File suffixes to ignore on completion" \
      -entries fignoreComponent
  
  CheckBox autolist \
      -text "Show possible completion on ambiguous completion" \
      -default 1

  CheckBox autolist_amb \
      -text "Show only possible completions, when no new characters is added"

  CheckBox complete \
      -text "Use enhanced completion" 

  CheckBox nonomatch \
      -text "No errors on Filename- Directory stack- substitution"

  CheckBox recexact \
      -text "Complete on exact match, even if longer is valid"

  CheckBox autoexpand \
      -text "expand history substitution on completion"

  Menu matchbeep \
      -text "when to beep on completion" \
      -entries {Never "on no match" "on not uniq completion" "ambiguous"} \
      -defaultIndex 1

  CheckBox verify \
      -text "veryfy executables on command completions"

  Line l1
  
  Int maxrows \
      -text "Maximum number of rows to show without asking" \
      -orient right \
      -textafter "(blank = infinity)"

  Int maxelm \
      -text "maximum element to show without asking" \
      -textafter "(blank = infinity)" \
      -orient right

  ################################ Help ################################
  
  Help addsuffix \
      "If this option is set, a slash will be appended to directories,"\
      "and a space to files, when they are match exactly."

  Help fignoreComponent \
      "A suffix is the last part of the file name\n eg. \".c\" is the"\
      "last part of test.c\n \~ is the last part of test~ (Remember"\
      "\"\\\" to escape ~)\n NOTE: suffix doesn't, in this context,"\
      "mean \"the part after the last dot\", but rather \"the last part"\
      "of the file name\""

  Help fignore \
      "This is a list of filename extension to ignore on file"\
      "completion.\n Ex. if \"o\" is in this list, and you have the"\
      "file test.c and test.o in to complete on, tcsh will complete to"\
      "test.c and ignore test.o.\n NOTE: This may be dangerous, if you"\
      "want to remove the file test.o, you may easily type \"rm test\""\
      "and press TAB to complete. Tcsh will now complete to test.c, and"\
      "if you are a bit too fast, you may press enter, and vups...Your"\
      "source file is gone."

  Help autolist \
      "If this option is selected, an ambiguous completion will result"\
      "in that all possible completions is printed. If it's not set,"\
      "the terminal will beep instead."

  Help autolist_amb \
      "When this option is set, the list of completions will only be"\
      "shown, if no new character is added to your command line on"\
      "completion. Here is an example to show it:\n\n Say, you have two"\
      "files called abXdef and abYdef. If you now type eg. \"cat a\""\
      "and press the tab key, the shell will add b to your command, but"\
      "will not show the list of completions (since a character was"\
      "added!). If however you type \"cat ab\" and press the tab key,"\
      "the shell will list the two files, since both of them is a"\
      "completion of \"ab\", but no characters can be added to your"\
      "command line (ie you have to tell it whether the next character"\
      "should be X or Y)"
  
  Help complete \
      "If this option is selected, completion is case insensitive,"\
      "and \".\", \"_\" and \"-\" are considered as word separators."\
      "\ This means that you can complete Makefile from mak, but it"\
      "also means that if you have a file called test.abc, then this"\
      "will show up when you try to complete .ab"

  Help nonomatch \
      "If this option is selected, a filename substitution or Directory"\
      "stack substitution which does not match any existing files is"\
      "left untouched rather than causing an error.\n If eg. you type"\
      "\"echo *.c\" and there does not exist any .c files in the"\
      "current directory, then an error will be raised if this option"\
      "is not selected. Otherwise if it is selected, the echo command"\
      "will get one argument which is \"*.c\", and it will then just"\
      "print \"*.c\""

  Help recexact \
      "If this option is selected completion will complete to an exact"\
      "completion even though a longer one is valid\n if eg. you have"\
      "two files called \"test\" and \"testagain\", and you type \"cat"\
      "test\" and the complete, then it will complete to"\
      "test. Otherwise the terminal will either beep or match possible"\
      "completion."

  Help autoexpand \
      "If you complete on a line where there is history reference and"\
      "this option is selected, then the reference will be expanded. To"\
      "test this, type !! and press the TAB key."

  Help matchbeep \
      "You can configure when tcsh will beep on completion, and you"\
      "have the following possibilities:\nnever: Never beep on"\
      "completion\non no match: beep when there is nothing which"\
      "matches your completion\non not uniq matches: beep on no match"\
      "as well as matches which is not uniq.\n\nIf you have selected"\
      "the check box \"Complete on exact match, even if longer is"\
      "valid\" you may select \"ambiguous\" for this option too, which"\
      "means that it will beep when completing on a match, where a"\
      "longer one is valid. (This means nomatch and not complete too)"

  Help verify \
      "If this options is set, tcsh will verify that a file, which is"\
      "located in the path is executable.\n\nNOTE: If this is selected,"\
      "it will take very long time to complete the first time, since"\
      "tcsh need to stat all files on the file system. By that reason"\
      "it is very advisable not to enable this feature."
  
  Help maxrows \
      "If more rows than specified here are about to be printed,"\
      "then a message like this is shown:\n"\
      "\"There are 13 rows, list them anyway? \[n/y\]\""

  Help maxelm \
      "If more element than specified here are about to be printed,"\
      "then a message like this is shown:\n"\
      "\"There are 24 items, list them anyway? \[n/y\] \""


  ################################ Change ##############################
  Change {
    if {$changeElm == "autolist"} {
      eval "[pick $autolist Enable Disable] autolist_amb"
    }
  }
  ################################ Save ################################

  Save {
    ########## addsuffix ##########
    if {$addsuffix == 1 || $generateDefault} {
      print "[pick $addsuffix set unset] addsuffix"
    }
    ########## fignore ##########
    set names ""
    forevery fignore {
      if {$fignoreComponent != ""} {
        append names "\t$fignoreComponent\\\n"
      }
    }
    if {$names != "" || $generateDefault} {
      print "set fignore = (\\\n$names)"
    }
    ########## autolist ##########
    if {$autolist || $generateDefault} {
      if {!$autolist} {
        print "unset autolist"
      } else {
        if {$autolist_amb} {
          print "set autolist = ambiguous"
        } else {
          print "set autolist"
        }
      }
    }
    ########## complete ##########
    if {$complete || $generateDefault} {
      if {$complete} {
        print "set complete = enhance"
      } else {
        print "unset complete"
      }
    }
    ########## nonomatch ##########
    if {$nonomatch || $generateDefault} {
      print "[pick $nonomatch set unset] nonomatch"
    }
    ########## recexact ##########
    if {$recexact || $generateDefault} {
      print "[pick $recexact set unset] recexact"
    }
    ########## autoexpand ##########
    if {$autoexpand || $generateDefault} {
      print "[pick $autoexpand set unset] autoexpand"
    }
    ########## matchbeep ##########
    if {$matchbeep(index) != 2 || $generateDefault} {
      switch $matchbeep(index) {
        0  {print "set matchbeep = never"}
        1  {print "set matchbeep = nomatch"}
        2  {print "unset matchbeep"}
        3  {print "set matchbeep=ambiguous"}
      }
    }
    ########## recognize_only_executables ##########
    if {$verify || $generateDefault} {
      print "[pick $verify set unset] recognize_only_executables"
    }
    ########## listmaxrows ##########
    if {$maxrows != "" || $generateDefault} {
      if {$maxrows != ""} {
        print "set listmaxrows = $maxrows"
      } else {
        print "unset listmaxrows"
      }
    }
    ########## listmax ##########
    if {$maxelm != "" || $generateDefault} {
      if {$maxelm != ""} {
        print "set listmax = $maxelm"
      } else {
        print "unset listmax"
      }
    }
  }
}
