Пример #1
0
 def dynamicCompletion(self, event=None):
     '''
     dabbrev-completion
     Insert the common prefix of all dynamic abbrev's matching the present word.
     This corresponds to C-M-/ in Emacs.
     '''
     c, p, u = self.c, self.c.p, self.c.p.v.u
     w = self.editWidget(event)
     if not w: return
     s = w.getAllText()
     ins = ins1 = w.getInsertPoint()
     if 0 < ins < len(s) and not g.isWordChar(s[ins]): ins1 -= 1
     i, j = g.getWord(s, ins1)
     word = w.get(i, j)
     aList = self.getDynamicList(w, word)
     if not aList: return
     # Bug fix: remove s itself, otherwise we can not extend beyond it.
     if word in aList and len(aList) > 1:
         aList.remove(word)
     prefix = functools.reduce(g.longestCommonPrefix, aList)
     if prefix.strip():
         ypos = w.getYScrollPosition()
         b = c.undoer.beforeChangeNodeContents(p, oldYScroll=ypos)
         s = s[: i] + prefix + s[j:]
         w.setAllText(s)
         w.setInsertPoint(i + len(prefix))
         w.setYScrollPosition(ypos)
         c.undoer.afterChangeNodeContents(p,
             command='dabbrev-completion', bunch=b, dirtyVnodeList=[])
         c.recolor()
Пример #2
0
    def dynamicExpansion(self, event=None):
        '''
        dabbrev-expands (M-/ in Emacs).

        Inserts the longest common prefix of the word at the cursor. Displays
        all possible completions if the prefix is the same as the word.
        '''
        trace = False and not g.unitTesting
        c = self.c
        p = c.p
        w = self.editWidget(event)
        if not w:
            if trace: g.trace('no widget!')
            return
        s = w.getAllText()
        ins = ins1 = w.getInsertPoint()
        if 0 < ins < len(s) and not g.isWordChar(s[ins]): ins1 -= 1
        i, j = g.getWord(s, ins1)
        w.setInsertPoint(j)
            # This allows the cursor to be placed anywhere in the word.
        word = w.get(i, j)
        aList = self.getDynamicList(w, word)
        if not aList:
            if trace: g.trace('empty completion list')
            return
        if word in aList and len(aList) > 1:
            aList.remove(word)
        prefix = functools.reduce(g.longestCommonPrefix, aList)
        prefix = prefix.strip()
        if trace: g.trace(word, prefix, aList)
        self.dynamicExpandHelper(event, prefix, aList, w)
Пример #3
0
    def dynamicExpansion(self, event=None):
        """
        dabbrev-expands (M-/ in Emacs).

        Inserts the longest common prefix of the word at the cursor. Displays
        all possible completions if the prefix is the same as the word.
        """
        w = self.editWidget(event)
        if not w:
            return
        s = w.getAllText()
        ins = ins1 = w.getInsertPoint()
        if 0 < ins < len(s) and not g.isWordChar(s[ins]):
            ins1 -= 1
        i, j = g.getWord(s, ins1)
        # This allows the cursor to be placed anywhere in the word.
        w.setInsertPoint(j)
        word = w.get(i, j)
        aList = self.getDynamicList(w, word)
        if not aList:
            return
        if word in aList and len(aList) > 1:
            aList.remove(word)
        prefix = functools.reduce(g.longestCommonPrefix, aList)
        prefix = prefix.strip()
        self.dynamicExpandHelper(event, prefix, aList, w)
Пример #4
0
 def dynamicCompletion(self, event=None):
     """
     dabbrev-completion
     Insert the common prefix of all dynamic abbrev's matching the present word.
     This corresponds to C-M-/ in Emacs.
     """
     c, p = self.c, self.c.p
     w = self.editWidget(event)
     if not w:
         return
     s = w.getAllText()
     ins = ins1 = w.getInsertPoint()
     if 0 < ins < len(s) and not g.isWordChar(s[ins]):
         ins1 -= 1
     i, j = g.getWord(s, ins1)
     word = w.get(i, j)
     aList = self.getDynamicList(w, word)
     if not aList:
         return
     # Bug fix: remove s itself, otherwise we can not extend beyond it.
     if word in aList and len(aList) > 1:
         aList.remove(word)
     prefix = functools.reduce(g.longestCommonPrefix, aList)
     if prefix.strip():
         ypos = w.getYScrollPosition()
         b = c.undoer.beforeChangeNodeContents(p)
         s = s[:i] + prefix + s[j:]
         w.setAllText(s)
         w.setInsertPoint(i + len(prefix))
         w.setYScrollPosition(ypos)
         c.undoer.afterChangeNodeContents(p, command='dabbrev-completion', bunch=b)
         c.recolor()
