0

I recently got a new Chromebook and installed Ubuntu via crouton. I then installed Emacs 23 and transferred my .emacs file to the new machine. However, a few of my key rebindings have been overridden by definitions in the LaTeX major mode of the new installation. This did not happen on my previous computer (emacs 24.something). The three changes I would like to make are:

  1. When I press [, I want } to display.
  2. When I press (, I want { to display.
  3. When I press $, I want ^ to display.

I have the following lines in my .emacs file (along with other similar lines that work as intended):

(global-set-key (kbd "[") '(lambda () (interactive) (princ "{" (get-buffer (current-buffer)))))

(global-set-key (kbd "(") '(lambda () (interactive) (princ "[" (get-buffer (current-buffer)))))

(global-set-key (kbd "$") '(lambda () (interactive) (princ "^" (get-buffer (current-buffer)))))

I only use Emacs for LaTeX, so I am not concerned with the fact that I am defining everything globally. Currently, if I use C-h k [, I see that [ calls skeleton-pair-insert-maybe instead of self-insert-command, as expected (and similarly for the other two). All of my attempts to search on how to disable this returned only results talking about the usage of skeleton pairs and why one would want to use them, nothing about getting rid of them. Similarly, I have been unable to find a way to edit the LaTeX major mode to remove the lines that bind this function in the first place.

Any method which allows me to redefine these keys over the LaTeX major mode, or to change the LaTeX major mode, would be appreciated.

1

If you are trying to move keys around, but only in emacs, then it is probably easier to use a translation keymap.

(define-key key-translation-map "[" "{")
(define-key key-translation-map "(" "[")

As far as the binding to skeleton-pair-insert-maybe, I don't see this being setup to any key. You can use the code How can I find out in which keymap a key is bound? to find the keymap,and then use (define-key keymap "[" nil) to unbind it from that keymap. When you want to unbind it depends on where it is being bound!

  • Perfect. It seems define-key is the correct way to do what I originally wanted, but I of course found a different hack first when I made the initial changes. Partially as expected, skeleton-pair-insert-maybe was not really the problem, just the part that I could see was different from before. Thanks. – Zach Oct 25 '16 at 3:57
  • 1
    As I said in emacs.stackexchange.com/questions/27811/… set-global-key is just a thin wrapper around define-key, providing the global keymap. – icarus Oct 25 '16 at 4:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.