Function: majutsu-template--str-escape

majutsu-template--str-escape is a natively compiled function defined in majutsu-template.el.

Signature

(majutsu-template--str-escape S)

Documentation

Escape S into a jj double-quoted string literal content.

Supported escapes (aligned with jj docs):
  \" \\ \t \r \n \0 \e and generic control bytes as \xHH.
All other characters are emitted verbatim (UTF-8 allowed).

Source Code

;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-template.el
;; Internal node representation: (:tag ...)

(defun majutsu-template--str-escape (s)
  "Escape S into a jj double-quoted string literal content.

Supported escapes (aligned with jj docs):
  \\\" \\\\ \\t \\r \\n \\0 \\e and generic control bytes as \\xHH.
All other characters are emitted verbatim (UTF-8 allowed)."
  (unless (stringp s)
    (user-error "majutsu-template: expected string, got %S" s))
  (apply #'concat
         (cl-loop for ch across s
                  collect
                  (pcase ch
                    (?\" "\\\"")          ; double quote
                    (?\\ "\\\\")          ; backslash
                    (?\t "\\t")            ; tab
                    (?\r "\\r")            ; carriage return
                    (?\n "\\n")            ; newline
                    (0   "\\0")            ; NUL
                    (27  "\\e")            ; ESC (0x1b)
                    (_
                     (if (or (< ch 32) (= ch 127))
                         (format "\\x%02X" ch) ; other ASCII controls as \xHH
                       (string ch)))))))