init-dubcaps.el 933 B

12345678910111213141516171819202122232425262728
  1. (define-minor-mode dubcaps-mode
  2. "Toggle `dubcaps-mode'. Converts words in DOuble CApitals to
  3. Single Capitals as you type."
  4. :init-value nil
  5. :lighter (" DC")
  6. (if dubcaps-mode
  7. (add-hook 'post-self-insert-hook #'dcaps-to-scaps nil 'local)
  8. (remove-hook 'post-self-insert-hook #'dcaps-to-scaps 'local)))
  9. (defun dcaps-to-scaps ()
  10. "Convert word in DOuble CApitals to Single Capitals."
  11. (interactive)
  12. (and (= ?w (char-syntax (char-before)))
  13. (save-excursion
  14. (and (if (called-interactively-p)
  15. (skip-syntax-backward "w")
  16. (= -3 (skip-syntax-backward "w")))
  17. (let (case-fold-search)
  18. (looking-at "\\b[[:upper:]]\\{2\\}[[:lower:]]"))
  19. (capitalize-word 1)))))
  20. (add-hook 'post-self-insert-hook #'dcaps-to-scaps nil 'local)
  21. (add-hook 'text-mode-hook #'dubcaps-mode)
  22. (add-hook 'prog-mode-hook #'dubcaps-mode)
  23. (provide 'init-dubcaps)