# HG changeset patch # User Augie Fackler # Date 1229448655 21600 # Node ID d6fd2964258c41620bda3b34ea35c94c34dd33c5 # Parent e1caf3e773a8cee9480f578bcc93b1cedd87041e New version of textmate.el diff --git a/.elisp/textmate.el b/.elisp/textmate.el --- 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)