diff options
author | Kyle Meyer <kyle@kyleam.com> | 2015-02-21 22:04:27 -0500 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2015-02-28 00:29:49 -0500 |
commit | 506ef6fa7e01da611b0cc738db036ff971b791b1 (patch) | |
tree | 69ac334be089207de24464fefa2c3b8952e127ce | |
parent | bc45dcdc3065d2d6fc111a390cdeae1f9a4c4a1d (diff) | |
download | emacs.d-506ef6fa7e01da611b0cc738db036ff971b791b1.tar.gz |
Add case-only abbrev functions
-rw-r--r-- | lisp/init-general.el | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lisp/init-general.el b/lisp/init-general.el index c1206f3..6869f44 100644 --- a/lisp/init-general.el +++ b/lisp/init-general.el @@ -44,6 +44,42 @@ `(eval-after-load ,mode '(progn ,@body))) +(defun km/abbrev-add-case-global () + "Define lower abbreviation for the word before point. +Like `add-global-abbrev', but always make the abbreviation the +lower case variant of the word before point." + (interactive) + ;; Modified from `add-abbrev'. + (let* ((table global-abbrev-table) + (exp (buffer-substring-no-properties + (point) + (save-excursion (forward-word -1) (point)))) + (name (downcase exp))) + (when (or (not (abbrev-expansion name table)) + (y-or-n-p (format "%s expands to \"%s\"; redefine? " + name (abbrev-expansion name table)))) + (define-abbrev table name exp)))) + +(defun km/abbrev-inverse-add-uppercase-global () + "Define uppercase expansion for the word before point. +Like `inverse-add-global-abbrev', but always use the lower case +version of the word before point as the abbreviation and the +upper case version as the expansion." + (interactive) + ;; Modified from `inverse-add-abbrev'. + (let* ((table global-abbrev-table) + (end (point)) + (start (save-excursion (forward-word -1) (point))) + (name (downcase (buffer-substring-no-properties start end))) + (exp (upcase name))) + (when (or (not (abbrev-expansion name table)) + (y-or-n-p (format "%s expands to \"%s\"; redefine? " + name (abbrev-expansion name table)))) + (define-abbrev table name exp) + (save-excursion + (goto-char end) + (expand-abbrev))))) + (global-set-key (kbd "C-h ;") 'find-function) (global-set-key (kbd "C-c l") 'km/imenu) @@ -60,6 +96,9 @@ (define-key occur-mode-map "n" 'next-line) (define-key occur-mode-map "p" 'previous-line) +(define-key abbrev-map "c" 'km/abbrev-add-case-global) +(define-key abbrev-map "iu" 'km/abbrev-inverse-add-uppercase-global) + (show-paren-mode) (global-auto-revert-mode) (transient-mark-mode -1) |