summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/init-general.el39
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)