Changeset 1256


Ignore:
Timestamp:
Jul 23, 2011, 12:59:13 PM (6 years ago)
Author:
stefan
Message:

added built-in environments

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/codehelper/commands.xml

    r1250 r1256  
    11<!DOCTYPE commandList [
    2     <!ELEMENT commandList (environment|command)+>
    3 
    4     <!ELEMENT environment (command)*>
    5     <!ATTLIST environment name CDATA #REQUIRED>
     2    <!ELEMENT commandList (scope|command,environment)+>
     3
     4    <!ELEMENT scope (command)*>
     5    <!ATTLIST scope name CDATA #REQUIRED>
    66
    77    <!ELEMENT command (argument)*>
     
    1010                      hint CDATA #IMPLIED
    1111                      style CDATA #IMPLIED>
     12
     13    <!ELEMENT environment (argument)*>
     14    <!ATTLIST environment name CDATA #REQUIRED
     15                          usage CDATA #IMPLIED
     16                          hint CDATA #IMPLIED
     17                          style CDATA #IMPLIED>
    1218
    1319    <!ELEMENT argument (argumentValue)*>
     
    928934
    929935  <command name="begin" usage="\begin{@environment@}@|@&nl;\end{@environment@}" hint="paragraph-making environments" style="begin">
    930     <argument name="environment" type="opening_env" value="" completion="true">
    931       <argumentValue value="abstract"/>
    932       <argumentValue value="array"/>
    933       <argumentValue value="center"/>
    934       <argumentValue value="description"/>
    935       <argumentValue value="displaymath"/>
    936       <argumentValue value="enumerate"/>
    937       <argumentValue value="eqnarray"/>
    938       <argumentValue value="equation"/>
    939       <argumentValue value="figure"/>
    940       <argumentValue value="flushleft"/>
    941       <argumentValue value="flushright"/>
    942       <argumentValue value="itemize"/>
    943       <argumentValue value="list"/>
    944       <argumentValue value="math"/>
    945       <argumentValue value="minipage"/>
    946       <argumentValue value="picture"/>
    947       <argumentValue value="quotation"/>
    948       <argumentValue value="quote"/>
    949       <argumentValue value="tabbing"/>
    950       <argumentValue value="table"/>
    951       <argumentValue value="tabular"/>
    952       <argumentValue value="thebibliography"/>
    953       <argumentValue value="theorem"/>
    954       <argumentValue value="titlepage"/>
    955       <argumentValue value="trivlist"/>
    956       <argumentValue value="verbatim"/>
    957       <argumentValue value="verse"/>
    958     </argument>
     936    <argument name="environment" type="opening_env" value="" completion="true"/>
    959937  </command>
    960938
     
    963941  </command>
    964942
    965   <environment name="picture">
     943  <environment name="array" hint="array in math environment"/>
     944  <environment name="description" hint="labeled list of items"/>
     945  <environment name="displaymath" hint="display formulas without numbering"/>
     946  <environment name="enumerate" hint="list of numbered items"/>
     947  <environment name="eqnarray" hint="aligned math formulas"/>
     948  <environment name="equation" hint="aligned math formula"/>
     949  <environment name="figure" hint="figure with caption"/>
     950  <environment name="flushleft" hint="align lines on the left"/>
     951  <environment name="flushright" hint="align lines on the right"/>
     952  <environment name="itemize" hint="list of unnumbered items"/>
     953  <environment name="list" hint="general list of items"/>
     954  <environment name="math" hint="math environment"/>
     955  <environment name="minipage" hint="small page inside the page"/>
     956  <environment name="picture"/>
     957  <environment name="quotation"/>
     958  <environment name="quote"/>
     959  <environment name="tabbing" hint=""/>
     960  <environment name="table" hint=""/>
     961  <environment name="tabular" hint=""/>
     962  <environment name="tabularx" hint=""/>
     963  <environment name="thebibliography" hint=""/>
     964  <environment name="theorem" hint=""/>
     965  <environment name="titlepage" hint=""/>
     966  <environment name="trivlist" hint=""/>
     967  <environment name="verbatim" hint=""/>
     968  <environment name="verse" hint=""/>
     969
     970  <scope name="picture">
    966971    <command name="line" usage="\line(@x-slope@,@y-slope@){@length@}"
    967972             hint="draws a line of the specified length and slope">
     
    10111016      </argument>
    10121017    </command>
    1013   </environment>
    1014 
    1015   <environment name="math">
     1018  </scope>
     1019
     1020  <scope name="math">
    10161021    <command name="mathcal" usage="\mathcal{@cal@}" hint="calligraphic letter (LaTeX2e)">
    10171022      <argument name="cal" hint="the letter">
     
    10301035      </argument>
    10311036    </command>
    1032   </environment>
    1033 
    1034   <environment name="array &amp; table">
     1037  </scope>
     1038
     1039  <scope name="array &amp; table">
    10351040    <command name="multicolumn" usage="\multicolumn{@cols@}{@pos@}{@text@}"
    10361041             hint="used to make an entry that spans several columns">
     
    10451050      </argument>
    10461051    </command>
    1047   </environment>
    1048 
    1049   <environment name="paragraph">
     1052  </scope>
     1053
     1054  <scope name="paragraph">
    10501055    <command name="newline" hint="breaks the line right where it is">
    10511056    </command>
    1052   </environment>
     1057  </scope>
    10531058</commandList>
  • trunk/src/jlatexeditor/codehelper/EnvironmentCodeHelper.java

    r1248 r1256  
    3232    }
    3333  };
     34  private static final Function1<CHCommand,String> CHCOMMAND_2_STING_FUNCTION = new Function1<CHCommand, String>() {
     35    public String apply(CHCommand a1) {
     36      return a1.getName();
     37    }
     38  };
    3439
    3540  public EnvironmentCodeHelper() {
     
    4954  public Iterable<CHCommand> getCompletions(String search, Function1<TrieSet<PackagesExtractor.Environment>, Boolean> filterFunc) {
    5055    ExtIterable<String> userIter = SCEManager.getBackgroundParser().getEnvironments().getObjectsIterable(search).map(ENVIRONMENT_2_STRING_FUNCTION);
     56    ExtIterable<String> standardIter = SCEManager.getLatexCommands().getEnvironments().getObjectsIterable(search).map(CHCOMMAND_2_STING_FUNCTION);
    5157    ExtIterable<String> packEnvIter = PackagesExtractor.getPackageParser().getEnvironments().getTrieSetIterator(search).filter(filterFunc).map(TRIE_SET_2_STRING_FUNCTION);
    5258    ExtIterable<String> dcEnvIter = PackagesExtractor.getDocClassesParser().getEnvironments().getTrieSetIterator(search).filter(filterFunc).map(TRIE_SET_2_STRING_FUNCTION);
    5359
    54     return new MergeSortIterable<String>(STRING_COMPARATOR, userIter, packEnvIter, dcEnvIter).distinct().map(STRING_2_CHCOMMAND).toList(20);
     60    return new MergeSortIterable<String>(STRING_COMPARATOR, userIter, standardIter, packEnvIter, dcEnvIter).distinct().map(STRING_2_CHCOMMAND).toList(20);
    5561  }
    5662
     
    6773    List<AbstractTrie<? extends Object>> tries = Arrays.asList(
    6874      SCEManager.getBackgroundParser().getEnvironments(),
     75      SCEManager.getLatexCommands().getEnvironments(),
    6976      PackagesExtractor.getPackageParser().getEnvironments(),
    7077      PackagesExtractor.getDocClassesParser().getEnvironments()
  • trunk/src/sce/codehelper/StaticCommandsCodeHelper.java

    r1233 r1256  
    2727    pattern = new PatternPair(patternString);
    2828    commands = commandsReader.getCommands();
    29     environments = commandsReader.getEnvironments();
     29    environments = commandsReader.getScopes();
    3030  }
    3131
  • trunk/src/sce/codehelper/StaticCommandsReader.java

    r1246 r1256  
    1515public class StaticCommandsReader {
    1616  /** The command reference. */
    17   protected Trie<CHCommand> commands = null;
     17  protected Trie<CHCommand> commands = new Trie<CHCommand>();
     18  /** The environment reference. */
     19  protected Trie<CHCommand> environments = new Trie<CHCommand>();
    1820  /** Maps an environment name to a list of commands. */
    19   protected HashMap<String,ArrayList<CHCommand>> environments = new HashMap<String, ArrayList<CHCommand>>();
     21  protected HashMap<String,ArrayList<CHCommand>> scopes = new HashMap<String, ArrayList<CHCommand>>();
    2022
    2123  public StaticCommandsReader(String filename) {
    22     commands = new Trie<CHCommand>();
    23 
    2424    readCommands(filename, false);
    2525  }
     
    5151      if (commandXML.getName().equals("command")) {
    5252        // extract command form XML element
    53         CHCommand command = getCommand(commandXML);
     53        CHCommand command = getComEnv(commandXML, false);
    5454        if (command == null) continue;
    5555
     
    6262
    6363      if (commandXML.getName().equals("environment")) {
     64        // extract command form XML element
     65        CHCommand env = getComEnv(commandXML, true);
     66        if (env == null) continue;
     67
     68        // user defined command?
     69        env.setUserDefined(true);
     70
     71        // add the command to the commands list
     72        environments.add(env.getName(), env);
     73      } else
     74
     75      if (commandXML.getName().equals("scope")) {
    6476        String envName = decode(commandXML.getAttribute("name"));
    6577        if (envName == null) {
     
    7183        for (XMLElement element : commandXML.getChildElements()) {
    7284          // extract command form XML element
    73           CHCommand command = getCommand(element);
     85          CHCommand command = getComEnv(element, false);
    7486          if (command == null) continue;
    7587
     
    7789          envCommands.add(command);
    7890        }
    79         environments.put(envName, envCommands);
     91        scopes.put(envName, envCommands);
    8092      } else {
    8193        System.out.println("Error in commands.xml: expected element 'command' or 'environment' instead of element '" + commandXML.getName() + "'");
     
    8698  }
    8799
    88   private CHCommand getCommand(XMLElement commandXML) {
     100  private CHCommand getComEnv(XMLElement commandXML, boolean env) {
    89101    String commandName = decode(commandXML.getAttribute("name"));
    90102    if (commandName == null) {
     
    98110    command.setUsage(usage);
    99111    if (usage == null) {
    100       command.setUsage("\\" + command);
     112      if (!env) {
     113        command.setUsage("\\" + command);
     114      } else {
     115        command.setUsage("\\begin{" + command + "}@|@\n\\end{" + command + "}");
     116      }
    101117    }
    102118    command.setStyle(decode(commandXML.getAttribute("style")));
     
    189205  }
    190206
    191   public HashMap<String, ArrayList<CHCommand>> getEnvironments() {
     207  public Trie<CHCommand> getEnvironments() {
    192208    return environments;
    193209  }
     210
     211  public HashMap<String, ArrayList<CHCommand>> getScopes() {
     212    return scopes;
     213  }
    194214}
Note: See TracChangeset for help on using the changeset viewer.