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.
Asked
Active
Viewed 215 times
1
-
1You 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](https://github.com/Trevoke/sqlup-mode.el) for a similar minor mode. You have the benefit of your solution being even simpler! The author even [gave a presentation](https://blog.trevoke.net/sqlup-talk/#/slide-orgheadline1) about this, which might be useful as reference. – zck Aug 29 '16 at 20:31
2 Answers
2
You could do worse than look at GNU ELPA's caps-lock
package.

Stefan
- 26,154
- 3
- 46
- 84
-
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 08: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
1
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.

Andrea
- 173
- 5