1

I'm trying to set up C-S-s to run isearch-forward-symbol-at-point, but when I do the obvious step of:

(global-set-key [C-S-s] 'isearch-forward-symbol-at-point)

It doesn't work. It just does a normal incremental search. When I press C-h k, followed by C-S-s (to find out what it's actually doing) emacs tells me:

C-s (**translated from C-S-s**) runs the command isearch-forward (found in
global-map), which is an interactive compiled Lisp function in
‘isearch.el’.

I think my question is "How do I stop C-S-s from being translated so that I can rebind that key sequence to isearch-forward-symbol-at-point?"

(I read up on keymaps and translation a bit, but it's not clear to me which translation keymap I should be changing, or how to change it)(maybe local-/global-unset-key?)

6

Actually the problem is not the translation: if you had bound the key that you meant to bind, it would have precedence over the translation. The problem is that you didn't bind Ctrl+Shift+S.

There are several syntaxes for keyboard events and it can occasionally get confusing. You can use modifier prefixes like C- for Control and S- for Shift with function keys, but not with characters. Your binding is for a function key whose name is C-S-s, and has no practical effect since there is no such key on your keyboard. For a character, even with modifiers, you need to use a character literal.

(global-set-key [?\C-\S-s] 'isearch-forward-symbol-at-point)

Some modifier+character combinations can be expressed with a string instead of an array of characters, e.g. (global-set-key "\C-s" 'isearch-forward). But strings can only store characters with modifiers that result in another string character: the result has to be an ASCII character, or Meta plus an ASCII character, or a member of an extended character set such as Unicode. Other modifier combinations can be expressed through character constants, but these characters can't be put in strings.

Instead of using a character literal, you can build the key chord using a list containing the modifiers and, at the end, the base key.

(global-set-key [(control shift ?s)] 'isearch-forward-symbol-at-point)

Alternatively, you can use the kbd macro and let it build the key sequence from the usual user-visible syntax. It will figure out that C-S-s means a modified character S and not a function key.

(global-set-key (kbd "C-S-s") 'isearch-forward-symbol-at-point)
  • 3
    @MikeTheTall, personally I strongly recommend the (kbd "C-S-s") syntax and using kbd in general, as that way you can use the description of the key sequence that Emacs gives you, verbatim, which tends to eliminate confusion. – phils Oct 17 '18 at 10:57
  • This worked perfectly! Thanks! (And, for the future, I will just default to the (kbd) syntax!) – MikeTheTall Oct 17 '18 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.