diff options
Diffstat (limited to 'ravi-init-appearance.el')
| -rw-r--r-- | ravi-init-appearance.el | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/ravi-init-appearance.el b/ravi-init-appearance.el index c227b99..8ed039a 100644 --- a/ravi-init-appearance.el +++ b/ravi-init-appearance.el @@ -135,6 +135,56 @@ Delete all whitespace on a successive key press." (bind-key "<return>" 'smart-newline emacs-lisp-mode-map)) :ensure t) +;; Case toggling: from Oleg Krehel http://oremacs.com/2014/12/25/ode-to-toggle/ +(defun oremacs/char-upcasep (letter) + (eq letter (upcase letter))) + +(defun oremacs/capitalize-word-toggle () + (interactive) + (let ((start + (car + (save-excursion + (backward-word) + (bounds-of-thing-at-point 'symbol))))) + (if start + (save-excursion + (goto-char start) + (funcall + (if (oremacs/char-upcasep (char-after)) + 'downcase-region + 'upcase-region) + start (1+ start))) + (capitalize-word -1)))) +(bind-key "M-c" 'oremacs/capitalize-word-toggle) + +(defun oremacs/upcase-word-toggle () + (interactive) + (let ((bounds (bounds-of-thing-at-point 'symbol)) + beg end + (regionp + (if (eq this-command last-command) + (get this-command 'regionp) + (put this-command 'regionp nil)))) + (cond + ((or (region-active-p) regionp) + (setq beg (region-beginning) + end (region-end)) + (put this-command 'regionp t)) + (bounds + (setq beg (car bounds) + end (cdr bounds))) + (t + (setq beg (point) + end (1+ beg)))) + (save-excursion + (goto-char (1- beg)) + (and (re-search-forward "[A-Za-z]" end t) + (funcall (if (oremacs/char-upcasep (char-before)) + 'downcase-region + 'upcase-region) + beg end))))) +(bind-key "M-l" 'oremacs/upcase-word-toggle) + ;; Zap up to char is more useful than zap-char (autoload 'zap-up-to-char "misc" "Kill up to, but not including ARGth occurrence of CHAR.") (bind-key "M-z" 'zap-up-to-char) |
