0

camelCase.el emacswiki has a function to un-camelcase. But It doesn't seem to work. I added that piece to the camelCase.el itself. But can't get it to work. What am I missing ? Did anyone else have the same problem ?

EDIT : I have added last two functions, one of which is the function that doesn't work

(defun camelCase-downcase-word (count)
  "Make word starting at point lowercase, leaving point after word."
  (interactive "*p")
  (let ((start (point)))
    (camelCase-forward-word count)
    (downcase-region start (point))))

(defun un-camelcase-string (s &optional sep start)
  "Convert CamelCase string S to lower case with word separator SEP.
    Default for SEP is a hyphen \"-\".
 If third argument START is non-nil, convert words after that
    index in STRING."
  (let ((case-fold-search nil))
    (while (string-match "[A-Z]" s (or start 1))
      (setq s (replace-match (concat (or sep "_")
                                     (downcase (match-string 0 s)))
                             t nil s)))
    (downcase s)))

(provide 'camelCase)
navderm
  • 799
  • 2
  • 11
  • 33

1 Answers1

1

Other than the misleading doc-string (it actually defaults to "_", not "-" for the separator), the definition of un-camelcase-string you provide works. Can you give us more details about how it fails and under what circumstances?

Inaimathi
  • 13,853
  • 9
  • 49
  • 93
  • Yeah I changed that. When I have a cpp file written in camel case format. I use this function to convert a variable to the google-style case. I have tried with both camelcase-mode enabled and disabled Whether selecting the word or without selecting it. When i do M-x i can't get this function to show up to use – navderm Mar 15 '13 at 18:28
  • Only commands (being functions which start with an `(interactive)` declaration) are available to `M-x`. – phils Mar 15 '13 at 22:44
  • in the code, the third argument is non optional. How do I provide that. Can you tell me how you used this function. I added interactive to be able to make a shortcut for the same – navderm Mar 16 '13 at 02:54
  • *All* arguments following `&optional` are optional (naturally -- a required argument following an optional one makes no sense). I haven't used this function, but as it processes a string argument rather than text in the current buffer, I suspect it's not what you're looking for? – phils Mar 16 '13 at 04:39