changeset 24:d6fd2964258c

New version of textmate.el
author Augie Fackler <durin42@gmail.com>
date Tue, 16 Dec 2008 11:30:55 -0600
parents e1caf3e773a8
children c7ff220bba9f
files .elisp/textmate.el
diffstat 1 files changed, 30 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.elisp/textmate.el
+++ b/.elisp/textmate.el
@@ -94,7 +94,9 @@
                                      (textmate-goto-file
                                       ,(kbd "A-t")   [(meta t)])
                                      (textmate-goto-symbol
-                                      ,(kbd "A-T")   [(meta T)])))
+                                      ,(kbd "A-T")   [(meta T)])
+				     (textmate-toggle-camel-case
+				      ,(kbd "C-_")   [(control _))))
 
 (defvar *textmate-project-root-p*
   #'(lambda (coll) (or (member ".git" coll)
@@ -186,6 +188,33 @@
   (setq *textmate-project-files* nil)
   (message "textmate-mode cache cleared."))
 
+(defun textmate-toggle-camel-case ()
+  "Toggle current sexp between camelCase and snake_case, like TextMate C-_."
+  (interactive)
+  (if (thing-at-point 'word)
+      (progn
+	(unless (looking-at "\\<") (backward-sexp))
+	(let ((case-fold-search nil)
+	      (start (point))
+	      (end (save-excursion (forward-sexp) (point))))
+	  (if (and (looking-at "[a-z0-9_]+") (= end (match-end 0))) ; snake-case
+	      (progn
+		(goto-char start)
+		(while (re-search-forward "_[a-z]" end t)
+		  (goto-char (1- (point)))
+		  (delete-char -1)
+		  (upcase-region (point) (1+ (point)))
+		  (setq end (1- end))))
+	    (downcase-region (point) (1+ (point)))
+	    (while (re-search-forward "[A-Z][a-z]" end t)
+	      (forward-char -2)
+	      (insert "_")
+	      (downcase-region (point) (1+ (point)))
+	      (forward-char 1)
+	      (setq end (1+ end)))
+	    (downcase-region start end)
+	    )))))
+
 ;;; Utilities
 
 (defun textmate-also-ignore (pattern)