;;; caps-back.el --- one-keystroke word pre-capitalizer -*- lexical-binding: t -*- ;; ;; Author: Emanuel Berg ;; Created: 2021-05-23 ;; Keywords: unix ;; License: GPL3+ ;; URL: https://dataswamp.org/~incal/emacs-init/caps-back.el ;; Version: 2.1.1 ;; ;;; Commentary: ;; ;; This minor mode capitalizes the entire next word that is ;; typed, at the same time as it is typed, then quietly ;; disables itself at the word boundary. ;; ;; For this to work efficiently, a short and close keystroke, ;; optimally a single key, should be assigned to invoke the ;; minor mode, which happens with the ;; `toggle-caps-mode' function. ;; ;; Setup a shortcut like this: ;; ;; (global-set-key KEY #'toggle-caps-mode) ;; ;; Then, hit \\[toggle-caps-mode] and type one and only one ;; WORD in caps. ;; ;;; Code: (defun char-alphanum-or-dash (c) "True if C is a character, a number, a dash, or an underscore." (or (member c '(?- ?_)) (member c '(?å ?Å ?ä ?Ä ?ö ?Ö)) (and (>= c ?1) (<= c ?9)) (and (>= c ?A) (<= c ?Z)) (and (>= c ?a) (<= c ?z)) )) (defun caps-mode-self-insert-command (&optional times) "Insert the `last-command-event' char 1 or TIMES times. Uppercase unless something else than an alphanum or a dash." (interactive "p") (or times (setq times 1)) (let*((chr last-command-event) (alphanum-or-dash (char-alphanum-or-dash chr))) (if alphanum-or-dash (insert-char (if (= chr ?-) ?_ (upcase chr) ) times) (caps-mode 0) (insert-char chr times) ))) (defvar caps-mode-map (let ((map (make-keymap))) (substitute-key-definition #'self-insert-command #'caps-mode-self-insert-command map global-map) map) ) (define-minor-mode caps-mode "Caps on you." :init-value nil :lighter " Caps") (defun toggle-caps-mode () "Toggle Caps mode." (interactive) (caps-mode 'toggle) ) (provide 'caps-back) ;;; caps-back.el ends here