Last active
August 12, 2020 23:42
-
-
Save benley/5d26fc399c18bade77a3ff1432a30a74 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 's) | |
(defun count-leading-whitespace (str) | |
"Count leading indentation chars in STR." | |
(let ((trimmed (string-trim-left str))) | |
(- (length str) (length trimmed)))) | |
(defun unindent-string (str) | |
"Remove common leading whitespace from each line in STR." | |
(let* ((str-as-lines (s-lines str)) | |
(n-to-trim (apply #'min | |
(mapcar #'count-leading-whitespace str-as-lines)))) | |
(mapconcat 'identity | |
(mapcar (lambda (s) (substring s n-to-trim)) str-as-lines) | |
"\n"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment