or better, detect if the current file need camelize automatically. for some reason, my project require me to create MyModule.js instead of my_module.js
Here is my fix:
commit 38339c6b8549813a17431f4843d728999348dd24
Author: chen bin <chenbin.sh@gmail.com>
Date: Wed Mar 27 12:19:15 2013 +1100
maybe the javascript file name already camelized
diff --git a/requirejs-mode.el b/requirejs-mode.el
index 82cb4c9..e3d4247 100644
--- a/requirejs-mode.el
+++ b/requirejs-mode.el
@@ -68,11 +68,21 @@ dependencies in an AMD style javascript module."
(defun is-first-import ()
(looking-back "[\[]" 2))
+(defun camelized-p (s)
+ "Detect if a string is already camelized"
+ (save-match-data
+ (let ((case-fold-search nil))
+ (string-match "\\`[A-Z][A-Za-z0-9]+\\'" s)))
+ )
+
(defun camelize (s)
"Convert dash-based string S to CamelCase string."
- (mapconcat 'identity (mapcar
- '(lambda (word) (capitalize (downcase word)))
- (split-string s "-")) ""))
+ (if (camelized-p s)
+ s
+ (mapconcat 'identity (mapcar
+ '(lambda (word) (capitalize (downcase word)))
+ (split-string s "-")) ""))
+ )
(defun un-camelcase-string (s &optional sep start)
(let ((case-fold-search nil))
or better, detect if the current file need camelize automatically. for some reason, my project require me to create MyModule.js instead of my_module.js
Here is my fix:
commit 38339c6b8549813a17431f4843d728999348dd24 Author: chen bin <chenbin.sh@gmail.com> Date: Wed Mar 27 12:19:15 2013 +1100 maybe the javascript file name already camelized diff --git a/requirejs-mode.el b/requirejs-mode.el index 82cb4c9..e3d4247 100644 --- a/requirejs-mode.el +++ b/requirejs-mode.el @@ -68,11 +68,21 @@ dependencies in an AMD style javascript module." (defun is-first-import () (looking-back "[\[]" 2)) +(defun camelized-p (s) + "Detect if a string is already camelized" + (save-match-data + (let ((case-fold-search nil)) + (string-match "\\`[A-Z][A-Za-z0-9]+\\'" s))) + ) + (defun camelize (s) "Convert dash-based string S to CamelCase string." - (mapconcat 'identity (mapcar - '(lambda (word) (capitalize (downcase word))) - (split-string s "-")) "")) + (if (camelized-p s) + s + (mapconcat 'identity (mapcar + '(lambda (word) (capitalize (downcase word))) + (split-string s "-")) "")) + ) (defun un-camelcase-string (s &optional sep start) (let ((case-fold-search nil))