# pascal-mode.tcl - mode for editing pascal code
######################################################################

global MODE EDITPREFS
global TE_MODE_SEARCH_STRING TE_MODE_NAVIG_SHOW_TEXT

# chaine de recherche 
set part1 "\n\[ \t\]*(procedure|function)"
set part2 "\[ \t\]*(\[a-zA-Z0-9_\]*)"
set TE_MODE_SEARCH_STRING $part1$part2
set TE_MODE_NAVIG_SHOW_TEXT "procs"

# # # variable de gestion des electric-alias
# # global EA_8bit_mark EA_8bit_begin EA_8bit_end EA_8bit_var
# # set M $EA_8bit_mark
# # set B $EA_8bit_begin
# # set E $EA_8bit_end
# # set V $EA_8bit_var

# Pour simplifier l'écriture des electricAlias : on déclare
# les variables M, B, E et V au niveau local pour 
# 
#      M :  Marque temporaire
#      B :  début de postcommande 
#      E :  fin de postcommande
#      V :  Inclusion d'une variable TCL
# 
electricAlias-use8bitsCars


# cette procedure renvoie l'indentation courante dans l'editeur
proc i {} {
 global EDITPREFS
 return $EDITPREFS(indent_string)
}

# Aliases for Pascal mode

electricAlias-def ${M}pascal ${M}pascal ${M}pascal
electricAlias-var pascal bb "begin"
electricAlias-var pascal eb "end"
electricAlias-var pascal bc "\{"
electricAlias-var pascal ec "\}"

set func1 "${B}askalias {function name} NAME${E}function $V{NAME}($M):$M;\n"
set func2 "${M}begin\n${B}i${E}$M\nend$V{bc}function $V{NAME}$V{ec}\n\n$M"
electricAlias-def ${M}pascal function  $func1$func2

set proc1 "${B}askalias {procedure name} NAME${E}procedure $V{NAME}($M);\n"
set proc2 "${M}begin\n${B}i${E}$M\nend$V{bc}procedure $V{NAME}$V{ec}\n\n$M"
electricAlias-def ${M}pascal procedure $proc1$proc2

electricAlias-def ${M}pascal label  "label $M;$M"
electricAlias-def ${M}pascal const  "const $M;$M"
electricAlias-def ${M}pascal type   "type $M;$M"
electricAlias-def ${M}pascal var    "var $M;$M"
electricAlias-def ${M}pascal record "record\n${B}i${E}$M\nend;$M"
electricAlias-def ${M}pascal begin  "begin\n${B}i${E}$M\nend$M"

set for1 "for $M := $M to $M do $V{bb}\n"
set for2 "${B}i${E}$M\n$V{eb} $V{bc}for$V{ec}$M"
electricAlias-def ${M}pascal for $for1$for2

set while1 "while ($M) do $V{bb}\n${B}i${E}$M"
set while2 "\n$V{eb} $V{bc}while$V{ec}$M"
electricAlias-def ${M}pascal while $while1$while2

electricAlias-def ${M}pascal repeat  "repeat\n${B}i${E}$M\nuntil ($M);$M"

set if1 "if ($M) then $V{bb}\n${B}i${E}$M"
set if2 "\n$V{eb} $V{bc}if$V{ec}$M"
electricAlias-def ${M}pascal if $if1$if2

electricAlias-def ${M}pascal elseif  "\b$V{eb} else if ($M) $V{bb}\n$M"
electricAlias-def ${M}pascal else    "\b$V{eb} else $V{bb}\n$M"

set case1 "case  ($M)\n${B}i${E}$M : begin\n${B}i${E}${B}i${E}$M"
set case2 "\n${B}i${E}end\n\nend $V{bc}case$V{ec}$M"
electricAlias-def ${M}pascal case $case1$case2


###########################################################################
# tri des procedures pour la navigation
# par ordre alphabetique
###########################################################################

proc te:mode:navig_sort_hook {l} {
  return [lsort -command te:mode:sort_command $l]
}


######################################################################
# define the pascal menu:

te:mode:make_menu $MODE

.menu.pascal.m add command -label {Colorize Procedures} \
-command {te:cmd:colorise $TE_MODE_SEARCH_STRING all blue}
.menu.pascal.m add separator
.menu.pascal.m add command -label {Clear Procedures colour} \
-command {stead:coloursResetForeground_BOF all blue}

###########################################################################
# definit le menu des mots-cles

te:mode:make_menu {templates}

te:cmd:create_alias_menu .menu.templates.m

################################################################################
# define the prefix for pascal mode

set EDITPREFS(suffix) " \}"
set EDITPREFS(prefix) "\{ "

######################################################################
# cleanup for pascal mode
######################################################################

proc stead:modeCleanup {} "
global MODE
te:mode:destroy_menu $MODE
te:mode:destroy_menu templates
te:cmd:destroy_alias_menu .menu.templates.m
"
