WorldsEndless · 2022-03-15 16:06
With my new keyboard often I hit Meta instead of Super, with the result that I start passing numeric args to the next command instead which can be destructive when I don't catch it in time and C-g out of it.
Can I change my mode-line during numeric arguments being entered? I already do that when I'm in God Mode, so I would like to copy the same thing. Only, I don't know a mode or other indicator for "I'm entering numeric arguments now". How can I do this?
crawsphi · 2022-03-15 17:44
As a simple option maybe just lowering the `echo-keystrokes` delay would be enough?
Otherwise a `pre-command-hook` could be used to warn you. Just as a demonstration:
(defun wend/numeric-arg-warning ()
(when-let ((n (and current-prefix-arg
(prefix-numeric-value current-prefix-arg))))
(warn "Numeric arg! %d" n)))
(add-hook 'pre-command-hook #'numeric-arg-warning)
If you want to change the modeline, a `post-command-hook` would be needed for cleanup, but the timing seems tricky. This doesn't quite work but maybe you can figure it out from here:
(defvar-local wend/orig-mode-line-background nil)
(defun wend/numeric-arg-warning ()
(when (and current-prefix-arg
(prefix-numeric-value current-prefix-arg))
(setq wend/orig-mode-line-background (face-background 'mode-line))
(set-face-background 'mode-line "red")))
(defun wend/numeric-arg-unwarning ()
(when (and wend/orig-mode-line-background
(not (eq last-command #'self-insert-command)))
(set-face-background 'mode-line wend/orig-mode-line-background)
(setq wend/orig-mode-line-background nil)))
(add-hook 'pre-command-hook #'wend/numeric-arg-warning)
(add-hook 'post-command-hook #'wend/numeric-arg-unwarning)
WorldsEndless · 2022-03-15 21:15
I think echo-keystrokes is a great solution, but it led me to a next question: is it possible to stylize the echo area? I don't see any customization options for "status", but making it a different color would do the trick of calling attention.
00-11 · 2022-03-15 22:59
Sure.
`M-: (progn (message (propertize "QQQQQQQ" 'face 'highlight)) (sleep-for 2))`
WorldsEndless · 2022-03-16 14:13
any idea how to apply this to certain echo messages, like the numerical args one?
crawsphi · 2022-03-16 18:13
I don't know for sure but I suspect the echoing is done in C code. Otherwise you might be able to add some advice.