--- a/QScintilla/Editor.py Wed Oct 04 20:06:26 2017 +0200 +++ b/QScintilla/Editor.py Thu Oct 05 19:11:59 2017 +0200 @@ -4661,11 +4661,7 @@ if self.isListActive(): self.cancelList() - self.showUserList( - EditorAutoCompletionListID, - sorted(list(completions), - reverse=Preferences.getEditor( - "AutoCompletionReversedList"))) + self.__showCompletionsList(completions) else: if context is None: context = self.__acContext @@ -4698,11 +4694,36 @@ self.__acCompletions.update(set(completions)) if self.__acCompletions: self.__acCache.add(acText, set(self.__acCompletions)) - self.showUserList( - EditorAutoCompletionListID, - sorted(list(self.__acCompletions), - reverse=Preferences.getEditor( - "AutoCompletionReversedList"))) + self.__showCompletionsList(self.__acCompletions) + + def __showCompletionsList(self, completions): + """ + Private method to show the completions list. + + @param completions completions to be shown + @type list of str or set of str + """ + if Preferences.getEditor("AutoCompletionReversedList"): + acCompletions = sorted( + list(completions), + key=self.__replaceLeadingUnderscores) + else: + acCompletions = sorted(list(completions)) + self.showUserList(EditorAutoCompletionListID, acCompletions) + + def __replaceLeadingUnderscores(self, txt): + """ + Private method to replace the first two underlines for invers sorting. + + @param txt completion text + @type str + @return modified completion text + @rtype str + """ + if txt.startswith('_'): + return txt[:2].replace('_', '~') + txt[2:] + else: + return txt def __clearCompletionsCache(self): """