vith 0.16.2__tar.gz → 0.16.4__tar.gz
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.
- {vith-0.16.2/vith.egg-info → vith-0.16.4}/PKG-INFO +6 -4
- {vith-0.16.2 → vith-0.16.4}/README.md +5 -3
- {vith-0.16.2 → vith-0.16.4}/pyproject.toml +1 -1
- vith-0.16.4/tests/test_io_backends.py +256 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_thai.py +8 -2
- {vith-0.16.2 → vith-0.16.4}/vith/__init__.py +1 -1
- {vith-0.16.2 → vith-0.16.4}/vith/commands/completer.py +15 -2
- {vith-0.16.2 → vith-0.16.4}/vith/commands/files.py +4 -3
- {vith-0.16.2 → vith-0.16.4}/vith/commands/handler.py +29 -1
- {vith-0.16.2 → vith-0.16.4}/vith/commands/options.py +6 -0
- {vith-0.16.2 → vith-0.16.4}/vith/editor.py +49 -6
- {vith-0.16.2 → vith-0.16.4}/vith/editor_buffer.py +7 -6
- vith-0.16.4/vith/io/__init__.py +12 -0
- {vith-0.16.2 → vith-0.16.4}/vith/io/backends.py +25 -3
- {vith-0.16.2 → vith-0.16.4}/vith/rc_file.py +15 -13
- {vith-0.16.2 → vith-0.16.4}/vith/thai/__init__.py +5 -0
- {vith-0.16.2 → vith-0.16.4}/vith/thai/clusters.py +50 -5
- {vith-0.16.2 → vith-0.16.4}/vith/thai/patches.py +79 -1
- {vith-0.16.2 → vith-0.16.4}/vith/window_arrangement.py +4 -0
- {vith-0.16.2 → vith-0.16.4/vith.egg-info}/PKG-INFO +6 -4
- vith-0.16.2/tests/test_io_backends.py +0 -136
- vith-0.16.2/vith/io/__init__.py +0 -10
- {vith-0.16.2 → vith-0.16.4}/LICENSE +0 -0
- {vith-0.16.2 → vith-0.16.4}/setup.cfg +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_cd.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_cli_and_process.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_cold_text.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_commands_grammar.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_completion.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_editor_buffer.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_editor_title.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_ex_commands.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_filetype.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_filetype_tabstops.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_key_bindings_fixes.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_layout.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_lexer.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_preview.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_quit_and_goto.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_range_commands.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_read_command.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_render.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_reporting.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_round10_perf.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_round11_bugs.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_round8_perf.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_round8_semantics.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_round9_dedup.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_round9_perf.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_round9_readability.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_set_ergonomics.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_set_int_options.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_startup_io.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_style.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_substitute.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_thai_motions.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_thai_tabs_motion.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_toml_config.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_window_arrangements.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/tests/test_write_commands.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/__main__.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/cold_text.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/commands/__init__.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/commands/buffers.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/commands/common.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/commands/editing.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/commands/global_cmd.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/commands/grammar.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/commands/info.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/commands/lexer.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/commands/normal.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/commands/preview.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/commands/ranges.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/commands/registry.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/commands/render.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/commands/substitution.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/commands/tabs.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/completion.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/entry_points/__init__.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/entry_points/run_vith.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/help.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/io/base.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/key_bindings.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/layout.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/lexer.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/process.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/render.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/reporting.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/style.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/thai/classify.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/thai/words.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith/welcome_message.py +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith.egg-info/SOURCES.txt +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith.egg-info/dependency_links.txt +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith.egg-info/entry_points.txt +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith.egg-info/requires.txt +0 -0
- {vith-0.16.2 → vith-0.16.4}/vith.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vith
|
|
3
|
-
Version: 0.16.
|
|
3
|
+
Version: 0.16.4
|
|
4
4
|
Summary: Vith — a pure-Python Vi clone with Thai & Lao script support (fork of pyvim)
|
|
5
5
|
Author-email: Chaiwat Suttipongsakul <cwt@bashell.com>
|
|
6
6
|
Maintainer-email: Chaiwat Suttipongsakul <cwt@bashell.com>
|
|
@@ -68,7 +68,7 @@ This fork runs on **Python 3.10+** (`prompt_toolkit` 3.0) and adds four major, m
|
|
|
68
68
|
- **Ex command completeness & `:set` parity**: full Vim Ex command set across files (`:r`/`:read` incl. `:r !cmd`, `:sav`, `:up`, `:x`, `:wa`, `:xa`, `:so`, `:f`, `:enew`), buffers/windows/tabs (`:ls`, `:b #`, `:bf`/`:bl`, `:sb`, `:bd <target>`, `:clo`, `:on`, `:tabo`/`:tabm`/`:tabs`), generalized range editing (`:$`/`±N`, `:d`, `:y`, `:pu`, `:m`, `:t`/`:co`, `:j`, `:sort`, `:retab`, `:g`/`:v`, `:[range]!cmd`, `:[range]w` partial/append/pipe, `:[range]norm[!]`), `%`/`#` filename expansion with `:p`/`:h`/`:t`/`:r`/`:e`, in-editor read-only info splits (`:ver`, `:mes`, `:reg`, `:marks`, `:set`), and ergonomic `:set` syntax (`?`, `!`, `inv`, multi-arg, `smartcase`, `shiftwidth`, `readonly`, `autoindent`, `fileencoding`, `fileformat`). See [`docs/command_completeness_plan.md`](docs/command_completeness_plan.md).
|
|
69
69
|
- **Live async `:render` split preview**: real-time non-blocking split preview (`:render`, `:render-split-v`, `:render-split-h`) powered by optional `vith[render]` (`rich` + `rich-rst`), with direct `Segment` → `StyleAndTextTuples` bridging, debounced executor rendering, stale-edit fallback, heading/landmark-anchored scroll sync, and pluggable `[render.commands]` CLI renderers. See [`docs/live_render.md`](docs/live_render.md).
|
|
70
70
|
|
|
71
|
-
All changes are audited in [`docs/bugs/`](docs/bugs/) (
|
|
71
|
+
All changes are audited in [`docs/bugs/`](docs/bugs/) (194 machine-verified findings across 14 audit rounds and 4 addenda — 193 fixed, 1 archived/withdrawn); quality is enforced with pytest (562 tests), mypy and ruff.
|
|
72
72
|
|
|
73
73
|
Issues, questions, wishes, comments, feedback, remarks? Please create a GitHub issue, I appreciate it.
|
|
74
74
|
|
|
@@ -155,6 +155,8 @@ For full technical details (architecture, Rich-to-`prompt_toolkit` style bridgin
|
|
|
155
155
|
|
|
156
156
|
Vith uses a declarative TOML configuration file loaded from `~/.config/vith/config.toml` (or `~/.vithrc`). Advanced Python callbacks and keybindings can be placed in `~/.config/vith/hooks/` and registered under `[hooks]`.
|
|
157
157
|
|
|
158
|
+
Wide-emoji note: terminals that widen emoji presentation (Kitty, Alacritty, szn with `variation-selector-always-wide on`) render some narrow bases followed by U+FE0F (e.g. `❤️`) as 2 cells. Set `variation_selector_always_wide = true` under `[editor]` in `config.toml` (or `:set variation_selector_always_wide`) so vith counts them as 2 cells and keeps cursor, wrapping, and block selection aligned.
|
|
159
|
+
|
|
158
160
|
Have a look at these examples:
|
|
159
161
|
- TOML configuration: [`config.toml`](examples/config/config.toml)
|
|
160
162
|
- Modular Python hook: [`build-and-run.py`](examples/config/hooks/build-and-run.py)
|
|
@@ -183,7 +185,7 @@ To run all tests, install the optional and development dependencies (pytest, pyt
|
|
|
183
185
|
pip install -e ".[jedi,lzo,render,dev]"
|
|
184
186
|
```
|
|
185
187
|
|
|
186
|
-
Run unit tests via the test runner script (executes all
|
|
188
|
+
Run unit tests via the test runner script (executes all 562 tests in parallel and enforces ≥85% test coverage):
|
|
187
189
|
|
|
188
190
|
```sh
|
|
189
191
|
bash scripts/runtest.sh
|
|
@@ -197,7 +199,7 @@ python -m pytest tests
|
|
|
197
199
|
|
|
198
200
|
Developer helper scripts are provided in `scripts/`:
|
|
199
201
|
|
|
200
|
-
- `scripts/runtest.sh`: run the full test suite in parallel with coverage enforcement (
|
|
202
|
+
- `scripts/runtest.sh`: run the full test suite in parallel with coverage enforcement (562 tests)
|
|
201
203
|
- `scripts/type-check.sh`: run `mypy .` (typing, 88 source files checked against the 3.10 floor)
|
|
202
204
|
- `scripts/lint-check-and-fix.sh`: run `ruff check --fix .` (linting)
|
|
203
205
|
- `scripts/code-format.sh`: run `ruff format` (formatting)
|
|
@@ -25,7 +25,7 @@ This fork runs on **Python 3.10+** (`prompt_toolkit` 3.0) and adds four major, m
|
|
|
25
25
|
- **Ex command completeness & `:set` parity**: full Vim Ex command set across files (`:r`/`:read` incl. `:r !cmd`, `:sav`, `:up`, `:x`, `:wa`, `:xa`, `:so`, `:f`, `:enew`), buffers/windows/tabs (`:ls`, `:b #`, `:bf`/`:bl`, `:sb`, `:bd <target>`, `:clo`, `:on`, `:tabo`/`:tabm`/`:tabs`), generalized range editing (`:$`/`±N`, `:d`, `:y`, `:pu`, `:m`, `:t`/`:co`, `:j`, `:sort`, `:retab`, `:g`/`:v`, `:[range]!cmd`, `:[range]w` partial/append/pipe, `:[range]norm[!]`), `%`/`#` filename expansion with `:p`/`:h`/`:t`/`:r`/`:e`, in-editor read-only info splits (`:ver`, `:mes`, `:reg`, `:marks`, `:set`), and ergonomic `:set` syntax (`?`, `!`, `inv`, multi-arg, `smartcase`, `shiftwidth`, `readonly`, `autoindent`, `fileencoding`, `fileformat`). See [`docs/command_completeness_plan.md`](docs/command_completeness_plan.md).
|
|
26
26
|
- **Live async `:render` split preview**: real-time non-blocking split preview (`:render`, `:render-split-v`, `:render-split-h`) powered by optional `vith[render]` (`rich` + `rich-rst`), with direct `Segment` → `StyleAndTextTuples` bridging, debounced executor rendering, stale-edit fallback, heading/landmark-anchored scroll sync, and pluggable `[render.commands]` CLI renderers. See [`docs/live_render.md`](docs/live_render.md).
|
|
27
27
|
|
|
28
|
-
All changes are audited in [`docs/bugs/`](docs/bugs/) (
|
|
28
|
+
All changes are audited in [`docs/bugs/`](docs/bugs/) (194 machine-verified findings across 14 audit rounds and 4 addenda — 193 fixed, 1 archived/withdrawn); quality is enforced with pytest (562 tests), mypy and ruff.
|
|
29
29
|
|
|
30
30
|
Issues, questions, wishes, comments, feedback, remarks? Please create a GitHub issue, I appreciate it.
|
|
31
31
|
|
|
@@ -112,6 +112,8 @@ For full technical details (architecture, Rich-to-`prompt_toolkit` style bridgin
|
|
|
112
112
|
|
|
113
113
|
Vith uses a declarative TOML configuration file loaded from `~/.config/vith/config.toml` (or `~/.vithrc`). Advanced Python callbacks and keybindings can be placed in `~/.config/vith/hooks/` and registered under `[hooks]`.
|
|
114
114
|
|
|
115
|
+
Wide-emoji note: terminals that widen emoji presentation (Kitty, Alacritty, szn with `variation-selector-always-wide on`) render some narrow bases followed by U+FE0F (e.g. `❤️`) as 2 cells. Set `variation_selector_always_wide = true` under `[editor]` in `config.toml` (or `:set variation_selector_always_wide`) so vith counts them as 2 cells and keeps cursor, wrapping, and block selection aligned.
|
|
116
|
+
|
|
115
117
|
Have a look at these examples:
|
|
116
118
|
- TOML configuration: [`config.toml`](examples/config/config.toml)
|
|
117
119
|
- Modular Python hook: [`build-and-run.py`](examples/config/hooks/build-and-run.py)
|
|
@@ -140,7 +142,7 @@ To run all tests, install the optional and development dependencies (pytest, pyt
|
|
|
140
142
|
pip install -e ".[jedi,lzo,render,dev]"
|
|
141
143
|
```
|
|
142
144
|
|
|
143
|
-
Run unit tests via the test runner script (executes all
|
|
145
|
+
Run unit tests via the test runner script (executes all 562 tests in parallel and enforces ≥85% test coverage):
|
|
144
146
|
|
|
145
147
|
```sh
|
|
146
148
|
bash scripts/runtest.sh
|
|
@@ -154,7 +156,7 @@ python -m pytest tests
|
|
|
154
156
|
|
|
155
157
|
Developer helper scripts are provided in `scripts/`:
|
|
156
158
|
|
|
157
|
-
- `scripts/runtest.sh`: run the full test suite in parallel with coverage enforcement (
|
|
159
|
+
- `scripts/runtest.sh`: run the full test suite in parallel with coverage enforcement (562 tests)
|
|
158
160
|
- `scripts/type-check.sh`: run `mypy .` (typing, 88 source files checked against the 3.10 floor)
|
|
159
161
|
- `scripts/lint-check-and-fix.sh`: run `ruff check --fix .` (linting)
|
|
160
162
|
- `scripts/code-format.sh`: run `ruff format` (formatting)
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests for `vith/io/backends.py` (P5: `codecs.open` deprecation removal,
|
|
3
|
+
`FileIO`/`GZipFileIO` behaviour).
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import io
|
|
7
|
+
import warnings
|
|
8
|
+
|
|
9
|
+
from vith.io.backends import FileIO, GZipFileIO
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_fileio_write_read_utf8_roundtrip(tmp_path):
|
|
13
|
+
f = FileIO()
|
|
14
|
+
p = str(tmp_path / 'file.txt')
|
|
15
|
+
|
|
16
|
+
f.write(p, 'héllo wörld', 'utf-8')
|
|
17
|
+
text, encoding = f.read(p)
|
|
18
|
+
|
|
19
|
+
assert text == 'héllo wörld'
|
|
20
|
+
assert encoding == 'utf-8'
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_fileio_latin1_fallback(tmp_path):
|
|
24
|
+
p = tmp_path / 'latin1.txt'
|
|
25
|
+
# A byte that is not valid UTF-8: falls back to latin-1 (which accepts
|
|
26
|
+
# any byte sequence).
|
|
27
|
+
p.write_bytes(b'caf\xe9')
|
|
28
|
+
|
|
29
|
+
text, encoding = FileIO().read(str(p))
|
|
30
|
+
|
|
31
|
+
assert text == 'café'
|
|
32
|
+
assert encoding == 'latin-1'
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_fileio_no_deprecation_warning(tmp_path):
|
|
36
|
+
# P5: `codecs.open` is deprecated in Python 3.14+; the C-buffered
|
|
37
|
+
# `io.open` must be used instead, so no DeprecationWarning may be
|
|
38
|
+
# emitted while reading or writing.
|
|
39
|
+
p = str(tmp_path / 'deprecation.txt')
|
|
40
|
+
f = FileIO()
|
|
41
|
+
|
|
42
|
+
with warnings.catch_warnings(record=True) as caught:
|
|
43
|
+
warnings.simplefilter('always')
|
|
44
|
+
f.write(p, 'plain text', 'utf-8')
|
|
45
|
+
f.read(p)
|
|
46
|
+
|
|
47
|
+
deprecations = [w for w in caught if issubclass(w.category, DeprecationWarning)]
|
|
48
|
+
assert deprecations == [], (
|
|
49
|
+
'FileIO read/write must not emit DeprecationWarnings: %r' % deprecations
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_fileio_uses_io_open(tmp_path, monkeypatch):
|
|
54
|
+
# Explicitly: reads/writes go through `io.open`, not `codecs.open`.
|
|
55
|
+
p = str(tmp_path / 'tracked.txt')
|
|
56
|
+
f = FileIO()
|
|
57
|
+
|
|
58
|
+
calls = []
|
|
59
|
+
original = io.open
|
|
60
|
+
|
|
61
|
+
def tracking_open(*args, **kwargs):
|
|
62
|
+
calls.append((args, kwargs))
|
|
63
|
+
return original(*args, **kwargs)
|
|
64
|
+
|
|
65
|
+
monkeypatch.setattr('vith.io.backends.io.open', tracking_open)
|
|
66
|
+
|
|
67
|
+
f.write(p, 'data', 'utf-8')
|
|
68
|
+
assert f.read(p) == ('data', 'utf-8')
|
|
69
|
+
|
|
70
|
+
assert [args[1] for args, _kw in calls] == ['w']
|
|
71
|
+
assert [kw.get('encoding') for _args, kw in calls] == ['utf-8']
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_gzip_roundtrip(tmp_path):
|
|
75
|
+
p = str(tmp_path / 'data.txt.gz')
|
|
76
|
+
g = GZipFileIO()
|
|
77
|
+
|
|
78
|
+
g.write(p, 'compressed content', 'utf-8')
|
|
79
|
+
text, encoding = g.read(p)
|
|
80
|
+
|
|
81
|
+
assert text == 'compressed content'
|
|
82
|
+
assert encoding == 'utf-8'
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_gzip_can_open_location():
|
|
86
|
+
g = GZipFileIO()
|
|
87
|
+
assert g.can_open_location('/tmp/some-file.txt.gz') is True
|
|
88
|
+
assert g.can_open_location('/tmp/some-file.txt') is False
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_directory_io_handles_tilde(editor):
|
|
92
|
+
editor.load_initial_files(['~'])
|
|
93
|
+
eb = editor.window_arrangement.active_editor_buffer
|
|
94
|
+
assert eb.in_file_explorer_mode is True
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def test_gzip_can_open_location_expands_tilde(monkeypatch, tmp_path):
|
|
98
|
+
# 113 item 6: `GZipFileIO.can_open_location` delegates to `super()` and
|
|
99
|
+
# `_expand_location` consistently for `~/` paths.
|
|
100
|
+
monkeypatch.setenv('HOME', str(tmp_path))
|
|
101
|
+
gz_dir = tmp_path / 'dir.gz'
|
|
102
|
+
gz_dir.mkdir()
|
|
103
|
+
|
|
104
|
+
g = GZipFileIO()
|
|
105
|
+
assert g.can_open_location('~/archive.txt.gz') is True
|
|
106
|
+
assert g.can_open_location('~/dir.gz') is False
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_auto_decode_primary_and_fallback_encodings():
|
|
110
|
+
# 115 item 6: `_auto_decode` tries `PRIMARY_ENCODING` ('utf-8') then
|
|
111
|
+
# falls back to `FALLBACK_ENCODING` ('latin-1').
|
|
112
|
+
from vith.io.backends import ENCODINGS, FALLBACK_ENCODING, PRIMARY_ENCODING, _auto_decode
|
|
113
|
+
|
|
114
|
+
assert ENCODINGS == (PRIMARY_ENCODING, FALLBACK_ENCODING) == ('utf-8', 'latin-1')
|
|
115
|
+
assert _auto_decode('สวัสดี'.encode('utf-8')) == ('สวัสดี', 'utf-8')
|
|
116
|
+
assert _auto_decode(b'\xff\xfe') == ('\xff\xfe', 'latin-1')
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_directory_io_unreadable_raises_oserror(editor, tmp_path, monkeypatch):
|
|
120
|
+
# 110 item 8: `DirectoryIO.read` propagates `OSError` to `EditorBuffer._read`,
|
|
121
|
+
# which surfaces an error message in the editor instead of crashing.
|
|
122
|
+
import os
|
|
123
|
+
|
|
124
|
+
from vith.editor_buffer import EditorBuffer
|
|
125
|
+
|
|
126
|
+
target_dir = tmp_path / 'restricted'
|
|
127
|
+
target_dir.mkdir()
|
|
128
|
+
|
|
129
|
+
def failing_scandir(_path):
|
|
130
|
+
raise PermissionError('Permission denied')
|
|
131
|
+
|
|
132
|
+
monkeypatch.setattr(os, 'scandir', failing_scandir)
|
|
133
|
+
editor.message = None
|
|
134
|
+
eb = EditorBuffer(editor, str(target_dir))
|
|
135
|
+
assert eb.in_file_explorer_mode is True
|
|
136
|
+
assert editor.message is not None and 'Permission denied' in editor.message
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def test_expand_env_vars_and_location_preserve_urls(monkeypatch, tmp_path):
|
|
140
|
+
import os
|
|
141
|
+
|
|
142
|
+
from vith.io.backends import expand_env_vars, expand_location
|
|
143
|
+
|
|
144
|
+
monkeypatch.setenv('VITH_TEST_ROOT', str(tmp_path))
|
|
145
|
+
|
|
146
|
+
# `$VAR` and `${VAR}` expand on every platform.
|
|
147
|
+
expected = os.path.join(str(tmp_path), 'alacritty.toml')
|
|
148
|
+
assert expand_env_vars(os.path.join('$VITH_TEST_ROOT', 'alacritty.toml')) == expected
|
|
149
|
+
assert expand_env_vars(os.path.join('${VITH_TEST_ROOT}', 'alacritty.toml')) == expected
|
|
150
|
+
assert expand_location(os.path.join('$VITH_TEST_ROOT', 'alacritty.toml')) == expected
|
|
151
|
+
|
|
152
|
+
# URLs must never undergo env-var or tilde expansion.
|
|
153
|
+
assert expand_env_vars('https://example.com/$VITH_TEST_ROOT') == (
|
|
154
|
+
'https://example.com/$VITH_TEST_ROOT'
|
|
155
|
+
)
|
|
156
|
+
assert expand_location('http://example.com/%VITH_TEST_ROOT%/a') == (
|
|
157
|
+
'http://example.com/%VITH_TEST_ROOT%/a'
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
# On Windows, `%VAR%` (case-insensitive) expands too.
|
|
161
|
+
if os.name == 'nt':
|
|
162
|
+
assert expand_env_vars(r'%VITH_TEST_ROOT%\alacritty.toml') == expected
|
|
163
|
+
assert expand_env_vars(r'%vith_test_root%\alacritty.toml') == expected
|
|
164
|
+
assert expand_location(r'%VITH_TEST_ROOT%\alacritty.toml') == expected
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def test_load_initial_files_and_ex_commands_expand_env_vars(editor, tmp_path, monkeypatch):
|
|
168
|
+
import os
|
|
169
|
+
|
|
170
|
+
from prompt_toolkit.completion import CompleteEvent
|
|
171
|
+
from prompt_toolkit.document import Document
|
|
172
|
+
|
|
173
|
+
from vith.commands.completer import create_command_completer
|
|
174
|
+
from vith.commands.handler import expand_command_filenames, handle_command
|
|
175
|
+
from vith.rc_file import run_rc_file
|
|
176
|
+
|
|
177
|
+
sub = tmp_path / 'alacritty'
|
|
178
|
+
sub.mkdir()
|
|
179
|
+
cfg = sub / 'alacritty.toml'
|
|
180
|
+
cfg.write_bytes(b'size = 14.0\n')
|
|
181
|
+
|
|
182
|
+
rc = tmp_path / 'vith.toml'
|
|
183
|
+
rc.write_bytes(b'tabstop = 4\n')
|
|
184
|
+
|
|
185
|
+
monkeypatch.setenv('VITH_TEST_APPDATA', str(tmp_path))
|
|
186
|
+
|
|
187
|
+
path_expr = (
|
|
188
|
+
r'%VITH_TEST_APPDATA%\alacritty\alacritty.toml'
|
|
189
|
+
if os.name == 'nt'
|
|
190
|
+
else '$VITH_TEST_APPDATA/alacritty/alacritty.toml'
|
|
191
|
+
)
|
|
192
|
+
rc_expr = (
|
|
193
|
+
r'%VITH_TEST_APPDATA%\vith.toml' if os.name == 'nt' else '$VITH_TEST_APPDATA/vith.toml'
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
# 1. CLI `load_initial_files` opens the real file and stores the expanded path.
|
|
197
|
+
editor.load_initial_files([path_expr])
|
|
198
|
+
eb = editor.window_arrangement.active_editor_buffer
|
|
199
|
+
assert eb is not None
|
|
200
|
+
assert eb.is_new is False
|
|
201
|
+
assert eb.location == str(cfg)
|
|
202
|
+
assert eb.buffer.text == 'size = 14.0'
|
|
203
|
+
|
|
204
|
+
# Opening the expanded path again reuses the existing buffer (no duplicate).
|
|
205
|
+
editor.window_arrangement.open_buffer(str(cfg), show_in_current_window=True)
|
|
206
|
+
assert len(editor.window_arrangement.editor_buffers) == 1
|
|
207
|
+
|
|
208
|
+
# 2. Ex `:e` expands env vars without triggering `%` E499 or corrupting `%VAR%`.
|
|
209
|
+
editor.window_arrangement.open_buffer(None, show_in_current_window=True)
|
|
210
|
+
handle_command(editor, f'e {path_expr}')
|
|
211
|
+
active = editor.window_arrangement.active_editor_buffer
|
|
212
|
+
assert active is not None
|
|
213
|
+
assert active.location == str(cfg)
|
|
214
|
+
assert active.buffer.text == 'size = 14.0'
|
|
215
|
+
|
|
216
|
+
# 3. `:w` overwrite guard and `:cd` honor env-var paths.
|
|
217
|
+
out_expr = r'%VITH_TEST_APPDATA%\out.txt' if os.name == 'nt' else '$VITH_TEST_APPDATA/out.txt'
|
|
218
|
+
handle_command(editor, f'w {out_expr}')
|
|
219
|
+
assert (tmp_path / 'out.txt').read_text(encoding='utf-8') == 'size = 14.0\n'
|
|
220
|
+
editor.message = None
|
|
221
|
+
handle_command(editor, f'w {out_expr}')
|
|
222
|
+
assert editor.message == 'File exists (add ! to override)'
|
|
223
|
+
|
|
224
|
+
orig_cwd = os.getcwd()
|
|
225
|
+
try:
|
|
226
|
+
dir_expr = (
|
|
227
|
+
r'%VITH_TEST_APPDATA%\alacritty' if os.name == 'nt' else '$VITH_TEST_APPDATA/alacritty'
|
|
228
|
+
)
|
|
229
|
+
handle_command(editor, f'cd {dir_expr}')
|
|
230
|
+
assert os.path.realpath(os.getcwd()) == os.path.realpath(str(sub))
|
|
231
|
+
finally:
|
|
232
|
+
os.chdir(orig_cwd)
|
|
233
|
+
|
|
234
|
+
# 4. `run_rc_file` (`vith -u` / `:so`) expands env vars.
|
|
235
|
+
assert run_rc_file(editor, rc_expr) is True
|
|
236
|
+
assert editor.tabstop == 4
|
|
237
|
+
|
|
238
|
+
# 5. Path completion completes files inside env-var directories.
|
|
239
|
+
completer = create_command_completer(editor)
|
|
240
|
+
prefix = (
|
|
241
|
+
r'e %VITH_TEST_APPDATA%\alacritty\al'
|
|
242
|
+
if os.name == 'nt'
|
|
243
|
+
else 'e $VITH_TEST_APPDATA/alacritty/al'
|
|
244
|
+
)
|
|
245
|
+
comps = list(completer.get_completions(Document(prefix, len(prefix)), CompleteEvent()))
|
|
246
|
+
assert any(c.display_text == 'alacritty.toml' for c in comps)
|
|
247
|
+
|
|
248
|
+
# 6. On Windows, shell commands preserve `%VAR%` while still expanding trailing `%`.
|
|
249
|
+
if os.name == 'nt':
|
|
250
|
+
cmd_str, err = expand_command_filenames(
|
|
251
|
+
r'echo %VITH_TEST_APPDATA% %', editor, shell_escape=True
|
|
252
|
+
)
|
|
253
|
+
assert err is None
|
|
254
|
+
assert cmd_str is not None
|
|
255
|
+
assert cmd_str.startswith('echo %VITH_TEST_APPDATA% ')
|
|
256
|
+
assert 'alacritty.toml' in cmd_str
|
|
@@ -1578,7 +1578,10 @@ def test_win32_input_patch_accepts_conpty_vk_menu_keyup(monkeypatch) -> None:
|
|
|
1578
1578
|
|
|
1579
1579
|
from ctypes.wintypes import DWORD
|
|
1580
1580
|
|
|
1581
|
-
from prompt_toolkit.input.win32 import
|
|
1581
|
+
from prompt_toolkit.input.win32 import ( # type: ignore[attr-defined]
|
|
1582
|
+
ConsoleInputReader,
|
|
1583
|
+
Vt100ConsoleInputReader,
|
|
1584
|
+
)
|
|
1582
1585
|
from prompt_toolkit.win32_types import INPUT_RECORD
|
|
1583
1586
|
|
|
1584
1587
|
assert thai.install_prompt_toolkit_thai_patches() is True
|
|
@@ -1627,7 +1630,10 @@ def test_version_gate_rollback_covers_win32_input_patch(monkeypatch) -> None:
|
|
|
1627
1630
|
if sys.platform != "win32":
|
|
1628
1631
|
pytest.skip("Win32 console input patch only applies on Windows")
|
|
1629
1632
|
|
|
1630
|
-
from prompt_toolkit.input.win32 import
|
|
1633
|
+
from prompt_toolkit.input.win32 import ( # type: ignore[attr-defined]
|
|
1634
|
+
ConsoleInputReader,
|
|
1635
|
+
Vt100ConsoleInputReader,
|
|
1636
|
+
)
|
|
1631
1637
|
|
|
1632
1638
|
for cls in (Vt100ConsoleInputReader, ConsoleInputReader):
|
|
1633
1639
|
orig = getattr(cls._get_keys, "_vith_original", None)
|
|
@@ -11,7 +11,7 @@ from pathlib import Path
|
|
|
11
11
|
# In a development checkout (e.g. repo root), read directly from pyproject.toml
|
|
12
12
|
# so editing the version requires touching only pyproject.toml. The fallback
|
|
13
13
|
# is a single constant (docs/bugs/075.md); pyproject.toml remains primary.
|
|
14
|
-
_FALLBACK_VERSION = "0.16.
|
|
14
|
+
_FALLBACK_VERSION = "0.16.4"
|
|
15
15
|
_pyproject = Path(__file__).resolve().parent.parent / "pyproject.toml"
|
|
16
16
|
if _pyproject.is_file():
|
|
17
17
|
_m = re.search(
|
|
@@ -7,6 +7,8 @@ from prompt_toolkit.contrib.completers.system import SystemCompleter
|
|
|
7
7
|
from prompt_toolkit.contrib.regular_languages.completion import GrammarCompleter
|
|
8
8
|
from prompt_toolkit.document import Document
|
|
9
9
|
|
|
10
|
+
from vith.io.backends import expand_env_vars
|
|
11
|
+
|
|
10
12
|
from .grammar import COMMAND_GRAMMAR
|
|
11
13
|
from .options import SET_EXTRA_TOGGLE_ON_NAMES, SET_TOGGLE_GROUPS
|
|
12
14
|
from .registry import SET_COMMANDS, get_commands
|
|
@@ -178,6 +180,17 @@ class CommandCompleter(Completer):
|
|
|
178
180
|
yield from self.inner.get_completions(document, complete_event)
|
|
179
181
|
|
|
180
182
|
|
|
183
|
+
class _EnvPathCompleter(PathCompleter):
|
|
184
|
+
"""`PathCompleter` that also expands environment variables (`$VAR`, `%VAR%`)."""
|
|
185
|
+
|
|
186
|
+
def get_completions(self, document, complete_event):
|
|
187
|
+
raw = document.text_before_cursor
|
|
188
|
+
expanded = expand_env_vars(raw)
|
|
189
|
+
if expanded != raw:
|
|
190
|
+
document = Document(expanded, len(expanded))
|
|
191
|
+
yield from super().get_completions(document, complete_event)
|
|
192
|
+
|
|
193
|
+
|
|
181
194
|
def create_command_completer(editor):
|
|
182
195
|
commands = [c + ' ' for c in get_commands()]
|
|
183
196
|
|
|
@@ -185,8 +198,8 @@ def create_command_completer(editor):
|
|
|
185
198
|
COMMAND_GRAMMAR,
|
|
186
199
|
{
|
|
187
200
|
'command': WordCompleter(commands),
|
|
188
|
-
'location':
|
|
189
|
-
'write_append':
|
|
201
|
+
'location': _EnvPathCompleter(expanduser=True),
|
|
202
|
+
'write_append': _EnvPathCompleter(expanduser=True),
|
|
190
203
|
'set_option': WordCompleter(sorted(SET_COMMANDS)),
|
|
191
204
|
'buffer_name': BufferNameCompleter(editor),
|
|
192
205
|
'colorscheme': ColorSchemeCompleter(editor),
|
|
@@ -10,6 +10,7 @@ import os
|
|
|
10
10
|
from typing import Any
|
|
11
11
|
|
|
12
12
|
from vith.editor_buffer import is_same_write_target
|
|
13
|
+
from vith.io.backends import expand_location
|
|
13
14
|
from vith.io.base import find_backend
|
|
14
15
|
from vith.thai import note_document_text
|
|
15
16
|
|
|
@@ -163,7 +164,7 @@ def file_info(editor: Any, location: str | None) -> None:
|
|
|
163
164
|
if location is not None:
|
|
164
165
|
# `:f {name}` renames the buffer; normalize metadata the same way
|
|
165
166
|
# writes do (docs/bugs/147.md).
|
|
166
|
-
normalized = os.path.abspath(
|
|
167
|
+
normalized = os.path.abspath(expand_location(location))
|
|
167
168
|
eb.location = normalized
|
|
168
169
|
eb.is_new = not os.path.exists(normalized)
|
|
169
170
|
eb.isdir = os.path.isdir(normalized)
|
|
@@ -188,7 +189,7 @@ def _reject_existing_write_target(editor: Any, eb: Any, location: str | None, fo
|
|
|
188
189
|
return False
|
|
189
190
|
if is_same_write_target(eb.location, location):
|
|
190
191
|
return False
|
|
191
|
-
if os.path.exists(
|
|
192
|
+
if os.path.exists(expand_location(location)):
|
|
192
193
|
editor.show_message('File exists (add ! to override)')
|
|
193
194
|
return True
|
|
194
195
|
return False
|
|
@@ -519,7 +520,7 @@ def source_file(editor: Any, location: str | None) -> None:
|
|
|
519
520
|
@location_cmd('cd', accepts_force=False)
|
|
520
521
|
def cd(editor: Any, location: str | None) -> None:
|
|
521
522
|
"""Change working directory."""
|
|
522
|
-
target =
|
|
523
|
+
target = expand_location(location or '~')
|
|
523
524
|
try:
|
|
524
525
|
os.chdir(target)
|
|
525
526
|
except OSError as exc:
|
|
@@ -3,6 +3,8 @@ import os
|
|
|
3
3
|
import shlex
|
|
4
4
|
from typing import Any
|
|
5
5
|
|
|
6
|
+
from vith.io.backends import expand_env_vars, expand_location
|
|
7
|
+
|
|
6
8
|
from .files import filter_range_command
|
|
7
9
|
from .grammar import COMMAND_GRAMMAR
|
|
8
10
|
from .ranges import NO_SUCH_LINE_TEXT, resolve_line_address
|
|
@@ -37,7 +39,7 @@ class _ExpandedVariables:
|
|
|
37
39
|
def _apply_filename_modifier(path: str, modifier: str) -> str:
|
|
38
40
|
"""Apply a single Vim filename modifier (`:p`, `:h`, `:t`, `:r`, `:e`)."""
|
|
39
41
|
if modifier == 'p':
|
|
40
|
-
return os.path.abspath(
|
|
42
|
+
return os.path.abspath(expand_location(path))
|
|
41
43
|
if modifier == 'h':
|
|
42
44
|
head = os.path.dirname(path)
|
|
43
45
|
return head if head else '.'
|
|
@@ -50,6 +52,22 @@ def _apply_filename_modifier(path: str, modifier: str) -> str:
|
|
|
50
52
|
return path
|
|
51
53
|
|
|
52
54
|
|
|
55
|
+
def _match_windows_env_var(text: str, start: int) -> tuple[str, int] | None:
|
|
56
|
+
"""
|
|
57
|
+
If `text[start:]` begins with `%VAR%` for a defined Windows environment
|
|
58
|
+
variable, return `(var_name, end_index)` (index after the closing `%`).
|
|
59
|
+
"""
|
|
60
|
+
if os.name != 'nt' or text[start] != '%':
|
|
61
|
+
return None
|
|
62
|
+
end = text.find('%', start + 1)
|
|
63
|
+
if end <= start + 1:
|
|
64
|
+
return None
|
|
65
|
+
var_name = text[start + 1 : end]
|
|
66
|
+
if any(c in var_name for c in '/\\:') or var_name not in os.environ:
|
|
67
|
+
return None
|
|
68
|
+
return var_name, end + 1
|
|
69
|
+
|
|
70
|
+
|
|
53
71
|
def expand_command_filenames(
|
|
54
72
|
text: str, editor: Any, *, shell_escape: bool = False
|
|
55
73
|
) -> tuple[str | None, str | None]:
|
|
@@ -75,6 +93,15 @@ def expand_command_filenames(
|
|
|
75
93
|
i += 2
|
|
76
94
|
continue
|
|
77
95
|
|
|
96
|
+
# On Windows, treat `%VAR%` as an environment variable when `VAR`
|
|
97
|
+
# exists in `os.environ` (e.g. `:e %APPDATA%\alacritty\alacritty.toml`)
|
|
98
|
+
# instead of expanding both `%` delimiters as the current buffer name.
|
|
99
|
+
if (win_env := _match_windows_env_var(text, i)) is not None:
|
|
100
|
+
var_name, next_i = win_env
|
|
101
|
+
out.append(text[i:next_i] if shell_escape else os.environ[var_name])
|
|
102
|
+
i = next_i
|
|
103
|
+
continue
|
|
104
|
+
|
|
78
105
|
if ch in ('%', '#'):
|
|
79
106
|
wa = editor.window_arrangement
|
|
80
107
|
if ch == '%':
|
|
@@ -118,6 +145,7 @@ def _expand_variables(variables: Any, editor: Any) -> tuple[Any, str | None]:
|
|
|
118
145
|
expanded, err = expand_command_filenames(raw, editor, shell_escape=False)
|
|
119
146
|
if err is not None or expanded is None:
|
|
120
147
|
return None, err
|
|
148
|
+
expanded = expand_env_vars(expanded)
|
|
121
149
|
if expanded != raw:
|
|
122
150
|
overrides[key] = expanded
|
|
123
151
|
|
|
@@ -39,6 +39,12 @@ SET_TOGGLE_GROUPS = (
|
|
|
39
39
|
('mouse', 'enable_mouse_support', ('mouse',), ('nomouse',)),
|
|
40
40
|
('cursorline', 'cursorline', ('cursorline', 'cul'), ('nocursorline', 'nocul')),
|
|
41
41
|
('cursorcolumn', 'cursorcolumn', ('cursorcolumn', 'cuc'), ('nocursorcolumn', 'nocuc')),
|
|
42
|
+
(
|
|
43
|
+
'variation_selector_always_wide',
|
|
44
|
+
'variation_selector_always_wide',
|
|
45
|
+
('variation_selector_always_wide', 'vsaw'),
|
|
46
|
+
('novariation_selector_always_wide', 'novsaw'),
|
|
47
|
+
),
|
|
42
48
|
)
|
|
43
49
|
|
|
44
50
|
#: (display name, editor attribute, aliases, minimum)
|
|
@@ -32,7 +32,7 @@ from .commands.options import snapshot_default_options
|
|
|
32
32
|
from .commands.preview import CommandPreviewer
|
|
33
33
|
from .commands.substitution import resolve_ignore_case
|
|
34
34
|
from .help import HELP_TEXT
|
|
35
|
-
from .io import DirectoryIO, FileIO, GZipFileIO, HttpIO
|
|
35
|
+
from .io import DirectoryIO, FileIO, GZipFileIO, HttpIO, expand_location
|
|
36
36
|
from .key_bindings import create_key_bindings
|
|
37
37
|
from .layout import EditorLayout
|
|
38
38
|
from .process import set_process_name
|
|
@@ -196,6 +196,46 @@ class Editor:
|
|
|
196
196
|
:param output: (Optionally) `prompt_toolkit.output.Output` object.
|
|
197
197
|
"""
|
|
198
198
|
|
|
199
|
+
@property
|
|
200
|
+
def variation_selector_always_wide(self) -> bool:
|
|
201
|
+
try:
|
|
202
|
+
import vith.thai.clusters as _clusters_mod
|
|
203
|
+
|
|
204
|
+
if getattr(_clusters_mod, 'variation_selector_always_wide', False) or getattr(
|
|
205
|
+
_clusters_mod, 'VARIATION_SELECTOR_ALWAYS_WIDE', False
|
|
206
|
+
):
|
|
207
|
+
return True
|
|
208
|
+
except Exception:
|
|
209
|
+
pass
|
|
210
|
+
try:
|
|
211
|
+
import vith.thai as _thai_mod
|
|
212
|
+
|
|
213
|
+
if getattr(_thai_mod, 'variation_selector_always_wide', False) or getattr(
|
|
214
|
+
_thai_mod, 'VARIATION_SELECTOR_ALWAYS_WIDE', False
|
|
215
|
+
):
|
|
216
|
+
return True
|
|
217
|
+
except Exception:
|
|
218
|
+
pass
|
|
219
|
+
return bool(getattr(self, '_variation_selector_always_wide', False))
|
|
220
|
+
|
|
221
|
+
@variation_selector_always_wide.setter
|
|
222
|
+
def variation_selector_always_wide(self, value: bool) -> None:
|
|
223
|
+
self._variation_selector_always_wide = bool(value)
|
|
224
|
+
try:
|
|
225
|
+
import vith.thai.clusters as _clusters_mod
|
|
226
|
+
|
|
227
|
+
_clusters_mod.variation_selector_always_wide = bool(value)
|
|
228
|
+
_clusters_mod.VARIATION_SELECTOR_ALWAYS_WIDE = bool(value)
|
|
229
|
+
except Exception:
|
|
230
|
+
pass
|
|
231
|
+
try:
|
|
232
|
+
import vith.thai as _thai_mod
|
|
233
|
+
|
|
234
|
+
_thai_mod.variation_selector_always_wide = bool(value)
|
|
235
|
+
_thai_mod.VARIATION_SELECTOR_ALWAYS_WIDE = bool(value)
|
|
236
|
+
except Exception:
|
|
237
|
+
pass
|
|
238
|
+
|
|
199
239
|
def __init__(self, config_directory='~/.vith', input=None, output=None):
|
|
200
240
|
set_process_name('vith')
|
|
201
241
|
install_prompt_toolkit_thai_patches()
|
|
@@ -232,6 +272,9 @@ class Editor:
|
|
|
232
272
|
self.break_indent = False # ':set breakindent'
|
|
233
273
|
self.cursorline = False # ':set cursorline'
|
|
234
274
|
self.cursorcolumn = False # ':set cursorcolumn'
|
|
275
|
+
# Opt-in: treat VS16-promoted narrow emoji bases as 2 cells
|
|
276
|
+
# (szn `variation-selector-always-wide`).
|
|
277
|
+
self._variation_selector_always_wide = False
|
|
235
278
|
self.colorcolumn = [] # ':set colorcolumn'. List of integers.
|
|
236
279
|
self.fileformat = 'unix' # ':set fileformat' (dos/unix/mac).
|
|
237
280
|
# Live `:render` split preview defaults (configurable via `[render]` in config.toml).
|
|
@@ -248,11 +291,11 @@ class Editor:
|
|
|
248
291
|
self._default_options = snapshot_default_options(self)
|
|
249
292
|
|
|
250
293
|
# Ensure config directory exists (with legacy fallback).
|
|
251
|
-
target_dir = os.path.abspath(
|
|
252
|
-
if
|
|
253
|
-
|
|
254
|
-
)
|
|
255
|
-
legacy_dir = os.path.abspath(
|
|
294
|
+
target_dir = os.path.abspath(expand_location(config_directory))
|
|
295
|
+
if expand_location(config_directory) == expand_location('~/.vith') and not os.path.exists(
|
|
296
|
+
target_dir
|
|
297
|
+
):
|
|
298
|
+
legacy_dir = os.path.abspath(expand_location('~/.pyvim'))
|
|
256
299
|
if os.path.exists(legacy_dir):
|
|
257
300
|
target_dir = legacy_dir
|
|
258
301
|
self.config_directory = target_dir
|
|
@@ -9,6 +9,7 @@ from prompt_toolkit.filters import to_filter
|
|
|
9
9
|
|
|
10
10
|
from vith.cold_text import ColdTextBuffer, make_cold_text_compressor
|
|
11
11
|
from vith.completion import DocumentCompleter
|
|
12
|
+
from vith.io.backends import expand_env_vars, expand_location
|
|
12
13
|
from vith.io.base import find_backend
|
|
13
14
|
from vith.lexer import sniff_filetype_from_text
|
|
14
15
|
from vith.reporting import checks_python_file, report
|
|
@@ -20,12 +21,12 @@ UNTITLED_LABEL = '[New file]'
|
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
def normalize_write_target(location: str | None) -> str | None:
|
|
23
|
-
"""Normalize a write path for same-file comparison (tilde/symlink safe; docs/bugs/152.md)."""
|
|
24
|
+
"""Normalize a write path for same-file comparison (tilde/env/symlink safe; docs/bugs/152.md)."""
|
|
24
25
|
if not location:
|
|
25
26
|
return None
|
|
26
27
|
if '://' in location:
|
|
27
28
|
return location
|
|
28
|
-
return os.path.realpath(os.path.abspath(
|
|
29
|
+
return os.path.realpath(os.path.abspath(expand_location(location)))
|
|
29
30
|
|
|
30
31
|
|
|
31
32
|
def is_same_write_target(current_location: str | None, target_location: str | None) -> bool:
|
|
@@ -51,7 +52,7 @@ class EditorBuffer:
|
|
|
51
52
|
assert not (location and text)
|
|
52
53
|
|
|
53
54
|
self._editor_ref = weakref.ref(editor)
|
|
54
|
-
self.location = location
|
|
55
|
+
self.location = expand_env_vars(location) if location is not None else None
|
|
55
56
|
self.encoding = 'utf-8'
|
|
56
57
|
# Pygments lexer alias overriding filename-based detection
|
|
57
58
|
# (`:set filetype=python`). `None` means auto-detect.
|
|
@@ -87,8 +88,8 @@ class EditorBuffer:
|
|
|
87
88
|
|
|
88
89
|
# Read text.
|
|
89
90
|
unreadable = False
|
|
90
|
-
if location:
|
|
91
|
-
text = self._read(location)
|
|
91
|
+
if self.location:
|
|
92
|
+
text = self._read(self.location)
|
|
92
93
|
if text is None:
|
|
93
94
|
# Not a new file: an unknown backend or a read failure.
|
|
94
95
|
# Show a fallback-empty buffer, but keep it read-only so the
|
|
@@ -466,7 +467,7 @@ class EditorBuffer:
|
|
|
466
467
|
Writing an untitled buffer names it and marks it clean.
|
|
467
468
|
"""
|
|
468
469
|
# Resolve the target location without mutating state up front.
|
|
469
|
-
target_location = location if location is not None else self.location
|
|
470
|
+
target_location = expand_env_vars(location) if location is not None else self.location
|
|
470
471
|
if not target_location:
|
|
471
472
|
self.editor.show_message('Unknown location: %r' % location)
|
|
472
473
|
return False
|