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
@@ -237,7 +237,7 @@ Initializes custom variables for use in various commands, extending beyond stand
237
237
238
238
Custom variables maintain their values throughout a single Replace-All or within a list of multiple Replace operations. Thus, they can transfer values from one list entry to subsequent ones. They reset at the start of each new document in **'Replace All in All Open Documents'**.
239
239
240
-
> **Tip**: To learn how to preload variables using an empty Find field before the main replacement process starts, see [Preloading Variables](#preloading-variables).
240
+
**Init usage:** can be used as an init entry (empty Find) to preload before replacements; not mandatory. See [Preload variables & helpers](#preload-variables--helpers) for workflow and examples.
> **Tip**: To learn how to preload variables using an empty Find field before the main replacement process starts, see [Preloading Variables](#preloading-variables).
272
+
**Init usage:** can be used as an init entry (empty Find) to preload before replacements; not mandatory. See [Preload variables & helpers](#preload-variables--helpers) for workflow and examples.
@@ -348,21 +348,65 @@ Formats numbers based on precision (maxDecimals) and whether the number of decim
348
348
349
349
<br>
350
350
351
-
### **Preloading Variables**
352
-
MultiReplace supports **predefining or loading variables** before any replacements occur. By separating initialization from the actual replacements, operations stay clean and maintainable.
351
+
#### **lcmd(path)**
353
352
354
-
#### 🔹 **How it works:**
355
-
-**Place `vars()` or `lvars()` next to an empty Find field.**
356
-
- This entry does **not** search for matches but runs before replacements begin.
357
-
- It ensures that **variables are loaded once**, regardless of their position in the list.
353
+
Load user-defined helper functions from a Lua file. The file **must**`return` a table of functions. `lcmd` registers those functions as globals for the current run.
358
354
359
-
**Examples**
355
+
**Purpose:** add reusable helper functions (formatters, slugifiers, padding, small logic). Helpers **must return a string or number** and are intended to be called from **action** commands (e.g. `set(...)`, `cond(...)`).
356
+
**Init usage:** can be used as an init entry (empty Find) to preload before replacements; not mandatory. See [Preload variables & helpers](#preload-variables--helpers) for workflow and examples.
|*(empty)*|`lcmd([[C:\tmp\mycmds.lcmd]])`| No | Load helpers from file (init row — no replacement). |
361
+
|`(\d+)`|`set(padLeft(CAP1, 6, '0'))`| Yes | Zero-pad captured number to width 6 using `padLeft`. |
362
+
|`(.+)`|`set(slug(CAP1))`| Yes | Create a URL-safe slug from the whole line using `slug`. |
363
+
364
+
**File format:**
365
+
```lua
366
+
return {
367
+
-- padLeft: left-pad to width
368
+
padLeft=function(s, w, ch)
369
+
s=tostring(sor"")
370
+
ch=chor""
371
+
if#s>=wthenreturnsend
372
+
returnstring.rep(ch, w-#s) ..s
373
+
end,
374
+
375
+
-- slug: make URL-friendly
376
+
slug=function(s)
377
+
s=tostring(sor""):lower()
378
+
s=s:gsub("%s+", "-"):gsub("[^%w%-]", "")
379
+
returns
380
+
end
381
+
}
382
+
```
383
+
384
+
<br>
385
+
386
+
### **Preload variables & helpers**
387
+
Use init entries (empty Find) to preload variables or helper functions before any replacements run. Init entries run once per Replace-All (or per list pass) and do not change text directly.
388
+
389
+
#### **How it works**
390
+
-**Place `vars()`, `lvars()` or `lcmd()` next to an empty Find field.**
391
+
- This entry does **not** search for matches but runs before replacements begin.
392
+
- It ensures that **variables and helpers are loaded once**, regardless of their position in the list.
393
+
- Use **Use Variables = ON** for init rows so loaded variables/helpers are available to later rows.
|`(\d+)`|`set(padLeft(CAP1, 6, '0'))`| Use helper loaded by `lcmd` to zero-pad (`123` → `000123`). |
404
+
|`(.+)`|`set(slug(CAP1))`| Use helper loaded by `lcmd` to create a slug (`Hello World!` → `hello-world`). |
405
+
406
+
#### File notes
407
+
-`lvars` / `lcmd` files must **return a table**. Recommended extension: `*.lua` (e.g. `myVars.vars`, `mycmds.lcmd`).
408
+
-`lcmd` registers helper functions globally for the run and **errors on name collisions** (no overrides).
409
+
- Errors from loading are reported to the user (loader returns `(false, errMsg)` on failure).
366
410
367
411
<br>
368
412
@@ -560,6 +604,9 @@ The MultiReplace plugin provides several configuration options, including transp
560
604
-**Default**: `GroupResults=0` (disabled).
561
605
-**Description**: This option changes how 'Find All' results are presented. When enabled (`1`), results are grouped by their source list entry, creating a categorized view. When disabled (`0`), all results are displayed as a single, flat list, sorted by their position in the document, without any categorization.
562
606
607
+
-**SafeMode**: Controls which standard Lua libraries are available.
608
+
-**Default**: `SafeMode=1` (enabled).
609
+
-**Description**: When enabled (`1`), some libraries are disabled (`os`, `io`, `package`, `debug`, and functions like `dofile`, `require`, `load`). Common libraries such as `string`, `table`, `math`, `utf8`, `coroutine` remain available. When disabled (`0`), all standard libraries are loaded.
0 commit comments