This is driving me nuts.
I've bound M-e to some useful stuff, but cc-mode is hogging it. I've tried adding c-mode-hooks, c-mode-commons and I've tried eval-after-load on c-mode, ie
(eval-after-load "c-mode"
'(define-key c-mode-map (kbd "M-e") nil))
but whenever I open a C file, M-e is still bound to c-end-of-statement. How do I disable it and replace it with my own bindings?
Maybe you could try this
(define-key c-mode-map [remap c-end-of-statement] 'your-useful-stuff)
or
(define-key cc-mode-map [remap c-end-of-statement] 'your-useful-stuff)
Related
I would like to bind my TAB key in emacs to clang-format-region when in C/C++ mode. How do I achieve this without affecting other modes? In particular, global-set-key doesn't achieve what I want, since it makes editing text with emacs a tad difficult.
You can use define-key on c-mode-base-map (C, C++ ...)
(define-key c-mode-base-map (kbd "<tab>") 'clang-format-region)
You may use local-set-key
(add-hook
'c++-mode-hook
(lambda ()
(local-set-key (kbd "<tab>") #'clang-format-region)))
You can use define-key:
(define-key c++-mode-map (kbd "<tab>") 'clang-format-region)
Is there a way to make Emacs' auto-complete package not trigger menu completion on return key but instead on some other key-combination say C-Return? For a fast typist having it bound to return often causes non-deterministic behaviour of return. This because its behaviour now depends on how fast I type the previous characters.
See https://github.com/auto-complete/auto-complete.
This code should do exactly what you want
(define-key ac-completing-map (kbd "RET") nil)
(define-key ac-completing-map [return] nil)
(define-key ac-completing-map [(control return)] 'ac-complete)
I didn't try it on the terminal as I'm on windows at the moment.
I have this little problem, I have some key bindings like so C-. C-x or C-. C-m. After I activate the flyspell-mode, I cannot use these commands. In my .emacs file I have the next 2 lines before
(global-unset-key (kbd "C-."))
(define-key (current-global-map) (kbd "C-.") nil)
(global-set-key (kbd "C-. C-l") 'global-linum-mode)
Then, my C-. C-l works, but it does not when the flyspell-mode is activated. The command bound to C-. is flyspell-auto-correct-word. I tried to deactivate it as follows:
;; first try
(defun flyspell-auto-correct-word-disable() (define-key (current-local-map) (kbd "C-.") nil))
(add-hook 'flyspell-mode-hook 'flyspell-auto-correct-word-disable)
;; second try
(define-key (current-global-map) [remap flyspell-auto-correct-word] nil)
None of the tries work, what can I do? I tried in Emacs 23 and 24 and I have the same issue.
What about:
(eval-after-load "flyspell"
'(define-key flyspell-mode-map (kbd "C-.") nil))
Your first solution is almost correct, but you have to remember that the current local map is set up by the major mode, not minor modes. The best option you have it to directly access flyspell-mode-map and modify it (another option would be to find it in minor-mode-map-alist but I think it would be needlessly complicated).
Also, I prefer putting such mode-specific settings within eval-after-load (which means they will be evaluated once) rather than in a hook (in which case the settings are evaluated multiple times: each time one buffer activates flyspell-mode). But this is a matter of preference and either way is fine.
I have tried several different ways of doing this, and none have been successful. I want to switch the M-d and C-d functionality (delete word, delete char) respectively while working in c++ files.
Can someone please lend me a hand?
(add-hook 'c-initialization-hook
(lambda ()
(define-key c++-mode-map "\C-d" 'kill-word)
(define-key c++-mode-map "\M-d" 'c-electric-delete-forward)))
From CC Hooks - CC Mode Manulal:
Variable: c-initialization-hook
Hook run only once per Emacs session, when CC Mode is initialized. This is a good place to change key bindings (or add new ones) in any of the CC Mode key maps. See Sample .emacs File.
(eval-after-load "cc-mode"
'(progn
(define-key c++-mode-map (kbd "C-d") 'kill-word)
(define-key c++-mode-map (kbd "M-d") 'delete-char)))
I'm experimenting with new bindings for basic movement in Emacs. Borrowing from this page and ErgoEmacs, this remapping works as expected:
(global-set-key (kbd "M-i") 'previous-line)
(global-set-key (kbd "M-k") 'next-line)
(global-set-key (kbd "M-j") 'backward-char)
(global-set-key (kbd "M-l") 'forward-char)
But defining a Shift-Alt combination gives an unwanted side-effect.
(global-set-key (kbd "M-I") 'cua-scroll-down)
(global-set-key (kbd "M-K") 'cua-scroll-up)
(global-set-key (kbd "M-J") 'backward-word)
(global-set-key (kbd "M-L") 'forward-word)
Running describe-key (C-h k) shows that the bindings were successful. And these bindings move point as they should, but for some reason it sets the mark at my original position, and gives me a highlighted region as I move the point.
How do I correct this?
EDIT:
This has something to do with cua-mode. When I disable cua-mode, the problem disappears. Unfortunately, disabling cua-mode is not a desirable solution.
EDIT:
This is a bug in Emacs. It's tracked as bug#11221, title 'cua-mode activates the mark for shifted bindings'. From the discussion on the mailing list, it sounds like there will be a fix to cua-base.el.
It's indeed likely triggered by shift-select-mode, but it looks like a bug: shift-select-mode should pay attention to the fact that the command is bound to a shifted key. Try to reproduce the problem without using CUA and then please report it with M-x report-emacs-bug.
That's because of the shift selection. You can disable it by setting shift-select-mode to nil.