1

Previously I used C-SPC to activate/deactivate mark, now I use expand-region package and set key binding to C-@ like this:

(global-set-key (kbd "C-@") 'er/expand-region)

But this affected the C-SPC keybinding also, so it is also bound to expand-region.

What I need is C-@ bind to expand-region and C-SPC to bind to old activate/deactivate mark.

jogojapan
  • 68,383
  • 11
  • 101
  • 131
user3995789
  • 3,452
  • 1
  • 19
  • 35

2 Answers2

1

Suggest you refer to:

set-mark-command not working emacs with C-SPC

and

https://www.gnu.org/software/emacs/manual/html_node/emacs/Setting-Mark.html

Quoting from the latter:

"Footnotes [1] There is no C-<SPC> character in ASCII; usually, typing C-<SPC> on a text terminal gives the character C-@. This key is also bound to set-mark-command, so unless you are unlucky enough to have a text terminal that behaves differently, you might as well think of C-@ as C-<SPC>."

I think you'll find that they are not separate keys; C-SPC sends a code that's the same as C-@. I think that means you'll have to find somewhere else to bind one of the functions, (even if you have to override expand-region)

Community
  • 1
  • 1
koan911
  • 360
  • 1
  • 3
  • 13
  • Sorry: https://www.gnu.org/software/emacs/manual/html_node/emacs/Setting-Mark.html – koan911 Oct 25 '14 at 13:54
  • when I run `C-h k C-SPC` I get the explanation for `C-@` as if I pressed it. `C-x C-x` works fine. I think first link doesn't solve my problem, because emacs sees `C-SPC` the same as `C-@` somehow. @koan911 – user3995789 Oct 25 '14 at 14:27
  • 1
    @koan911, link-only answers are discouraged on Stack Overflow. But if you edit your answer and add the quote you have put in the comments, this will probably be a good answer. – ChrisGPT was on strike Oct 25 '14 at 15:01
  • When I press `Ctrl + 2` or `Ctrl + Shift + 2` it sends `C-@`, (note that `Shift` makes no difference), but when I want to send a `C-#` and press `Ctrl + Shift + 3` or `Ctrl + 3` it sends `M-[ ; 6 s is undefined`, what is going on, how can I send a `C-#` what key should I bind this expand-region to? And Finally why does Shift not matter here? @koan911 – user3995789 Oct 25 '14 at 16:51
0

Apologies for a second answer... I think the first was wrong because I have now been able to make separate definitions for C-SPC and C-@, as described below.

This works to define C-@ and C-SPC separately:

(global-set-key [?\C-@] 'beginning-of-line) (global-set-key (kbd "C-SPC") 'end-of-line)

To give credit, I derived the answer from here: Rebind C-space in Emacs after googling "emacs control space"

(Regarding your question, "what key should I bind this expand-region to?", I ordinarily use C-h C-k and type some key I don't think I use. Then look at the function that that key is bound to by default. If it seems useful to me, I try another key and keep looking. If I feel like I will never use the default definition, I redefine it for my own purposes.)

Community
  • 1
  • 1
koan911
  • 360
  • 1
  • 3
  • 13
  • You can certainly make separate bindings for `C-@` and `C-SPC`. The issue is whether Emacs will ever actually *receive* the sequence `C-SPC`. If running in GUI mode, it will. If running in a terminal then, as detailed in the quote included in your other answer, it most likely won't. – phils Oct 27 '14 at 12:51