Skip to content

Instantly share code, notes, and snippets.

@qoobaa
Created October 20, 2011 14:04
Show Gist options
  • Save qoobaa/1301216 to your computer and use it in GitHub Desktop.
Save qoobaa/1301216 to your computer and use it in GitHub Desktop.
underscore
(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:_-"))))))
@ncr
Copy link

ncr commented Oct 20, 2011

Cool! Zaczynam lubic skladnie Lispowa. Kryzys wieku sredniego ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment