0

My RSI is acting up, and I am trying to remap some keys in Emacs to help. Here's what I want to do:

  1. Be able to type the { character with the sequence M-j.
  2. Remove the ability to type the { character with the { key.

I've gotten 1 working by myself but not 2. Point 2 is important for me because the habit is pretty deeply ingrained in me, and I need a reminder to help me switch.

Is this possible? Thank you! -Patrick

Patrick Li
  • 672
  • 4
  • 11
  • `(global-set-key "{" (lambda () (interactive) (message "Bad boy!")))` or `(global-set-key "{" nil)` Note that some major or minor modes may expressly set the key to something else, in which case a major or minor mode map needs to be used to remove the assignment. – lawlist May 08 '16 at 18:06
  • I tried that. Is there a way to do that while ensuring that 1 still works? I used (global-set-key "M-j" "{") to get 1 working. But after your suggestion, that now also types "Bad boy!". – Patrick Li May 08 '16 at 21:55
  • lawlist made *two* suggestions, and the second one *unbinds* `{` from the global map. As also mentioned, this does not preclude other modes and keymaps from defining that key (e.g. in `c-mode`, `}` is bound to `c-electric-brace`, so you may need to unbind it from other maps; or else add a definition which *isn't* `nil` in a custom keymap with a higher priority (e.g. http://stackoverflow.com/q/683425/324105 ) – phils May 09 '16 at 01:39
  • 1
    How about?: `(global-set-key [?\M-j] (lambda () (interactive) (insert "{")))` instead of `(global-set-key "M-j" "{")` – lawlist May 09 '16 at 04:22
  • The insert function was what I was missing. Thank you! – Patrick Li May 09 '16 at 06:05
  • @lawlist: Please post it as an answer. OP: Please consider accepting the answer. – Drew May 09 '16 at 16:44

1 Answers1

2

The original poster indicated that he remapped { to M-j, which caused Emacs to treat the latter as the former. In other words, the behavior for { was the same as M-j.

The following is a means of separating the two, and will serve to help remind the original poster that he wishes to train himself not to press the { key:

(global-set-key [?\M-j] (lambda () (interactive) (insert "{")))

(global-set-key "{" (lambda () (interactive) (message "Bad boy!")))
;;; OR use the following instead:
;; (global-set-key "{" nil)
lawlist
  • 13,099
  • 3
  • 49
  • 158