From 506ef6fa7e01da611b0cc738db036ff971b791b1 Mon Sep 17 00:00:00 2001
From: Kyle Meyer <kyle@kyleam.com>
Date: Sat, 21 Feb 2015 22:04:27 -0500
Subject: Add case-only abbrev functions

---
 lisp/init-general.el | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

(limited to 'lisp')

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)
-- 
cgit v1.2.3