How to remap C-c? - emacs

Given that there are so many major modes which define their own maps for this prefix (e.g. latex, org, term), is there a safe way to move these maps somewhere else, and always have the C-c key free?
I'm hoping there's a convenient way, because I noticed ErgoEmacs does exactly this.

As far as i know, there no easy way, unless you dive deep into emacs innards and create ways to remap every mode's keys on load. (I think Matthew Fidler is actually working on this)
ergoemacs-mode does not remap the C-c. It turns on cua-mode, but cua-mode doesn't remap C-c neither, it just create several clever ways so that key can be used for multiple purposes (e.g. by the speed you press the key, or whether there's a text selection, etc.). All C-c * keys are still there.
see discussion on this same question here
https://plus.google.com/103652929131043355278/posts/Nb4xn4gDB6p

Related

keybindings for a single character in emacs

I would like to use "Ctrl+'" to replace "\" (i.e., the backslash key). How should I do that? Originally I did it by kbd macro, but it is still different. For example, for the package smartparens, if one types "\{", a "\}" will be automatically typed. However, keyboard macro "ctrl+'"+"{" is not the same as "\{" for this case.
So I am just wondering if there are other ways achieving this? Some global keybinding tool (works for the whole X system) is also ok. But so far I cannot find one that can do such keybinding (two keys for one key).
Thanks!

Emacs Prelude, Smartparens, and OsX

I'm using OSX 10.9, iTerm2, Emacs Prelude, and Clojure with all the modes that entails most relevantly, smartparens. Good so far.
The short version is: has anybody out there found a harmonious way to use all of this together with OSX Mission Control?
The longer version goes: I want to be able to use commands like sp-forward-slurp-sexp, which has a default keybinding of C-<right>, better known as the default OS-level shortcut for "switch Spaces right via Mission Control." I can re-map that fairly easily (say, to C-Shift-<right>) -- but now, I discover that C-<right> actually seems to be sending something like M-[1;4A. Instead of triggering sp-forward-slurp-sexp, you get sp-wrap-with-pair "[". Uhm.
I dug up this dissertation on re-mapping keys, which is very thorough, but also involves re-mapping rather a deal of stuff, then disabling the parts of paredit that are listening for the M-[ command. While this technically seems to work, I actually rather like having sp-wrap-with-pair enabled. Perhaps a better option would be to embrace the theoretically equivalent C-( -- except iTerm2 only interprets that as a literal 9, and C-) as 0. This SO post chews on this problem, and gets as far as a tantalizing comment suggesting that C-( and C-) simply be re-mapped to escape sequences that emacs can map back to C-( and C-) -- but frankly, I haven't a clue how to figure out what escape sequences those should be.
Bringing it all home: has anybody found a way to use all of these tools (Mission Control, iTerm2, Emacs Prelude, smartparens) together without having to re-wire or disable parts of some or most of them? Or: who has the most elegant re-wiring? Anybody figured out the C-)-to-escape-sequence-back-to-C-) trick yet?
Edit
Stabbing in the dark, I've done the following:
1. Set iTerm to send an escape sequence for the keyboard shortcut Ctrl-Shift-0 (C-S-)) of SPRTPRN.
2. Put this in my emacs config:
(define-key input-decode-map "\eSPRTPRN" [C-right-paren])
(global-set-key [C-right-paren] (kbd "C-)"))
...it does not work, but I've a hunch I'm getting closer. I think.
Edit, Again
I realized something: the notion that Shift doesn't work here doesn't make sense to me. At least on my emacs install, M-< and M-> jump to the beginning and end of a buffer, respectively -- and to use those commands, I have to actually press Meta-Shift-<. Huh.

How to preserve keybindings when using multi-term.el in line mode?

