Created
October 20, 2017 22:09
-
-
Save amasad/8e838f48c582f0d0654be3dc461a6932 to your computer and use it in GitHub Desktop.
css-in-js to css elisp command
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
(defun un-camelcase-string (s) | |
(let ((case-fold-search nil)) | |
(while (string-match "[A-Z]" s 1) | |
(setq s (replace-match (concat "-" | |
(downcase (match-string 0 s))) | |
t nil s))) | |
(downcase s))) | |
(defun cssjs-to-css () | |
(interactive) | |
(insert (let ((lines (split-string (delete-and-extract-region (region-beginning) (region-end)) "\n"))) | |
(mapconcat (lambda (line) | |
(if (= (length line) 0) "" | |
(let ((parts (split-string line ":"))) | |
(if (/= (length parts) 2) | |
(error "Invalid line %s" line) | |
(concat | |
(un-camelcase-string (car parts)) | |
": " | |
(string-trim | |
(replace-regexp-in-string "'" ""(replace-regexp-in-string "," ";" (car (cdr parts)))))))))) | |
lines | |
"\n")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment