codis 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codis-1.1.1.dist-info/METADATA +194 -0
- codis-1.1.1.dist-info/RECORD +329 -0
- codis-1.1.1.dist-info/WHEEL +5 -0
- codis-1.1.1.dist-info/entry_points.txt +5 -0
- codis-1.1.1.dist-info/licenses/LICENSE +21 -0
- codis-1.1.1.dist-info/top_level.txt +2 -0
- run.py +190 -0
- src/__init__.py +1 -0
- src/__main__.py +81 -0
- src/_app_build.py +1507 -0
- src/_app_editor.py +1274 -0
- src/_app_kui.py +825 -0
- src/_app_lsp.py +625 -0
- src/_app_recovery.py +189 -0
- src/_app_settings.py +1385 -0
- src/_app_tools.py +2471 -0
- src/_app_webpreview.py +126 -0
- src/_font_safety.py +127 -0
- src/_shells.py +172 -0
- src/app.py +1488 -0
- src/chat/__init__.py +1 -0
- src/chat/adapters/__init__.py +33 -0
- src/chat/adapters/base.py +209 -0
- src/chat/adapters/discord.py +190 -0
- src/chat/adapters/http.py +78 -0
- src/chat/adapters/irc.py +360 -0
- src/chat/adapters/matrix.py +219 -0
- src/chat/adapters/mattermost.py +178 -0
- src/chat/adapters/mqtt.py +165 -0
- src/chat/adapters/slack.py +204 -0
- src/chat/adapters/telegram.py +117 -0
- src/chat/adapters/ws.py +154 -0
- src/chat/adapters/xmpp.py +337 -0
- src/chat/history.py +76 -0
- src/chat/models.py +207 -0
- src/chat/probe.py +79 -0
- src/chat/session.py +446 -0
- src/chat/util.py +125 -0
- src/collab/__init__.py +1 -0
- src/collab/net.py +411 -0
- src/collab/ot.py +311 -0
- src/collab/session.py +141 -0
- src/collab/tk_adapter.py +134 -0
- src/config.py +335 -0
- src/constants.py +2552 -0
- src/dep_catalog.py +446 -0
- src/diff/__init__.py +1 -0
- src/diff/engine.py +247 -0
- src/dpi.py +30 -0
- src/editor/__init__.py +1 -0
- src/editor/_pane_lsp.py +2937 -0
- src/editor/_pane_utils.py +171 -0
- src/editor/autocomplete.py +607 -0
- src/editor/code_folding.py +836 -0
- src/editor/color_preview.py +382 -0
- src/editor/complexity_lens.py +281 -0
- src/editor/diff_pane.py +623 -0
- src/editor/file_watcher.py +144 -0
- src/editor/focus_block.py +236 -0
- src/editor/heatmap.py +141 -0
- src/editor/inlay_hints.py +366 -0
- src/editor/inline_blame.py +429 -0
- src/editor/kdocs.py +3376 -0
- src/editor/large_file.py +488 -0
- src/editor/ligatures.py +180 -0
- src/editor/line_numbers.py +598 -0
- src/editor/minimap.py +691 -0
- src/editor/multi_cursor.py +269 -0
- src/editor/pane.py +2082 -0
- src/editor/rhythm.py +206 -0
- src/editor/save_hooks.py +43 -0
- src/editor/smart_selection.py +425 -0
- src/editor/smart_tips.py +719 -0
- src/editor/snippets.py +411 -0
- src/editor/sticky_note_gutter.py +410 -0
- src/editor/sticky_scroll.py +385 -0
- src/editor/suggest.py +464 -0
- src/editor/text_transforms.py +310 -0
- src/editor/vim_mode.py +1074 -0
- src/events/__init__.py +84 -0
- src/events/bus.py +427 -0
- src/events/correlator.py +244 -0
- src/events/kinds.py +125 -0
- src/events/pipeline.py +264 -0
- src/events/stream.py +416 -0
- src/events/window.py +204 -0
- src/extcompat/__init__.py +19 -0
- src/extcompat/code/__init__.py +13 -0
- src/extcompat/code/consent.py +162 -0
- src/extcompat/code/host.py +353 -0
- src/extcompat/code/hosts/py_host.py +763 -0
- src/extcompat/code/locate.py +105 -0
- src/extcompat/code/manager.py +325 -0
- src/extcompat/code/permissions.py +154 -0
- src/extcompat/code/sandbox.py +60 -0
- src/extcompat/colors.py +131 -0
- src/extcompat/common.py +184 -0
- src/extcompat/cson.py +269 -0
- src/extcompat/formats/__init__.py +22 -0
- src/extcompat/formats/_tm.py +189 -0
- src/extcompat/formats/_util.py +31 -0
- src/extcompat/formats/base16.py +66 -0
- src/extcompat/formats/brackets.py +172 -0
- src/extcompat/formats/eclipse.py +193 -0
- src/extcompat/formats/emacs.py +361 -0
- src/extcompat/formats/geany.py +147 -0
- src/extcompat/formats/generic.py +184 -0
- src/extcompat/formats/gtksource.py +117 -0
- src/extcompat/formats/helix.py +91 -0
- src/extcompat/formats/jetbrains.py +343 -0
- src/extcompat/formats/kate.py +130 -0
- src/extcompat/formats/micro.py +131 -0
- src/extcompat/formats/nano.py +111 -0
- src/extcompat/formats/notepadpp.py +140 -0
- src/extcompat/formats/pulsar.py +165 -0
- src/extcompat/formats/pyides.py +163 -0
- src/extcompat/formats/sublime.py +340 -0
- src/extcompat/jsonc.py +65 -0
- src/extcompat/lessish.py +128 -0
- src/extcompat/manager.py +122 -0
- src/extcompat/market/__init__.py +63 -0
- src/extcompat/market/sources.py +211 -0
- src/extcompat/model.py +88 -0
- src/extcompat/net.py +228 -0
- src/extcompat/openvsx.py +63 -0
- src/extcompat/readers.py +362 -0
- src/extcompat/registry.py +73 -0
- src/extcompat/safexml.py +63 -0
- src/extcompat/sexp.py +187 -0
- src/extcompat/sources.py +105 -0
- src/extcompat/store.py +276 -0
- src/extcompat/textmate.py +214 -0
- src/extcompat/themes.py +487 -0
- src/extcompat/yamlite.py +294 -0
- src/fileio.py +94 -0
- src/fs_ops.py +106 -0
- src/i18n.py +233 -0
- src/ia/__init__.py +1 -0
- src/ia/actions.py +295 -0
- src/ia/approval_gate.py +672 -0
- src/ia/checkpoints.py +308 -0
- src/ia/context_builder.py +921 -0
- src/ia/dialdiff.py +408 -0
- src/ia/iaspace.py +2078 -0
- src/ia/pair.py +296 -0
- src/ia/providers.py +954 -0
- src/ia/session.py +335 -0
- src/ia/toolbox.py +2524 -0
- src/launcher_actions.py +204 -0
- src/lint/__init__.py +1 -0
- src/lint/manager.py +1058 -0
- src/locales/.translate_manifest.json +64170 -0
- src/locales/de.json +4936 -0
- src/locales/en.json +4936 -0
- src/locales/es.json +4936 -0
- src/locales/fr.json +4936 -0
- src/locales/it.json +4936 -0
- src/locales/ja.json +4936 -0
- src/locales/ko.json +4936 -0
- src/locales/nl.json +4936 -0
- src/locales/pl.json +4936 -0
- src/locales/pt-BR.json +4936 -0
- src/locales/ru.json +4936 -0
- src/locales/tr.json +4936 -0
- src/locales/uk.json +4936 -0
- src/locales/zh-CN.json +4936 -0
- src/lsp/__init__.py +26 -0
- src/lsp/client.py +2300 -0
- src/lsp/dap_client.py +480 -0
- src/lsp/edits.py +84 -0
- src/lsp/framing.py +73 -0
- src/lsp/protocol.py +931 -0
- src/main.py +260 -0
- src/memtrim.py +91 -0
- src/plugins/__init__.py +1 -0
- src/plugins/api.py +1761 -0
- src/plugins/loader.py +571 -0
- src/plugins/process_runner.py +519 -0
- src/plugins/registry.py +342 -0
- src/plugins/safety.py +367 -0
- src/plugins/startup.py +195 -0
- src/plugins/store.py +1178 -0
- src/proc_registry.py +278 -0
- src/pyexec.py +394 -0
- src/recovery.py +259 -0
- src/stall_trace.py +92 -0
- src/standalone.py +1070 -0
- src/startup_profile.py +35 -0
- src/syntax/__init__.py +1 -0
- src/syntax/highlighter.py +776 -0
- src/syntax/patterns.py +584 -0
- src/system_profile.py +430 -0
- src/terminal/backends.py +658 -0
- src/terminal/internal.py +346 -0
- src/terminal/keys.py +138 -0
- src/terminal/palette.py +67 -0
- src/terminal/session.py +283 -0
- src/terminal/shells.py +79 -0
- src/terminal/view.py +489 -0
- src/terminal/vt.py +870 -0
- src/textfmt.py +22 -0
- src/theme/__init__.py +1 -0
- src/theme/base.py +1281 -0
- src/theme/colors.py +49 -0
- src/theme/manager.py +602 -0
- src/theme/utils.py +312 -0
- src/toolbox.py +329 -0
- src/trash_core.py +531 -0
- src/ui/__init__.py +1 -0
- src/ui/_perf_utils.py +285 -0
- src/ui/_persistence_utils.py +93 -0
- src/ui/accessibility.py +843 -0
- src/ui/activity_bar.py +860 -0
- src/ui/app_embed.py +434 -0
- src/ui/archive_panel.py +608 -0
- src/ui/bookmarks.py +314 -0
- src/ui/breadcrumb.py +383 -0
- src/ui/calculator_panel.py +982 -0
- src/ui/calendar_panel.py +1218 -0
- src/ui/chat_panel.py +1271 -0
- src/ui/chat_profile_dialog.py +278 -0
- src/ui/chat_render.py +128 -0
- src/ui/clock_panel.py +810 -0
- src/ui/code_outline.py +364 -0
- src/ui/code_runner.py +729 -0
- src/ui/code_stats.py +546 -0
- src/ui/collab_panel.py +1009 -0
- src/ui/color_picker.py +547 -0
- src/ui/command_palette.py +452 -0
- src/ui/cursor_manager.py +750 -0
- src/ui/custom_keywords_panel.py +413 -0
- src/ui/debug_panel.py +1037 -0
- src/ui/dependency_graph.py +692 -0
- src/ui/diff_panel.py +381 -0
- src/ui/docs_panel.py +514 -0
- src/ui/doom_embed.py +349 -0
- src/ui/dropdown.py +321 -0
- src/ui/easter_eggs.py +979 -0
- src/ui/env_manager.py +666 -0
- src/ui/extcode_bridge.py +215 -0
- src/ui/extcode_dialogs.py +412 -0
- src/ui/extcompat_dialog.py +583 -0
- src/ui/file_timeline.py +319 -0
- src/ui/file_tree.py +1208 -0
- src/ui/find_in_files.py +1355 -0
- src/ui/flowchart_panel.py +727 -0
- src/ui/formatter_panel.py +490 -0
- src/ui/git_auth.py +763 -0
- src/ui/git_clone_dialog.py +487 -0
- src/ui/git_panel.py +1483 -0
- src/ui/grab_safe.py +84 -0
- src/ui/internal_python_dialog.py +98 -0
- src/ui/k_ui/__init__.py +1305 -0
- src/ui/k_ui/_bgrenderer.py +317 -0
- src/ui/k_ui/_colors.py +213 -0
- src/ui/k_ui/_dock.py +545 -0
- src/ui/k_ui/_easter.py +290 -0
- src/ui/k_ui/_engine.py +5448 -0
- src/ui/k_ui/_perf.py +333 -0
- src/ui/k_ui/_tkutil.py +7 -0
- src/ui/k_ui/_tooltip.py +365 -0
- src/ui/k_ui/_widgets.py +1204 -0
- src/ui/k_ui/_world.py +837 -0
- src/ui/key_remapper.py +856 -0
- src/ui/launcher.py +1252 -0
- src/ui/lazy_panel.py +73 -0
- src/ui/macro_recorder.py +610 -0
- src/ui/menu_bar.py +898 -0
- src/ui/output_panel.py +321 -0
- src/ui/paint_canvas.py +1000 -0
- src/ui/paint_engine.py +535 -0
- src/ui/paint_panel.py +888 -0
- src/ui/panel_detach.py +112 -0
- src/ui/performance_panel.py +861 -0
- src/ui/pip_manager.py +1758 -0
- src/ui/plugin_panel.py +1586 -0
- src/ui/pomodoro_panel.py +447 -0
- src/ui/problems.py +566 -0
- src/ui/process_manager.py +1657 -0
- src/ui/project_templates.py +775 -0
- src/ui/recovery_dialog.py +122 -0
- src/ui/regex_playground.py +304 -0
- src/ui/remote_adapters.py +1398 -0
- src/ui/remote_browser.py +1224 -0
- src/ui/remote_profile_dialog.py +342 -0
- src/ui/render_panel.py +1293 -0
- src/ui/rest_client.py +549 -0
- src/ui/scratchpad.py +548 -0
- src/ui/search_bar.py +1274 -0
- src/ui/settings_editor.py +3349 -0
- src/ui/settings_window.py +1554 -0
- src/ui/snippets_panel.py +597 -0
- src/ui/sql_studio.py +1815 -0
- src/ui/status_bar.py +438 -0
- src/ui/tab_bar.py +654 -0
- src/ui/task_manager.py +1773 -0
- src/ui/terminal.py +525 -0
- src/ui/theme_preview_panel.py +851 -0
- src/ui/thread_safe_tk.py +152 -0
- src/ui/time_tracker.py +574 -0
- src/ui/tkbind.py +43 -0
- src/ui/todo_panel.py +358 -0
- src/ui/toolbox_panels.py +658 -0
- src/ui/trash_manager.py +657 -0
- src/ui/ui_scale.py +294 -0
- src/ui/ux_enhancements.py +41 -0
- src/ui/web_preview.py +397 -0
- src/ui/webdev.py +630 -0
- src/ui/welcome.py +567 -0
- src/ui/window_embed.py +1500 -0
- src/ui/wizard.py +1550 -0
- src/ui/workspace_switcher.py +418 -0
- src/ui/workspace_trust.py +370 -0
- src/ui/zen_audio.py +354 -0
- src/ui/zen_media.py +2271 -0
- src/ui/zen_media_client.py +303 -0
- src/ui/zen_media_host.py +329 -0
- src/ui/zen_player.py +907 -0
- src/ui/zen_player_widgets.py +700 -0
- src/updater/__init__.py +11 -0
- src/updater/assets.py +145 -0
- src/updater/backup.py +101 -0
- src/updater/channel.py +221 -0
- src/updater/dialog.py +492 -0
- src/updater/integrity.py +111 -0
- src/updater/manager.py +727 -0
- src/updater/result.py +114 -0
- src/venv_runtime.py +531 -0
- src/workspace_state.py +25 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
"""Emacs: temas (``deftheme``), snippets do yasnippet e modos simples. O Elisp só é lido, nunca avaliado."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from .. import colors as col
|
|
10
|
+
from .. import registry, sexp
|
|
11
|
+
from ..common import decode, mode_lang, simple_tokens, title_of
|
|
12
|
+
from ..model import Extension, LanguageSpec, SnippetSpec, ThemeSpec
|
|
13
|
+
from ..registry import Format
|
|
14
|
+
from ..sexp import Sym, head, unquote
|
|
15
|
+
from ..sources import Bundle
|
|
16
|
+
from ..themes import assemble, slug
|
|
17
|
+
|
|
18
|
+
_MAX_FILES = 600
|
|
19
|
+
_YAS_HEADER = re.compile(r"^#\s*([\w-]+)\s*:\s*(.*)$")
|
|
20
|
+
_GRAY = re.compile(r"^gr[ae]y(\d{1,3})$")
|
|
21
|
+
|
|
22
|
+
# Face do Emacs -> (campo do Codis, atributo).
|
|
23
|
+
_FACES: dict[str, tuple[str, str]] = {
|
|
24
|
+
"font-lock-keyword-face": ("t_keyword", ":foreground"),
|
|
25
|
+
"font-lock-string-face": ("t_string", ":foreground"),
|
|
26
|
+
"font-lock-comment-face": ("t_comment", ":foreground"),
|
|
27
|
+
"font-lock-function-name-face": ("t_func", ":foreground"),
|
|
28
|
+
"font-lock-type-face": ("t_type", ":foreground"),
|
|
29
|
+
"font-lock-constant-face": ("t_constant", ":foreground"),
|
|
30
|
+
"font-lock-builtin-face": ("t_builtin", ":foreground"),
|
|
31
|
+
"font-lock-variable-name-face": ("t_variable", ":foreground"),
|
|
32
|
+
"font-lock-preprocessor-face": ("t_decorator", ":foreground"),
|
|
33
|
+
"font-lock-number-face": ("t_number", ":foreground"),
|
|
34
|
+
"font-lock-operator-face": ("t_operator", ":foreground"),
|
|
35
|
+
"font-lock-regexp-grouping-construct": ("t_regex", ":foreground"),
|
|
36
|
+
"font-lock-escape-face": ("t_escape", ":foreground"),
|
|
37
|
+
"font-lock-property-name-face": ("t_attr", ":foreground"),
|
|
38
|
+
"link": ("t_link", ":foreground"),
|
|
39
|
+
"region": ("sel_bg", ":background"),
|
|
40
|
+
"cursor": ("cursor", ":background"),
|
|
41
|
+
"hl-line": ("line_hl", ":background"),
|
|
42
|
+
"line-number": ("gutter_fg", ":foreground"),
|
|
43
|
+
"line-number-current-line": ("gutter_active_fg", ":foreground"),
|
|
44
|
+
"mode-line": ("statusbar_bg", ":background"),
|
|
45
|
+
"minibuffer-prompt": ("accent", ":foreground"),
|
|
46
|
+
"error": ("err_fg", ":foreground"),
|
|
47
|
+
"warning": ("warn_fg", ":foreground"),
|
|
48
|
+
"success": ("ok_fg", ":foreground"),
|
|
49
|
+
"shadow": ("fg_muted", ":foreground"),
|
|
50
|
+
"vertical-border": ("border", ":foreground"),
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _is_emacs(root: Path) -> bool:
|
|
55
|
+
bundle = Bundle(root)
|
|
56
|
+
if any(n.lower().endswith(".el") for n in bundle.names()):
|
|
57
|
+
return True
|
|
58
|
+
return any(n.lower().startswith("snippets/") and n.lower().endswith(".yasnippet") for n in bundle.names())
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
# --- cores e faces ----------------------------------------------------------------------
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _named_color(name: str) -> str | None:
|
|
65
|
+
gray = _GRAY.match(name.lower())
|
|
66
|
+
if gray:
|
|
67
|
+
level = round(int(gray.group(1)) * 2.55)
|
|
68
|
+
return col.to_hex(level, level, level)
|
|
69
|
+
return col.normalize(name.replace(" ", ""))
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _bindings(forms: list[Any]) -> dict[str, Any]:
|
|
73
|
+
"""Valores literais de ``let``, ``defvar``, ``defconst`` e ``setq``: strings e listas simples."""
|
|
74
|
+
env: dict[str, Any] = {}
|
|
75
|
+
|
|
76
|
+
def literal(node: Any) -> Any:
|
|
77
|
+
node = unquote(node)
|
|
78
|
+
return node if isinstance(node, (str, list)) and not isinstance(node, Sym) else None
|
|
79
|
+
|
|
80
|
+
for node in (n for form in forms for n in sexp.walk(form)):
|
|
81
|
+
h = head(node)
|
|
82
|
+
if h in ("let", "let*") and len(node) > 1 and isinstance(node[1], list):
|
|
83
|
+
for pair in node[1]:
|
|
84
|
+
if isinstance(pair, list) and len(pair) == 2 and isinstance(pair[0], Sym) and literal(pair[1]) is not None:
|
|
85
|
+
env[str(pair[0])] = literal(pair[1])
|
|
86
|
+
elif h in ("defvar", "defconst", "defcustom") and len(node) > 2 and isinstance(node[1], Sym):
|
|
87
|
+
if literal(node[2]) is not None:
|
|
88
|
+
env[str(node[1])] = literal(node[2])
|
|
89
|
+
elif h == "setq":
|
|
90
|
+
for key, value in zip(node[1::2], node[2::2], strict=False):
|
|
91
|
+
if isinstance(key, Sym) and literal(value) is not None:
|
|
92
|
+
env[str(key)] = literal(value)
|
|
93
|
+
return env
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _value(node: Any, env: dict[str, Any]) -> Any:
|
|
97
|
+
if isinstance(node, list) and len(node) == 2 and node[0] in (sexp.COMMA, sexp.COMMA_AT):
|
|
98
|
+
node = node[1]
|
|
99
|
+
return env.get(str(node)) if isinstance(node, Sym) else None
|
|
100
|
+
if isinstance(node, Sym):
|
|
101
|
+
return env.get(str(node), str(node))
|
|
102
|
+
return node
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _display_ok(display: Any, dark: bool, env: dict[str, Any]) -> bool:
|
|
106
|
+
"""Se a condição de exibição de um rosto vale para uma tela gráfica colorida do fundo dado."""
|
|
107
|
+
if isinstance(display, list) and head(display) == ",":
|
|
108
|
+
display = _value(display, env)
|
|
109
|
+
if not isinstance(display, list):
|
|
110
|
+
return True # ``t`` ou uma variável que não conseguimos resolver
|
|
111
|
+
if display and isinstance(display[0], list) and display[0] and isinstance(display[0][0], list):
|
|
112
|
+
return any(_display_ok(alt, dark, env) for alt in display)
|
|
113
|
+
for cond in display:
|
|
114
|
+
if not (isinstance(cond, list) and cond and isinstance(cond[0], Sym)):
|
|
115
|
+
continue
|
|
116
|
+
key, values = str(cond[0]), {str(v) for v in cond[1:]}
|
|
117
|
+
if key == "class" and "color" not in values:
|
|
118
|
+
return False
|
|
119
|
+
if key == "background" and ("dark" if dark else "light") not in values:
|
|
120
|
+
return False
|
|
121
|
+
if key == "type" and values <= {"tty"}:
|
|
122
|
+
return False
|
|
123
|
+
return True
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _face_attrs(spec_list: Any, dark: bool, env: dict[str, Any]) -> dict[str, Any]:
|
|
127
|
+
"""Atributos da primeira especificação do rosto que vale para o fundo escuro ou claro."""
|
|
128
|
+
specs = spec_list if isinstance(spec_list, list) else []
|
|
129
|
+
for spec in specs:
|
|
130
|
+
if not isinstance(spec, list) or len(spec) < 2:
|
|
131
|
+
continue
|
|
132
|
+
if not _display_ok(spec[0], dark, env):
|
|
133
|
+
continue
|
|
134
|
+
attrs = spec[1] if isinstance(spec[1], list) else spec[1:]
|
|
135
|
+
pl = sexp.plist([_value(a, env) if not isinstance(a, Sym) else a for a in attrs])
|
|
136
|
+
if pl:
|
|
137
|
+
return pl
|
|
138
|
+
return {}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _color_of(value: Any) -> str | None:
|
|
142
|
+
if isinstance(value, str):
|
|
143
|
+
return _named_color(value)
|
|
144
|
+
return None
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def from_emacs_theme(text: str, *, theme_id: str, fallback: str) -> ThemeSpec | None:
|
|
148
|
+
forms = sexp.parse_all(text)
|
|
149
|
+
env = _bindings(forms)
|
|
150
|
+
name = fallback
|
|
151
|
+
for node in forms:
|
|
152
|
+
if head(node) == "deftheme" and len(node) > 1:
|
|
153
|
+
name = str(node[1])
|
|
154
|
+
faces: dict[str, Any] = {}
|
|
155
|
+
for node in (n for form in forms for n in sexp.walk(form)):
|
|
156
|
+
if head(node) != "custom-theme-set-faces":
|
|
157
|
+
continue
|
|
158
|
+
for entry in node[2:]:
|
|
159
|
+
entry = unquote(entry)
|
|
160
|
+
if not (isinstance(entry, list) and entry):
|
|
161
|
+
continue
|
|
162
|
+
# Uma definição ``(rosto especificações)``, ou uma lista delas quando vem toda entre aspas.
|
|
163
|
+
for item in [entry] if isinstance(entry[0], Sym) else entry:
|
|
164
|
+
if isinstance(item, list) and len(item) >= 2 and isinstance(item[0], Sym):
|
|
165
|
+
faces[str(item[0])] = item[1]
|
|
166
|
+
if not faces:
|
|
167
|
+
return None
|
|
168
|
+
dark_hint = None
|
|
169
|
+
if "frame-background-mode" in {str(k) for k in env} or any(
|
|
170
|
+
head(n) == "setq" and "frame-background-mode" in [str(x) for x in n] for form in forms for n in sexp.walk(form)
|
|
171
|
+
):
|
|
172
|
+
dark_hint = "dark" in text.split("frame-background-mode", 1)[1][:30]
|
|
173
|
+
default_bg = _color_of(_face_attrs(faces.get("default"), True, env).get(":background")) or _color_of(
|
|
174
|
+
_face_attrs(faces.get("default"), False, env).get(":background")
|
|
175
|
+
)
|
|
176
|
+
dark = dark_hint if dark_hint is not None else (col.is_dark(default_bg) if default_bg else "light" not in name.lower())
|
|
177
|
+
|
|
178
|
+
def attrs_of(face: str, depth: int = 0) -> dict[str, Any]:
|
|
179
|
+
attrs = _face_attrs(faces.get(face), dark, env)
|
|
180
|
+
parent = attrs.get(":inherit")
|
|
181
|
+
if depth < 4 and isinstance(parent, str) and parent != face and (":foreground" not in attrs or ":background" not in attrs):
|
|
182
|
+
return {**attrs_of(parent, depth + 1), **attrs}
|
|
183
|
+
return attrs
|
|
184
|
+
|
|
185
|
+
fields: dict[str, str | None] = {}
|
|
186
|
+
base = attrs_of("default")
|
|
187
|
+
fields["fg"], fields["bg"], fields["editor_bg"] = (
|
|
188
|
+
_color_of(base.get(":foreground")), _color_of(base.get(":background")), _color_of(base.get(":background")),
|
|
189
|
+
)
|
|
190
|
+
for face, (target, attr) in _FACES.items():
|
|
191
|
+
if face in faces:
|
|
192
|
+
fields[target] = _color_of(attrs_of(face).get(attr))
|
|
193
|
+
if face_fg := attrs_of("mode-line").get(":foreground"):
|
|
194
|
+
fields["statusbar_fg"] = _color_of(face_fg)
|
|
195
|
+
if not (fields["bg"] or fields["fg"]):
|
|
196
|
+
return None
|
|
197
|
+
return assemble(theme_id, title_of(name), fields, dark)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
# --- snippets do yasnippet ----------------------------------------------------------------
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def _convert_yas_body(body: str) -> str | None:
|
|
204
|
+
"""Corpo do yasnippet em sintaxe TextMate; ``None`` se depender de Elisp que não executamos."""
|
|
205
|
+
if re.search(r"`[^`]*`", body):
|
|
206
|
+
body = re.sub(r"`[^`]*`", "", body) # expressões Elisp entre crases são descartadas
|
|
207
|
+
body = re.sub(r"\$\{(\d+):\$\(.*?\)\}", r"$\1", body, flags=re.DOTALL)
|
|
208
|
+
if "$(" in body:
|
|
209
|
+
return None
|
|
210
|
+
return body
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def parse_yasnippet(text: str, lang: str, key_default: str) -> SnippetSpec | None:
|
|
214
|
+
lines = text.replace("\r\n", "\n").split("\n")
|
|
215
|
+
meta: dict[str, str] = {}
|
|
216
|
+
body_start = 0
|
|
217
|
+
if any(line.strip() == "# --" for line in lines):
|
|
218
|
+
for i, line in enumerate(lines):
|
|
219
|
+
if line.strip() == "# --":
|
|
220
|
+
body_start = i + 1
|
|
221
|
+
break
|
|
222
|
+
m = _YAS_HEADER.match(line)
|
|
223
|
+
if m:
|
|
224
|
+
meta[m.group(1).lower()] = m.group(2).strip()
|
|
225
|
+
body = "\n".join(lines[body_start:]).rstrip("\n")
|
|
226
|
+
converted = _convert_yas_body(body)
|
|
227
|
+
key = meta.get("key") or key_default
|
|
228
|
+
if not (converted and key):
|
|
229
|
+
return None
|
|
230
|
+
return SnippetSpec(lang, key, converted, meta.get("name") or key)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def _define_snippets(forms: list[Any]) -> list[SnippetSpec]:
|
|
234
|
+
out: list[SnippetSpec] = []
|
|
235
|
+
for node in (n for form in forms for n in sexp.walk(form)):
|
|
236
|
+
if head(node) != "yas-define-snippets" or len(node) < 3:
|
|
237
|
+
continue
|
|
238
|
+
mode = unquote(node[1])
|
|
239
|
+
entries = unquote(node[2])
|
|
240
|
+
if not isinstance(mode, Sym) or not isinstance(entries, list):
|
|
241
|
+
continue
|
|
242
|
+
lang = mode_lang(str(mode))
|
|
243
|
+
for entry in entries:
|
|
244
|
+
if isinstance(entry, list) and len(entry) >= 2 and isinstance(entry[0], str) and isinstance(entry[1], str):
|
|
245
|
+
body = _convert_yas_body(entry[1])
|
|
246
|
+
if body:
|
|
247
|
+
out.append(SnippetSpec(lang, entry[0], body, str(entry[2]) if len(entry) > 2 and isinstance(entry[2], str) else entry[0]))
|
|
248
|
+
return out
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
# --- modos --------------------------------------------------------------------------------
|
|
252
|
+
|
|
253
|
+
_AUTO_MODE = re.compile(r"^\\\.([\w+-]+)\\'$")
|
|
254
|
+
_AUTO_MODE_GROUP = re.compile(r"^\\\.\\\(([\w+|\\-]+)\\\)\\'$")
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def _extensions_of(pattern: str) -> list[str]:
|
|
258
|
+
m = _AUTO_MODE.match(pattern)
|
|
259
|
+
if m:
|
|
260
|
+
return [f".{m.group(1).lower()}"]
|
|
261
|
+
m = _AUTO_MODE_GROUP.match(pattern)
|
|
262
|
+
if m:
|
|
263
|
+
return [f".{e.lower()}" for e in m.group(1).replace("\\|", "|").split("|") if e]
|
|
264
|
+
return []
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def _modes(forms: list[Any], known: set[str]) -> list[LanguageSpec]:
|
|
268
|
+
"""Modos principais que registram extensões em ``auto-mode-alist`` e listam palavras-chave."""
|
|
269
|
+
exts_by_mode: dict[str, list[str]] = {}
|
|
270
|
+
for node in (n for form in forms for n in sexp.walk(form)):
|
|
271
|
+
h = head(node)
|
|
272
|
+
candidates: list[Any] = []
|
|
273
|
+
if h == "add-to-list" and len(node) >= 3 and unquote(node[1]) == Sym("auto-mode-alist"):
|
|
274
|
+
candidates = [unquote(node[2])]
|
|
275
|
+
elif h == "setq" and len(node) >= 3 and node[1] == Sym("auto-mode-alist"):
|
|
276
|
+
candidates = [c for c in sexp.walk(node) if isinstance(c, list) and len(c) == 3 and c[1] == Sym(".")]
|
|
277
|
+
for cand in candidates:
|
|
278
|
+
if isinstance(cand, list) and head(cand) == "cons" and len(cand) == 3:
|
|
279
|
+
cand = [cand[1], Sym("."), unquote(cand[2])]
|
|
280
|
+
if isinstance(cand, list) and len(cand) == 3 and isinstance(cand[0], str) and isinstance(cand[2], Sym):
|
|
281
|
+
exts = _extensions_of(cand[0])
|
|
282
|
+
if exts:
|
|
283
|
+
exts_by_mode.setdefault(str(cand[2]), []).extend(exts)
|
|
284
|
+
words: list[str] = []
|
|
285
|
+
for node in (n for form in forms for n in sexp.walk(form)):
|
|
286
|
+
if head(node) in ("defconst", "defvar", "defcustom") and len(node) > 2 and isinstance(node[1], Sym) and "keywords" in node[1]:
|
|
287
|
+
lst = unquote(node[2])
|
|
288
|
+
if isinstance(lst, list):
|
|
289
|
+
words.extend(w for w in lst if isinstance(w, str))
|
|
290
|
+
comment = None
|
|
291
|
+
for node in (n for form in forms for n in sexp.walk(form)):
|
|
292
|
+
if head(node) in ("setq", "setq-local") and len(node) >= 3 and node[1] == Sym("comment-start") and isinstance(node[2], str):
|
|
293
|
+
comment = node[2].strip()
|
|
294
|
+
out: list[LanguageSpec] = []
|
|
295
|
+
for mode, exts in exts_by_mode.items():
|
|
296
|
+
lid = mode_lang(mode)
|
|
297
|
+
if lid in known:
|
|
298
|
+
continue
|
|
299
|
+
tokens, kw = simple_tokens(line_comment=comment, keywords=words)
|
|
300
|
+
out.append(LanguageSpec(id=lid, label=title_of(lid), extensions=sorted(set(exts)), comment=comment, patterns=tokens, keywords=kw))
|
|
301
|
+
return out
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def load_emacs(root: Path, known: set[str]) -> Extension:
|
|
305
|
+
bundle = Bundle(root)
|
|
306
|
+
pkg_name, pkg_version, pkg_desc = root.name, "0", ""
|
|
307
|
+
for rel in bundle.glob("*-pkg.el")[:1]:
|
|
308
|
+
for node in sexp.parse_all(bundle.text(rel) or ""):
|
|
309
|
+
if head(node) == "define-package" and len(node) > 2:
|
|
310
|
+
pkg_name, pkg_version = str(node[1]), str(node[2])
|
|
311
|
+
pkg_desc = str(node[3]) if len(node) > 3 and isinstance(node[3], str) else ""
|
|
312
|
+
ext = Extension(
|
|
313
|
+
id=f"emacs.{slug(pkg_name)}", name=pkg_name, version=pkg_version, kind="emacs", path=root, description=pkg_desc
|
|
314
|
+
)
|
|
315
|
+
code_files = 0
|
|
316
|
+
all_forms: list[Any] = []
|
|
317
|
+
for rel in bundle.with_suffix(".el")[:_MAX_FILES]:
|
|
318
|
+
text = bundle.text(rel)
|
|
319
|
+
if text is None:
|
|
320
|
+
continue
|
|
321
|
+
stem = Path(rel).name[:-3]
|
|
322
|
+
if rel.endswith("-pkg.el"):
|
|
323
|
+
continue
|
|
324
|
+
try:
|
|
325
|
+
forms = sexp.parse_all(text)
|
|
326
|
+
except ValueError as exc:
|
|
327
|
+
ext.warnings.append(f"{Path(rel).name}: não foi possível ler ({exc})")
|
|
328
|
+
continue
|
|
329
|
+
code_files += 1
|
|
330
|
+
if any(head(f) == "deftheme" for f in forms):
|
|
331
|
+
theme_id = f"emacs_{slug(stem.removesuffix('-theme'))}"
|
|
332
|
+
spec = from_emacs_theme(text, theme_id=theme_id, fallback=stem.removesuffix("-theme"))
|
|
333
|
+
if spec:
|
|
334
|
+
ext.themes.append(spec)
|
|
335
|
+
else:
|
|
336
|
+
ext.warnings.append(f"{Path(rel).name}: tema montado por macros ou paletas; nenhuma cor literal encontrada")
|
|
337
|
+
else:
|
|
338
|
+
ext.snippets.extend(_define_snippets(forms))
|
|
339
|
+
all_forms.extend(forms)
|
|
340
|
+
ext.languages.extend(_modes(all_forms, known))
|
|
341
|
+
|
|
342
|
+
for rel in bundle.names():
|
|
343
|
+
parts = rel.split("/")
|
|
344
|
+
if len(parts) >= 3 and parts[0] == "snippets" and not parts[-1].startswith(".") and not parts[-1].endswith((".el", "~")):
|
|
345
|
+
raw = bundle.read(rel)
|
|
346
|
+
if raw:
|
|
347
|
+
spec = parse_yasnippet(decode(raw), mode_lang(parts[1]), parts[-1].split(".")[0])
|
|
348
|
+
if spec:
|
|
349
|
+
ext.snippets.append(spec)
|
|
350
|
+
if code_files and not ext.themes and not ext.languages:
|
|
351
|
+
ext.ignored.append("código Elisp do pacote (não é executado)")
|
|
352
|
+
elif code_files:
|
|
353
|
+
ext.ignored.append("o restante do código Elisp (não é executado)")
|
|
354
|
+
return ext
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
registry.register(Format(
|
|
358
|
+
"emacs", "Emacs", _is_emacs, load_emacs, priority=41,
|
|
359
|
+
suffixes=(".el", ".tar"),
|
|
360
|
+
provides="temas, snippets do yasnippet e modos simples",
|
|
361
|
+
))
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"""Geany: esquemas de cores (``colorschemes/*.conf``) e definições de tipos de arquivo (``filetypes.*``)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import configparser
|
|
6
|
+
import re
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from .. import colors as col
|
|
10
|
+
from .. import registry
|
|
11
|
+
from ..common import decode, simple_tokens, title_of
|
|
12
|
+
from ..model import Extension, LanguageSpec, ThemeSpec
|
|
13
|
+
from ..registry import Format
|
|
14
|
+
from ..sources import Bundle
|
|
15
|
+
from ..themes import assemble, slug
|
|
16
|
+
|
|
17
|
+
_MAX_FILES = 300
|
|
18
|
+
_STYLES = {
|
|
19
|
+
"t_comment": ("comment", "comment_line", "comment_doc"), "t_number": ("number", "number_1"),
|
|
20
|
+
"t_string": ("string", "string_1"), "t_type": ("type",), "t_class": ("class", "type"), "t_func": ("function",),
|
|
21
|
+
"t_keyword": ("keyword", "keyword_1"), "t_builtin": ("keyword_2", "identifier_2"), "t_operator": ("operator",),
|
|
22
|
+
"t_decorator": ("decorator", "preprocessor"), "t_regex": ("regex",), "t_variable": ("identifier", "identifier_1"),
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _parser(text: str) -> configparser.ConfigParser:
|
|
27
|
+
cp = configparser.ConfigParser(interpolation=None, strict=False, delimiters=("=",), comment_prefixes=("#",), allow_no_value=True)
|
|
28
|
+
cp.optionxform = str # type: ignore[assignment,method-assign]
|
|
29
|
+
cp.read_string(text)
|
|
30
|
+
return cp
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _is_scheme(text: str) -> bool:
|
|
34
|
+
return "[named_styles]" in text or "[theme_info]" in text
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _is_filetype(rel: str, text: str) -> bool:
|
|
38
|
+
return Path(rel).name.startswith("filetypes.") and ("[keywords]" in text or "[settings]" in text)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _candidates(bundle: Bundle) -> list[tuple[str, str]]:
|
|
42
|
+
out = []
|
|
43
|
+
for rel in bundle.names():
|
|
44
|
+
low = rel.lower()
|
|
45
|
+
if not (low.endswith((".conf", ".in")) or Path(rel).name.startswith("filetypes.")):
|
|
46
|
+
continue
|
|
47
|
+
text = bundle.text(rel) or ""
|
|
48
|
+
if len(text) < 400_000 and (_is_scheme(text) or _is_filetype(rel, text)):
|
|
49
|
+
out.append((rel, text))
|
|
50
|
+
if len(out) >= _MAX_FILES:
|
|
51
|
+
break
|
|
52
|
+
return out
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _is_geany(root: Path) -> bool:
|
|
56
|
+
return bool(_candidates(Bundle(root)))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def from_scheme(text: str, *, theme_id: str, fallback: str) -> ThemeSpec | None:
|
|
60
|
+
cp = _parser(text)
|
|
61
|
+
colors = dict(cp["named_colors"]) if cp.has_section("named_colors") else {}
|
|
62
|
+
styles = dict(cp["named_styles"]) if cp.has_section("named_styles") else {}
|
|
63
|
+
name = cp.get("theme_info", "name", fallback=fallback) if cp.has_section("theme_info") else fallback
|
|
64
|
+
|
|
65
|
+
def color(token: str, depth: int = 0) -> str | None:
|
|
66
|
+
token = token.strip()
|
|
67
|
+
if not token or depth > 6:
|
|
68
|
+
return None
|
|
69
|
+
if token.startswith("#"):
|
|
70
|
+
return token if col.parse(token) else None
|
|
71
|
+
return color(colors[token], depth + 1) if token in colors else None
|
|
72
|
+
|
|
73
|
+
def fields_of(style: str, depth: int = 0) -> tuple[str | None, str | None]:
|
|
74
|
+
value = styles.get(style)
|
|
75
|
+
if value is None or depth > 6:
|
|
76
|
+
return None, None
|
|
77
|
+
parts = value.split(";")
|
|
78
|
+
head = parts[0].split(",")[0].strip()
|
|
79
|
+
fg = color(head)
|
|
80
|
+
alias = fields_of(head, depth + 1) if fg is None and head in styles else (None, None)
|
|
81
|
+
bg = color(parts[1].split(",")[0]) if len(parts) > 1 else None
|
|
82
|
+
return fg or alias[0], bg or alias[1]
|
|
83
|
+
|
|
84
|
+
out: dict[str, str | None] = {}
|
|
85
|
+
out["fg"], out["bg"] = fields_of("default")
|
|
86
|
+
out["editor_bg"] = out["bg"]
|
|
87
|
+
out["sel_fg"], out["sel_bg"] = fields_of("selection")
|
|
88
|
+
out["line_hl"] = fields_of("current_line")[1]
|
|
89
|
+
out["gutter_fg"] = fields_of("margin_line_number")[0]
|
|
90
|
+
out["cursor"] = fields_of("caret")[0]
|
|
91
|
+
for target, names in _STYLES.items():
|
|
92
|
+
for style in names:
|
|
93
|
+
fg = fields_of(style)[0]
|
|
94
|
+
if fg:
|
|
95
|
+
out[target] = fg
|
|
96
|
+
break
|
|
97
|
+
if not (out["bg"] and out["fg"]):
|
|
98
|
+
return None
|
|
99
|
+
return assemble(theme_id, name, out)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def language_from_filetype(rel: str, text: str, known: set[str]) -> LanguageSpec | None:
|
|
103
|
+
cp = _parser(text)
|
|
104
|
+
name = Path(rel).name.split(".", 1)[1].split(".")[0] if "." in Path(rel).name else ""
|
|
105
|
+
lid = slug(name).replace("_", "-")
|
|
106
|
+
exts = [f".{e.lower()}" for e in re.split(r"[;\s]+", cp.get("settings", "extension", fallback="")) if e]
|
|
107
|
+
if not lid or lid in known or not exts:
|
|
108
|
+
return None
|
|
109
|
+
line = cp.get("settings", "comment_single", fallback="").replace("\\s", " ").strip() or None
|
|
110
|
+
open_, close = cp.get("settings", "comment_open", fallback="").strip(), cp.get("settings", "comment_close", fallback="").strip()
|
|
111
|
+
block = (open_, close) if open_ and close else None
|
|
112
|
+
words: list[str] = []
|
|
113
|
+
types: list[str] = []
|
|
114
|
+
if cp.has_section("keywords"):
|
|
115
|
+
for key, value in cp["keywords"].items():
|
|
116
|
+
bucket = types if "type" in key.lower() else words
|
|
117
|
+
bucket.extend(w for w in (value or "").split() if w.isidentifier())
|
|
118
|
+
tokens, kws = simple_tokens(line_comment=line, block_comment=block, keywords=words, types=types)
|
|
119
|
+
return LanguageSpec(id=lid, label=title_of(lid), extensions=exts, comment=line, comment_block=block, patterns=tokens, keywords=kws)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def load_geany(root: Path, known: set[str]) -> Extension:
|
|
123
|
+
bundle = Bundle(root)
|
|
124
|
+
ext = Extension(id=f"geany.{slug(root.name)}", name=root.name, version="0", kind="geany", path=root)
|
|
125
|
+
used: set[str] = set()
|
|
126
|
+
for rel, text in _candidates(bundle):
|
|
127
|
+
try:
|
|
128
|
+
if _is_scheme(text):
|
|
129
|
+
spec = from_scheme(text, theme_id=f"geany_{slug(Path(rel).stem)}", fallback=title_of(Path(rel).stem))
|
|
130
|
+
if spec and spec.id not in used:
|
|
131
|
+
used.add(spec.id)
|
|
132
|
+
ext.themes.append(spec)
|
|
133
|
+
elif spec is None:
|
|
134
|
+
ext.warnings.append(f"{Path(rel).name}: esquema sem cor de texto e de fundo")
|
|
135
|
+
else:
|
|
136
|
+
lang = language_from_filetype(rel, decode(text.encode()), known)
|
|
137
|
+
if lang and not any(x.id == lang.id for x in ext.languages):
|
|
138
|
+
ext.languages.append(lang)
|
|
139
|
+
except configparser.Error as exc:
|
|
140
|
+
ext.warnings.append(f"{Path(rel).name}: arquivo ilegível ({type(exc).__name__})")
|
|
141
|
+
return ext
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
registry.register(Format(
|
|
145
|
+
"geany", "Geany", _is_geany, load_geany, priority=61, suffixes=(".conf",),
|
|
146
|
+
provides="esquemas de cores e tipos de arquivo",
|
|
147
|
+
))
|