Created
July 12, 2017 15:31
-
-
Save paulsmith/45ea8e5cc552f0ca9d97cf0091d5823f to your computer and use it in GitHub Desktop.
numeronym minor mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun pas-numeronym () | |
"Replace last word with its numeronym. eg.: 'accessibility' with 'a11y'." | |
(interactive) | |
(save-excursion | |
(backward-word) | |
(let ((count 0) (the-word (current-word))) | |
(while (looking-at "[a-zA-Z']") | |
(setq count (1+ count)) | |
(forward-char 1)) | |
(if (>= count 4) | |
(progn | |
(let ((numeronym (format "%s%d%s" (substring the-word 0 1) (- count 2) (substring the-word (1- count))))) | |
(search-backward the-word) | |
(replace-match numeronym))))))) | |
(define-minor-mode numeronym-mode | |
"Automatically replace words as typed with their numeronym." | |
:lighter " numeronym" | |
(add-hook 'post-self-insert-hook | |
(lambda () | |
(if (member (char-before) (string-to-list " .,:;?!")) | |
(pas-numeronym))))) |
Author
paulsmith
commented
Jul 12, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment