docs: def _complete(self):
          """
          Main completion function.
  
          Gets list of potential completion candidates for currently edited word,
          completes it to the longest common part, and shows convenient completion
          widget (if multiple completions are returned) with currently selected
          candidate highlighted.
          """
          def find_word_start(p_text, p_pos):
              """ Returns position of the beginning of a word ending in p_pos. """
              return p_text.lstrip().rfind(' ', 0, p_pos) + 1
  
          def get_word_before_pos(p_text, p_pos):
              start = find_word_start(p_text, p_pos)
  
              return (p_text[start:p_pos], start)
  
          pos = self.edit_pos
          text = self.edit_text
          completer = self.completer
  
          word_before_cursor, start = get_word_before_pos(text, pos)
          completions = completer.get_completions(word_before_cursor, start == 0)
          # store slices before and after place for completion
          self._surrounding_text = (text[:start], text[pos:])
  
          single_completion = len(completions) == 1
          completion_done = single_completion and completions[0] == word_before_cursor
  
          if completion_done or not completions:
              self.completion_mode = False
              return
          elif single_completion:
              replacement = completions[0]
          else:
              replacement = commonprefix(completions)
              zero_candidate = replacement if replacement else word_before_cursor
  
              if zero_candidate != completions[0]:
                  completions.insert(0, zero_candidate)
  
              self.completion_box.add_completions(completions)
  
          self.insert_completion(replacement)
          self.completion_mode = not single_completion