;;; caps-back -- one-keystroke word pre-capitalizer ;;; Commentary: ;; .-------------------------------------------. ;; | caps-back - | ;; | (sort of) by Emanuel Berg \:.. ;; | http://user.it.uu.se/~embe8573/conf/emacs-init/caps-back.el ;; | embe8573 AT&T student DOS uu DOS se /|'' ;; | updated: 16.01, 04/07/14 | ;; '-------------------------------------------' ;; This minor mode capitalizes the (whole) following ;; word that is typed, _as_ it is typed, and then ;; quietly disables automatically at the ;; word boundary. ;; For this to work efficiently, a short and close ;; keystroke -- optimally a single key -- is assigned ;; to invoke the minor mode: i.e., to the ;; `toggle-caps-mode' command. It is anyone's game as ;; the shortcut isn't set here. (I use M-CAPS, by ;; the way.) ;; So: \\[toggle-caps-mode] TYPE one word in caps ;; (The reason I write "sort of" above is I found some ;; work on this which I used, at this point however ;; I don't know exactly who did what; for sure, I did ;; the automatic reset.) ;;; Code: (defun newline-and-indent-and-reset-caps () "Deactivate Caps mode, then process the \\[newline-and-indent]-keystroke as it normally would." (interactive) (caps-mode 0) (if (minibuffer-selected-window) (exit-minibuffer) (newline-and-indent) )) (defun char-alphanum-or-dash (c) "True if C is a character, a number, or a dash." (or (eq c ?-) (and (>= c ?1) (<= c ?9)) (and (>= c ?A) (<= c ?Z)) (and (>= c ?a) (<= c ?z)) )) (defun upcase-change-dash (the-char) "The capital version of THE-CHAR, or an underscore if CHAR is a dash. Useful when doing old-school constants in C, perhaps. Change the code that is `caps-mode-self-insert-command' to get it!" (let ((dash ?-)) (if (= the-char dash) dash (upcase the-char) ))) (defun caps-mode-self-insert-command (n) "Insert the capital version of N, unless N isn't `char-alphanum-or-dash': if so, exit Caps mode'." (interactive "p") (let*((the-char last-command-event) (alphanum-or-dash (char-alphanum-or-dash the-char)) ) (unless alphanum-or-dash (caps-mode 0)) (insert-char (upcase the-char) ;; (upcase-change-dash 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 () "Toggle Caps mode." (interactive) (if caps-mode (caps-mode 0) (caps-mode) )) (provide 'caps-back) ;;; caps-back.el ends here