(defun newline-and-indent-and-reset-caps () (interactive) (caps-mode 0) (if (minibuffer-selected-window) (exit-minibuffer) (newline-and-indent) )) (defun char-alphanum-or-dash (c) (or (memq c '(?- ?Å ?Ä ?Ö ?å ?ä ?ö)) (and (>= c ?1) (<= c ?9)) (and (>= c ?A) (<= c ?Z)) (and (>= c ?a) (<= c ?z)) )) (defun upcase-change-dash (c) "C upcased, unless C is a dash, if so, underscore." (if (eq c ?-) ?_ (upcase c) )) (defun caps-mode-self-insert-command (n) (interactive "p") (let ((the-char last-command-event)) (if (not (char-alphanum-or-dash the-char)) (caps-mode 0)) (insert-char (upcase the-char) n) )) (defvar caps-mode-map (let ((map (make-keymap))) (substitute-key-definition 'newline-and-indent 'newline-and-indent-and-reset-caps map global-map) (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 () (interactive) (if caps-mode (caps-mode 0) (caps-mode) ))