Due to various/extensive remappings I insert symbols with Control+key, for example Ctrl+9 inserts a left parenthesis (. This works fine with the remappings and the insert/insert-commands, however, modes such as smartparens do not catch this. In my example hitting Ctrl+9 with spartparens should insert a pair of parentheses () instead of a single one (which works using Shift+9). I suspect that the problem is due to using insert/insert-char instead of self-insert-command so the mode does not see/register the event. I wonder if anyone has any idea for a fix?
This my setup code for reference, essentially a loop over a macro that sets up a global keybinding for C-[unshifted char] to [corresponding shifted char]:
; Bind Ctrl as shift for symbols. (defun my-bind-symbols-to-crtl () (interactive) (let ( (chars (split-string "~1234567890-=;']\\,./" "")) (shifted-chars (split-string "`!@#$%^&*()_+:\"}|<>?" "")) (char "") (shifted-char "") ) (while chars (setq char (pop chars)) (setq shifted-char (pop shifted-chars)) (when (> (length char) 0) (global-set-key (kbd (concat "C-" char)) (eval(macroexpand `(insert-key-macro ,shifted-char)))) ) ))) (defmacro insert-key-macro (in) `(lambda () (interactive) (insert ,in))) (my-bind-symbols-to-crtl) (global-set-key (kbd "H-[") (lambda () (interactive) (insert "{"))) (define-key input-decode-map (kbd "C-[") (kbd "H-["))
function-key-mapto translateC-9toS-9and then let nature take its course.(define-key input-decode-map (kbd (concat "C-" char)) (kbd shifted-char))))post-self-insert-hooks, You could just(run-hooks 'post-self-insert-hooks)after inserting. But I think @Lindydancer's solution is the better one.