eric6/QScintilla/TypingCompleters/CompleterYaml.py

Mon, 12 Oct 2020 19:28:42 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 12 Oct 2020 19:28:42 +0200
changeset 7781
607a6098cb44
parent 7360
9190402e4505
child 7923
91e843545d9a
permissions
-rw-r--r--

Performed some more code cleanup.

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

eric ide

mercurial