Skip to content
Browse files

Merge branch 'master' of github.com:leadtune/emacs-starter-kit

  • Loading branch information...
2 parents 5566345 + e11f3a5 commit 931a30f069a1977f45547d5ef7b6d1b96e981fb2 @bmabey bmabey committed Dec 19, 2010
View
2 initializers.available/textmate-plus.el
@@ -34,7 +34,7 @@
(filter-buffer-substring (- p2 1) p2 t)
(filter-buffer-substring p1 (+ p1 1) t)))
-(global-set-key (kbd "<C-M-delete>") 'trim-selection)
+(global-set-key (kbd "<C-s-backspace>") 'trim-selection)
(global-set-key (kbd "s-(") 'select-previous-paren)
(global-set-key (kbd "s-)") 'select-next-paren)
(global-set-key (kbd "C-s-0") 'select-outer-paren)
View
72 initializers.available/textmate.el
@@ -193,3 +193,75 @@
(global-set-key (kbd "<s-left>") 'beginning-of-line)
(global-set-key (kbd "<s-right>") 'end-of-line)
+
+;; CamelCase related behavior
+
+(defun textmate-case/camelCase-p (word)
+ (let (case-fold-search)
+ (and (not (string-match "_" word))
+ (not (string-match "^[A-Z]" word)))))
+
+(defun textmate-case/snake_case-p (word)
+ (string-match "_" word))
+
+(defun textmate-case/PascalCase-p (word)
+ (let (case-fold-search)
+ (and (not (string-match "_" word))
+ (string-match "^[A-Z]" word))))
+
+(defun textmate-case/word-pieces (word)
+ "returns a list of the pieces of a word, separated by snake-case or camel-case boundaries"
+ (with-temp-buffer
+ (insert-string word)
+ (goto-char 0)
+ (let (case-fold-search
+ (pieces '())
+ (accumulate-piece (lambda ()
+ (setq pieces (append pieces (list (filter-buffer-substring 1 (point) t)))))))
+ (while (search-forward-regexp "_\\|[a-z][A-Z]" nil t)
+ (if (looking-back "_")
+ (backward-delete-char 1)
+ (backward-char))
+ (funcall accumulate-piece))
+
+ (goto-char (point-max))
+ (funcall accumulate-piece)
+
+ pieces)))
+
+(defun textmate-case/convert-case (case-format word)
+ "convert provided word to camelCase and return as string"
+ (with-temp-buffer
+ (let ((word-pieces (textmate-case/word-pieces word)))
+ (if (or (equal 'camelCase case-format)
+ (equal 'PascalCase case-format))
+ (progn
+ (mapcar (lambda (piece)
+ (save-excursion (insert piece))
+ (capitalize-word 1))
+ word-pieces)
+ (if (equal 'camelCase case-format) (downcase-region (point-min) (1+ (point-min)))))
+ (progn
+ (insert (mapconcat 'identity word-pieces "_"))
+ (downcase-region (point-min) (point-max)))))
+ (buffer-string)))
+
+
+(defconst textmate-case/boundary-regex "[^a-zA-Z0-9_]")
+
+(defun textmate-case/toggle (arg)
+ "Toggles between camelCase, PascalCase, and snake_case"
+ (interactive "p")
+ (let* ((start (progn (search-backward-regexp textmate-case/boundary-regex) (forward-char) (point)))
+ (end (progn (search-forward-regexp textmate-case/boundary-regex) (backward-char) (point)))
+ (word (filter-buffer-substring start end t))
+ (target-case-format (cond ((textmate-case/snake_case-p word) 'camelCase)
+ ((textmate-case/PascalCase-p word) 'snake_case)
+ ((textmate-case/camelCase-p word) 'PascalCase))))
+ (insert
+ (textmate-case/convert-case target-case-format
+ word)))
+ (if (or (= arg -1) (= arg 2)) (textmate-case/toggle 1)))
+
+(define-key *textmate-mode-map* (kbd "C-c t _") 'textmate-case/toggle)
+(define-key *textmate-mode-map* (kbd "C-c t -") 'textmate-case/toggle)
View
7 initializers.available/viper.el
@@ -32,13 +32,18 @@
(global-set-key (kbd "s-j") 'viper-intercept-ESC-key) ;; escape is hard to reach... this is easy!
+;; This ensures that Emacs will only undo up to the last insert/modal state change.
+(add-hook 'viper-insert-state-hook 'undo-boundary t)
+(add-hook 'viper-emacs-state-hook 'undo-boundary t)
+(add-hook 'viper-vi-state-hook 'undo-boundary t)
+
+
;; Cursor magic ------------
;; This should be default, or there should be a better way to change this... for now, this code
;; handles changing the cursor from a square to a line
(add-hook 'viper-insert-state-hook 'viper-set-cursor t)
(add-hook 'viper-emacs-state-hook 'viper-set-cursor t)
(add-hook 'viper-vi-state-hook 'viper-set-cursor t)
-
(defun viper-set-cursor ()
"Set the cursor for a given state"
(cond
2 vendor/rspec-mode
@@ -1 +1 @@
-Subproject commit cebbee1a266367a528504810dc19a5e2d972fada
+Subproject commit 69a5bc1b1ba7acf220637f6aa841fb9826afda84

0 comments on commit 931a30f

Please sign in to comment.
Something went wrong with that request. Please try again.