Пример #5
0
 def dynamicExpandHelper(self, event, prefix=None, aList=None, w=None):
     '''State handler for dabbrev-expands command.'''
     trace = False and not g.unitTesting
     c, k = self.c, self.c.k
     p = c.p
     tag = 'dabbrev-expand'
     state = k.getState(tag)
     if state == 0:
         self.w = w
         prefix2 = 'dabbrev-expand: '
         c.frame.log.deleteTab('Completion')
         g.es('', '\n'.join(aList), tabName='Completion')
         # Protect only prefix2.
         # This is required for tab completion and backspace to work properly.
         k.setLabelBlue(prefix2, protect=True)
         k.setLabelBlue(prefix2 + prefix, protect=False)
         if trace: g.trace('len(aList)', len(aList))
         k.getArg(event,
                  tag,
                  1,
                  self.dynamicExpandHelper,
                  tabList=aList,
                  prefix=prefix)
     else:
         c.frame.log.deleteTab('Completion')
         k.clearState()
         k.resetLabel()
         if k.arg:
             w = self.w
             s = w.getAllText()
             ypos = w.getYScrollPosition()
             b = c.undoer.beforeChangeNodeContents(p, oldYScroll=ypos)
             ins = ins1 = w.getInsertPoint()
             if 0 < ins < len(s) and not g.isWordChar(s[ins]): ins1 -= 1
             i, j = g.getWord(s, ins1)
             word = s[i:j]
             s = s[:i] + k.arg + s[j:]
             if trace:
                 g.trace('ins', ins, 'k.arg', repr(k.arg), 'word', word)
             w.setAllText(s)
             w.setInsertPoint(i + len(k.arg))
             w.setYScrollPosition(ypos)
             c.undoer.afterChangeNodeContents(p,
                                              command=tag,
                                              bunch=b,
                                              dirtyVnodeList=[])
             c.recolor()
Пример #6
0
 def dynamicExpandHelper(self, event, prefix=None, aList=None, w=None):
     '''State handler for dabbrev-expands command.'''
     trace = False and not g.unitTesting
     c, k = self.c, self.c.k
     p = c.p
     tag = 'dabbrev-expand'
     state = k.getState(tag)
     if state == 0:
         self.w = w
         prefix2 = 'dabbrev-expand: '
         c.frame.log.deleteTab('Completion')
         g.es('', '\n'.join(aList), tabName='Completion')
         # Protect only prefix2.
         # This is required for tab completion and backspace to work properly.
         k.setLabelBlue(prefix2, protect=True)
         k.setLabelBlue(prefix2 + prefix, protect=False)
         if trace: g.trace('len(aList)', len(aList))
         k.getArg(event, tag, 1, self.dynamicExpandHelper, tabList=aList, prefix=prefix)
     else:
         c.frame.log.deleteTab('Completion')
         k.clearState()
         k.resetLabel()
         if k.arg:
             w = self.w
             s = w.getAllText()
             ypos = w.getYScrollPosition()
             b = c.undoer.beforeChangeNodeContents(p, oldYScroll=ypos)
             ins = ins1 = w.getInsertPoint()
             if 0 < ins < len(s) and not g.isWordChar(s[ins]): ins1 -= 1
             i, j = g.getWord(s, ins1)
             word = s[i: j]
             s = s[: i] + k.arg + s[j:]
             if trace: g.trace('ins', ins, 'k.arg', repr(k.arg), 'word', word)
             w.setAllText(s)
             w.setInsertPoint(i + len(k.arg))
             w.setYScrollPosition(ypos)
             c.undoer.afterChangeNodeContents(p,
                 command=tag, bunch=b, dirtyVnodeList=[])
             c.recolor()
Пример #7
0
 def addInverseAbbreviation(self, event):
     '''
     Add an inverse abbreviation:
     The selected text is the abbreviation name.
     The minibuffer prompts you for the value of the abbreviation.
     '''
     k = self.c.k
     state = k.getState('add-inverse-abbr')
     if state == 0:
         self.w = self.editWidget(event)
         if self.w:
             k.setLabelBlue('Add Inverse Abbreviation: ')
             k.getArg(event, 'add-inverse-abbr', 1, self.addInverseAbbreviation)
     else:
         w = self.w
         k.clearState()
         k.resetLabel()
         s = w.getAllText()
         i = w.getInsertPoint()
         i, j = g.getWord(s, i - 1)
         word = s[i: j]
         if word:
             self.abbrevs[word] = k.arg, 'add-inverse-abbr'
Пример #8
0
 def dynamicExpandHelper1(self, event):
     '''Finisher for dabbrev-expands.'''
     c, k = self.c, self.c.k
     p = c.p
     c.frame.log.deleteTab('Completion')
     k.clearState()
     k.resetLabel()
     if k.arg:
         w = self.w
         s = w.getAllText()
         ypos = w.getYScrollPosition()
         b = c.undoer.beforeChangeNodeContents(p, oldYScroll=ypos)
         ins = ins1 = w.getInsertPoint()
         if 0 < ins < len(s) and not g.isWordChar(s[ins]): ins1 -= 1
         i, j = g.getWord(s, ins1)
         # word = s[i: j]
         s = s[: i] + k.arg + s[j:]
         w.setAllText(s)
         w.setInsertPoint(i + len(k.arg))
         w.setYScrollPosition(ypos)
         c.undoer.afterChangeNodeContents(p,
             command='dabbrev-expand', bunch=b, dirtyVnodeList=[])
         c.recolor()
Пример #9
0
 def dynamicExpandHelper1(self, event):
     trace = False and not g.unitTesting
     c, k = self.c, self.c.k
     p = c.p
     c.frame.log.deleteTab('Completion')
     k.clearState()
     k.resetLabel()
     if k.arg:
         w = self.w
         s = w.getAllText()
         ypos = w.getYScrollPosition()
         b = c.undoer.beforeChangeNodeContents(p, oldYScroll=ypos)
         ins = ins1 = w.getInsertPoint()
         if 0 < ins < len(s) and not g.isWordChar(s[ins]): ins1 -= 1
         i, j = g.getWord(s, ins1)
         word = s[i: j]
         s = s[: i] + k.arg + s[j:]
         if trace: g.trace('ins', ins, 'k.arg', repr(k.arg), 'word', word)
         w.setAllText(s)
         w.setInsertPoint(i + len(k.arg))
         w.setYScrollPosition(ypos)
         c.undoer.afterChangeNodeContents(p,
             command='dabbrev-expand', bunch=b, dirtyVnodeList=[])
         c.recolor()