Skip to content

Commit

Permalink
tweak(core): more generic +env-save
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Oct 16, 2023
1 parent 478d4f6 commit 46fda3c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions elisp/+minemacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,13 @@ Works like `shell-command-to-string' with two differences:
(insert ";; Adding the rest of the environment variables\n")
(dolist (env-var env-vars)
(unless (cl-some (+apply-partially-right #'string-match-p (car env-var)) +env-deny-vars)
;; Correctly handle edge cases '\n' and '\"'
(let ((value (string-replace "\n" "\\n" (string-replace "\"" "\\\"" (cdr env-var)))))
(insert (format "(setenv \"%s\" \"%s\")\n"
(car env-var)
(string-replace "\n" "\\n" value)))))))
(let ((value (cdr env-var)))
;; Correctly handle special characters
(dolist (pair '(("\a" . "\\a") ("\b" . "\\b") ("\f" . "\\f")
("\n" . "\\n") ("\r" . "\\r") ("\t" . "\\t")
("\v" . "\\v") ("\"" . "\\\"")))
(setq value (string-replace (car pair) (cdr pair) value)))
(insert (format "(setenv \"%s\" \"%s\")\n" (car env-var) value))))))
(write-file +env-file))))

;;;###autoload
Expand Down

0 comments on commit 46fda3c

Please sign in to comment.