Ejemplo n.º 1
0
    def execute(self, app, cont, state=None):
        """See [Action.execute].
        
        .. [Action.execute] file:///./actions_gen.Action.html#execute"""
        match = app.search_for(regexp=':.*',
                               direction=self.direction,
                               unlogged=1)
        if not match:
            return


# check if the next line is blank.  If the previous search succeeded, then
# we should be at the end of the line containing the ":" and the next
# character should be a newline (unless we are at the end of the buffer).
# In either case, this next search, with where = -1, should not move the
# cursor.
        match = app.search_for('\n[ \t]*(\n|$)', where=-1, unlogged=1)
        if not match:
            # if no blank line, insert a new one and indent it appropriately
            insert_indented_line = ActionInsert(code_bef='\n\t', code_after='')
            insert_indented_line.execute(app, cont, state=state)
        else:
            # if there is a blank line, just go to the end of it
            # (and assume that it has the correct indentation)
            match = app.search_for('\n[ \t]*', unlogged=1)
Ejemplo n.º 2
0
  def test_the_index_of_simple_csc_and_an_lsa_definition(self):
      wciSay = WhatCanISay.WhatCanISay()
      interp = CmdInterp()
      # do one csc and one lsa:
      interp.add_csc(
          CSCmd(["equals"],
                meanings={contAny: ActionInsert("====")},
                name="equals csc"))
      interp.add_lsa(
          LSAlias(["plus"],
                  meanings={all_languages: " + "},
                  name="plus sign"))
      wciSay.load_commands_from_interpreter(self._app(), interp, 'C')
      expected = \
 {'C': {'equals': [[{'action': "Inserts '====^' in current buffer",
                  'doc': None,
                  'equiv': 'Any',
                  'scope': 'global',
                  'setdescription': 'no description',
                  'setname': 'cscs'}]],
      'plus': [{'description': 'no description',
               'name': 'plus sign',
               'new_symbol': None,
               'setname': 'lsas',
               'spacing': 0,
               'written_form': ' + '}]}}
      self.assert_equal(
          expected, wciSay.index,
          "index of one CSC and one LSA command is not as expected")
Ejemplo n.º 3
0
    def test_the_index_of_a_cmdset_with_an_lsa_and_a_csc_in_it(self):
        wciSay = WhatCanISay.WhatCanISay()
        interp = CmdInterp()
        # the new CmdSet can contain both CSCs and LSAs...
        # do one csc and one lsa:
        cmds = CmdSet("commands set", description="generic commands set")
        cmds.add_lsa(
            LSAlias(["plus"],
                    meanings={all_languages: " + "},
                    name="plus sign"))
        # without docstring:
        cmds.add_csc(
            CSCmd(["equals"], meanings={contAny: ActionInsert("====")}))
        # with docstring:
        cmds.add_csc(
            CSCmd(["not equal"],
                  meanings={contAny: ActionInsert(" != ")},
                  docstring="csc not equal"))

        interp.add_cmd_set(cmds)
        wciSay.load_commands_from_interpreter(self._app(), interp, 'C')
        expected = \
   {'C': {'equals': [[{'action': "Inserts '====^' in current buffer",
                    'doc': None,
                    'equiv': 'Any',
                    'scope': 'global',
                    'setdescription': 'generic commands set',
                    'setname': 'commands set'}]],
        'not equal': [[{'action': "Inserts ' != ^' in current buffer",
                       'doc': 'csc not equal',
                       'equiv': 'Any',
                       'scope': 'global',
                       'setdescription': 'generic commands set',
                       'setname': 'commands set'}]],
        'plus': [{'name': 'plus sign',
                 'new_symbol': None,
                 'setdescription': 'generic commands set',
                 'setname': 'commands set',
                 'spacing': 0,
                 'written_form': ' + '}]}}
        self.assert_equal(
            expected, wciSay.index,
            "index of one CSC and one LSA command is not as expected")
Ejemplo n.º 4
0
 def test_This_is_how_you_create_a_WhatCanISay_instance(self):
     wciSay = WhatCanISay.WhatCanISay()
     interp = CmdInterp()
     # load one lsa and one csc:
     interp.add_csc(
         CSCmd(["equals"],
               meanings={contAny: ActionInsert("====")},
               name="equals csc"))
     interp.add_lsa(
         LSAlias(["plus"],
                 meanings={all_languages: " + "},
                 name="plus sign"))
     wciSay.load_commands_from_interpreter(self._app(), interp, 'C')
