How to link the text box to isearch

I would like to have Mu to insert an underscore when I'm in isearch (isearch-regexp, as well as reverse options).

Neither

 (define-key isearch-mode-map (kbd "Mu") 'insert-underscore) 

neither

 (add-hook 'isearch-mode-hook (lambda () (local-set-key (kbd "Mu") 'insert-underscore) )) "Mu") 'insert-underscore) (add-hook 'isearch-mode-hook (lambda () (local-set-key (kbd "Mu") 'insert-underscore) )) 

insert-underscore is my function that simply inserts "_". It works in the main frame, as well as in the minibuffer, but I can not get it to work in isearch ...

Thanks!

+4
source share
1 answer

Isearch does not use regular commands. (kbd "_") together with all the other printable characters, is tied to a special command in isearch-mode-map . This is not obvious, but in "isearch-mode" a lot of things happen when you press the key. The display is updated with new results, packaging is possible, etc. Etc.,

You will need to manipulate the raw keyboard events, to make it work.

 (defun underscore () (interactive) (isearch-unread-key-sequence (list ?_))) (define-key isearch-mode-map (kbd "Mu") 'underscore) 

Please note that this code is not reliable; for example, a numeric prefix does not work.

EDIT: After I held out in my brain for a while, it seemed to me that this was an exact precedent for broadcast layouts

 (define-key key-translation-map (kbd "Mu") (kbd "_")) 

Emacs does not grand?

+4
source

All Articles