In emacs (ver. 24.3), I have my forward-paragraph and backward-paragraph mapped to M-p and M-n instead of M-{ and M-}. It is easier for me to remember and use fluidly with C-p and C-n. I've recently started using multi-term to run most of my terminal work. However, when I switch to line-mode my custom bindings for forward and backward paragraph no longer work. It says 'empty input ring'. Oddly when I'm in char-mode, the C-p and C-n do what they are supposed to do (bringing up previous prompt entries), but my paragraph movements work.
So in short, my custom forward and backward paragraph bindings work in char-mode (where I don't really need them), but not in line-mode. Any ideas?
See term-bind-key-alist, which includes C-p, C-n, M-p, and M-n by default. See also these passages from the EmacsWiki page MultiTerm. The second especially seems relevant to your problem. These do not mention term-line-mode or term-char-mode, but I think they might give you a place to start.
Note 1
‘term-unbind-key-list’ is a list of keys which emacs keeps for itself. By default it contains (“C-z” “C-c” “C-x” “C-h” “C-y” “”)
‘term-bind-key-alist’ is a list of keys and functions which you can use, for example to use Emacs style cursor movement to the multi-terminal. The default is long, so I’ll let you look it up yourself.
Note 2
Because C-r is default keystroke for isearch-backward, for avoid conflict with C-r, i binding M-r to send “C-r” character to shell.
You can use option term-bind-key-alist/term-unbind-key-list to binding/unbinding special keystroke in multi-term.el, and don’t use term-mode-hook. ☺ –- AndyStewart
Also, I don't see term-line-mode anywhere in multi-term.el. It looks as if it makes use only of term-char-mode. See, for instance, multi-term-keystroke-setup.

Find a good hotkey for new emacs commands

In Emacs everything is about hotkeys. Everybody who creates new shortcuts knows the problem:
Which hotkeys should be used?
Which hotkeys are used by the most popular Emacs extensions (org-mode...) and should be avoided?
Are there reserved hotkeys for "users" that will never be used by extensions?
Which hotkeys should be avoided, if the code should be public? (Some keys like right/left Win are sometimes missing on keyboards, M-TAB will be catched by the windowmanager)
Is there a list of all reserved hotkeys?
Sticking to the reserved C-c <letter> sequences is as close as you'll get to guaranteeing that you won't conflict with any other code (although it's still just a convention; sometimes you'll see people making code available that uses one of those sequences, but you can report those cases as bugs to the author).
I would suggest using some of the C-c <letter> sequences as prefix bindings for grouping related functionality together. For instance, you might use C-c w <key> as the pattern for window-related functionality. That gives you a dramatically larger number of reserved bindings, probably with better mnemonic properties, and of course the subsequent <key> can be anything at all, not just a letter.
That also lets you use C-c <letter> C-h to list everything you've bound under that prefix, which can be convenient.
The GNU Emacs Lisp Reference manual has a detailed page on key binding conventions:
http://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Binding-Conventions.html
The keys C-c <letter> are reserved for the users, so packages should normally not use them (note that "letter" is really a letter of the alphabet, not "any key" or "any character"). But most users just use which ever key they like and when that binding conflicts with some package, they handle the conflict in an ad-hoc way (either by using another key, or by specifically overriding the package's binding).
automate key-binding checks evaluating forms like
(key-binding [(control c) (delete)])

How to remap keys when in Emacs?

I am looking for a way to have my control key and caps-lock key switched when I am in the emacs window, but when I go to any other program such as Firefox I want to be able to use the normal control button for new windows, tabs and such.
Additional Information: I am using Ubuntu, but answers for all systems are good since someone else may want to know how to do it on their system.
Emacs never actually sees the CapsLock keycode (under X anyway), so you can't remap the key in Lisp. Take a look at this page for details:
http://www.emacswiki.org/emacs/MovingTheCtrlKey
On windows using Auto Hot Key you can achieve this with this piece of code put in default script:
#IfWinActive, emacs#
CapsLock::Control
#IfWinActive
Auto Hot Key is a very handy utility and it is also free software like in GPL.
For globally remapping keys there is xmodmap. xkeycaps is an interactive tool. You can put control on both keys.
Since you want to remap the keys only for Emacs (which I find somewhat ill-advised) you need to look inside Emacs for a solution. It should be possible, because you can rebind all keys, but it may be too tedious to swap all keys around if the modifiers cannot be swapped.
Personally I map CapsLock to Compose, to type all kinds of funny characters like ä, ß, å, þ, «, —, ...