Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unbind C-m from RET

Tags:

emacs

elisp

In my emacs config file I have created a minor mode so that I can re-bind keys without having to rebind them separately for each major mode.

In doing so, I have re-mapped C-m to kill-ring-save. However, in default emacs C-m is the same as RET. Therefore when I have the following in my .emacs :

 (define-key my-minor-mode-map (kbd "C-m") 'kill-ring-save)

When I press the return key, kill-ring-save is executed

How should I go about fixing my config file so that I don't run into these problems?

I am also open to taking a different approach to creating a key binding that works in all major modes.

Edit: I am running in graphical mode

like image 645
pseudosudo Avatar asked Aug 29 '11 20:08

pseudosudo


1 Answers

This won't work in a non-graphical mode emacs. When run in a terminal, return and C-m are not distinguishable.

If you're not running terminal mode emacs, just rebind <return> and C-m separately.

For example:

(cond (window-system  ; ensure not running in a terminal
       (local-set-key (kbd "<return>") 'newline)
       (local-set-key (kbd "C-m") 'kill-ring-save)))
like image 67
ataylor Avatar answered Nov 05 '22 03:11

ataylor