Created
October 20, 2011 14:04
-
-
Save qoobaa/1301216 to your computer and use it in GitHub Desktop.
underscore
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 activesupport-underscore (string) | |
"underscores string just like in ActiveSupport inflector" | |
(let ((case-fold-search nil)) | |
(downcase | |
(reduce (lambda (string replacement) | |
(replace-regexp-in-string (car replacement) (cadr replacement) string)) | |
'(("::" "/") | |
("\\([[:upper:]]+\\)\\([[:upper:]][[:lower:]]\\)" "\\1_\\2") | |
("\\([[:lower:][:digit:]]\\)\\([[:upper:]]\\)" "\\1_\\2") | |
("-" "_")) | |
:initial-value string)))) | |
(defun activesupport-underscore-word () | |
"underscores word just like in ActiveSupport inflector" | |
(interactive) | |
(insert-string | |
(activesupport-underscore | |
(delete-and-extract-region (point) (+ (point) (skip-chars-forward "A-Za-z0-9:_-")))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool! Zaczynam lubic skladnie Lispowa. Kryzys wieku sredniego ;)