Created
February 24, 2016 09:28
-
-
Save davazp/fbbf361b183ff80165db to your computer and use it in GitHub Desktop.
This file contains 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 camelcasefy () | |
"Convert a string in camel-case interactively." | |
(interactive) | |
(catch 'exit | |
(let ((stack nil)) | |
(while t | |
(let ((ch (read-char "Character: "))) | |
(cond | |
((char-equal ch ?\n) | |
(throw 'exit nil)) | |
((char-equal ch ?\d) | |
(downcase-region (point) (1+ (point))) | |
(let ((point (pop stack))) | |
(when point | |
(goto-char point)))) | |
((char-equal ch ?\s) | |
(downcase-region (point) (1+ (point))) | |
(forward-char) | |
(pop stack)) | |
((char-equal ch ?\t) | |
;; Undo the current one | |
(downcase-region (point) (1+ (point))) | |
(pop stack) | |
;; Capitalize the next instance of the character | |
(push (point) stack) | |
(let ((ch (buffer-substring-no-properties (point) (1+ (point))))) | |
(search-forward ch)) | |
(upcase-region (point) (1+ (point)))) | |
(t | |
(push (point) stack) | |
(forward-char) | |
(search-forward (string ch)) | |
(backward-char) | |
(upcase-region (point) (1+ (point)))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment