Return the current word (incomplete word left of cursor).
(self)
| 707 | ) |
| 708 | |
| 709 | def cw(self): |
| 710 | """Return the current word (incomplete word left of cursor).""" |
| 711 | if self.edit is None: |
| 712 | return |
| 713 | |
| 714 | pos = self.edit.edit_pos |
| 715 | text = self.edit.get_edit_text() |
| 716 | if pos != len(text): |
| 717 | # Disable autocomplete if not at end of line, like cli does. |
| 718 | return |
| 719 | |
| 720 | # Stolen from cli. TODO: clean up and split out. |
| 721 | if not text or (not text[-1].isalnum() and text[-1] not in (".", "_")): |
| 722 | return |
| 723 | |
| 724 | # Seek backwards in text for the first non-identifier char: |
| 725 | for i, c in enumerate(reversed(text)): |
| 726 | if not c.isalnum() and c not in (".", "_"): |
| 727 | break |
| 728 | else: |
| 729 | # No non-identifiers, return everything. |
| 730 | return text |
| 731 | # Return everything to the right of the non-identifier. |
| 732 | return text[-i:] |
| 733 | |
| 734 | @property |
| 735 | def cpos(self): |