Using a semicolon in a global key set for a function in .emacs

I am trying to set [Ctrl] - [;] as a key binding in my .emacs such as

(global-set-key "\C-;" 'comment-or-uncomment-region) 

however, it does not work when I try (I do not receive any error messages, it just does not affect). It will work if I try a normal character (for example, set it to "\ Cp").

I also tried

 (global-set-key (kbd "C-;") 'comment-or-uncomment-region) 

but I don’t like this option because for me it doesn’t work when I run "emacs -nw". Any thoughts on how I can do this?

EDIT: When I run Ch c C-; in emacs -nw , I get the output:

 ; runs the command self-insert-command 

which is exactly the same as starting Ch c ; in emacs -nw

So, I believe that phils is right, that this is a terminal problem, because emacs never sees C-; she sees only ;

+4
source share
2 answers

Using (kbd "C-;") absolutely true and correct.

I suspect that when you type C-; when you start emacs -nw your terminal does not actually send Emacs anything.

So your problem is most likely related to the question of how to get your terminal to send C-; in Emacs (or, alternatively, how to make Emacs recognize the sent sequence).

If you run emacs -Q -nw and type Ch c C-; , you get the message "C-; is undefined" ?

Assuming this is a terminal issue, here are some related questions and answers that may point you in the right direction, but it depends on the particular terminal you are using.

+4
source

Really C-; it’s usually not something your terminal can send to a basic application such as Emacs (therefore it works under a graphical interface, but not in a terminal). But I wonder: why do you need such a binding in any case, given that M-; already attached to comment-dwim , which comments / uncomments the region when choosing a region, so it provides a superset of comment-or-uncomment-region .

+4
source

Source: https://habr.com/ru/post/1403280/


All Articles