You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DEV.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,7 +88,7 @@ Maturin's `data` option in `pyproject.toml` points to `python/exhash.data/`. Fil
88
88
89
89
The Rust core has three parsing functions:
90
90
91
-
-`parse_commands_from_strs(&[&str])` — for the Python API; each string is one command, text blocks are the remaining lines (no `.` terminator; a trailing `.` line is literal text and the Python binding warns about this common mistake)
91
+
-`parse_commands_from_strs(&[&str])` — for the Python API; each string is one command, and multiline `a/i/c`text blocks must be in that same string using newlines, e.g. `["12|abcd|c\nnew line 1\nnew line 2"]`. Do not use `.` terminators or split the inserted text into separate command entries; a trailing `.` line is literal text and the Python binding warns about this common mistake.
92
92
-`parse_commands_from_script(&str)` — for script strings; commands separated by newlines, text blocks terminated by `.`
93
93
-`parse_commands_from_args(&[String], &mut BufRead)` — for the CLI; each arg is a command, text blocks read from stdin terminated by `.`
Copy file name to clipboardExpand all lines: README.md
+5-2Lines changed: 5 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -118,7 +118,7 @@ view = lnhashview_file("f.py", start=1, end=260) # end past EOF is clamped
118
118
119
119
### Editing
120
120
121
-
`exhash(text, cmds, sw=4)` takes the text and a required iterable of command strings (use `[]` for no-op). `sw` controls how far `<` and `>` shift. For `a`/`i`/`c` commands, lines after the command are the text block. Do not include an ex-style trailing `.`line here: unlike CLI/script mode, `exhash(text, cmds)` does not use one, and a final `.` lineis inserted literally.
121
+
`exhash(text, cmds, sw=4)` takes the text and a required iterable of command strings (use `[]` for no-op). `sw` controls how far `<` and `>` shift. For multiline `a`/`i`/`c` commands, include the inserted text in the same command string using newline characters, e.g. `["12|abcd|c\nnew line 1\nnew line 2"]`. Do not use `.`terminators, and do not split the text block into separate `cmds` entries. If you include a final `.` line, it is inserted literally and exhash emits a warning.
122
122
123
123
```py
124
124
addr = lnhash(1, "foo") # "1|a1b2|"
@@ -133,12 +133,15 @@ res = exhash(text, [f"{a1}s/foo/FOO/", f"{a2}s/bar/BAR/"])
133
133
# Hashes are checked just-in-time per command.
134
134
# If earlier commands change/shift a later target line, recompute lnhash first.
135
135
136
-
# Append multiline text (no dot terminator)
136
+
# Append multiline text in the same command string (no dot terminator)
137
137
res = exhash(text, [f"{addr}a\nnew line 1\nnew line 2"])
138
138
139
139
# Wrong for the Python API: the trailing "." would be inserted literally
140
140
# res = exhash(text, [f"{addr}a\nnew line 1\nnew line 2\n."])
141
141
142
+
# Also wrong: do not split the inserted text into separate cmds entries
143
+
# res = exhash(text, [f"{addr}a", "new line 1", "new line 2"])
'Like ``exhash`` but reads from file at ``path``. Uses the same no-``.``-terminator rule for a/i/c text blocks. If the file is missing and the commands are valid on empty input (for example ``0|0000|a``), it is treated as empty and created on inplace write. If ``inplace``, writes back and returns diff string.'
91
+
'Like ``exhash`` but reads from file at ``path``. For multiline a/i/c commands, include the inserted text in the same command string using newline characters, e.g. ``["12|abcd|c\\nnew line 1\\nnew line 2"]``. Do not use ``.`` terminators, and do not split the text block into separate ``cmds`` entries. If the file is missing and the commands are valid on empty input (for example ``0|0000|a``), it is treated as empty and created on inplace write. If ``inplace``, writes back and returns diff string.'
0 commit comments