5

Is there a command in Emacs to turn on what might be described as "caps lock minor mode"? I'm looking to do something like M-x toggle-caps-mode, then every letter I type in the buffer is a capital letter until I do M-x toggle-caps-mode again.

Note: I'm NOT looking for directions on how to swap caps and control. In reality this is because I have already done that. I am generally quite happy with it, but occasionally I'm editing code where there are a bunch of constants that are in all caps, and it gets to be a strain holding down the shift key. I'm aware of the various upcase conversion functions; I'd rather not have to type the word, select it, then run upcase-region.

If it matters, I'm using Aquamacs 2.2 w/ Emacs 23.3.1.

dantswain
  • 5,427
  • 1
  • 29
  • 37
  • If yow have swapped caps and control then you have caps lock on the control key, don't you? Why don't you use that? – Tom Oct 27 '11 at 18:28
  • I guess I'm playing fast and loose with the word "swapped". I really mean that I've remapped caps to control. Control is still control, but I could actually swap them. Still curious if there's a simple answer to this question. – dantswain Oct 27 '11 at 19:46

2 Answers2

5

You don't need to type the word then select it. If you want to upcase the last word, press M-b M-u or ESC b u. Ok, you'll need to press b several times if it's a word_with_underscores.

If you really want a caps lock minor mode, try John Paul Wallington's lockcaps.el.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
2

You can try something like this:

(define-minor-mode caps-lock-mode
  "caps-lock mode"
  ;;   The initial value.   
  nil   
  ;; The indicator for the mode line.   
  " CAPS-LOCK"   
  ;; The minor mode bindings.   
  '(("a" . (lambda () (interactive) (insert-char ?A 1)))
    ("b" . (lambda () (interactive) (insert-char ?B 1)))
    ;;etc 
    ("A" . (lambda () (interactive) (insert-char ?a 1)))    
    ("B" . (lambda () (interactive) (insert-char ?b 1)))    
    ;;etc
    ))
Oleg Pavliv
  • 20,462
  • 7
  • 59
  • 75
  • 1
    I found this: http://lists.gnu.org/archive/html/gnu-emacs-sources/2004-08/msg00013.html and the various replies, which end up giving a slightly more compact version. I was hoping for a built-in, but if this is the answer, then this is the answer. I'll give it some time to see if anyone else has anything different to offer. – dantswain Oct 27 '11 at 19:51
  • Thanks, it's an interesting thread. Especially about how to replace the long keymap with a single function. – Oleg Pavliv Oct 27 '11 at 19:55