home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 September (IDG) / Sep99.iso / Shareware World / Utilities / Text Processing / Alpha / Tcl / Completions / TeXCompletions.tcl < prev   
Encoding:
Text File  |  1999-02-28  |  17.3 KB  |  553 lines  |  [TEXT/ALFA]

  1. ## -*-Tcl-*-
  2.  # ###################################################################
  3.  #    Vince's    Additions -    an extension package for Alpha
  4.  # 
  5.  #    FILE: "TeXCompletions.tcl"
  6.  #                      created: 26/2/96 {2:27:17 pm} 
  7.  #                      last update: 28/2/1999 {2:42:04 am} 
  8.  #    Author:    Vince Darley
  9.  #    E-mail:    <darley@fas.harvard.edu>
  10.  #      mail:    Division of    Applied    Sciences, Harvard University
  11.  #            Oxford Street, Cambridge MA    02138, USA
  12.  #       www:    <http://www.fas.harvard.edu/~darley/>
  13.  #    
  14.  #  Adds completion routines for TeX mode.  This includes reference
  15.  #  (\label) completion, citation completion, environment completion,
  16.  #  environment item insertion.
  17.  #    
  18.  #  Cool new feature: the '{' key is bound to electric completion.  This
  19.  #  means you can just type as normal in most circumstances, and when you
  20.  #  hit '{', if the previous text is capable of being extended as a command
  21.  #  (e.g. \begin, \frac, ...), then it is!
  22.  # 
  23.  #  modified by  rev reason
  24.  #  -------- --- --- -----------
  25.  #  18/12/97 VMD 1.1 added TeX::IncludeFile completions, better handling of '*'
  26.  #  14/1/98  VMD 1.2 Env completion rewritten, some in core latex mode
  27.  #  28/1/98  VMD 1.3 huge thanks to Pierre Basso for improvements.
  28.  # ###################################################################
  29.  ##
  30.  
  31. # ◊◊◊◊ completions & expanders ◊◊◊◊ #
  32. ensureset completions(TeX) {beginContraction Env Cmd Electric Reference Cite Word}
  33. ensureset expanders(TeX) {ExCmd}
  34.  
  35. # ◊◊◊◊ Preferences ◊◊◊◊ #
  36.  
  37. # Add an item inside any environment 
  38. # bound to shift-opt-i
  39. newPref binding TeXAddItem "/I<U<I" TeX "" 1
  40.  
  41. newPref f showTitlesWithTeXCiteCompletion 1 TeX
  42. # complete an environment even if we don't recognise it!
  43. newPref f acceptAnyTeXEnvironment 1 TeX
  44. # if we don't recognise the environment, create a body on the fly
  45. newPref f promptToCreateTeXEnvironment 1 TeX
  46. newPref f electricContractions 1 TeX
  47.  
  48. # ◊◊◊◊ extra invoker key ◊◊◊◊ #
  49.  
  50. proc TeX::electricLeft {} {
  51.     global TeXmodeVars
  52.     set p [getPos]
  53.     if {$TeXmodeVars(electricContractions)} {
  54.     catch {TeX::Completion::beginContraction}
  55.     }
  56.     if {[pos::compare [getPos] == $p]} {
  57.     catch {TeX::Completion::Electric}
  58.     }
  59.     if {[pos::compare [getPos] == $p]} {
  60.     insertText "\{"
  61.     }
  62. }
  63.  
  64. proc TeX::electricRight {} {
  65.     insertText "\}"
  66.     catch {blink [matchIt "\}" [pos::math [getPos] - 2]]}
  67. }
  68.  
  69. # ◊◊◊◊ Completions ◊◊◊◊ #
  70.  
  71. ## 
  72.  # -------------------------------------------------------------------------
  73.  # 
  74.  # "TeX::Completion::beginContraction" --
  75.  # 
  76.  #  The idea here is to see if you see a hint in the form of 
  77.  #  "b'<some-word>", if so replace the "b'" with "\begin ".
  78.  # -------------------------------------------------------------------------
  79.  ##
  80. proc TeX::Completion::beginContraction {{dummy ""}} {
  81.     set lastword [completion::lastTwoWords leadingHint]
  82.     if {$leadingHint != "b'"} {return 0} 
  83.     set curPos [getPos]
  84.     backwardWord
  85.     set startEnvPos [getPos]
  86.     set evironmentHint [getText $startEnvPos $curPos]
  87.     backwardWord
  88.     deleteText [getPos] $curPos
  89.     insertText "\\begin"
  90.     TeX::Completion::Electric "begin"
  91.     typeText $lastword
  92.     return 0
  93. }
  94.  
  95. ## 
  96.  # -------------------------------------------------------------------------
  97.  #     
  98.  # "TeX::Completion::Env" --
  99.  #    
  100.  #  Complete the contents of a \begin...\end pair as appropriate.  Uses the
  101.  #  TeXbodies array.  You can either type '\begin<cmd-Tab>figure<cmd-Tab>'
  102.  #  (for example) or just '\begin{figure}<cmd-Tab>'. 
  103.  # -------------------------------------------------------------------------
  104.  ##
  105. proc TeX::Completion::Env {dummy} {
  106.     set cmd [completion::lastTwoWords begin]
  107.     if { $begin != "\\begin\{" } { return 0 }
  108.     if [regexp {^(.*)\}$} $cmd "" cmd] {
  109.     # hmm
  110.     }
  111.     set matches [completion::fromList $cmd TeXenvironments]
  112.     if { $matches == "" } {
  113.     global TeXmodeVars TeXbodies
  114.     if [info exists TeXbodies($cmd)] {
  115.         set match $cmd
  116.     } else {            
  117.         if {$TeXmodeVars(acceptAnyTeXEnvironment)} {
  118.         if $TeXmodeVars(promptToCreateTeXEnvironment) {
  119.             set y 40
  120.             set yb 200
  121.             set res [eval dialog -w 400 -h 340 \
  122.               [dialog::title "New TeX environment" 400] \
  123.               [dialog::button "OK" 310 yb] \
  124.               [dialog::button "Cancel" 310 yb] \
  125.               [dialog::text "Enter the template for the body of the environment" 10 y] \
  126.               [dialog::text "Write '•prompt message•' for each template stop," 10 y] \
  127.               [dialog::text "'\\r','\\\{','\\t',... for return, brace, tab etc." 10 y] \
  128.               [dialog::edit "•body•" 10 y 35 6] \
  129.               ]
  130.             set match $cmd
  131.             if {![lindex $res 1]} {
  132.             eval set "TeXbodies($match)" [lindex $res 2]
  133.             addUserLine "set TeXbodies($match) \"[quoteExpr3 $TeXbodies($match)]\""
  134.             } else {
  135.             # we cancelled, so move on
  136.             completion::already error
  137.             return 1
  138.             }
  139.         } else {
  140.             message "Warning: I don't recognise that environment"
  141.             set match $cmd
  142.         }
  143.         } else {
  144.         return 0
  145.         }
  146.     }
  147.     } else {
  148.     set match [completion::Find $cmd $matches]
  149.     }    
  150.     if [string length $match] {
  151.     # we completed or cancelled, so move on
  152.     completion::already error
  153.     if { $match == 1 } {
  154.         return 1
  155.     } else {            
  156.         if {![ring::type]} {
  157.         endOfLine
  158.         set p [getPos]
  159.         ring::+
  160.         insertText $match
  161.         goto $p
  162.         return [elec::findCmd $match TeXbodies ""]
  163.         }
  164.         if {![ring::TMarkAt "environment name" [pos::math [getPos] - [string length $match]]]} {
  165.         # we probably typed '\begin{name}' all in one go
  166.         set i "••"
  167.         if {[lookAt [pos::math [getPos] - 1]] != "\}"} {
  168.             append i "\}"
  169.         }
  170.         append i "\r\\end\{${match}\}\r••"
  171.         elec::Insertion $i
  172.         endOfLine
  173.         } else {
  174.         endOfLine
  175.         set p [getPos]
  176.         # delete the stop of the \end{•}
  177.         ring::+
  178.         ring::deleteStop
  179.         # we need to fill in the '\end{}'
  180.         insertText $match
  181.         goto $p
  182.         }
  183.         set ret [elec::findCmd $match TeXbodies ""]
  184.         # delete the stop of \begin{•}
  185.         # we do this afterwards, otherwise we lose the nesting of
  186.         # templates, which is bad.
  187.         ring::-
  188.         ring::deleteStopAndMove
  189.         return $ret
  190.     }
  191.     } else {
  192.     completion::already TeX::Completion::Env
  193.     return 1
  194.     }    
  195. }
  196.  
  197. ## 
  198.  # -------------------------------------------------------------------------
  199.  #     
  200.  # "TeX::Completion::Cmd" --
  201.  #    
  202.  #  Takes account of the backslash which commands in TeX use
  203.  # -------------------------------------------------------------------------
  204.  ##
  205. proc TeX::Completion::Cmd {dummy} {
  206.     set cmd [completion::lastWord pos]
  207.     if {[regexp {^\\([^\*]*)\*?$} $cmd "" cmd]} {
  208.     return [completion::cmd $cmd]
  209.     } else {
  210.     return 0
  211.     }
  212. }
  213.  
  214. proc TeX::Completion::Insert {what} {
  215.     insertText "\\${what}"
  216.     bind::Completion
  217. }
  218.  
  219. ## 
  220.  # -------------------------------------------------------------------------
  221.  #     
  222.  #    "TeX::Completion::Electric"    --
  223.  #    
  224.  #  An example of calling the completion::electric procedure.  In TeX mode,
  225.  #  '{••}••' is a good default. 
  226.  # -------------------------------------------------------------------------
  227.  ##
  228. proc TeX::Completion::Electric { {cmd ""} } {
  229.     if {![string length $cmd]} { 
  230.     if {[containsSpace $cmd]} { return 0 }
  231.     set cmd [completion::lastWord]
  232.     }
  233.     if {[regexp {^\\([^\*]*)\*?$} $cmd "" cmd]} {
  234.     # nothing
  235.     } elseif {[regexp {\]\{?$} $cmd got]} {
  236.     # we might have an optional [...] after the command we really want.
  237.     # This should work but doesn't (Alpha bug)!
  238.     #{matchIt "]" [pos::math [getPos] - [expr 1 + [string length $got]]]}
  239.     if {![catch {search -s -f 0 -r 0 -m 0 "\[" [getPos]} where]} {
  240.         set p [getPos]
  241.         goto [lindex $where 0]
  242.         set cmd [completion::lastWord]
  243.         goto $p
  244.         regexp {^\\([^\*]*)\*?$} $cmd "" cmd
  245.     }
  246.     }
  247.     return [completion::electric $cmd "\{••\}••"]
  248. }
  249.  
  250.     
  251. ## 
  252.  # -------------------------------------------------------------------------
  253.  #     
  254.  # "TeX::Completion::Reference"    --
  255.  #    
  256.  #  If we're in any kind of reference, search for appropriate labels to get
  257.  #  the information from and fill them in.  'TeXRefCompletion' in
  258.  #  "latexEngine.tcl" is obsolete. 
  259.  # -------------------------------------------------------------------------
  260.  ##
  261. proc TeX::Completion::Reference { {dummy ""} } {
  262.     global completion::in_progress_pos completion_got completion_looking
  263.     global _texrefprefixes
  264.     # cursor changed place?
  265.     set pos [getPos]
  266.     if {[pos::compare $pos == ${completion::in_progress_pos}]} {
  267.     completion::update Reference $completion_got $completion_looking
  268.     message "press <Cmd Tab> for another label"
  269.     return 1
  270.     }
  271.     
  272.     global TeXmodeVars
  273.     
  274.     set lastword [completion::lastTwoWords prevword]
  275.     set gotprefix ""
  276.     set prevword [string trim [string range $prevword 1 end] "\{"]
  277.     if {[set ref [lsearch -exact $TeXmodeVars(refCommands) $prevword]] != -1} {
  278.     set gotprefix $lastword
  279.     set lastword $prevword
  280.     } else {
  281.     # trim the backslash and opening brace:
  282.     set lastword [string trim [string range $lastword 1 end] "\{"]
  283.     # check if it's a \ref-like command:
  284.     set ref [lsearch -exact $TeXmodeVars(refCommands) $lastword]
  285.     }    
  286.     
  287.     if { $ref != -1 } {
  288.     # got a \ref-like command:
  289.     set completion_got "\\[lindex $TeXmodeVars(refCommands) $ref]\{${gotprefix}"
  290.     # make sure we have the brace:
  291.     if { $gotprefix == "" && [lookAt [pos::math $pos - 1]] != "\{" } {
  292.         insertText "\{"
  293.     }
  294.     set completion_looking "label\{${gotprefix}"
  295.     TeX::updateCompletion Reference $completion_got $completion_looking
  296.     completion::already Reference
  297.     return 1
  298.     } else {
  299.     return 0 
  300.     }
  301. }
  302.  
  303. ## 
  304.  # -------------------------------------------------------------------------
  305.  #     
  306.  # "TeX::Completion::Cite" --
  307.  #    
  308.  #  Checks for any \cite like command, and looks up the partial argument in
  309.  #  the known bibliographies, completing the entry as appropriate. 
  310.  # -------------------------------------------------------------------------
  311.  ##
  312. proc TeX::Completion::Cite { {dummy ""} } {
  313.     global completion::in_progress_pos completion_got completion_looking TeXmodeVars
  314.     # cursor changed place?
  315.     if {[pos::compare [getPos] == ${completion::in_progress_pos}]} {
  316.     set lastword [completion::lastWord]
  317.     set completion_got [completion::fromList $lastword completion_got]
  318.     } else {
  319.     global TeXmodeVars
  320.     set a [getText [lineStart [getPos]] [getPos]]
  321.     # got a \cite-like command:
  322.     if ![regexp "\\\\([join [string trim $TeXmodeVars(citeCommands)] |])\\\{(\[a-zA-Z0-9\]+,)*(\[a-zA-Z0-9\]+)$" $a d d d lastword] {
  323.         return 0
  324.     }
  325.     set completion_got [Bib::_FindAllEntries $lastword \
  326.       $TeXmodeVars(showTitlesWithTeXCiteCompletion)]
  327.     if {$completion_got == ""} {
  328.         if [catch {dialog::optionMenu \
  329.           "No matching citations found.  Perhaps you should\
  330.           rebuild your bib data-base, or create a new entry." \
  331.           [list "Rebuild database" "New entry" "New entry in new file"]} res] {
  332.         # user cancelled
  333.         return 0
  334.         }
  335.         switch $res {
  336.         "Rebuild database" {
  337.             if $TeXmodeVars(showTitlesWithTeXCiteCompletion) {
  338.             Bib::rebuildDatabase
  339.             } else {
  340.             Bib::rebuildIndex
  341.             }
  342.             # try again
  343.             return [TeX::Completion::Cite $dummy]
  344.         }
  345.         "New entry" {
  346.             Bib::_newEntry $lastword
  347.         }
  348.         "New entry in new file" {
  349.             Bib::_newEntry $lastword 1
  350.         }
  351.         }
  352.         return 0
  353.     }
  354.     }
  355.     if $TeXmodeVars(showTitlesWithTeXCiteCompletion) {
  356.     set query "Rebuild Bibliography Database"
  357.     set rebuild Bib::rebuildDatabase
  358.     } else {
  359.     set query "Rebuild Bibliography Index"
  360.     set rebuild Bib::rebuildIndex
  361.     }
  362.     set match [completion::Find $lastword $completion_got \
  363.       $TeXmodeVars(showTitlesWithTeXCiteCompletion) 1 $query $rebuild]
  364.     if {$match != ""} {
  365.     if {[lookAt [getPos]] != "\}"} { insertText "\}" }
  366.     }
  367.     # we never bother with calling ourselves again, since we forced the above
  368.     # 'completion::Find' call to complete.
  369.     completion::already error
  370.     return 1
  371. }
  372.  
  373. proc TeX::Completion::Word {dummy} {
  374.     # we only complete the word if it doesn't end in some command
  375.     if {[lookAt [pos::math [getPos] - 1]] != "\{" } {
  376.     return [completion::word $dummy]
  377.     }
  378. }
  379.  
  380. # ◊◊◊◊ helpers ◊◊◊◊ #
  381.  
  382. proc TeX::updateCompletion { proc {got ""} {looking ""} } {
  383.     if [completion::general $got $looking] {
  384.     if {[lookAt [getPos]] != "\}"} {
  385.         insertText "\}"
  386.     } 
  387.     completion::already $proc
  388.     message "press <Cmd Tab> for another label"
  389.     return 1
  390.     } else {
  391.     completion::already error
  392.     # if {[lookAt [expr [getPos] - 1]] != "\}"} {
  393.     #     elec::Insertion "\}••"        
  394.     # } 
  395.     error ""
  396.     return 0
  397.     }
  398. }    
  399.  
  400. # ◊◊◊◊ setup various arrays for electrics ◊◊◊◊ #
  401. uplevel \#0 [list source [file join ${HOME} Tcl Completions TeXcmds.tcl]]
  402.  
  403. hook::register TeX::labelDelimChanged TeX::adjustElectricLabels
  404. proc TeX::adjustElectricLabels {args} {
  405. uplevel \#0 {
  406. set _x $TeXmodeVars(standardTeXLabelDelimiter)
  407. set TeXelectrics(*section) "\{•section name•\}\n••"
  408. set TeXelectrics(frac) "\{•numerator•\}\{•denominator•\}••"
  409. set TeXelectrics(sum) "_\{•from•\}^\{•to•\}••"
  410. set TeXelectrics(emph) "◊1"
  411. set TeXelectrics(includegraphics) "◊\[TeX::IncludeFile\]"
  412. set TeXelectrics(begin) "\{•environment name•\}\n\\end\{••\}\n••"
  413. set TeXelectrics(Sec*) "◊kill0Section~\\ref\{sec${_x}•label•\}••"
  414. set TeXelectrics(Table) "~\\ref\{tab${_x}•label•\}••"
  415. set TeXelectrics(App*) "◊kill0Appendix~\\ref\{sec${_x}•label•\}••"
  416. set TeXelectrics(Eq.) "~\\eqref\{eq${_x}•label•\}••"
  417. set TeXelectrics(Fig*) "◊kill0Figure~\\ref\{fig${_x}•label•\}••"
  418. set TeXelectrics(Cha*) "◊kill0Chapter~\\ref\{chap${_x}•label•\}••"
  419. set TeXelectrics(mbox) "\{••\}"
  420. set TeXelectrics(fbox) "\{••\}"
  421. set TeXelectrics(mbox) "\{••\}"
  422. set TeXelectrics(parbox) "◊\[TeX::parbox\]"
  423. set TeXelectrics(makebox) "◊\[TeX::boxes\]"
  424. set TeXelectrics(framebox) "◊\[TeX::boxes\]"
  425. set TeXelectrics(raisebox) "◊\[TeX::raisebox\]"
  426. set TeXelectrics(newsavebox) "\{••\}"
  427. set TeXelectrics(usebox) "\{••\}"
  428. set TeXelectrics(sbox) "◊\[TeX::sbox\]"
  429. set TeXelectrics(savebox) "◊\[TeX::savebox\]"
  430. set TeXelectrics(rule) "◊\[TeX::rule\]"
  431. #set TeXelectrics(subfigure) "\[•caption•\]\{\\label\{fig${_x}••\}\}\%\r\\includegraphics\[•width=,height=•\]\{•eps file•\}\}"
  432. set TeXbodies(array) "◊\[TeX::BuildTabular array\]"
  433. set TeXbodies(equation) "\n\t•equation body•\n\t\\label\{eq${_x}•label•\}"
  434. set TeXbodies(description) "◊\[TeX::BuildList description\]"
  435. set TeXbodies(enumerate) "◊\[TeX::BuildList enumerate\]"
  436. set TeXbodies(itemize) "◊\[TeX::BuildList itemize\]"
  437. set TeXbodies(list) "◊\[TeX::BuildList list\]"
  438. set TeXbodies(trivlist) "◊\[TeX::BuildList trivlist\]"
  439. set TeXbodies(figure) "◊\[TeX::Figure\]"
  440. set TeXbodies(table) "\n\t••\n\t\\caption•\[short title for t.o.t.\]•\{•caption•\}\n\t\\protect[TeX::label tab]"
  441.  
  442. set TeXbodies(tabular) "◊\[TeX::BuildTabular tabular\]"
  443. set TeXbodies(tabular*) "◊\[TeX::BuildTabular tabular*\]"
  444. set TeXbodies(gather) "\n\t•• \n\t\\label\{eq${_x}••\} \\\\\n\t•• \n\t\\label\{eq${_x}••\}"
  445. set TeXbodies(split) "\n\t•• &•• \\\\\n\t•• &•• \\\\"
  446. set TeXbodies(cases) "\n\t•• & •• \\\\\n\t•• & ••"
  447.  
  448. set TeXbodies(equationarray) "◊\[TeX::equationarray\]"
  449. set TeXbodies(minipage) "◊\[TeX::minipage\]"
  450. set TeXbodies(matrix) "◊\[TeX::matrix\]"
  451. set TeXbodies(pmatrix) "◊\[TeX::matrix\]"
  452. set TeXbodies(bmatrix) "◊\[TeX::matrix\]"
  453. set TeXbodies(vmatrix) "◊\[TeX::matrix\]"
  454. set TeXbodies(Vmatrix) "◊\[TeX::matrix\]"
  455. set TeXbodies(align) "◊\[TeX::align\]"
  456. set TeXbodies(alignat) "◊\[TeX::alignat\]"
  457.  
  458. set TeXbodies(align) "\n\t•equation 1 l.h.s.• &•• \n\t\\label\{eq${_x}••\} \\\\\n\t•equation 2 l.h.s.• &•• \n\t\\label\{eq${_x}••\}"
  459.  
  460. set TeXEnvItems(enumerate) "\n\\item ••"
  461. set TeXEnvItems(itemize) "\n\\item ••"
  462. set TeXEnvItems(description) "\n\\item\[•name•\] •description•"
  463. set TeXEnvItems(align) "\\\\\n•next equation l.h.s.• &•• \n\\label\{eq${_x}••\} "
  464. set TeXEnvItems(gather) "\\\\\n•• \n\\label\{eq${_x}••\} "
  465. set TeXEnvItems(split) "•• &•• \\\\"
  466. set TeXEnvItems(cases) "•• &•• \\\\"
  467. set _texrefprefixes [list fig${_x} eq${_x} sec${_x} chap${_x} tab${_x} ]
  468. unset _x
  469. }
  470.  
  471. }
  472.  
  473. # call it now
  474. TeX::adjustElectricLabels
  475.  
  476.  
  477. # ◊◊◊◊ environment assistors ◊◊◊◊ #
  478.  
  479. ## 
  480.  # -------------------------------------------------------------------------
  481.  #     
  482.  # "TeXAddItem"    --
  483.  #    
  484.  #  Scan the local environment and insert a new item into that environment,
  485.  #  of the appropriate type.
  486.  #    
  487.  #  Currently not too sophisticated.
  488.  # -------------------------------------------------------------------------
  489.  ##
  490. proc TeXAddItem {} {
  491.     set env [lindex [split [eval getText [searchEnvironment]] "{}"] 1]
  492.     global TeXEnvItems
  493.     if ![catch {set item $TeXEnvItems($env)}] {
  494.     elec::Insertion $item
  495.     }
  496. }
  497.  
  498. # ◊◊◊◊ Template embeddable proc's ◊◊◊◊ #
  499.  
  500. proc TeX::IncludeFile {} {
  501.     # could try to ensure this file's on the search path?
  502.     if ![regexp {\{, } [lookAt [pos::math [getPos] - 1]]] {
  503.     append res "\{"
  504.     }
  505.     append res [file tail [getfile "Name of file to include:"]]
  506.     return $res
  507. }
  508.     
  509.  
  510.  
  511. # ◊◊◊◊ Expansions ◊◊◊◊ #
  512. namespace eval TeX::Expansion {}
  513.  
  514. # proc by Tom Fetherston
  515. proc TeX::Expansion::ExCmd { {cmd ""} {dictExt "acronyms"}} {
  516.     if ![string length $cmd] { 
  517.     set cmd [completion::lastWord]
  518.     # if there's any whitespace in the command then it's no good to us
  519.     if [containsSpace $cmd] { return 0 }
  520.     }
  521.     
  522.     set m [modeALike]
  523.     set hint [string trim [join [split $cmd \\ ]]]
  524.     
  525.     if { [set matches [elec::acronymListExpansions $hint ${m}${dictExt}]] == 0 } {
  526.     return 0
  527.     } else {
  528.     set result [elec::expandThis $cmd $matches]
  529.     set match [lindex  $result 0]
  530.     catch {set keystroke [lindex $result 1]}
  531.     if [string length $match] {
  532.         # we completed or cancelled, so move on
  533.         # WHY ISN'T THIS 'alreadyExpanding' ???????????? vmd
  534.         completion::already error
  535.         if { $match == 1 } {
  536.         return 1
  537.         } else {
  538.         set curPos [getPos]
  539.         set retVal [completion [modeALike] Electric "${match}"]
  540.         if {([pos::compare [getPos] == $curPos]) && [info exists keystroke]} {
  541.             insertText $keystroke
  542.         } 
  543.         return $retVal
  544.         }
  545.     } else {
  546.         elec::alreadyExpanding Cmd
  547.         return 1
  548.     }
  549.     }
  550.     
  551. }
  552.  
  553.