I want to create a mode which in certain states converts all input to uppercase, regardless of the caps-lock status. But I'm at a loss as to how to go for this, and I'm not sure it could even be done. Any help would be appreciated.

  • 1
    You could create 26 key-bindings (your own major-mode, or your own minor-mode) and thus not have to worry about playing with any hooks. Or, you could play with the pre-command-hook or post-command-hook if you don't want 26 key-bindings.
    – lawlist
    Aug 29 '16 at 17:26
  • There is also the post-self-insert-hook if you prefer using that (for a custom uppercase function) instead of having 26 key-bindings.
    – lawlist
    Aug 29 '16 at 17:32
  • You might want to look at sqlup for a similar minor mode. You have the benefit of your solution being even simpler! The author even gave a presentation about this, which might be useful as reference.
    – zck
    Aug 29 '16 at 20:31

You could do worse than look at GNU ELPA's caps-lock package.

  • I think the wording of your answer, while logically very clear, is confusing (but I'm not english native)
    – YoungFrog
    Aug 30 '16 at 15:09
  • I will look into it. However I was hoping for an answer that didn't require external packages.
    – Andrea
    Aug 31 '16 at 8:29
  • @Andrea IIUC this package provides a solution to your problem. Either you use it, or you decide you want to rewrite it from scratch.
    – YoungFrog
    Aug 31 '16 at 10:13

I was able to do it by adding a buffer local post-command-hook and upcasing the previous word when the self-insert-command is executed and I am in the right state.

(add-hook 'post-command-hook 'mymode-post-command-hook nil t)

(defun mymode-post-command-hook ()
  (when (and
         (eq this-command 'self-insert-command)
         (eq mymode-state 0))
    (upcase-word -1)))

I have tested this a bit and seems to work fine. It could probably be slimmer with the post-self-insert-hook. Thank you for all the suggestions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.