Ejemplo n.º 5
0
lsa_not_meanings = dict(python='not', C="!", perl="!")

csc_with_arguments_spoken_forms = ['with arguments']
csc_with_arguments_meanings = {all_languages: gen_parens_pair}

csc_with_arguments_docstring = 'giving the parens after a function call, position inside'
csc_else_spoken_forms = ['else']
csc_else_duplicate_spoken_forms = ['else duplicate']
csc_python_else_meanings = {
    ContBlankLine('python'):
    ActionInsertNewClause('($|\n)',
                          code_bef='else on blank line',
                          code_after='',
                          where=-1),
    contPython:
    ActionInsert("else on non blank line")
}
csc_c_else_meanings = {contC: c_else}

csc_python_else_docstring = 'else clause only python'
csc_c_else_docstring = 'else clause only c'
csc_equals_spoken_forms = ['equals']
# only python, otherwise lsa:
csc_equals_meanings = {ContInsideArguments('python'): ActionInsert("=")}

csc_equals_docstring = 'equal sign inside arguments'

# lsa in case csc does not apply:
lsa_equals_spoken_forms = ['equals']
lsa_equals_meanings = {('python', 'C'): ' = '}
Ejemplo n.º 6
0
lsa_not_meanings = dict(python='not', C="!", perl="!")

csc_with_arguments_spoken_forms = ['with arguments']
csc_with_arguments_meanings = {all_languages: gen_parens_pair}

csc_with_arguments_docstring = 'giving the parens after a function call, position inside'
csc_else_spoken_forms = ['else']
csc_else_duplicate_spoken_forms = ['else duplicate']
csc_python_else_meanings = {
    ContBlankLine('python'):
    ActionInsertNewClause('($|\n)',
                          code_bef='else on blank line',
                          code_after='',
                          where=-1),
    contPython:
    ActionInsert("else on non blank line")
}
csc_c_else_meanings = {contC: c_else}

csc_python_else_docstring = 'else clause only python'
csc_c_else_docstring = 'else clause only c'
csc_equals_spoken_forms = ['equals']
csc_equals_meanings = {
    ContPyInsideArguments(): ActionInsert("="),
    ContAny(): ActionInsert(' = ')
}
csc_equals_docstring = 'equal sign'

# lsa in case csc does not apply:
lsa_equals_spoken_forms = ['equals']
lsa_equals_meanings = {('python', 'C'): ' = '}
Ejemplo n.º 7
0
# VoiceCode, a programming-by-voice environment
#
# 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# (C)2000, National Research Council of Canada
#
##############################################################################

"""Action functions for java language """

from actions_gen import Action, ActionInsert

java_function_definition = \
    ActionInsert(code_bef='function ',
                 code_after='(){\n\t\n}',
                 docstring = """Types template code for a java function (including body)""")

java_function_declaration = java_function_definition
Ejemplo n.º 8
0
# 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# (C)2000, National Research Council of Canada
#
##############################################################################
"""Action functions for php language (in places where different from c) """

from actions_gen import Action, ActionInsert

php_function_declaration = \
    ActionInsert(code_bef='',
                 code_after='();',
                 docstring = """Types template code for a php function (no function body)""")

php_function_definition = \
    ActionInsert(code_bef='',
                 code_after='()\n{\n\t\n}',
                 docstring = """Types template code for a php function (including body)""")
Ejemplo n.º 9
0
# 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# (C)2000, National Research Council of Canada
#
##############################################################################
"""Action functions for java language """

from actions_gen import Action, ActionInsert, ActionSearch, ActionInsertNewClause



java_function_definition = \
    ActionInsert(code_bef='',
                 code_after='(){\n\t\n}',
                 docstring = """Types template code for a java function (including body)""")

java_function_declaration = java_function_definition

# this assumes the if ends with a '}' (not a one-liner)
java_else_if = \
                ActionInsertNewClause(end_of_clause_regexp='\}',
                                      where = 1, direction = 1,
                                      add_lines = 1,
                                      code_bef='\nelse if (', code_after='){\n\t\n}',
                                      back_indent_by=0,
                                      docstring='else-if clause of a Java conditional')

