12345678910111213141516171819202122232425262728 |
- (define-minor-mode dubcaps-mode
- "Toggle `dubcaps-mode'. Converts words in DOuble CApitals to
- Single Capitals as you type."
- :init-value nil
- :lighter (" DC")
- (if dubcaps-mode
- (add-hook 'post-self-insert-hook #'dcaps-to-scaps nil 'local)
- (remove-hook 'post-self-insert-hook #'dcaps-to-scaps 'local)))
- (defun dcaps-to-scaps ()
- "Convert word in DOuble CApitals to Single Capitals."
- (interactive)
- (and (= ?w (char-syntax (char-before)))
- (save-excursion
- (and (if (called-interactively-p)
- (skip-syntax-backward "w")
- (= -3 (skip-syntax-backward "w")))
- (let (case-fold-search)
- (looking-at "\\b[[:upper:]]\\{2\\}[[:lower:]]"))
- (capitalize-word 1)))))
- (add-hook 'post-self-insert-hook #'dcaps-to-scaps nil 'local)
- (add-hook 'text-mode-hook #'dubcaps-mode)
- (add-hook 'prog-mode-hook #'dubcaps-mode)
- (provide 'init-dubcaps)
|