Guest User

Untitled

a guest
Feb 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. (progn
  2. (defun camel-case-p (s)
  3. (let ((case-fold-search nil))
  4. (not (split-string s "[A-Z][a-z0-9]*" t))))
  5.  
  6. (defun camel-case-to-lower-underscore (s)
  7. (if (camel-case-p s)
  8. (let ((case-fold-search nil))
  9. (downcase (replace-regexp-in-string "\\([a-z0-9]\\)\\([A-Z]\\)" "\\1_\\2" s)))
  10. (message "Not a CamelCase string.")))
  11.  
  12. (defun camel-case-to-upper-underscore (s)
  13. (if (camel-case-p s)
  14. (let ((case-fold-search nil))
  15. (upcase (replace-regexp-in-string "\\([a-z0-9]\\)\\([A-Z]\\)" "\\1_\\2" s)))
  16. (message "Not a CamelCase string.")))
  17.  
  18. (defun replace-various-conventions (s1 s2)
  19. "doc here"
  20. (interactive "MReplace variable: \nMReplace variable with: ")
  21. (if (and (camel-case-p s1) (camel-case-p s2))
  22. (save-excursion
  23. (let ((case-fold-search nil)
  24. (replace-list
  25. (list
  26. (list s1 s2)
  27. (list (camel-case-to-upper-underscore s1) (camel-case-to-upper-underscore s2))
  28. (list (camel-case-to-lower-underscore s1) (camel-case-to-lower-underscore s2)))))
  29. (mapcar (lambda (list)
  30. (goto-char (point-min))
  31. (perform-replace (car list) (cadr list) nil nil nil (point-min) (point-max)))
  32. replace-list)
  33. )
  34. )
  35. (message "Either %s or %s is not in CamelCase." s1 s2)
  36. )
  37. )
Add Comment
Please, Sign In to add comment