java_class_body = \
    ActionSearch(regexp=r'\{\s*',
Ejemplo n.º 10
0
            #
            # Insert comma if this is not the first argument in the list
            #
            if not arg_list_empty:
                app.insert_indent(', ', '')


c_simple_for = \
    ActionInsert(code_bef='for (',
                   #                code_after=';  <= ; ++)\n\t{\n\t\n\t}\n',
                   # I'm switching this to use the more common indentation, which matches
                   # what Emacs does anyway
                   # ugh - that's not true -- Emacs does it this way for for-loops which
                   # start at indentation = 0, but the way above for for-loops which are
                   # inside another block.  That's idiotic!

                   # because it's easy to say e.g. 'equals zero' and harder to correct it
                   # if we want to handle the loop another way, don't insert the '=0'
                   # automatically (SN)
                   #                code_after='=0;  <= ; ++)\n{\n\t\n}\n',
                 code_after='; ; )\n{\n\t\n}\n',
                 docstring = """Insert template code for a simple C for loop""")

c_simple_while = \
    ActionInsert(code_bef='while (', code_after=')\n{\n\t\n}',
                 docstring = """Insert template code for a simple C while loop""")

c_do_while = \
    ActionInsert(code_bef='do\n{\n\t', code_after='\n} while ();\n',
                 docstring = """Insert template code for a C/C++ do-while loop""")
Ejemplo n.º 11
0
# 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# (C)2000, National Research Council of Canada
#
##############################################################################
"""Action functions for Python language"""

import re, sys

import SymDict
from actions_gen import Action, ActionInsert, ActionSearch, ActionInsertNewClause

py_empty_dictionary = ActionInsert(
    code_bef='{}',
    code_after='',
    docstring="""Types code for an empty Python dictionary (e.g. {}^)""")

py_simple_for = ActionInsert(
    code_bef='for ',
    code_after=':\n\t',
    docstring="""Insert template code for a simple Python for loop""")

py_goto_body = \
    ActionSearch(regexp=':[ \t]*(\n|$)[ \t]*',
                 docstring="""Move cursor to the body of a Python compound statement""")

py_new_statement = \
    ActionInsertNewClause(end_of_clause_regexp='(\n|$)',
                          where = -1, direction = 1,
                          add_lines = 1,
Ejemplo n.º 12
0
# 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# (C)2000, National Research Council of Canada
#
##############################################################################
"""Action functions for perl language """

from actions_gen import Action, ActionInsert

perl_else_if = \
    ActionInsert(code_bef='*** action perl_else_if not implemented yet ***')

perl_function_declaration = \
    ActionInsert(code_bef='',
                 code_after='();',
                 docstring = """Types template code for a perl function (no function body)""")

perl_function_definition = \
    ActionInsert(code_bef='',
                 code_after='()\n{\n\t\n}',
                 docstring = """Types template code for a perl function (including body)""")
Ejemplo n.º 13
0
            #
            # Insert comma if this is not the first argument in the list
            #
            if not arg_list_empty:
                app.insert_indent(', ', '')


m_simple_for = \
    ActionInsert(code_bef='for ',
                   #                code_after=';  <= ; ++)\n\t{\n\t\n\t}\n',
                   # I'm switching this to use the more common indentation, which matches
                   # what Emacs does anyway
                   # ugh - that's not true -- Emacs does it this way for for-loops which
                   # start at indentation = 0, but the way above for for-loops which are
                   # inside another block.  That's idiotic!

                   # because it's easy to say e.g. 'equals zero' and harder to correct it
                   # if we want to handle the loop another way, don't insert the '=0'
                   # automatically (SN)
                   #                code_after='=0;  <= ; ++)\n{\n\t\n}\n',
                 code_after='\nend',
                 docstring = """Insert template code for a simple Matlab for loop""")

m_simple_while = \
    ActionInsert(code_bef='while ', code_after='\nend',
                 docstring = """Insert template code for a simple Matlab while loop""")

m_do_while = \
    ActionInsert(code_bef='do\n\t', code_after='\n while ',
                 docstring = """Insert template code for a Matlab do-while loop""")