diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-10 14:13:56 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-10 14:13:56 -0500 |
| commit | f1e8f0898244bd2d834baf7541d10e5eff351d34 (patch) | |
| tree | 0398749a566619df6d5f8a63ce0edc6e1c245fb4 /modules/system-lib.el | |
| parent | 4f8eabac69f6477b83276e583dcdf91c17f6cf0f (diff) | |
| download | dotemacs-f1e8f0898244bd2d834baf7541d10e5eff351d34.tar.gz dotemacs-f1e8f0898244bd2d834baf7541d10e5eff351d34.zip | |
refactor(system-lib): extract cj/shell-quote-argument-readable from dev-fkeys
Phase 2.2 of utility-consolidation. The "quote only when shell-unsafe characters appear, otherwise leave the argument readable" pattern was trapped in dev-fkeys as `cj/--f6-shell-quote-argument' alongside its `cj/--f6-shell-safe-argument-regexp' constant. Lift both into system-lib.el under their generic names; the F6 branding hid that the same shape is useful for any generated compile/test command where the surrounding line ends up in a *compilation* buffer the user reads.
Six Normal/Boundary tests cover safe inputs that pass through unchanged (alphanumeric paths, test regexes, `FLAG=value', `host:port'), unsafe inputs that get quoted (spaces, `$', `;', `&', backticks, `*'), and the empty-string boundary.
Migrate dev-fkeys's five callers to the new name and add `(require \='system-lib)' per the Phase 2 exit criterion.
Diffstat (limited to 'modules/system-lib.el')
| -rw-r--r-- | modules/system-lib.el | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/modules/system-lib.el b/modules/system-lib.el index f932353f..dc1f8316 100644 --- a/modules/system-lib.el +++ b/modules/system-lib.el @@ -36,6 +36,24 @@ keep working." :warning) nil))) +(defconst cj/shell-safe-argument-regexp "\\`[[:alnum:]_./=+@%:,^-]+\\'" + "Regexp matching shell arguments safe to interpolate unchanged. +Members of this character set survive shell parsing without quoting, +so a command line containing only these characters in each argument +remains both safe and readable.") + +(defun cj/shell-quote-argument-readable (argument) + "Quote ARGUMENT for shell command interpolation when needed. + +When ARGUMENT consists only of characters in `cj/shell-safe-argument-regexp' +it is returned unchanged so the surrounding command stays human-readable +(useful for compile/test command lines you'll inspect in *compilation*). +Otherwise falls back to `shell-quote-argument' so the result is safe to +interpolate." + (if (string-match-p cj/shell-safe-argument-regexp argument) + argument + (shell-quote-argument argument))) + (defun cj/log-silently (format-string &rest args) "Append formatted message (FORMAT-STRING with ARGS) to *Messages* buffer. This does so without echoing in the minibuffer." |
