ProjectKivy/CompleterKivy.py

Tue, 10 Dec 2024 15:48:59 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 10 Dec 2024 15:48:59 +0100
branch
eric7
changeset 70
2c0a54bf5b4c
parent 68
20cdd6e03807
permissions
-rw-r--r--

Updated copyright for 2025.

59
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
70
2c0a54bf5b4c Updated copyright for 2025.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 68
diff changeset
3 # Copyright (c) 2023 - 2025 Detlev Offenbach <detlev@die-offenbachs.de>
59
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the Kivy typing completer.
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import re
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from PyQt6.Qsci import QsciScintilla
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from eric7.QScintilla.TypingCompleters.CompleterBase import CompleterBase
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 class CompleterKivy(CompleterBase):
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Class implementing the Kivy typing completer.
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 def __init__(self, plugin, editor, parent=None):
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 Constructor
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 @param plugin reference to the plugin object
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @type ProjectKivyPlugin
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 @param editor reference to the editor object
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @type Editor
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @param parent reference to the parent object
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @type QObject
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 super().__init__(editor, parent)
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.__plugin = plugin
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 self.__autoIndentationRe = re.compile(r"(?:\(|\[|{|:)(\s*)\r?\n")
64
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
38 self.__trailingBlankRe = re.compile(r"(?:,)(\s*)\r?\n")
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
39 # Trailing blank after ':' is already covered by auto indent rule
59
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.readSettings()
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 def readSettings(self):
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 Public slot called to reread the configuration parameters.
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 self.setEnabled(self.__plugin.getTypingPreferences("EnabledTypingAids"))
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.__insertClosingBrace = self.__plugin.getTypingPreferences(
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 "InsertClosingBrace"
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 )
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 self.__skipBrace = self.__plugin.getTypingPreferences("SkipBrace")
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.__colonDetection = self.__plugin.getTypingPreferences("ColonDetection")
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.__autoIndentation = self.__plugin.getTypingPreferences("AutoIndentation")
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.__insertQuote = self.__plugin.getTypingPreferences("InsertQuote")
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.__insertBlankColon = self.__plugin.getTypingPreferences("InsertBlankColon")
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.__insertBlankComma = self.__plugin.getTypingPreferences("InsertBlankComma")
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 def charAdded(self, charNumber):
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 Public slot called to handle the user entering a character.
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 @param charNumber value of the character entered
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 @type int
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 """
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 char = chr(charNumber)
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 if char not in (
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 "{",
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 "}",
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 "[",
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 "]",
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 "(",
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 ")",
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 "<",
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 ">",
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 "'",
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 '"',
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 ":",
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 ",",
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 "\n",
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 ):
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 return # take the short route
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 line, col = self.editor.getCursorPosition()
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 if self.__inComment(line, col):
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 return
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 # open parenthesis
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 # insert closing parenthesis
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 if char == "(" and self.__insertClosingBrace:
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.editor.insert(")")
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 # open curly bracket
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 # insert closing bracket
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 elif char == "{" and self.__insertClosingBrace:
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 self.editor.insert("}")
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 # open bracket
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 # insert closing bracket
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 elif char == "[" and self.__insertClosingBrace:
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 self.editor.insert("]")
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 # open tag bracket
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 # insert closing bracket
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 elif char == "<" and self.__insertClosingBrace:
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 self.editor.insert(">")
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 # closing parenthesis
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 # skip matching closing parenthesis
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 elif char in (")", "}", "]", ">"):
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 txt = self.editor.text(line)
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 if col < len(txt) and char == txt[col] and self.__skipBrace:
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 self.editor.setSelection(line, col, line, col + 1)
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 self.editor.removeSelectedText()
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 # colon
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 # 1. skip colon if not last character
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 # 2. insert blank if last character
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 elif char == ":":
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 text = self.editor.text(line)
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 if col < len(text) and char == text[col]:
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 if self.__colonDetection:
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 self.editor.setSelection(line, col, line, col + 1)
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 self.editor.removeSelectedText()
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 elif self.__insertBlankColon and col == len(text.rstrip()):
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 self.editor.insert(" ")
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 self.editor.setCursorPosition(line, col + 1)
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 # comma
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 # insert blank
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 elif char == "," and self.__insertBlankComma:
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 self.editor.insert(" ")
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 self.editor.setCursorPosition(line, col + 1)
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 # double quote
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 # insert double quote
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 elif char == '"' and self.__insertQuote:
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 self.editor.insert('"')
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 # quote
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 # insert quote
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 elif char == "'" and self.__insertQuote:
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 self.editor.insert("'")
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 # new line
64
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
146 # indent after line ending with auto indentation character
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
147 elif char == "\n":
59
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 txt = self.editor.text(line - 1)
64
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
149 if self.__autoIndentation and self.__autoIndentationRe.search(txt):
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
150 match = self.__autoIndentationRe.search(txt)
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
151 if match is not None:
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
152 startBlanks = match.start(1)
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
153 endBlanks = match.end(1)
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
154 if startBlanks != -1 and startBlanks != endBlanks:
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
155 # previous line ends with whitespace, e.g. caused by
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
156 # blank insertion above
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
157 self.editor.setSelection(
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
158 line - 1, startBlanks, line - 1, endBlanks
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
159 )
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
160 self.editor.removeSelectedText()
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
161
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
162 self.editor.indent(line)
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
163 self.editor.setCursorPosition(line, 0)
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
164 self.editor.editorCommand(QsciScintilla.SCI_VCHOME)
59
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165
64
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
166 elif (
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
167 self.__insertBlankColon or self.__insertBlankComma
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
168 ) and self.__trailingBlankRe.search(txt):
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
169 # remove blank at end of line inserted by blank insertion above
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
170 match = self.__trailingBlankRe.search(txt)
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
171 if match is not None:
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
172 startBlanks = match.start(1)
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
173 endBlanks = match.end(1)
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
174 if startBlanks != -1 and startBlanks != endBlanks:
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
175 self.editor.setSelection(
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
176 line - 1, startBlanks, line - 1, endBlanks
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
177 )
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
178 self.editor.removeSelectedText()
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
179
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
180 self.editor.setCursorPosition(line, 0)
c3b1bb6fddd6 Slight improvement of the typing completer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 59
diff changeset
181 self.editor.editorCommand(QsciScintilla.SCI_VCHOME)
59
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 def __inComment(self, line, col):
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 """
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 Private method to check, if the cursor is inside a comment.
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 @param line current line
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 @type int
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 @param col current position within line
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 @type int
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 @return flag indicating, if the cursor is inside a comment
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 @rtype bool
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 """
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 txt = self.editor.text(line)
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 if col == len(txt):
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 col -= 1
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 while col >= 0:
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 if txt[col] == "#":
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 return True
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 col -= 1
fb361b396c68 Added a Typing Completer and an associated configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 return False

eric ide

mercurial