Skip to content

Instantly share code, notes, and snippets.

@paulsmith
Created July 12, 2017 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulsmith/45ea8e5cc552f0ca9d97cf0091d5823f to your computer and use it in GitHub Desktop.
Save paulsmith/45ea8e5cc552f0ca9d97cf0091d5823f to your computer and use it in GitHub Desktop.
numeronym minor mode
(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)))))
@paulsmith
Copy link
Author

numeronym

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment