AutoCorrect2 integration¶
integration ¶
Manage custom hotstring includes in AutoCorrect2's autocorrection context.
AutoCorrect2IntegrationError ¶
Bases: RuntimeError
Raised when AutoCorrect2's include structure is inconsistent or ambiguous.
Source code in hotstring\autocorrect2\integration.py
37 38 | |
_IncludeState
dataclass
¶
Store validated source state for one custom include.
Attributes:
| Name | Type | Description |
|---|---|---|
source_path |
Path
|
AutoCorrect2 main script being inspected. |
lines |
list[str]
|
Main-script source lines including newline terminators. |
hotif_start |
int
|
Index of the target |
hotif_end |
int
|
Index of the next |
custom_include_index |
int | None
|
Existing custom include line, or |
Source code in hotstring\autocorrect2\integration.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
has_custom_hotstring_include ¶
Return whether a custom file is included in AutoCorrect2's correction context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
custom_file_path
|
str | Path
|
Custom file to look for. A relative path is interpreted relative to the AutoCorrect2 project directory. |
required |
project_dir
|
str | Path
|
AutoCorrect2 project directory. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
|
bool
|
when the include is completely absent. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If AutoCorrect2's main source file does not exist. |
ValueError
|
If the custom path refers to a protected integration source. |
AutoCorrect2IntegrationError
|
If the expected include/context structure is ambiguous. |
OSError
|
If AutoCorrect2's main source file cannot be read. |
Source code in hotstring\autocorrect2\integration.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
add_custom_hotstring_include ¶
Add a custom file to AutoCorrect2's autocorrection context if absent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
custom_file_path
|
str | Path
|
Custom file to include. A relative path is interpreted relative to the AutoCorrect2 project directory. |
required |
project_dir
|
str | Path
|
AutoCorrect2 project directory. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
already correctly present. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If AutoCorrect2's main source file does not exist. |
ValueError
|
If the path is invalid or cannot be represented safely. |
AutoCorrect2IntegrationError
|
If the expected include/context structure is ambiguous. |
OSError
|
If the source file cannot be read or written. |
Source code in hotstring\autocorrect2\integration.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
remove_custom_hotstring_include ¶
Remove a custom file from AutoCorrect2's autocorrection context if present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
custom_file_path
|
str | Path
|
Custom file whose include should be removed. |
required |
project_dir
|
str | Path
|
AutoCorrect2 project directory. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
already absent. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If AutoCorrect2's main source file does not exist. |
ValueError
|
If the custom path refers to a protected integration source. |
AutoCorrect2IntegrationError
|
If the expected include/context structure is ambiguous. |
OSError
|
If the source file cannot be read or written. |
Source code in hotstring\autocorrect2\integration.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
_inspect_include_state ¶
_inspect_include_state(
custom_file_path: Path, project_dir: Path
) -> _IncludeState
Read and validate AutoCorrect2's include state for one custom file.
Source code in hotstring\autocorrect2\integration.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
_find_autocorrection_hotif ¶
Return the start and end indices of the autocorrection #HotIf block.
Source code in hotstring\autocorrect2\integration.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
_find_include_indices ¶
Return line indices whose static include resolves to target_path.
Source code in hotstring\autocorrect2\integration.py
288 289 290 291 292 293 294 295 | |
_parse_include_path ¶
Resolve a static AutoHotkey include directive, if the line contains one.
Source code in hotstring\autocorrect2\integration.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
_resolve_custom_file_path ¶
Resolve a caller-supplied custom path against the AutoCorrect2 project.
Source code in hotstring\autocorrect2\integration.py
320 321 322 323 324 325 326 327 328 | |
_render_include_path ¶
Render a static include path relative to AutoCorrect2's main source file.
Source code in hotstring\autocorrect2\integration.py
331 332 333 334 335 336 337 338 339 340 341 342 | |
_hotif_indentation ¶
_hotif_indentation(state: _IncludeState) -> str
Return the indentation convention used inside the target #HotIf block.
Source code in hotstring\autocorrect2\integration.py
345 346 347 348 349 350 351 | |
_detect_newline ¶
Return the source file's existing newline convention.
Source code in hotstring\autocorrect2\integration.py
354 355 356 357 358 359 360 361 362 363 | |
_same_path ¶
Compare paths using Windows-style case-insensitive semantics.
Source code in hotstring\autocorrect2\integration.py
366 367 368 369 370 | |