summaryrefslogtreecommitdiff
path: root/emacs/scripts/caps-lock-mode.el
diff options
context:
space:
mode:
authortslil clingman <>2019-09-11 19:18:14 -0400
committertslil clingman <>2019-09-11 19:18:14 -0400
commitac1a4884d03fc0495c773500d8a13f84b695fa43 (patch)
tree29e5ec49e0ce957d80d8f11a155b47840c74f488 /emacs/scripts/caps-lock-mode.el
Init
Diffstat (limited to 'emacs/scripts/caps-lock-mode.el')
-rw-r--r--emacs/scripts/caps-lock-mode.el21
1 files changed, 21 insertions, 0 deletions
diff --git a/emacs/scripts/caps-lock-mode.el b/emacs/scripts/caps-lock-mode.el
new file mode 100644
index 0000000..c80883a
--- /dev/null
+++ b/emacs/scripts/caps-lock-mode.el
@@ -0,0 +1,21 @@
+(defvar caps-lock-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map [remap self-insert-command] 'upcased-self-insert)
+ map))
+
+(define-minor-mode caps-lock-mode
+ "Caps lock minor mode."
+ nil " CLK" caps-lock-mode-map)
+
+(defun upcased-self-insert (arg)
+ "Insert an uppercase version of the input, unless in a comment or string"
+ (interactive "p")
+ (let* ((syn (syntax-ppss))
+ (comment-or-string (or (nth 4 syn) (nth 3 syn)))
+ (last-command-event (if (and (not comment-or-string)
+ (characterp last-command-event))
+ (upcase last-command-event)
+ last-command-event)))
+ (self-insert-command arg)))
+
+(provide 'caps-lock-mode)