spacemacs
spacemacs copied to clipboard
Unreasonable behavior of 'C-u number SPC' in insert mode
Hi, I use spacemacs develop branch, and hybrid key mode.
In insert mode, if I want to type 4 whitespace, it should work by C-u 4 " " but in spacemacs it does not work, instead I have to type C-u 4 SPC u "", this seems unreasonable, as this is in insert mode, seems no need to treat SPC special.
Confirmed, it also happens in insert state with the vim editing style.
Windows 10, System Info (Click to expand)
#### System Info :computer:
- OS: windows-nt
- Emacs: 27.1
- Spacemacs: 0.300.0
- Spacemacs branch: develop (rev. 3eb66f4ce)
- Graphic display: t
- Distribution: spacemacs
- Editing style: vim
- Completion: helm
- Layers:
```elisp
(autohotkey clojure emacs-lisp git helm javascript lsp multiple-cursors
(org :variables org-agenda-files
'("c:/Users/username/org/")
org-enable-jira-support t org-enable-roam-support t)
python shell spell-checking syntax-checking version-control treemacs)
```
- System configuration features: XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY W32NOTIFY ACL GNUTLS LIBXML2 HARFBUZZ ZLIB TOOLKIT_SCROLL_BARS MODULES THREADS JSON PDUMPER LCMS2 GMP
I think this is due to these lines
(when (memq dotspacemacs-editing-style '(vim hybrid))
(define-key universal-argument-map
(kbd (concat dotspacemacs-leader-key " u"))
'universal-argument-more))
I assume that universal-argument-map is active whenever a "universal argument" is pending.
Inspecting universal-argument-map (by SPC h d K) shows this to be the case, as SPC u is bound to universal-argument-more. Here's the rest of the keymap
universal-argument-map
----------------------
For more information check the manuals.
Keymap used while processing SPC u.
key binding
--- -------
C-u universal-argument-more
SPC Prefix Command
- negative-argument
0 .. 9 digit-argument
<kp-0> digit-argument
<kp-1> digit-argument
<kp-2> digit-argument
<kp-3> digit-argument
<kp-4> digit-argument
<kp-5> digit-argument
<kp-6> digit-argument
<kp-7> digit-argument
<kp-8> digit-argument
<kp-9> digit-argument
<kp-subtract> negative-argument
<switch-frame> ??
SPC u universal-argument-more
and so this is similarly why you can't use C-u 3 4 to insert 444.
My emacs skills are not good enough to interrogate which keymaps are active after entering a prefix command, although I notice that while in a normal state, entering SPC u SPC u does not trigger universal-argument-more but instead just regular universal-argument, so I assume that universal-argument-map must be loaded somewhere with lower priority than the evil keymaps (which I think are usually at the top of the emulation-mode-map-alists).
I'm not quite sure how to fix this behavior without likely breaking the way prefixes work, but thought it might be useful to direct y'all to the relevant bit of code.
SPC u SPC u binds to universal-argument-more, which calls universal-argument--mode (also called by universal-argument).
Interesting; if from normal state I do SPC u SPC, then which-key describes u as just universal-argument, whereas if I go into insert mode, then after C-u SPC, which-key's pop-up describes u as universal-argument-more (although I agree with you after having read more of the simple.el source code that it must be indeed as you describe).
Try this
(setq dummy-universal-argument-map (make-sparse-keymap))
(set-keymap-parent dummy-universal-argument-map universal-argument-map)
(define-key dummy-universal-argument-map (kbd "SPC") nil)
(define-key dummy-universal-argument-map (kbd "C-u") nil)
(defun dummy-universal-argument--mode ()
(prefix-command-update)
(set-transient-map (if (memq evil-state '(insert emacs))
dummy-universal-argument-map
universal-argument-map)
nil))
(advice-add 'universal-argument--mode :override 'dummy-universal-argument--mode)
Very clever! (Minor typo: setq-keymap-parent -> set-keymap-parent).
I wonder if we can improve this further. For example, the lines I linked above hinge on whether the editing style is set to vim or hybrid when the code is run (presumably at startup), so if for example I launch with vim editing style, but then I toggle emacs with SPC t E h, the "weirdness" of C-u 4 SPC not inserting four spaces will persist (and I presume this is not fixed by your clever idea above, since the evil-state then is emacs and not insert, although that's readily remedied).
Perhaps it'd be good to add some logic to spacemacs-editing-style-hook (which is not documented but I assume runs when changing the editing style).
@dankessler updated the script
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!